Data reception demo.

Dependencies:   modem_ref_helper CRC

Revision:
3:e9ea4d325c01
Parent:
2:6652be2d061f
Child:
4:854f22f7962b
--- a/main.cpp	Mon May 15 15:55:09 2017 +0000
+++ b/main.cpp	Wed May 17 14:38:25 2017 +0000
@@ -22,6 +22,9 @@
 
 #include "CriusOLED.h"
 
+#define MODEM_VERSION_MAJOR         4
+#define MODEM_VERSION_MINOR         8
+
 #define RESTORE_TIME    30
 #define KEEP_ALIVE      3600
 
@@ -40,30 +43,23 @@
 
 void thread_reset_display()
 {
-    char str[SIZE_STRING_FILE];
-    uint32_t time;
-    Timer up_time;
+    FPRINT("(id:0x%08x)\r\n", osThreadGetId());
     
-    up_time.start();
-
+    uint32_t time = 0;
+    uint8_t status = 0;
+    
     while (true)
     {
         if (g_restore_time++ == RESTORE_TIME)
         {
             display_logo();
         }
-        
-        time = (uint32_t)up_time.read();
-        
-        memset(str, 0, SIZE_STRING_FILE);
-        sprintf(str, "Up time: %02d:%02d:%02d", time/3600, (time/60)%60, time%60);
-        ram_fs_write(FID_STRING_FILE, 0, SIZE_STRING_FILE, (uint8_t*)str);
-        
-        if ((time % KEEP_ALIVE) == 0)
+       
+        if ((time++ % KEEP_ALIVE) == 0)
         {
-            // Keep alive: Report uptime
-            modem_notify_file(FID_STRING_FILE, 0, strlen(str) + 1, g_main_id);
-            modem_ready.wait();
+            // Keep alive: Report status
+            modem_write_file(FID_STATUS_FILE, &status, 0, SIZE_STATUS_FILE, g_main_id);
+            //modem_ready.wait();
         }
         
         Thread::wait(1000);
@@ -72,6 +68,8 @@
 
 void thread_file_modified()
 {
+    FPRINT("(id:0x%08x)\r\n", osThreadGetId());
+    
     uint8_t fid;
     osEvent evt;
     
@@ -96,6 +94,7 @@
                 g_restore_time = 0;
                 break;
             default:
+                PRINT("Unknown file %d\n", fid);
             break;
         }
     }
@@ -168,6 +167,7 @@
     .read_fprop = my_read_fprop,
     .flush      = my_flush,
     .remove     = my_delete,
+    .udata      = my_udata,
     .lqual      = my_lqual,
     .ldown      = my_ldown,
     .reset      = my_reset,
@@ -279,7 +279,16 @@
     PRINT(" - Firmware version: v%d.%d.%d\r\n", rev.fw_version.major, rev.fw_version.minor, rev.fw_version.patch);
     PRINT(" - File system CRC:  0x%08x\r\n", rev.fs_crc);
     PRINT("-----------------------------------------\r\n");
-    
+        
+    // Check version
+    if (rev.fw_version.major != MODEM_VERSION_MAJOR || rev.fw_version.minor != MODEM_VERSION_MINOR)
+    {
+        PRINT("You need a modem at version %d.%d.x to use this APP.\n"
+              "Please check updates by importing:\n"
+              "https://developer.mbed.org/teams/WizziLab/code/D7A_WM_Updater\n"
+              , MODEM_VERSION_MAJOR, MODEM_VERSION_MINOR);
+        Thread::wait(osWaitForever);
+    }
     //DPRINT("UID: %08X%08X\n", HAL_U32_BYTE_SWAP(uid.w[0]), HAL_U32_BYTE_SWAP(uid.w[1]));
 
     DPRINT("Register Files\n");
@@ -288,6 +297,7 @@
     
     // Allow remote access.
     modem_update_file(FID_STRING_FILE, (alp_file_header_t*)&h_string_file, (uint8_t*)&f_string_file);
+    modem_update_file(FID_STATUS_FILE, (alp_file_header_t*)&h_status_file, NULL);
 
     // Put modem to listen to this access class
     d7a_xcl_t my_xcl = { .bf.s = 0, .bf.m = 2 };
@@ -300,7 +310,7 @@
     modem_ready.wait();
     
     PRINT("Start D7A Stack\n");
-    modem_activate_itf(ALP_ITF_TYPE_D7A, 24, 0, ALP_D7A_ISTAT_RESP , true, g_main_id);
+    modem_activate_itf(ALP_ITF_TYPE_D7A, 24, 0, ALP_D7A_ISTAT_RESP | ALP_D7A_ISTAT_UNS , true, g_main_id);
     modem_ready.wait();
     
     PRINT("Notify Modem Version\n");
@@ -317,7 +327,7 @@
     ASSERT(status == osOK, "Failed to start thread_file_modified (err: %d)\r\n", status);
     
     // Start reset display thread
-    Thread th_reset_display(osPriorityNormal, 512, NULL);
+    Thread th_reset_display(osPriorityLow, 1024, NULL);
     status = th_reset_display.start(thread_reset_display);
     ASSERT(status == osOK, "Failed to start thread_reset_display (err: %d)\r\n", status);