RealtimeCompLab2

Dependencies:   mbed

Fork of PPP-Blinky by Nicolas Nackel

Revision:
47:00a5ca075f8f
Parent:
46:d73a565eaf7c
Child:
48:6352c1411c5f
--- a/main.cpp	Wed Jan 18 21:00:13 2017 +0000
+++ b/main.cpp	Thu Jan 19 20:28:54 2017 +0000
@@ -28,7 +28,7 @@
 
 // The #define below enables/disables a second serial port that prints out interesting diagnostic messages.
 // change to SERIAL_PORT_MONITOR_YES to enable diagnistics messages. You will also need a second serial port.
-#define SERIAL_PORT_MONITOR_NO /* or SERIAL_PORT_MONITOR_YES */
+#define SERIAL_PORT_MONITOR_YES /* or SERIAL_PORT_MONITOR_YES */
 
 #ifndef SERIAL_PORT_MONITOR_NO
 Serial xx(PC_10, PC_11); // Not necessary to run - if you have a compile error here change line 31 to SERIAL_PORT_MONITOR_NO
@@ -546,14 +546,14 @@
             int contentLengthStart = n; // remember where Content-Length is in buffer
             n=n+sprintf(n+dataStart,"?????\r\n"); // leave five spaces for content length - will be updated later
             n=n+sprintf(n+dataStart,"Content-Type: text/html; charset=us-ascii\r\n\r\n"); // http header must end with empty line (\r\n)
-            int nHeader=n; // byte total of all headers
+            int nHeader=n; // byte total of all headers. Note - seems like this must be 1+(multiple of four)
 
             n=n+sprintf(n+dataStart,"<!DOCTYPE html>\n<html><head><title>mbed-PPP-Blinky</title>\n<script>window.onload=function()"); // html start
             n=n+sprintf(n+dataStart,"{setInterval(function(){function x(){return document.getElementById('w');};\n"); // html
             n=n+sprintf(n+dataStart,"x().textContent = parseInt(x().textContent)+1;},100);};</script></head>\n"); // html 
             n=n+sprintf(n+dataStart,"<body style=\"font-family: sans-serif; font-size:30px; color:#807070\">"); // html
             n=n+sprintf(n+dataStart,"<h1>mbed PPP-Blinky Up and Running</h1>\n<h1 id=\"w\" style=\"text-align:"); // html
-            n=n+sprintf(n+dataStart," center;\">0</h1><h1><a href=\"http://bit.ly/pppBlink2\">Source on mbed</a></h1>\n</body></html>\n"); // html end
+            n=n+sprintf(n+dataStart," center;\">0</h1><h1><a href=\"http://bit.ly/pppBlink2\">Source on mbed</a></h1>\n</body></html>\r\n"); // html end
             
             int contentLength = n-nHeader; // Content-Length is the count of every character after the header
             int cSize = 5; // maximum number of digits we allow for Content-Length
@@ -574,12 +574,12 @@
             n=n+sprintf(n+dataStart,"Content-Length: "); // http header
             int contentLengthStart = n; // remember where Content-Length is in buffer
             n=n+sprintf(n+dataStart,"?????\r\n"); // leave five spaces for content length - will be updated later
-            n=n+sprintf(n+dataStart,"Content-Type: text/html; charset=us-ascii\r\n\r\n"); // http header must end with empty line (\r\n)
-            int nHeader=n; // byte total of all headers
+            n=n+sprintf(n+dataStart,"Content-Type: text/html;  charset=us-ascii\r\n\r\n"); // http header must end with empty line (\r\n)
+            int nHeader=n; // byte total of all headers. Note - seems like this must be 1+(multiple of four)
 
             n=n+sprintf(n+dataStart,"<!DOCTYPE html><html><head></head>"); // html start
             n=n+sprintf(n+dataStart,"<body><h1>File Not Found</h1></body>");
-            n=n+sprintf(n+dataStart,"</html>\n"); // html end
+            n=n+sprintf(n+dataStart,"</html>\r\n"); // html end
 
             int contentLength = n-nHeader; // Content-Length is the count of every character after the header
             int cSize = 5; // maximum number of digits we allow for Content-Length
@@ -678,6 +678,7 @@
         debug("TCP %d ipHeader %d tcpHeader %d Data %d\n", ipPktLen, ipHeaderLen, headerSizeTCP, dataLen);    // 1 for more verbose
     }
     if (dataLen > 0) {
+        ppp.pkt.buf[4+ipHeaderLen+headerSizeTCP+dataLen]=0; // insert a null after the data so debug printf stops printing after the data
         debug("%s\n",ppp.pkt.buf+4+ipHeaderLen+headerSizeTCP);    // show the data
     }
 }