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 MODSERIAL mbed-rtos mbed
Fork of UDPEchoServer by
Diff: UDP.txt
- Revision:
- 7:42bc53611fc7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UDP.txt Fri Sep 07 08:40:42 2018 +0000 @@ -0,0 +1,75 @@ + +void Init_Ethernet() +{ + printf("# Init Ethernet\r\n"); + eth.init(); //Use DHCP + eth.connect(); + printf("# Server IP Address is %s\r\n", eth.getIPAddress()); + server.bind(SERVER_PORT); + server.set_blocking(false,10); + printf("# UDP Server listening at Port: %d\r\n",SERVER_PORT);wait_ms(10); +} + + +//############################################################################# +// UDP-Server +//############################################################################# +void Call_UDP_Server(void) +{ + int n = server.receiveFrom(client, UDP_CharBuf, sizeof(UDP_CharBuf)); + if (n>0) + { printf("# UDP %s from %s:%d\r\n", UDP_CharBuf,client.get_address(),client.get_port()); wait_ms(10); + if (UDP_CharBuf[0]=='%' && UDP_CharBuf[1]=='A') + { + sprintf(UDP_CharBuf,"# Analog IN: %1.2f %1.2f %1.1f %1.1f %1.1f \r\n",U_Analog1,U_Analog2,U_Analog3,U_Analog4,U_Analog5); + printf("# Data to UDP Client %s:%d\r\n", client.get_address(),client.get_port()); + server.sendTo(client, UDP_CharBuf, strlen(UDP_CharBuf)); // variable Länge + memset (UDP_CharBuf,'\0',sizeof(UDP_CharBuf)); + wait_ms(10); + } + if (UDP_CharBuf[0]=='%' && UDP_CharBuf[1]=='P') + { int value=0; + UDP_CharBuf[0]='0';UDP_CharBuf[1]='0'; + sscanf (UDP_CharBuf,"%d",&value); + DigOUT01 = value & 0xFF; + WR_IO(); + sprintf(UDP_CharBuf,"# Dig.OUT: %d\r\n",DigOUT01); + USB.printf("# Data to UDP Client %s:%d\r\n", client.get_address(),client.get_port()); + server.sendTo(client, UDP_CharBuf, strlen(UDP_CharBuf)); // variable Länge + memset (UDP_CharBuf,'\0',sizeof(UDP_CharBuf)); + wait_ms(10); + //USB.printf("# Dig.OUT: %d\r\n",DigOUT01);wait_ms(10); + } + if (UDP_CharBuf[0]=='%' && UDP_CharBuf[1]=='D') + { + USB.printf("# Send Data to %s:%d\r\n", client.get_address(),client.get_port()); + for (int i=0;i<DataCnt;i++) + { sprintf(UDP_CharBuf,"$%d %1.2f %1.2f\r\n",i,Data1[i],Data2[i]); + server.sendTo(client, UDP_CharBuf, strlen(UDP_CharBuf)); // variable Länge + memset (UDP_CharBuf,'\0',sizeof(UDP_CharBuf)); + } + wait_ms(10); + } + if (UDP_CharBuf[0]=='%' && UDP_CharBuf[1]=='S') + { + USB.printf("# Starte Messung\r\n"); + DataCnt=0; + DataOutCnt=1; + AnalogDataTimer.attach_us(&GetAnalogData, AD_uSek); + MessRunning=true; + wait_ms(10); + } + } +} + + + + + if (EthernetConnection && client.get_port()>0) + { + sprintf(UDP_CharBuf,"# Dig.IN: %d\r\n", DigIN01); wait_ms(10); + USB.printf("# Data to UDP Client %s:%d\r\n", client.get_address(),client.get_port()); + server.sendTo(client, UDP_CharBuf, strlen(UDP_CharBuf)); // variable Länge + memset (UDP_CharBuf,'\0',sizeof(UDP_CharBuf)); + wait_ms(10); + }