RealtimeCompLab2
Dependencies: mbed
Fork of PPP-Blinky by
Diff: main.cpp
- Revision:
- 68:0b74763ae67f
- Parent:
- 67:a63e3486bcda
- Child:
- 69:23f560087c16
--- a/main.cpp Mon Jun 05 16:45:03 2017 +0000 +++ b/main.cpp Mon Jun 05 22:45:39 2017 +0000 @@ -61,7 +61,7 @@ <h1 id=\"w\" style=\"text-align:center;\">0</h1>\ <h1><a href=\"http://bit.ly/pppBlink2\">Source on mbed</a></h1>\ </body>\ -</html>"; // current size is approximately 500 characters +</html>"; // current size is approximately 470 characters // The serial port on your mbed hardware. Your PC should view this as a standard dial-up networking modem. See instructions at the top. // On a typical mbed hardware platform this is a USB virtual com port (VCP) @@ -513,7 +513,7 @@ } } -int httpResponse( char * dataStart) +int httpResponse(char * dataStart) { int n=0; // number of bytes we have printed so far if(strncmp(dataStart, "GET / HTTP/1.1", 14) == 0 ) { @@ -527,10 +527,9 @@ // this is where we insert our web page into the buffer n=n+sprintf(n+dataStart,"%s\r\n", ourWebPage); - int contentLength = n-nHeader; // contentLength is the count of every character after the header -#define CONTENTLENGTHSIZE 5 +#define CONTENTLENGTHSIZE 5 char contentLengthString[CONTENTLENGTHSIZE+1]; // temporary buffer to create Content-Length string - snprintf(contentLengthString,CONTENTLENGTHSIZE+1,"%*d",CONTENTLENGTHSIZE,contentLength); // print Content-Length with leading spaces and fixed width equal to csize + snprintf(contentLengthString,CONTENTLENGTHSIZE+1,"%*d",CONTENTLENGTHSIZE,n-nHeader); // print Content-Length with leading spaces and fixed width equal to csize memcpy(dataStart+contentLengthStart, contentLengthString, CONTENTLENGTHSIZE); // copy Content-Length to it's place in the send buffer if (v0) { @@ -548,11 +547,9 @@ n=n+sprintf(n+dataStart,"<body><h1>File Not Found</h1></body>"); 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 - char contentLengthString[cSize+1]; // temporary buffer to create Content-Length string - snprintf(contentLengthString,cSize+1,"%*d",cSize,contentLength); // print Content-Length with leading spaces and fixed width = csize - memcpy(dataStart+contentLengthStart, contentLengthString, cSize); // copy Content-Length to the send buffer + char contentLengthString[CONTENTLENGTHSIZE+1]; // temporary buffer to create Content-Length string + snprintf(contentLengthString,CONTENTLENGTHSIZE+1,"%*d",CONTENTLENGTHSIZE,n-nHeader); // print Content-Length with leading spaces and fixed width equal to csize + memcpy(dataStart+contentLengthStart, contentLengthString, CONTENTLENGTHSIZE); // copy Content-Length to it's place in the send buffer if (v0) { debug("HTTP GET BufSize %d*32=%d Header %d Content-Length %d Total %d Available %d\n",dataLen/32,dataLen,nHeader,contentLength,n,dataLen-n); @@ -695,7 +692,9 @@ if (fastResponse==1) { fastResponse=0; // reset and skip 200 ms wait } else { - wait(0.2); // normally, you wait 200 ms before sending a TCP packet + // normally, you wait 200 ms before sending a TCP packet + // remove the wait to respond faster + // wait(0.2); } sendFrame(); // All done! Send the TCP packet ppp.seq = ppp.seq + dataLen; // increase OUR sequence by the outgoing data length - for the next round