Dash7Board Code Upgrade Protocol demonstration code.

Dependencies:   modem_ref_helper CRC

Revision:
3:cfe26c2bb78b
Parent:
2:49acddddec25
Child:
4:c97df2bc1731
--- a/main.cpp	Wed Sep 19 15:58:35 2018 +0000
+++ b/main.cpp	Fri Oct 05 16:59:14 2018 +0000
@@ -13,6 +13,7 @@
 
 // CRC calculated on the incoming data stream
 extern uint32_t stream_crc;
+extern int32_t last_end;
 
 const uint8_t default_root_key[] = {206, 87, 116, 11, 4, 30, 202, 254, 206, 87, 116, 11, 4, 30, 202, 254};
 
@@ -66,6 +67,7 @@
     Timer tim;
     uint32_t total = 0;
     uint32_t next_chunk = 0;
+    uint32_t chunks=0;
     
     uint8_t id = modem_get_id(my_main_callback);
     
@@ -93,6 +95,7 @@
                     total = 0;
                     next_chunk = 0;
                     stream_crc = 0;
+                    chunks=0;
                     
                     // Write to the modem CUP config file (as root)
                     // to enter upload mode
@@ -105,10 +108,10 @@
                     float time_s = tim.read();
                     uint32_t expected_size = cup_cfg.src_offset;
                     uint32_t expected_crc = cup_cfg.signature;
-                    
-                    PRINT("Done. %d/%d bytes received in %.2f sec (%.2f kb/s)\r\n"
+                
+                    PRINT("\nDone. %d/%d bytes received in %d chunks in %.2f sec (%.2f kb/s)\r\n"
                           "Expected CRC 0x%08X. Stream CRC 0x%08X.\r\n",
-                            total, expected_size, time_s, (double)(total/time_s)/1024.0,
+                            total, expected_size, chunks, time_s, (double)(total/time_s)/1024.0,
                             expected_crc, stream_crc);
                     
                     tim.stop();
@@ -144,21 +147,33 @@
                 break;
             case FID_APP_CUP_CODE:
                 // Chunk data should be saved in my_write callback
-                PRINT("Got CUP code chunk length %d offset %d\n", touch->length, touch->offset);
+                //PRINT("Got CUP code chunk length %d offset %d\n", touch->length, touch->offset);
+                chunks++;
                 
                 if (!next_chunk)
                 {
                     // First chunk, start timer
                     tim.start();
+                    PRINT("Receiving CUP code chunks-> ");
                 }
                 
-                total += touch->length;
                 
-                if (next_chunk != touch->offset)
+                if (next_chunk < touch->offset)
+                {
+                    PRINT("\nMissed %d chunk(s) at offset %d (got offset %d)\n", (touch->offset - next_chunk) / CHUNK_SIZE, next_chunk, touch->offset);
+                    next_chunk = touch->offset + touch->length;
+                    total += touch->length;
+                }
+                else if (next_chunk == touch->offset)
                 {
-                    PRINT("Missed %d chunk(s) at offset %d (got offset %d)\n", (touch->offset - next_chunk) / CHUNK_SIZE, next_chunk, touch->offset);
+                    next_chunk = touch->offset + touch->length;
+                    total += touch->length;
+                    PRINT(".");
                 }
-                next_chunk = touch->offset + touch->length;
+                else
+                {
+                     //PRINT("Repeat chunk(s) at offset %d\n", touch->offset);
+                }
                 
                 // Notify modem code file to reset upload watchdog
                 // else the device will exit upload mode after the watchdog timeout