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.
Fork of eth_v13 by
Diff: main.cpp
- Revision:
- 1:f45d6c8ec0a9
- Parent:
- 0:f7caac9b804e
- Child:
- 2:8f5bacfef390
--- a/main.cpp Tue Mar 18 17:00:22 2014 +0000 +++ b/main.cpp Tue Mar 18 18:30:45 2014 +0000 @@ -7,8 +7,11 @@ Serial pc(D1, D0); Timer sendStatusTimer; Timer pollUDPTimer; +Ticker callUDPSocket; UDPSocket testsocket1(0); +DigitalOut myled(LED1); + void exFunction(UDPSocketEvent var) { char buf[1000]; @@ -23,22 +26,24 @@ buf[len]=0; // letztes Zeichen eine null, damit es das Stringende erkannt wird pc.printf("%s\n", buf); + // Led blinken lassen + myled = !myled; + // empfangene Daten zurücksenden testsocket1.sendto(buf, len, mac, udpPort); } int main() { - char buf[1000]; - int len; int udpPort=33; - int rcvPort = 0; - + IpAddr localhost(192,168,1,68); IpAddr netmask(255,255,255,0); IpAddr gateway(192,168,1,1); IpAddr tempIP; + wait(5); + // Serielle Schnittstelle initialisieren pc.baud(115200); @@ -50,36 +55,20 @@ uint8_t mac[6] = {0x00,0x00,0x5e,0x00,0x01,0x01}; W5100.setMACAddress(mac); - pc.printf("Start: HW Addr is : %02x:%02x:%02x:%02x:%02x:%02x.\n", mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]); - uint8_t u[4]; - /*u[0] = 192; - u[1] = 168; - u[2] = 1; - u[3] = 66; - */ localhost.getIP(u); W5100.setIPAddress(u); - /*u[0] = 255; - u[1] = 255; - u[2] = 255; - u[3] = 0; - */ netmask.getIP(u); W5100.setSubnetMask(u); - /*u[0] = 192; - u[1] = 168; - u[2] = 2; - u[3] = 1; - */ gateway.getIP(u); W5100.setGatewayIp(u); // init testSocket int socketNr = 0; - testsocket1.bind(&exFunction, udpPort); + testsocket1.bind(exFunction, udpPort); + callUDPSocket.attach(&testsocket1, &UDPSocket::poll, 0.1); // Sendetimer starten (und anschließend per Polling abfragen) pc.printf("Sendetimer starten.\n"); @@ -121,23 +110,12 @@ } - - + /* if (pollUDPTimer.read_ms() >= 200) { pollUDPTimer.reset(); - len = testsocket1.poll(); - if (len > 0) { - - // empfangene Daten anzeigen - testsocket1.recvfrom(buf, len , mac, &rcvPort); - pc.printf("\n========\nNachricht von : %d.%d.%d.%d:%d\n", mac[0], mac[1], mac[2], mac[3], rcvPort); - buf[len]=0; - pc.printf("%s\n", buf); - - // empfangene Daten zurücksenden - testsocket1.sendto(buf, len, mac, udpPort); - } + testsocket1.poll(); } + */ } }