Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of webserverBlinky by
Diff: main.cpp
- Revision:
- 14:c65831c25aaa
- Parent:
- 13:d882b8a042b4
- Child:
- 15:b0154c910143
diff -r d882b8a042b4 -r c65831c25aaa main.cpp --- a/main.cpp Sun Jan 01 02:09:18 2017 +0000 +++ b/main.cpp Sun Jan 01 04:44:30 2017 +0000 @@ -15,7 +15,7 @@ // https://en.wikibooks.org/wiki/Serial_Programming/IP_Over_Serial_Connections Serial pc(USBTX, USBRX); // The USB com port - Set this up as a Dial-Up Modem on your pc -Serial xx(PC_10, PC_11); // debug port - use a second USB serial port to monitor +Serial xx(PC_10, PC_11); // debug port - use an additional USB serial port to monitor this #define debug(x) xx.printf( x ) @@ -58,6 +58,12 @@ __enable_irq(); } +int ledState=0; +void led1Toggle(){ + ledState = ledState? 0 : 1; + led1 = ledState; +} + int pc_readable() // check if buffer has data { return (ppp.rx.head==ppp.rx.tail) ? 0 : 1 ; @@ -76,6 +82,7 @@ void scanForConnectString(); // scan for connect attempts from pc void processFrame(int start, int end) { // process received frame + led1Toggle(); // change led1 state when frames are received if(start==end) { xx.printf("Null Frame c=%d\n",ppp.rx.total); pc.putc(0x7e); return; } crcReset(); char * dest = ppp.pkt.buf; @@ -144,7 +151,6 @@ void ipDefaultHandler(){ debug("IPCP Other\n"); } void IPCPframe() { - led1 = ppp.pkt.buf[5] & 1; // This is the sequence number so the led blinks on packets //ppp.pkt.id = ppp.pkt.buf[5]; // remember the sequence number int code = ppp.pkt.buf[4]; // packet type is here switch (code) { @@ -355,8 +361,8 @@ int main() { - pc.baud(115200); - xx.baud(115200); + pc.baud(115200); // USB virtual serial port + xx.baud(115200); // second serial port for debug messages xx.puts("\x1b[2J\x1b[HReady\n"); // VT100 code for clear screen & home pppInitStruct(); // initialize all the PPP properties @@ -369,12 +375,10 @@ if ( ppp.online==0 ) scanForConnectString(); // try to connect while ( pc_readable() ) { int rx = pc_getBuf(); - wait(0.001); if (frameBusy) { if (rx==FRAME_7E) { frameBusy=0; // done gathering frame frameEndIndex=ppp.rx.tail-1; // remember where frame ends - void processFrame(int start, int end); // process a received frame processFrame(frameStartIndex, frameEndIndex); } }