Scan example on D7-LoRa
Dependencies: modem_ref_helper DebouncedInterrupt
Diff: main.cpp
- Revision:
- 2:de388004dca6
- Parent:
- 1:27716ee59ca4
- Child:
- 3:c1a36c817c48
--- a/main.cpp Tue Jun 12 15:15:54 2018 +0000 +++ b/main.cpp Thu Sep 20 08:36:34 2018 +0000 @@ -35,20 +35,6 @@ MODEM_RESP_DONE, }; -// 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, // 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 }; @@ -60,7 +46,7 @@ .cfg.to = 0, .cfg.te = 0, .cfg.qos.bf.resp = D7A_RESP_ALL, - .cfg.qos.bf.retry = MY_POLICY_IDX, + .cfg.qos.bf.retry = ALP_RPOL_ONESHOT, .cfg.addressee.ctrl.bf.nls = D7A_NLS_AES_CCM_64, .cfg.addressee.ctrl.bf.idf = D7A_ID_NBID, .cfg.addressee.xcl = XCL_UL, @@ -135,7 +121,7 @@ fw_version_t fw_ver; uint8_t nb = 0; - uint8_t my_user_id = modem_get_id(my_read_response_callback); + uint8_t id = modem_get_id(my_read_response_callback); uint8_t scan_xcl[] = { XCL_DL.byte, XCL_UL.byte }; @@ -155,7 +141,7 @@ PRINT("Scanning XCL 0x%02X...\n", my_itf.cfg.addressee.xcl.byte); - modem_remote_read_file((uint8_t*)&my_itf, D7_ITF_SIZE(&my_itf), (void*)&istat, D7A_FID_FIRMWARE_VERSION, (void*)&fw_ver, 12, sizeof(fw_version_t), my_user_id); + modem_remote_read_file((uint8_t*)&my_itf, D7_ITF_SIZE(&my_itf), (void*)&istat, D7A_FID_FIRMWARE_VERSION, (void*)&fw_ver, 12, sizeof(fw_version_t), id); do { @@ -195,7 +181,7 @@ .boot = my_boot }; -// Callback for g_main_id User +// Callback for id User void my_main_callback(uint8_t terminal, int8_t err, uint8_t id) { (void)id; @@ -229,61 +215,41 @@ modem_helper_open(&callbacks); - g_main_id = modem_get_id(my_main_callback); - - // 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 - alp_retry_policy_t old; - modem_read_file(WM_FID_ALP_CFG, &old, MY_POLICY_IDX * sizeof(alp_retry_policy_t), sizeof(alp_retry_policy_t), g_main_id); - modem_ready.wait(); - if (memcmp(&old, &my_policy, sizeof(alp_retry_policy_t))) - { - // Update retry policy - modem_write_file(WM_FID_ALP_CFG, &my_policy, MY_POLICY_IDX * sizeof(alp_retry_policy_t), sizeof(alp_retry_policy_t), g_main_id); - modem_ready.wait(); - modem_flush_file(WM_FID_ALP_CFG, g_main_id); - modem_ready.wait(); - - // Reboot - PRINT("Rebooting to apply new retry policy\n"); - my_reset(); - } + uint8_t id = modem_get_id(my_main_callback); // 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_write_file(D7A_FID_DLL_CFG, &XCL_DL, offsetof(d7a_dll_cfg_t, xcl), sizeof(d7a_xcl_t), 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_write_file(IFID_ONESHOT_HOST, &XCL_UL, offsetof(alp_d7a_itf_t, cfg.addressee.xcl), sizeof(d7a_xcl_t), 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_write_file(IFID_ONESHOT_ACTP, &XCL_UL, offsetof(alp_d7a_itf_t, cfg.addressee.xcl), sizeof(d7a_xcl_t), 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_write_file(IFID_REPORT, &XCL_UL, offsetof(alp_d7a_itf_t, cfg.addressee.xcl), sizeof(d7a_xcl_t), 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_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), 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_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), 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_activate_itf(ALP_ITF_TYPE_D7A, 24, 0, ALP_D7A_ISTAT_RESP | ALP_D7A_ISTAT_UNS, true, id); modem_ready.wait(); + + modem_free_id(id); #ifdef DEBUG_BUTTON DebouncedInterrupt user_interrupt(DEBUG_BUTTON);