Data reception demo.

Dependencies:   modem_ref_helper

Committer:
Jeej
Date:
Thu Oct 11 14:46:39 2018 +0000
Revision:
11:7df24b241621
Parent:
9:72a15235e097
Child:
12:404a3ca64a44
Activate stack errors. Relaxed modem version check.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jeej 4:854f22f7962b 1 #include "modem_ref_helper.h"
Jeej 0:02418479dcf7 2
Jeej 0:02418479dcf7 3 extern Queue<void, 8> g_file_modified;
Jeej 0:02418479dcf7 4
Jeej 0:02418479dcf7 5 // ============================================================}}}
Jeej 0:02418479dcf7 6
Jeej 0:02418479dcf7 7 // Callbacks to MODEM's ALP requests
Jeej 0:02418479dcf7 8 // ============================================================{{{
Jeej 0:02418479dcf7 9 void my_read(u8 fid, u32 offset, u32 length, int id)
Jeej 0:02418479dcf7 10 {
Jeej 0:02418479dcf7 11 u8 data[256];
Jeej 0:02418479dcf7 12
Jeej 5:a44b6f60bfc7 13 if (!ram_fs_read(fid, offset, length, data))
Jeej 0:02418479dcf7 14 {
Jeej 5:a44b6f60bfc7 15 modem_respond_read(fid, data, offset, length, id);
Jeej 0:02418479dcf7 16 }
Jeej 0:02418479dcf7 17 else
Jeej 0:02418479dcf7 18 {
Jeej 5:a44b6f60bfc7 19 modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id);
Jeej 0:02418479dcf7 20 }
Jeej 0:02418479dcf7 21 }
Jeej 0:02418479dcf7 22
Jeej 0:02418479dcf7 23 void my_write(u8 fid, void *data, u32 offset, u32 length, int id)
Jeej 0:02418479dcf7 24 {
Jeej 5:a44b6f60bfc7 25 if (!ram_fs_write(fid, offset, length, (uint8_t*)data))
Jeej 3:e9ea4d325c01 26 {
Jeej 5:a44b6f60bfc7 27 modem_respond(0, ALP_ERR_NONE, id);
Jeej 5:a44b6f60bfc7 28 g_file_modified.put((void*)fid);
Jeej 3:e9ea4d325c01 29 }
Jeej 3:e9ea4d325c01 30 else
Jeej 3:e9ea4d325c01 31 {
Jeej 5:a44b6f60bfc7 32 modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id);
Jeej 5:a44b6f60bfc7 33 }
Jeej 0:02418479dcf7 34 }
Jeej 0:02418479dcf7 35
Jeej 0:02418479dcf7 36 void my_read_fprop(u8 fid, int id)
Jeej 0:02418479dcf7 37 {
Jeej 0:02418479dcf7 38 u8* hdr = (u8*)ram_fs_get_header(fid);
Jeej 0:02418479dcf7 39
Jeej 0:02418479dcf7 40 if (hdr != NULL)
Jeej 0:02418479dcf7 41 {
Jeej 0:02418479dcf7 42 modem_respond_fprop(fid, hdr, id);
Jeej 0:02418479dcf7 43 }
Jeej 0:02418479dcf7 44 else
Jeej 0:02418479dcf7 45 {
Jeej 0:02418479dcf7 46 modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id);
Jeej 0:02418479dcf7 47 }
Jeej 0:02418479dcf7 48 }
Jeej 0:02418479dcf7 49
Jeej 0:02418479dcf7 50 void my_flush(u8 fid, int id)
Jeej 0:02418479dcf7 51 {
Jeej 0:02418479dcf7 52 // No flush in this file system
Jeej 0:02418479dcf7 53 modem_respond(0, ALP_ERR_NONE, id);
Jeej 0:02418479dcf7 54 }
Jeej 0:02418479dcf7 55
Jeej 0:02418479dcf7 56 void my_delete(u8 fid, int id)
Jeej 0:02418479dcf7 57 {
Jeej 0:02418479dcf7 58 modem_respond(0, (ram_fs_delete(fid))? ALP_ERR_FILE_NOT_FOUND : ALP_ERR_NONE, id);
Jeej 0:02418479dcf7 59 }
Jeej 0:02418479dcf7 60
Jeej 9:72a15235e097 61 void my_udata(void *data, u32 length)
Jeej 9:72a15235e097 62 {
Jeej 9:72a15235e097 63 uint8_t* p = (uint8_t*)data;
Jeej 9:72a15235e097 64 int32_t rem = length;
Jeej 9:72a15235e097 65 alp_parsed_chunk_t r;
Jeej 9:72a15235e097 66 d7a_sp_res_t* istat;
Jeej 9:72a15235e097 67
Jeej 9:72a15235e097 68 do {
Jeej 9:72a15235e097 69 uint32_t parsed = alp_parse_chunk(&p, &r);
Jeej 9:72a15235e097 70 if (!parsed)
Jeej 9:72a15235e097 71 {
Jeej 9:72a15235e097 72 // Discard the payload in case of parsing error.
Jeej 9:72a15235e097 73 PRINT("Parsing error!\r\n");
Jeej 9:72a15235e097 74 break;
Jeej 9:72a15235e097 75 }
Jeej 9:72a15235e097 76 rem -= parsed;
Jeej 9:72a15235e097 77
Jeej 9:72a15235e097 78 switch (r.type)
Jeej 9:72a15235e097 79 {
Jeej 9:72a15235e097 80 // Interface status
Jeej 9:72a15235e097 81 case ALP_OPCODE_RSP_ISTATUS:
Jeej 9:72a15235e097 82 // D7A Interface
Jeej 9:72a15235e097 83 if (ALP_ITF_TYPE_D7A == r.meta.itf.type)
Jeej 9:72a15235e097 84 {
Jeej 9:72a15235e097 85 union {
Jeej 9:72a15235e097 86 u8 b[8];
Jeej 9:72a15235e097 87 u32 w[2];
Jeej 9:72a15235e097 88 } uid;
Jeej 9:72a15235e097 89
Jeej 9:72a15235e097 90 // ISTATUS can come either alone or together with ALP_OPCODE_RSP_F_DATA
Jeej 9:72a15235e097 91 // but there should be only one per payload, moreover it will come first
Jeej 9:72a15235e097 92 istat = (d7a_sp_res_t*)r.data;
Jeej 9:72a15235e097 93 memcpy(uid.b,istat->addressee.id,8);
Jeej 9:72a15235e097 94
Jeej 9:72a15235e097 95 PRINT("Got accessed by UID:%08X%08X SNR: %3ddB RXLEV: -%-3ddBm LB: %3ddB\n",
Jeej 9:72a15235e097 96 HAL_U32_BYTE_SWAP(uid.w[0]), HAL_U32_BYTE_SWAP(uid.w[1]),
Jeej 9:72a15235e097 97 istat->snr, istat->rxlev, istat->lb);
Jeej 9:72a15235e097 98 }
Jeej 9:72a15235e097 99 else
Jeej 9:72a15235e097 100 {
Jeej 9:72a15235e097 101 PRINT("Got accessed by unknown Interface 0x%02X\n", r.meta.itf.type);
Jeej 9:72a15235e097 102 }
Jeej 9:72a15235e097 103 break;
Jeej 9:72a15235e097 104 // Data return
Jeej 9:72a15235e097 105 case ALP_OPCODE_RSP_F_DATA:
Jeej 9:72a15235e097 106 // RSP_F_DATA can come either alone or together with ISTATUS
Jeej 9:72a15235e097 107 PRINT("Got UNS File[%3d]@%d %d Bytes\n", r.meta.f_data.fid, r.meta.f_data.offset, r.meta.f_data.length);
Jeej 9:72a15235e097 108 break;
Jeej 9:72a15235e097 109 default:
Jeej 9:72a15235e097 110 PRINT("Untreated OPCODE %d\n", r.type);
Jeej 9:72a15235e097 111 break;
Jeej 9:72a15235e097 112 }
Jeej 9:72a15235e097 113 } while (rem > 0);
Jeej 3:e9ea4d325c01 114 }
Jeej 3:e9ea4d325c01 115
Jeej 0:02418479dcf7 116 void my_lqual(u8 ifid, int per)
Jeej 0:02418479dcf7 117 {
Jeej 2:6652be2d061f 118 PRINT("Interface File [%3d] LQUAL : %d%% PER\r\n", ifid, per);
Jeej 0:02418479dcf7 119 }
Jeej 0:02418479dcf7 120
Jeej 0:02418479dcf7 121 void my_ldown(u8 ifid)
Jeej 0:02418479dcf7 122 {
Jeej 2:6652be2d061f 123 PRINT("Interface File [%3d] LDOWN\r\n", ifid);
Jeej 0:02418479dcf7 124 }
Jeej 0:02418479dcf7 125
Jeej 0:02418479dcf7 126 void my_reset(void)
Jeej 0:02418479dcf7 127 {
Jeej 5:a44b6f60bfc7 128 PRINT("Restarting application...\r\n");
Jeej 5:a44b6f60bfc7 129 FLUSH();
Jeej 0:02418479dcf7 130 NVIC_SystemReset();
Jeej 0:02418479dcf7 131 }
Jeej 0:02418479dcf7 132
Jeej 0:02418479dcf7 133 void my_boot(u8 cause, u16 number)
Jeej 0:02418479dcf7 134 {
Jeej 5:a44b6f60bfc7 135 PRINT("Modem BOOT[%c] #%d\r\n", cause, number);
Jeej 0:02418479dcf7 136
Jeej 0:02418479dcf7 137 // Modem re-booted, restart APP
Jeej 0:02418479dcf7 138 my_reset();
Jeej 9:72a15235e097 139 }
Jeej 9:72a15235e097 140
Jeej 9:72a15235e097 141 void my_busy(u8 busy)
Jeej 9:72a15235e097 142 {
Jeej 9:72a15235e097 143 if (busy)
Jeej 9:72a15235e097 144 {
Jeej 9:72a15235e097 145 PRINT("Modem Busy\r\n");
Jeej 9:72a15235e097 146
Jeej 9:72a15235e097 147 /* Stop report, do not use modem */
Jeej 9:72a15235e097 148 /* Wait for modem reboot or modem not busy */
Jeej 9:72a15235e097 149 }
Jeej 9:72a15235e097 150 else
Jeej 9:72a15235e097 151 {
Jeej 9:72a15235e097 152 PRINT("Modem not Busy\r\n");
Jeej 9:72a15235e097 153
Jeej 9:72a15235e097 154 /* Resume reports */
Jeej 9:72a15235e097 155 }
Jeej 0:02418479dcf7 156 }