Send file data demo.
Dependencies: modem_ref_helper CRC DebouncedInterrupt
Diff: modem_callbacks.cpp
- Revision:
- 20:5856f9bfd8e3
- Parent:
- 17:d50191689d1f
--- a/modem_callbacks.cpp Thu May 28 09:13:44 2020 +0000 +++ b/modem_callbacks.cpp Fri Oct 29 13:11:38 2021 +0000 @@ -1,107 +1,82 @@ -#include "modem_ref_helper.h" +#include "modem_d7a.h" +#include "files.h" +#define SERIAL_MAX_PACKET_SIZE (255) // ============================================================}}} // Callbacks to MODEM's ALP requests // ============================================================{{{ -void my_read(u8 fid, u32 offset, u32 length, int id) +void my_read(u8 action, u8 fid, u32 offset, u32 length, int id) { - u8 data[256]; + u8 data[SERIAL_MAX_PACKET_SIZE]; - if (ram_fs_read(fid, offset, length, data)) + ASSERT((ALP_ACTION_RSP_TAG_SIZE + ALP_ACTION_RSP_F_DATA_SIZE(offset, length)) <= SERIAL_MAX_PACKET_SIZE, + "Read response too big for serial protocol (%d/%dmax)", length, ALP_ACTION_RSP_TAG_SIZE + ALP_ACTION_RSP_F_DATA_SIZE(offset,SERIAL_MAX_PACKET_SIZE)); + + if (ram_fs_read(fid, data, offset, length)) { - modem_respond(ALP_ERR_FILE_NOT_FOUND, id); + modem_ref_respond(action, ALP_ERR_FILE_NOT_FOUND, id); } else { - modem_respond_read(fid, data, offset, length, id); + modem_ref_respond_read(fid, data, offset, length, id); } } -void my_write(u8 fid, void *data, u32 offset, u32 length, int id) + +void my_write(u8 action, u8 fid, void *data, u32 offset, u32 length, int id) { - modem_respond((ram_fs_write(fid, offset, length, (uint8_t*)data))? ALP_ERR_FILE_NOT_FOUND : ALP_ERR_NONE, id); + alp_errors_t err; + + if (ram_fs_write(fid, (uint8_t*)data, offset, length)) + { + err = ALP_ERR_FILE_NOT_FOUND; + } + else + { + err = ALP_ERR_NONE; + + touch_t* touch = (touch_t*)MALLOC(sizeof(touch_t)); + + touch->fid = fid; + touch->offset = offset; + touch->length = length; + + modem_resp.put(touch); + } + + modem_ref_respond(action, err, id); } -void my_read_fprop(u8 fid, int id) +void my_read_fprop(u8 action, u8 fid, int id) { u8* hdr = (u8*)ram_fs_get_header(fid); if (hdr != NULL) { - modem_respond_fprop(fid, hdr, id); + modem_ref_respond_fprop(fid, (alp_file_header_t*)hdr, id); } else { - modem_respond(ALP_ERR_FILE_NOT_FOUND, id); + modem_ref_respond(action, ALP_ERR_FILE_NOT_FOUND, id); } } -void my_flush(u8 fid, int id) +void my_flush(u8 action, u8 fid, int id) { // No flush in this file system - modem_respond(ALP_ERR_NONE, id); -} - -void my_delete(u8 fid, int id) -{ - modem_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, 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_delete(u8 action, u8 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(u8 ifid, int per)