Data reception demo.

Dependencies:   modem_ref_helper

Committer:
Jeej
Date:
Wed May 17 14:38:25 2017 +0000
Revision:
3:e9ea4d325c01
Parent:
2:6652be2d061f
Child:
4:854f22f7962b
Added modem version check.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jeej 0:02418479dcf7 1 #include "mbed.h"
Jeej 0:02418479dcf7 2 #include "rtos.h"
Jeej 0:02418479dcf7 3 #include "WizziDebug.h"
Jeej 0:02418479dcf7 4
Jeej 0:02418479dcf7 5 #include "alp_spec.h"
Jeej 0:02418479dcf7 6 #include "alp_helpers.h"
Jeej 0:02418479dcf7 7 #include "modem_ref.h"
Jeej 3:e9ea4d325c01 8 #include "d7a_1x.h"
Jeej 0:02418479dcf7 9
Jeej 0:02418479dcf7 10 #include "ram_fs.h"
Jeej 0:02418479dcf7 11 #include "hal_types.h"
Jeej 0:02418479dcf7 12
Jeej 0:02418479dcf7 13 extern Queue<void, 8> g_file_modified;
Jeej 0:02418479dcf7 14
Jeej 0:02418479dcf7 15 // ============================================================}}}
Jeej 0:02418479dcf7 16
Jeej 0:02418479dcf7 17 // Callbacks to MODEM's ALP requests
Jeej 0:02418479dcf7 18 // ============================================================{{{
Jeej 0:02418479dcf7 19 void my_read(u8 fid, u32 offset, u32 length, int id)
Jeej 0:02418479dcf7 20 {
Jeej 0:02418479dcf7 21 u8 data[256];
Jeej 0:02418479dcf7 22
Jeej 0:02418479dcf7 23 if (ram_fs_read(fid, offset, length, data))
Jeej 0:02418479dcf7 24 {
Jeej 0:02418479dcf7 25 modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id);
Jeej 0:02418479dcf7 26 }
Jeej 0:02418479dcf7 27 else
Jeej 0:02418479dcf7 28 {
Jeej 0:02418479dcf7 29 modem_respond_read(fid, data, offset, length, id);
Jeej 0:02418479dcf7 30 }
Jeej 0:02418479dcf7 31 }
Jeej 0:02418479dcf7 32
Jeej 0:02418479dcf7 33 void my_write(u8 fid, void *data, u32 offset, u32 length, int id)
Jeej 0:02418479dcf7 34 {
Jeej 3:e9ea4d325c01 35 alp_errors_t err;
Jeej 0:02418479dcf7 36
Jeej 3:e9ea4d325c01 37 if (ram_fs_write(fid, offset, length, (uint8_t*)data))
Jeej 3:e9ea4d325c01 38 {
Jeej 3:e9ea4d325c01 39 err = ALP_ERR_FILE_NOT_FOUND;
Jeej 3:e9ea4d325c01 40 }
Jeej 3:e9ea4d325c01 41 else
Jeej 3:e9ea4d325c01 42 {
Jeej 3:e9ea4d325c01 43 err = ALP_ERR_NONE;
Jeej 3:e9ea4d325c01 44 g_file_modified.put((void*)fid);
Jeej 3:e9ea4d325c01 45 }
Jeej 3:e9ea4d325c01 46
Jeej 3:e9ea4d325c01 47 modem_respond(0, err, id);
Jeej 0:02418479dcf7 48 }
Jeej 0:02418479dcf7 49
Jeej 0:02418479dcf7 50 void my_read_fprop(u8 fid, int id)
Jeej 0:02418479dcf7 51 {
Jeej 0:02418479dcf7 52 u8* hdr = (u8*)ram_fs_get_header(fid);
Jeej 0:02418479dcf7 53
Jeej 0:02418479dcf7 54 if (hdr != NULL)
Jeej 0:02418479dcf7 55 {
Jeej 0:02418479dcf7 56 modem_respond_fprop(fid, hdr, id);
Jeej 0:02418479dcf7 57 }
Jeej 0:02418479dcf7 58 else
Jeej 0:02418479dcf7 59 {
Jeej 0:02418479dcf7 60 modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id);
Jeej 0:02418479dcf7 61 }
Jeej 0:02418479dcf7 62 }
Jeej 0:02418479dcf7 63
Jeej 0:02418479dcf7 64 void my_flush(u8 fid, int id)
Jeej 0:02418479dcf7 65 {
Jeej 0:02418479dcf7 66 // No flush in this file system
Jeej 0:02418479dcf7 67 modem_respond(0, ALP_ERR_NONE, id);
Jeej 0:02418479dcf7 68 }
Jeej 0:02418479dcf7 69
Jeej 0:02418479dcf7 70 void my_delete(u8 fid, int id)
Jeej 0:02418479dcf7 71 {
Jeej 0:02418479dcf7 72 modem_respond(0, (ram_fs_delete(fid))? ALP_ERR_FILE_NOT_FOUND : ALP_ERR_NONE, id);
Jeej 0:02418479dcf7 73 }
Jeej 0:02418479dcf7 74
Jeej 3:e9ea4d325c01 75 void my_udata(u8 fid,void *data,u32 offset,u32 length, u8 i_type, u8 i_length, u8* i_data)
Jeej 3:e9ea4d325c01 76 {
Jeej 3:e9ea4d325c01 77 (void)data;
Jeej 3:e9ea4d325c01 78 (void)i_length;
Jeej 3:e9ea4d325c01 79 PRINT("Got UNS File[%3d]@%d %d Bytes\n",fid,offset,length);
Jeej 3:e9ea4d325c01 80 if (i_type == ALP_ITF_TYPE_D7A)
Jeej 3:e9ea4d325c01 81 {
Jeej 3:e9ea4d325c01 82 static union {
Jeej 3:e9ea4d325c01 83 u8 b[8];
Jeej 3:e9ea4d325c01 84 u32 w[2];
Jeej 3:e9ea4d325c01 85 } uid;
Jeej 3:e9ea4d325c01 86 d7a_sp_res_t* istat = (d7a_sp_res_t*) i_data;
Jeej 3:e9ea4d325c01 87 memcpy(uid.b,istat->addressee.id,8);
Jeej 3:e9ea4d325c01 88 PRINT("From UID: %08X%08X (rxlev:%d lb:%d)\n",
Jeej 3:e9ea4d325c01 89 HAL_U32_BYTE_SWAP(uid.w[0]), HAL_U32_BYTE_SWAP(uid.w[1]),
Jeej 3:e9ea4d325c01 90 istat->rxlev, istat->lb);
Jeej 3:e9ea4d325c01 91 }
Jeej 3:e9ea4d325c01 92 }
Jeej 3:e9ea4d325c01 93
Jeej 0:02418479dcf7 94 void my_lqual(u8 ifid, int per)
Jeej 0:02418479dcf7 95 {
Jeej 2:6652be2d061f 96 PRINT("Interface File [%3d] LQUAL : %d%% PER\r\n", ifid, per);
Jeej 0:02418479dcf7 97 }
Jeej 0:02418479dcf7 98
Jeej 0:02418479dcf7 99 void my_ldown(u8 ifid)
Jeej 0:02418479dcf7 100 {
Jeej 2:6652be2d061f 101 PRINT("Interface File [%3d] LDOWN\r\n", ifid);
Jeej 0:02418479dcf7 102 }
Jeej 0:02418479dcf7 103
Jeej 0:02418479dcf7 104 void my_reset(void)
Jeej 0:02418479dcf7 105 {
Jeej 0:02418479dcf7 106 NVIC_SystemReset();
Jeej 0:02418479dcf7 107 }
Jeej 0:02418479dcf7 108
Jeej 0:02418479dcf7 109 void my_boot(u8 cause, u16 number)
Jeej 0:02418479dcf7 110 {
Jeej 2:6652be2d061f 111 PRINT("Modem BOOT[%c] #%d\r\nRe-Init\r\n", cause, number);
Jeej 0:02418479dcf7 112
Jeej 0:02418479dcf7 113 // Modem re-booted, restart APP
Jeej 0:02418479dcf7 114 my_reset();
Jeej 0:02418479dcf7 115 }