Dash7Board Code Upgrade Protocol demonstration code.

Dependencies:   modem_ref_helper CRC

Revision:
7:bfe920ee44f2
Parent:
6:1bdff7d6689c
Child:
8:6b7d38139b43
--- a/main.cpp	Tue Oct 16 15:24:09 2018 +0000
+++ b/main.cpp	Tue Aug 20 13:55:45 2019 +0000
@@ -68,14 +68,14 @@
         
         switch (touch->fid)
         {
-            case FID_APP_CUP_CFG:
-                cup_cfg_t cup_cfg;
+            case FID_APP_CUP_CFG_BCAST:
+                cup_cfg_bcast_header_t cup_cfg;
                 
-                ram_fs_read(FID_APP_CUP_CFG, 0, sizeof(cup_cfg_t), (uint8_t*)&cup_cfg);
+                ram_fs_read(FID_APP_CUP_CFG_BCAST, 0, sizeof(cup_cfg_bcast_header_t), (uint8_t*)&cup_cfg);
                         
                 if (CUP_CMD_UPGRADE_FILE_START == cup_cfg.cmd)
                 {
-                    PRINT("Enter upload mode. Watchdog %ds\n", cup_cfg.arch_nb);
+                    PRINT("Enter upload mode. Watchdog %ds\n", cup_cfg.to);
                     
                     tim.stop();
                     tim.reset();
@@ -86,15 +86,18 @@
                     
                     // Write to the modem CUP config file (as root)
                     // to enter upload mode
-                    cup_cfg.cmd = CUP_CMD_UPGRADE_UPLOAD;
-                    modem_write_file_root(FID_CUP_CFG, (uint8_t*)&cup_cfg, 0, 4, (uint8_t*)default_root_key, id);
-                    modem_ready.wait();
+                    cup_cfg_t cup_start = {
+                        .cmd = CUP_CMD_UPGRADE_UPLOAD,
+                        .arch_nb = cup_cfg.to,
+                        };
+                    modem_write_file_root(FID_CUP_CFG, (uint8_t*)&cup_start, 0, 4, (uint8_t*)default_root_key, id);
+                    modem_ready.acquire();
                 }
                 else if (CUP_CMD_UPGRADE_FILE_END == cup_cfg.cmd)
                 {
                     float time_s = tim.read();
-                    uint32_t expected_size = cup_cfg.src_offset;
-                    uint32_t expected_crc = cup_cfg.signature;
+                    uint32_t expected_size = cup_cfg.len;
+                    uint32_t expected_crc = cup_cfg.sig_new;
                 
                     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",
@@ -164,7 +167,7 @@
                 // Notify modem code file to reset upload watchdog
                 // else the device will exit upload mode after the watchdog timeout
                 modem_notify_file(FID_CUP_CODE, 0, 1, id);
-                modem_ready.wait();
+                modem_ready.acquire();
                 
                 break;
             default:
@@ -203,26 +206,26 @@
 
     PRINT("Register Files\n");
     modem_update_file(FID_HOST_REV, (alp_file_header_t*)&h_rev, (uint8_t*)&f_rev);
-    modem_update_file(FID_APP_CUP_CFG, (alp_file_header_t*)&h_cup_cfg, (uint8_t*)&f_cup_cfg);
+    modem_update_file(FID_APP_CUP_CFG_BCAST, (alp_file_header_t*)&h_cup_cfg_bcast, (uint8_t*)&f_cup_cfg_bcast);
     
     // Declare the cup code file
     // It needs a special handling of its data in my_write callback since we want to keep them.
     // (can't be done with the current RAM file system)
     modem_declare_file(FID_APP_CUP_CODE, (alp_file_header_t*)&h_cup_code, true, id);
-    modem_ready.wait();
+    modem_ready.acquire();
     
     PRINT("Setup URCs\n");
     // Busy URC to know if modem enters CUP mode
     modem_enable_urc(ALP_URC_TYPE_BUSY, 0, 0, true, id);
-    modem_ready.wait();
+    modem_ready.acquire();
     
     PRINT("Start D7A Stack\n");
     modem_activate_itf(ALP_ITF_TYPE_D7A, 24, 0,  ALP_D7A_ISTAT_RESP | ALP_D7A_ISTAT_UNS | ALP_D7A_ISTAT_EOP, true, id);
-    modem_ready.wait();
+    modem_ready.acquire();
     
     PRINT("Notify Modem Version\n");
     modem_notify_file(D7A_FID_FIRMWARE_VERSION, 0, SIZE_HOST_REV, id);
-    modem_ready.wait();
+    modem_ready.acquire();
     
     PRINT("Notify Host Version\n");
     modem_notify_host_rev(&f_rev, &h_rev, (uint8_t*)default_root_key);
@@ -240,10 +243,10 @@
 #endif
     
     // Set main task to lowest priority
-    osThreadSetPriority(osThreadGetId(), osPriorityIdle);
+    osThreadSetPriority(osThreadGetId(), osPriorityLow);
     while(true)
     {
-        Thread::wait(500);
+        ThisThread::sleep_for(500);
 #ifdef DEBUG_LED
         my_led = !my_led;
 #endif