Program to update the D7A modem's firmware.

Dependencies:   modem_ref_helper DebouncedInterrupt

Revision:
32:e3ee65b5b835
Parent:
26:7fc24677a950
Child:
33:9cd782e2b423
--- a/cup.cpp	Fri Feb 22 16:35:52 2019 +0000
+++ b/cup.cpp	Tue Aug 20 13:51:30 2019 +0000
@@ -58,6 +58,10 @@
             FLUSH();
             while(1);
         }
+        else
+        {
+            //PRINT("\nDone.\n");
+        }
         modem_cup_ready.release();
     }
     else if (err)
@@ -82,6 +86,11 @@
     uint8_t percent_old = 255;
     Timer tim;
     int32_t rem;
+    float now = 0;
+    float before = 0;
+    float speed = 0;
+    int speed_data = 0;
+    float time_left = 0;
     
     uint8_t id = modem_get_id(my_cup_callback);
     
@@ -100,7 +109,7 @@
         
     // Start CUP
     modem_write_file_root(cup->cfg_fid, (uint8_t*)&cfg, 0, 4, root_key, id);
-    modem_cup_ready.wait();
+    modem_cup_ready.acquire();
         
     // Upload file
     PRINT("Uploading %d bytes to CUP file. (offset %d)\r\n", cup->data_size, offset);
@@ -111,27 +120,33 @@
     {
         int32_t chunk = (rem > cup->local_mtu)? cup->local_mtu : rem;
         modem_write_file(cup->code_fid, &(cup->data[fof]), fof + offset, chunk, id);
-        modem_cup_ready.wait();
+        modem_cup_ready.acquire();
         rem -= chunk;
         fof += chunk;
         
         percent = (100*fof)/cup->data_size;
-        if (percent != percent_old && !(percent%5))
+        now = tim.read();
+        speed_data += chunk;
+        
+        if (now - before > 1.0 || before == 0)
         {
-            PRINT("UPLOADING CUP FILE %3d percent\r\n", percent);
-            percent_old = percent;
+            speed = (speed_data/(now - before))/1024.0;
+            before = now;
+            speed_data = 0;
+            time_left = (rem / speed) / 1024.0;
         }
         
-        // Wait to avoid COM faillure
-        Thread::wait(1);
+        PRINT("\rUPLOADING CUP FILE %d/%d (%3d%%) %.2f kB/s %.0fs    ", fof, cup->data_size, percent, speed, time_left);
     }
     
+    PRINT("\n");
+    
     float time_s = tim.read();
     PRINT("CUP: %d bytes written in %.2f sec (%.2f kB/s)\r\n", cup->data_size, time_s, (cup->data_size/time_s)/1024.0);
         
     // Force PFLASH-cache flushing
     modem_flush_file_root(cup->code_fid, root_key, id);
-    modem_cup_ready.wait();
+    modem_cup_ready.acquire();
         
     // Send Upgrade command
     cfg.cmd = 0xC0D5;
@@ -140,7 +155,7 @@
     cfg.signature = cup->signature;
         
     modem_write_file_root(cup->cfg_fid, (uint8_t*)&cfg, 0, 12, root_key, id);
-    modem_cup_ready.wait();
+    modem_cup_ready.acquire();
     
     PRINT("Waiting self reboot...\r\n");
 }