programme
Dependencies: EthernetInterface mbed-rtos mbed
Revision 0:8a6f406dd109, committed 2015-06-16
- Comitter:
- Starz
- Date:
- Tue Jun 16 12:13:57 2015 +0000
- Commit message:
- c pour val
Changed in this revision
diff -r 000000000000 -r 8a6f406dd109 EthernetInterface.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Tue Jun 16 12:13:57 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/EthernetInterface/#2fc406e2553f
diff -r 000000000000 -r 8a6f406dd109 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jun 16 12:13:57 2015 +0000 @@ -0,0 +1,78 @@ +#include "mbed.h" +#include "EthernetInterface.h" + + + +EthernetInterface eth; +char ip[] = "192.168.1.10"; +char masque[] = "255.255.255.0"; +char passerelle[] = "192.168.1.255"; +TCPSocketServer server; +TCPSocketConnection client; +int serveur_port = 2000; +DigitalOut myled(LED1); +Serial pc(USBTX, USBRX); +int main() { +bool client_connected = false; +char buffer [100]; +pc.printf("Hello, I'm happy my Serial port is ok.\n\r"); +if (eth.init(ip,masque,passerelle)!=0) { +pc.printf("ERREUR INIT ETHERNET\r\n"); +return -1; +} +if (eth.connect()!=0) { +pc.printf("ERREUR CONNECT\r\n"); +return -1; +} +pc.printf("L addresse Ip est %s\r\n", eth.getIPAddress()); +pc.printf("IP est OK, vous pouvez continuer\r\n"); +if (server.bind (serveur_port)!=0) { +pc.printf("Erreur Tcp bind\r\n"); +return -1; +} +pc.printf("Succes Tcp Bind\r\n"); +if (server.listen()!=0){ +pc.printf("ERREUR Tcp Listen\r\n"); +return -1; +} +pc.printf("Succes Tcp listen\r\n"); +pc.printf("Connectez un client Tcp port 2000...\r\n"); +client.set_blocking(false, 100); // Timeout after (100ms) +while(1) { +if (client_connected==false) +{ +if (server.accept (client)!=0){ +pc.printf("ERREUR connexion client\r\n"); // erreur +return -1; +} +client_connected = true; +pc.printf("Client Tcp connecte\r\n"); +pc.printf("Adresse Ip client %s\r\n",client.get_address()); +client.send("Hello\r\n",strlen("Hello\r\n")); +} +else +{ +if ( client.is_connected() ) +{ +if (pc.readable()) // interface virtuel serie recoit donnees +{ +buffer[0] = pc.getc(); +client.send(buffer,1); +} +int nbcaractere = client.receive(buffer,sizeof(buffer)); +if (nbcaractere>0) // interface Ethernet recoit donnees +{ +buffer[nbcaractere] = 0; +pc.printf("%s",buffer); +} +} +else +{ +client_connected = false; +client.close(); +pc.printf("Client deconnecte\r\n"); +pc.printf("Connectez un client Tcp port 2000...\r\n"); +} +} +} +} \ No newline at end of file
diff -r 000000000000 -r 8a6f406dd109 mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Tue Jun 16 12:13:57 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#34292fba723c
diff -r 000000000000 -r 8a6f406dd109 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Jun 16 12:13:57 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/433970e64889 \ No newline at end of file