How to process received Mesh message with scheduler

Hi, team.

**********
environment :
SDK : Mesh v3.2  (w/ SDK v15.3.0)
SoC : nRF52840
IDE : SES
**********


I am challenging to handle each event, such as Mesh receive interrupt and timer interrupt with the scheduler.
I have confirmed that simple GPIO interrupts and timer interrupts can be handled using the scheduler according to the tutorial.

However, I did not know how to process the received Mesh message using the scheduler, so I asked a question...

For example, in the simple light_switch sample, multiple structures are passed to the application as arguments, as shown below.

static void app_generic_onoff_client_status_cb(const generic_onoff_client_t * p_self,
                                               const access_message_rx_meta_t * p_meta,
                                               const generic_onoff_status_params_t * p_in)
{
    // some process...
}


At this time, for example, how can I push all the structures (pointers) received as arguments to the event queue of the scheduler?

I tried declaring the original structure as shown below and trying to copy the argument pointers,
but the parameters I received  in the scheduled function were not the intended values at all.

typedef struct
{
    const generic_onoff_client_t * pp_self;
    const access_message_rx_meta_t * pp_meta;
    const generic_onoff_status_params_t * pp_in;
} my_event_packet_t;



Copy pointer as shown below.

static void app_generic_onoff_client_status_cb(const generic_onoff_client_t * p_self,
                                               const access_message_rx_meta_t * p_meta,
                                               const generic_onoff_status_params_t * p_in)
{
    my_event_packet_t * packet_datas;
    
    packet_datas->pp_self = p_self;
    packet_datas->pp_meta = p_meta;
    packet_datas->pp_in = p_in;

    app_sched_event_put(&packet_datas, sizeof(* packet_datas), scheduled_status_cb);
}



Scheduled function.

static void scheduled_status_cb(void * p_event, uint16_t event_size)
{
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "%s called.\n", __func__);

    my_event_packet_t * check_struct = (my_event_packet_t *) p_event;

    /*
        Various processing such as log output
    */
}



Perhaps it is related to the fact that the structure being communicated is  a pointer, but no good approach could found so far.

Can you tell me if there is any good approach?
Also, if you have any points to be careful about using the scheduler to perform processing related to Bluetooth (Mesh) communication, please also provide a guide.


I hope you will be able to provide the information.

Best regards,
Wataru

Parents
No Data
Reply
  • Hello,

    You might have been trying to give me some guide, but I seem to have solved it myself.
    However, since I am not confident about whether this method is safe, I would be grateful if you could comment.


    I modified the structure to extract only the data needed for the application:

    typedef struct
    {
        uint16_t src_addr;
        uint16_t dst_addr;
        int8_t rssi;
        generic_onoff_status_params_t pp_in;
    } my_event_packet_t;
    



    In the callback function called in the interrupt handler mode, only necessary information is copied and pushed to the event queue as follows.

    static void app_generic_onoff_client_status_cb(const generic_onoff_client_t * p_self,
                                                   const access_message_rx_meta_t * p_meta,
                                                   const generic_onoff_status_params_t * p_in)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "%s called.\n", __func__);
    
        my_event_packet_t packet_datas = {0};
    
        packet_datas.src_addr = p_meta->src.value;
        packet_datas.dst_addr = p_meta->dst.value;
        packet_datas.rssi = p_meta->p_core_metadata->params.scanner.rssi;
        memcpy(&packet_datas.pp_in, p_in, sizeof(generic_onoff_status_params_t));
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "src : %X, rssi : %d, dst : %X.\n",
              p_meta->src.value, p_meta->p_core_metadata->params.scanner.rssi, p_meta->dst.value);
    
        app_sched_event_put((void *)&packet_datas, sizeof(packet_datas), scheduled_status_cb);
    }
    



    The function executed by the scheduler gets the data as follows:

    static void scheduled_status_cb(void * p_event, uint16_t event_size)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "%s called.\n", __func__);
    
        my_event_packet_t * check_struct = (my_event_packet_t *) p_event;
        
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "src : %X, RSSI : %d, dst : %X, onoff : %d.\n",
              check_struct->src_addr,
              check_struct->rssi,
              check_struct->dst_addr,
              check_struct->pp_in.present_on_off);
        
        /*
            some process...
        */
    }
    



    Paste the run time log below.

    <t:     478980>, main.c,  250, app_generic_onoff_client_status_cb called.
    <t:     478983>, main.c,  288, src : 18, rssi : -29, dst : C005.
    <t:     478991>, main.c,  196, scheduled_status_cb called.
    <t:     478993>, main.c,  227, src : 18, RSSI : -29, dst : C005, onoff : 1.
    



    In this way, it seems that I could handled the same data between the callback function when receiving a message and the function executed by the scheduler.

    Can you find any fatal drawbacks to the above methods?
    If you feel that there are no shortcomings, my next goal is to send a message from a function that is executed from the scheduler.

    If I call the send function, mesh assert will occur. . .
    Can you tell me how to send a message with a function executed from the scheduler?


    I hope you will be able to provide the information.

    Best regards,
    Wataru

Children
Related