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
Go to the documentation of this file.
1
11#include <meshx_api.h>
12
13#define MESSAGE_BUFF_CLEAR(buff) memset(&buff, 0, sizeof(buff))
14
15static struct{
16
21
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}
52
66static 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)
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}
82
96meshx_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)
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}
110
124meshx_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)
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}
138
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}
166
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}
static struct @116303252105212016000076260223147336330304166341 meshx_api_ctrl
meshx_app_ctrl_cb_t app_ctrl_cb
Definition meshx_api.c:18
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
#define MESSAGE_BUFF_CLEAR(buff)
Definition meshx_api.c:13
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.
Definition meshx_api.c:96
meshx_app_data_cb_t app_data_cb
Definition meshx_api.c:17
meshx_app_api_msg_t msg_buff
Definition meshx_api.c:19
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.
Definition meshx_api.c:124
meshx_err_t meshx_app_reg_element_callback(meshx_app_data_cb_t cb)
Registers the BLE Mesh application callback.
Definition meshx_api.c:148
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 meshx_app_reg_system_events_callback(meshx_app_ctrl_cb_t cb)
Registers the BLE Mesh application control callback.
Definition meshx_api.c:176
This file contains the API definitions for the MeshX application.
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.
meshx_err_t(* meshx_app_data_cb_t)(const meshx_app_element_msg_header_t *msg_hdr, const meshx_data_payload_t *msg)
BLE Mesh application callback function.
Definition meshx_api.h:187
meshx_err_t(* meshx_app_ctrl_cb_t)(const meshx_ctrl_msg_header_t *msg_hdr, const meshx_ctrl_payload_t *msg)
BLE Mesh application control callback function.
Definition meshx_api.h:199
struct meshx_app_api_msg meshx_app_api_msg_t
Structure for the BLE Mesh application API message.
#define MESHX_APP_API_MSG_MAX_SIZE
Definition meshx_api.h:18
struct dev_struct dev_struct_t
Structure representing the device composition and elements.
uint32_t control_task_msg_evt_t
Type definition for control task message event.
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
@ CONTROL_TASK_MSG_CODE_TO_MESHX
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.
CONTROL_TASK_MSG_EVT_CTRL
CONTROL_TASK_MSG_EVT_DATA
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.
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
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:73
@ MODULE_ID_COMMON
Definition module_id.h:32
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