RealtimeCompLab2

Dependencies:   mbed

Fork of PPP-Blinky by Nicolas Nackel

Revision:
23:af88d429bed1
Parent:
22:00df34cd4d7e
Child:
24:9f3db3bf7f9c
--- a/main.cpp	Mon Jan 02 17:45:55 2017 +0000
+++ b/main.cpp	Mon Jan 02 18:22:51 2017 +0000
@@ -195,7 +195,8 @@
 }
 
 int dataCheckSum(char * ptr, int len) {
-    int sum=0;
+    int sum=0; int placeHolder;
+    if (len&1) { placeHolder = ptr[len-1]; ptr[len-1]=0; } // case where length is odd
     for (int i=0;i<len/2;i++) {
         int hi = *ptr; ptr++;
         int lo = *ptr; ptr++;
@@ -203,6 +204,7 @@
         sum = sum + val;
     }
     sum = sum + (sum>>16);
+    if (len&1) { ptr[len-1] = placeHolder; } // for odd lengths restore the last byte
     return ~sum;
 }    
 
@@ -256,11 +258,13 @@
         icmpSum[0]=sum>>8; icmpSum[1]=sum; // new checksum for ICMP data portion
 
         int printSize = icmpLength-8; // exclude size of icmp header
+        debug (("DS %d ", printSize));
         char * icmpData = icmpType+8; // the actual data is after the header
         if (printSize > 10) printSize = 10; // print only first 20 characters
         for (int i=0; i<printSize; i++) { char ch = icmpData[i]; if (ch>31 && ch<127) { debug(("%c",ch)); } else { debug(("%c",'_')); }}
         debug(("%c",'\n'));
         sendFrame(); // reply to the ping
+        dumpFrame();
     } else {
         debug(("ICMP type=%d \n", icmpType[0])); 
     }