MeshX 0.3
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>
Include dependency graph for meshx_api.c:

Go to the source code of this file.

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.
 
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_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

Definition in file meshx_api.c.

Macro Definition Documentation

◆ MESSAGE_BUFF_CLEAR

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

Definition at line 13 of file meshx_api.c.

Function Documentation

◆ meshx_api_control_task_handler()

static 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.

Definition at line 33 of file meshx_api.c.

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 @116303252105212016000076260223147336330304166341 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
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:39
@ MESHX_SUCCESS
Definition meshx_err.h:40
@ MESHX_INVALID_ARG
Definition meshx_err.h:42
union meshx_app_api_msg::@336376344215041027113126022265212173363045212317 msg_type_u
uint8_t data[MESHX_APP_API_MSG_MAX_SIZE]
Definition meshx_api.h:174
meshx_app_element_msg_header_t element_msg
Definition meshx_api.h:171
meshx_ctrl_msg_header_t ctrl_msg
Definition meshx_api.h:170

◆ 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.

Definition at line 148 of file meshx_api.c.

149{
151
156 if (err)
157 {
158 MESHX_LOGE(MODULE_ID_COMMON, "Failed to register control task callback: (%d)", err);
159 return err;
160 }
161
162 meshx_api_ctrl.app_data_cb = cb;
163
164 return err;
165}
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.
@ CONTROL_TASK_MSG_CODE_TO_APP
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.
static meshx_err_t meshx_api_control_task_handler(const dev_struct_t *pdev, const control_task_msg_evt_t evt, const void *params)
CW-WW server model event handler.
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:73
@ MODULE_ID_COMMON
Definition module_id.h:32
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Definition at line 176 of file meshx_api.c.

177{
179
184 if (err)
185 {
186 MESHX_LOGE(MODULE_ID_COMMON, "Failed to register control task callback: (%d)", err);
187 return err;
188 }
189
190 meshx_api_ctrl.app_ctrl_cb = cb;
191
192 return err;
193}
CONTROL_TASK_MSG_EVT_CTRL
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_prepare_data_message()

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 )
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.

Definition at line 66 of file meshx_api.c.

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 memcpy(meshx_api_ctrl.msg_buff.data, msg, msg_len);
79
80 return MESHX_SUCCESS;
81}
#define MESSAGE_BUFF_CLEAR(buff)
Definition meshx_api.c:13
#define MESHX_APP_API_MSG_MAX_SIZE
Definition meshx_api.h:18
Here is the caller graph for this function:

◆ 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.

Definition at line 96 of file meshx_api.c.

97{
99
100 err = meshx_prepare_data_message(element_id, element_type, func_id, msg_len,msg);
101 if(err)
102 MESHX_LOGE(MODULE_ID_COMMON, "Failed to create message: (0x%x)", err);
103
105 if(err)
106 MESHX_LOGE(MODULE_ID_COMMON, "Failed to send message to app: (0x%x)", err);
107
108 return err;
109}
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_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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Definition at line 124 of file meshx_api.c.

125{
127
128 err = meshx_prepare_data_message(element_id, element_type, func_id, msg_len,msg);
129 if(err)
130 MESHX_LOGE(MODULE_ID_COMMON, "Failed to create message: (0x%x)", err);
131
133 if(err)
134 MESHX_LOGE(MODULE_ID_COMMON, "Failed to send message to app: (0x%x)", err);
135
136 return err;
137}
@ CONTROL_TASK_MSG_CODE_TO_MESHX
Here is the call graph for this function:

Variable Documentation

◆ app_ctrl_cb

meshx_app_ctrl_cb_t app_ctrl_cb

BLE Mesh application control callback

Definition at line 18 of file meshx_api.c.

◆ app_data_cb

meshx_app_data_cb_t app_data_cb

BLE Mesh application data callback

Definition at line 17 of file meshx_api.c.

◆ [struct]

struct { ... } meshx_api_ctrl

◆ msg_buff

BLE Mesh application message buffer

Definition at line 19 of file meshx_api.c.