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_hsl.hpp
Go to the documentation of this file.
1/**
2 * @file meshx_model_hsl.hpp
3 *
4 * @brief Header file for MeshX Light HSL Models
5 * This file contains the declarations and definitions for the MeshX Light HSL Models,
6 * including the Light HSL Server and Client models for hue, saturation, and lightness control.
7 *
8 * Key Features:
9 * - Implements Bluetooth SIG-defined Light HSL model
10 * - Inherits from meshXServerModel and meshXClientModel templates
11 * - Provides standard Light HSL control operations (hue, saturation, lightness)
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_HSL_HPP_
20#define _MESHX_MODEL_HSL_HPP_
21
22#include <meshx_model_class.hpp>
24
25#define MESHX_LIGHT_HSL_CLIENT_MODEL_TEMPLATE_PROTO
26#define MESHX_LIGHT_HSL_CLIENT_MODEL_TEMPLATE_PARAMS
27
28#define MESHX_LIGHT_HSL_SERVER_MODEL_TEMPLATE_PROTO
29#define MESHX_LIGHT_HSL_SERVER_MODEL_TEMPLATE_PARAMS
30
31/**
32 * @brief Structure to hold the Light HSL model state.
33 */
35{
36 uint16_t lightness; /**< Present lightness value */
37 uint16_t hue; /**< Present hue value */
38 uint16_t saturation; /**< Present saturation value */
39 uint16_t target_lightness; /**< Target lightness value */
40 uint16_t target_hue; /**< Target hue value */
41 uint16_t target_saturation;/**< Target saturation value */
42 uint16_t hue_range_min; /**< Hue range minimum */
43 uint16_t hue_range_max; /**< Hue range maximum */
44 uint16_t sat_range_min; /**< Saturation range minimum */
45 uint16_t sat_range_max; /**< Saturation range maximum */
46};
47
49
50/**
51 * @brief Structure to hold the parameters for sending a Light HSL message.
52 */
54{
55 meshx_model_t *model; /**< Pointer to the Light HSL client model. */
56 meshx_ctx_t *ctx; /**< The context of the message. */
57 uint8_t tid; /**< Transaction ID of the message. Only used by Client */
58 meshx_light_hsl_model_state_t state; /**< The state of the message. */
59};
60
62
63#if CONFIG_ENABLE_LIGHT_HSL_CLIENT
64
65/**
66 * @brief Structure to hold the Light HSL Client to element message.
67 */
68struct meshx_light_hsl_cli_el_msg
69{
70 meshx_cli_model_send_param_header_t header; /**< Client model send param header */
71 meshx_light_hsl_model_state_t state; /**< The state of the message. */
72};
73
74using meshx_light_hsl_cli_el_msg_t = struct meshx_light_hsl_cli_el_msg;
75
76/**
77 * @class meshXLightHSLClientModel
78 * @brief A template class for creating Light HSL Client models.
79 *
80 * This class is derived from meshXClientModel and provides a convenient interface for
81 * creating Light HSL Client models. It handles the Light HSL state change
82 * notifications from the MeshX stack and publishes the state change event to the
83 * element layer.
84 */
86class meshXLightHSLClientModel MESHX_LIGHT_HSL_CLIENT_MODEL_TEMPLATE_PARAMS
87 : public meshXClientModel<meshXBaseLightClientModel, meshx_light_hsl_send_params_t>
88{
89private:
90 /* New or updated model state from BLE layer */
92
93 meshx_err_t meshx_state_change_notify (
95 uint8_t status
96 );
97
99
100public:
103 meshx_err_t request_hsl (uint16_t lightness, uint16_t hue, uint16_t saturation, uint8_t tid);
104
105 meshXLightHSLClientModel(
106 meshXElementIF *parent_element = nullptr,
107 meshx_ptr_t parent_element_state = nullptr,
108 uint16_t model_func_id = 0
109 );
110 ~meshXLightHSLClientModel() = default;
111};
112
113#endif /* CONFIG_ENABLE_LIGHT_HSL_CLIENT */
114
115/********************************************************************************************************************************** */
116/**
117 * @brief Structure to hold the Light HSL Server to element message.
118 */
120{
121 meshx_srv_model_send_param_header_t header; /**< Server model send param header */
122 meshx_light_hsl_model_state_t state; /**< The state of the message. */
123};
124
126
127#if CONFIG_ENABLE_LIGHT_HSL_SERVER
128
129/**
130 * @class meshXLightHSLServerModel
131 * @brief A template class for creating Light HSL Server models.
132 *
133 * This class is derived from meshXServerModel and provides a convenient interface for
134 * creating Light HSL Server models. It handles the Light HSL state change
135 * notifications from the MeshX stack and publishes the state change event to the
136 * element layer.
137 */
140 : public meshXServerModel<meshXBaseLightServerModel, meshx_light_hsl_send_params_t>
141{
142private:
143 /* New or updated model state from BLE layer */
147
148 meshx_err_t plat_model_create (MESHX_MODEL* p_plat_model_ptr = nullptr) override;
149 meshx_err_t plat_model_delete (void) override;
151 meshx_err_t prepare_element_msg(meshx_ptr_t *msg_ptr, size_t *msg_size) override;
152
153public:
156 meshx_err_t request_status (uint16_t dst_addr = 0);
157
160 meshx_ptr_t parent_element_state = nullptr,
161 uint16_t model_func_id = 0
162 );
164};
165
166#endif /* CONFIG_ENABLE_LIGHT_HSL_SERVER */
167
168#endif /* _MESHX_MODEL_HSL_HPP_ */
Base class for all client models in the mesh network.
Definition meshx_model_class.hpp:429
Interface class for MeshX elements.
Definition meshx_fwd_decl.hpp:82
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 HSL Server model.
Definition meshx_model_hsl.cpp:427
meshx_light_hsl_model_state_t model_state
Definition meshx_model_hsl.hpp:144
bool element_msg_prepared
Definition meshx_model_hsl.hpp:146
meshx_light_hsl_srv_el_msg_t element_msg
Definition meshx_model_hsl.hpp:145
meshx_err_t model_send(meshx_light_hsl_send_params_t *params) override
Send a packet to the MeshX stack based on the given parameters.
Definition meshx_model_hsl.cpp:387
meshx_err_t plat_model_delete(void) override
Deletes the Light HSL Server model and its associated resources.
Definition meshx_model_hsl.cpp:356
meshx_err_t request_status(uint16_t dst_addr=0)
Definition meshx_model_hsl.cpp:619
meshx_err_t element_state_change_handle(void) override
Handle state change request from element.
Definition meshx_model_hsl.cpp:573
meshx_err_t prepare_element_msg(meshx_ptr_t *msg_ptr, size_t *msg_size) override
Handle state change request from element.
Definition meshx_model_hsl.cpp:553
meshx_err_t plat_model_create(MESHX_MODEL *p_plat_model_ptr=nullptr) override
Creates and initializes a server model instance.
Definition meshx_model_hsl.cpp:319
~meshXLightHSLServerModel()=default
meshXLightHSLServerModel(meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
Constructor for Light HSL Server Model.
Definition meshx_model_hsl.cpp:607
meshXElementIF * parent_element
Definition meshx_model_class.hpp:42
virtual meshx_err_t element_state_change_handle(void)=0
Handle state change request from element.
virtual meshx_err_t model_from_ble_cb(dev_struct_t *dev, control_task_msg_evt_t evt, meshx_ptr_t data)=0
uint16_t model_func_id
Definition meshx_model_class.hpp:181
virtual meshx_err_t model_send(meshx_send_packet_params_t *params)=0
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
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_hsl_model_state meshx_light_hsl_model_state_t
Definition meshx_model_hsl.hpp:48
#define MESHX_LIGHT_HSL_SERVER_MODEL_TEMPLATE_PARAMS
Definition meshx_model_hsl.hpp:29
struct meshx_light_hsl_srv_el_msg meshx_light_hsl_srv_el_msg_t
Definition meshx_model_hsl.hpp:125
struct meshx_light_hsl_send_params meshx_light_hsl_send_params_t
Definition meshx_model_hsl.hpp:61
#define MESHX_LIGHT_HSL_SERVER_MODEL_TEMPLATE_PROTO
Definition meshx_model_hsl.hpp:28
#define MESHX_LIGHT_HSL_CLIENT_MODEL_TEMPLATE_PROTO
Definition meshx_model_hsl.hpp:25
#define MESHX_LIGHT_HSL_CLIENT_MODEL_TEMPLATE_PARAMS
Definition meshx_model_hsl.hpp:26
uint8_t state
Definition meshx_serial.c:39
Structure to hold the Light HSL model state.
Definition meshx_model_hsl.hpp:35
uint16_t target_saturation
Definition meshx_model_hsl.hpp:41
uint16_t target_lightness
Definition meshx_model_hsl.hpp:39
uint16_t sat_range_min
Definition meshx_model_hsl.hpp:44
uint16_t saturation
Definition meshx_model_hsl.hpp:38
uint16_t target_hue
Definition meshx_model_hsl.hpp:40
uint16_t hue
Definition meshx_model_hsl.hpp:37
uint16_t hue_range_max
Definition meshx_model_hsl.hpp:43
uint16_t lightness
Definition meshx_model_hsl.hpp:36
uint16_t sat_range_max
Definition meshx_model_hsl.hpp:45
uint16_t hue_range_min
Definition meshx_model_hsl.hpp:42
Structure to hold the parameters for sending a Light HSL message.
Definition meshx_model_hsl.hpp:54
meshx_ctx_t * ctx
Definition meshx_model_hsl.hpp:56
meshx_model_t * model
Definition meshx_model_hsl.hpp:55
uint8_t tid
Definition meshx_model_hsl.hpp:57
meshx_light_hsl_model_state_t state
Definition meshx_model_hsl.hpp:58
Structure to hold the Light HSL Server to element message.
Definition meshx_model_hsl.hpp:120
meshx_light_hsl_model_state_t state
Definition meshx_model_hsl.hpp:122
meshx_srv_model_send_param_header_t header
Definition meshx_model_hsl.hpp:121