Lab2_web / Mbed 2 deprecated webserverBlinky

Dependencies:   mbed

Fork of webserverBlinky by RealTimeCompLab2

Revision:
72:ad3d12753acf
Parent:
71:965619fedb3a
Child:
73:2f56ec87dbe9
diff -r 965619fedb3a -r ad3d12753acf main.cpp
--- a/main.cpp	Thu Jun 08 15:45:40 2017 +0000
+++ b/main.cpp	Sat Jun 17 20:25:39 2017 +0000
@@ -3,7 +3,7 @@
 // Copyright 2016 Nicolas Nackel aka Nixnax. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 // PPP-Blinky - "My Internet Of Thing"
-// A Tiny Webserver Using Windows XP/7/8/10 Networking Over A Serial Port.
+// A Tiny Webserver Using Windows XP/7/8/10 Dial-Up Networking Over A Serial Port.
 
 // Also receives UDP packets and responds to ping (ICMP Echo requests)
 
@@ -44,7 +44,7 @@
 #define v1 1
 
 // this is the webpage we serve when we get an HTTP request
-// keep size under 900 bytes to fit in a single frame
+// keep size under 900 bytes to fit into a single frame
 const static char ourWebPage[] = "\
 <!DOCTYPE html>\
 <html>\
@@ -65,7 +65,10 @@
 
 
 
-// The serial port on your mbed hardware. Your PC should view this as a standard dial-up networking modem. See instructions at the top.
+// The serial port on your mbed hardware. Your PC should view this as a standard dial-up networking modem.
+// The modem type on windows should be selected as "Direct communication between two computers"
+// The modem baud rate should be set to 115200 baud
+// See instructions at the top.
 // On a typical mbed hardware platform this is a USB virtual com port (VCP)
 Serial pc(USBTX, USBRX); // usb virtual com port
 
@@ -75,9 +78,6 @@
 #define FRAME_7E (0x7e)
 
 // the serial port receive buffer and packet buffer
-#define BUFLEN (1<<13)
-char rxbufppp[BUFLEN]; // BUFLEN MUST be a power of two because we use & operator for fast wrap-around in rxHandler
-char hdlcBuffer[3000]; // send and receive buffer for unstuffed (decoded) hdlc frames
 
 // a structure to keep all our ppp globals in
 struct pppType {
@@ -87,14 +87,17 @@
     int crc; // for calculating IP and TCP CRCs
     int ledState; // state of LED1
     struct {
-        char * buf;
+#define BUFLEN (1<<13)
+        char buf[BUFLEN]; // BUFLEN MUST be a power of two because we use & operator for fast wrap-around in rxHandler
+        //char * buf;
         volatile int head;
         volatile int tail;
     } rx; // serial port objects
     struct {
         int len; // number of bytes in buffer
         int crc; // PPP CRC (frame check)
-        char * buf; // the actual buffer
+        //char * buf; // the actual buffer
+        char buf[3300]; // send and receive buffer large enough for unstuffed (decoded) hdlc frames
     } pkt; // ppp buffer objects
     struct {
         int frameStartIndex; // frame start marker
@@ -109,10 +112,10 @@
 void pppInitStruct()
 {
     ppp.online=0;
-    ppp.rx.buf=rxbufppp;
+    //ppp.rx.buf=rxbufppp;
     ppp.rx.tail=0;
     ppp.rx.head=0;
-    ppp.pkt.buf=hdlcBuffer;
+    //ppp.pkt.buf=hdlcBuffer;
     ppp.pkt.len=0;
     ppp.ident=0;
     ppp.seq=1000;
@@ -177,7 +180,6 @@
 {
     led1Toggle(); // change led1 state on every frame we receive
     if(start==end) {
-        pc.putc(0x7e);
         return;
     }
     crcReset();
@@ -187,18 +189,18 @@
     int idx = start;
     while(1) {
         if (unstuff==0) {
-            if (rxbufppp[idx]==0x7d) unstuff=1;
+            if (ppp.rx.buf[idx]==0x7d) unstuff=1;
             else {
-                *dest = rxbufppp[idx];
+                *dest = ppp.rx.buf[idx];
                 ppp.pkt.len++;
                 dest++;
-                crcDo(rxbufppp[idx]);
+                crcDo(ppp.rx.buf[idx]);
             }
         } else { // unstuff characters prefixed with 0x7d
-            *dest = rxbufppp[idx]^0x20;
+            *dest = ppp.rx.buf[idx]^0x20;
             ppp.pkt.len++;
             dest++;
-            crcDo(rxbufppp[idx]^0x20);
+            crcDo(ppp.rx.buf[idx]^0x20);
             unstuff=0;
         }
         idx = (idx+1) & (BUFLEN-1);
@@ -901,6 +903,7 @@
                     ppp.hdlc.frameEndIndex=ppp.rx.tail-1; // remember where frame ends
                 }
                 processHDLCFrame(ppp.hdlc.frameStartIndex, ppp.hdlc.frameEndIndex);
+                ppp.hdlc.frameStartIndex = ppp.hdlc.frameEndIndex;
             }
         } else {
             if (rx==FRAME_7E) {
@@ -915,7 +918,7 @@
 {
     if ( ppp.online==0 ) {
         // look for Windows Dialup Networking "Direct Connection Between Two Computers" expected connect string
-        char * clientFound = strstr( (char *)rxbufppp, "CLIENTCLIENT" ); 
+        char * clientFound = strstr( (char *)ppp.rx.buf, "CLIENTCLIENT" ); 
         if( clientFound ) {
             strcpy( clientFound, "FOUND!FOUND!" ); // overwrite so we don't find it again
             // respond with Windows Dialup networking expected "Direct Connection Between Two Computers" response string