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_base_model_light.hpp
Go to the documentation of this file.
1/**
2 * @file meshx_base_model_light.hpp
3 * @brief Header file for MeshX Light Client model declarations.
4 *
5 * This header file contains the declarations for Light BLE mesh model classes
6 * that extend the template-based meshXBaseClientModel. It defines the specific
7 * implementation for Light models including message contexts, callback structures,
8 * and the main Light Client model class.
9 *
10 * Key Components:
11 * - Light Client message context structures for TXCM integration
12 * - Resend context for timeout and retry mechanisms
13 * - meshXBaseLightClientModel class with Light-specific functionality
14 * - Platform-specific message sending and handling interfaces
15 * - Opcode validation for Light model operations
16 *
17 * Template Specialization:
18 * This file provides concrete implementations of the template-based base classes
19 * specifically tailored for Light BLE mesh models, ensuring type safety and
20 * optimal performance for Light Lightness, CTL, HSL, XYL, and LC models.
21 *
22 * @author Pranjal Chanda
23 * @date 2024-2025
24 * @copyright Copyright © 2024 - 2025 MeshX
25 */
26#ifndef _MESHX_BASE_MODEL_LIGHT_H_
27#define _MESHX_BASE_MODEL_LIGHT_H_
28
30
31#define MESHX_BASE_LIGHT_SERVER_TEMPLATE_PROTO
32#define MESHX_BASE_LIGHT_SERVER_TEMPLATE_PARAMS
33
34#define MESHX_BASE_LIGHT_CLIENT_TEMPLATE_PROTO
35#define MESHX_BASE_LIGHT_CLIENT_TEMPLATE_PARAMS
36
37#if CONFIG_ENABLE_LIGHT_CLIENT
38/*********************************************************************************************************
39 * meshXBaseLightClientModel
40 ********************************************************************************************************/
41/**
42 * @struct meshx_light_cli_resend_ctx
43 * @brief Structure containing the model ID and parameter for light client model message re-sending.
44 *
45 * This structure is used to store the model ID and parameter associated with a light client model message re-sending.
46 */
48{
49 uint16_t model_id; /**< Model ID associated with the re-sending. */
50 meshx_gen_light_cli_cb_param_t param; /**< Parameter associated with the re-sending. */
51};
52
53/**
54 * @struct meshx_light_client_msg_ctx
55 * @brief Structure containing the message context for light client model messages.
56 *
57 * This structure is used to store the message context for light client model messages, including the model context, state parameters, opcode, destination address, network index, and application key index.
58 */
60{
61 meshx_ptr_t model; /**< Model context associated with the message. */
62 uint16_t opcode; /**< Opcode associated with the message. */
63 uint16_t addr; /**< Destination address associated with the message. */
64 uint16_t net_idx; /**< Network index associated with the message. */
65 uint16_t app_idx; /**< Application key index associated with the message. */
66 meshx_light_client_set_state_t state; /**< State parameters associated with the message. */
67};
68
69/**
70 * @class meshXBaseLightClientModel
71 * @brief Template specialization of meshXBaseClientModel for Light BLE mesh models.
72 *
73 * This class provides a concrete implementation of the template-based meshXBaseClientModel
74 * specifically designed for Light BLE mesh client models. It inherits all the template
75 * benefits including type safety, static callback dispatching, and enhanced debugging
76 * while providing Light-specific functionality.
77 *
78 * Key Features:
79 * - Inherits template-based architecture from meshXBaseClientModel
80 * - Provides Light-specific opcode validation and message handling
81 * - Implements platform-specific message sending via TXCM integration
82 * - Supports all Light model types (Lightness, CTL, HSL, XYL, LC)
83 * - Enhanced error handling and debugging with template type identification
84 * - Static wrapper functions for C-style callback compatibility
85 *
86 * Template Parameters:
87 * - baseClientModelDerived_t: meshXBaseLightClientModel (CRTP pattern)
88 * - ble_mesh_plat_model_cb_params_t: meshx_gen_light_cli_cb_param_t
89 * - ble_mesh_send_msg_params_t: meshx_gen_light_client_send_params_t
90 *
91 * Supported Operations:
92 * - Light Lightness SET/GET operations
93 * - Light CTL SET/GET operations
94 * - Light HSL SET/GET operations
95 * - Light XYL SET/GET operations
96 * - Light LC (Light Control) operations
97 *
98 * @note This class uses private inheritance to maintain encapsulation while
99 * providing access to base functionality through friendship.
100 * @see meshXBaseClientModel for base template functionality.
101 * @see meshx_gen_light_cli_cb_param_t for callback parameter structure.
102 * @see meshx_gen_light_client_send_params_t for send parameter structure.
103 */
105class meshXBaseLightClientModel : public meshXBaseClientModel <meshXBaseLightClientModel, meshx_gen_light_client_send_params_t, meshx_gen_light_cli_cb_param_t>
106{
107public:
109 /* @copydoc meshXBaseClientModel::plat_model_init */
110 meshx_err_t plat_model_init(void) override;
111
112 /* @copydoc meshXBaseClientModel::validate_client_model_id */
114
115 static meshx_err_t meshx_is_unack_opcode(uint32_t opcode);
116 static meshx_err_t meshx_is_get_req_opcode(uint16_t opcode);
118public:
120
123
124 virtual ~meshXBaseLightClientModel() = default;
125};
126
127#endif /* CONFIG_ENABLE_LIGHT_CLIENT */
128
129#if CONFIG_ENABLE_LIGHT_SERVER
130/*********************************************************************************************************
131 * meshXBaseLightServerModel
132 ********************************************************************************************************/
133/**
134 * @class meshXBaseLightServerModel
135 * @brief Implementation of meshXBaseServerModel for Light BLE mesh models.
136 *
137 * This class provides a concrete implementation of the template-based meshXBaseServerModel
138 * specifically designed for Light BLE mesh server models. It inherits all the template
139 * benefits including type safety, static callback dispatching, and enhanced debugging
140 * while providing Light-specific functionality.
141 *
142 * Key Features:
143 * - Inherits template-based architecture from meshXBaseServerModel
144 * - Provides Light-specific opcode validation and message handling
145 * - Implements platform-specific message sending for Light models
146 * - Supports all Light server model types (Lightness, CTL, HSL, XYL, LC)
147 * - Enhanced error handling and debugging with template type identification
148 *
149 * Supported Operations:
150 * - Light Lightness status operations
151 * - Light CTL status operations
152 * - Light HSL status operations
153 * - Light XYL status operations
154 * - Light LC (Light Control) status operations
155 *
156 * @see meshXBaseServerModel for base template functionality.
157 * @see meshx_light_server_send_params_t for send parameter structure.
158 */
159
160/* Restore params for light server state restore (used by server_state_restore) */
161using meshx_light_server_restore_params_t = struct meshx_light_server_restore_params
162{
163 meshx_model_t *p_model; /**< Pointer to the server model. */
164 meshx_lighting_server_state_t state_change; /**< State change information. Platform Interface. */
165};
166
168class meshXBaseLightServerModel : public meshXBaseServerModel<meshXBaseLightServerModel, meshx_light_server_send_params_t, meshx_light_server_restore_params_t, meshx_lighting_server_cb_param_t>
169{
170public:
172 meshx_err_t plat_model_init(void) override;
173 meshx_err_t validate_server_status_opcode(uint16_t opcode) override;
174public:
178
180 ~meshXBaseLightServerModel() final = default;
181};
182#endif /* CONFIG_ENABLE_LIGHT_SERVER */
183
184#endif /* _MESHX_BASE_MODEL_LIGHT_H_ */
static meshx_err_t meshx_is_unack_opcode(uint32_t opcode)
Validates if a given opcode corresponds to an unacknowledged (SET_UNACK) message.
Definition meshx_base_model_light.cpp:105
meshx_err_t plat_model_init(void) override
Initialization function for the Light Client model.
Definition meshx_base_model_light.cpp:214
static meshx_err_t meshx_light_client_txcm_fn_model_send(meshx_light_client_msg_ctx_t *msg_param, size_t msg_param_len)
Send a message using the light client model.
Definition meshx_base_model_light.cpp:162
meshx_err_t plat_send_msg(meshx_gen_light_client_send_params_t *params) override
Send a message using the light client model.
Definition meshx_base_model_light.cpp:237
meshx_err_t validate_client_model_id(uint32_t model_id) override
Validates if the given model ID corresponds to a supported Light Client model.
Definition meshx_base_model_light.cpp:61
static meshx_err_t meshx_is_get_req_opcode(uint16_t opcode)
Checks if a given opcode is a GET request opcode.
Definition meshx_base_model_light.cpp:133
virtual ~meshXBaseLightClientModel()=default
meshx_err_t plat_model_init(void) override
Initialization function for the Light Server model.
Definition meshx_base_model_light.cpp:310
meshx_err_t server_state_restore(meshx_light_server_restore_params_t *param) override
Restores the state of the Light Server model.
Definition meshx_base_model_light.cpp:408
~meshXBaseLightServerModel() final=default
meshx_err_t validate_server_status_opcode(uint16_t opcode) override
Validate a light server status opcode.
Definition meshx_base_model_light.cpp:329
meshx_err_t plat_send_msg(meshx_light_server_send_params_t *params) override
Sends a status message for the Light Server model.
Definition meshx_base_model_light.cpp:375
meshXBaseLightServerModel(uint32_t model_id, meshx_ptr_t p_plat_model, const control_msg_cb &from_ble_cb)
Constructor for the meshXBaseLightServerModel class.
Definition meshx_base_model_light.cpp:290
meshx_err_t from_ble_reg_cb(void) const
Definition meshx_base_model_class.cpp:82
uint32_t model_id
Definition meshx_base_model_class.hpp:52
control_task_msg_handle_t from_ble_cb
Definition meshx_base_model_class.hpp:54
This file declares the meshXBaseModel class and its derived Client and Server classes.
std::function< meshx_err_t(dev_struct_t *, control_task_msg_evt_t, meshx_ptr_t)> control_msg_cb
Definition meshx_base_model_class.hpp:32
struct meshx_light_client_msg_ctx { meshx_ptr_t model; uint16_t opcode; uint16_t addr; uint16_t net_idx; uint16_t app_idx; meshx_light_client_set_state_t state; } meshx_light_client_msg_ctx_t
Definition meshx_base_model_light.hpp:59
struct meshx_light_cli_resend_ctx { uint16_t model_id; meshx_gen_light_cli_cb_param_t param; } meshx_light_cli_resend_ctx_t
Definition meshx_base_model_light.hpp:47
struct meshx_light_server_restore_params { meshx_model_t *p_model; meshx_lighting_server_state_t state_change; } meshx_light_server_restore_params_t
Definition meshx_base_model_light.hpp:161
#define MESHX_BASE_LIGHT_CLIENT_TEMPLATE_PROTO
Definition meshx_base_model_light.hpp:34
#define MESHX_BASE_LIGHT_SERVER_TEMPLATE_PROTO
Definition meshx_base_model_light.hpp:31
struct meshx_model meshx_model_t
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 meshx_gen_light_client_send_params meshx_gen_light_client_send_params_t
Generic Light Client Model send parameters.
struct meshx_lighting_server_state meshx_lighting_server_state_t
Lighting Server Model state Used to set/restore the model state values internally.
struct meshx_light_server_send_params meshx_light_server_send_params_t
Light Server send parameters. Used by meshXBaseLightServerModel::plat_send_msg to forward state chang...
struct meshx_lighting_server_cb_param meshx_lighting_server_cb_param_t
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
uint8_t state
Definition meshx_serial.c:39
Structure containing the model ID and parameter for light client model message re-sending.
Structure containing the message context for light client model messages.
Lighting Client Model set message union.
Definition meshx_ble_mesh_light_cli.h:210