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:
- 0:2cf4880c312a
- Child:
- 1:9e03798d4367
diff -r 000000000000 -r 2cf4880c312a main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Dec 27 16:42:24 2016 +0000 @@ -0,0 +1,57 @@ +#include "mbed.h" + +// Proof-of-concept for TCP/IP using Windows 7/8/10 Dial Up Networking over MBED USB Virtual COM Port + +// Toggles LED1 every time the PC tries to establish a Dial-up Networking Connection + +Serial pc(USBTX, USBRX); // The USB com port - Set this up as a Dial-Up Modem + +DigitalOut myled(LED1); + +#define BUFLEN (1<<12) +char rxbuf[BUFLEN]; + +int headPointer = 0; // head of receive buffer +int tailPointer = 0; // tail of receive buffer + +void rxHandler() // serial port receive interrupt handler +{ + rxbuf[headPointer]=pc.getc(); // insert in buffer + __disable_irq(); + headPointer=(headPointer+1)&(BUFLEN-1); + __enable_irq(); +} + +int pc_readable() // check if buffer has data +{ + return (headPointer==tailPointer) ? 0 : 1 ; +} + +int pc_getBuf() // get one character from the buffer +{ + if (pc_readable()) { + int x = rxbuf[tailPointer]; + tailPointer=(tailPointer+1)&(BUFLEN-1); + return x; + } + return -1; +} + +int main() +{ + pc.baud(115200); + pc.attach(&rxHandler,Serial::RxIrq); // activate the receive interrupt handler + int waitingForPpp = 1; // client string not found yet + while(1) { + while ( pc_readable() ) { + pc_getBuf(); // for now just flush input + 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 + } + } +}