Lab2_web / Mbed 2 deprecated webserverBlinky

Dependencies:   mbed

Fork of webserverBlinky by RealTimeCompLab2

Revision:
117:c819ae068336
Parent:
116:1272e9f7ad70
Child:
118:54d1936e3768
diff -r 1272e9f7ad70 -r c819ae068336 main.cpp
--- a/main.cpp	Sun Aug 06 17:39:22 2017 +0000
+++ b/main.cpp	Mon Aug 07 15:06:25 2017 +0000
@@ -42,18 +42,18 @@
 // here we define the OPTIONAL, second debug serial port for the various target boards
 // insert your target board's port here if it's not in yet - if it works, please send it to me - thanks!!!
 #ifdef SERIAL_PORT_MONITOR_YES
-    #if defined(TARGET_LPC1768)
-        Serial xx(p9, p10); // Second serial port on LPC1768 - not required to run, if you get compile error here, change #define SERIAL_PORT_MONITOR_YES to #define SERIAL_PORT_MONITOR_NO
-    #elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_L152RE) || defined(TARGET_NUCLEO_L053R8) || defined(TARGET_NUCLEO_L476RG) || defined(TARGET_NUCLEO_F401RE)
-        Serial xx(PC_10, PC_11); // Second serial port on NUCLEO boards - not required to run, if you get compile error here, change #define SERIAL_PORT_MONITOR_YES to #define SERIAL_PORT_MONITOR_NO
-    #elif defined(TARGET_LPC11U24)
-        #error The LPC11U24 does not have a second serial port to use for debugging - change SERIAL_PORT_MONITOR_YES back to SERIAL_PORT_MONITOR_NO
-    #else
-        #error Add your target board's second serial port here if you want to use debugging - or choose SERIAL_PORT_MONITOR_NO
-    #endif
-    #define debug(x...) xx.printf (x) /* if we have a serial port we print debug messages */
+#if defined(TARGET_LPC1768)
+Serial xx(p9, p10); // Second serial port on LPC1768 - not required to run, if you get compile error here, change #define SERIAL_PORT_MONITOR_YES to #define SERIAL_PORT_MONITOR_NO
+#elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_L152RE) || defined(TARGET_NUCLEO_L053R8) || defined(TARGET_NUCLEO_L476RG) || defined(TARGET_NUCLEO_F401RE)
+Serial xx(PC_10, PC_11); // Second serial port on NUCLEO boards - not required to run, if you get compile error here, change #define SERIAL_PORT_MONITOR_YES to #define SERIAL_PORT_MONITOR_NO
+#elif defined(TARGET_LPC11U24)
+#error The LPC11U24 does not have a second serial port to use for debugging - change SERIAL_PORT_MONITOR_YES back to SERIAL_PORT_MONITOR_NO
 #else
-    #define debug(x...) {} /* if we don't have a serial port we do nothing */
+#error Add your target board's second serial port here if you want to use debugging - or choose SERIAL_PORT_MONITOR_NO
+#endif
+#define debug(x...) xx.printf (x) /* if we have a serial port we print debug messages */
+#else
+#define debug(x...) {} /* if we don't have a serial port we do nothing */
 #endif
 
 // verbosity flags used in debug printouts - change to 1 to see increasingly more detailed debug info.
@@ -103,7 +103,7 @@
     int httpPageCount;
     struct {
 #define RXBUFLEN (1<<11)
-        // the serial port receive buffer and packet buffer, size is RXBUFLEN (currently 8192 bytes)
+        // the serial port receive buffer and packet buffer, size is RXBUFLEN (currently 2048 bytes)
         char buf[RXBUFLEN]; // RXBUFLEN MUST be a power of two because we use & operator for fast wrap-around in ring buffer
         int head;
         int tail;
@@ -504,7 +504,7 @@
     unsigned int checksumIP = (headercheck[0]<<8)|headercheck[1];
 #endif
     int identIP = (ident[0]<<8)|ident[1];
-#ifndef DUMP_FULL_IP_ADDRESS
+#ifdef DUMP_FULL_IP_ADDRESS
     xx.printf("IP %d.%d.%d.%d %d.%d.%d.%d ",srcAdr[0],srcAdr[1],srcAdr[2],srcAdr[3], dstAdr[0],dstAdr[1],dstAdr[2],dstAdr[3]); // full ip addresses
 #else
     xx.printf("IP %d %d ",srcAdr[3], dstAdr[3]); // short format - only least significant byte of the ip addresses
@@ -541,7 +541,11 @@
     if (flags & (1<<5)) flagInfo[2]='U';
     if (flags & (1<<6)) flagInfo[1]='E';
     if (flags & (1<<7)) flagInfo[0]='C';
+#ifdef DUMP_IP_SEQUENCE_NUMBER
     xx.printf("%s Seq %10u\n", flagInfo, seq); // tcp flags and the sequence number
+#else    
+    xx.printf("%s\n", flagInfo); // tcp flags only
+#endif    
     if( (flags == (1<<4)) && outGoing ) // if this is a pure ack its probably then of the TCP link
         xx.putc('\n'); // so insert an extra line to mark the end of the conversation
 #endif
@@ -699,7 +703,7 @@
             break;
         case TCP_FLAG_ACK | TCP_FLAG_PSH:
             if ( strncmp(tcpDataIn, "GET /", 5) == 0) { // check for an http GET command
-                flagsOut = TCP_FLAG_ACK | TCP_FLAG_FIN; // set the FIN flag to start closing this TCP connection
+                flagsOut = TCP_FLAG_ACK | TCP_FLAG_FIN; // set outgoing FIN flag to ask them to close from their side
                 dataLen = httpResponse(tcpDataOut); // send an http response
             } else {
                 dataLen = tcpResponse(tcpDataOut,tcpDataSize); // not a web request, send a packet reporting number of received bytes
@@ -708,7 +712,7 @@
         case TCP_FLAG_FIN:
         case TCP_FLAG_FIN | TCP_FLAG_ACK:
         case TCP_FLAG_FIN | TCP_FLAG_PSH | TCP_FLAG_ACK:
-            flagsOut = TCP_FLAG_ACK | TCP_FLAG_FIN; // set the FIN flag to start closing the connection
+            flagsOut = TCP_FLAG_ACK | TCP_FLAG_FIN; // set outgoing FIN flag to ask them to close from their side
             ack_out++; // for FIN flag we always have to increase sequence by 1
             break;
         default:
@@ -776,7 +780,7 @@
     memcpy( tcp-12, tempHold, 12); // restore the 12 bytes that the pseudo-header overwrote
     dumpHeaderIP(1); // dump outgoing IP header
     dumpHeaderTCP(1); // dump outgoing TCP header
-    wait_ms(8); // wait long enoug to get 90 characters printed at 115200 bps
+    wait_ms(20); // wait long enough to ensure we will be given time to dump the headers if we wanted to
     send_pppFrame(); // All preparation complete - send the TCP response
 }
 
@@ -981,6 +985,7 @@
 
 
 
+
 int main()
 {
     pc.baud(115200); // USB virtual serial port