RealtimeCompLab2
Dependencies: mbed
Fork of PPP-Blinky by
Diff: main.cpp
- Revision:
- 1:9e03798d4367
- Parent:
- 0:2cf4880c312a
- Child:
- 2:b6ccdc962742
--- a/main.cpp Tue Dec 27 16:42:24 2016 +0000 +++ b/main.cpp Tue Dec 27 17:45:57 2016 +0000 @@ -37,21 +37,26 @@ return -1; } +// ppp frame start/end flag +#define FRAME_START_END 0x7e + int main() { pc.baud(115200); pc.attach(&rxHandler,Serial::RxIrq); // activate the receive interrupt handler int waitingForPpp = 1; // client string not found yet + int flagCount=0; while(1) { while ( pc_readable() ) { - pc_getBuf(); // for now just flush input + int rx = pc_getBuf(); + if (rx == FRAME_START_END) flagCount++; char * clientFound = strstr( rxbuf, "CLIENTCLIENT" ); // look for string if( clientFound ) { strcpy( clientFound, "FOUND!FOUND!" ); // overwrite found string if (waitingForPpp) pc.printf("CLIENTSERVER"); // respond to PC waitingForPpp = waitingForPpp ? 0 : 1; // TOGGLE waiting flag } - myled = waitingForPpp ? 1 : 0; // display found status on led + if ( flagCount>0 ) myled = ((flagCount/2)%2); // toggle on PPP frame detect } } }