Sending and reception of big data file (1kB example)
Dependencies: modem_ref_helper CRC DebouncedInterrupt
Diff: modem_callbacks.cpp
- Revision:
- 0:a2bbc478f812
- Child:
- 4:fd480d5fe62b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modem_callbacks.cpp Thu Dec 14 14:22:40 2017 +0000 @@ -0,0 +1,113 @@ +#include "modem_ref_helper.h" +#include "files.h" + +// ============================================================}}} + +// Callbacks to MODEM's ALP requests +// ============================================================{{{ +void my_read(u8 fid, u32 offset, u32 length, int id) +{ + u8 data[256]; + + if (ram_fs_read(fid, offset, length, data)) + { + modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id); + } + else + { + modem_respond_read(fid, data, offset, length, id); + } +} + +void my_write(u8 fid, void *data, u32 offset, u32 length, int id) +{ + alp_errors_t err; + + if (ram_fs_write(fid, offset, length, (uint8_t*)data)) + { + 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; + + g_file_modified.put(touch); + } + + modem_respond(0, err, id); +} + +void my_read_fprop(u8 fid, int id) +{ + u8* hdr = (u8*)ram_fs_get_header(fid); + + if (hdr != NULL) + { + modem_respond_fprop(fid, hdr, id); + } + else + { + modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id); + } +} + +void my_flush(u8 fid, int id) +{ + // No flush in this file system + modem_respond(0, ALP_ERR_NONE, id); +} + +void my_delete(u8 fid, int id) +{ + modem_respond(0, (ram_fs_delete(fid))? ALP_ERR_FILE_NOT_FOUND : ALP_ERR_NONE, 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_lqual(u8 ifid, int per) +{ + PRINT("Interface File [%3d] LQUAL : %d%% PER\r\n", ifid, per); +} + +void my_ldown(u8 ifid) +{ + PRINT("Interface File [%3d] LDOWN\r\n", ifid); +} + +void my_reset(void) +{ + PRINT("Restarting application...\r\n"); + FLUSH(); + NVIC_SystemReset(); +} + +void my_boot(u8 cause, u16 number) +{ + PRINT("Modem BOOT[%c] #%d\r\n", cause, number); + + // Modem re-booted, restart APP + my_reset(); +} \ No newline at end of file