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 File Reference

BLE Mesh Composition Initialization and Element Creation. More...

Include dependency graph for composition.c:

Go to the source code of this file.

Typedefs

typedef meshx_err_t(* root_model_getfn_t) (void *p_model)
 

Functions

MESHX_MODELget_root_sig_models (void)
 Returns the root models for BLE Mesh elements.
 
MESHX_MODELget_root_ven_models (void)
 Returns the root models for BLE Mesh elements.
 
size_t get_root_sig_models_count (void)
 Returns the count of the root models.
 
size_t get_root_ven_models_count (void)
 Returns the count of the vendor root models.
 
meshx_err_t meshx_create_element_composition (dev_struct_t *p_dev, meshx_config_t const *config)
 Creates the BLE Mesh element composition.
 

Variables

element_comp_fn_t element_comp_fn [MESHX_ELEMENT_TYPE_MAX]
 
static MESHX_MODELmeshx_sig_root_model_arr = NULL
 
static MESHX_MODELmeshx_ven_root_model_arr = NULL
 
static root_model_getfn_t meshx_sig_root_model_getfn []
 
static root_model_getfn_t meshx_ven_root_model_getfn [] = {}
 
static uint16_t meshx_sig_root_model_arr_len = MESHX_ARRAY_SIZE(meshx_sig_root_model_getfn)
 
static uint16_t meshx_ven_root_model_arr_len = MESHX_ARRAY_SIZE(meshx_ven_root_model_getfn)
 

Detailed Description

BLE Mesh Composition Initialization and Element Creation.

Copyright © 2024 - 2025 MeshX

This file contains functions and definitions for initializing BLE Mesh composition data and creating BLE Mesh elements for various configurations such as relay servers, relay clients, and CWWW (Cool White and Warm White) servers.

The file includes necessary headers and conditionally includes headers based on configuration macros. It defines macros for error handling and contains static variables for provisioning parameters and Light CTL state.

Definition in file composition.c.

Typedef Documentation

◆ root_model_getfn_t

typedef meshx_err_t(* root_model_getfn_t) (void *p_model)

Definition at line 67 of file composition.c.

Function Documentation

◆ get_root_sig_models()

MESHX_MODEL * get_root_sig_models ( void )

Returns the root models for BLE Mesh elements.

Returns
Pointer to the root models.

Definition at line 89 of file composition.c.

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}
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 MESHX_MODEL * meshx_sig_root_model_arr
Definition composition.c:64
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:39
@ MESHX_SUCCESS
Definition meshx_err.h:40
#define MESHX_MALLOC
Definition meshx_err.h:24
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:73
#define MESHX_MODEL
@ MODULE_ID_COMMON
Definition module_id.h:32
Here is the caller graph for this function:

◆ get_root_sig_models_count()

size_t get_root_sig_models_count ( void )

Returns the count of the root models.

Returns
Size of the root models.

Definition at line 156 of file composition.c.

157{
159}
Here is the caller graph for this function:

◆ get_root_ven_models()

MESHX_MODEL * get_root_ven_models ( void )

Returns the root models for BLE Mesh elements.

Returns
Pointer to the root models.

Definition at line 126 of file composition.c.

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}
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
static root_model_getfn_t meshx_ven_root_model_getfn[]
Definition composition.c:79

◆ get_root_ven_models_count()

size_t get_root_ven_models_count ( void )

Returns the count of the vendor root models.

Returns
Size of the vendor root models.

Definition at line 166 of file composition.c.

167{
169}
Here is the caller graph for this function:

◆ meshx_create_element_composition()

meshx_err_t meshx_create_element_composition ( dev_struct_t * p_dev,
meshx_config_t const * config )

Creates the BLE Mesh element composition.

Initializes the BLE Mesh elements for different configurations like relay servers, relay clients, and CWWW (Cool White and Warm White) servers.

Parameters
[in]p_devPointer to the device structure containing element information.
[in]configPointer to the meshx configuration.
Returns
MESHX_SUCCESS on success, or an error code on failure.

Definition at line 182 of file composition.c.

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
#define MESHX_ERR_PRINT_RET(_e_str, _err)
Print and return error message if an error occurs.
Definition meshx.h:37
struct element_comp_table element_comp_table_t
meshx_err_t meshx_init_config_server(void)
Initialize the meshxuction configuration server.
@ MESHX_INVALID_ARG
Definition meshx_err.h:42
Structure to store element composition functions.
element_comp_fn_t element_comp_fn
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ element_comp_fn

Initial value:
= {
}
@ MESHX_ELEMENT_TYPE_LIGHT_CWWW_CLIENT
Definition meshx_api.h:47
@ MESHX_ELEMENT_TYPE_RELAY_CLIENT
Definition meshx_api.h:45
@ MESHX_ELEMENT_TYPE_LIGHT_CWWW_SERVER
Definition meshx_api.h:46
@ MESHX_ELEMENT_TYPE_RELAY_SERVER
Definition meshx_api.h:44
meshx_err_t meshx_create_cwww_elements(dev_struct_t *pdev, uint16_t element_cnt)
Create Dynamic CWWW Server Model Elements.
meshx_err_t create_cwww_client_elements(dev_struct_t *pdev, uint16_t element_cnt)
Create Dynamic CW-WW Model Elements.
meshx_err_t create_relay_client_elements(dev_struct_t *pdev, uint16_t element_cnt)
Create Dynamic Relay Model Elements.
meshx_err_t meshx_create_relay_elements(dev_struct_t *pdev, uint16_t element_cnt)
Create Dynamic Relay Model Elements.

Definition at line 46 of file composition.c.

46 {
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};

◆ meshx_sig_root_model_arr

MESHX_MODEL* meshx_sig_root_model_arr = NULL
static

Root models for BLE Mesh elements.

Definition at line 64 of file composition.c.

◆ meshx_sig_root_model_arr_len

uint16_t meshx_sig_root_model_arr_len = MESHX_ARRAY_SIZE(meshx_sig_root_model_getfn)
static

Definition at line 81 of file composition.c.

◆ meshx_sig_root_model_getfn

root_model_getfn_t meshx_sig_root_model_getfn[]
static
Initial value:
= {
}
meshx_err_t meshx_get_config_srv_model(void *p_model)
Retrieves the configuration server model for the MeshX framework.
meshx_err_t meshx_get_ctl_setup_srv_model(meshx_ptr_t p_model)
Retrieves the CTL (Color Temperature Lightness) Setup Server model instance.

Definition at line 70 of file composition.c.

70 {
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};

◆ meshx_ven_root_model_arr

MESHX_MODEL* meshx_ven_root_model_arr = NULL
static

Definition at line 65 of file composition.c.

◆ meshx_ven_root_model_arr_len

uint16_t meshx_ven_root_model_arr_len = MESHX_ARRAY_SIZE(meshx_ven_root_model_getfn)
static

Definition at line 82 of file composition.c.

◆ meshx_ven_root_model_getfn

root_model_getfn_t meshx_ven_root_model_getfn[] = {}
static

Definition at line 79 of file composition.c.

79{};