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
composition.c
Go to the documentation of this file.
1
16
17#include "meshx_common.h"
18#include "meshx.h"
20
21#if CONFIG_RELAY_SERVER_COUNT
23#endif /* CONFIG_RELAY_SERVER_COUNT */
24
25#if CONFIG_RELAY_CLIENT_COUNT
27#endif /* CONFIG_RELAY_CLIENT_COUNT */
28
29#if CONFIG_LIGHT_CWWW_SRV_COUNT
31#endif /* CONFIG_LIGHT_CWWW_SRV_COUNT */
32
33#if CONFIG_LIGHT_CWWW_CLIENT_COUNT
35#endif /* CONFIG_LIGHT_CWWW_CLIENT_COUNT */
36
37#if CONFIG_SECTION_ENABLE_ELEMENT_TABLE
38#define MESHX_ELEMENT_COMP_TABLE_START _element_table_start
39#define MESHX_ELEMENT_COMP_TABLE_STOP _element_table_end
40
41extern element_comp_table_t MESHX_ELEMENT_COMP_TABLE_START;
42extern element_comp_table_t MESHX_ELEMENT_COMP_TABLE_STOP;
43
44#else
45
47#if CONFIG_RELAY_SERVER_COUNT
49#endif /* CONFIG_RELAY_SERVER_COUNT */
50#if CONFIG_RELAY_CLIENT_COUNT
52#endif /* CONFIG_RELAY_CLIENT_COUNT */
53#if CONFIG_LIGHT_CWWW_SRV_COUNT
55#endif /* CONFIG_LIGHT_CWWW_CLIENT_COUNT */
56#if CONFIG_LIGHT_CWWW_CLIENT_COUNT
58#endif /* CONFIG_LIGHT_CWWW_SRV_COUNT */
59};
60
61#endif /* CONFIG_SECTION_ENABLE_ELEMENT_TABLE */
62
66
67typedef meshx_err_t (*root_model_getfn_t)(void* p_model);
68
69/* This table registers the functions that returns the root models */
71#if CONFIG_ENABLE_CONFIG_SERVER
73#endif /* CONFIG_ENABLE_CONFIG_SERVER */
74#if CONFIG_ENABLE_LIGHT_CTL_SERVER
76#endif /* CONFIG_ENABLE_LIGHT_CTL_SERVER */
77};
78
80
83
90{
91 meshx_err_t err;
92 static MESHX_MODEL temp_model;
94 {
96 if(meshx_sig_root_model_arr == NULL)
97 {
98 MESHX_LOGE(MODULE_ID_COMMON, "Failed to allocate memory for root models");
99 return NULL;
100 }
102
103 for(uint16_t i = 0; i < meshx_sig_root_model_arr_len; i++)
104 {
105 if(meshx_sig_root_model_getfn[i] == NULL)
106 {
107 continue;
108 }
109 err = meshx_sig_root_model_getfn[i]((void**)&temp_model);
110 if (err != MESHX_SUCCESS)
111 {
112 MESHX_LOGE(MODULE_ID_COMMON, "Failed to get root model (%p) (%d)", meshx_sig_root_model_getfn[i], err);
113 return NULL;
114 }
115 memcpy(&meshx_sig_root_model_arr[i], &temp_model, sizeof(MESHX_MODEL));
116 }
117 }
119}
120
127{
128 static MESHX_MODEL temp_model;
130 {
132 if(meshx_ven_root_model_arr == NULL)
133 {
134 MESHX_LOGE(MODULE_ID_COMMON, "Failed to allocate memory for root models");
135 return NULL;
136 }
138
139 for(uint16_t i = 0; i < meshx_ven_root_model_arr_len; i++)
140 {
141 if(meshx_ven_root_model_getfn[i] == NULL)
142 {
143 continue;
144 }
145 meshx_ven_root_model_getfn[i]((void**)&temp_model);
146 memcpy(&meshx_ven_root_model_arr[i], &temp_model, sizeof(MESHX_MODEL));
147 }
148 }
150}
151
160
170
183{
184#if CONFIG_MAX_ELEMENT_COUNT > 0
185 meshx_err_t err;
186#if CONFIG_SECTION_ENABLE_ELEMENT_TABLE
188#endif /* CONFIG_SECTION_ENABLE_ELEMENT_TABLE */
189 if(!p_dev || !config || !config->element_comp_arr_len || !config->element_comp_arr)
190 return MESHX_INVALID_ARG;
191
193 MESHX_ERR_PRINT_RET("Failed to initialize config server", err);
194 for(uint16_t element_id = 0; element_id < config->element_comp_arr_len; element_id++)
195 {
196#if !CONFIG_SECTION_ENABLE_ELEMENT_TABLE
197 if(config->element_comp_arr[element_id].element_cnt != 0
198 && element_comp_fn[config->element_comp_arr[element_id].type] != NULL)
199 {
200 err = element_comp_fn[config->element_comp_arr[element_id].type](p_dev, config->element_comp_arr[element_id].element_cnt);
201 if(err)
202 {
203 MESHX_LOGE(MODULE_ID_COMMON, "Element composition failed: (%d)", err);
204 return err;
205 }
206 }
207#else
208 element_comp_table = &MESHX_ELEMENT_COMP_TABLE_START;
209 while(element_comp_table < &MESHX_ELEMENT_COMP_TABLE_STOP)
210 {
211 if(element_comp_table->idx == element_id && config->element_comp_arr[element_id].element_cnt != 0)
212 {
213 err = element_comp_table->element_comp_fn(p_dev, config->element_comp_arr[element_id].element_cnt);
214 if(err)
215 {
216 MESHX_LOGE(MODULE_ID_COMMON, "Element composition failed: (%d)", err);
217 return err;
218 }
219 }
221 }
222#endif /* CONFIG_SECTION_ENABLE_ELEMENT_TABLE */
223 }
224#endif /* CONFIG_MAX_ELEMENT_COUNT */
225 return err;
226}
element_comp_fn_t element_comp_fn[MESHX_ELEMENT_TYPE_MAX]
Definition composition.c:46
MESHX_MODEL * get_root_sig_models(void)
Returns the root models for BLE Mesh elements.
Definition composition.c:89
size_t get_root_ven_models_count(void)
Returns the count of the vendor root models.
static root_model_getfn_t meshx_sig_root_model_getfn[]
Definition composition.c:70
static uint16_t meshx_sig_root_model_arr_len
Definition composition.c:81
static uint16_t meshx_ven_root_model_arr_len
Definition composition.c:82
static MESHX_MODEL * meshx_ven_root_model_arr
Definition composition.c:65
size_t get_root_sig_models_count(void)
Returns the count of the root models.
static root_model_getfn_t meshx_ven_root_model_getfn[]
Definition composition.c:79
MESHX_MODEL * get_root_ven_models(void)
Returns the root models for BLE Mesh elements.
meshx_err_t(* root_model_getfn_t)(void *p_model)
Definition composition.c:67
static MESHX_MODEL * meshx_sig_root_model_arr
Definition composition.c:64
meshx_err_t meshx_create_element_composition(dev_struct_t *p_dev, meshx_config_t const *config)
Creates the BLE Mesh element composition.
This file contains the headers for meshx.c.
struct meshx_config meshx_config_t
#define MESHX_ERR_PRINT_RET(_e_str, _err)
Print and return error message if an error occurs.
Definition meshx.h:37
@ MESHX_ELEMENT_TYPE_LIGHT_CWWW_CLIENT
Definition meshx_api.h:47
@ MESHX_ELEMENT_TYPE_RELAY_CLIENT
Definition meshx_api.h:45
@ MESHX_ELEMENT_TYPE_MAX
Definition meshx_api.h:48
@ MESHX_ELEMENT_TYPE_LIGHT_CWWW_SERVER
Definition meshx_api.h:46
@ MESHX_ELEMENT_TYPE_RELAY_SERVER
Definition meshx_api.h:44
#define MESHX_ARRAY_SIZE(_arr)
This header file defines the provisioning server interface for the MeshX BLE Mesh stack....
Common application definitions and includes for BLE Mesh Node.
struct element_comp_table element_comp_table_t
struct dev_struct dev_struct_t
Structure representing the device composition and elements.
meshx_err_t(* element_comp_fn_t)(dev_struct_t *pdev, uint16_t element_cnt)
MeshX Compostion init Function Pointer.
meshx_err_t meshx_get_config_srv_model(void *p_model)
Retrieves the configuration server model for the MeshX framework.
meshx_err_t meshx_init_config_server(void)
Initialize the meshxuction configuration server.
Header file for CWWW Server Model.
meshx_err_t meshx_create_cwww_elements(dev_struct_t *pdev, uint16_t element_cnt)
Create Dynamic CWWW Server Model Elements.
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_MALLOC
Definition meshx_err.h:24
meshx_err_t meshx_get_ctl_setup_srv_model(meshx_ptr_t p_model)
Retrieves the CTL (Color Temperature Lightness) Setup Server model instance.
Implementation of the CW-WW (Cool White - Warm White) client model for BLE Mesh.
meshx_err_t create_cwww_client_elements(dev_struct_t *pdev, uint16_t element_cnt)
Create Dynamic CW-WW Model Elements.
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:73
#define MESHX_MODEL
Header file for the Relay Client Model in BLE Mesh.
meshx_err_t create_relay_client_elements(dev_struct_t *pdev, uint16_t element_cnt)
Create Dynamic Relay Model Elements.
Header file for the Relay Server Model.
meshx_err_t meshx_create_relay_elements(dev_struct_t *pdev, uint16_t element_cnt)
Create Dynamic Relay Model Elements.
@ MODULE_ID_COMMON
Definition module_id.h:32
Structure to store element composition functions.
element_comp_fn_t element_comp_fn
uint16_t element_cnt
Definition meshx.h:53
meshx_element_type_t type
Definition meshx.h:52
uint16_t element_comp_arr_len
Definition meshx.h:66
element_comp_t * element_comp_arr
Definition meshx.h:67