Lab2_web / Mbed 2 deprecated webserverBlinky

Dependencies:   mbed

Fork of webserverBlinky by RealTimeCompLab2

Revision:
107:5fe806713d49
Parent:
106:d14e6b597ca3
Child:
108:f77ec4605945
--- a/main.cpp	Thu Aug 03 11:14:28 2017 +0000
+++ b/main.cpp	Thu Aug 03 21:09:50 2017 +0000
@@ -169,13 +169,21 @@
 // fill our own receive buffer with characters from the PPP serial port
 void fillbuf()
 {
+    char ch;
     if ( pc.readable() ) {
         int hd = (ppp.rx.head+1)&(RXBUFLEN-1); // increment/wrap head index
         if ( hd == ppp.rx.rtail ) {
             debug("\nReceive buffer full\n");
             return;
         }
-        ppp.rx.buf[ppp.rx.head]=pc.getc(); // insert in rx buffer
+        ch = pc.getc(); // read new character
+        ppp.rx.buf[ppp.rx.head] = ch; // insert in our receive buffer
+        if ( ppp.online == 0 ) {
+            if (ch == 0x7E) {
+                ppp.online = 1;
+                debug("HDLC Frame (0x7E)\n");
+            }                
+        }            
         ppp.rx.head = hd; // update head pointer
         ppp.rx.buflevel++;
     }
@@ -263,8 +271,7 @@
     pc.putc(0x7e); // hdlc start-of-frame "flag"
     for(int i=0; i<ppp.pkt.len; i++) {
         hdlcPut( ppp.pkt.buf[i] ); // send a character
-
-        if((i&0x7f)==0) fillbuf(); // handle received characters very every 128 sent
+        if((i&0x7f)==0) fillbuf(); // handle received characters every 128 sent
     }
     pc.putc(0x7e); // hdlc end-of-frame "flag"
 }
@@ -275,7 +282,7 @@
     ppp.pkt.buf[4]=2; // change code to ack
     send_pppFrame(); // acknowledge everything they ask for - assume it's an IP address
 
-    debug("Our IPCP Ask\n");
+    debug("Our IPCP Ask (no options)\n");
     ppp.pkt.buf[4]=1; // change code to request
     ppp.pkt.buf[7]=4; // no options in this request
     ppp.pkt.len=10; // no options in this request shortest ipcp packet possible (4 ppp + 4 ipcp + 2 crc)
@@ -287,16 +294,10 @@
     debug("Their IPCP Grant\n");
 }
 
-
-
-
-
-
-
 void ipcpNackHandler()
 {
     debug("Their IPCP Nack, Our ACK\n");
-    if (ppp.pkt.buf[8]=3) { // check if the NACK contains an IP address parameter
+    if (ppp.pkt.buf[8]==3) { // check if the NACK contains an IP address parameter
         ppp.pkt.buf[4]=1; // assume the NACK contains our "suggested" IP address
         send_pppFrame(); // let's request this IP address as ours
     } // if it's not an IP nack we ignore it
@@ -949,7 +950,9 @@
             int rx = pc_getBuf(); // get the character
             if (rx==FRAME_7E) {
                 ppp.hdlc.frameEndIndex=oldTail; // mark the frame end character
+                
                 processHDLCFrame(ppp.hdlc.frameStartIndex, ppp.hdlc.frameEndIndex); // process the frame
+                
                 ppp.rx.rtail = ppp.rx.tail;
                 ppp.hdlc.frameStartIndex = ppp.rx.tail; // where next frame will start
                 break;
@@ -964,24 +967,21 @@
         fillbuf();
         // search for Windows Dialup Networking "Direct Connection Between Two Computers" expected connect string
         char * found1 = strstr( (char *)ppp.rx.buf, "CLIENT" );
-        // also search for HDLC frame start character 0x7e
-        void * found2 = memchr( (char *)ppp.rx.buf, 0x7e, RXBUFLEN );
-        if( (found1 != NULL) | (found2 != NULL) ) {
-            if (found1 != NULL) {
-                // respond with Windows Dialup networking expected "Direct Connection Between Two Computers" response string
-                led1Toggle();
-                pc.puts("CLIENTSERVER");
-                if (v0) debug("Found connect string \"CLIENT\"\n");
-            }
-            if (found2 != NULL) {
-                if (v0) debug("Found HDLC frame start (7E)\n");
-            }
-            ppp.online=1; // we are connected, so stop looking for the string
+        if (found1 != NULL) {
+            // respond with Windows Dialup networking expected "Direct Connection Between Two Computers" response string
+            led1Toggle();
+            if (v0) debug("Found connect string \"CLIENT\", sent \"CLIENTSERVER\"\n");
+            pc.puts("CLIENTSERVER");
+            ppp.online=1; // we are connected, so we can stop looking for the connect string
         }
     }
 }
 
 
+
+
+
+
 int main()
 {
     pc.baud(115200); // USB virtual serial port