From 99a83ce409de08805a28081b14082abd3b55e926 Mon Sep 17 00:00:00 2001 From: pifou Date: Tue, 5 Mar 2019 14:43:50 +0000 Subject: [PATCH] Ajout réponse TCP et reception UDP --- Tangible/ethernet.o | Bin 0 -> 1060 bytes Tangible/iic.o | Bin 0 -> 1260 bytes Tangible/serial.h | 9 ++++++--- Tangible/serial.o | Bin 0 -> 1348 bytes Tangible/socket.h | 7 ++++++- Tangible/socket.o | Bin 0 -> 6880 bytes Tangible/tangibleInterface.c | 42 +++++++++++++++++++++++++++++++++++++++--- Tangible/tangibleInterface.o | Bin 0 -> 1576 bytes Tangible/w5100.o | Bin 0 -> 7944 bytes 9 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 Tangible/ethernet.o create mode 100644 Tangible/iic.o create mode 100644 Tangible/serial.o create mode 100644 Tangible/socket.o create mode 100644 Tangible/tangibleInterface.o create mode 100644 Tangible/w5100.o diff --git a/Tangible/ethernet.o b/Tangible/ethernet.o new file mode 100644 index 0000000..8726fd7 Binary files /dev/null and b/Tangible/ethernet.o differ diff --git a/Tangible/iic.o b/Tangible/iic.o new file mode 100644 index 0000000..18a4914 Binary files /dev/null and b/Tangible/iic.o differ diff --git a/Tangible/serial.h b/Tangible/serial.h index fcababf..ef05963 100644 --- a/Tangible/serial.h +++ b/Tangible/serial.h @@ -1,6 +1,9 @@ /** Definitions for serial port **/ +void init_printf(void); // Met le BD à 9600 + void init_serial(int speed); -void send_serial(char c); -char get_serial(void); -void init_printf(void); + +void send_serial(char c); //Envoi via UDR0 +char get_serial(void); // Recupère UDR0 + diff --git a/Tangible/serial.o b/Tangible/serial.o new file mode 100644 index 0000000..cd1079f Binary files /dev/null and b/Tangible/serial.o differ diff --git a/Tangible/socket.h b/Tangible/socket.h index 11e6bf7..4347686 100755 --- a/Tangible/socket.h +++ b/Tangible/socket.h @@ -10,11 +10,16 @@ extern uint8 socket(SOCKET s, uint8 protocol, uint16 port, uint8 flag); // Opens a socket(TCP or UDP or IP_RAW mode) extern void close(SOCKET s); // Close socket + + extern uint8 connect(SOCKET s, uint8 * addr, uint16 port); // Establish TCP connection (Active connection) -extern void disconnect(SOCKET s); // disconnect the connection +extern void disconnect(SOCKET s); // Disconnect the connection + extern uint8 listen(SOCKET s); // Establish TCP connection (Passive connection) extern uint16 send(SOCKET s, const uint8 * buf, uint16 len); // Send data (TCP) extern uint16 recv(SOCKET s, uint8 * buf, uint16 len); // Receive data (TCP) + + extern uint16 sendto(SOCKET s, const uint8 * buf, uint16 len, uint8 * addr, uint16 port); // Send data (UDP/IP RAW) extern uint16 recvfrom(SOCKET s, uint8 * buf, uint16 len, uint8 * addr, uint16 *port); // Receive data (UDP/IP RAW) diff --git a/Tangible/socket.o b/Tangible/socket.o new file mode 100644 index 0000000..0aca7b5 Binary files /dev/null and b/Tangible/socket.o differ diff --git a/Tangible/tangibleInterface.c b/Tangible/tangibleInterface.c index 2673430..b071b5c 100644 --- a/Tangible/tangibleInterface.c +++ b/Tangible/tangibleInterface.c @@ -12,7 +12,43 @@ int main(void) { -init_printf(); -// Your code here !! -return 0; + uint8_t mac[MAC_SIZE] = {0xAD,0xBD,0xCD,0xDD,0xED,0xFD}; + uint8_t ip[IPV4_SIZE] = {172,26,145,205}; + uint8_t gateway[4] = {172,26,145,35}; + uint8_t mask[4] = {255,255,255,0}; + + const char * answer = "I'm ok"; + + char buf[16]; // Message à stocker. + uint8_t addr[IPV4_SIZE]; // Adresse source du message reçu. + uint16_t port; // Port source du message reçu. + + SOCKET sUDP; + SOCKET sTCP; + + init_printf(); // On active la liaison série (9600 BD). + ethernet_init(mac,ip,gateway,mask); // On assimile une adresse MAC et IP au shield + Indication de la passerelle et du masque de sous-réseau. + if (!socket(sUDP,Sn_MR_UDP,2020,0)) + { + return -1; + } + if (!socket(sTCP,Sn_MR_TCP,2020,0)) + { + return -1; + } + while(1) + { + if(listen(sTCP)) //Repondre je vais bien à un client + { + send(sTCP,(uint8 *)answer,sizeof(answer)); + } + + if (recvfrom(sUDP,buf,sizeof(buf),addr,&port) != -1) //Reception via UDP (infos de la sonde) + { + + } + } + close(sTCP); + close(sUDP); + return 0; } diff --git a/Tangible/tangibleInterface.o b/Tangible/tangibleInterface.o new file mode 100644 index 0000000..b76091d Binary files /dev/null and b/Tangible/tangibleInterface.o differ diff --git a/Tangible/w5100.o b/Tangible/w5100.o new file mode 100644 index 0000000..4085724 Binary files /dev/null and b/Tangible/w5100.o differ -- libgit2 0.21.2