cancel
Showing results for 
Search instead for 
Did you mean: 

ModusToolbox Bluetooth SDK

Contributor

Hi :

     I use the mesh client control to send the customer command from the scene client to the customer server,I find out some customer commands can't be received by the

  cumstomer server,and  the scene client code is below:

uint32_t mesh_app_proc_rx_cmd(uint16_t opcode, uint8_t *p_data, uint32_t length)

{

#if 0

    wiced_bt_mesh_event_t *p_event;

    WICED_BT_TRACE("[%s] cmd_opcode 0x%02x\n", __FUNCTION__, opcode);

    switch (opcode)

    {

    case HCI_CONTROL_MESH_COMMAND_SCENE_STORE:

    case HCI_CONTROL_MESH_COMMAND_SCENE_RECALL:

    case HCI_CONTROL_MESH_COMMAND_SCENE_GET:

    case HCI_CONTROL_MESH_COMMAND_SCENE_REGISTER_GET:

    case HCI_CONTROL_MESH_COMMAND_SCENE_DELETE:

        break;

    default:

        WICED_BT_TRACE("unknown\n");

        return WICED_FALSE;

    }

    p_event = wiced_bt_mesh_create_event_from_wiced_hci(opcode, MESH_COMPANY_ID_BT_SIG, WICED_BT_MESH_CORE_MODEL_ID_SCENE_CLNT, &p_data, &length);

    if (p_event == NULL)

    {

        WICED_BT_TRACE("bad hdr\n");

        return WICED_TRUE;

    }

    switch (opcode)

    {

    case HCI_CONTROL_MESH_COMMAND_SCENE_STORE:

        mesh_scene_client_store(p_event, p_data, length);

        break;

    case HCI_CONTROL_MESH_COMMAND_SCENE_RECALL:

        mesh_scene_client_recall(p_event, p_data, length);

        break;

    case HCI_CONTROL_MESH_COMMAND_SCENE_GET:

        mesh_scene_client_get(p_event, p_data, length);

        break;

    case HCI_CONTROL_MESH_COMMAND_SCENE_REGISTER_GET:

        mesh_scene_client_register_get(p_event, p_data, length);

        break;

    case HCI_CONTROL_MESH_COMMAND_SCENE_DELETE:

        mesh_scene_client_delete(p_event, p_data, length);

        break;

    }

    return WICED_TRUE;

#endif

    wiced_bt_mesh_event_t *p_event;

    uint16_t dst         = p_data[0] + (p_data[1] << 8);

    uint16_t app_key_idx = p_data[2] + (p_data[3] << 8);

    uint8_t  element_idx = p_data[4];

    uint16_t company_id  = p_data[5] + (p_data[6] << 8);

    uint16_t model_id    = p_data[7] + (p_data[8] << 8);

    uint8_t  cmd_opcode  = p_data[9];

    WICED_BT_TRACE("[%s] cmd_opcode 0x%02x\n", __FUNCTION__, opcode);

    if (opcode != HCI_CONTROL_MESH_COMMAND_VENDOR_DATA)

        return WICED_FALSE;

    p_event = wiced_bt_mesh_create_event(element_idx, company_id, model_id, dst, app_key_idx);

    if (p_event == NULL)

    {

        WICED_BT_TRACE("app_proc_rx_cmd: no mem\n");

        return WICED_TRUE;

    }

    mesh_client_send_data(p_event, cmd_opcode, p_data + 6, length - 6);

    return WICED_TRUE;

}

and  the customer server code  receive message callback is below:

wiced_bt_mesh_core_received_msg_handler_t get_msg_handler_callback(uint16_t company_id, uint16_t opcode, uint16_t *p_model_id, wiced_bool_t *p_dont_save_rpl)

{

    wiced_bt_mesh_core_received_msg_handler_t p_message_handler = NULL;

    uint8_t                                   idx_elem, idx_model;

    wiced_bt_mesh_event_t                     temp_event;

    uint16_t                                  model_id = 0xffff;

    WICED_BT_TRACE("\ncompany_id:%x opcode:%x\n", company_id, opcode);

    // Each model present on the element contains the callback which will be executed.

    // If message handler returns that callback, that means that Opcode is for that model.

    // The special case is Proxy Status messages, which do not belong to any model.

    if ((company_id == MESH_COMPANY_ID_UNUSED) && (p_proxy_status_message_handler != NULL))

    {

        p_message_handler = p_proxy_status_message_handler;

    }

    else

    {

        temp_event.company_id = company_id;

        temp_event.opcode     = opcode;

        temp_event.model_id   = 0xffff;   // it is a sign of special mode for model to just return true if the opcode is for that model, without message handling.

                                          // Model library changes model_id to any other value if it wants do disable RPL saving for its messages

        for (idx_elem = 0; idx_elem < mesh_config.elements_num; idx_elem++)

        {

            for (idx_model = 0; idx_model < mesh_config.elements[idx_elem].models_num; idx_model++)

            {

               /* 如果是厂商自定义的model,这个地方修改注释掉,否则消息将到达不了上层应用进行处理*/

                if (((company_id != MESH_COMPANY_ID_BT_SIG) && (mesh_config.elements[idx_elem].models[idx_model].company_id == MESH_COMPANY_ID_BT_SIG)) ||

                    ((company_id == MESH_COMPANY_ID_BT_SIG) && (mesh_config.elements[idx_elem].models[idx_model].company_id != MESH_COMPANY_ID_BT_SIG)))

                    continue;

                p_message_handler = (wiced_bt_mesh_core_received_msg_handler_t)mesh_config.elements[idx_elem].models[idx_model].p_message_handler;

                if (p_message_handler == NULL)

                    continue;

                if (!p_message_handler(&temp_event, NULL, 0))

                    continue;

                model_id = mesh_config.elements[idx_elem].models[idx_model].model_id;

                if (p_model_id)

                    *p_model_id = model_id;

                // Check if model wants to disable RPL saving for its messages

                if (temp_event.model_id != 0xffff && p_dont_save_rpl != NULL)

                    *p_dont_save_rpl = WICED_TRUE;

                break;

            }

            if (idx_model < mesh_config.elements[idx_elem].models_num)

                break;

        }

        if (idx_elem >= mesh_config.elements_num)

            p_message_handler = NULL;

    }

    // Application may overwrite models library and receive raw core data.  Do not allow

    // to overwrite certain profiles though.

    if ((p_app_model_message_handler != NULL) &&

        (model_id != WICED_BT_MESH_CORE_MODEL_ID_CONFIG_CLNT) &&

        (model_id != WICED_BT_MESH_CORE_MODEL_ID_REMOTE_PROVISION_SRV) &&

        (model_id != WICED_BT_MESH_CORE_MODEL_ID_REMOTE_PROVISION_CLNT) &&

        (model_id != WICED_BT_MESH_CORE_MODEL_ID_DIRECTED_FORWARDING_SRV) &&

        (model_id != WICED_BT_MESH_CORE_MODEL_ID_DIRECTED_FORWARDING_CLNT) &&

        (model_id != WICED_BT_MESH_CORE_MODEL_ID_FW_UPDATE_SRV) &&

        (model_id != WICED_BT_MESH_CORE_MODEL_ID_FW_UPDATE_CLNT) &&

        (model_id != WICED_BT_MESH_CORE_MODEL_ID_FW_DISTRIBUTION_SRV) &&

        (model_id != WICED_BT_MESH_CORE_MODEL_ID_FW_DISTRIBUTION_CLNT) &&

        (model_id != WICED_BT_MESH_CORE_MODEL_ID_OBJ_TRANSFER_SRV) &&

        (model_id != WICED_BT_MESH_CORE_MODEL_ID_OBJ_TRANSFER_CLNT) &&

        (model_id != WICED_BT_MESH_CORE_MODEL_ID_GENERIC_DEFTT_CLNT))

    {

        p_message_handler = p_app_model_message_handler;

    }

    if (p_message_handler == NULL)

    {

        WICED_BT_TRACE("ignored\n");

    }

    return p_message_handler;

}

and  I send the customer messages  by the mesh client control is the appendix.

when I  send the 0x07 command code  and the customer server can receive the message in the get_msg_handler_callback,and  print the message by  WICED_BT_TRACE("\ncompany_id:%x opcode:%x\n", company_id, opcode); however when I send the  0x06 command code,the customer server have not called the get_msg_handler_callback. I have done  many tries

I  don't  know what is the reason

0 Likes
Reply
1 Solution
Employee

Please have a look at common\libraries\mesh_app_lib\mesh_app_hci.c. This is functionality common to all mesh applications.  The app defines the UART transport configuration in

const wiced_transport_cfg_t  transport_cfg =

where it defines the function where received messages shall be processed which is

uint32_t mesh_application_proc_rx_cmd(uint8_t *p_buffer, uint32_t length)

When UART driver receives a well formatted message from the MCU (0x19, 2 bytes of opcode, 2 bytes of length, data), it is directed to that function. There is some test code used for running certification tests, and some messages are directed to the core.  Please comment this line out.

//        if (wiced_bt_mesh_core_test_mode_signal(opcode, p_data, payload_len))

Then all HCI data will go to your application.

The get_msg_handler_callback is called by the Mesh Core to find the handler for the message received over the air.  I am not sure I understand what you are trying to do and how you are sending 0x06 and 0x07.  But 0x06 is a valid configuration Opcode and will be processed by the Mesh Core Library if the message is encrypted using device key.

#define WICED_BT_MESH_CORE_CMD_HEARTBEAT_PUBLICATION_STATUS                     0x06

The picture points to the Transport Send method which is used for certification testing. It should not be used in the real application.  If you need to send vendor specific data, please use VS Data button.

View solution in original post

0 Likes
Reply
4 Replies
Contributor

Hi: 

I  verified a fact that when I  send the transport layer message by the mesh client control and the  mesh_app_proc_rx_cmd has not been called, I want to know which API will be called when I do that!

0 Likes
Reply
Contributor

Hi:

   I  find out a question that when I send the transport lay messages by the mesh client control  and the

0 Likes
Reply
Employee

Please have a look at common\libraries\mesh_app_lib\mesh_app_hci.c. This is functionality common to all mesh applications.  The app defines the UART transport configuration in

const wiced_transport_cfg_t  transport_cfg =

where it defines the function where received messages shall be processed which is

uint32_t mesh_application_proc_rx_cmd(uint8_t *p_buffer, uint32_t length)

When UART driver receives a well formatted message from the MCU (0x19, 2 bytes of opcode, 2 bytes of length, data), it is directed to that function. There is some test code used for running certification tests, and some messages are directed to the core.  Please comment this line out.

//        if (wiced_bt_mesh_core_test_mode_signal(opcode, p_data, payload_len))

Then all HCI data will go to your application.

The get_msg_handler_callback is called by the Mesh Core to find the handler for the message received over the air.  I am not sure I understand what you are trying to do and how you are sending 0x06 and 0x07.  But 0x06 is a valid configuration Opcode and will be processed by the Mesh Core Library if the message is encrypted using device key.

#define WICED_BT_MESH_CORE_CMD_HEARTBEAT_PUBLICATION_STATUS                     0x06

The picture points to the Transport Send method which is used for certification testing. It should not be used in the real application.  If you need to send vendor specific data, please use VS Data button.

View solution in original post

0 Likes
Reply
Contributor

Hi  VictorZ_46 :

       thank you !   I have known how to solve this question  by reading your suggestion.

0 Likes
Reply