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_model_ctl.hpp
Go to the documentation of this file.
1/**
2 * @file meshx_model_ctl.hpp
3 *
4 * @brief Header file for MeshX Light CTL Models
5 * This file contains the declarations and definitions for the MeshX Light CTL Models,
6 * including the Light CTL Server and Client models for color temperature and lightness control.
7 *
8 * Key Features:
9 * - Implements Bluetooth SIG-defined Light CTL model
10 * - Inherits from meshXServerModel and meshXClientModel templates
11 * - Provides standard Light CTL control operations (lightness, temperature, delta UV)
12 * - Integrates with MeshX transmission control
13 *
14 * @author Pranjal Chanda
15 * @date 2024-2025
16 * @copyright Copyright 2024 - 2025 MeshX
17 */
18
19#ifndef _MESHX_MODEL_CTL_HPP_
20#define _MESHX_MODEL_CTL_HPP_
21
22#include <meshx_model_class.hpp>
24
25#define MESHX_LIGHT_CTL_CLIENT_MODEL_TEMPLATE_PROTO
26#define MESHX_LIGHT_CTL_CLIENT_MODEL_TEMPLATE_PARAMS
27
28#define MESHX_LIGHT_CTL_SERVER_MODEL_TEMPLATE_PROTO
29#define MESHX_LIGHT_CTL_SERVER_MODEL_TEMPLATE_PARAMS
30
31/**
32 * @brief Structure to hold the Light CTL model state.
33 */
35{
36 uint16_t lightness; /**< The lightness value of the message. */
37 uint16_t temperature; /**< The color temperature value of the message. */
38 int16_t delta_uv; /**< The delta UV value of the message. */
39 uint16_t temp_range_min; /**< Minimum temperature range */
40 uint16_t temp_range_max; /**< Maximum temperature range */
41};
43
44/**
45 * @brief Structure to hold the parameters for sending a Light CTL message.
46 */
48{
49 meshx_model_t *model; /**< Pointer to the Light CTL client model. */
50 meshx_ctx_t *ctx; /**< The context of the message. */
51 uint8_t tid; /**< Transaction ID of the message. Only used by Client */
52 meshx_light_ctl_model_state_t state; /**< The state of the message. */
53};
54
56
57#if CONFIG_ENABLE_LIGHT_CTL_CLIENT
58
59/**
60 * @brief Structure to hold the Light CTL Client to element message.
61 */
63{
64 meshx_cli_model_send_param_header_t header; /**< Client model send param header */
65 meshx_light_ctl_model_state_t state; /**< The state of the message. */
66};
67
69
70/**
71 * @class meshXLightCTLClientModel
72 * @brief A template class for creating Light CTL Client models.
73 *
74 * This class is derived from meshXClientModel and provides a convenient interface for
75 * creating Light CTL Client models. It handles the Light CTL state change
76 * notifications from the MeshX stack and publishes the state change event to the
77 * element layer.
78 */
81 : public meshXClientModel<meshXBaseLightClientModel, meshx_light_ctl_send_params_t>
82{
83private:
85
86 /* Message to send to parent element - stored as member to persist */
88
91 uint8_t status
92 );
93
95
96public:
99 meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override;
100 meshx_err_t request_ctl (uint16_t lightness, uint16_t temperature, int16_t delta_uv, uint8_t tid = 0);
101
102 explicit meshXLightCTLClientModel (
104 meshx_ptr_t parent_element_state = nullptr,
105 uint16_t model_func_id = 0
106 );
107};
108
109#endif /* CONFIG_ENABLE_LIGHT_CTL_CLIENT */
110
111/********************************************************************************************************************************** */
112#if CONFIG_ENABLE_LIGHT_CTL_SERVER
113
114/**
115 * @brief Structure to hold the Light CTL Server to element message.
116 */
118{
119 meshx_srv_model_send_param_header_t header; /**< Server model send param header */
120 meshx_light_ctl_model_state_t state; /**< The state of the message. */
121};
122
124
125/**
126 * @class meshXLightCTLServerModel
127 * @brief A template class for creating Light CTL Server models.
128 *
129 * This class is derived from meshXServerModel and provides a convenient interface for
130 * creating Light CTL Server models. It handles the Light CTL state change
131 * notifications from the MeshX stack and publishes the state change event to the
132 * element layer.
133 */
136 : public meshXServerModel<meshXBaseLightServerModel, meshx_light_ctl_send_params_t>
137{
138private:
140
141 /* Message to send to parent element - stored as member to persist */
143
144 /* Flag to indicate if message was prepared for element notification */
146
147 meshx_err_t plat_model_create (MESHX_MODEL* p_plat_model_ptr = nullptr) override;
148 meshx_err_t plat_model_delete (void) override;
150
151public:
154 meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override;
155 meshx_err_t request_status (uint16_t dst_addr = 0);
156
157 explicit meshXLightCTLServerModel (
159 meshx_ptr_t parent_element_state = nullptr,
160 uint16_t model_func_id = 0
161 );
162};
163
164/**
165 * @class meshXLightCTLSetupServerModel
166 * @brief A class for creating Light CTL Setup Server models.
167 */
169 : public meshXServerModel<meshXBaseLightServerModel, meshx_light_ctl_send_params_t>
170{
171private:
172 meshx_err_t plat_model_create (MESHX_MODEL* p_plat_model_ptr = nullptr) override;
173 meshx_err_t plat_model_delete (void) override;
174
175public:
178 meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override { return MESHX_NOT_SUPPORTED; }
180
183 meshx_ptr_t parent_element_state = nullptr,
184 uint16_t model_func_id = 0
185 );
186};
187
188#endif /* CONFIG_ENABLE_LIGHT_CTL_SERVER */
189
190#endif /* _MESHX_MODEL_CTL_HPP_ */
Interface class for MeshX elements.
Definition meshx_fwd_decl.hpp:82
meshXLightCTLClientModel(meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
A template class for creating Light CTL Client models.
Definition meshx_model_ctl.cpp:290
meshx_err_t meshx_state_change_notify(const meshx_gen_light_cli_cb_param_t *param, uint8_t status)
Handle Light CTL state change notifications from MeshX stack.
Definition meshx_model_ctl.cpp:39
meshx_err_t element_state_change_handle(void) override
Handle state change request from element.
Definition meshx_model_ctl.cpp:83
meshx_err_t model_from_ble_cb(dev_struct_t *, control_task_msg_evt_t, meshx_ptr_t) override
Creates a meshXLightCTLClientModel instance based on a BLE device.
Definition meshx_model_ctl.cpp:117
meshx_err_t prepare_element_msg(meshx_ptr_t *msg_ptr, size_t *msg_size) override
Prepare message for element notification.
Definition meshx_model_ctl.cpp:149
meshx_err_t request_ctl(uint16_t lightness, uint16_t temperature, int16_t delta_uv, uint8_t tid=0)
Definition meshx_model_ctl.cpp:228
meshx_light_ctl_model_state_t model_state
Definition meshx_model_ctl.hpp:84
meshx_light_ctl_cli_el_msg_t element_msg
Definition meshx_model_ctl.hpp:87
meshx_err_t model_send(meshx_light_ctl_send_params_t *params) override
Send a packet to the MeshX stack based on the given parameters.
Definition meshx_model_ctl.cpp:173
meshXLightCTLServerModel(meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
Constructor for Light CTL Server Model.
Definition meshx_model_ctl.cpp:583
meshx_err_t request_status(uint16_t dst_addr=0)
Definition meshx_model_ctl.cpp:691
meshx_light_ctl_model_state_t model_state
Definition meshx_model_ctl.hpp:139
meshx_err_t plat_model_create(MESHX_MODEL *p_plat_model_ptr=nullptr) override
Creates and initializes a server model instance.
Definition meshx_model_ctl.cpp:321
meshx_err_t model_from_ble_cb(dev_struct_t *, control_task_msg_evt_t, meshx_ptr_t) override
This function is the callback for the Light CTL Server model.
Definition meshx_model_ctl.cpp:443
meshx_err_t element_state_change_handle(void) override
Handle state change request from element.
Definition meshx_model_ctl.cpp:609
meshx_light_ctl_srv_el_msg_t element_msg
Definition meshx_model_ctl.hpp:142
bool element_msg_prepared
Definition meshx_model_ctl.hpp:145
meshx_err_t plat_model_delete(void) override
Deletes the Light CTL Server model and its associated resources.
Definition meshx_model_ctl.cpp:371
meshx_err_t prepare_element_msg(meshx_ptr_t *msg_ptr, size_t *msg_size) override
Prepare message for element notification.
Definition meshx_model_ctl.cpp:555
meshx_err_t model_send(meshx_light_ctl_send_params_t *params) override
Send a packet to the MeshX stack based on the given parameters.
Definition meshx_model_ctl.cpp:402
meshx_err_t model_send(meshx_light_ctl_send_params_t *params) override
Send message through the model.
Definition meshx_model_ctl.hpp:176
meshx_err_t plat_model_create(MESHX_MODEL *p_plat_model_ptr=nullptr) override
Create logical model instance.
Definition meshx_model_ctl.cpp:634
meshXLightCTLSetupServerModel(meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
Constructor for Light CTL Setup Server Model.
Definition meshx_model_ctl.cpp:675
meshx_err_t element_state_change_handle(void) override
Handle state change request from element.
Definition meshx_model_ctl.hpp:179
meshx_err_t prepare_element_msg(meshx_ptr_t *msg_ptr, size_t *msg_size) override
Prepare message for element notification.
Definition meshx_model_ctl.hpp:178
meshx_err_t plat_model_delete(void) override
Delete logical model instance.
Definition meshx_model_ctl.cpp:655
meshx_err_t model_from_ble_cb(dev_struct_t *, control_task_msg_evt_t, meshx_ptr_t) override
Handle upstream BLE Mesh events.
Definition meshx_model_ctl.cpp:661
meshXElementIF * parent_element
Definition meshx_model_class.hpp:42
meshx_err_t status
Definition meshx_model_class.hpp:179
uint16_t model_func_id
Definition meshx_model_class.hpp:181
meshXClientModel(MESHX_MODEL *p_plat_model, uint32_t model_id, meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
Definition meshx_model_class.cpp:216
meshXServerModel(MESHX_MODEL *p_plat_model, uint32_t model_id, meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
Definition meshx_model_class.cpp:200
Header file for MeshX Light Client model declarations.
struct meshx_model meshx_model_t
struct meshx_ctx meshx_ctx_t
Structure to hold context information for BLE Mesh operations.
void * meshx_ptr_t
Definition meshx_ble_mesh_cmn_def.h:636
struct meshx_gen_light_cli_cb_param meshx_gen_light_cli_cb_param_t
Callback parameters for Generic Light Client Model events. This structure is used to pass information...
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
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
@ MESHX_NOT_SUPPORTED
Definition meshx_err.h:51
Template declarations for MeshX model wrapper classes.
struct meshx_cli_model_send_param_header meshx_cli_model_send_param_header_t
Definition meshx_model_class.hpp:417
struct meshx_srv_model_send_param_header meshx_srv_model_send_param_header_t
Definition meshx_model_class.hpp:354
struct meshx_light_ctl_model_state meshx_light_ctl_model_state_t
Definition meshx_model_ctl.hpp:42
#define MESHX_LIGHT_CTL_CLIENT_MODEL_TEMPLATE_PARAMS
Definition meshx_model_ctl.hpp:26
struct meshx_light_ctl_cli_el_msg meshx_light_ctl_cli_el_msg_t
Definition meshx_model_ctl.hpp:68
#define MESHX_LIGHT_CTL_CLIENT_MODEL_TEMPLATE_PROTO
Definition meshx_model_ctl.hpp:25
#define MESHX_LIGHT_CTL_SERVER_MODEL_TEMPLATE_PROTO
Definition meshx_model_ctl.hpp:28
struct meshx_light_ctl_send_params meshx_light_ctl_send_params_t
Definition meshx_model_ctl.hpp:55
#define MESHX_LIGHT_CTL_SERVER_MODEL_TEMPLATE_PARAMS
Definition meshx_model_ctl.hpp:29
struct meshx_light_ctl_srv_el_msg meshx_light_ctl_srv_el_msg_t
Definition meshx_model_ctl.hpp:123
**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
Structure to hold the Light CTL Client to element message.
Definition meshx_model_ctl.hpp:63
meshx_light_ctl_model_state_t state
Definition meshx_model_ctl.hpp:65
meshx_cli_model_send_param_header_t header
Definition meshx_model_ctl.hpp:64
Structure to hold the Light CTL model state.
Definition meshx_model_ctl.hpp:35
uint16_t temp_range_min
Definition meshx_model_ctl.hpp:39
uint16_t temp_range_max
Definition meshx_model_ctl.hpp:40
int16_t delta_uv
Definition meshx_model_ctl.hpp:38
uint16_t temperature
Definition meshx_model_ctl.hpp:37
uint16_t lightness
Definition meshx_model_ctl.hpp:36
Structure to hold the parameters for sending a Light CTL message.
Definition meshx_model_ctl.hpp:48
uint8_t tid
Definition meshx_model_ctl.hpp:51
meshx_light_ctl_model_state_t state
Definition meshx_model_ctl.hpp:52
meshx_ctx_t * ctx
Definition meshx_model_ctl.hpp:50
meshx_model_t * model
Definition meshx_model_ctl.hpp:49
Structure to hold the Light CTL Server to element message.
Definition meshx_model_ctl.hpp:118
meshx_srv_model_send_param_header_t header
Definition meshx_model_ctl.hpp:119
meshx_light_ctl_model_state_t state
Definition meshx_model_ctl.hpp:120