Robert Spangenberg / Mbed 2 deprecated AF_IO05

Dependencies:   EthernetInterface MODSERIAL mbed-rtos mbed

Fork of UDPEchoServer by Mbed

Committer:
vibe
Date:
Fri Sep 07 08:40:42 2018 +0000
Revision:
7:42bc53611fc7
AF_IO

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vibe 7:42bc53611fc7 1
vibe 7:42bc53611fc7 2 void Init_Ethernet()
vibe 7:42bc53611fc7 3 {
vibe 7:42bc53611fc7 4 printf("# Init Ethernet\r\n");
vibe 7:42bc53611fc7 5 eth.init(); //Use DHCP
vibe 7:42bc53611fc7 6 eth.connect();
vibe 7:42bc53611fc7 7 printf("# Server IP Address is %s\r\n", eth.getIPAddress());
vibe 7:42bc53611fc7 8 server.bind(SERVER_PORT);
vibe 7:42bc53611fc7 9 server.set_blocking(false,10);
vibe 7:42bc53611fc7 10 printf("# UDP Server listening at Port: %d\r\n",SERVER_PORT);wait_ms(10);
vibe 7:42bc53611fc7 11 }
vibe 7:42bc53611fc7 12
vibe 7:42bc53611fc7 13
vibe 7:42bc53611fc7 14 //#############################################################################
vibe 7:42bc53611fc7 15 // UDP-Server
vibe 7:42bc53611fc7 16 //#############################################################################
vibe 7:42bc53611fc7 17 void Call_UDP_Server(void)
vibe 7:42bc53611fc7 18 {
vibe 7:42bc53611fc7 19 int n = server.receiveFrom(client, UDP_CharBuf, sizeof(UDP_CharBuf));
vibe 7:42bc53611fc7 20 if (n>0)
vibe 7:42bc53611fc7 21 { printf("# UDP %s from %s:%d\r\n", UDP_CharBuf,client.get_address(),client.get_port()); wait_ms(10);
vibe 7:42bc53611fc7 22 if (UDP_CharBuf[0]=='%' && UDP_CharBuf[1]=='A')
vibe 7:42bc53611fc7 23 {
vibe 7:42bc53611fc7 24 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);
vibe 7:42bc53611fc7 25 printf("# Data to UDP Client %s:%d\r\n", client.get_address(),client.get_port());
vibe 7:42bc53611fc7 26 server.sendTo(client, UDP_CharBuf, strlen(UDP_CharBuf)); // variable Länge
vibe 7:42bc53611fc7 27 memset (UDP_CharBuf,'\0',sizeof(UDP_CharBuf));
vibe 7:42bc53611fc7 28 wait_ms(10);
vibe 7:42bc53611fc7 29 }
vibe 7:42bc53611fc7 30 if (UDP_CharBuf[0]=='%' && UDP_CharBuf[1]=='P')
vibe 7:42bc53611fc7 31 { int value=0;
vibe 7:42bc53611fc7 32 UDP_CharBuf[0]='0';UDP_CharBuf[1]='0';
vibe 7:42bc53611fc7 33 sscanf (UDP_CharBuf,"%d",&value);
vibe 7:42bc53611fc7 34 DigOUT01 = value & 0xFF;
vibe 7:42bc53611fc7 35 WR_IO();
vibe 7:42bc53611fc7 36 sprintf(UDP_CharBuf,"# Dig.OUT: %d\r\n",DigOUT01);
vibe 7:42bc53611fc7 37 USB.printf("# Data to UDP Client %s:%d\r\n", client.get_address(),client.get_port());
vibe 7:42bc53611fc7 38 server.sendTo(client, UDP_CharBuf, strlen(UDP_CharBuf)); // variable Länge
vibe 7:42bc53611fc7 39 memset (UDP_CharBuf,'\0',sizeof(UDP_CharBuf));
vibe 7:42bc53611fc7 40 wait_ms(10);
vibe 7:42bc53611fc7 41 //USB.printf("# Dig.OUT: %d\r\n",DigOUT01);wait_ms(10);
vibe 7:42bc53611fc7 42 }
vibe 7:42bc53611fc7 43 if (UDP_CharBuf[0]=='%' && UDP_CharBuf[1]=='D')
vibe 7:42bc53611fc7 44 {
vibe 7:42bc53611fc7 45 USB.printf("# Send Data to %s:%d\r\n", client.get_address(),client.get_port());
vibe 7:42bc53611fc7 46 for (int i=0;i<DataCnt;i++)
vibe 7:42bc53611fc7 47 { sprintf(UDP_CharBuf,"$%d %1.2f %1.2f\r\n",i,Data1[i],Data2[i]);
vibe 7:42bc53611fc7 48 server.sendTo(client, UDP_CharBuf, strlen(UDP_CharBuf)); // variable Länge
vibe 7:42bc53611fc7 49 memset (UDP_CharBuf,'\0',sizeof(UDP_CharBuf));
vibe 7:42bc53611fc7 50 }
vibe 7:42bc53611fc7 51 wait_ms(10);
vibe 7:42bc53611fc7 52 }
vibe 7:42bc53611fc7 53 if (UDP_CharBuf[0]=='%' && UDP_CharBuf[1]=='S')
vibe 7:42bc53611fc7 54 {
vibe 7:42bc53611fc7 55 USB.printf("# Starte Messung\r\n");
vibe 7:42bc53611fc7 56 DataCnt=0;
vibe 7:42bc53611fc7 57 DataOutCnt=1;
vibe 7:42bc53611fc7 58 AnalogDataTimer.attach_us(&GetAnalogData, AD_uSek);
vibe 7:42bc53611fc7 59 MessRunning=true;
vibe 7:42bc53611fc7 60 wait_ms(10);
vibe 7:42bc53611fc7 61 }
vibe 7:42bc53611fc7 62 }
vibe 7:42bc53611fc7 63 }
vibe 7:42bc53611fc7 64
vibe 7:42bc53611fc7 65
vibe 7:42bc53611fc7 66
vibe 7:42bc53611fc7 67
vibe 7:42bc53611fc7 68 if (EthernetConnection && client.get_port()>0)
vibe 7:42bc53611fc7 69 {
vibe 7:42bc53611fc7 70 sprintf(UDP_CharBuf,"# Dig.IN: %d\r\n", DigIN01); wait_ms(10);
vibe 7:42bc53611fc7 71 USB.printf("# Data to UDP Client %s:%d\r\n", client.get_address(),client.get_port());
vibe 7:42bc53611fc7 72 server.sendTo(client, UDP_CharBuf, strlen(UDP_CharBuf)); // variable Länge
vibe 7:42bc53611fc7 73 memset (UDP_CharBuf,'\0',sizeof(UDP_CharBuf));
vibe 7:42bc53611fc7 74 wait_ms(10);
vibe 7:42bc53611fc7 75 }