Ping pong app demo.
Dependencies: modem_ref_helper DebouncedInterrupt
Diff: main.cpp
- Revision:
- 3:0979d8cba5ec
- Parent:
- 2:785b422c7d22
- Child:
- 6:287a9759d70a
--- a/main.cpp Thu May 18 13:09:03 2017 +0000 +++ b/main.cpp Thu Sep 21 15:14:08 2017 +0000 @@ -26,10 +26,18 @@ #define MY_POLICY_IDX 0 #define FID_PING_PONG 128 -#define PING_DELAY 500 +#define PING_DELAY 1000 #define PING_COUNTER_SIZE sizeof(uint32_t) #define MAX_PING_NB MAX_USER_NB-2 +// Special access classes for tests: no duty cycle limit, continuous scan +// { .bf.s = 12, .bf.m = 1 }; --> High Rate +// { .bf.s = 13, .bf.m = 1 }; --> Normal Rate +// { .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. + d7a_xcl_t ping_pong_xcl = { .bf.s = 13, .bf.m = 1 }; alp_retry_policy_t my_policy = { @@ -60,7 +68,7 @@ switch (status) { case ALP_ERR_NONE: - PRINT("Status: OK\n"); + //PRINT("Status: OK\n"); break; case ALP_ERR_FILE_EXIST: PRINT("Status: Already registered\n"); @@ -76,7 +84,7 @@ switch (status) { case ALP_ERR_NONE: - PRINT("Resp: OK\n"); + //PRINT("Resp: OK\n"); break; case ALP_ERR_FILE_EXIST: PRINT("Resp: Already registered\n"); @@ -121,48 +129,52 @@ DigitalOut my_led(DEBUG_LED); #endif -void my_udata(u8 fid,void *data,u32 offset,u32 length, u8 i_type, u8 i_length, u8* i_data) +void my_udata(u8 fid, void *data, u32 offset, u32 length, u8 i_type, u8 i_length, u8* i_data) { (void)data; (void)i_length; - if (i_type == ALP_ITF_TYPE_D7A && fid == FID_PING_PONG && offset == 0 && length == PING_COUNTER_SIZE) + if (i_type == ALP_ITF_TYPE_D7A) { d7a_sp_res_t* istat = (d7a_sp_res_t*)i_data; - uint32_t* count = (uint32_t*)data; - - PRINT("Got PING %d", *count); - PRINT_DATA(" from ", "%02X", istat->addressee.id, 8, ""); - PRINT(" (rxlev:%d lb:%d)\n", istat->rxlev, istat->lb); - -#ifdef DEBUG_LED - my_led = 1; -#endif - - Thread::wait(PING_DELAY); - -#ifdef DEBUG_LED - my_led = 0; -#endif + + if(fid == FID_PING_PONG && offset == 0 && length == PING_COUNTER_SIZE) + { + uint32_t* count = (uint32_t*)data; + + 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 - alp_d7a_itf_t resp_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 = istat->addressee, - }; - - (*count)++; - - // Send ping - 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); + Thread::wait(PING_DELAY); + + #ifdef DEBUG_LED + my_led = 0; + #endif + + alp_d7a_itf_t resp_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 = istat->addressee, + }; + + (*count)++; + + // Send ping + 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); + } } } @@ -176,6 +188,7 @@ while (true) { // Wait for button press + PRINT("PRESS BUTTON TO INITIATE PING...\n"); button_user.wait(); // Initiate ping @@ -207,7 +220,11 @@ #else DBG_OPEN(NC); #endif - PRINT("\r\n--- Starting new run ---\r\n"); + PRINT("\n" + "-----------------------------------------\n" + "------------ Demo Ping Pong -------------\n" + "-----------------------------------------\n"); + FPRINT("(id:0x%08x)\r\n", osThreadGetId()); modem_helper_open(&callbacks);