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

#include <meshx_cwww_element.hpp>

Inheritance diagram for meshXCWWWServerElement:
meshXElementServer meshXElement< meshx_srv_model_send_param_header_t > meshXElementIF

Public Member Functions

 meshXCWWWServerElement (uint16_t element_idx)
 Constructs a new meshXCWWWServerElement instance. The meshXCWWWServerElement represents a CWWW server 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 server models.
 meshXCWWWServerElement ()=delete
uint8_t get_onoff ()
meshx_light_ctl_model_state_tget_ctl ()
Public Member Functions inherited from meshXElementServer
 meshXElementServer ()=default
 meshXElementServer (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_srv_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 Server 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 (Status broadcast).
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_srv_el_ctx_t element_ctx

Additional Inherited Members

Static Public Member Functions inherited from meshXElement< meshx_srv_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

◆ meshXCWWWServerElement() [1/2]

meshXCWWWServerElement::meshXCWWWServerElement ( uint16_t element_idx)
explicit

Constructs a new meshXCWWWServerElement instance. The meshXCWWWServerElement represents a CWWW server 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 server models.

Parameters
element_idxThe index of the element within the node.
67{
68 memset(&element_ctx, 0, sizeof(meshx_cwww_srv_el_ctx_t));
70
71 /* Restore from NVS if available */
72 meshx_nvs_element_ctx_get(element_idx, MESHX_ELEMENT_TYPE_LIGHT_CWWW_SERVER, &element_ctx, sizeof(meshx_cwww_srv_el_ctx_t));
73
75 this->set_element_variant(MESHX_ELEMENT_TYPE_LIGHT_CWWW_SERVER);
76
77 /* Subscribe to BLE events for this element type */
82
83#if CONFIG_ENABLE_UNIT_TEST
85#endif
86}
meshx_cwww_srv_el_ctx_t element_ctx
Definition meshx_cwww_element.hpp:63
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:197
uint16_t element_idx
Definition meshx_fwd_decl.hpp:84
meshXElementServer()=default
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_srv_ut_handler(int cmd_id, int argc, char **argv)
Definition meshx_cwww_element.cpp:560
#define CWWW_SRV_TO_BLE_EVT_MASK
Definition meshx_cwww_element.cpp:41
struct meshx_cwww_srv_el_ctx_t meshx_cwww_srv_el_ctx_t
Definition meshx_cwww_element.hpp:46
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_SERVER
Definition module_id.h:33
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

◆ meshXCWWWServerElement() [2/2]

meshXCWWWServerElement::meshXCWWWServerElement ( )
delete

Member Function Documentation

◆ element_state_change_notify()

meshx_err_t meshXCWWWServerElement::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, saves to NVS, notifies app.

Reimplemented from meshXElement< meshx_srv_model_send_param_header_t >.

125{
126 if (!param) return MESHX_INVALID_ARG;
127
128 auto *header = static_cast<meshx_srv_model_send_param_header_t *>(param);
129 uint16_t el_id = header->model.el_id;
130 uint16_t mid = header->model.model_id;
131 uint16_t func_id = 0;
133
135 {
136 auto *msg = static_cast<meshx_on_off_srv_el_msg_t *>(param);
137 /* State is already updated by model layer via pointer, but we sync here for clarity */
138 element_ctx.gen_on_off_state = msg->state;
139 app_evt.state_change.on_off.state = element_ctx.gen_on_off_state.on_off;
141 }
142 else if (mid == MESHX_MODEL_ID_LIGHT_CTL_SRV)
143 {
144 auto *msg = static_cast<meshx_light_ctl_srv_el_msg_t *>(param);
145 element_ctx.light_ctl_state = msg->state;
146 app_evt.state_change.ctl = {
147 .lightness = msg->state.lightness,
148 .temperature = msg->state.temperature,
149 .delta_uv = (uint16_t)msg->state.delta_uv,
150 .temp_range_min = msg->state.temp_range_min,
151 .temp_range_max = msg->state.temp_range_max
152 };
154 }
155 else
156 {
157 return MESHX_INVALID_ARG;
158 }
159
161 if (err)
162 MESHX_LOGW(MODULE_ID_ELEMENT_LIGHT_CWWW_SERVER, "CWWW Srv [%d]: NVS save failed: %d", el_id, err);
163
164 return meshx_send_msg_to_app(el_id, MESHX_ELEMENT_TYPE_LIGHT_CWWW_SERVER,
165 func_id, sizeof(app_evt), &app_evt);
166}
meshx_element_type_t get_element_variant(void) const final
Definition meshx_element_class.hpp:70
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_SERVER_ONN_OFF
Definition meshx_api.h:31
#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_SERVER_CTL
Definition meshx_api.h:32
struct meshx_api_light_cwww_server_evt meshx_api_light_cwww_server_evt_t
Structure defines the payload for MESHX_ELEMENT_TYPE_LIGHT_CWWW_SERVER.
#define MESHX_MODEL_ID_LIGHT_CTL_SRV
Definition meshx_ble_mesh_cmn_def.h:107
#define MESHX_MODEL_ID_GEN_ONOFF_SRV
Definition meshx_ble_mesh_cmn_def.h:70
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
@ MESHX_INVALID_ARG
Definition meshx_err.h:46
#define MESHX_LOGW(module_id, format,...)
Definition meshx_log.h:120
struct meshx_srv_model_send_param_header meshx_srv_model_send_param_header_t
Definition meshx_model_class.hpp:354
struct meshx_light_ctl_srv_el_msg meshx_light_ctl_srv_el_msg_t
Definition meshx_model_ctl.hpp:123
struct meshx_on_off_srv_el_msg meshx_on_off_srv_el_msg_t
Definition meshx_model_onoff.hpp:114
meshx_err_t meshx_nvs_element_ctx_set(uint16_t element_id, meshx_element_type_t element_type, const void *blob, size_t blob_size)
Store the context of a specific element to NVS.
Definition meshx_nvs.c:466
union meshx_api_light_cwww_server_evt::@257165005032013366004013204037032016036030275264 state_change
struct meshx_api_light_cwww_server_evt::@257165005032013366004013204037032016036030275264::@375004001161356005102054253202024137247030164222 on_off
struct meshx_api_light_cwww_server_evt::@257165005032013366004013204037032016036030275264::@245341060156102221224175046143367317210200103050 ctl
uint8_t state
Definition meshx_api.h:72
uint16_t el_id
Definition meshx_ble_mesh_cmn.h:36
meshx_model_t model
Definition meshx_model_class.hpp:350

◆ get_ctl()

meshx_light_ctl_model_state_t & meshXCWWWServerElement::get_ctl ( )
inline
104{ return element_ctx.light_ctl_state; }

◆ get_element_name()

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

Get the name of the element.

Returns
String literal representing the element name.

Implements meshXElementIF.

118{
119 return "CWWW Server";
120}

◆ get_onoff()

uint8_t meshXCWWWServerElement::get_onoff ( )
inline
103{ return element_ctx.gen_on_off_state.on_off; }

◆ handle_config()

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

Handle configuration server events.

Implements meshXElementIF.

191{
192 MESHX_LOGD(MODULE_ID_ELEMENT_LIGHT_CWWW_SERVER, "CWWW Server [%d] Config Evt: %d", get_element_idx(), evt);
193}
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 meshXCWWWServerElement::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_srv_model_send_param_header_t >.

90{
91 auto onoff_model = std::make_unique<meshXGenericOnOffServerModel>(
92 this, &element_ctx.gen_on_off_state,
93 (uint16_t)static_cast<int>(
95 this->get_sig_models().push_back(std::move(onoff_model));
96
97
98 auto ctl_model = std::make_unique<meshXLightCTLServerModel>(
99 this, &element_ctx.light_ctl_state,
100 (uint16_t)static_cast<int>(
102 this->get_sig_models().push_back(std::move(ctl_model));
103
104 return (uint8_t)this->get_sig_models().size();
105}
std::vector< std::unique_ptr< meshXModelIF > > & get_sig_models(void) final
Definition meshx_element_class.hpp:78
@ MESHX_CWWW_SERVER_ELEMENT_COMP_LIGHT_CTL_SERVER
Definition meshx_cwww_element.hpp:55
@ MESHX_CWWW_SERVER_ELEMENT_COMP_GENERIC_ONOFF_SERVER
Definition meshx_cwww_element.hpp:54

◆ list_ven_models()

uint8_t meshXCWWWServerElement::list_ven_models ( void )
overrideprivatevirtual

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

Reimplemented from meshXElement< meshx_srv_model_send_param_header_t >.

112{
113 return 0; /* No vendor models for CWWW server */
114}

◆ s_to_ble_cb()

meshx_err_t meshXCWWWServerElement::s_to_ble_cb ( const dev_struct_t * pdev,
control_task_msg_evt_t evt,
const void * params )
staticprivate
198{
199 MESHX_UNUSED(pdev); MESHX_UNUSED(evt); MESHX_UNUSED(params);
200 return MESHX_SUCCESS;
201}
#define MESHX_UNUSED(x)
Definition meshx_err.h:19
**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 meshXCWWWServerElement::sync ( control_task_msg_evt_t evt)
overrideprivatevirtual

Synchronize element state (Status broadcast).

Implements meshXElementIF.

169{
170 MESHX_LOGD(MODULE_ID_ELEMENT_LIGHT_CWWW_SERVER, "CWWW Srv [%d] sync event: %d", get_element_idx(), evt);
172 {
173 if (!meshx_prov_srv_is_provisioned()) return;
174 if (element_ctx.pub_addr == MESHX_ADDR_UNASSIGNED) return;
175
176 auto &models = this->get_sig_models();
177
178#if CONFIG_ENABLE_GEN_ONOFF_SERVER
179 auto *onoff = static_cast<meshXGenericOnOffServerModel *>(models[0].get());
180 onoff->request_status();
181#endif
182
183#if CONFIG_ENABLE_LIGHT_CTL_SERVER
184 auto *ctl = static_cast<meshXLightCTLServerModel *>(models[1].get());
185 ctl->request_status();
186#endif
187 }
188}
CONTROL_TASK_MSG_EVT_SYSTEM_STACK_READY
Definition meshx_control_task.h:168
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_srv_el_ctx_t meshXCWWWServerElement::element_ctx
private

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