Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface Servo mbed-rtos mbed
Diff: main.cpp
- Revision:
- 3:269f1844a464
- Parent:
- 2:f3e4edf4d638
--- a/main.cpp Thu Dec 14 05:11:38 2017 +0000 +++ b/main.cpp Thu Dec 14 11:30:40 2017 +0000 @@ -37,13 +37,13 @@ //inicializa o módulo ethernet eth.init(); eth.connect(); - + Servo1.Enable(POS_CENTRO,20000); // inicializa threads tcp_server.start(tcp_server_thread); broadcast.start(udp_broadcast); //controle.start(controle_thread); - + broadcast.join(); printf("Todas as thread iniciadas\n"); @@ -59,55 +59,65 @@ TCPSocketServer server; server.bind(ECHO_SERVER_PORT); server.listen(); - - printf("\nWait for new connection...\n"); - TCPSocketConnection client; - server.accept(client); - client.set_blocking(false, 1500); // Timeout after (1.5)s + + printf("\nWait for new connection...\n"); + TCPSocketConnection client; + server.accept(client); + client.set_blocking(false, 1500); // Timeout after (1.5)s - conectado = true; - printf("\nConnection from: %s\n", client.get_address()); - char buffer[256]; - while (true) { - int n = client.receive(buffer, sizeof(buffer)); - - if (n <=1) { - //printf("Waiting messenger..."); - //break; - }else{ + conectado = true; + printf("\nConnection from: %s\n", client.get_address()); + char buffer[256]; + while (true) { + int n = client.receive(buffer, sizeof(buffer)); + + if (n <=1) { + //printf("Waiting messenger..."); + //break; + } else { // print received message to terminal buffer[n] = '\0'; printf("Received message from Client :'%s'\n",buffer); - + int pos = buffer[8] - '0'; - + if(pos == 1)setpoint = 20; else if(pos == 2)setpoint = 35; else if(pos == 3)setpoint = 50; printf("Setpoint: %d\n", setpoint); - + m_ref.lock(); // ref = atof(buffer); sprintf (buffer, "%s", client.get_address()); m_ref.unlock(); - + m_ref.lock(); sprintf (buffer, "%s", client.get_address()); m_ref.unlock(); - + // print sending message to terminal printf("Sending message to Client: '%s'\n",buffer); - + // Echo received message back to client //client.send_all(buffer, n); - // if (n <= 0) break; - memset(buffer,0,256); - Servo1.SetPosition(sizeof(buffer)); + // if (n <= 0) break; + memset(buffer,0,256); + + if(buffer[0] == 'd') { + for(int pos = 1000; pos < 2000; pos +=25) { + Servo1.SetPosition(pos); + } + } else if(buffer[0] == 'e') { + for(int pos = 2000; pos > 1000; pos -=25) { + Servo1.SetPosition(pos); + } } - } - client.close(); + } + } + + client.close(); } void udp_broadcast ()