LoRaWAN demo.
Dependencies: modem_ref_helper DebouncedInterrupt
Diff: d7a_callbacks.cpp
- Revision:
- 21:f0aecd41db08
- Parent:
- 20:49a8ecd1dda3
--- a/d7a_callbacks.cpp Wed Jan 27 14:45:50 2021 +0000 +++ b/d7a_callbacks.cpp Fri Feb 19 14:58:25 2021 +0000 @@ -6,7 +6,7 @@ // Callbacks to MODEM's ALP requests // ============================================================{{{ -void my_read(uint8_t fid, uint32_t offset, uint32_t length, int id) +void my_read(u8 action, uint8_t fid, uint32_t offset, uint32_t length, int id) { uint8_t data[256]; #if 0 @@ -17,26 +17,26 @@ else #endif { - modem_ref_respond(ALP_ERR_FILE_NOT_FOUND, id); + modem_ref_respond(action, ALP_ERR_FILE_NOT_FOUND, id); } } -void my_write(uint8_t fid, void *data, uint32_t offset, uint32_t length, int id) +void my_write(u8 action, uint8_t fid, void *data, uint32_t offset, uint32_t length, int id) { if (!ram_fs_write(fid, (uint8_t*)data, offset, length)) { extern Queue<uint8_t, 8> g_file_modified; - modem_ref_respond(ALP_ERR_NONE, id); + modem_ref_respond(action, ALP_ERR_NONE, id); g_file_modified.put((uint8_t*)(uint32_t)fid); } else { - modem_ref_respond(ALP_ERR_FILE_NOT_FOUND, id); + modem_ref_respond(action, ALP_ERR_FILE_NOT_FOUND, id); } } -void my_read_fprop(uint8_t fid, int id) +void my_read_fprop(u8 action, uint8_t fid, int id) { uint8_t* hdr = (uint8_t*)ram_fs_get_header(fid); @@ -46,74 +46,24 @@ } else { - modem_ref_respond(ALP_ERR_FILE_NOT_FOUND, id); + modem_ref_respond(action, ALP_ERR_FILE_NOT_FOUND, id); } } -void my_flush(uint8_t fid, int id) +void my_flush(u8 action, uint8_t fid, int id) { // No flush in this file system - modem_ref_respond(ALP_ERR_NONE, id); -} - -void my_delete(uint8_t fid, int id) -{ - modem_ref_respond((ram_fs_delete(fid))? ALP_ERR_FILE_NOT_FOUND : ALP_ERR_NONE, id); + modem_ref_respond(action, ALP_ERR_NONE, id); } -void my_udata(void *data, uint32_t 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 { - uint8_t b[8]; - uint32_t 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_delete(u8 action, uint8_t fid, int id) +{ + modem_ref_respond(action, (ram_fs_delete(fid))? ALP_ERR_FILE_NOT_FOUND : ALP_ERR_NONE, id); +} + +void my_udata(alp_payload_t* alp) +{ + alp_payload_print(alp); } void my_lqual(uint8_t ifid, int per)