Scan example on D7-LoRa

Dependencies:   modem_ref_helper DebouncedInterrupt

Revision:
1:27716ee59ca4
Parent:
0:6703784ff93e
Child:
2:de388004dca6
--- a/main.cpp	Fri May 25 16:10:45 2018 +0000
+++ b/main.cpp	Tue Jun 12 15:15:54 2018 +0000
@@ -5,6 +5,24 @@
 #include "modem_ref_helper.h"
 #include "modem_callbacks.h"
 
+#if 1
+    // Use D7 LoRa
+    #define XCL_DL d7lora_dl_xcl
+    #define XCL_UL d7lora_ul_xcl
+#else
+    // Use D7 FSK
+    #define XCL_DL d7fsk_dl_xcl
+    #define XCL_UL d7fsk_ul_xcl
+#endif
+
+#if 1
+    // Disable Duty Cycle
+    #define DUTY 255
+#else
+    // Use default Duty Cycle
+    #define DUTY D7A_CTF_ENCODE(31)
+#endif
+
 #define MY_POLICY_IDX           0
 
 Semaphore button_user(0);
@@ -17,21 +35,26 @@
     MODEM_RESP_DONE,
 };
 
-uint8_t g_main_id;
-    
-d7a_xcl_t d7lora_dl_xcl = { .bf.s = 8, .bf.m = 1 };
-d7a_xcl_t d7lora_ul_xcl = { .bf.s = 9, .bf.m = 1 };
-
+// This discribes the retry policy of the stack for each packet
+// Do not modify uncommented parameters
 alp_retry_policy_t my_policy = {
     .meta.procedure     = 0,
     .meta.respond       = true,
     .meta.persistant    = false,
     .meta.bulk          = false,
     .depth              = 1,
-    .retries            = 0,
-    .slot_time          = 0
+    .retries            = 0, // The stack will retry x times (each packet will be sent a maximum of x+1 times)
+    .slot_time          = 0  // Interval between retries in seconds
 };
 
+uint8_t g_main_id;
+
+d7a_xcl_t d7fsk_dl_xcl = { .bf.s = 0, .bf.m = 1 };
+d7a_xcl_t d7fsk_ul_xcl = { .bf.s = 2, .bf.m = 1 };
+
+d7a_xcl_t d7lora_dl_xcl = { .bf.s = 8, .bf.m = 1 };
+d7a_xcl_t d7lora_ul_xcl = { .bf.s = 9, .bf.m = 1 };
+
 alp_d7a_itf_t my_itf = {
     .type                           = ALP_ITF_TYPE_D7A,
     .cfg.to                         = 0,
@@ -40,7 +63,7 @@
     .cfg.qos.bf.retry               = MY_POLICY_IDX,
     .cfg.addressee.ctrl.bf.nls      = D7A_NLS_AES_CCM_64,
     .cfg.addressee.ctrl.bf.idf      = D7A_ID_NBID,
-    .cfg.addressee.xcl              = d7lora_ul_xcl,
+    .cfg.addressee.xcl              = XCL_UL,
     .cfg.addressee.id[0]            = D7A_CTF_VAL(4,0),
 };
 
@@ -114,7 +137,7 @@
 
     uint8_t my_user_id = modem_get_id(my_read_response_callback);
         
-    uint8_t scan_xcl[] = { d7lora_dl_xcl.byte, d7lora_ul_xcl.byte };
+    uint8_t scan_xcl[] = { XCL_DL.byte, XCL_UL.byte };
     
     memset(&istat, 0, sizeof(d7a_sp_res_t));
     memset(&fw_ver, 0, sizeof(fw_version_t));
@@ -199,7 +222,7 @@
 #endif
     PRINT("\n"
           "-----------------------------------------\n"
-          "--------- Demo ActiveRFIDReader ---------\n"
+          "-------------- Demo D7A LoRa ------------\n"
           "-----------------------------------------\n");
           
     FPRINT("(id:0x%08x)\r\n", osThreadGetId());
@@ -208,23 +231,6 @@
     
     g_main_id = modem_get_id(my_main_callback);
     
-    // Put modem to listen to downlink access class
-    modem_write_file(D7A_FID_DLL_CFG, &d7lora_dl_xcl, offsetof(d7a_dll_cfg_t, xcl), sizeof(d7a_xcl_t), g_main_id);
-    modem_ready.wait();
-    
-    // Configure interfaces to use uplink access class
-    modem_write_file(FID_D7A_ITF0, &d7lora_ul_xcl, offsetof(alp_d7a_itf_t, cfg.addressee.xcl), sizeof(d7a_xcl_t), g_main_id);
-    modem_ready.wait();
-    
-    modem_write_file(FID_D7A_ITF1, &d7lora_ul_xcl, offsetof(alp_d7a_itf_t, cfg.addressee.xcl), sizeof(d7a_xcl_t), g_main_id);
-    modem_ready.wait();
-    
-    modem_write_file(FID_D7A_ITF2, &d7lora_ul_xcl, offsetof(alp_d7a_itf_t, cfg.addressee.xcl), sizeof(d7a_xcl_t), g_main_id);
-    modem_ready.wait();
-    
-    modem_write_file(FID_D7A_ITF3, &d7lora_ul_xcl, offsetof(alp_d7a_itf_t, cfg.addressee.xcl), sizeof(d7a_xcl_t), g_main_id);
-    modem_ready.wait();
-    
     // Set custom retry policy
     // XXX Won't work the first time as we need to reboot the modem for the changes to be applied
     // Check current retry policy
@@ -244,11 +250,37 @@
         my_reset();
     }
     
-    // Configure URC: LQUAL on report file notification every 10 reports
-    PRINT("Setup URCs\n");
-    modem_enable_urc(ALP_URC_TYPE_LQUAL, IFID_REPORT, 10, true, g_main_id);
+    // Put modem to listen to downlink access class
+    modem_write_file(D7A_FID_DLL_CFG, &XCL_DL, offsetof(d7a_dll_cfg_t, xcl), sizeof(d7a_xcl_t), g_main_id);
+    modem_ready.wait();
+    
+    // Configure interfaces to use uplink access class
+    modem_write_file(FID_D7A_ITF0, &XCL_UL, offsetof(alp_d7a_itf_t, cfg.addressee.xcl), sizeof(d7a_xcl_t), g_main_id);
+    modem_ready.wait();
+    
+    modem_write_file(FID_D7A_ITF1, &XCL_UL, offsetof(alp_d7a_itf_t, cfg.addressee.xcl), sizeof(d7a_xcl_t), g_main_id);
+    modem_ready.wait();
+    
+    modem_write_file(FID_D7A_ITF2, &XCL_UL, offsetof(alp_d7a_itf_t, cfg.addressee.xcl), sizeof(d7a_xcl_t), g_main_id);
     modem_ready.wait();
     
+    modem_write_file(FID_D7A_ITF3, &XCL_UL, offsetof(alp_d7a_itf_t, cfg.addressee.xcl), sizeof(d7a_xcl_t), g_main_id);
+    modem_ready.wait();
+    
+    // Configure duty
+    d7a_ctf_t duty = { .byte = DUTY };
+    for (int i = 0; i < 8; i++)
+    {
+        modem_write_file(D7A_FID_ACCESS_PROFILE_0 + XCL_DL.bf.s, &duty, offsetof(d7a_access_profile_t, sb[0].duty) + (i * sizeof(d7a_subband_t)), sizeof(d7a_ctf_t), g_main_id);
+        modem_ready.wait();
+    }
+    
+    for (int i = 0; i < 8; i++)
+    {
+        modem_write_file(D7A_FID_ACCESS_PROFILE_0 + XCL_UL.bf.s, &duty, offsetof(d7a_access_profile_t, sb[0].duty) + (i * sizeof(d7a_subband_t)), sizeof(d7a_ctf_t), g_main_id);
+        modem_ready.wait();
+    }
+    
     PRINT("Start D7A Stack\n");
     modem_activate_itf(ALP_ITF_TYPE_D7A, 24, 0, ALP_D7A_ISTAT_RESP | ALP_D7A_ISTAT_UNS, true, g_main_id);
     modem_ready.wait();