Code to run tests on the Ethernet library

Dependencies:   EthernetInterface mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
lawless
Date:
Mon Oct 28 21:14:44 2013 +0000
Parent:
1:effed2d57b6c
Child:
3:021bdd25958a
Commit message:
test

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Oct 28 20:37:19 2013 +0000
+++ b/main.cpp	Mon Oct 28 21:14:44 2013 +0000
@@ -1,14 +1,12 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
 
-
-DigitalOut myled(LED1);
+DigitalOut myled(LED2);
 Ticker pkt;
 EthernetInterface *eth;
 UDPSocket *sock;
 InterruptIn *flow;
-//PwmOut *pump;
-
+PwmOut *pump;
 
 unsigned int flowcount = 0;
 float pi = 3.1415926535897932384626433832795;
@@ -18,12 +16,16 @@
 }
 
 void ping() {
+    Endpoint seven;
+    UDPSocket sock;
+    sock.init();
     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));  
+    sock.sendTo(seven, out_buffer, sizeof(out_buffer));  
+    sock.close();
     wait(0.5);
     myled.write(0);
 }
@@ -31,15 +33,11 @@
 int main() {
     eth = new EthernetInterface();
     flow = new InterruptIn(p5);
- //   pump = new PwmOut(p21);
-    sock = new UDPSocket();    
-    
+    pump = new PwmOut(p21);  
     
- //   pump->period(1.0);
+    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();    
+    eth->connect();   
     
     flow->rise(&flowtick);
     pkt.attach(&ping, 2.0);
@@ -48,13 +46,11 @@
     while(1) {   
         if(t < pi) {
             t += 0.01;
-//            pump->write(1 - cos(t));
+            pump->write(1 - cos(t));
         }
         
         wait(0.1);
     }
     
-    sock->close();
-    
     eth->disconnect();
 }