Data reception demo.

Dependencies:   modem_ref_helper

modem_callbacks.cpp

Committer:
Jeej
Date:
2017-09-21
Revision:
5:a44b6f60bfc7
Parent:
4:854f22f7962b
Child:
9:72a15235e097

File content as of revision 5:a44b6f60bfc7:

#include "modem_ref_helper.h"

extern Queue<void, 8>   g_file_modified;

// ============================================================}}}

// Callbacks to MODEM's ALP requests
// ============================================================{{{
void my_read(u8 fid, u32 offset, u32 length, int id)
{
    u8 data[256];
    
    if (!ram_fs_read(fid, offset, length, data))
    {
        modem_respond_read(fid, data, offset, length, id);
    }
    else
    {
        modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id);
    }
}

void my_write(u8 fid, void *data, u32 offset, u32 length, int id)
{
    if (!ram_fs_write(fid, offset, length, (uint8_t*)data))
    {
        modem_respond(0, ALP_ERR_NONE, id);
        g_file_modified.put((void*)fid);
    }
    else
    {
        modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id);
    }   
}

void my_read_fprop(u8 fid, int id)
{
    u8* hdr = (u8*)ram_fs_get_header(fid);
    
    if (hdr != NULL)
    {
        modem_respond_fprop(fid, hdr, id);
    }
    else
    {
        modem_respond(0, ALP_ERR_FILE_NOT_FOUND, id);
    }
}

void my_flush(u8 fid, int id)
{
    // No flush in this file system
    modem_respond(0, ALP_ERR_NONE, id);
}

void my_delete(u8 fid, int id)
{
    modem_respond(0, (ram_fs_delete(fid))? ALP_ERR_FILE_NOT_FOUND : ALP_ERR_NONE, id);
}

void my_udata(u8 fid,void *data,u32 offset,u32 length, u8 i_type, u8 i_length, u8* i_data)
{
    (void)data;
    (void)i_length;
    PRINT("Got UNS File[%3d]@%d %d Bytes\n",fid,offset,length);
    if (i_type == ALP_ITF_TYPE_D7A)
    {
        static union {
            u8      b[8];
            u32     w[2];
        } uid;
        d7a_sp_res_t* istat = (d7a_sp_res_t*) i_data;
        memcpy(uid.b,istat->addressee.id,8);
        PRINT("From UID: %08X%08X (rxlev:%d lb:%d)\n",
                HAL_U32_BYTE_SWAP(uid.w[0]), HAL_U32_BYTE_SWAP(uid.w[1]),
                istat->rxlev, istat->lb);
    }
}

void my_lqual(u8 ifid, int per)
{
    PRINT("Interface File [%3d] LQUAL : %d%% PER\r\n", ifid, per);
}

void my_ldown(u8 ifid)
{
    PRINT("Interface File [%3d] LDOWN\r\n", ifid);
}

void my_reset(void)
{
    PRINT("Restarting application...\r\n");
    FLUSH();
    NVIC_SystemReset();
}

void my_boot(u8 cause, u16 number)
{
    PRINT("Modem BOOT[%c] #%d\r\n", cause, number);
    
    // Modem re-booted, restart APP
    my_reset();
}