UDP test example code.

Dependencies:   EthernetInterface mbed-rtos mbed

Committer:
ban4jp
Date:
Mon Oct 13 06:26:10 2014 +0000
Revision:
0:b9107cf31131
UDP test example code.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ban4jp 0:b9107cf31131 1 #include "mbed.h"
ban4jp 0:b9107cf31131 2 #include "EthernetInterface.h"
ban4jp 0:b9107cf31131 3 #include "UDPSocket.h"
ban4jp 0:b9107cf31131 4
ban4jp 0:b9107cf31131 5 EthernetInterface eth;
ban4jp 0:b9107cf31131 6 UDPSocket udpClient;
ban4jp 0:b9107cf31131 7 Endpoint epServer;
ban4jp 0:b9107cf31131 8
ban4jp 0:b9107cf31131 9 Serial pc(USBTX, USBRX);
ban4jp 0:b9107cf31131 10 DigitalOut myled1(LED1);
ban4jp 0:b9107cf31131 11 DigitalOut myled2(LED2);
ban4jp 0:b9107cf31131 12
ban4jp 0:b9107cf31131 13 const char SENDDATA[] = "testtesttesttesttesttesttesttest";
ban4jp 0:b9107cf31131 14
ban4jp 0:b9107cf31131 15 int main()
ban4jp 0:b9107cf31131 16 {
ban4jp 0:b9107cf31131 17 pc.printf("eth.init() dhcp return = %d\n", eth.init());
ban4jp 0:b9107cf31131 18 //pc.printf("eth.init() static return = %d\n", eth.init("192.168.0.38", "255.255.255.0", "192.168.0.38"));
ban4jp 0:b9107cf31131 19
ban4jp 0:b9107cf31131 20 eth.connect();
ban4jp 0:b9107cf31131 21 udpClient.init();
ban4jp 0:b9107cf31131 22
ban4jp 0:b9107cf31131 23 epServer.set_address("239.168.1.1", 38383);
ban4jp 0:b9107cf31131 24 pc.printf("IP Address = %s\n", eth.getIPAddress());
ban4jp 0:b9107cf31131 25
ban4jp 0:b9107cf31131 26 while(1) {
ban4jp 0:b9107cf31131 27 for(int i=16; i<=sizeof(SENDDATA); i++) {
ban4jp 0:b9107cf31131 28 myled1 = !myled1;
ban4jp 0:b9107cf31131 29 udpClient.sendTo(epServer, (char * )&SENDDATA, i);
ban4jp 0:b9107cf31131 30 wait(0.25);
ban4jp 0:b9107cf31131 31 }
ban4jp 0:b9107cf31131 32 myled2 = !myled2;
ban4jp 0:b9107cf31131 33 wait(2);
ban4jp 0:b9107cf31131 34 }
ban4jp 0:b9107cf31131 35 }