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:
- 84:456e73151f11
- Parent:
- 83:cdcb81d1910f
- Child:
- 85:53e57ff1cf05
--- a/main.cpp Tue Jul 18 00:17:03 2017 +0000 +++ b/main.cpp Tue Jul 18 01:01:10 2017 +0000 @@ -88,6 +88,7 @@ unsigned int seq; // our TCP sequence number int crc; // for calculating IP and TCP CRCs int ledState; // state of LED1 + int httpFrame; struct { #define RXBUFLEN (1<<14) char buf[RXBUFLEN]; // RXBUFLEN MUST be a power of two because we use & operator for fast wrap-around in rxHandler @@ -127,6 +128,7 @@ ppp.ledState=0; ppp.hdlc.frameFound=0; ppp.hdlc.frameStartIndex=0; + ppp.httpFrame=0; } void led1Toggle() @@ -534,8 +536,12 @@ int n=0; // number of bytes we have printed so far int nHeader; // byte size of HTTP header int contentLengthStart; // index where HTML starts + + ppp.httpFrame++; // increment count of response frames + + int rootFetch = strncmp(dataStart, "GET / HTTP/1.1", 14); - if(strncmp(dataStart, "GET / HTTP/1.1", 14) == 0 ) { + if( rootFetch == 0 ) { n=n+sprintf(n+dataStart,"HTTP/1.1 200 OK\r\nServer: PPP-Blinky\r\n"); // http header } else { n=n+sprintf(n+dataStart,"HTTP/1.1 404 Not Found\r\nServer: PPP-Blinky\r\n"); // http header @@ -548,14 +554,13 @@ 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) nHeader=n; // size of HTTP header - if(strncmp(dataStart, "GET / HTTP/1.1", 14) == 0 ) { + if( rootFetch == 0 ) { // this is where we insert our web page into the buffer n=n+sprintf(n+dataStart,"%s", ourWebPage); } else { // all other requests get 404 Not Found response a - n=n+sprintf(n+dataStart,"<!DOCTYPE html><html><head></head>"); // html start - n=n+sprintf(n+dataStart,"<body>Not Found %06d</body>",ppp.ident); // here we print a variable in the html - n=n+sprintf(n+dataStart,"</html>"); // html end + n=n+sprintf(n+dataStart,"<!DOCTYPE html>"); // html start + n=n+sprintf(n+dataStart,"<title>%06d</title>",ppp.httpFrame); // shortest possible valid frame } while( (n%4)!= 2)