Complete sensor demo.
Dependencies: modem_ref_helper CRC X_NUCLEO_IKS01A1 DebouncedInterrupt
modem_callbacks.cpp@18:51b15d8bf2fe, 2021-10-29 (annotated)
- Committer:
- marin_wizzi
- Date:
- Fri Oct 29 12:55:52 2021 +0000
- Revision:
- 18:51b15d8bf2fe
- Parent:
- 15:1271f3566b98
Compatible with 6.2 modem version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marin_wizzi | 18:51b15d8bf2fe | 1 | #include "modem_d7a.h" |
marin_wizzi | 18:51b15d8bf2fe | 2 | #include "files.h" |
Jeej | 0:87c57e1b1e1c | 3 | |
Jeej | 15:1271f3566b98 | 4 | #define SERIAL_MAX_PACKET_SIZE (255) |
Jeej | 0:87c57e1b1e1c | 5 | |
Jeej | 0:87c57e1b1e1c | 6 | // ============================================================}}} |
Jeej | 0:87c57e1b1e1c | 7 | |
Jeej | 0:87c57e1b1e1c | 8 | // Callbacks to MODEM's ALP requests |
Jeej | 0:87c57e1b1e1c | 9 | // ============================================================{{{ |
marin_wizzi | 18:51b15d8bf2fe | 10 | void my_read(u8 action, u8 fid, u32 offset, u32 length, int id) |
Jeej | 0:87c57e1b1e1c | 11 | { |
Jeej | 15:1271f3566b98 | 12 | u8 data[SERIAL_MAX_PACKET_SIZE]; |
Jeej | 0:87c57e1b1e1c | 13 | |
Jeej | 15:1271f3566b98 | 14 | ASSERT((ALP_ACTION_RSP_TAG_SIZE + ALP_ACTION_RSP_F_DATA_SIZE(offset, length)) <= SERIAL_MAX_PACKET_SIZE, |
marin_wizzi | 18:51b15d8bf2fe | 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)); |
marin_wizzi | 18:51b15d8bf2fe | 16 | |
marin_wizzi | 18:51b15d8bf2fe | 17 | if (ram_fs_read(fid, data, offset, length)) |
Jeej | 0:87c57e1b1e1c | 18 | { |
marin_wizzi | 18:51b15d8bf2fe | 19 | modem_ref_respond(action, ALP_ERR_FILE_NOT_FOUND, id); |
Jeej | 0:87c57e1b1e1c | 20 | } |
Jeej | 15:1271f3566b98 | 21 | else |
Jeej | 15:1271f3566b98 | 22 | { |
marin_wizzi | 18:51b15d8bf2fe | 23 | modem_ref_respond_read(fid, data, offset, length, id); |
Jeej | 15:1271f3566b98 | 24 | } |
Jeej | 0:87c57e1b1e1c | 25 | } |
Jeej | 0:87c57e1b1e1c | 26 | |
marin_wizzi | 18:51b15d8bf2fe | 27 | |
marin_wizzi | 18:51b15d8bf2fe | 28 | void my_write(u8 action, u8 fid, void *data, u32 offset, u32 length, int id) |
Jeej | 0:87c57e1b1e1c | 29 | { |
Jeej | 0:87c57e1b1e1c | 30 | alp_errors_t err; |
Jeej | 0:87c57e1b1e1c | 31 | |
marin_wizzi | 18:51b15d8bf2fe | 32 | if (ram_fs_write(fid, (uint8_t*)data, offset, length)) |
Jeej | 0:87c57e1b1e1c | 33 | { |
Jeej | 0:87c57e1b1e1c | 34 | err = ALP_ERR_FILE_NOT_FOUND; |
Jeej | 0:87c57e1b1e1c | 35 | } |
Jeej | 0:87c57e1b1e1c | 36 | else |
Jeej | 0:87c57e1b1e1c | 37 | { |
Jeej | 0:87c57e1b1e1c | 38 | err = ALP_ERR_NONE; |
marin_wizzi | 18:51b15d8bf2fe | 39 | |
marin_wizzi | 18:51b15d8bf2fe | 40 | touch_t* touch = (touch_t*)MALLOC(sizeof(touch_t)); |
marin_wizzi | 18:51b15d8bf2fe | 41 | |
marin_wizzi | 18:51b15d8bf2fe | 42 | touch->fid = fid; |
marin_wizzi | 18:51b15d8bf2fe | 43 | touch->offset = offset; |
marin_wizzi | 18:51b15d8bf2fe | 44 | touch->length = length; |
marin_wizzi | 18:51b15d8bf2fe | 45 | |
marin_wizzi | 18:51b15d8bf2fe | 46 | g_file_modified.put(touch); |
Jeej | 0:87c57e1b1e1c | 47 | } |
Jeej | 0:87c57e1b1e1c | 48 | |
marin_wizzi | 18:51b15d8bf2fe | 49 | modem_ref_respond(action, err, id); |
Jeej | 0:87c57e1b1e1c | 50 | } |
Jeej | 0:87c57e1b1e1c | 51 | |
marin_wizzi | 18:51b15d8bf2fe | 52 | void my_read_fprop(u8 action, u8 fid, int id) |
Jeej | 0:87c57e1b1e1c | 53 | { |
Jeej | 0:87c57e1b1e1c | 54 | u8* hdr = (u8*)ram_fs_get_header(fid); |
Jeej | 0:87c57e1b1e1c | 55 | |
marin_wizzi | 18:51b15d8bf2fe | 56 | if (hdr != NULL) |
marin_wizzi | 18:51b15d8bf2fe | 57 | { |
marin_wizzi | 18:51b15d8bf2fe | 58 | modem_ref_respond_fprop(fid, (alp_file_header_t*)hdr, id); |
marin_wizzi | 18:51b15d8bf2fe | 59 | } |
marin_wizzi | 18:51b15d8bf2fe | 60 | else |
marin_wizzi | 18:51b15d8bf2fe | 61 | { |
marin_wizzi | 18:51b15d8bf2fe | 62 | modem_ref_respond(action, ALP_ERR_FILE_NOT_FOUND, id); |
marin_wizzi | 18:51b15d8bf2fe | 63 | } |
Jeej | 0:87c57e1b1e1c | 64 | } |
Jeej | 0:87c57e1b1e1c | 65 | |
marin_wizzi | 18:51b15d8bf2fe | 66 | void my_flush(u8 action, u8 fid, int id) |
marin_wizzi | 18:51b15d8bf2fe | 67 | { |
marin_wizzi | 18:51b15d8bf2fe | 68 | // No flush in this file system |
marin_wizzi | 18:51b15d8bf2fe | 69 | modem_ref_respond(action, ALP_ERR_NONE, id); |
marin_wizzi | 18:51b15d8bf2fe | 70 | } |
marin_wizzi | 18:51b15d8bf2fe | 71 | |
marin_wizzi | 18:51b15d8bf2fe | 72 | void my_delete(u8 action, u8 fid, int id) |
marin_wizzi | 18:51b15d8bf2fe | 73 | { |
marin_wizzi | 18:51b15d8bf2fe | 74 | modem_ref_respond(action, (ram_fs_delete(fid))? ALP_ERR_FILE_NOT_FOUND : ALP_ERR_NONE, id); |
marin_wizzi | 18:51b15d8bf2fe | 75 | } |
marin_wizzi | 18:51b15d8bf2fe | 76 | |
marin_wizzi | 18:51b15d8bf2fe | 77 | void my_udata(alp_payload_t* alp) |
marin_wizzi | 18:51b15d8bf2fe | 78 | { |
marin_wizzi | 18:51b15d8bf2fe | 79 | alp_payload_print(alp); |
Jeej | 1:4d3968b2941b | 80 | } |
Jeej | 1:4d3968b2941b | 81 | |
Jeej | 0:87c57e1b1e1c | 82 | void my_lqual(u8 ifid, int per) |
Jeej | 0:87c57e1b1e1c | 83 | { |
Jeej | 0:87c57e1b1e1c | 84 | PRINT("Interface File [%3d] LQUAL : %d%% PER\r\n", ifid, per); |
Jeej | 0:87c57e1b1e1c | 85 | } |
Jeej | 0:87c57e1b1e1c | 86 | |
Jeej | 0:87c57e1b1e1c | 87 | void my_ldown(u8 ifid) |
Jeej | 0:87c57e1b1e1c | 88 | { |
Jeej | 0:87c57e1b1e1c | 89 | PRINT("Interface File [%3d] LDOWN\r\n", ifid); |
Jeej | 0:87c57e1b1e1c | 90 | } |
Jeej | 0:87c57e1b1e1c | 91 | |
Jeej | 0:87c57e1b1e1c | 92 | void my_reset(void) |
Jeej | 0:87c57e1b1e1c | 93 | { |
Jeej | 6:c17f7cbdeb1a | 94 | PRINT("Restarting application...\r\n"); |
Jeej | 6:c17f7cbdeb1a | 95 | FLUSH(); |
Jeej | 0:87c57e1b1e1c | 96 | NVIC_SystemReset(); |
Jeej | 0:87c57e1b1e1c | 97 | } |
Jeej | 0:87c57e1b1e1c | 98 | |
Jeej | 0:87c57e1b1e1c | 99 | void my_boot(u8 cause, u16 number) |
Jeej | 0:87c57e1b1e1c | 100 | { |
Jeej | 6:c17f7cbdeb1a | 101 | PRINT("Modem BOOT[%c] #%d\r\n", cause, number); |
Jeej | 0:87c57e1b1e1c | 102 | |
Jeej | 0:87c57e1b1e1c | 103 | // Modem re-booted, restart APP |
Jeej | 0:87c57e1b1e1c | 104 | my_reset(); |
Jeej | 11:9683d014dece | 105 | } |
Jeej | 11:9683d014dece | 106 | |
Jeej | 11:9683d014dece | 107 | void my_busy(u8 busy) |
Jeej | 11:9683d014dece | 108 | { |
Jeej | 11:9683d014dece | 109 | if (busy) |
Jeej | 11:9683d014dece | 110 | { |
Jeej | 11:9683d014dece | 111 | PRINT("Modem Busy\r\n"); |
Jeej | 11:9683d014dece | 112 | |
Jeej | 11:9683d014dece | 113 | /* Stop report, do not use modem */ |
Jeej | 11:9683d014dece | 114 | /* Wait for modem reboot or modem not busy */ |
Jeej | 11:9683d014dece | 115 | } |
Jeej | 11:9683d014dece | 116 | else |
Jeej | 11:9683d014dece | 117 | { |
Jeej | 11:9683d014dece | 118 | PRINT("Modem not Busy\r\n"); |
Jeej | 11:9683d014dece | 119 | |
Jeej | 11:9683d014dece | 120 | /* Resume reports */ |
Jeej | 11:9683d014dece | 121 | } |
Jeej | 0:87c57e1b1e1c | 122 | } |