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
main.cpp
- Committer:
- hggerdd
- Date:
- 2014-03-18
- Revision:
- 1:f45d6c8ec0a9
- Parent:
- 0:f7caac9b804e
- Child:
- 2:8f5bacfef390
File content as of revision 1:f45d6c8ec0a9:
#include "mbed.h" #include "w5100.h" #include "UDPSocket.h" #include "ipaddr.h" extern W5100Class W5100; Serial pc(D1, D0); Timer sendStatusTimer; Timer pollUDPTimer; Ticker callUDPSocket; UDPSocket testsocket1(0); DigitalOut myled(LED1); void exFunction(UDPSocketEvent var) { char buf[1000]; int len=0; int rcvPort = 0; uint8_t mac[6]; int udpPort = 33; // empfangene Daten anzeigen len = testsocket1.recvfrom(buf, sizeof(buf) , 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; // 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() { int udpPort=33; 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); // Initialisieren des Ethernetinterfaces pc.printf("Etbernet initialisieren.\n"); W5100.hardware_reset(); W5100.init(); uint8_t mac[6] = {0x00,0x00,0x5e,0x00,0x01,0x01}; W5100.setMACAddress(mac); uint8_t u[4]; localhost.getIP(u); W5100.setIPAddress(u); netmask.getIP(u); W5100.setSubnetMask(u); gateway.getIP(u); W5100.setGatewayIp(u); // init testSocket int socketNr = 0; testsocket1.bind(exFunction, udpPort); callUDPSocket.attach(&testsocket1, &UDPSocket::poll, 0.1); // Sendetimer starten (und anschließend per Polling abfragen) pc.printf("Sendetimer starten.\n"); sendStatusTimer.start(); pollUDPTimer.start(); while(1) { // nach Ablauf der Wartezeit die STatusinformationen per Serieller Schnittstelle senden if (sendStatusTimer.read_ms() >= 2000) { sendStatusTimer.reset(); // Timer schnellst möglich neu starten pc.printf("\n----------------------------------------------------.\n"); W5100.getMACAddress(mac); pc.printf("MAC Addr is : %02d:%02d:%02d:%02d:%02d:%02d.\n", mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]); W5100.getIPAddress(mac); pc.printf("IP Addr is : %d.%d.%d.%d\n", mac[0],mac[1],mac[2],mac[3]); W5100.getGatewayIp(mac); pc.printf("GW Addr is : %d.%d.%d.%d\n", mac[0],mac[1],mac[2],mac[3]); printf("socket:%d SnMR:%02x SnIR:%02x SnSR:%02x\n", socketNr, W5100.readSnMR(socketNr), W5100.readSnIR(socketNr), W5100.readSnSR(socketNr)); W5100.readSnDIPR(socketNr, mac); pc.printf("Sn_DIPR: %d.%d.%d.%d Sn_DPORT: %d\n", mac[0], mac[1], mac[2], mac[3], W5100.readSnDPORT(socketNr)); W5100.readSnDHAR(socketNr, mac); pc.printf("Sn_DHAR: %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); pc.printf("Sn_RX_RSR:%d, Sn_RX_RD:%d, Sn_RX_WR:%d\n", W5100.readSnRX_RSR(socketNr), W5100.readSnRX_RD(socketNr), W5100.readSnRX_WR(socketNr)); pc.printf("Sn_TX_FSR:%d, Sn_TX_RD:%d, Sn_TX_WR:%d\n", W5100.readSnTX_FSR(socketNr), W5100.readSnTX_RD(socketNr), W5100.readSnTX_WR(socketNr)); } /* if (pollUDPTimer.read_ms() >= 200) { pollUDPTimer.reset(); testsocket1.poll(); } */ } }