Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of webserverBlinky by
Diff: main.cpp
- Revision:
- 120:bef89e4c906e
- Parent:
- 119:e14dd2bf0ea3
- Child:
- 121:705679672685
diff -r e14dd2bf0ea3 -r bef89e4c906e main.cpp --- a/main.cpp Tue Aug 08 17:10:29 2017 +0000 +++ b/main.cpp Tue Aug 08 18:36:38 2017 +0000 @@ -37,7 +37,7 @@ // 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. // Note - the LPC11U24 does NOT have a second serial port -#define SERIAL_PORT_MONITOR_YES /* change to SERIAL_PORT_MONITOR_YES for debug messages */ +#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!!! @@ -65,7 +65,7 @@ // verbosity flags used in debug printouts - change to 1 to see increasingly more detailed debug info. #define v0 1 -#define v1 0 +#define v1 1 #define v2 0 #define IP_HEADER_DUMP_YES /* YES for ip header dump */ #define TCP_HEADER_DUMP_YES /* YES for tcp header dump */ @@ -173,7 +173,6 @@ if ( ppp.online == 0 ) { if (ch == 0x7E) { ppp.online = 1; - debugPrintf("HDLC Frame (0x7E)\n"); } } ppp.rx.head = hd; // update head pointer @@ -242,8 +241,17 @@ // In WireShark, use "Import Hex File". Options are: Offset=None, Protocol=PPP. void dumpPPPFrame() { - for(int i=0; i<ppp.pkt.len; i++) debugPrintf("%02x ", ppp.pkt.buf[i]); - debugPrintf(" CRC=%04x Len=%d\n", ppp.pkt.crc, ppp.pkt.len); + char pbuf[30]; + for(int i=0; i<ppp.pkt.len; i++) { + fillbuf(); + sprintf(pbuf, "%02x ", ppp.pkt.buf[i]); + fillbuf(); + printWhileCheckingInput(pbuf); + } + fillbuf(); + sprintf(pbuf, " CRC=%04x Len=%d\n", ppp.pkt.crc, ppp.pkt.len); + fillbuf(); + printWhileCheckingInput(pbuf); } void processPPPFrame(int start, int end) // process received frame @@ -277,15 +285,18 @@ if (idx == end) break; } ppp.pkt.crc = ppp.crc & 0xffff; + if(0) dumpPPPFrame(); // set to 1 to dump ALL ppp frames if (ppp.pkt.crc == 0xf0b8) { // check for good CRC void determinePacketType(); // declaration only determinePacketType(); } else { - if (1) { + if (0) { // set to 1 to report FCS errors char pbuf[50]; // local print buffer + fillbuf(); sprintf(pbuf, "PPP FCS(crc) Error CRC=%x Length = %d\n",ppp.pkt.crc,ppp.pkt.len); // print a debug line + fillbuf(); printWhileCheckingInput( pbuf ); - if(0) dumpPPPFrame(); + if(0) dumpPPPFrame(); // set to 1 to dump frames with errors in them } } } @@ -605,7 +616,6 @@ if( outGoing && ( flags == 0x11 ) ) { // ACK/FIN - if this is an outgoing ACK/FIN its the end of a tcp conversation putcWhileCheckingInput('\n'); // insert an extra new line to mark the end of an HTTP the conversation } - if( pc.readable()) printWhileCheckingInput( "Char2\n"); #endif } @@ -669,7 +679,7 @@ memcpy(dataStart+contentLengthStart, contentLengthString, CONTENTLENGTHSIZE); // copy Content-Length to it's place in the send buffer if (v2) { - debugPrintf("HTTP Response: HTTP-header %d HTTP-content %d HTTP-total %d\n",nHeader,n-nHeader,n); + // debugPrintf("HTTP Response: HTTP-header %d HTTP-content %d HTTP-total %d\n",nHeader,n-nHeader,n); } return n; // total byte size of our response } @@ -682,7 +692,7 @@ n=n+sprintf(n+dataStart,"Got %04d bytes.\n",len); // report the number of bytes received while( (n%4)!= 0) n=n+sprintf(n+dataStart,"*"); // insert spaces until n is exactly two away from a multiple of four if (v2) { - debugPrintf("TCP response %d bytes\n",n); + // debugPrintf("TCP response %d bytes\n",n); } return n; // total byte size of our response } @@ -838,7 +848,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 - for (int i=0; i<35000/50; i++) { // a 35 ms delay before sending frame + for (int i=0; i<60000/50; i++) { // a 60 ms delay before sending frame - typical internet delay time fillbuf(); // catch any incoming characters wait_us(50); // wait less than 1 character duration at 115200 } @@ -852,11 +862,16 @@ int headerSizeTCP = ((ppp.pkt.buf[4+ipHeaderLen+12]>>4)&0xf)*4;; // length of tcp header int dataLen = ipPktLen - ipHeaderLen - headerSizeTCP; // data is what's left after the two headers if (v1) { - debugPrintf("TCP %d ipHeader %d tcpHeader %d Data %d\n", ipPktLen, ipHeaderLen, headerSizeTCP, dataLen); // 1 for more verbose + char pbuf[50]; // local print buffer + fillbuf(); + sprintf(pbuf, "TCP %d ipHeader %d tcpHeader %d Data %d\n", ipPktLen, ipHeaderLen, headerSizeTCP, dataLen); // 1 for more verbose + fillbuf(); + printWhileCheckingInput( pbuf ); } 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 - debugPrintf("%s\n",ppp.pkt.buf+4+ipHeaderLen+headerSizeTCP); // show the data + printWhileCheckingInput( ppp.pkt.buf+4+ipHeaderLen+headerSizeTCP ); // print the tcp payload data + printWhileCheckingInput("\n"); } } @@ -996,14 +1011,14 @@ int oldTail = ppp.rx.tail; // remember where the character is located in the buffer int rx = pc_getBuf(); // get the character if (rx==FRAME_7E) { - if (ppp.firstFrame) { // is this the first frame start + if (ppp.firstFrame) { // is this the start of the first frame start ppp.firstFrame=0; - ppp.hdlc.frameStartIndex = ppp.rx.tail; // remember first frame start - break; + ppp.rx.rtail = ppp.rx.tail; // update real-time tail with virtual tail + ppp.hdlc.frameStartIndex = ppp.rx.tail; // remember where first frame started } else { ppp.hdlc.frameEndIndex=oldTail; // mark the frame end character processPPPFrame(ppp.hdlc.frameStartIndex, ppp.hdlc.frameEndIndex); // process the frame - ppp.rx.rtail = ppp.rx.tail; + ppp.rx.rtail = ppp.rx.tail; // update real-time tail with virtual tail ppp.hdlc.frameStartIndex = ppp.rx.tail; // where next frame will start break; } @@ -1022,7 +1037,7 @@ // respond with Windows Dialup networking expected "Direct Connection Between Two Computers" response string if (v0) debugPrintf("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 + ppp.online=1; // we are connected - set flag so we stop looking for the connect string fillbuf(); } } @@ -1030,14 +1045,14 @@ int main() { - pc.baud(115200); // USB virtual serial port - debugBaudRate(115200); // baud rate for our debug port if we have one - debugPrintf("\x1b[2J\x1b[HReady\n"); // VT100 code for clear screen & home on our debug port - Tera Term is a good VT100 terminal + pc.baud(115200); // USB serial port + debugBaudRate(115200); // baud rate for our debug port - if we have one + debugPrintf("\x1b[2J\x1b[H\x1b[30mPPP-Blinky Ready.\n"); // VT100 codes for clear_screen, home, black_text - Tera Term is a handy VT100 terminal pppInitStruct(); // initialize all the PPP properties while(1) { - scanForConnectString(); // wait for connect command from windows dial up networking + scanForConnectString(); // wait for connect while(ppp.online) { - wait_for_PPP_frame(); + wait_for_PPP_frame(); // wait for a PPP frame } } } \ No newline at end of file