Sending and reception of big data file (1kB example)

Dependencies:   modem_ref_helper CRC DebouncedInterrupt

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers modem_callbacks.cpp Source File

modem_callbacks.cpp

00001 #include "modem_d7a.h"
00002 #include "files.h"
00003 
00004 #define SERIAL_MAX_PACKET_SIZE  (255)
00005 
00006 // ============================================================}}}
00007 
00008 // Callbacks to MODEM's ALP requests
00009 // ============================================================{{{
00010 void my_read(u8 action, u8 fid, u32 offset, u32 length, int id)
00011 {
00012     u8 data[SERIAL_MAX_PACKET_SIZE];
00013     
00014     ASSERT((ALP_ACTION_RSP_TAG_SIZE + ALP_ACTION_RSP_F_DATA_SIZE(offset, length)) <= SERIAL_MAX_PACKET_SIZE,
00015     "Read response too big for serial protocol (%d/%dmax)", length, ALP_ACTION_RSP_TAG_SIZE + ALP_ACTION_RSP_F_DATA_SIZE(offset,SERIAL_MAX_PACKET_SIZE));
00016     
00017     if (ram_fs_read(fid, data, offset, length))
00018     {
00019         modem_ref_respond(action, ALP_ERR_FILE_NOT_FOUND, id);
00020     }
00021     else
00022     {
00023         modem_ref_respond_read(fid, data, offset, length, id);
00024     }
00025 }
00026 
00027 void my_write(u8 action, u8 fid, void *data, u32 offset, u32 length, int id)
00028 {
00029     alp_errors_t err;
00030     
00031     if (ram_fs_write(fid, (uint8_t*)data, offset, length))
00032     {
00033         err = ALP_ERR_FILE_NOT_FOUND;
00034     }
00035     else
00036     {
00037         err = ALP_ERR_NONE;
00038         
00039         touch_t* touch = (touch_t*)MALLOC(sizeof(touch_t));
00040         
00041         touch->fid = fid;
00042         touch->offset = offset;
00043         touch->length = length;
00044         
00045         g_file_modified.put(touch);
00046     }
00047     
00048     modem_ref_respond(action, err, id);
00049 }
00050 
00051 void my_read_fprop(u8 action, u8 fid, int id)
00052 {
00053     u8* hdr = (u8*)ram_fs_get_header(fid);
00054     
00055     if (hdr != NULL)
00056     {
00057         modem_ref_respond_fprop(fid, (alp_file_header_t*)hdr, id);
00058     }
00059     else
00060     {
00061         modem_ref_respond(action, ALP_ERR_FILE_NOT_FOUND, id);
00062     }
00063 }
00064 
00065 void my_flush(u8 action, u8 fid, int id)
00066 {
00067     // No flush in this file system
00068     modem_ref_respond(action, ALP_ERR_NONE, id);
00069 }
00070 
00071 void my_delete(u8 action, u8 fid, int id)
00072 {
00073     modem_ref_respond(action, (ram_fs_delete(fid))? ALP_ERR_FILE_NOT_FOUND : ALP_ERR_NONE, id);
00074 }
00075 
00076 void my_udata(alp_payload_t* alp)
00077 {
00078     alp_payload_print(alp);
00079 }
00080 
00081 void my_lqual(u8 ifid, int per)
00082 {
00083     PRINT("Interface File [%3d] LQUAL : %d%% PER\r\n", ifid, per);
00084 }
00085 
00086 void my_ldown(u8 ifid)
00087 {
00088     PRINT("Interface File [%3d] LDOWN\r\n", ifid);
00089 }
00090 
00091 void my_reset(void)
00092 {
00093     PRINT("Restarting application...\r\n");
00094     FLUSH();
00095     NVIC_SystemReset();
00096 }
00097 
00098 void my_boot(u8 cause, u16 number)
00099 {
00100     PRINT("Modem BOOT[%c] #%d\r\n", cause, number);
00101     
00102     // Modem re-booted, restart APP
00103     my_reset();
00104 }
00105 
00106 void my_busy(u8 busy)
00107 {
00108     if (busy)
00109     {
00110         PRINT("Modem Busy\r\n");
00111         
00112         /* Stop report, do not use modem */
00113         /* Wait for modem reboot or modem not busy */
00114     }
00115     else
00116     {
00117         PRINT("Modem not Busy\r\n");
00118         
00119         /* Resume reports */
00120     }
00121 }