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_onoff.hpp
Go to the documentation of this file.
1/**
2 * @file meshx_model_power_onoff.hpp
3 * @brief Implementation of Generic Power OnOff Model for MeshX
4 *
5 * This file contains the implementation of the Generic Power OnOff model,
6 * which provides standard Power OnOff model functionality in the MeshX BLE mesh framework.
7 *
8 * Key Features:
9 * - Implements Bluetooth SIG-defined Generic Power OnOff model
10 * - Inherits from meshXClientModel, meshXServerModel templates
11 * - Provides standard Power OnOff control operations
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_POWER_ONOFF_HPP_
20#define _MESHX_MODEL_POWER_ONOFF_HPP_
21
22#include <meshx_model_class.hpp>
24
25#define MESHX_GEN_POWER_ONOFF_CLIENT_MODEL_TEMPLATE_PROTO
26#define MESHX_GEN_POWER_ONOFF_CLIENT_MODEL_TEMPLATE_PARAMS
27
28#define MESHX_GEN_POWER_ONOFF_SERVER_MODEL_TEMPLATE_PROTO
29#define MESHX_GEN_POWER_ONOFF_SERVER_MODEL_TEMPLATE_PARAMS
30
31#define MESHX_GEN_POWER_ONOFF_SETUP_SERVER_MODEL_TEMPLATE_PROTO
32#define MESHX_GEN_POWER_ONOFF_SETUP_SERVER_MODEL_TEMPLATE_PARAMS
33
34/**
35 * @brief Structure to hold the Power OnOff model state.
36 */
38{
39 uint8_t on_power_up; /**< The OnPowerUp state value. */
40};
41
43
44/**
45 * @brief Structure to hold the parameters for sending a Generic Power OnOff message.
46 */
48{
49 meshx_model_t *model; /**< Pointer to the Power OnOff client model. */
50 meshx_ctx_t *ctx; /**< The context of the message. */
51 uint8_t tid; /**< The transaction ID of the message. Only used by Client*/
52 meshx_gen_power_onoff_model_state_t state; /**< The state of the message. */
53};
54
56
57#if CONFIG_ENABLE_GEN_POWER_ONOFF_CLIENT
58/**
59 * @brief Structure to hold the Power OnOff Server to parent element message.
60 * The structure is used by the on_model_cb function to send the Power OnOff state
61 * change notification to the parent element.
62 */
64{
65 meshx_cli_model_send_param_header_t header; /**< Client model send param header */
66 meshx_gen_power_onoff_model_state_t state; /**< The state of the message. */
67};
68
70/**
71 * @class meshXGenericPowerOnOffClientModel
72 * @brief A template class for creating Generic Power OnOff Client models.
73 *
74 * This class is derived from meshXClientModel and provides a convenient interface for
75 * creating Generic Power OnOff Client models. It handles the Generic Power OnOff state change
76 * notifications from the MeshX stack and publishes the state change event to the
77 * element layer.
78 */
80class meshXGenericPowerOnOffClientModel : public meshXClientModel<meshXBaseGenericClientModel, meshx_gen_power_onoff_send_params_t>
81{
82private:
83 /* New or updated model state from BLE layer */
85
86 /* Message to be sent to parent element */
88
91
92public:
95 meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override;
96
99 meshx_ptr_t parent_element_state = nullptr,
100 uint16_t model_func_id = 0
101 );
103};
104
105#endif /* CONFIG_ENABLE_GEN_POWER_ONOFF_CLIENT */
106
107#if CONFIG_ENABLE_GEN_POWER_ONOFF_SERVER
108
109/**
110 * @brief Structure to hold the Power OnOff Server to parent element message.
111 * The structure is used by the on_model_cb function to send the Power OnOff state
112 * change notification to the parent element.
113 */
115{
116 meshx_srv_model_send_param_header_t header; /**< Server model send param header */
117 meshx_gen_power_onoff_model_state_t state; /**< The state of the message. */
118};
119
121
122/**
123 * @class meshXGenericPowerOnOffServerModel
124 * @brief A template class for creating Generic Power OnOff Server models.
125 *
126 * This class is derived from meshXServerModel and provides a convenient interface for
127 * creating Generic Power OnOff Server models. It handles the Generic Power OnOff state change
128 * notifications from the MeshX stack and publishes the state change event to the
129 * element layer.
130 */
132class meshXGenericPowerOnOffServerModel : public meshXServerModel<meshXBaseGenericServerModel, meshx_gen_power_onoff_send_params_t>
133{
134private:
135 /* New or updated model state from BLE layer */
137
138 /* Message to be sent to parent element */
140
141 /* Flag to indicate if element message has been prepared */
143
144 meshx_err_t plat_model_create (MESHX_MODEL* p_plat_model_ptr = nullptr) override;
145 meshx_err_t plat_model_delete (void) override;
146
147public:
150 meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override;
151
152 // Virtual method implementation from meshXModelIF
154
157 meshx_ptr_t parent_element_state = nullptr,
158 uint16_t model_func_id = 0
159 );
161};
162#endif /* CONFIG_ENABLE_GEN_POWER_ONOFF_SERVER */
163
164#if CONFIG_ENABLE_GEN_POWER_ONOFF_SETUP_SERVER
165/**
166 * @class meshXGenericPowerOnOffSetupServerModel
167 * @brief A template class for creating Generic Power OnOff Setup Server models.
168 *
169 * This class is derived from meshXServerModel and provides a convenient interface for
170 * creating Generic Power OnOff Setup Server models. It handles the Generic Power OnOff setup
171 * operations from the MeshX stack.
172 */
174class meshXGenericPowerOnOffSetupServerModel : public meshXServerModel<meshXBaseGenericServerModel, meshx_gen_power_onoff_send_params_t>
175{
176private:
177 /* Message to be sent to parent element */
179
180 /* Flag to indicate if element message has been prepared */
182
183 meshx_err_t plat_model_create (MESHX_MODEL* p_plat_model_ptr = nullptr) override;
184 meshx_err_t plat_model_delete (void) override;
185
186public:
189 meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override;
190
193 meshx_ptr_t parent_element_state = nullptr,
194 uint16_t model_func_id = 0
195 );
197};
198#endif /* CONFIG_ENABLE_GEN_POWER_ONOFF_SETUP_SERVER */
199
200#endif /* CONFIG_ENABLE_GEN_POWER_ONOFF */
Interface class for MeshX elements.
Definition meshx_fwd_decl.hpp:82
meshx_err_t meshx_state_change_notify(const meshx_gen_cli_cb_param_t *param, uint8_t status)
Handle Generic Power OnOff state change notifications from the MeshX stack.
Definition meshx_model_power_onoff.cpp:38
meshx_err_t model_from_ble_cb(dev_struct_t *, control_task_msg_evt_t, meshx_ptr_t) override
Creates a meshXGenericPowerOnOffClientModel instance based on a BLE device.
Definition meshx_model_power_onoff.cpp:128
meshx_power_onoff_cli_el_msg_t element_msg
Definition meshx_model_power_onoff.hpp:87
meshXGenericPowerOnOffClientModel(meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
A template class for creating Generic Power OnOff Client models.
Definition meshx_model_power_onoff.cpp:218
meshx_gen_power_onoff_model_state_t model_state
Definition meshx_model_power_onoff.hpp:84
meshx_err_t prepare_element_msg(meshx_ptr_t *msg_ptr, size_t *msg_size) override
Prepare message for element notification.
meshx_err_t element_state_change_handle(void) override
Handle state change request from element.
Definition meshx_model_power_onoff.cpp:92
meshx_err_t model_send(meshx_gen_power_onoff_send_params_t *params) override
Send a packet to the MeshX stack based on the given parameters.
Definition meshx_model_power_onoff.cpp:162
meshx_gen_power_onoff_model_state_t model_state
Definition meshx_model_power_onoff.hpp:136
meshx_err_t plat_model_delete(void) override
Deletes the Generic Power OnOff Server model and its associated resources.
Definition meshx_model_power_onoff.cpp:442
meshx_err_t model_send(meshx_gen_power_onoff_send_params_t *params) override
Send a packet to the MeshX stack based on the given parameters.
Definition meshx_model_power_onoff.cpp:241
bool element_msg_prepared
Definition meshx_model_power_onoff.hpp:142
meshx_power_onoff_srv_el_msg_t element_msg
Definition meshx_model_power_onoff.hpp:139
meshx_err_t plat_model_create(MESHX_MODEL *p_plat_model_ptr=nullptr) override
Creates and initializes a server model instance for Generic Power OnOff Server.
Definition meshx_model_power_onoff.cpp:406
meshx_err_t element_state_change_handle(void) override
Handle state change request from element.
Definition meshx_model_power_onoff.cpp:347
meshXGenericPowerOnOffServerModel(meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
Constructor for Generic Power OnOff Server Model.
Definition meshx_model_power_onoff.cpp:381
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 OnOff Server Model.
Definition meshx_model_power_onoff.cpp:272
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_onoff.cpp:315
meshx_err_t model_send(meshx_gen_power_onoff_send_params_t *params) override
Send a packet to the MeshX stack based on the given parameters.
Definition meshx_model_power_onoff.cpp:473
bool element_msg_prepared
Definition meshx_model_power_onoff.hpp:181
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_onoff.cpp:564
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 OnOff Setup Server Model.
Definition meshx_model_power_onoff.cpp:521
meshx_err_t plat_model_create(MESHX_MODEL *p_plat_model_ptr=nullptr) override
Creates and initializes a server model instance for Generic Power OnOff Setup Server.
Definition meshx_model_power_onoff.cpp:599
meshx_err_t plat_model_delete(void) override
Deletes the Generic Power OnOff Setup Server model and its associated resources.
Definition meshx_model_power_onoff.cpp:635
meshXGenericPowerOnOffSetupServerModel(meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
Constructor for Generic Power OnOff Setup Server Model.
Definition meshx_model_power_onoff.cpp:503
meshx_power_onoff_srv_el_msg_t element_msg
Definition meshx_model_power_onoff.hpp:178
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_power_onoff_srv_el_msg meshx_power_onoff_srv_el_msg_t
Definition meshx_model_power_onoff.hpp:120
struct meshx_power_onoff_cli_el_msg meshx_power_onoff_cli_el_msg_t
Definition meshx_model_power_onoff.hpp:69
#define MESHX_GEN_POWER_ONOFF_CLIENT_MODEL_TEMPLATE_PROTO
Definition meshx_model_power_onoff.hpp:25
struct meshx_gen_power_onoff_send_params meshx_gen_power_onoff_send_params_t
Definition meshx_model_power_onoff.hpp:55
#define MESHX_GEN_POWER_ONOFF_SERVER_MODEL_TEMPLATE_PROTO
Definition meshx_model_power_onoff.hpp:28
#define MESHX_GEN_POWER_ONOFF_SETUP_SERVER_MODEL_TEMPLATE_PROTO
Definition meshx_model_power_onoff.hpp:31
struct meshx_gen_power_onoff_model_state meshx_gen_power_onoff_model_state_t
Definition meshx_model_power_onoff.hpp:42
Structure to hold the Power OnOff model state.
Definition meshx_model_power_onoff.hpp:38
uint8_t on_power_up
Definition meshx_model_power_onoff.hpp:39
Structure to hold the parameters for sending a Generic Power OnOff message.
Definition meshx_model_power_onoff.hpp:48
meshx_ctx_t * ctx
Definition meshx_model_power_onoff.hpp:50
meshx_model_t * model
Definition meshx_model_power_onoff.hpp:49
uint8_t tid
Definition meshx_model_power_onoff.hpp:51
meshx_gen_power_onoff_model_state_t state
Definition meshx_model_power_onoff.hpp:52
Structure to hold the Power OnOff Server to parent element message. The structure is used by the on_m...
Definition meshx_model_power_onoff.hpp:64
meshx_cli_model_send_param_header_t header
Definition meshx_model_power_onoff.hpp:65
meshx_gen_power_onoff_model_state_t state
Definition meshx_model_power_onoff.hpp:66
Structure to hold the Power OnOff Server to parent element message. The structure is used by the on_m...
Definition meshx_model_power_onoff.hpp:115
meshx_gen_power_onoff_model_state_t state
Definition meshx_model_power_onoff.hpp:117
meshx_srv_model_send_param_header_t header
Definition meshx_model_power_onoff.hpp:116