Ping pong app demo.
Dependencies: modem_ref_helper DebouncedInterrupt
Diff: main.cpp
- Revision:
- 6:287a9759d70a
- Parent:
- 3:0979d8cba5ec
- Child:
- 7:7524fab147aa
--- a/main.cpp Tue Jan 30 09:44:14 2018 +0000 +++ b/main.cpp Mon Mar 05 09:56:30 2018 +0000 @@ -36,31 +36,40 @@ // { .bf.s = 14, .bf.m = 1 }; --> Slow Rate // We use these access class in this test, because in a normal access class, -// the transmission we be stopped by the duty cycle limit after several PINGs. - +// the transmission will be stopped by the duty cycle limit after several PINGs. d7a_xcl_t ping_pong_xcl = { .bf.s = 13, .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 }; + +// This describe the interface used for communication +// Do not modify uncommented parameters alp_d7a_itf_t my_itf = { .type = ALP_ITF_TYPE_D7A, .cfg.to = 0, .cfg.te = 0, - .cfg.qos.bf.resp = D7A_RESP_NO, - .cfg.qos.bf.retry = MY_POLICY_IDX, - .cfg.qos.bf.record = 0, - .cfg.qos.bf.stop_on_err = 0, - .cfg.addressee.ctrl.bf.nls = D7A_NLS_AES_CCM_64, - .cfg.addressee.ctrl.bf.idf = D7A_ID_NOID, - .cfg.addressee.xcl = ping_pong_xcl + .cfg.qos.bf.resp = D7A_RESP_NO, // Communication protocol + .cfg.qos.bf.retry = MY_POLICY_IDX, // Retry policy + .cfg.addressee.ctrl.bf.nls = D7A_NLS_AES_CCM_64, // Security level + .cfg.addressee.xcl = ping_pong_xcl, // Used Access Class + // One of the followings: + .cfg.addressee.ctrl.bf.idf = D7A_ID_NOID, // No response + + //.cfg.addressee.ctrl.bf.idf = D7A_ID_UID, // in Unicast + //.cfg.addressee.id = { 0x00, 0x1B, 0xC5, 0x0C, 0x70, 0x00, 0x00, 0x00 }, // Destination UID + + //.cfg.addressee.ctrl.bf.idf = D7A_ID_NBID, // in Broadcast + //.cfg.addressee.id[0] = 4, // Estimation of reachable devices (2 to 32) }; void print_status(int status) @@ -136,25 +145,31 @@ if (i_type == ALP_ITF_TYPE_D7A) { - d7a_sp_res_t* istat = (d7a_sp_res_t*)i_data; - - if(fid == FID_PING_PONG && offset == 0 && length == PING_COUNTER_SIZE) - { - uint32_t* count = (uint32_t*)data; + d7a_sp_res_t istat; + + // Get interface status + memcpy(&istat, i_data, i_length); - PRINT("Got PING %d", *count); - PRINT_DATA(" from ", "%02X", istat->addressee.id, 8, ""); - PRINT(" (SNR:%d dB RXLEV:%d dBm LB:%d dB)\n", istat->snr, -istat->rxlev, istat->lb); + if(FID_PING_PONG == fid && 0 == offset && PING_COUNTER_SIZE == length) + { + uint32_t count; + + // Get data + memcpy(&count, data, length); - #ifdef DEBUG_LED + PRINT("Got PING %d", count); + PRINT_DATA(" from ", "%02X", istat.addressee.id, 8, ""); + PRINT(" (SNR:%d dB RXLEV:%d dBm LB:%d dB)\n", istat.snr, -istat.rxlev, istat.lb); + +#ifdef DEBUG_LED my_led = 1; - #endif +#endif Thread::wait(PING_DELAY); - #ifdef DEBUG_LED +#ifdef DEBUG_LED my_led = 0; - #endif +#endif alp_d7a_itf_t resp_itf = { .type = ALP_ITF_TYPE_D7A, @@ -162,18 +177,16 @@ .cfg.te = 0, .cfg.qos.bf.resp = D7A_RESP_NO, .cfg.qos.bf.retry = MY_POLICY_IDX, - .cfg.qos.bf.record = 0, - .cfg.qos.bf.stop_on_err = 0, - .cfg.addressee = istat->addressee, + .cfg.addressee = istat.addressee, }; - (*count)++; + count++; // Send ping - PRINT("Send PING %d", *count); + PRINT("Send PING %d", count); PRINT_DATA(" to ", "%02X", resp_itf.cfg.addressee.id, 8, "\n"); - modem_send_file_content((uint8_t*)&resp_itf, D7_ITF_SIZE(&resp_itf), istat, FID_PING_PONG, count, 0, PING_COUNTER_SIZE, g_void_id); + modem_send_file_content((uint8_t*)&resp_itf, D7_ITF_SIZE(&resp_itf), NULL, FID_PING_PONG, &count, 0, PING_COUNTER_SIZE, g_void_id); } } } @@ -235,14 +248,23 @@ modem_write_file(D7A_FID_DLL_CFG, &ping_pong_xcl, 0, sizeof(d7a_xcl_t), g_main_id); modem_ready[g_main_id].wait(); - // Set custom 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); + alp_retry_policy_t old_policy; + + // Get old retry policy + modem_read_file(WM_FID_ALP_CFG, &old_policy, MY_POLICY_IDX * sizeof(alp_retry_policy_t), sizeof(alp_retry_policy_t), g_main_id); modem_ready[g_main_id].wait(); - // 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); - modem_ready[g_main_id].wait(); + if (!memcmp(&old_policy, &my_policy, sizeof(alp_retry_policy_t))) + { + // Set custom 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[g_main_id].wait(); + modem_flush_file(WM_FID_ALP_CFG, g_main_id); + modem_ready[g_main_id].wait(); + + // XXX We need to reboot the modem for the changes to be applied + my_reset(); + } 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);