Lab2_web / Mbed 2 deprecated webserverBlinky

Dependencies:   mbed

Fork of webserverBlinky by RealTimeCompLab2

Committer:
nixnax
Date:
Tue Dec 27 18:38:49 2016 +0000
Revision:
3:bcc66de0bdcd
Parent:
2:b6ccdc962742
Child:
4:a469050d5b80
Remove unneeded flag

Who changed what in which revision?

UserRevisionLine numberNew 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 1:9e03798d4367 40 // ppp frame start/end flag
nixnax 1:9e03798d4367 41 #define FRAME_START_END 0x7e
nixnax 1:9e03798d4367 42
nixnax 0:2cf4880c312a 43 int main()
nixnax 0:2cf4880c312a 44 {
nixnax 0:2cf4880c312a 45 pc.baud(115200);
nixnax 0:2cf4880c312a 46 pc.attach(&rxHandler,Serial::RxIrq); // activate the receive interrupt handler
nixnax 1:9e03798d4367 47 int flagCount=0;
nixnax 0:2cf4880c312a 48 while(1) {
nixnax 0:2cf4880c312a 49 while ( pc_readable() ) {
nixnax 1:9e03798d4367 50 int rx = pc_getBuf();
nixnax 1:9e03798d4367 51 if (rx == FRAME_START_END) flagCount++;
nixnax 0:2cf4880c312a 52 char * clientFound = strstr( rxbuf, "CLIENTCLIENT" ); // look for string
nixnax 0:2cf4880c312a 53 if( clientFound ) {
nixnax 0:2cf4880c312a 54 strcpy( clientFound, "FOUND!FOUND!" ); // overwrite found string
nixnax 3:bcc66de0bdcd 55 pc.printf("CLIENTSERVER"); // respond to PC
nixnax 0:2cf4880c312a 56 }
nixnax 2:b6ccdc962742 57 if ( flagCount>0 ) myled = ((flagCount/2)%2); // toggle on PPP frame found
nixnax 0:2cf4880c312a 58 }
nixnax 0:2cf4880c312a 59 }
nixnax 0:2cf4880c312a 60 }