Test example of UDP for http://mbed.org/forum/helloworld/topic/1279/, fixing some settings for LPC2368

Dependencies:   NetServices mbed

Files at this revision

API Documentation at this revision

Comitter:
simon
Date:
Mon Nov 22 22:29:39 2010 +0000
Child:
1:0013c61ce210
Commit message:

Changed in this revision

EthernetNetIf.lib Show annotated file Show diff for this revision Revisions of this file
UDPSocketExample.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetNetIf.lib	Mon Nov 22 22:29:39 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UDPSocketExample.cpp	Mon Nov 22 22:29:39 2010 +0000
@@ -0,0 +1,55 @@
+#include "mbed.h"
+#include "EthernetNetIf.h"
+#include "UDPSocket.h"
+EthernetNetIf eth;
+UDPSocket     cfgSocket;
+
+void onUDPSocketEvent(UDPSocketEvent e) {
+    if ( e == UDPSOCKET_READABLE ) {
+        char buf[64] = {0};
+        Host host;
+        while ( int len = cfgSocket.recvfrom( buf, 63, &host ) ) {
+            if ( len <= 0 )
+                break;
+            printf("From %d.%d.%d.%d: %s\n", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3], buf);
+        }
+    }
+}
+
+int main() {
+//   pc.baud(115200);
+    printf ("HEllo World - 7 *\n");
+
+    EthernetErr ethErr = eth.setup();
+    if ( ethErr == ETH_OK ) {
+        IpAddr ip = eth.getIp();
+        printf("mbed IP Address is %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]);
+    } else printf ("ETHERNETSETUP FAILED\n");
+
+    printf("seting event\n");
+    cfgSocket.setOnEvent(&onUDPSocketEvent);
+    printf("seting host\n");
+    Host x(IpAddr(),5556);
+    printf("seting bind\n");
+
+    UDPSocketErr udpErr = cfgSocket.bind( x );
+    if ( udpErr != UDPSOCKET_OK )
+        printf("error %d\n", udpErr);
+
+    int i = 0;
+    Host brdHost(IpAddr(255,255,255,255), 5555);                    //broadcast test msg
+    char cfgRqstMsg[]="SERVER CONFIG REQUEST";
+
+    Timer tmr;
+    tmr.start();
+    while (1) {
+        Net::poll();
+        if ( tmr.read() > 5) {
+            tmr.reset();
+            int nSent = cfgSocket.sendto(cfgRqstMsg,strlen(cfgRqstMsg),&brdHost);
+            printf("PLONKER %d :: %d\n",++i,nSent);
+            if ( nSent < 0 )
+                printf("error %d\n", (UDPSocketErr)nSent);
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Nov 22 22:29:39 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da