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
main.cpp@0:2cf4880c312a, 2016-12-27 (annotated)
- Committer:
- nixnax
- Date:
- Tue Dec 27 16:42:24 2016 +0000
- Revision:
- 0:2cf4880c312a
- Child:
- 1:9e03798d4367
PPP-Blinky flash LED1 when a Dial-up Connection is made
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nixnax | 0:2cf4880c312a | 1 | #include "mbed.h" |
nixnax | 0:2cf4880c312a | 2 | |
nixnax | 0:2cf4880c312a | 3 | // Proof-of-concept for TCP/IP using Windows 7/8/10 Dial Up Networking over MBED USB Virtual COM Port |
nixnax | 0:2cf4880c312a | 4 | |
nixnax | 0:2cf4880c312a | 5 | // Toggles LED1 every time the PC tries to establish a Dial-up Networking Connection |
nixnax | 0:2cf4880c312a | 6 | |
nixnax | 0:2cf4880c312a | 7 | Serial pc(USBTX, USBRX); // The USB com port - Set this up as a Dial-Up Modem |
nixnax | 0:2cf4880c312a | 8 | |
nixnax | 0:2cf4880c312a | 9 | DigitalOut myled(LED1); |
nixnax | 0:2cf4880c312a | 10 | |
nixnax | 0:2cf4880c312a | 11 | #define BUFLEN (1<<12) |
nixnax | 0:2cf4880c312a | 12 | char rxbuf[BUFLEN]; |
nixnax | 0:2cf4880c312a | 13 | |
nixnax | 0:2cf4880c312a | 14 | int headPointer = 0; // head of receive buffer |
nixnax | 0:2cf4880c312a | 15 | int tailPointer = 0; // tail of receive buffer |
nixnax | 0:2cf4880c312a | 16 | |
nixnax | 0:2cf4880c312a | 17 | void rxHandler() // serial port receive interrupt handler |
nixnax | 0:2cf4880c312a | 18 | { |
nixnax | 0:2cf4880c312a | 19 | rxbuf[headPointer]=pc.getc(); // insert in buffer |
nixnax | 0:2cf4880c312a | 20 | __disable_irq(); |
nixnax | 0:2cf4880c312a | 21 | headPointer=(headPointer+1)&(BUFLEN-1); |
nixnax | 0:2cf4880c312a | 22 | __enable_irq(); |
nixnax | 0:2cf4880c312a | 23 | } |
nixnax | 0:2cf4880c312a | 24 | |
nixnax | 0:2cf4880c312a | 25 | int pc_readable() // check if buffer has data |
nixnax | 0:2cf4880c312a | 26 | { |
nixnax | 0:2cf4880c312a | 27 | return (headPointer==tailPointer) ? 0 : 1 ; |
nixnax | 0:2cf4880c312a | 28 | } |
nixnax | 0:2cf4880c312a | 29 | |
nixnax | 0:2cf4880c312a | 30 | int pc_getBuf() // get one character from the buffer |
nixnax | 0:2cf4880c312a | 31 | { |
nixnax | 0:2cf4880c312a | 32 | if (pc_readable()) { |
nixnax | 0:2cf4880c312a | 33 | int x = rxbuf[tailPointer]; |
nixnax | 0:2cf4880c312a | 34 | tailPointer=(tailPointer+1)&(BUFLEN-1); |
nixnax | 0:2cf4880c312a | 35 | return x; |
nixnax | 0:2cf4880c312a | 36 | } |
nixnax | 0:2cf4880c312a | 37 | return -1; |
nixnax | 0:2cf4880c312a | 38 | } |
nixnax | 0:2cf4880c312a | 39 | |
nixnax | 0:2cf4880c312a | 40 | int main() |
nixnax | 0:2cf4880c312a | 41 | { |
nixnax | 0:2cf4880c312a | 42 | pc.baud(115200); |
nixnax | 0:2cf4880c312a | 43 | pc.attach(&rxHandler,Serial::RxIrq); // activate the receive interrupt handler |
nixnax | 0:2cf4880c312a | 44 | int waitingForPpp = 1; // client string not found yet |
nixnax | 0:2cf4880c312a | 45 | while(1) { |
nixnax | 0:2cf4880c312a | 46 | while ( pc_readable() ) { |
nixnax | 0:2cf4880c312a | 47 | pc_getBuf(); // for now just flush input |
nixnax | 0:2cf4880c312a | 48 | char * clientFound = strstr( rxbuf, "CLIENTCLIENT" ); // look for string |
nixnax | 0:2cf4880c312a | 49 | if( clientFound ) { |
nixnax | 0:2cf4880c312a | 50 | strcpy( clientFound, "FOUND!FOUND!" ); // overwrite found string |
nixnax | 0:2cf4880c312a | 51 | if (waitingForPpp) pc.printf("CLIENTSERVER"); // respond to PC |
nixnax | 0:2cf4880c312a | 52 | waitingForPpp = waitingForPpp ? 0 : 1; // TOGGLE waiting flag |
nixnax | 0:2cf4880c312a | 53 | } |
nixnax | 0:2cf4880c312a | 54 | myled = waitingForPpp ? 1 : 0; // display found status on led |
nixnax | 0:2cf4880c312a | 55 | } |
nixnax | 0:2cf4880c312a | 56 | } |
nixnax | 0:2cf4880c312a | 57 | } |