Data reception demo.

Dependencies:   modem_ref_helper

Committer:
Jeej
Date:
Thu May 18 13:46:00 2017 +0000
Revision:
4:854f22f7962b
Parent:
3:e9ea4d325c01
Child:
5:a44b6f60bfc7
Factorized libraries.

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 0:02418479dcf7 13 if (ram_fs_read(fid, offset, length, data))
Jeej 0:02418479dcf7 14 {
Jeej 0:02418479dcf7 15 modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id);
Jeej 0:02418479dcf7 16 }
Jeej 0:02418479dcf7 17 else
Jeej 0:02418479dcf7 18 {
Jeej 0:02418479dcf7 19 modem_respond_read(fid, data, offset, length, 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 3:e9ea4d325c01 25 alp_errors_t err;
Jeej 0:02418479dcf7 26
Jeej 3:e9ea4d325c01 27 if (ram_fs_write(fid, offset, length, (uint8_t*)data))
Jeej 3:e9ea4d325c01 28 {
Jeej 3:e9ea4d325c01 29 err = ALP_ERR_FILE_NOT_FOUND;
Jeej 3:e9ea4d325c01 30 }
Jeej 3:e9ea4d325c01 31 else
Jeej 3:e9ea4d325c01 32 {
Jeej 3:e9ea4d325c01 33 err = ALP_ERR_NONE;
Jeej 3:e9ea4d325c01 34 g_file_modified.put((void*)fid);
Jeej 3:e9ea4d325c01 35 }
Jeej 3:e9ea4d325c01 36
Jeej 3:e9ea4d325c01 37 modem_respond(0, err, id);
Jeej 0:02418479dcf7 38 }
Jeej 0:02418479dcf7 39
Jeej 0:02418479dcf7 40 void my_read_fprop(u8 fid, int id)
Jeej 0:02418479dcf7 41 {
Jeej 0:02418479dcf7 42 u8* hdr = (u8*)ram_fs_get_header(fid);
Jeej 0:02418479dcf7 43
Jeej 0:02418479dcf7 44 if (hdr != NULL)
Jeej 0:02418479dcf7 45 {
Jeej 0:02418479dcf7 46 modem_respond_fprop(fid, hdr, id);
Jeej 0:02418479dcf7 47 }
Jeej 0:02418479dcf7 48 else
Jeej 0:02418479dcf7 49 {
Jeej 0:02418479dcf7 50 modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id);
Jeej 0:02418479dcf7 51 }
Jeej 0:02418479dcf7 52 }
Jeej 0:02418479dcf7 53
Jeej 0:02418479dcf7 54 void my_flush(u8 fid, int id)
Jeej 0:02418479dcf7 55 {
Jeej 0:02418479dcf7 56 // No flush in this file system
Jeej 0:02418479dcf7 57 modem_respond(0, ALP_ERR_NONE, id);
Jeej 0:02418479dcf7 58 }
Jeej 0:02418479dcf7 59
Jeej 0:02418479dcf7 60 void my_delete(u8 fid, int id)
Jeej 0:02418479dcf7 61 {
Jeej 0:02418479dcf7 62 modem_respond(0, (ram_fs_delete(fid))? ALP_ERR_FILE_NOT_FOUND : ALP_ERR_NONE, id);
Jeej 0:02418479dcf7 63 }
Jeej 0:02418479dcf7 64
Jeej 3:e9ea4d325c01 65 void my_udata(u8 fid,void *data,u32 offset,u32 length, u8 i_type, u8 i_length, u8* i_data)
Jeej 3:e9ea4d325c01 66 {
Jeej 3:e9ea4d325c01 67 (void)data;
Jeej 3:e9ea4d325c01 68 (void)i_length;
Jeej 3:e9ea4d325c01 69 PRINT("Got UNS File[%3d]@%d %d Bytes\n",fid,offset,length);
Jeej 3:e9ea4d325c01 70 if (i_type == ALP_ITF_TYPE_D7A)
Jeej 3:e9ea4d325c01 71 {
Jeej 3:e9ea4d325c01 72 static union {
Jeej 3:e9ea4d325c01 73 u8 b[8];
Jeej 3:e9ea4d325c01 74 u32 w[2];
Jeej 3:e9ea4d325c01 75 } uid;
Jeej 3:e9ea4d325c01 76 d7a_sp_res_t* istat = (d7a_sp_res_t*) i_data;
Jeej 3:e9ea4d325c01 77 memcpy(uid.b,istat->addressee.id,8);
Jeej 3:e9ea4d325c01 78 PRINT("From UID: %08X%08X (rxlev:%d lb:%d)\n",
Jeej 3:e9ea4d325c01 79 HAL_U32_BYTE_SWAP(uid.w[0]), HAL_U32_BYTE_SWAP(uid.w[1]),
Jeej 3:e9ea4d325c01 80 istat->rxlev, istat->lb);
Jeej 3:e9ea4d325c01 81 }
Jeej 3:e9ea4d325c01 82 }
Jeej 3:e9ea4d325c01 83
Jeej 0:02418479dcf7 84 void my_lqual(u8 ifid, int per)
Jeej 0:02418479dcf7 85 {
Jeej 2:6652be2d061f 86 PRINT("Interface File [%3d] LQUAL : %d%% PER\r\n", ifid, per);
Jeej 0:02418479dcf7 87 }
Jeej 0:02418479dcf7 88
Jeej 0:02418479dcf7 89 void my_ldown(u8 ifid)
Jeej 0:02418479dcf7 90 {
Jeej 2:6652be2d061f 91 PRINT("Interface File [%3d] LDOWN\r\n", ifid);
Jeej 0:02418479dcf7 92 }
Jeej 0:02418479dcf7 93
Jeej 0:02418479dcf7 94 void my_reset(void)
Jeej 0:02418479dcf7 95 {
Jeej 0:02418479dcf7 96 NVIC_SystemReset();
Jeej 0:02418479dcf7 97 }
Jeej 0:02418479dcf7 98
Jeej 0:02418479dcf7 99 void my_boot(u8 cause, u16 number)
Jeej 0:02418479dcf7 100 {
Jeej 2:6652be2d061f 101 PRINT("Modem BOOT[%c] #%d\r\nRe-Init\r\n", cause, number);
Jeej 0:02418479dcf7 102
Jeej 0:02418479dcf7 103 // Modem re-booted, restart APP
Jeej 0:02418479dcf7 104 my_reset();
Jeej 0:02418479dcf7 105 }