MeshX 0.4
This repository provides an implementation for Bluetooth Low Energy (BLE) Mesh network nodes. The project allows you to create BLE mesh nodes that can communicate with each other, enabling the development of smart home solutions or other IoT-based applications.
Loading...
Searching...
No Matches
meshx_api.c File Reference

Implementation of the BLE Mesh application API. More...

#include <meshx_api.h>

Macros

#define MESSAGE_BUFF_CLEAR(buff)

Functions

static meshx_err_t meshx_api_control_task_handler (const dev_struct_t *pdev, control_task_msg_evt_t evt, const void *params)
 Control task handler for BLE Mesh application messages.
static meshx_err_t meshx_prepare_data_message (uint16_t element_id, uint16_t element_type, uint16_t func_id, uint16_t msg_len, const void *msg)
 Prepares a message to be sent to the BLE Mesh application.
static meshx_err_t meshx_prepare_ctrl_message (meshx_ctrl_evt_t evt, uint16_t msg_len, const void *msg)
 Prepares a control message to be sent to the BLE Mesh application.
meshx_err_t meshx_send_msg_to_app (uint16_t element_id, uint16_t element_type, uint16_t func_id, uint16_t msg_len, const void *msg)
 Sends a message to the BLE Mesh application.
meshx_err_t meshx_send_ctrl_msg_to_app (meshx_ctrl_evt_t evt, uint16_t msg_len, const void *msg)
 Sends a control message to the BLE Mesh application.
meshx_err_t meshx_send_msg_to_element (uint16_t element_id, uint16_t element_type, uint16_t func_id, uint16_t msg_len, const void *msg)
 Sends a message to the element.
meshx_err_t meshx_app_reg_element_callback (meshx_app_data_cb_t cb)
 Registers the BLE Mesh application callback.
meshx_err_t meshx_app_reg_system_events_callback (meshx_app_ctrl_cb_t cb)
 Registers the BLE Mesh application control callback.

Variables

struct { 
   meshx_app_data_cb_t   app_data_cb 
   meshx_app_ctrl_cb_t   app_ctrl_cb 
   meshx_app_api_msg_t   msg_buff 
meshx_api_ctrl

Detailed Description

Implementation of the BLE Mesh application API.

This file contains the implementation of the BLE Mesh application API. It includes functions to send messages to the BLE Mesh application and register the BLE Mesh application callback.

Author
Pranjal Chanda

Macro Definition Documentation

◆ MESSAGE_BUFF_CLEAR

#define MESSAGE_BUFF_CLEAR ( buff)
Value:
memset(&buff, 0, sizeof(buff))

Function Documentation

◆ meshx_api_control_task_handler()

meshx_err_t meshx_api_control_task_handler ( const dev_struct_t * pdev,
control_task_msg_evt_t evt,
const void * params )
static

Control task handler for BLE Mesh application messages.

This function handles BLE Mesh application messages.

Parameters
[in]pdevPointer to the device structure.
[in]evtEvent type.
[in]paramsPointer to the message parameters.
Returns
MESHX_SUCCESS on success, error code otherwise.
34{
35 const meshx_app_api_msg_t *msg = (const meshx_app_api_msg_t *)params;
36
38
39 if (!pdev)
40 return MESHX_INVALID_ARG;
41
43 err = meshx_api_ctrl.app_data_cb ? meshx_api_ctrl.app_data_cb(&msg->msg_type_u.element_msg,
45
46 else
47 err = meshx_api_ctrl.app_ctrl_cb ? meshx_api_ctrl.app_ctrl_cb(&msg->msg_type_u.ctrl_msg,
49
50 return err;
51}
static struct @023200254140264171361220101366151270341050312256 meshx_api_ctrl
union meshx_data_payload meshx_data_payload_t
Structure for the BLE Mesh application control message.
union meshx_ctrl_payload meshx_ctrl_payload_t
Structure defines the payload for meshx_ctrl_payload.
struct meshx_app_api_msg meshx_app_api_msg_t
Structure for the BLE Mesh application API message.
CONTROL_TASK_MSG_EVT_DATA
Definition meshx_control_task.h:88
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
@ MESHX_INVALID_ARG
Definition meshx_err.h:46
**This function is called by the parent element when a state change request *is received It validates the request and returns a result to the element not the model layer **return * MESHX_SUCCESS
Definition meshx_model_level.cpp:385
uint8_t data[sizeof(meshx_data_payload_t)]
Definition meshx_api.h:216
union meshx_app_api_msg::@072073010055105213156102377164134137032042011011 msg_type_u
meshx_app_element_msg_header_t element_msg
Definition meshx_api.h:213
meshx_ctrl_msg_header_t ctrl_msg
Definition meshx_api.h:212

◆ meshx_app_reg_element_callback()

meshx_err_t meshx_app_reg_element_callback ( meshx_app_data_cb_t cb)

Registers the BLE Mesh application callback.

This function registers the BLE Mesh application data path callback.

Parameters
[in]cbPointer to the application callback.
Returns
MESHX_SUCCESS on success, error code otherwise.
207{
209
214 if (err)
215 {
216 MESHX_LOGE(MODULE_ID_COMMON, "Failed to register control task callback: (%d)", err);
217 return err;
218 }
219
220 meshx_api_ctrl.app_data_cb = cb;
221
222 return err;
223}
static meshx_err_t meshx_api_control_task_handler(const dev_struct_t *pdev, control_task_msg_evt_t evt, const void *params)
Control task handler for BLE Mesh application messages.
Definition meshx_api.c:33
meshx_err_t(* control_task_msg_handle_t)(dev_struct_t *pdev, control_task_msg_evt_t evt, void *params)
Function pointer type for control task message handler.
Definition meshx_control_task.h:188
@ CONTROL_TASK_MSG_CODE_TO_APP
Definition meshx_control_task.h:72
meshx_err_t control_task_msg_subscribe(control_task_msg_code_t msg_code, control_task_msg_evt_t evt_bmap, control_task_msg_handle_t callback)
Subscribe to a control task message.
Definition meshx_control_task.c:142
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:114
@ MODULE_ID_COMMON
Definition module_id.h:36

◆ meshx_app_reg_system_events_callback()

meshx_err_t meshx_app_reg_system_events_callback ( meshx_app_ctrl_cb_t cb)

Registers the BLE Mesh application control callback.

This function registers the BLE Mesh application control callback.

Parameters
[in]cbPointer to the control callback.
Returns
MESHX_SUCCESS on success, error code otherwise.
235{
237
242 if (err)
243 {
244 MESHX_LOGE(MODULE_ID_COMMON, "Failed to register control task callback: (%d)", err);
245 return err;
246 }
247
248 meshx_api_ctrl.app_ctrl_cb = cb;
249
250 return err;
251}
CONTROL_TASK_MSG_EVT_CTRL
Definition meshx_control_task.h:89

◆ meshx_prepare_ctrl_message()

meshx_err_t meshx_prepare_ctrl_message ( meshx_ctrl_evt_t evt,
uint16_t msg_len,
const void * msg )
static

Prepares a control message to be sent to the BLE Mesh application.

This function prepares a control message to be sent to the BLE Mesh application.

Parameters
[in]evtThe event ID.
[in]msg_lenThe message length.
[in]msgPointer to the message.
Returns
MESHX_SUCCESS on success, error code otherwise.
98{
99 if (msg_len > MESHX_APP_API_MSG_MAX_SIZE)
100 return MESHX_INVALID_ARG;
101
103
104 meshx_api_ctrl.msg_buff.msg_type_u.ctrl_msg.evt_id = evt;
105 meshx_api_ctrl.msg_buff.msg_type_u.ctrl_msg.reserved = 0;
106
107 if (msg && msg_len > 0)
108 {
109 memcpy(meshx_api_ctrl.msg_buff.data, msg, msg_len);
110 }
111
112 return MESHX_SUCCESS;
113}
#define MESSAGE_BUFF_CLEAR(buff)
Definition meshx_api.c:13
#define MESHX_APP_API_MSG_MAX_SIZE
Definition meshx_api.h:25

◆ meshx_prepare_data_message()

meshx_err_t meshx_prepare_data_message ( uint16_t element_id,
uint16_t element_type,
uint16_t func_id,
uint16_t msg_len,
const void * msg )
static

Prepares a message to be sent to the BLE Mesh application.

This function prepares a message to be sent to the BLE Mesh application.

Parameters
[in]element_idThe element ID.
[in]element_typeThe element type.
[in]func_idThe function ID.
[in]msg_lenThe message length.
[in]msgPointer to the message.
Returns
MESHX_SUCCESS on success, error code otherwise.
67{
68 if (!msg || msg_len > MESHX_APP_API_MSG_MAX_SIZE)
69 return MESHX_INVALID_ARG;
70
72
73 meshx_api_ctrl.msg_buff.msg_type_u.element_msg.func_id = func_id;
74 meshx_api_ctrl.msg_buff.msg_type_u.element_msg.msg_len = msg_len;
75 meshx_api_ctrl.msg_buff.msg_type_u.element_msg.element_id = element_id;
76 meshx_api_ctrl.msg_buff.msg_type_u.element_msg.element_type = element_type;
77
78 if (msg && msg_len > 0)
79 {
80 memcpy(meshx_api_ctrl.msg_buff.data, msg, msg_len);
81 }
82
83 return MESHX_SUCCESS;
84}

◆ meshx_send_ctrl_msg_to_app()

meshx_err_t meshx_send_ctrl_msg_to_app ( meshx_ctrl_evt_t evt,
uint16_t msg_len,
const void * msg )

Sends a control message to the BLE Mesh application.

This function sends a control message to the BLE Mesh application.

Parameters
[in]evtThe event ID.
[in]msg_lenThe message length.
[in]msgPointer to the message.
Returns
MESHX_SUCCESS on success, error code otherwise.
155{
157
158 err = meshx_prepare_ctrl_message(evt, msg_len, msg);
159 if(err)
160 MESHX_LOGE(MODULE_ID_COMMON, "Failed to create ctrl message: (0x%x)", err);
161
163 if(err)
164 MESHX_LOGE(MODULE_ID_COMMON, "Failed to send ctrl message to app: (0x%x)", err);
165
166 return err;
167}
static meshx_err_t meshx_prepare_ctrl_message(meshx_ctrl_evt_t evt, uint16_t msg_len, const void *msg)
Prepares a control message to be sent to the BLE Mesh application.
Definition meshx_api.c:97
meshx_err_t control_task_msg_publish(control_task_msg_code_t msg_code, control_task_msg_evt_t msg_evt, const void *msg_evt_params, size_t sizeof_msg_evt_params)
Publish a control task message.
Definition meshx_control_task.c:84

◆ meshx_send_msg_to_app()

meshx_err_t meshx_send_msg_to_app ( uint16_t element_id,
uint16_t element_type,
uint16_t func_id,
uint16_t msg_len,
const void * msg )

Sends a message to the BLE Mesh application.

This function sends a message to the BLE Mesh application.

Parameters
[in]element_idThe element ID.
[in]element_typeThe element type.
[in]func_idThe function ID.
[in]msg_lenThe message length.
[in]msgPointer to the message.
Returns
MESHX_SUCCESS on success, error code otherwise.
129{
131
132 err = meshx_prepare_data_message(element_id, element_type, func_id, msg_len,msg);
133 if(err)
134 MESHX_LOGE(MODULE_ID_COMMON, "Failed to create message: (0x%x)", err);
135
137 if(err)
138 MESHX_LOGE(MODULE_ID_COMMON, "Failed to send message to app: (0x%x)", err);
139
140 return err;
141}
static meshx_err_t meshx_prepare_data_message(uint16_t element_id, uint16_t element_type, uint16_t func_id, uint16_t msg_len, const void *msg)
Prepares a message to be sent to the BLE Mesh application.
Definition meshx_api.c:66

◆ meshx_send_msg_to_element()

meshx_err_t meshx_send_msg_to_element ( uint16_t element_id,
uint16_t element_type,
uint16_t func_id,
uint16_t msg_len,
const void * msg )

Sends a message to the element.

This function sends a message to the element from BLE mesh Application

Parameters
[in]element_idThe element ID.
[in]element_typeThe element type.
[in]func_idThe function ID.
[in]msg_lenThe message length.
[in]msgPointer to the message.
Returns
MESHX_SUCCESS on success, error code otherwise.
183{
185
186 err = meshx_prepare_data_message(element_id, element_type, func_id, msg_len,msg);
187 if(err)
188 MESHX_LOGE(MODULE_ID_COMMON, "Failed to create message: (0x%x)", err);
189
191 if(err)
192 MESHX_LOGE(MODULE_ID_COMMON, "Failed to send message to app: (0x%x)", err);
193
194 return err;
195}
@ CONTROL_TASK_MSG_CODE_TO_MESHX
Definition meshx_control_task.h:73

Variable Documentation

◆ app_ctrl_cb

meshx_app_ctrl_cb_t app_ctrl_cb

BLE Mesh application control callback

◆ app_data_cb

meshx_app_data_cb_t app_data_cb

BLE Mesh application data callback

◆ [struct]

struct { ... } meshx_api_ctrl

◆ msg_buff

BLE Mesh application message buffer