The London Hackspace bandwidth meter
Dependencies: LPD8806 MODSERIAL mbed picojson
See:
- https://github.com/londonhackspace/net-o-meter
- http://wiki.london.hackspace.org.uk/view/Projects/BandwidthMeter
Diff: main.cpp
- Revision:
- 3:7fca72f96711
- Parent:
- 2:81155674a852
- Child:
- 4:7087ea3d13c1
--- a/main.cpp Sun Jun 10 23:05:12 2012 +0000 +++ b/main.cpp Thu Aug 23 00:17:04 2012 +0000 @@ -1,12 +1,16 @@ #include "mbed.h" +#include "ctype.h" #include "LPD8806.h" +#include "vfd.h" DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); +Ethernet eth; + /* talk to the world */ Serial pc(USBTX, USBRX); @@ -66,6 +70,11 @@ setPixelsBottom(14, quantity < 16 ? quantity : 16, strip.Color(127, 0, 0)); } +void emf_blue() { + setPixelsBottom(0, 15, strip.Color(0, 161, 228)); + setPixelsTop(0, 15, strip.Color(0, 161, 228)); +} + #define s_looking 1 #define s_top 2 #define s_bottom 3 @@ -75,6 +84,28 @@ int i, state = s_looking, tmp = 0, col = 1; bool changed = false; char got; + char buf[0x600]; + char mad[6]; + + pc.printf("Hello!\r\n"); + + vfd_init(); + wait_ms(1); + + for (i = 'a'; i < 'a' + 25 ; i++){ + vfd_data(i); + } + for (i = 'a'; i < 'a' + 25 ; i++){ + vfd_data(i); + } + for (i = 'a'; i < 'a' + 25 ; i++){ + vfd_data(i); + } + +/* eth.init(); + eth.connect(); + printf("IP Address is %s\n", eth.getIPAddress()); + eth.disconnect();*/ strip.begin(); @@ -89,8 +120,9 @@ if (pc.readable()) { got = pc.getc(); - pc.putc(got); // remote echo - + if (isprint(got)) + pc.putc(got); // remote echo + vfd_data(got); changed = false; if (got == '\n' || got == '\r') { @@ -103,12 +135,21 @@ col = 1; if (t > 16) t = 16; if (b > 16) b = 16; - printf("t: %d b: %d\n", t, b); + printf("t: %d b: %d\r\n", t, b); changed = true; + printf("link: %d\r\n", eth.link()); + if (eth.link()) { + eth.address(mad); + printf("mymac: %02X:%02X:%02X:%02X:%02X:%02X\r\n", + mad[0], mad[1], mad[2], mad[3], mad[4], mad[5]); + } } else if (got == 'b') { state = s_bottom; } else if (got == 't') { state = s_top; + } else if (got == 'e') { + emf_blue(); + strip.show(); } else if (got <= '9' and got >= '0') { tmp += (got - '0') * col; col = col * 10; @@ -121,5 +162,16 @@ bottom_strip(b); strip.show(); } + + int size = eth.receive(); +/* if(size > 0) { + eth.read(buf, size); + printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\r\n", + buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); + printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\r\n", + buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]); + printf("Size: %d\r\n", size); + }*/ + } }