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

A template class for creating Generic Battery Client models. More...

#include <meshx_model_battery.hpp>

Inheritance diagram for meshXGenericBatteryClientModel:
meshXClientModel< meshXBaseGenericClientModel, meshx_gen_battery_send_params_t > meshXModel< meshXBaseGenericClientModel, meshx_gen_battery_send_params_t > meshXModelIF

Public Member Functions

meshx_err_t model_send (meshx_gen_battery_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 meshXGenericBatteryClientModel 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.
 meshXGenericBatteryClientModel (meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
 A template class for creating Generic Battery Client models.
 ~meshXGenericBatteryClientModel ()=default
Public Member Functions inherited from meshXClientModel< meshXBaseGenericClientModel, meshx_gen_battery_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_battery_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 Battery 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_battery_model_state_t model_state
meshx_battery_cli_el_msg_t element_msg

Additional Inherited Members

Protected Member Functions inherited from meshXClientModel< meshXBaseGenericClientModel, meshx_gen_battery_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 Battery Client models.

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

Constructor & Destructor Documentation

◆ meshXGenericBatteryClientModel()

meshXGenericBatteryClientModel::meshXGenericBatteryClientModel ( meshXElementIF * parent_element = nullptr,
meshx_ptr_t parent_element_state = nullptr,
uint16_t model_func_id = 0 )

A template class for creating Generic Battery Client models.

This class is derived from meshXClientModel and provides a convenient interface for creating Generic Battery Client models. It handles the Generic Battery 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.
226{
227 /* Used only for initialization of Parent Class */
228}
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_BATTERY_CLI
Definition meshx_ble_mesh_cmn_def.h:83

◆ ~meshXGenericBatteryClientModel()

meshXGenericBatteryClientModel::~meshXGenericBatteryClientModel ( )
default

Member Function Documentation

◆ element_state_change_handle()

meshx_err_t meshXGenericBatteryClientModel::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.

103{
106 if(!el_state)
107 {
108 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Invalid parameter in element_state_change_handle");
109 return MESHX_INVALID_ARG;
110 }
111 if(memcmp(&model_state, el_state, sizeof(meshx_gen_battery_model_state_t)) != 0)
112 {
114 "Battery state change request: level=%d discharge=%d charge=%d",
115 el_state->battery_level, el_state->time_to_discharge, el_state->time_to_charge);
116 model_state = *el_state;
117 }
118 else
119 {
120 return MESHX_INVALID_STATE;
121 }
122 return MESHX_SUCCESS;
123}
meshx_gen_battery_model_state_t model_state
Definition meshx_model_battery.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
struct meshx_gen_battery_model_state meshx_gen_battery_model_state_t
Definition meshx_model_battery.hpp:43
**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
@ MODULE_ID_MODEL_SERVER
Definition module_id.h:34
uint32_t time_to_discharge
Definition meshx_model_battery.hpp:36
uint32_t time_to_charge
Definition meshx_model_battery.hpp:37
uint8_t battery_level
Definition meshx_model_battery.hpp:35

◆ meshx_state_change_notify()

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

Handle Generic Battery state change notifications from the MeshX stack.

This function is responsible for handling Generic Battery state change notifications from the MeshX stack. It is called when the MeshX stack receives a state change event from the Generic Battery 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 Battery 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.battery_level = param->status.battery_status.battery_level;
45 model_state.time_to_discharge = param->status.battery_status.time_to_discharge;
46 model_state.time_to_charge = param->status.battery_status.time_to_charge;
47 model_state.presence = param->status.battery_status.presence;
48 model_state.charge_level = param->status.battery_status.charge_level;
49 model_state.charge_type = param->status.battery_status.charge_type;
50
51 // Store the message in member variable for later use by prepare_element_msg
52 element_msg = {
53 .header = {
54 .err_code = param->err_code,
55 .model = param->model,
56 .ctx = param->ctx,
57 .element_state_change = MESHX_SUCCESS,
58 },
59 .state = model_state,
60 };
61
62 return MESHX_SUCCESS;
63}
meshx_battery_cli_el_msg_t element_msg
Definition meshx_model_battery.hpp:87
uint32_t time_to_discharge
Definition meshx_ble_mesh_gen_cli.h:184
uint32_t time_to_charge
Definition meshx_ble_mesh_gen_cli.h:185
uint32_t battery_level
Definition meshx_ble_mesh_gen_cli.h:183
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
meshx_gen_battery_status_cb_t battery_status
Definition meshx_ble_mesh_gen_cli.h:261

◆ model_from_ble_cb()

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

Creates a meshXGenericBatteryClientModel instance based on a BLE device.

This function is used to create a meshXGenericBatteryClientModel 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 meshXGenericBatteryClientModel instance

Implements meshXModel< meshXBaseGenericClientModel, meshx_gen_battery_send_params_t >.

144{
145 if(!params || !p_dev)
146 {
147 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Invalid parameters");
148 return MESHX_INVALID_ARG;
149 }
151 {
152 /* Callback triggered not for this model */
153 return MESHX_SUCCESS;
154 }
155 const auto *param = static_cast<const meshx_gen_cli_cb_param_t *>(params);
156
157 return static_cast<int>(param->evt) == static_cast<int>(meshx_base_cli_evt::MESHX_BASE_CLI_TIMEOUT) ?
160}
meshx_err_t meshx_state_change_notify(const meshx_gen_cli_cb_param_t *param, uint8_t status)
Handle Generic Battery state change notifications from the MeshX stack.
Definition meshx_model_battery.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
@ MODULE_ID_MODEL_CLIENT
Definition module_id.h:35

◆ model_send()

meshx_err_t meshXGenericBatteryClientModel::model_send ( meshx_gen_battery_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_battery_send_params_t structure as input and sends the corresponding packet to the MeshX stack for processing.

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

Implements meshXModel< meshXBaseGenericClientModel, meshx_gen_battery_send_params_t >.

174{
175 meshx_err_t err;
176 meshx_gen_cli_set_t set;
177 if (!params || !params->model || !params->model->p_model)
178 {
179 return MESHX_INVALID_ARG;
180 }
181
183
184 send_params.state = &set;
185 send_params.opcode = static_cast<uint16_t>(params->ctx->opcode);
186 send_params.net_idx = params->ctx->net_idx;
187 send_params.app_idx = params->ctx->app_idx;
188 send_params.addr = params->model->pub_addr;
189 send_params.model = params->model->p_model;
190
192 {
193 err = this->get_base_model()->plat_send_msg(&send_params);
194 }
195 else
196 {
197 err = MESHX_INVALID_ARG; // Invalid opcode
198 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Invalid opcode for Generic Battery Client: %04x", params->ctx->opcode);
199 }
200 return err;
201}
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_BATTERY_GET
Definition meshx_ble_mesh_cmn_def.h:289
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
meshx_ctx_t * ctx
Definition meshx_model_battery.hpp:51
meshx_model_t * model
Definition meshx_model_battery.hpp:50
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
meshx_ptr_t p_model
Definition meshx_ble_mesh_cmn.h:39
uint16_t pub_addr
Definition meshx_ble_mesh_cmn.h:38

◆ prepare_element_msg()

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

Prepare message for element notification.

Returns pointer to the stored element message

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.

76{
77 if (!msg_ptr || !msg_size)
78 {
79 return MESHX_INVALID_ARG;
80 }
81
82 *msg_ptr = &element_msg;
83 *msg_size = sizeof(element_msg);
84
85 return MESHX_SUCCESS;
86}

Field Documentation

◆ element_msg

meshx_battery_cli_el_msg_t meshXGenericBatteryClientModel::element_msg
private

◆ model_state

meshx_gen_battery_model_state_t meshXGenericBatteryClientModel::model_state
private

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