Send file data through D7A Action Protocol demo.

Dependencies:   modem_ref_helper

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers modem_callbacks.cpp Source File

modem_callbacks.cpp

00001 #include "modem_ref_helper.h"
00002 
00003 extern Queue<void, 8>   g_file_modified;
00004 
00005 // ============================================================}}}
00006 
00007 // Callbacks to MODEM's ALP requests
00008 // ============================================================{{{
00009 void my_read(u8 fid, u32 offset, u32 length, int id)
00010 {
00011     u8 data[256];
00012     
00013     if (ram_fs_read(fid, offset, length, data))
00014     {
00015         modem_respond(ALP_ERR_FILE_NOT_FOUND, id);
00016     }
00017     else
00018     {
00019         modem_respond_read(fid, data, offset, length, id);
00020     }
00021 }
00022 
00023 void my_write(u8 fid, void *data, u32 offset, u32 length, int id)
00024 {
00025     alp_errors_t err;
00026     
00027     if (ram_fs_write(fid, offset, length, (uint8_t*)data))
00028     {
00029         err = ALP_ERR_FILE_NOT_FOUND;
00030     }
00031     else
00032     {
00033         err = ALP_ERR_NONE;
00034         g_file_modified.put((void*)fid);
00035     }
00036     
00037     modem_respond(err, id);
00038 }
00039 
00040 void my_read_fprop(u8 fid, int id)
00041 {
00042     u8* hdr = (u8*)ram_fs_get_header(fid);
00043     
00044     if (hdr != NULL)
00045     {
00046         modem_respond_fprop(fid, hdr, id);
00047     }
00048     else
00049     {
00050         modem_respond(ALP_ERR_FILE_NOT_FOUND, id);
00051     }
00052 }
00053 
00054 void my_flush(u8 fid, int id)
00055 {
00056     // No flush in this file system
00057     modem_respond(ALP_ERR_NONE, id);
00058 }
00059 
00060 void my_delete(u8 fid, int id)
00061 {
00062     modem_respond((ram_fs_delete(fid))? ALP_ERR_FILE_NOT_FOUND : ALP_ERR_NONE, id);
00063 }
00064 
00065 void my_udata(void *data, u32 length)
00066 {    
00067     uint8_t* p = (uint8_t*)data;
00068     int32_t rem = length;
00069     alp_parsed_chunk_t r;
00070     d7a_sp_res_t* istat;
00071     
00072     do {
00073         uint32_t parsed = alp_parse_chunk(&p, &r);
00074         if (!parsed)
00075         {
00076             // Discard the payload in case of parsing error.
00077             PRINT("Parsing error!\r\n");
00078             break;
00079         }
00080         rem -= parsed;
00081         
00082         switch (r.type)
00083         {
00084             // Interface status
00085             case ALP_OPCODE_RSP_ISTATUS:
00086                 // D7A Interface
00087                 if (ALP_ITF_TYPE_D7A == r.meta.itf.type)
00088                 {
00089                     union {
00090                         u8      b[8];
00091                         u32     w[2];
00092                     } uid;
00093                     
00094                     // ISTATUS can come either alone or together with ALP_OPCODE_RSP_F_DATA
00095                     // but there should be only one per payload, moreover it will come first
00096                     istat = (d7a_sp_res_t*)r.data;
00097                     memcpy(uid.b,istat->addressee.id,8);
00098                         
00099                     PRINT("Got accessed by UID:%08X%08X SNR: %3ddB RXLEV: -%-3ddBm LB: %3ddB\n",
00100                     HAL_U32_BYTE_SWAP(uid.w[0]), HAL_U32_BYTE_SWAP(uid.w[1]),
00101                     istat->snr, istat->rxlev, istat->lb);
00102                 }
00103                 else
00104                 {
00105                     PRINT("Got accessed by unknown Interface 0x%02X\n", r.meta.itf.type);
00106                 }
00107                 break;
00108             // Data return
00109             case ALP_OPCODE_RSP_F_DATA:
00110                 // RSP_F_DATA can come either alone or together with ISTATUS
00111                 PRINT("Got UNS File[%3d]@%d %d Bytes\n", r.meta.f_data.fid, r.meta.f_data.offset, r.meta.f_data.length);
00112                 break;
00113             default:
00114                 PRINT("Untreated OPCODE %d\n", r.type);
00115                 break;
00116         }
00117     } while (rem > 0);
00118 }
00119 
00120 void my_lqual(u8 ifid, int per)
00121 {
00122     PRINT("Interface File [%3d] LQUAL : %d%% PER\r\n", ifid, per);
00123 }
00124 
00125 void my_ldown(u8 ifid)
00126 {
00127     PRINT("Interface File [%3d] LDOWN\r\n", ifid);
00128 }
00129 
00130 void my_reset(void)
00131 {
00132     PRINT("Restarting application...\r\n");
00133     FLUSH();
00134     NVIC_SystemReset();
00135 }
00136 
00137 void my_boot(u8 cause, u16 number)
00138 {
00139     PRINT("Modem BOOT[%c] #%d\r\n", cause, number);
00140     
00141     // Modem re-booted, restart APP
00142     my_reset();
00143 }
00144 
00145 void my_busy(u8 busy)
00146 {
00147     if (busy)
00148     {
00149         PRINT("Modem Busy\r\n");
00150         
00151         /* Stop report, do not use modem */
00152         /* Wait for modem reboot or modem not busy */
00153     }
00154     else
00155     {
00156         PRINT("Modem not Busy\r\n");
00157         
00158         /* Resume reports */
00159     }
00160 }