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_power_level.hpp
Go to the documentation of this file.
1/**
2 * @file meshx_model_power_level.hpp
3 * @brief Implementation of Generic Power Level Model for MeshX
4 *
5 * This file contains the implementation of the Generic Power Level model,
6 * which provides standard Power Level model functionality in the MeshX BLE mesh framework.
7 *
8 * Key Features:
9 * - Implements Bluetooth SIG-defined Generic Power Level model
10 * - Inherits from meshXClientModel, meshXServerModel templates
11 * - Provides standard Power Level control operations (GET, SET, LAST, DEFAULT, RANGE)
12 * - Integrates with MeshX transmission control
13 *
14 * @author Pranjal Chanda
15 * @date 2024-2025
16 * @copyright Copyright 2024 - 2025 MeshX
17 */
18#ifndef _MESHX_MODEL_POWER_LEVEL_HPP_
19#define _MESHX_MODEL_POWER_LEVEL_HPP_
20
21#include <meshx_model_class.hpp>
23
24#define MESHX_GEN_POWER_LEVEL_CLIENT_MODEL_TEMPLATE_PROTO
25#define MESHX_GEN_POWER_LEVEL_CLIENT_MODEL_TEMPLATE_PARAMS
26
27#define MESHX_GEN_POWER_LEVEL_SERVER_MODEL_TEMPLATE_PROTO
28#define MESHX_GEN_POWER_LEVEL_SERVER_MODEL_TEMPLATE_PARAMS
29
30#define MESHX_GEN_POWER_LEVEL_SETUP_SERVER_MODEL_TEMPLATE_PROTO
31#define MESHX_GEN_POWER_LEVEL_SETUP_SERVER_MODEL_TEMPLATE_PARAMS
32
33/**
34 * @brief Structure to hold the Power Level model state.
35 */
37{
38 uint16_t present_power; /**< The present value of Generic Power Level state */
39 uint16_t target_power; /**< The target value of Generic Power Level state (optional) */
40 uint8_t remain_time; /**< Time to complete state transition (C.1) */
41 uint16_t power_default; /**< The default power level */
42 struct
43 {
44 uint16_t range_min; /**< Minimum value of Generic Power Level state */
45 uint16_t range_max; /**< Maximum value of Generic Power Level state */
46 } range; /**< Power level range parameters */
47};
48
50
51/**
52 * @brief Structure to hold the parameters for sending a Generic Power Level message.
53 */
55{
56 meshx_model_t *model; /**< Pointer to the Power Level client model. */
57 meshx_ctx_t *ctx; /**< The context of the message. */
58 uint8_t tid; /**< The transaction ID of the message. Only used by Client*/
59 uint8_t transition_time; /**< Transition time (optional). */
60 uint8_t delay; /**< Delay (optional). */
61 meshx_gen_power_level_model_state_t state; /**< The state of the message. */
62};
63
65
66#if CONFIG_ENABLE_GEN_POWER_LEVEL_CLIENT
67/**
68 * @brief Structure to hold the Power Level Server to parent element message.
69 * The structure is used by the on_model_cb function to send the Power Level state
70 * change notification to the parent element.
71 */
73{
74 meshx_cli_model_send_param_header_t header; /**< Client model send param header */
75 meshx_gen_power_level_model_state_t state; /**< The state of the message. */
76};
77
79/**
80 * @class meshXGenericPowerLevelClientModel
81 * @brief A template class for creating Generic Power Level Client models.
82 *
83 * This class is derived from meshXClientModel and provides a convenient interface for
84 * creating Generic Power Level Client models. It handles the Generic Power Level state change
85 * notifications from the MeshX stack and publishes the state change event to the
86 * element layer.
87 */
89class meshXGenericPowerLevelClientModel : public meshXClientModel<meshXBaseGenericClientModel, meshx_gen_power_level_send_params_t>
90{
91private:
92 /* New or updated model state from BLE layer */
94
95 /* Message to be sent to parent element */
97
100
101public:
104 meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override;
105
108 meshx_ptr_t parent_element_state = nullptr,
109 uint16_t model_func_id = 0
110 );
112};
113
114#endif /* CONFIG_ENABLE_GEN_POWER_LEVEL_CLIENT */
115
116#if CONFIG_ENABLE_GEN_POWER_LEVEL_SERVER
117
118/**
119 * @brief Structure to hold the Power Level Server to parent element message.
120 * The structure is used by the on_model_cb function to send the Power Level state
121 * change notification to the parent element.
122 */
124{
125 meshx_srv_model_send_param_header_t header; /**< Server model send param header */
126 meshx_gen_power_level_model_state_t state; /**< The state of the message. */
127};
128
130
131/**
132 * @class meshXGenericPowerLevelServerModel
133 * @brief A template class for creating Generic Power Level Server models.
134 *
135 * This class is derived from meshXServerModel and provides a convenient interface for
136 * creating Generic Power Level Server models. It handles the Generic Power Level state change
137 * notifications from the MeshX stack and publishes the state change event to the
138 * element layer.
139 */
141class meshXGenericPowerLevelServerModel : public meshXServerModel<meshXBaseGenericServerModel, meshx_gen_power_level_send_params_t>
142{
143private:
144 /* New or updated model state from BLE layer */
146
147 /* Message to be sent to parent element */
149
150 /* Flag to indicate if element message has been prepared */
152
153 meshx_err_t plat_model_create (MESHX_MODEL* p_plat_model_ptr = nullptr) override;
154 meshx_err_t plat_model_delete (void) override;
155
156public:
159 meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override;
160
161 // Virtual method implementation from meshXModelIF
163
166 meshx_ptr_t parent_element_state = nullptr,
167 uint16_t model_func_id = 0
168 );
170};
171#endif /* CONFIG_ENABLE_GEN_POWER_LEVEL_SERVER */
172
173#if CONFIG_ENABLE_GEN_POWER_LEVEL_SETUP_SERVER
174/**
175 * @class meshXGenericPowerLevelSetupServerModel
176 * @brief A template class for creating Generic Power Level Setup Server models.
177 *
178 * This class is derived from meshXServerModel and provides a convenient interface for
179 * creating Generic Power Level Setup Server models. It handles the Generic Power Level setup
180 * operations from the MeshX stack.
181 */
183class meshXGenericPowerLevelSetupServerModel : public meshXServerModel<meshXBaseGenericServerModel, meshx_gen_power_level_send_params_t>
184{
185private:
186 /* Message to be sent to parent element */
188
189 /* Flag to indicate if element message has been prepared */
191
192public:
195 meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override;
196
199 meshx_ptr_t parent_element_state = nullptr,
200 uint16_t model_func_id = 0
201 );
203};
204#endif /* CONFIG_ENABLE_GEN_POWER_LEVEL_SETUP_SERVER */
205
206#endif /* _MESHX_MODEL_POWER_LEVEL_HPP_ */
Interface class for MeshX elements.
Definition meshx_fwd_decl.hpp:82
meshx_gen_power_level_model_state_t model_state
Definition meshx_model_power_level.hpp:93
meshx_power_level_cli_el_msg_t element_msg
Definition meshx_model_power_level.hpp:96
meshx_err_t model_send(meshx_gen_power_level_send_params_t *params) override
Send a packet to the MeshX stack based on the given parameters.
Definition meshx_model_power_level.cpp:168
meshx_err_t element_state_change_handle(void) override
Handle state change request from element.
Definition meshx_model_power_level.cpp:99
meshXGenericPowerLevelClientModel(meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
A template class for creating Generic Power Level Client models.
Definition meshx_model_power_level.cpp:253
meshx_err_t model_from_ble_cb(dev_struct_t *, control_task_msg_evt_t, meshx_ptr_t) override
Creates a meshXGenericPowerLevelClientModel instance based on a BLE device.
Definition meshx_model_power_level.cpp:135
meshx_err_t prepare_element_msg(meshx_ptr_t *msg_ptr, size_t *msg_size) override
Prepare message for element notification.
Definition meshx_model_power_level.cpp:72
meshx_err_t meshx_state_change_notify(const meshx_gen_cli_cb_param_t *param, uint8_t status)
Handle Generic Power Level state change notifications from the MeshX stack.
Definition meshx_model_power_level.cpp:38
meshx_err_t prepare_element_msg(meshx_ptr_t *msg_ptr, size_t *msg_size) override
Prepare message for element notification.
Definition meshx_model_power_level.cpp:359
meshx_gen_power_level_model_state_t model_state
Definition meshx_model_power_level.hpp:145
meshx_err_t model_send(meshx_gen_power_level_send_params_t *params) override
Send a packet to the MeshX stack based on the given parameters.
Definition meshx_model_power_level.cpp:276
meshx_err_t plat_model_delete(void) override
Deletes the Generic Power Level Server model and its associated resources.
Definition meshx_model_power_level.cpp:482
meshx_err_t plat_model_create(MESHX_MODEL *p_plat_model_ptr=nullptr) override
Creates and initializes a server model instance for Generic Power Level Server.
Definition meshx_model_power_level.cpp:447
meshx_power_level_srv_el_msg_t element_msg
Definition meshx_model_power_level.hpp:148
meshx_err_t element_state_change_handle(void) override
Handle state change request from element.
Definition meshx_model_power_level.cpp:390
meshx_err_t model_from_ble_cb(dev_struct_t *, control_task_msg_evt_t, meshx_ptr_t) override
Callback function for handling BLE mesh events for Generic Power Level Server Model.
Definition meshx_model_power_level.cpp:312
bool element_msg_prepared
Definition meshx_model_power_level.hpp:151
meshXGenericPowerLevelServerModel(meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
Constructor for Generic Power Level Server Model.
Definition meshx_model_power_level.cpp:424
bool element_msg_prepared
Definition meshx_model_power_level.hpp:190
meshx_err_t prepare_element_msg(meshx_ptr_t *msg_ptr, size_t *msg_size) override
Prepare message for element notification.
Definition meshx_model_power_level.cpp:610
meshx_err_t model_from_ble_cb(dev_struct_t *, control_task_msg_evt_t, meshx_ptr_t) override
Callback function for handling BLE mesh events for Generic Power Level Setup Server Model.
Definition meshx_model_power_level.cpp:563
meshXGenericPowerLevelSetupServerModel(meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
Constructor for Generic Power Level Setup Server Model.
Definition meshx_model_power_level.cpp:511
meshx_err_t model_send(meshx_gen_power_level_send_params_t *params) override
Send a packet to the MeshX stack based on the given parameters.
Definition meshx_model_power_level.cpp:530
meshx_power_level_srv_el_msg_t element_msg
Definition meshx_model_power_level.hpp:187
meshXElementIF * parent_element
Definition meshx_model_class.hpp:42
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 Generic Client and Server 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_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 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_gen_power_level_send_params meshx_gen_power_level_send_params_t
Definition meshx_model_power_level.hpp:64
struct meshx_power_level_cli_el_msg meshx_power_level_cli_el_msg_t
Definition meshx_model_power_level.hpp:78
struct meshx_gen_power_level_model_state meshx_gen_power_level_model_state_t
Definition meshx_model_power_level.hpp:49
#define MESHX_GEN_POWER_LEVEL_SERVER_MODEL_TEMPLATE_PROTO
Definition meshx_model_power_level.hpp:27
#define MESHX_GEN_POWER_LEVEL_CLIENT_MODEL_TEMPLATE_PROTO
Definition meshx_model_power_level.hpp:24
#define MESHX_GEN_POWER_LEVEL_SETUP_SERVER_MODEL_TEMPLATE_PROTO
Definition meshx_model_power_level.hpp:30
struct meshx_power_level_srv_el_msg meshx_power_level_srv_el_msg_t
Definition meshx_model_power_level.hpp:129
Structure to hold the Power Level model state.
Definition meshx_model_power_level.hpp:37
uint16_t present_power
Definition meshx_model_power_level.hpp:38
struct meshx_gen_power_level_model_state::@050173321264060024351136101134302133204105226056 range
uint8_t remain_time
Definition meshx_model_power_level.hpp:40
uint16_t range_max
Definition meshx_model_power_level.hpp:45
uint16_t range_min
Definition meshx_model_power_level.hpp:44
uint16_t power_default
Definition meshx_model_power_level.hpp:41
uint16_t target_power
Definition meshx_model_power_level.hpp:39
Structure to hold the parameters for sending a Generic Power Level message.
Definition meshx_model_power_level.hpp:55
uint8_t tid
Definition meshx_model_power_level.hpp:58
uint8_t transition_time
Definition meshx_model_power_level.hpp:59
uint8_t delay
Definition meshx_model_power_level.hpp:60
meshx_ctx_t * ctx
Definition meshx_model_power_level.hpp:57
meshx_gen_power_level_model_state_t state
Definition meshx_model_power_level.hpp:61
meshx_model_t * model
Definition meshx_model_power_level.hpp:56
Structure to hold the Power Level Server to parent element message. The structure is used by the on_m...
Definition meshx_model_power_level.hpp:73
meshx_cli_model_send_param_header_t header
Definition meshx_model_power_level.hpp:74
meshx_gen_power_level_model_state_t state
Definition meshx_model_power_level.hpp:75
Structure to hold the Power Level Server to parent element message. The structure is used by the on_m...
Definition meshx_model_power_level.hpp:124
meshx_gen_power_level_model_state_t state
Definition meshx_model_power_level.hpp:126
meshx_srv_model_send_param_header_t header
Definition meshx_model_power_level.hpp:125