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
meshXGenericPowerOnOffClientModel Class Reference

A template class for creating Generic Power OnOff Client models. More...

#include <meshx_model_power_onoff.hpp>

Inheritance diagram for meshXGenericPowerOnOffClientModel:
meshXClientModel< meshXBaseGenericClientModel, meshx_gen_power_onoff_send_params_t > meshXModel< meshXBaseGenericClientModel, meshx_gen_power_onoff_send_params_t > meshXModelIF

Public Member Functions

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.
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.
meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override
 Prepare message for element notification.
 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.
 ~meshXGenericPowerOnOffClientModel ()=default
Public Member Functions inherited from meshXClientModel< meshXBaseGenericClientModel, meshx_gen_power_onoff_send_params_t >
 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)
 Construct a new meshXClientModel.
Public Member Functions inherited from meshXModel< meshXBaseGenericClientModel, meshx_gen_power_onoff_send_params_t >
void set_plat_model (MESHX_MODEL *p_model) override
 Set the platform-specific model instance.
meshx_err_t model_handle_from_ble_cb (dev_struct_t *p_dev, evt_model_id_t evt_model_id, meshx_ptr_t params)
 Handle upstream BLE Mesh events.
void on_baked (void) override
 Called when the model's parent element is baked.
virtual ~meshXModel ()
 Destructor for meshXModel.
meshx_err_t send_to_parent_element (meshx_ptr_t msg_ptr, size_t msg_size)
 Send message to parent element.
uint16_t get_model_func_id (void) const
 Get the model function identifier.
void set_model_func_id (uint16_t func_id)
 Set the model function identifier.
uint16_t get_model_id (void) const override
 Get the model identifier.
bool is_initialized (void) const override
 Check if the model is successfully initialized.
void set_model_id (uint16_t id)
 Set the model identifier.
meshx_err_t get_init_status (void) const
 Get the model initialization status.
meshXBaseGenericClientModelget_base_model (void) const
 Get the base model instance.
 meshXModel (MESHX_MODEL *p_plat_model, uint32_t model_id, meshXElementIF *parent_element=nullptr, uint16_t model_func_id=0)
 Constructs a new meshXModel instance.
Public Member Functions inherited from meshXModelIF
 meshXModelIF ()
 meshXModelIF (MESHX_MODEL *p_plat_model)
virtual ~meshXModelIF ()=default
MESHX_MODEL * get_plat_model (void) const
 Get the platform-specific model instance.
meshx_ptr_t get_pub_struct (void) const
 Get the publication structures.
meshx_ptr_t get_gen_struct (void) const
 Get the generic structures.
void set_pub_struct (meshx_ptr_t pub)
 Set the publication structures.
void set_gen_struct (meshx_ptr_t gen)
 Set the generic structures.
void set_parent_element (meshXElementIF *parent)
 Set the parent element for this model.
meshXElementIFget_parent_element (void) const
 Get the parent element of this model.
void set_parent_element_state (meshx_ptr_t state)
 Set the parent element state pointer.
meshx_ptr_t get_parent_element_state (void) const
 Get the parent element state pointer.

Private Member Functions

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.
meshx_err_t element_state_change_handle (void) override
 Handle state change request from element.

Private Attributes

meshx_gen_power_onoff_model_state_t model_state
meshx_power_onoff_cli_el_msg_t element_msg

Additional Inherited Members

Protected Member Functions inherited from meshXClientModel< meshXBaseGenericClientModel, meshx_gen_power_onoff_send_params_t >
void update_element_state_change_header (meshx_err_t element_state_change, meshx_ptr_t msg_ptr) override
 Update element_state_change field in client message header.

Detailed Description

A template class for creating Generic Power OnOff Client models.

This class is derived from meshXClientModel and provides a convenient interface for creating Generic Power OnOff Client models. It handles the Generic Power OnOff state change notifications from the MeshX stack and publishes the state change event to the element layer.

Constructor & Destructor Documentation

◆ meshXGenericPowerOnOffClientModel()

meshXGenericPowerOnOffClientModel::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.

This class is derived from meshXClientModel and provides a convenient interface for creating Generic Power OnOff Client models. It handles the Generic Power OnOff state change notifications from the MeshX stack and publishes the state change event to the element layer.

Template Parameters
meshxBaseClientModel_tThe type of the meshXBaseClientModel class to be used.
meshx_send_packet_params_tThe type of the meshXSendPacketParams structure used for sending packets.
Parameters
[in]parent_elementA pointer to the parent element (meshXElementIF).
[in]parent_element_statePointer to the parent element's state structure.
[in]model_func_idFunctional ID for the model instance.
223{
224 /* Used only for initialization of Parent Class */
225}
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
#define MESHX_MODEL_ID_GEN_POWER_ONOFF_CLI
Definition meshx_ble_mesh_cmn_def.h:78

◆ ~meshXGenericPowerOnOffClientModel()

meshXGenericPowerOnOffClientModel::~meshXGenericPowerOnOffClientModel ( )
default

Member Function Documentation

◆ element_state_change_handle()

meshx_err_t meshXGenericPowerOnOffClientModel::element_state_change_handle ( void )
overrideprivatevirtual

Handle state change request from element.

This function is called by the parent element when a state change request is received. It validates the request and returns a result to the element. Note: The actual state is maintained in the element layer, not the model layer.

Returns
  • MESHX_SUCCESS: State change handled successfully
  • MESHX_INVALID_ARG: Invalid parameter

Implements meshXModelIF.

93{
96 if(!el_state)
97 {
98 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Invalid parameter in element_state_change_handle");
99 return MESHX_INVALID_ARG;
100 }
101 if(memcmp(&model_state, el_state, sizeof(meshx_gen_power_onoff_model_state_t)) != 0)
102 {
104 "Power OnOff state change request: on_power_up=%d",
105 el_state->on_power_up);
106 model_state = *el_state;
107 }
108 else
109 {
110 return MESHX_INVALID_STATE;
111 }
112 return MESHX_SUCCESS;
113}
meshx_gen_power_onoff_model_state_t model_state
Definition meshx_model_power_onoff.hpp:84
meshx_ptr_t get_parent_element_state(void) const
Get the parent element state pointer.
Definition meshx_model_class.hpp:154
@ MESHX_INVALID_ARG
Definition meshx_err.h:46
@ MESHX_INVALID_STATE
Definition meshx_err.h:49
#define MESHX_LOGI(module_id, format,...)
Definition meshx_log.h:126
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:114
**This function is called by the parent element when a state change request *is received It validates the request and returns a result to the element not the model layer **return * MESHX_SUCCESS
Definition meshx_model_level.cpp:385
struct meshx_gen_power_onoff_model_state meshx_gen_power_onoff_model_state_t
Definition meshx_model_power_onoff.hpp:42
@ MODULE_ID_MODEL_SERVER
Definition module_id.h:34
uint8_t on_power_up
Definition meshx_model_power_onoff.hpp:39

◆ meshx_state_change_notify()

meshx_err_t meshXGenericPowerOnOffClientModel::meshx_state_change_notify ( const meshx_gen_cli_cb_param_t * param,
uint8_t status )
private

Handle Generic Power OnOff state change notifications from the MeshX stack.

This function is responsible for handling Generic Power OnOff state change notifications from the MeshX stack. It is called when the MeshX stack receives a state change event from the Generic Power OnOff server model. The function publishes the state change event to the control task framework, which in turn notifies the application about the state change.

Parameters
[in]paramPointer to the Generic Power OnOff client callback parameter structure.
[in]statusStatus of the state change event (success or timeout).
Returns
  • MESHX_SUCCESS: Successfully handled the state change notification.
  • MESHX_INVALID_ARG: One or more arguments are invalid.
39{
40 if (!param){
41 return MESHX_INVALID_ARG;
42 }
43
44 model_state.on_power_up = param->status.onpowerup_status.onpowerup;
45
46 meshx_power_onoff_cli_el_msg_t power_onoff_param =
47 {
48 .header = {
49 .err_code = param->err_code,
50 .model = param->model,
51 .ctx = param->ctx,
52 .element_state_change = MESHX_SUCCESS,
53 },
54 .state = model_state,
55 };
56 /* Send the state change event to the respective Element */
57 if (this->get_parent_element())
58 {
59 if(this->get_parent_element_state())
60 {
62 }
63 else
64 {
65 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Parent element state is null");
67 }
68 return this->get_parent_element()->on_model_cb(&power_onoff_param, sizeof(power_onoff_param));
69 }
70 else
71 {
72 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Parent element is null");
73 }
74
76}
virtual meshx_err_t on_model_cb(meshx_ptr_t param, size_t param_size)=0
Handle model callback from child models.
meshx_err_t element_state_change_handle(void) override
Handle state change request from element.
Definition meshx_model_power_onoff.cpp:92
meshXElementIF * get_parent_element(void) const
Get the parent element of this model.
Definition meshx_model_class.hpp:143
@ MESHX_NOT_FOUND
Definition meshx_err.h:50
struct meshx_power_onoff_cli_el_msg meshx_power_onoff_cli_el_msg_t
Definition meshx_model_power_onoff.hpp:69
@ MODULE_ID_MODEL_CLIENT
Definition module_id.h:35
meshx_err_t element_state_change
Definition meshx_model_class.hpp:414
uint8_t err_code
Definition meshx_ble_mesh_gen_cli.h:285
meshx_gen_client_status_cb_t status
Definition meshx_ble_mesh_gen_cli.h:289
meshx_model_t model
Definition meshx_ble_mesh_gen_cli.h:287
meshx_ctx_t ctx
Definition meshx_ble_mesh_gen_cli.h:286
uint8_t onpowerup
Definition meshx_ble_mesh_gen_cli.h:153
meshx_cli_model_send_param_header_t header
Definition meshx_model_power_onoff.hpp:65
meshx_gen_onpowerup_status_cb_t onpowerup_status
Definition meshx_ble_mesh_gen_cli.h:256

◆ model_from_ble_cb()

meshx_err_t meshXGenericPowerOnOffClientModel::model_from_ble_cb ( dev_struct_t * p_dev,
control_task_msg_evt_t model_id,
meshx_ptr_t params )
overridevirtual

Creates a meshXGenericPowerOnOffClientModel instance based on a BLE device.

This function is used to create a meshXGenericPowerOnOffClientModel instance based on a BLE device. It takes the device structure, model ID, and parameters as input and returns a pointer to the created instance.

Parameters
[in]p_devPointer to the device structure
[in]model_idModel ID associated with the device
[in]paramsPointer to the parameters associated with the device
Returns
Pointer to the created meshXGenericPowerOnOffClientModel instance

Implements meshXModel< meshXBaseGenericClientModel, meshx_gen_power_onoff_send_params_t >.

133{
134 if(!params || !p_dev)
135 {
136 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Invalid parameters");
137 return MESHX_INVALID_ARG;
138 }
140 {
141 /* Callback triggered not for this model */
142 return MESHX_SUCCESS;
143 }
144 const auto *param = static_cast<const meshx_gen_cli_cb_param_t *>(params);
145
146 return static_cast<int>(param->evt) == static_cast<int>(meshx_base_cli_evt::MESHX_BASE_CLI_TIMEOUT) ?
149}
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_BASE_CLI_TIMEOUT
Definition meshx_base_model_class.hpp:233
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...
@ MESHX_TIMEOUT
Definition meshx_err.h:52

◆ model_send()

meshx_err_t meshXGenericPowerOnOffClientModel::model_send ( meshx_gen_power_onoff_send_params_t * params)
overridevirtual

Send a packet to the MeshX stack based on the given parameters.

This function takes a pointer to a meshx_gen_power_onoff_send_params_t structure as input and sends the corresponding packet to the MeshX stack for processing.

Parameters
[in]paramsPointer to the meshx_gen_power_onoff_send_params_t structure containing the parameters
Returns
MESHX_SUCCESS on success, or an error code on failure

Implements meshXModel< meshXBaseGenericClientModel, meshx_gen_power_onoff_send_params_t >.

163{
164 meshx_err_t err;
165 meshx_gen_cli_set_t set;
166 if (!params || !params->model || !params->model->p_model)
167 {
168 return MESHX_INVALID_ARG;
169 }
170
172
173 send_params.state = &set;
174 send_params.opcode = static_cast<uint16_t>(params->ctx->opcode);
175 send_params.net_idx = params->ctx->net_idx;
176 send_params.app_idx = params->ctx->app_idx;
177 send_params.addr = params->model->pub_addr;
178 send_params.model = params->model->p_model;
179
181 {
182 err = this->get_base_model()->plat_send_msg(&send_params);
183 }
184
185 else if (params->ctx->opcode == MESHX_MODEL_OP_GEN_ONPOWERUP_SET ||
187 {
188 set.power_set.onpowerup = params->on_power_up;
189 // Note: Power OnOff SET operations don't use TID
190
191 err = this->get_base_model()->plat_send_msg(&send_params);
192 }
193 else
194 {
195 err = MESHX_INVALID_ARG; // Invalid opcode
196 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Invalid opcode for Generic Power OnOff Client: %04x", params->ctx->opcode);
197 }
198 return err;
199}
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
meshXBaseGenericClientModel * get_base_model(void) const
Definition meshx_model_class.hpp:315
#define MESHX_MODEL_OP_GEN_ONPOWERUP_SET
Definition meshx_ble_mesh_cmn_def.h:267
#define MESHX_MODEL_OP_GEN_ONPOWERUP_GET
Definition meshx_ble_mesh_cmn_def.h:263
#define MESHX_MODEL_OP_GEN_ONPOWERUP_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:268
struct meshx_gen_client_send_params meshx_gen_client_send_params_t
Generic Client Model send parameters.
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
uint16_t app_idx
Definition meshx_ble_mesh_cmn.h:47
uint32_t opcode
Definition meshx_ble_mesh_cmn.h:49
uint16_t net_idx
Definition meshx_ble_mesh_cmn.h:48
uint16_t addr
Definition meshx_ble_mesh_gen_cli.h:299
uint16_t net_idx
Definition meshx_ble_mesh_gen_cli.h:300
meshx_gen_cli_set_t * state
Definition meshx_ble_mesh_gen_cli.h:302
meshx_ptr_t model
Definition meshx_ble_mesh_gen_cli.h:297
uint16_t opcode
Definition meshx_ble_mesh_gen_cli.h:298
uint16_t app_idx
Definition meshx_ble_mesh_gen_cli.h:301
uint8_t onpowerup
Definition meshx_ble_mesh_gen_cli.h:74
meshx_ctx_t * ctx
Definition meshx_model_power_onoff.hpp:50
meshx_model_t * model
Definition meshx_model_power_onoff.hpp:49
meshx_ptr_t p_model
Definition meshx_ble_mesh_cmn.h:39
uint16_t pub_addr
Definition meshx_ble_mesh_cmn.h:38
meshx_gen_onpowerup_set_t power_set
Definition meshx_ble_mesh_gen_cli.h:122

◆ prepare_element_msg()

meshx_err_t meshXGenericPowerOnOffClientModel::prepare_element_msg ( meshx_ptr_t * msg_ptr,
size_t * msg_size )
overridevirtual

Prepare message for element notification.

Pure virtual function that derived classes must implement to prepare a message structure that will be sent to the parent element. The message must persist after this function returns.

Parameters
[out]msg_ptrPointer to message structure (output parameter)
[out]msg_sizeSize of the message structure (output parameter)
Returns
MESHX_SUCCESS if message prepared successfully, error code otherwise

Implements meshXModelIF.

Field Documentation

◆ element_msg

meshx_power_onoff_cli_el_msg_t meshXGenericPowerOnOffClientModel::element_msg
private

◆ model_state

meshx_gen_power_onoff_model_state_t meshXGenericPowerOnOffClientModel::model_state
private

The documentation for this class was generated from the following files: