Data reception demo.

Dependencies:   modem_ref_helper

Committer:
Jeej
Date:
Thu Sep 21 13:50:17 2017 +0000
Revision:
5:a44b6f60bfc7
Parent:
4:854f22f7962b
Child:
9:72a15235e097
Updated for 4.10.x

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 3:e9ea4d325c01 61 void my_udata(u8 fid,void *data,u32 offset,u32 length, u8 i_type, u8 i_length, u8* i_data)
Jeej 3:e9ea4d325c01 62 {
Jeej 3:e9ea4d325c01 63 (void)data;
Jeej 3:e9ea4d325c01 64 (void)i_length;
Jeej 3:e9ea4d325c01 65 PRINT("Got UNS File[%3d]@%d %d Bytes\n",fid,offset,length);
Jeej 3:e9ea4d325c01 66 if (i_type == ALP_ITF_TYPE_D7A)
Jeej 3:e9ea4d325c01 67 {
Jeej 3:e9ea4d325c01 68 static union {
Jeej 3:e9ea4d325c01 69 u8 b[8];
Jeej 3:e9ea4d325c01 70 u32 w[2];
Jeej 3:e9ea4d325c01 71 } uid;
Jeej 3:e9ea4d325c01 72 d7a_sp_res_t* istat = (d7a_sp_res_t*) i_data;
Jeej 3:e9ea4d325c01 73 memcpy(uid.b,istat->addressee.id,8);
Jeej 3:e9ea4d325c01 74 PRINT("From UID: %08X%08X (rxlev:%d lb:%d)\n",
Jeej 3:e9ea4d325c01 75 HAL_U32_BYTE_SWAP(uid.w[0]), HAL_U32_BYTE_SWAP(uid.w[1]),
Jeej 3:e9ea4d325c01 76 istat->rxlev, istat->lb);
Jeej 3:e9ea4d325c01 77 }
Jeej 3:e9ea4d325c01 78 }
Jeej 3:e9ea4d325c01 79
Jeej 0:02418479dcf7 80 void my_lqual(u8 ifid, int per)
Jeej 0:02418479dcf7 81 {
Jeej 2:6652be2d061f 82 PRINT("Interface File [%3d] LQUAL : %d%% PER\r\n", ifid, per);
Jeej 0:02418479dcf7 83 }
Jeej 0:02418479dcf7 84
Jeej 0:02418479dcf7 85 void my_ldown(u8 ifid)
Jeej 0:02418479dcf7 86 {
Jeej 2:6652be2d061f 87 PRINT("Interface File [%3d] LDOWN\r\n", ifid);
Jeej 0:02418479dcf7 88 }
Jeej 0:02418479dcf7 89
Jeej 0:02418479dcf7 90 void my_reset(void)
Jeej 0:02418479dcf7 91 {
Jeej 5:a44b6f60bfc7 92 PRINT("Restarting application...\r\n");
Jeej 5:a44b6f60bfc7 93 FLUSH();
Jeej 0:02418479dcf7 94 NVIC_SystemReset();
Jeej 0:02418479dcf7 95 }
Jeej 0:02418479dcf7 96
Jeej 0:02418479dcf7 97 void my_boot(u8 cause, u16 number)
Jeej 0:02418479dcf7 98 {
Jeej 5:a44b6f60bfc7 99 PRINT("Modem BOOT[%c] #%d\r\n", cause, number);
Jeej 0:02418479dcf7 100
Jeej 0:02418479dcf7 101 // Modem re-booted, restart APP
Jeej 0:02418479dcf7 102 my_reset();
Jeej 0:02418479dcf7 103 }