Complete sensor demo.

Dependencies:   modem_ref_helper X_NUCLEO_IKS01A1 DebouncedInterrupt

Committer:
Jeej
Date:
Thu Oct 11 15:15:30 2018 +0000
Revision:
14:8fd5405f7ab2
Parent:
11:9683d014dece
Child:
15:1271f3566b98
Relaxed modem version check.

Who changed what in which revision?

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