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_onoff.hpp
Go to the documentation of this file.
1/**
2 * @file meshx_model_onoff.hpp
3 * @brief Implementation of Generic OnOff Client Model for MeshX
4 *
5 * This file contains the implementation of the Generic OnOff client model,
6 * which provides standard OnOff model functionality in the MeshX BLE mesh framework.
7 *
8 * Key Features:
9 * - Implements Bluetooth SIG-defined Generic OnOff model
10 * - Inherits from meshXClientModel template
11 * - Provides standard 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_ONOFF_HPP_
20#define _MESHX_MODEL_ONOFF_HPP_
21
22#include <meshx_model_class.hpp>
24
25#define MESHX_GEN_ONOFF_CLIENT_MODEL_TEMPLATE_PROTO
26#define MESHX_GEN_ONOFF_CLIENT_MODEL_TEMPLATE_PARAMS
27
28#define MESHX_GEN_ONOFF_SERVER_MODEL_TEMPLATE_PROTO
29#define MESHX_GEN_ONOFF_SERVER_MODEL_TEMPLATE_PARAMS
30
32{
33 uint8_t on_off; /**< The onoff state of the message. */
34 uint8_t next_on_off; /**< The next suggested onoff state (e.g. for toggle). */
35 uint8_t tid; /**< The transaction ID of the message. */
36};
37
39
40/**
41 * @brief Structure to hold the parameters for sending a Generic OnOff message.
42 */
44{
45 meshx_model_t *model; /**< Pointer to the On/Off client model. */
46 meshx_ctx_t *ctx; /**< The context of the message. */
47 meshx_gen_onoff_model_state_t state; /**< The state of the message. */
48 uint8_t tid; /**< The transaction ID of the message. Only sed by Client*/
49};
50
52
53#if CONFIG_ENABLE_GEN_ONOFF_CLIENT
54/**
55 * @brief Structure to hold the On/Off Server to parent element message.
56 * The structure is used by the on_model_cb function to send the On/Off state
57 * change notification to the parent element.
58 */
60{
61 meshx_cli_model_send_param_header_t header; /**< Client model send param header */
62 meshx_gen_onoff_model_state_t state; /**< The present value of Generic OnOff state */
63};
64
66/**
67 * @class meshXGenericOnOffClientModel
68 * @brief A template class for creating Generic OnOff Client models.
69 *
70 * This class is derived from meshXClientModel and provides a convenient interface for
71 * creating Generic OnOff Client models. It handles the Generic OnOff state change
72 * notifications from the MeshX stack and publishes the state change event to the
73 * element layer.
74 */
76class meshXGenericOnOffClientModel : public meshXClientModel<meshXBaseGenericClientModel, meshx_gen_onoff_send_params_t>
77{
78private:
79 /* New or updated model state from BLE layer */
81
82 /* Message to send to parent element - stored as member to persist */
84
87public:
90 meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override;
92
95 meshx_ptr_t parent_element_state = nullptr,
96 uint16_t model_func_id = 0
97 );
98 ~meshXGenericOnOffClientModel() override = default;
99};
100
101#endif /* CONFIG_ENABLE_GEN_ONOFF_CLIENT */
102
103/********************************************************************************************************************************** */
104#if CONFIG_ENABLE_GEN_ONOFF_SERVER
105/**
106 * @brief Structure to hold the On/Off Server to element message.
107 */
109{
110 meshx_srv_model_send_param_header_t header; /**< Server model send param header */
111 meshx_gen_onoff_model_state_t state; /**< The present value of Generic OnOff state */
112};
113
115/**
116 * @class meshXGenericOnOffServerModel
117 * @brief A template class for creating Generic OnOff Server models.
118 *
119 * This class is derived from meshXServerModel and provides a convenient interface for
120 * creating Generic OnOff Server models. It handles the Generic OnOff state change
121 * notifications from the MeshX stack and publishes the state change event to the
122 * element layer.
123 */
125class meshXGenericOnOffServerModel : public meshXServerModel<meshXBaseGenericServerModel, meshx_gen_onoff_send_params_t>
126{
127private:
128 /* New or updated model state from BLE layer */
130
131 /* Message to send to parent element - stored as member to persist */
133
134 /* Flag to indicate if message was prepared for element notification */
136
137 meshx_err_t plat_model_create (MESHX_MODEL* p_plat_model_ptr = nullptr) override;
138 meshx_err_t plat_model_delete (void) override;
139
140public:
143 meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override;
144 meshx_err_t request_status (uint16_t dst_addr = 0);
145
146 // Virtual method implementation from meshXModelIF
148
151 meshx_ptr_t parent_element_state = nullptr,
152 uint16_t model_func_id = 0
153 );
154
155 ~meshXGenericOnOffServerModel() override = default;
156};
157#endif /* CONFIG_ENABLE_GEN_ONOFF_SERVER */
158
159#endif /* _MESHX_MODEL_ONOFF_HPP_ */
struct meshx_gen_on_off_cli_msg meshx_gen_on_off_cli_msg_t
Standard Relay Client Message structure (shared between C element and C++ model).
Interface class for MeshX elements.
Definition meshx_fwd_decl.hpp:82
meshXGenericOnOffClientModel(meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
A template class for creating Generic OnOff Client models.
Definition meshx_model_onoff.cpp:314
meshx_err_t request_onoff(const meshx_gen_on_off_cli_msg_t *msg)
Request to change or get the Generic OnOff state.
Definition meshx_model_onoff.cpp:148
meshx_err_t model_send(meshx_gen_onoff_send_params_t *params) override
Send a packet to the MeshX stack based on the given parameters.
Definition meshx_model_onoff.cpp:236
meshx_on_off_cli_el_msg_t element_msg
Definition meshx_model_onoff.hpp:83
meshx_err_t element_state_change_handle(void) override
Handle state change request from element.
Definition meshx_model_onoff.cpp:75
meshx_gen_onoff_model_state_t model_state
Definition meshx_model_onoff.hpp:80
meshx_err_t meshx_state_change_notify(const meshx_gen_cli_cb_param_t *param, uint8_t status)
Handle Generic OnOff state change notifications from the MeshX stack.
Definition meshx_model_onoff.cpp:38
~meshXGenericOnOffClientModel() override=default
meshx_err_t model_from_ble_cb(dev_struct_t *, control_task_msg_evt_t, meshx_ptr_t) override
Creates a meshXGenericOnOffClientModel instance based on a BLE device.
Definition meshx_model_onoff.cpp:111
meshx_err_t prepare_element_msg(meshx_ptr_t *msg_ptr, size_t *msg_size) override
Prepare message for element notification.
Definition meshx_model_onoff.cpp:212
meshx_err_t model_send(meshx_gen_onoff_send_params_t *params) override
Send a packet to the MeshX stack based on the given parameters.
Definition meshx_model_onoff.cpp:493
meshx_err_t plat_model_create(MESHX_MODEL *p_plat_model_ptr=nullptr) override
Creates and initializes a server model instance.
Definition meshx_model_onoff.cpp:372
meshx_err_t element_state_change_handle(void) override
Handle state change request from element.
Definition meshx_model_onoff.cpp:461
~meshXGenericOnOffServerModel() override=default
meshx_err_t prepare_element_msg(meshx_ptr_t *msg_ptr, size_t *msg_size) override
Prepare the element message for notification.
Definition meshx_model_onoff.cpp:642
meshx_on_off_srv_el_msg_t element_msg
Definition meshx_model_onoff.hpp:132
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 Generic OnOff Server model.
Definition meshx_model_onoff.cpp:532
meshx_err_t plat_model_delete(void) override
Deletes the Generic OnOff Server model and its associated resources.
Definition meshx_model_onoff.cpp:427
meshx_gen_onoff_model_state_t model_state
Definition meshx_model_onoff.hpp:129
bool element_msg_prepared
Definition meshx_model_onoff.hpp:135
meshx_err_t request_status(uint16_t dst_addr=0)
Request to send the Generic OnOff status to a specific address.
Definition meshx_model_onoff.cpp:675
meshXGenericOnOffServerModel(meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
A template class for creating Generic OnOff Server models.
Definition meshx_model_onoff.cpp:346
meshXElementIF * parent_element
Definition meshx_model_class.hpp:42
meshx_err_t status
Definition meshx_model_class.hpp:179
uint16_t model_func_id
Definition meshx_model_class.hpp:181
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_onoff_send_params meshx_gen_onoff_send_params_t
Definition meshx_model_onoff.hpp:51
struct meshx_on_off_srv_el_msg meshx_on_off_srv_el_msg_t
Definition meshx_model_onoff.hpp:114
#define MESHX_GEN_ONOFF_SERVER_MODEL_TEMPLATE_PROTO
Definition meshx_model_onoff.hpp:28
struct meshx_gen_onoff_model_state meshx_gen_onoff_model_state_t
Definition meshx_model_onoff.hpp:38
#define MESHX_GEN_ONOFF_CLIENT_MODEL_TEMPLATE_PROTO
Definition meshx_model_onoff.hpp:25
struct meshx_on_off_cli_el_msg meshx_on_off_cli_el_msg_t
Definition meshx_model_onoff.hpp:65
Definition meshx_model_onoff.hpp:32
uint8_t next_on_off
Definition meshx_model_onoff.hpp:34
uint8_t on_off
Definition meshx_model_onoff.hpp:33
uint8_t tid
Definition meshx_model_onoff.hpp:35
Structure to hold the parameters for sending a Generic OnOff message.
Definition meshx_model_onoff.hpp:44
meshx_ctx_t * ctx
Definition meshx_model_onoff.hpp:46
meshx_gen_onoff_model_state_t state
Definition meshx_model_onoff.hpp:47
meshx_model_t * model
Definition meshx_model_onoff.hpp:45
uint8_t tid
Definition meshx_model_onoff.hpp:48
Structure to hold the On/Off Server to parent element message. The structure is used by the on_model_...
Definition meshx_model_onoff.hpp:60
meshx_cli_model_send_param_header_t header
Definition meshx_model_onoff.hpp:61
meshx_gen_onoff_model_state_t state
Definition meshx_model_onoff.hpp:62
Structure to hold the On/Off Server to element message.
Definition meshx_model_onoff.hpp:109
meshx_srv_model_send_param_header_t header
Definition meshx_model_onoff.hpp:110
meshx_gen_onoff_model_state_t state
Definition meshx_model_onoff.hpp:111