Lab2_web / Mbed 2 deprecated webserverBlinky

Dependencies:   mbed

Fork of webserverBlinky by RealTimeCompLab2

Revision:
141:4cc1518ee06f
Parent:
140:f526e9ecfebb
Child:
142:54d1543e23e5
--- a/main.cpp	Wed Aug 23 21:54:47 2017 +0000
+++ b/main.cpp	Mon Aug 28 15:36:09 2017 +0000
@@ -13,7 +13,6 @@
 // Handy reading material
 // https://technet.microsoft.com/en-us/library/cc957992.aspx
 // https://en.wikibooks.org/wiki/Serial_Programming/IP_Over_Serial_Connections
-// http://bit.ly/dialup777error - how to solve Dial Up Error 777 in Windows 7/8/10
 // http://atari.kensclassics.org/wcomlog.htm
 
 // Handy tools
@@ -46,12 +45,11 @@
 
 // The #define below enables/disables a second (OPTIONAL) serial port that prints out interesting diagnostic messages.
 // Change to SERIAL_PORT_MONITOR_YES to enable diagnostics messages. You need to wire a second serial port to your mbed hardware to monitor this.
+// Using the second serial port will slow down packet response time
 // Note - the LPC11U24 does NOT have a second serial port
 #define SERIAL_PORT_MONITOR_NO /* change to SERIAL_PORT_MONITOR_YES for debug messages */
 
-// 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!!!
-// note - if you enable this, some packets may initially be missed which will cause some retransmits
+// here we define the OPTIONAL, second debug serial port for various mbed target boards
 #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
@@ -62,9 +60,10 @@
 #elif defined (TARGET_KL46Z) || (TARGET_KL25Z)
 Serial xx(PTE0,PTE1); // Second serial port on FRDM-KL46Z board
 #elif defined(YOUR_TARGET_BOARD_NAME_HERE)
-Serial xx(p9, p10); // insert your board's debug serial port pins here - and please send it to me if it works
+// change the next line to YOUR target board's second serial port pin definition if it's not present - and if it works, please send it to me - thanks!!!
+Serial xx(p9, p10); // change this to YOUR board second serial port pin definition - and please send it to me if it works!!!
 #else
-#error Add your target board's second serial port here if you want to use debugging - or choose SERIAL_PORT_MONITOR_NO
+#error Add your target board's second serial port here if you want to use debugging - or simply change SERIAL_PORT_MONITOR_YES to SERIAL_PORT_MONITOR_NO
 #endif
 #define debugPrintf(x...) xx.printf (x) /* if we have a serial port we print debug messages */
 #define debugPutc(x...) xx.putc(x)
@@ -190,8 +189,9 @@
 };
 
 pppType ppp; // our global - definitely not thread safe
-
+///
 // Initialize our global structure, clear the buffer, etc.
+///
 void pppInitStruct()
 {
     memset( ppp.rx.buf, 0, RXBUFLEN);
@@ -208,6 +208,9 @@
     ppp.firstFrame=1;
 }
 
+///
+// Toggle the LED on every second PPP packet received
+///
 void led1Toggle()
 {
     led1 = (ppp.ledState >> 1) & 1; // use second bit, in other words toggle LED only every second packet
@@ -215,7 +218,9 @@
 
 }
 
+///
 // fill our own receive buffer with characters from the PPP serial port
+///
 void fillbuf()
 {
     char ch;
@@ -237,7 +242,9 @@
     }
 }
 
+///
 // print to debug port while checking for incoming characters
+///
 void putcWhileCheckingInput( char outByte )
 {
 #ifdef SERIAL_PORT_MONITOR_YES
@@ -247,6 +254,9 @@
 #endif
 }
 
+///
+// puts to debug port while checking the PPP input stream
+///
 void putsWhileCheckingInput( char * data )
 {
 #ifdef SERIAL_PORT_MONITOR_YES
@@ -258,17 +268,25 @@
 #endif
 }
 
+///
 // a sniffer tool to assist in figuring out where in the code we are having characters in the input buffer
+///
 void qq()
 {
     if ( pc.readable() ) putsWhileCheckingInput( "Character available!\n" );
 }
 
+///
+// Initialize the PPP CRC total
+///
 void crcReset()
 {
     ppp.crc=0xffff;   // crc restart
 }
 
+///
+// calculate the PPP CRC
+///
 void crcDo(int x) // cumulative crc
 {
     for (int i=0; i<8; i++) {
@@ -278,6 +296,9 @@
     fillbuf(); // handle input
 }
 
+//
+/// calculate the PPP CRC on an entire block of memory
+//
 int crcBuf(char * buf, int size) // crc on an entire block of memory
 {
     crcReset();
@@ -285,7 +306,10 @@
     return ppp.crc;
 }
 
-int pc_getBuf()   // get one character from the buffer
+///
+// Get one character from our received PPP buffer
+///
+int pc_getBuf()
 {
     int x = ppp.rx.buf[ ppp.rx.tail ];
     ppp.rx.tail=(ppp.rx.tail+1)&(RXBUFLEN-1);
@@ -293,9 +317,12 @@
     return x;
 }
 
+///
+// Dump a PPP frame to the debug serial port
 // Note - the hex output of dumpPPPFrame() can be imported into WireShark
 // Capture the frame's hex output in your terminal program and save as a text file
 // In WireShark, use "Import Hex File". Options are: Offset=None, Protocol=PPP.
+///
 void dumpPPPFrame()
 {
     char pbuf[30];
@@ -311,7 +338,10 @@
     putsWhileCheckingInput(pbuf);
 }
 
-void processPPPFrame(int start, int end)   // process received frame
+///
+// Process a received PPP frame
+///
+void processPPPFrame(int start, int end)
 {
     led1Toggle(); // change led1 state on every frame we receive
     if(start==end) {
@@ -1130,7 +1160,7 @@
     }
 }
 
-void wait_for_PPP_frame() // scan the PPP serial input stream for frame start markers
+void waitForPppFrame() // scan the PPP serial input stream for frame start markers
 {
     while(1) {
         fillbuf(); // handle received characters
@@ -1180,7 +1210,7 @@
     while(1) {
         scanForConnectString(); // wait for connect from PC dial-up networking
         while(ppp.online) {
-            wait_for_PPP_frame(); // wait for a PPP frame
+            waitForPppFrame(); // wait for a PPP frame
         }
     }
 }
\ No newline at end of file