Code to run tests on the Ethernet library

Dependencies:   EthernetInterface mbed-rtos mbed

main.cpp

Committer:
lawless
Date:
2013-10-28
Revision:
2:483bc2e71bfe
Parent:
1:effed2d57b6c
Child:
3:021bdd25958a

File content as of revision 2:483bc2e71bfe:

#include "mbed.h"
#include "EthernetInterface.h"

DigitalOut myled(LED2);
Ticker pkt;
EthernetInterface *eth;
UDPSocket *sock;
InterruptIn *flow;
PwmOut *pump;

unsigned int flowcount = 0;
float pi = 3.1415926535897932384626433832795;

void flowtick() {
    flowcount++;
}

void ping() {
    Endpoint seven;
    UDPSocket sock;
    sock.init();
    myled.write(1);
    
    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.close();
    wait(0.5);
    myled.write(0);
}
 
int main() {
    eth = new EthernetInterface();
    flow = new InterruptIn(p5);
    pump = new PwmOut(p21);  
    
    pump->period(1.0);
    eth->init("192.168.9.8", "255.255.255.0", "192.168.9.1");
    eth->connect();   
    
    flow->rise(&flowtick);
    pkt.attach(&ping, 2.0);
    
    float t = 0.0;
    while(1) {   
        if(t < pi) {
            t += 0.01;
            pump->write(1 - cos(t));
        }
        
        wait(0.1);
    }
    
    eth->disconnect();
}