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_generic.hpp
Go to the documentation of this file.
1/**
2 * @file meshx_base_model_generic.hpp
3 * @brief Header file for MeshX Generic Client and Server model declarations.
4 *
5 * This header file contains the declarations for Generic BLE mesh model classes
6 * that extend the template-based meshXBaseClientModel and meshXBaseServerModel.
7 * It defines the specific implementation for Generic models including message
8 * contexts, callback structures, and the main Generic Client model class.
9 *
10 * Key Components:
11 * - Generic Client message context structures for TXCM integration
12 * - Resend context for timeout and retry mechanisms
13 * - meshXBaseGenericClientModel class with Generic-specific functionality
14 * - Platform-specific message sending and handling interfaces
15 * - Opcode validation for Generic model operations
16 *
17 * Template Specialization:
18 * This file provides concrete implementations of the template-based base classes
19 * specifically tailored for Generic BLE mesh models, ensuring type safety and
20 * optimal performance for Generic OnOff, Level, Power, Battery, and Location models.
21 *
22 * @author Pranjal Chanda
23 * @date 2024-2025
24 * @copyright Copyright © 2024 - 2025 MeshX
25 */
26#ifndef _MESHX_BASE_MODEL_GENERIC_H_
27#define _MESHX_BASE_MODEL_GENERIC_H_
28
30
31#define MESHX_BASE_GENERIC_SERVER_TEMPLATE_PROTO
32#define MESHX_BASE_GENERIC_SERVER_TEMPLATE_PARAMS
33
34#define MESHX_BASE_GENERIC_CLIENT_TEMPLATE_PROTO
35#define MESHX_BASE_GENERIC_CLIENT_TEMPLATE_PARAMS
36
37#if CONFIG_ENABLE_GEN_CLIENT
38/*********************************************************************************************************
39 * meshXBaseGenericClientModel
40 ********************************************************************************************************/
41/**
42 * @struct meshx_gen_cli_resend_ctx
43 * @brief Structure containing the model ID and parameter for generic client model message re-sending.
44 *
45 * This structure is used to store the model ID and parameter associated with a generic client model message re-sending.
46 */
48{
49 uint16_t model_id; /**< Model ID associated with the re-sending. */
50 meshx_gen_cli_cb_param_t param; /**< Parameter associated with the re-sending. */
51};
52/**
53 * @struct meshx_gen_client_msg_ctx
54 * @brief Structure containing the message context for generic client model messages.
55 *
56 * This structure is used to store the message context for generic client model messages, including the model context, state parameters, opcode, destination address, network index, and application key index.
57 */
59{
60 meshx_ptr_t model; /**< Model context associated with the message. */
61 uint16_t opcode; /**< Opcode associated with the message. */
62 uint16_t addr; /**< Destination address associated with the message. */
63 uint16_t net_idx; /**< Network index associated with the message. */
64 uint16_t app_idx; /**< Application key index associated with the message. */
65 meshx_gen_cli_set_t state; /**< State parameters associated with the message. */
66};
67
68/**
69 * @class meshXBaseGenericClientModel
70 * @brief Template specialization of meshXBaseClientModel for Generic BLE mesh models.
71 *
72 * This class provides a concrete implementation of the template-based meshXBaseClientModel
73 * specifically designed for Generic BLE mesh client models. It inherits all the template
74 * benefits including type safety, static callback dispatching, and enhanced debugging
75 * while providing Generic-specific functionality.
76 *
77 * Key Features:
78 * - Inherits template-based architecture from meshXBaseClientModel
79 * - Provides Generic-specific opcode validation and message handling
80 * - Implements platform-specific message sending via TXCM integration
81 * - Supports all Generic model types (OnOff, Level, Power, Battery, Location)
82 * - Enhanced error handling and debugging with template type identification
83 * - Static wrapper functions for C-style callback compatibility
84 *
85 * Template Parameters:
86 * - baseClientModelDerived_t: meshXBaseGenericClientModel (CRTP pattern)
87 * - ble_mesh_plat_model_cb_params_t: meshx_gen_cli_cb_param_t
88 * - ble_mesh_send_msg_params_t: meshx_gen_client_send_params_t
89 *
90 * Supported Operations:
91 * - Generic OnOff SET/GET operations
92 * - Generic Level SET/GET operations
93 * - Generic Power Level operations
94 * - Generic Battery status operations
95 * - Generic Location operations
96 * - Property-based operations (Manufacturer, Admin, User)
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_cli_cb_param_t for callback parameter structure.
102 * @see meshx_gen_client_send_params_t for send parameter structure.
103 */
105class meshXBaseGenericClientModel : public meshXBaseClientModel<meshXBaseGenericClientModel, meshx_gen_client_send_params_t, meshx_gen_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);
117 static meshx_err_t meshx_gen_client_txcm_fn_model_send(meshx_gen_client_msg_ctx_t *msg_param, size_t msg_param_len);
118
119public:
121
124
125 virtual ~meshXBaseGenericClientModel() = default;
126};
127
128#endif /* CONFIG_ENABLE_GEN_CLIENT */
129
130#if CONFIG_ENABLE_GEN_SERVER
131/*********************************************************************************************************
132 * meshXBaseGenericServerModel
133 ********************************************************************************************************/
134
135using meshx_gen_server_send_params_t = struct meshx_gen_server_send_params
136{
137 meshx_model_t *p_model; /**< Pointer to the server model. */
138 meshx_ctx_t *p_ctx; /**< Pointer to the context. */
139 meshx_gen_srv_state_change_t state_change; /**< State change information. Platform Interface. */
140 size_t data_len; /**< Length of the data. */
141};
142
143using meshx_gen_server_restore_params_t = struct meshx_gen_server_restore_params
144{
145 meshx_model_t *p_model; /**< Pointer to the server model. */
146 meshx_gen_server_state_t state_change; /**< State change information. Platform Interface. */
147};
148/**
149 * @class meshXBaseGenericServerModel
150 * @brief Template specialization of meshXBaseServerModel for Generic BLE mesh models.
151 *
152 * This class provides a concrete implementation of the template-based meshXBaseServerModel
153 * specifically designed for Generic BLE mesh server models. It inherits all the template
154 * benefits including type safety, static callback dispatching, and enhanced debugging
155 * while providing Generic-specific functionality.
156 *
157 * Key Features:
158 * - Inherits template-based architecture from meshXBaseServerModel
159 * - Provides Generic-specific opcode validation and message handling
160 * - Implements platform-specific message sending
161 * - Supports all Generic model types (OnOff, Level, Power, Battery, Location)
162 * - Enhanced error handling and debugging with template type identification
163 * - Static wrapper functions for C-style callback compatibility
164 *
165 * Template Parameters:
166 * - baseServerModelDerived_t: meshXBaseGenericServerModel (CRTP pattern)
167 * - ble_mesh_send_msg_params_t: meshx_gen_server_send_params_t
168 *
169 * Supported Operations:
170 * - Generic OnOff status updates
171 * - Generic Level status updates
172 * - Generic Power Level status updates
173 * - Generic Battery status updates
174 * - Generic Location status updates
175 * - Property-based status updates (Manufacturer, Admin, User)
176 *
177 * @note This class uses private inheritance to maintain encapsulation while
178 * providing access to base functionality through friendship.
179 * @see meshXBaseServerModel for base template functionality.
180 * @see meshx_gen_server_send_params_t for send parameter structure.
181 */
183class meshXBaseGenericServerModel : public meshXBaseServerModel<meshXBaseGenericServerModel, meshx_gen_server_send_params_t, meshx_gen_server_restore_params_t, meshx_gen_srv_cb_param_t>
184{
185public:
187 meshx_err_t plat_model_init(void) override;
188 meshx_err_t validate_server_status_opcode(uint16_t opcode) override;
189public:
195};
196#endif /* CONFIG_ENABLE_GEN_SERVER */
197
198#endif /* _MESHX_BASE_MODEL_GENERIC_H_ */
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_generic.cpp:144
meshx_err_t plat_send_msg(meshx_gen_client_send_params_t *params) override
Send a message using the generic client model.
Definition meshx_base_model_generic.cpp:263
static meshx_err_t meshx_gen_client_txcm_fn_model_send(meshx_gen_client_msg_ctx_t *msg_param, size_t msg_param_len)
Send a message using the generic client model.
Definition meshx_base_model_generic.cpp:181
meshx_err_t validate_client_model_id(uint32_t model_id) override
Validates if the given model ID corresponds to a supported Generic Client model.
Definition meshx_base_model_generic.cpp:65
meshx_err_t plat_model_init(void) override
Initialization function for the Generic OnOff Client model.
Definition meshx_base_model_generic.cpp:238
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_generic.cpp:113
virtual ~meshXBaseGenericClientModel()=default
meshXBaseGenericServerModel(uint32_t model_id, meshx_ptr_t p_plat_model, const control_msg_cb &from_ble_cb)
Constructor for the meshXBaseGenericServerModel class.
Definition meshx_base_model_generic.cpp:318
meshx_err_t server_state_restore(meshx_gen_server_restore_params_t *param) override
Restores the state of the Generic Server model.
Definition meshx_base_model_generic.cpp:439
~meshXBaseGenericServerModel() final=default
meshx_err_t plat_model_init(void) override
Initialization function for the Generic OnOff Server model.
Definition meshx_base_model_generic.cpp:341
meshx_err_t validate_server_status_opcode(uint16_t opcode) override
Validate a server status opcode.
Definition meshx_base_model_generic.cpp:362
meshx_err_t plat_send_msg(meshx_gen_server_send_params_t *params) override
Sends a status message for the Generic Server model.
Definition meshx_base_model_generic.cpp:401
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
#define MESHX_BASE_GENERIC_SERVER_TEMPLATE_PROTO
Definition meshx_base_model_generic.hpp:31
struct meshx_gen_server_restore_params { meshx_model_t *p_model; meshx_gen_server_state_t state_change; } meshx_gen_server_restore_params_t
Definition meshx_base_model_generic.hpp:143
struct meshx_gen_client_msg_ctx { meshx_ptr_t model; uint16_t opcode; uint16_t addr; uint16_t net_idx; uint16_t app_idx; meshx_gen_cli_set_t state; } meshx_gen_client_msg_ctx_t
Definition meshx_base_model_generic.hpp:58
#define MESHX_BASE_GENERIC_CLIENT_TEMPLATE_PROTO
Definition meshx_base_model_generic.hpp:34
struct meshx_gen_server_send_params { meshx_model_t *p_model; meshx_ctx_t *p_ctx; meshx_gen_srv_state_change_t state_change; size_t data_len; } meshx_gen_server_send_params_t
Definition meshx_base_model_generic.hpp:135
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_client_send_params meshx_gen_client_send_params_t
Generic Client Model send parameters.
struct meshx_gen_cli_cb_param meshx_gen_cli_cb_param_t
Callback parameters for Generic Client Model events. This structure is used to pass information about...
struct meshx_gen_server_state meshx_gen_server_state_t
Generic Server Model state Used to set/restore the model state values internally.
struct meshx_gen_srv_cb_param meshx_gen_srv_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 generic client model message re-sending.
Structure containing the message context for generic client model messages.
Generic Client Model set message union.
Definition meshx_ble_mesh_gen_cli.h:116
Definition meshx_ble_mesh_gen_srv.h:118