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