Sending and reception of big data file (1kB example)
Dependencies: modem_ref_helper CRC DebouncedInterrupt
modem_callbacks.cpp@4:fd480d5fe62b, 2017-12-21 (annotated)
- Committer:
- Jeej
- Date:
- Thu Dec 21 15:19:49 2017 +0000
- Revision:
- 4:fd480d5fe62b
- Parent:
- 0:a2bbc478f812
- Child:
- 6:33dfecc85ebf
Assert when data return is too big
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jeej | 0:a2bbc478f812 | 1 | #include "modem_ref_helper.h" |
Jeej | 0:a2bbc478f812 | 2 | #include "files.h" |
Jeej | 0:a2bbc478f812 | 3 | |
Jeej | 4:fd480d5fe62b | 4 | #define SERIAL_MAX_PACKET_SIZE (255) |
Jeej | 4:fd480d5fe62b | 5 | |
Jeej | 0:a2bbc478f812 | 6 | // ============================================================}}} |
Jeej | 0:a2bbc478f812 | 7 | |
Jeej | 0:a2bbc478f812 | 8 | // Callbacks to MODEM's ALP requests |
Jeej | 0:a2bbc478f812 | 9 | // ============================================================{{{ |
Jeej | 0:a2bbc478f812 | 10 | void my_read(u8 fid, u32 offset, u32 length, int id) |
Jeej | 0:a2bbc478f812 | 11 | { |
Jeej | 4:fd480d5fe62b | 12 | u8 data[SERIAL_MAX_PACKET_SIZE]; |
Jeej | 4:fd480d5fe62b | 13 | |
Jeej | 4:fd480d5fe62b | 14 | ASSERT((ALP_ACTION_RSP_TAG_SIZE + ALP_ACTION_RSP_F_DATA_SIZE(offset, length)) <= SERIAL_MAX_PACKET_SIZE, |
Jeej | 4:fd480d5fe62b | 15 | "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)); |
Jeej | 0:a2bbc478f812 | 16 | |
Jeej | 0:a2bbc478f812 | 17 | if (ram_fs_read(fid, offset, length, data)) |
Jeej | 0:a2bbc478f812 | 18 | { |
Jeej | 0:a2bbc478f812 | 19 | modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id); |
Jeej | 0:a2bbc478f812 | 20 | } |
Jeej | 0:a2bbc478f812 | 21 | else |
Jeej | 0:a2bbc478f812 | 22 | { |
Jeej | 0:a2bbc478f812 | 23 | modem_respond_read(fid, data, offset, length, id); |
Jeej | 0:a2bbc478f812 | 24 | } |
Jeej | 0:a2bbc478f812 | 25 | } |
Jeej | 0:a2bbc478f812 | 26 | |
Jeej | 0:a2bbc478f812 | 27 | void my_write(u8 fid, void *data, u32 offset, u32 length, int id) |
Jeej | 0:a2bbc478f812 | 28 | { |
Jeej | 0:a2bbc478f812 | 29 | alp_errors_t err; |
Jeej | 0:a2bbc478f812 | 30 | |
Jeej | 0:a2bbc478f812 | 31 | if (ram_fs_write(fid, offset, length, (uint8_t*)data)) |
Jeej | 0:a2bbc478f812 | 32 | { |
Jeej | 0:a2bbc478f812 | 33 | err = ALP_ERR_FILE_NOT_FOUND; |
Jeej | 0:a2bbc478f812 | 34 | } |
Jeej | 0:a2bbc478f812 | 35 | else |
Jeej | 0:a2bbc478f812 | 36 | { |
Jeej | 0:a2bbc478f812 | 37 | err = ALP_ERR_NONE; |
Jeej | 0:a2bbc478f812 | 38 | |
Jeej | 0:a2bbc478f812 | 39 | touch_t* touch = (touch_t*)MALLOC(sizeof(touch_t)); |
Jeej | 0:a2bbc478f812 | 40 | |
Jeej | 0:a2bbc478f812 | 41 | touch->fid = fid; |
Jeej | 0:a2bbc478f812 | 42 | touch->offset = offset; |
Jeej | 0:a2bbc478f812 | 43 | touch->length = length; |
Jeej | 0:a2bbc478f812 | 44 | |
Jeej | 0:a2bbc478f812 | 45 | g_file_modified.put(touch); |
Jeej | 0:a2bbc478f812 | 46 | } |
Jeej | 0:a2bbc478f812 | 47 | |
Jeej | 0:a2bbc478f812 | 48 | modem_respond(0, err, id); |
Jeej | 0:a2bbc478f812 | 49 | } |
Jeej | 0:a2bbc478f812 | 50 | |
Jeej | 0:a2bbc478f812 | 51 | void my_read_fprop(u8 fid, int id) |
Jeej | 0:a2bbc478f812 | 52 | { |
Jeej | 0:a2bbc478f812 | 53 | u8* hdr = (u8*)ram_fs_get_header(fid); |
Jeej | 0:a2bbc478f812 | 54 | |
Jeej | 0:a2bbc478f812 | 55 | if (hdr != NULL) |
Jeej | 0:a2bbc478f812 | 56 | { |
Jeej | 0:a2bbc478f812 | 57 | modem_respond_fprop(fid, hdr, id); |
Jeej | 0:a2bbc478f812 | 58 | } |
Jeej | 0:a2bbc478f812 | 59 | else |
Jeej | 0:a2bbc478f812 | 60 | { |
Jeej | 0:a2bbc478f812 | 61 | modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id); |
Jeej | 0:a2bbc478f812 | 62 | } |
Jeej | 0:a2bbc478f812 | 63 | } |
Jeej | 0:a2bbc478f812 | 64 | |
Jeej | 0:a2bbc478f812 | 65 | void my_flush(u8 fid, int id) |
Jeej | 0:a2bbc478f812 | 66 | { |
Jeej | 0:a2bbc478f812 | 67 | // No flush in this file system |
Jeej | 0:a2bbc478f812 | 68 | modem_respond(0, ALP_ERR_NONE, id); |
Jeej | 0:a2bbc478f812 | 69 | } |
Jeej | 0:a2bbc478f812 | 70 | |
Jeej | 0:a2bbc478f812 | 71 | void my_delete(u8 fid, int id) |
Jeej | 0:a2bbc478f812 | 72 | { |
Jeej | 0:a2bbc478f812 | 73 | modem_respond(0, (ram_fs_delete(fid))? ALP_ERR_FILE_NOT_FOUND : ALP_ERR_NONE, id); |
Jeej | 0:a2bbc478f812 | 74 | } |
Jeej | 0:a2bbc478f812 | 75 | |
Jeej | 0:a2bbc478f812 | 76 | void my_udata(u8 fid, void *data, u32 offset, u32 length, u8 i_type, u8 i_length, u8* i_data) |
Jeej | 0:a2bbc478f812 | 77 | { |
Jeej | 0:a2bbc478f812 | 78 | (void)data; |
Jeej | 0:a2bbc478f812 | 79 | (void)i_length; |
Jeej | 0:a2bbc478f812 | 80 | PRINT("Got UNS File[%3d]@%d %d Bytes\n",fid,offset,length); |
Jeej | 0:a2bbc478f812 | 81 | if (i_type == ALP_ITF_TYPE_D7A) |
Jeej | 0:a2bbc478f812 | 82 | { |
Jeej | 0:a2bbc478f812 | 83 | static union { |
Jeej | 0:a2bbc478f812 | 84 | u8 b[8]; |
Jeej | 0:a2bbc478f812 | 85 | u32 w[2]; |
Jeej | 0:a2bbc478f812 | 86 | } uid; |
Jeej | 0:a2bbc478f812 | 87 | d7a_sp_res_t* istat = (d7a_sp_res_t*) i_data; |
Jeej | 0:a2bbc478f812 | 88 | memcpy(uid.b,istat->addressee.id,8); |
Jeej | 0:a2bbc478f812 | 89 | PRINT("From UID: %08X%08X (rxlev:%d lb:%d)\n", |
Jeej | 0:a2bbc478f812 | 90 | HAL_U32_BYTE_SWAP(uid.w[0]), HAL_U32_BYTE_SWAP(uid.w[1]), |
Jeej | 0:a2bbc478f812 | 91 | istat->rxlev, istat->lb); |
Jeej | 0:a2bbc478f812 | 92 | } |
Jeej | 0:a2bbc478f812 | 93 | } |
Jeej | 0:a2bbc478f812 | 94 | |
Jeej | 0:a2bbc478f812 | 95 | void my_lqual(u8 ifid, int per) |
Jeej | 0:a2bbc478f812 | 96 | { |
Jeej | 0:a2bbc478f812 | 97 | PRINT("Interface File [%3d] LQUAL : %d%% PER\r\n", ifid, per); |
Jeej | 0:a2bbc478f812 | 98 | } |
Jeej | 0:a2bbc478f812 | 99 | |
Jeej | 0:a2bbc478f812 | 100 | void my_ldown(u8 ifid) |
Jeej | 0:a2bbc478f812 | 101 | { |
Jeej | 0:a2bbc478f812 | 102 | PRINT("Interface File [%3d] LDOWN\r\n", ifid); |
Jeej | 0:a2bbc478f812 | 103 | } |
Jeej | 0:a2bbc478f812 | 104 | |
Jeej | 0:a2bbc478f812 | 105 | void my_reset(void) |
Jeej | 0:a2bbc478f812 | 106 | { |
Jeej | 0:a2bbc478f812 | 107 | PRINT("Restarting application...\r\n"); |
Jeej | 0:a2bbc478f812 | 108 | FLUSH(); |
Jeej | 0:a2bbc478f812 | 109 | NVIC_SystemReset(); |
Jeej | 0:a2bbc478f812 | 110 | } |
Jeej | 0:a2bbc478f812 | 111 | |
Jeej | 0:a2bbc478f812 | 112 | void my_boot(u8 cause, u16 number) |
Jeej | 0:a2bbc478f812 | 113 | { |
Jeej | 0:a2bbc478f812 | 114 | PRINT("Modem BOOT[%c] #%d\r\n", cause, number); |
Jeej | 0:a2bbc478f812 | 115 | |
Jeej | 0:a2bbc478f812 | 116 | // Modem re-booted, restart APP |
Jeej | 0:a2bbc478f812 | 117 | my_reset(); |
Jeej | 0:a2bbc478f812 | 118 | } |