Complete sensor demo.
Dependencies: modem_ref_helper CRC X_NUCLEO_IKS01A1 DebouncedInterrupt
Diff: modem_callbacks.cpp
- Revision:
- 11:9683d014dece
- Parent:
- 6:c17f7cbdeb1a
- Child:
- 15:1271f3566b98
diff -r c01db64b9e68 -r 9683d014dece modem_callbacks.cpp --- a/modem_callbacks.cpp Tue Sep 04 11:33:56 2018 +0000 +++ b/modem_callbacks.cpp Thu Sep 20 14:53:07 2018 +0000 @@ -58,23 +58,59 @@ modem_respond(0, err, id); } -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; - PRINT("Got UNS File[%3d]@%d %d Bytes\n",fid,offset,length); - if (i_type == ALP_ITF_TYPE_D7A) - { - static union { - u8 b[8]; - u32 w[2]; - } uid; - d7a_sp_res_t* istat = (d7a_sp_res_t*) i_data; - memcpy(uid.b,istat->addressee.id,8); - PRINT("From UID: %08X%08X (rxlev:%d lb:%d)\n", - HAL_U32_BYTE_SWAP(uid.w[0]), HAL_U32_BYTE_SWAP(uid.w[1]), - istat->rxlev, istat->lb); - } +void my_udata(void *data, u32 length) +{ + uint8_t* p = (uint8_t*)data; + int32_t rem = length; + alp_parsed_chunk_t r; + d7a_sp_res_t* istat; + + do { + uint32_t parsed = alp_parse_chunk(&p, &r); + if (!parsed) + { + // Discard the payload in case of parsing error. + PRINT("Parsing error!\r\n"); + break; + } + rem -= parsed; + + switch (r.type) + { + // Interface status + case ALP_OPCODE_RSP_ISTATUS: + // D7A Interface + if (ALP_ITF_TYPE_D7A == r.meta.itf.type) + { + union { + u8 b[8]; + u32 w[2]; + } uid; + + // ISTATUS can come either alone or together with ALP_OPCODE_RSP_F_DATA + // but there should be only one per payload, moreover it will come first + istat = (d7a_sp_res_t*)r.data; + memcpy(uid.b,istat->addressee.id,8); + + PRINT("Got accessed by UID:%08X%08X SNR: %3ddB RXLEV: -%-3ddBm LB: %3ddB\n", + HAL_U32_BYTE_SWAP(uid.w[0]), HAL_U32_BYTE_SWAP(uid.w[1]), + istat->snr, istat->rxlev, istat->lb); + } + else + { + PRINT("Got accessed by unknown Interface 0x%02X\n", r.meta.itf.type); + } + break; + // Data return + case ALP_OPCODE_RSP_F_DATA: + // RSP_F_DATA can come either alone or together with ISTATUS + PRINT("Got UNS File[%3d]@%d %d Bytes\n", r.meta.f_data.fid, r.meta.f_data.offset, r.meta.f_data.length); + break; + default: + PRINT("Untreated OPCODE %d\n", r.type); + break; + } + } while (rem > 0); } void my_lqual(u8 ifid, int per) @@ -100,4 +136,21 @@ // Modem re-booted, restart APP my_reset(); +} + +void my_busy(u8 busy) +{ + if (busy) + { + PRINT("Modem Busy\r\n"); + + /* Stop report, do not use modem */ + /* Wait for modem reboot or modem not busy */ + } + else + { + PRINT("Modem not Busy\r\n"); + + /* Resume reports */ + } } \ No newline at end of file