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

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

#include <meshx_model_property.hpp>

Inheritance diagram for meshXGenericPropertyClientModel:
meshXClientModel< meshXBaseGenericClientModel, meshx_gen_property_send_params_t > meshXModel< meshXBaseGenericClientModel, meshx_gen_property_send_params_t > meshXModelIF

Public Member Functions

meshx_err_t model_send (meshx_gen_property_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 meshXGenericPropertyClientModel 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.
 meshXGenericPropertyClientModel (meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
 A template class for creating Generic Property Client models.
 ~meshXGenericPropertyClientModel ()=default
Public Member Functions inherited from meshXClientModel< meshXBaseGenericClientModel, meshx_gen_property_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_property_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 Property 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_property_model_state_t model_state
meshx_property_cli_el_msg_t element_msg

Additional Inherited Members

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

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

Constructor & Destructor Documentation

◆ meshXGenericPropertyClientModel()

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

A template class for creating Generic Property Client models.

This class is derived from meshXClientModel and provides a convenient interface for creating Generic Property Client models. It handles the Generic Property 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.
288{
289 /* Used only for initialization of Parent Class */
290}
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_PROP_CLI
Definition meshx_ble_mesh_cmn_def.h:91

◆ ~meshXGenericPropertyClientModel()

meshXGenericPropertyClientModel::~meshXGenericPropertyClientModel ( )
default

Member Function Documentation

◆ element_state_change_handle()

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

141{
144 if(!el_state)
145 {
146 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Invalid parameter in element_state_change_handle");
147 return MESHX_INVALID_ARG;
148 }
149 if(el_state->property_id != model_state.property_id)
150 {
151 el_state->property_id = model_state.property_id;
152 }
153 if(el_state->access != model_state.access)
154 {
155 el_state->access = model_state.access;
156 }
157 // Note: property_value is a pointer and should be handled carefully
158 // The actual value management is typically done at the element level
159 return MESHX_SUCCESS;
160}
meshx_gen_property_model_state_t model_state
Definition meshx_model_property.hpp:91
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
#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_property_model_state meshx_gen_property_model_state_t
Definition meshx_model_property.hpp:50
@ MODULE_ID_MODEL_SERVER
Definition module_id.h:34
uint16_t property_id
Definition meshx_model_property.hpp:45
uint8_t access
Definition meshx_model_property.hpp:47

◆ meshx_state_change_notify()

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

Handle Generic Property state change notifications from the MeshX stack.

This function is responsible for handling Generic Property state change notifications from the MeshX stack. It is called when the MeshX stack receives a state change event from the Generic Property 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 Property 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.
40{
41 if (!param){
42 return MESHX_INVALID_ARG;
43 }
44
45 // Handle different property status types based on opcode
46 switch(param->ctx.opcode) {
48 model_state.property_id = 0;
49 model_state.property_value = nullptr;
50 model_state.access = 0;
51 break;
54 model_state.property_value = nullptr;
56 break;
58 model_state.property_id = 0;
59 model_state.property_value = nullptr;
60 model_state.access = 0;
61 break;
64 model_state.property_value = nullptr;
66 break;
68 model_state.property_id = 0;
69 model_state.property_value = nullptr;
70 model_state.access = 0;
71 break;
74 model_state.property_value = nullptr;
76 break;
78 model_state.property_id = 0;
79 model_state.property_value = nullptr;
80 model_state.access = 0;
81 break;
82 default:
83 model_state.property_id = 0;
84 model_state.property_value = nullptr;
85 model_state.access = 0;
86 break;
87 }
88
89 // Store the message in member variable for later use by prepare_element_msg
90 element_msg = {
91 .header = {
92 .err_code = param->err_code,
93 .model = param->model,
94 .ctx = param->ctx,
95 .element_state_change = MESHX_SUCCESS,
96 },
97 .state = model_state,
98 };
99
100 return MESHX_SUCCESS;
101}
meshx_property_cli_el_msg_t element_msg
Definition meshx_model_property.hpp:94
#define MESHX_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS
Definition meshx_ble_mesh_cmn_def.h:314
#define MESHX_MODEL_OP_GEN_USER_PROPERTIES_STATUS
Definition meshx_ble_mesh_cmn_def.h:322
#define MESHX_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS
Definition meshx_ble_mesh_cmn_def.h:330
#define MESHX_MODEL_OP_GEN_MANUFACTURER_PROPERTY_STATUS
Definition meshx_ble_mesh_cmn_def.h:310
#define MESHX_MODEL_OP_GEN_MANUFACTURER_PROPERTIES_STATUS
Definition meshx_ble_mesh_cmn_def.h:306
#define MESHX_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS
Definition meshx_ble_mesh_cmn_def.h:318
#define MESHX_MODEL_OP_GEN_USER_PROPERTY_STATUS
Definition meshx_ble_mesh_cmn_def.h:326
uint32_t opcode
Definition meshx_ble_mesh_cmn.h:49
uint8_t user_access
Definition meshx_ble_mesh_gen_cli.h:227
uint16_t property_id
Definition meshx_ble_mesh_gen_cli.h:226
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 user_access
Definition meshx_ble_mesh_gen_cli.h:240
uint16_t property_id
Definition meshx_ble_mesh_gen_cli.h:239
uint16_t property_id
Definition meshx_ble_mesh_gen_cli.h:213
uint8_t user_access
Definition meshx_ble_mesh_gen_cli.h:214
meshx_gen_user_property_status_cb_t user_property_status
Definition meshx_ble_mesh_gen_cli.h:265
meshx_gen_manufacturer_property_status_cb_t manufacturer_property_status
Definition meshx_ble_mesh_gen_cli.h:269
meshx_gen_admin_property_status_cb_t admin_property_status
Definition meshx_ble_mesh_gen_cli.h:267

◆ model_from_ble_cb()

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

Creates a meshXGenericPropertyClientModel instance based on a BLE device.

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

Implements meshXModel< meshXBaseGenericClientModel, meshx_gen_property_send_params_t >.

180{
181 if(!params || !p_dev)
182 {
183 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Invalid parameters");
184 return MESHX_INVALID_ARG;
185 }
187 {
188 /* Callback triggered not for this model */
189 return MESHX_SUCCESS;
190 }
191 const auto *param = static_cast<const meshx_gen_cli_cb_param_t *>(params);
192
193 return static_cast<int>(param->evt) == static_cast<int>(meshx_base_cli_evt::MESHX_BASE_CLI_TIMEOUT) ?
196}
meshx_err_t meshx_state_change_notify(const meshx_gen_cli_cb_param_t *param, uint8_t status)
Handle Generic Property state change notifications from the MeshX stack.
Definition meshx_model_property.cpp:39
@ 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 meshXGenericPropertyClientModel::model_send ( meshx_gen_property_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_property_send_params_t structure as input and sends the corresponding packet to the MeshX stack for processing.

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

Implements meshXModel< meshXBaseGenericClientModel, meshx_gen_property_send_params_t >.

210{
211 meshx_err_t err;
212 meshx_gen_cli_set_t set; // Not used for property GET operations
213 if (!params || !params->model || !params->model->p_model)
214 {
215 return MESHX_INVALID_ARG;
216 }
217
219
220 send_params.state = &set;
221 send_params.opcode = static_cast<uint16_t>(params->ctx->opcode);
222 send_params.net_idx = params->ctx->net_idx;
223 send_params.app_idx = params->ctx->app_idx;
224 send_params.addr = params->model->pub_addr;
225 send_params.model = params->model->p_model;
226
227 // Property client operations are primarily GET operations
229 {
230 err = this->get_base_model()->plat_send_msg(&send_params);
231 }
233 {
234 // For specific property GET, we don't need to set anything in the union
235 // The property ID would be passed through other means if needed
236 err = this->get_base_model()->plat_send_msg(&send_params);
237 }
239 {
240 err = this->get_base_model()->plat_send_msg(&send_params);
241 }
243 {
244 err = this->get_base_model()->plat_send_msg(&send_params);
245 }
247 {
248 err = this->get_base_model()->plat_send_msg(&send_params);
249 }
251 {
252 err = this->get_base_model()->plat_send_msg(&send_params);
253 }
255 {
256 err = this->get_base_model()->plat_send_msg(&send_params);
257 }
258 else
259 {
260 err = MESHX_INVALID_ARG; // Invalid opcode
261 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Invalid opcode for Generic Property Client: %04x", params->ctx->opcode);
262 }
263 return err;
264}
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_USER_PROPERTIES_GET
Definition meshx_ble_mesh_cmn_def.h:321
#define MESHX_MODEL_OP_GEN_MANUFACTURER_PROPERTIES_GET
Definition meshx_ble_mesh_cmn_def.h:305
#define MESHX_MODEL_OP_GEN_CLIENT_PROPERTIES_GET
Definition meshx_ble_mesh_cmn_def.h:329
#define MESHX_MODEL_OP_GEN_MANUFACTURER_PROPERTY_GET
Definition meshx_ble_mesh_cmn_def.h:307
#define MESHX_MODEL_OP_GEN_USER_PROPERTY_GET
Definition meshx_ble_mesh_cmn_def.h:323
#define MESHX_MODEL_OP_GEN_ADMIN_PROPERTIES_GET
Definition meshx_ble_mesh_cmn_def.h:313
#define MESHX_MODEL_OP_GEN_ADMIN_PROPERTY_GET
Definition meshx_ble_mesh_cmn_def.h:315
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
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
meshx_ctx_t * ctx
Definition meshx_model_property.hpp:58
meshx_model_t * model
Definition meshx_model_property.hpp:57
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 meshXGenericPropertyClientModel::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.

114{
115 if (!msg_ptr || !msg_size)
116 {
117 return MESHX_INVALID_ARG;
118 }
119
120 *msg_ptr = &element_msg;
121 *msg_size = sizeof(element_msg);
122
123 return MESHX_SUCCESS;
124}

Field Documentation

◆ element_msg

meshx_property_cli_el_msg_t meshXGenericPropertyClientModel::element_msg
private

◆ model_state

meshx_gen_property_model_state_t meshXGenericPropertyClientModel::model_state
private

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