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
meshx_cwww_element.hpp
Go to the documentation of this file.
1/**
2 * @file meshx_cwww_element.hpp
3 * @brief MeshX CWWW (Cool White - Warm White) Element class definition
4 * This file contains the meshXCWWWServerElement and meshXCWWWClientElement classes
5 * which represent CWWW elements in the MeshX BLE mesh network.
6 * The CWWW element is a combination of Generic OnOff and Light CTL server/clients.
7 *
8 * @author Pranjal Chanda
9 * @date 2024-2025
10 * @copyright Copyright 2024 - 2025 MeshX
11 */
12
13#ifndef __MESHX_CWWW_ELEMENT_HPP__
14#define __MESHX_CWWW_ELEMENT_HPP__
15
19#include <mutex>
20#include <array>
21
22#define MESHX_CWWW_SERVER_ELEMENT_TEMPLATE_PROTO
23#define MESHX_CWWW_SERVER_ELEMENT_TEMPLATE_PARAMS
24
25#define MESHX_CWWW_CLIENT_ELEMENT_TEMPLATE_PROTO
26#define MESHX_CWWW_CLIENT_ELEMENT_TEMPLATE_PARAMS
27
28/**
29 * @brief CWWW server element context structure
30 * @details This structure contains the state context for the CWWW server element,
31 * including OnOff state, CTL state, and publication/app binding information.
32 * This matches the C implementation pattern where state is maintained
33 * in the element layer (el_ctx) for NVS persistence.
34 */
36{
37 // Publication and app binding
38 uint16_t app_id; /**< Application key ID for publication */
39 uint16_t pub_addr; /**< Publication address */
40 // Generic OnOff state
41 meshx_gen_onoff_model_state_t gen_on_off_state; /**< Current OnOff state (0=OFF, 1=ON) */
42 // Light CTL state
43 meshx_light_ctl_model_state_t light_ctl_state; /**< Current Light CTL state */
44};
45
47
48/*********************************************************************************
49 * meshXCWWWServerElement
50 *********************************************************************************/
51
58
61{
62private:
64
65 uint8_t list_sig_models() override;
66 uint8_t list_ven_models() override;
67 const char* get_element_name(void) const override;
68
69 /**
70 * @brief Notify element of state change from child model.
71 * @details Discriminates ONOFF vs CTL via header->model.model_id.
72 * Updates element_ctx, saves to NVS, notifies app.
73 */
74 meshx_err_t element_state_change_notify(meshx_ptr_t param, size_t param_size) override;
75
76 /**
77 * @brief Synchronize element state (Status broadcast)
78 */
79 void sync(control_task_msg_evt_t evt) override;
80
81 /**
82 * @brief Handle configuration server events
83 */
85
87 const dev_struct_t *pdev,
89 const void *params);
90
91public:
92 /**
93 * @brief Constructs a new meshXCWWWServerElement instance.
94 * The meshXCWWWServerElement represents a CWWW server element in the MeshX BLE mesh network.
95 * It automatically initializes and configures all required SIG models for the CWWW element.
96 * The CWWW element combines Generic OnOff and Light CTL server models.
97 *
98 * @param element_idx The index of the element within the node.
99 */
100 explicit meshXCWWWServerElement(uint16_t element_idx);
102
103 uint8_t get_onoff() { return element_ctx.gen_on_off_state.on_off; }
104 meshx_light_ctl_model_state_t& get_ctl() { return element_ctx.light_ctl_state; }
105};
106
107/*********************************************************************************
108 * meshXCWWWClientElement
109 *********************************************************************************/
110
111/**
112 * @brief CWWW client element context structure
113 * @details This structure contains the state context for the CWWW client element,
114 * including OnOff state, CTL state, and publication/app binding information.
115 * This matches the C implementation pattern where state is maintained
116 * in the element layer (el_ctx) for NVS persistence.
117 */
119{
120 // Publication and app binding
121 uint16_t app_id; /**< Application key ID for publication */
122 uint16_t pub_addr; /**< Publication address */
123 // Generic OnOff state
124 meshx_gen_onoff_model_state_t gen_on_off_state; /**< Current OnOff state (0=OFF, 1=ON) */
125 // Light CTL state
126 meshx_light_ctl_model_state_t light_ctl_state; /**< Current Light CTL state */
127 uint8_t ctl_tid; /**< Transaction ID for CTL messages */
128};
129
136
139{
140private:
142
143 uint8_t list_sig_models() override;
144 uint8_t list_ven_models() override;
145 const char* get_element_name(void) const override;
146
147 /**
148 * @brief Notify element of state change from child model.
149 * @details Discriminates ONOFF vs CTL via header->model.model_id.
150 * Updates element_ctx and notifies app.
151 */
152 meshx_err_t element_state_change_notify(meshx_ptr_t param, size_t param_size) override;
153
154 /**
155 * @brief Synchronize element state (GET requests)
156 */
157 void sync(control_task_msg_evt_t evt) override;
158
159 /**
160 * @brief Handle configuration server events
161 */
162 void handle_config(control_task_msg_evt_t evt, const meshx_config_srv_cb_param_t *params) override;
163
165 const dev_struct_t *pdev,
167 const void *params);
168
169public:
170 /**
171 * @brief Constructs a new meshXCWWWClientElement instance.
172 * The meshXCWWWClientElement represents a CWWW client element in the MeshX BLE mesh network.
173 * It automatically initializes and configures all required SIG models for the CWWW element.
174 * The CWWW element combines Generic OnOff and Light CTL client models.
175 *
176 * @param element_idx The index of the element within the node.
177 */
178 explicit meshXCWWWClientElement(uint16_t element_idx);
180
181
182 uint8_t get_onoff() { return element_ctx.gen_on_off_state.on_off; }
183 meshx_light_ctl_model_state_t& get_ctl() { return element_ctx.light_ctl_state; }
185};
186
187#endif /* __MESHX_CWWW_ELEMENT_HPP__ */
meshx_cwww_cli_el_ctx_t element_ctx
Definition meshx_cwww_element.hpp:141
void handle_config(control_task_msg_evt_t evt, const meshx_config_srv_cb_param_t *params) override
Handle configuration server events.
Definition meshx_cwww_element.cpp:357
meshx_err_t element_state_change_notify(meshx_ptr_t param, size_t param_size) override
Notify element of state change from child model.
Definition meshx_cwww_element.cpp:271
meshx_light_ctl_model_state_t & get_ctl()
Definition meshx_cwww_element.hpp:183
meshXCWWWClientElement()=delete
meshx_cwww_cli_el_ctx_t & get_ctx()
Definition meshx_cwww_element.hpp:184
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
uint8_t list_sig_models() override
Lists and creates all required SIG models for the element.
Definition meshx_cwww_element.cpp:236
const char * get_element_name(void) const override
Get the name of the element.
Definition meshx_cwww_element.cpp:264
meshXCWWWClientElement(uint16_t element_idx)
Constructs a new meshXCWWWClientElement instance. The meshXCWWWClientElement represents a CWWW client...
Definition meshx_cwww_element.cpp:212
void sync(control_task_msg_evt_t evt) override
Synchronize element state (GET requests).
Definition meshx_cwww_element.cpp:311
uint8_t list_ven_models() override
Lists Vendor models for CWWW Client Element (none required).
Definition meshx_cwww_element.cpp:258
uint8_t get_onoff()
Definition meshx_cwww_element.hpp:182
const char * get_element_name(void) const override
Get the name of the element.
Definition meshx_cwww_element.cpp:117
uint8_t get_onoff()
Definition meshx_cwww_element.hpp:103
meshx_err_t element_state_change_notify(meshx_ptr_t param, size_t param_size) override
Notify element of state change from child model.
Definition meshx_cwww_element.cpp:124
meshx_cwww_srv_el_ctx_t element_ctx
Definition meshx_cwww_element.hpp:63
meshXCWWWServerElement(uint16_t element_idx)
Constructs a new meshXCWWWServerElement instance. The meshXCWWWServerElement represents a CWWW server...
Definition meshx_cwww_element.cpp:65
meshx_light_ctl_model_state_t & get_ctl()
Definition meshx_cwww_element.hpp:104
uint8_t list_ven_models() override
Lists Vendor models for CWWW Server Element (none required).
Definition meshx_cwww_element.cpp:111
uint8_t list_sig_models() override
Lists and creates all required SIG models for the element.
Definition meshx_cwww_element.cpp:89
void sync(control_task_msg_evt_t evt) override
Synchronize element state (Status broadcast).
Definition meshx_cwww_element.cpp:168
meshXCWWWServerElement()=delete
void handle_config(control_task_msg_evt_t evt, const meshx_config_srv_cb_param_t *params) override
Handle configuration server events.
Definition meshx_cwww_element.cpp:190
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
meshXElementClient()=default
uint16_t element_idx
Definition meshx_fwd_decl.hpp:84
meshXElementServer()=default
void * meshx_ptr_t
Definition meshx_ble_mesh_cmn_def.h:636
struct meshx_config_srv_cb_param meshx_config_srv_cb_param_t
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.
Definition meshx_control_task.h:81
#define MESHX_CWWW_SERVER_ELEMENT_TEMPLATE_PROTO
Definition meshx_cwww_element.hpp:22
meshxCWWWServerElementComposition
Definition meshx_cwww_element.hpp:53
@ 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
@ MESHX_CWWW_SERVER_ELEMENT_COMP_MAX
Definition meshx_cwww_element.hpp:56
#define MESHX_CWWW_CLIENT_ELEMENT_TEMPLATE_PROTO
Definition meshx_cwww_element.hpp:25
#define MESHX_CWWW_SERVER_ELEMENT_TEMPLATE_PARAMS
Definition meshx_cwww_element.hpp:23
#define MESHX_CWWW_CLIENT_ELEMENT_TEMPLATE_PARAMS
Definition meshx_cwww_element.hpp:26
meshxCWWWClientElementComposition
Definition meshx_cwww_element.hpp:131
@ MESHX_CWWW_CLIENT_ELEMENT_COMP_MAX
Definition meshx_cwww_element.hpp:134
@ 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
MeshX Element class and interface declaration This file contains the meshXElement class and its inter...
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
Header file for MeshX Light CTL Models This file contains the declarations and definitions for the Me...
struct meshx_light_ctl_model_state meshx_light_ctl_model_state_t
Definition meshx_model_ctl.hpp:42
Implementation of Generic OnOff Client Model for MeshX.
struct meshx_gen_onoff_model_state meshx_gen_onoff_model_state_t
Definition meshx_model_onoff.hpp:38
CWWW client element context structure.
Definition meshx_cwww_element.hpp:119
meshx_light_ctl_model_state_t light_ctl_state
Definition meshx_cwww_element.hpp:126
uint16_t app_id
Definition meshx_cwww_element.hpp:121
meshx_gen_onoff_model_state_t gen_on_off_state
Definition meshx_cwww_element.hpp:124
uint16_t pub_addr
Definition meshx_cwww_element.hpp:122
uint8_t ctl_tid
Definition meshx_cwww_element.hpp:127
CWWW server element context structure.
Definition meshx_cwww_element.hpp:36
meshx_gen_onoff_model_state_t gen_on_off_state
Definition meshx_cwww_element.hpp:41
uint16_t app_id
Definition meshx_cwww_element.hpp:38
meshx_light_ctl_model_state_t light_ctl_state
Definition meshx_cwww_element.hpp:43
uint16_t pub_addr
Definition meshx_cwww_element.hpp:39