Code to run tests on the Ethernet library
Dependencies: EthernetInterface mbed-rtos mbed
Diff: main.cpp
- Revision:
- 1:effed2d57b6c
- Parent:
- 0:3f5638515f99
- Child:
- 2:483bc2e71bfe
--- a/main.cpp Sun Oct 27 09:59:50 2013 +0000 +++ b/main.cpp Mon Oct 28 20:37:19 2013 +0000 @@ -1,26 +1,60 @@ #include "mbed.h" #include "EthernetInterface.h" + + +DigitalOut myled(LED1); +Ticker pkt; +EthernetInterface *eth; +UDPSocket *sock; +InterruptIn *flow; +//PwmOut *pump; + + +unsigned int flowcount = 0; +float pi = 3.1415926535897932384626433832795; + +void flowtick() { + flowcount++; +} + +void ping() { + myled.write(1); + Endpoint seven; + seven.set_address("192.168.9.7", 37); + char out_buffer[8]; // Does not matter + sprintf(out_buffer, "%07d", flowcount); + sock->sendTo(seven, out_buffer, sizeof(out_buffer)); + wait(0.5); + myled.write(0); +} int main() { - EthernetInterface eth; - eth.init("192.168.9.8", "255.255.255.0", "192.168.9.1"); - eth.connect(); - printf("IP Address is %s\n", eth.getIPAddress()); + eth = new EthernetInterface(); + flow = new InterruptIn(p5); + // pump = new PwmOut(p21); + sock = new UDPSocket(); + - UDPSocket sock; - sock.init(); + // pump->period(1.0); + eth->init("192.168.9.8", "255.255.255.0", "192.168.9.1"); + eth->connect(); + printf("IP Address is %s\n", eth->getIPAddress()); + sock->init(); - Endpoint seven; - seven.set_address("192.168.9.7", 37); + flow->rise(&flowtick); + pkt.attach(&ping, 2.0); - char out_buffer[] = "plop"; // Does not matter - - while(1) { - sock.sendTo(seven, out_buffer, sizeof(out_buffer)); - wait(1); + float t = 0.0; + while(1) { + if(t < pi) { + t += 0.01; +// pump->write(1 - cos(t)); + } + + wait(0.1); } - sock.close(); + sock->close(); - eth.disconnect(); + eth->disconnect(); }