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
meshXCWWWClientElement Class Reference

#include <meshx_cwww_element.hpp>

Inheritance diagram for meshXCWWWClientElement:
meshXElementClient meshXElement< meshx_cli_model_send_param_header_t > meshXElementIF

Public Member Functions

 meshXCWWWClientElement (uint16_t element_idx)
 Constructs a new meshXCWWWClientElement instance. The meshXCWWWClientElement represents a CWWW client element in the MeshX BLE mesh network. It automatically initializes and configures all required SIG models for the CWWW element. The CWWW element combines Generic OnOff and Light CTL client models.
 meshXCWWWClientElement ()=delete
uint8_t get_onoff ()
meshx_light_ctl_model_state_tget_ctl ()
meshx_cwww_cli_el_ctx_tget_ctx ()
Public Member Functions inherited from meshXElementClient
 meshXElementClient ()=default
 meshXElementClient (uint16_t element_idx, uint8_t no_of_sig_models=0, uint8_t no_of_ven_models=0)
Public Member Functions inherited from meshXElement< meshx_cli_model_send_param_header_t >
void set_element_type (meshxElementType_t type)
meshxElementType_t get_element_type (void) const final
 Get the element type.
void set_element_variant (meshx_element_type_t variant)
meshx_element_type_t get_element_variant (void) const final
 Get the element variant.
void set_no_of_sig_models (uint8_t cnt)
uint8_t get_no_of_sig_models (void) const final
 Get the number of SIG models supported by the element.
void set_no_of_ven_models (uint8_t cnt)
uint8_t get_no_of_ven_models (void) const final
 Get the number of Vendor models supported by the element.
std::vector< std::unique_ptr< meshXModelIF > > & get_sig_models (void) final
 Get the SIG models vector.
std::vector< std::unique_ptr< meshXModelIF > > & get_ven_models (void) final
 Get the Vendor models vector.
const char * get_element_name (void) const override
 Get the name of the element.
void register_element_ctx (meshx_ptr_t ctx, size_t ctx_size)
 Register element context structure.
meshx_ptr_t get_element_ctx (void) const override
 Get the element context structure.
size_t get_element_ctx_size (void) const override
 Get the size of the element context structure.
meshx_err_t sig_plat_model_array_allocate (void)
 Allocate memory for SIG model platform array.
meshx_err_t ven_plat_model_array_allocate (void)
 Allocate memory for Vendor model platform array.
std::vector< uint8_t > & get_sig_model_array (void)
 Get the SIG model array.
std::vector< uint8_t > & get_ven_model_array (void)
 Get the Vendor model array.
meshx_err_t add_sig_model (ConstructorsArgs &&... args)
 Add a SIG model to the element.
meshx_err_t add_ven_model (ConstructorsArgs &&... args)
 Add a Vendor model to the element.
uint8_t get_sig_model_count (void) const
 Get the number of SIG models currently added to the element.
uint8_t get_ven_model_count (void) const
 Get the number of Vendor models currently added to the element.
meshx_err_t add_sig_models (void)
 Add multiple SIG models to the element.
meshx_err_t add_ven_models (void)
 Add multiple Vendor models to the element.
meshx_err_t add_models (void)
 Add both SIG and Vendor models to the element.
MESHX_MODEL * get_sig_plat_model_array (void)
 Get the platform model array for SIG models.
MESHX_MODEL * get_ven_plat_model_array (void)
 Get the platform model array for Vendor models.
 meshXElement (void)
 Default constructor for meshXElement.
meshx_err_t initialize (void) override
 Initialize the element.
meshx_err_t reset (void) override
 Reset the element.
bool is_initialized (void) const override
 Check if the element is initialized.
meshx_err_t restore_nvs_context (void) override
 Restore the element's context from NVS.
bool has_model (uint16_t model_id) const override
 Check if the element contains a specific model by ID.
void on_baked (uint16_t index) override
 Called when the composition is baked to update the element's index.
 ~meshXElement () override
Public Member Functions inherited from meshXElementIF
void set_element_idx (uint16_t idx)
uint16_t get_element_idx (void) const
 meshXElementIF ()=delete
 meshXElementIF (uint16_t element_idx)
virtual ~meshXElementIF ()=default

Private Member Functions

uint8_t list_sig_models () override
 Lists and creates all required SIG models for the element.
uint8_t list_ven_models () override
 Lists Vendor models for CWWW Client Element (none required).
const char * get_element_name (void) const override
 Get the name of the element.
meshx_err_t element_state_change_notify (meshx_ptr_t param, size_t param_size) override
 Notify element of state change from child model.
void sync (control_task_msg_evt_t evt) override
 Synchronize element state (GET requests).
void handle_config (control_task_msg_evt_t evt, const meshx_config_srv_cb_param_t *params) override
 Handle configuration server events.

Static Private Member Functions

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

Private Attributes

meshx_cwww_cli_el_ctx_t element_ctx

Additional Inherited Members

Static Public Member Functions inherited from meshXElement< meshx_cli_model_send_param_header_t >
static meshx_err_t static_prov_srv_cb (const dev_struct_t *pdev, control_task_msg_evt_t evt, const void *params)
 Global static provisioning callback for Server elements.
static meshx_err_t static_prov_cli_cb (const dev_struct_t *pdev, control_task_msg_evt_t evt, const void *params)
 Global static provisioning callback for Client elements.
static meshx_err_t static_config_cb (const dev_struct_t *pdev, control_task_msg_evt_t evt, const meshx_config_srv_cb_param_t *params)
 Global static configuration callback.
static void register_global_callbacks (void)
 Register the global callbacks with the provisioning server.

Constructor & Destructor Documentation

◆ meshXCWWWClientElement() [1/2]

meshXCWWWClientElement::meshXCWWWClientElement ( uint16_t element_idx)
explicit

Constructs a new meshXCWWWClientElement instance. The meshXCWWWClientElement represents a CWWW client element in the MeshX BLE mesh network. It automatically initializes and configures all required SIG models for the CWWW element. The CWWW element combines Generic OnOff and Light CTL client models.

Parameters
element_idxThe index of the element within the node.
214{
215 memset(&element_ctx, 0, sizeof(meshx_cwww_cli_el_ctx_t));
217
218 /* Restore from NVS if available */
219 meshx_nvs_element_ctx_get(element_idx, MESHX_ELEMENT_TYPE_LIGHT_CWWW_CLIENT, &element_ctx, sizeof(meshx_cwww_cli_el_ctx_t));
220
221 this->register_element_ctx(&element_ctx, sizeof(meshx_cwww_cli_el_ctx_t));
222 this->set_element_variant(MESHX_ELEMENT_TYPE_LIGHT_CWWW_CLIENT);
223
224 /* Subscribe to BLE events for this element type */
229
230#if CONFIG_ENABLE_UNIT_TEST
232#endif
233}
meshx_cwww_cli_el_ctx_t element_ctx
Definition meshx_cwww_element.hpp:141
static meshx_err_t s_to_ble_cb(const dev_struct_t *pdev, control_task_msg_evt_t evt, const void *params)
Definition meshx_cwww_element.cpp:364
meshXElementClient()=default
uint16_t element_idx
Definition meshx_fwd_decl.hpp:84
void set_element_variant(meshx_element_type_t variant)
Definition meshx_element_class.hpp:69
void register_element_ctx(meshx_ptr_t ctx, size_t ctx_size)
Definition meshx_element_class.hpp:132
#define MESHX_ADDR_UNASSIGNED
Definition meshx_ble_mesh_cmn_def.h:30
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_BLE
Definition meshx_control_task.h:67
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
meshx_err_t cwww_cli_ut_handler(int cmd_id, int argc, char **argv)
Definition meshx_cwww_element.cpp:468
#define CWWW_CLI_TO_BLE_EVT_MASK
Definition meshx_cwww_element.cpp:40
meshx_err_t meshx_nvs_element_ctx_get(uint16_t element_id, meshx_element_type_t element_type, void *blob, size_t blob_size)
Retrieve the context of a specific element from NVS.
Definition meshx_nvs.c:447
@ MODULE_ID_ELEMENT_LIGHT_CWWW_CLIENT
Definition module_id.h:29
meshx_err_t register_unit_test(module_id_t module_id, module_callback_t callback)
Register a unit test for a specific module.
Definition unit_test.c:137

◆ meshXCWWWClientElement() [2/2]

meshXCWWWClientElement::meshXCWWWClientElement ( )
delete

Member Function Documentation

◆ element_state_change_notify()

meshx_err_t meshXCWWWClientElement::element_state_change_notify ( meshx_ptr_t param,
size_t param_size )
overrideprivatevirtual

Notify element of state change from child model.

Discriminates ONOFF vs CTL via header->model.model_id. Updates element_ctx and notifies app.

Reimplemented from meshXElement< meshx_cli_model_send_param_header_t >.

272{
273 if (!param) return MESHX_INVALID_ARG;
274
275 auto *header = static_cast<meshx_cli_model_send_param_header_t *>(param);
276 uint16_t el_id = header->model.el_id;
277 uint16_t mid = header->model.model_id;
278 uint16_t func_id = 0;
280 app_evt.err_code = header->err_code;
281
283 {
284 auto *msg = static_cast<meshx_on_off_cli_el_msg_t *>(param);
285 element_ctx.gen_on_off_state.on_off = msg->state.on_off;
286 app_evt.state_change.on_off.state = msg->state.on_off;
288 }
289 else if (mid == MESHX_MODEL_ID_LIGHT_CTL_CLI)
290 {
291 auto *msg = static_cast<meshx_light_ctl_cli_el_msg_t *>(param);
292 element_ctx.light_ctl_state = msg->state;
293 app_evt.state_change.ctl = {
294 .lightness = msg->state.lightness,
295 .temperature = msg->state.temperature,
296 .delta_uv = (uint16_t)msg->state.delta_uv,
297 .temp_range_min = msg->state.temp_range_min,
298 .temp_range_max = msg->state.temp_range_max,
299 };
301 }
302 else
303 {
304 return MESHX_INVALID_ARG;
305 }
306
307 return meshx_send_msg_to_app(el_id, MESHX_ELEMENT_TYPE_LIGHT_CWWW_CLIENT,
308 func_id, sizeof(app_evt), &app_evt);
309}
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:128
#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_CLIENT_ONN_OFF
Definition meshx_api.h:39
struct meshx_api_light_cwww_client_evt meshx_api_light_cwww_client_evt_t
Structure defines the payload for MESHX_ELEMENT_TYPE_LIGHT_CWWW_CLIENT.
#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_CLIENT_CTL
Definition meshx_api.h:40
#define MESHX_MODEL_ID_LIGHT_CTL_CLI
Definition meshx_ble_mesh_cmn_def.h:109
#define MESHX_MODEL_ID_GEN_ONOFF_CLI
Definition meshx_ble_mesh_cmn_def.h:71
@ MESHX_INVALID_ARG
Definition meshx_err.h:46
struct meshx_cli_model_send_param_header meshx_cli_model_send_param_header_t
Definition meshx_model_class.hpp:417
struct meshx_light_ctl_cli_el_msg meshx_light_ctl_cli_el_msg_t
Definition meshx_model_ctl.hpp:68
struct meshx_on_off_cli_el_msg meshx_on_off_cli_el_msg_t
Definition meshx_model_onoff.hpp:65
uint8_t err_code
Definition meshx_api.h:129
union meshx_api_light_cwww_client_evt::@010331215225145076254176237210306046131140170171 state_change
struct meshx_api_light_cwww_client_evt::@010331215225145076254176237210306046131140170171::@074174003215102134322053141270100354144151177356 on_off
struct meshx_api_light_cwww_client_evt::@010331215225145076254176237210306046131140170171::@376020317200137254005016072103236264206161124021 ctl
uint8_t state
Definition meshx_api.h:134
meshx_model_t model
Definition meshx_model_class.hpp:412
uint16_t el_id
Definition meshx_ble_mesh_cmn.h:36

◆ get_ctl()

meshx_light_ctl_model_state_t & meshXCWWWClientElement::get_ctl ( )
inline
183{ return element_ctx.light_ctl_state; }

◆ get_ctx()

meshx_cwww_cli_el_ctx_t & meshXCWWWClientElement::get_ctx ( )
inline
184{ return element_ctx; }

◆ get_element_name()

const char * meshXCWWWClientElement::get_element_name ( void ) const
overrideprivatevirtual

Get the name of the element.

Returns
String literal representing the element name.

Implements meshXElementIF.

265{
266 return "CWWW Client";
267}

◆ get_onoff()

uint8_t meshXCWWWClientElement::get_onoff ( )
inline
182{ return element_ctx.gen_on_off_state.on_off; }

◆ handle_config()

void meshXCWWWClientElement::handle_config ( control_task_msg_evt_t evt,
const meshx_config_srv_cb_param_t * params )
overrideprivatevirtual

Handle configuration server events.

Implements meshXElementIF.

358{
359 MESHX_LOGD(MODULE_ID_ELEMENT_LIGHT_CWWW_CLIENT, "CWWW Client [%d] Config Evt: %d", get_element_idx(), evt);
360}
uint16_t get_element_idx(void) const
Definition meshx_fwd_decl.hpp:99
#define MESHX_LOGD(module_id, format,...)
Definition meshx_log.h:132

◆ list_sig_models()

uint8_t meshXCWWWClientElement::list_sig_models ( void )
overrideprivatevirtual

Lists and creates all required SIG models for the element.

This function is responsible for creating and populating the sig_models vector with all essential SIG models that the element must have.

The function can be extended to include additional models based on configuration flags or specific requirements.

Returns
uint8_t The total number of SIG models created and added to the root_sig_models vector

Reimplemented from meshXElement< meshx_cli_model_send_param_header_t >.

237{
238 auto onoff_model = std::make_unique<meshXGenericOnOffClientModel>(
239 this, &element_ctx.gen_on_off_state,
240 (uint16_t)static_cast<int>(
242 this->get_sig_models().push_back(std::move(onoff_model));
243
244
245 auto ctl_model = std::make_unique<meshXLightCTLClientModel>(
246 this, &element_ctx.light_ctl_state,
247 (uint16_t)static_cast<int>(
249 this->get_sig_models().push_back(std::move(ctl_model));
250
251 return (uint8_t)this->get_sig_models().size();
252}
std::vector< std::unique_ptr< meshXModelIF > > & get_sig_models(void) final
Definition meshx_element_class.hpp:78
@ MESHX_CWWW_CLIENT_ELEMENT_COMP_LIGHT_CTL_CLIENT
Definition meshx_cwww_element.hpp:133
@ MESHX_CWWW_CLIENT_ELEMENT_COMP_GENERIC_ONOFF_CLIENT
Definition meshx_cwww_element.hpp:132

◆ list_ven_models()

uint8_t meshXCWWWClientElement::list_ven_models ( void )
overrideprivatevirtual

Lists Vendor models for CWWW Client Element (none required).

Reimplemented from meshXElement< meshx_cli_model_send_param_header_t >.

259{
260 return 0; /* No vendor models for CWWW client */
261}

◆ s_to_ble_cb()

meshx_err_t meshXCWWWClientElement::s_to_ble_cb ( const dev_struct_t * pdev,
control_task_msg_evt_t evt,
const void * params )
staticprivate
365{
366 if (!pdev || !params) return MESHX_INVALID_ARG;
367
369 {
370 const auto *msg = static_cast<const meshx_gen_on_off_cli_msg_t *>(params);
372 msg->element_id, MESHX_ELEMENT_TYPE_LIGHT_CWWW_CLIENT);
373 if (!el) return MESHX_SUCCESS;
374
375 if (el->element_ctx.pub_addr == MESHX_ADDR_UNASSIGNED)
376 return MESHX_INVALID_STATE;
377
378 /* Route through the model's request_onoff to leverage the centralized logic */
379 auto &models = el->get_sig_models();
380#if CONFIG_ENABLE_GEN_ONOFF_CLIENT
381 auto *onoff = static_cast<meshXGenericOnOffClientModel *>(models[0].get());
382 return onoff->request_onoff(msg);
383#else
384 return MESHX_SUCCESS;
385#endif
386 }
388 {
389 const auto *msg = static_cast<const meshx_light_ctl_cli_msg_t *>(params);
391 msg->element_id, MESHX_ELEMENT_TYPE_LIGHT_CWWW_CLIENT);
392 if (!el) return MESHX_SUCCESS;
393
394 if (el->element_ctx.pub_addr == MESHX_ADDR_UNASSIGNED)
395 return MESHX_INVALID_STATE;
396
397 auto &models = el->get_sig_models();
398#if CONFIG_ENABLE_LIGHT_CTL_CLIENT
399 auto *ctl = static_cast<meshXLightCTLClientModel *>(models[1].get());
400 return ctl->request_ctl(msg->lightness, msg->temperature, msg->delta_uv, ++el->element_ctx.ctl_tid);
401#else
402 return MESHX_SUCCESS;
403#endif
404 }
405 return MESHX_SUCCESS;
406}
struct meshx_gen_on_off_cli_msg meshx_gen_on_off_cli_msg_t
Standard Relay Client Message structure (shared between C element and C++ model).
meshXCWWWClientElement(uint16_t element_idx)
Constructs a new meshXCWWWClientElement instance. The meshXCWWWClientElement represents a CWWW client...
Definition meshx_cwww_element.cpp:212
T * find_and_cast(uint16_t element_idx, meshx_element_type_t expected_variant)
Find and cast an element instance.
Definition meshx_element_registry.hpp:84
static meshXElementRegistry & get_instance()
Definition meshx_element_registry.hpp:33
CONTROL_TASK_MSG_EVT_TO_BLE_SET_CTL
Definition meshx_control_task.h:110
CONTROL_TASK_MSG_EVT_TO_BLE_SET_ON_OFF
Definition meshx_control_task.h:109
struct meshx_light_ctl_cli_msg meshx_light_ctl_cli_msg_t
@ MESHX_INVALID_STATE
Definition meshx_err.h:49
**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

◆ sync()

void meshXCWWWClientElement::sync ( control_task_msg_evt_t evt)
overrideprivatevirtual

Synchronize element state (GET requests).

Implements meshXElementIF.

312{
314 {
315 if (!meshx_prov_srv_is_provisioned()) return;
316 if (element_ctx.pub_addr == MESHX_ADDR_UNASSIGNED) return;
317
318 auto &models = this->get_sig_models();
319 auto *onoff = static_cast<meshXGenericOnOffClientModel *>(models[0].get());
320 auto *ctl = static_cast<meshXLightCTLClientModel *>(models[1].get());
321
322#if CONFIG_ENABLE_GEN_ONOFF_CLIENT
324 .ack = 1,
326 .on_off = 0,
327 .reserved = 0,
328 .element_id = this->get_element_idx()
329 };
330 onoff->request_onoff(&msg);
331#endif
332
333#if CONFIG_ENABLE_LIGHT_CTL_CLIENT
334 meshx_model_t model_ref = { .el_id = this->get_element_idx(),
335 .model_id = (uint16_t)ctl->get_model_id(),
336 .pub_addr = element_ctx.pub_addr,
337 .p_model = (MESHX_MODEL*)ctl->get_plat_model() };
338 meshx_ctx_t ctl_ctx = { .app_idx = element_ctx.app_id,
339 .net_idx = meshx_get_net_key_id(),
341 .src_addr = 0,
342 .dst_addr = element_ctx.pub_addr,
343 .p_ctx = nullptr };
345 .model = &model_ref, .ctx = &ctl_ctx,
346 .tid = 0,
347 .state = { .lightness = element_ctx.light_ctl_state.lightness,
348 .temperature = element_ctx.light_ctl_state.temperature,
349 .delta_uv = element_ctx.light_ctl_state.delta_uv,
350 .temp_range_min = 0,
351 .temp_range_max = 0 } };
352 ctl->model_send(&cp);
353#endif
354 }
355}
#define MESHX_GEN_ON_OFF_CLI_MSG_GET
Definition ble_mesh/elements/inc/meshx_relay_msg_defs.h:27
uint16_t meshx_get_net_key_id(void)
Get the network key identifier.
Definition meshx.c:316
struct meshx_model meshx_model_t
struct meshx_ctx meshx_ctx_t
Structure to hold context information for BLE Mesh operations.
#define MESHX_MODEL_OP_LIGHT_CTL_GET
Definition meshx_ble_mesh_cmn_def.h:415
CONTROL_TASK_MSG_EVT_SYSTEM_FRESH_BOOT
Definition meshx_control_task.h:167
struct meshx_light_ctl_send_params meshx_light_ctl_send_params_t
Definition meshx_model_ctl.hpp:55
bool meshx_prov_srv_is_provisioned(void)
Checks if the device is provisioned.
Definition meshx_prov_srv.cpp:316

Field Documentation

◆ element_ctx

meshx_cwww_cli_el_ctx_t meshXCWWWClientElement::element_ctx
private

The documentation for this class was generated from the following files: