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

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

#include <meshx_model_property.hpp>

Inheritance diagram for meshXGenericClientPropertyServerModel:
meshXServerModel< meshXBaseGenericServerModel, meshx_gen_property_send_params_t > meshXModel< meshXBaseGenericServerModel, 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
 Callback function for handling BLE mesh events for Generic Client Property Server Model.
meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override
 Prepare message for element notification.
 meshXGenericClientPropertyServerModel (meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
 Constructor for Generic Client Property Server Model.
 ~meshXGenericClientPropertyServerModel ()=default
Public Member Functions inherited from meshXServerModel< meshXBaseGenericServerModel, meshx_gen_property_send_params_t >
 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)
 Construct a new Server Model.
Public Member Functions inherited from meshXModel< meshXBaseGenericServerModel, 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.
meshXBaseGenericServerModelget_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
virtual meshx_err_t element_state_change_handle (void)=0
 Handle state change request from element.
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 plat_model_create (MESHX_MODEL *p_plat_model_ptr=nullptr) override
 Creates and initializes a server model instance for Generic Client Property Server.
meshx_err_t plat_model_delete (void) override
 Deletes the Generic Client Property Server model.

Private Attributes

meshx_property_srv_el_msg_t element_msg
bool element_msg_prepared = false

Additional Inherited Members

Protected Member Functions inherited from meshXServerModel< meshXBaseGenericServerModel, 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 server message header.

Detailed Description

A template class for creating Generic Client Property Server models.

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

Constructor & Destructor Documentation

◆ meshXGenericClientPropertyServerModel()

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

Constructor for Generic Client Property Server Model.

Parameters
[in]parent_elementPointer 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.
1030{}
meshXElementIF * parent_element
Definition meshx_model_class.hpp:42
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
#define MESHX_MODEL_ID_GEN_CLIENT_PROP_SRV
Definition meshx_ble_mesh_cmn_def.h:90

◆ ~meshXGenericClientPropertyServerModel()

meshXGenericClientPropertyServerModel::~meshXGenericClientPropertyServerModel ( )
default

Member Function Documentation

◆ model_from_ble_cb()

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

Callback function for handling BLE mesh events for Generic Client Property Server Model.

Parameters
[in]p_devPointer to the device structure
[in]model_idModel ID associated with the event
[in]paramsPointer to the event parameters
Returns
MESHX_SUCCESS if successful, error code otherwise

Implements meshXModel< meshXBaseGenericServerModel, meshx_gen_property_send_params_t >.

1047{
1048 if(!params || !p_dev)
1049 {
1050 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Invalid parameters");
1051 return MESHX_INVALID_ARG;
1052 }
1054 {
1055 /* Callback triggered not for this model */
1056 return MESHX_SUCCESS;
1057 }
1058
1059 auto *param = static_cast<meshx_gen_srv_cb_param_t *>(params);
1060
1061 // Store the message in member variable for later use by prepare_element_msg
1062 element_msg = {
1063 .header = {
1064 .model = param->model,
1065 .element_state_change = MESHX_SUCCESS,
1066 },
1067 .state = {
1068 .property_id = 0,
1069 .property_value = nullptr,
1070 .access = 0
1071 }
1072 };
1073
1074 element_msg_prepared = true;
1075 return MESHX_SUCCESS;
1076}
bool element_msg_prepared
Definition meshx_model_property.hpp:275
meshx_property_srv_el_msg_t element_msg
Definition meshx_model_property.hpp:272
struct meshx_gen_srv_cb_param meshx_gen_srv_cb_param_t
@ 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
@ MODULE_ID_MODEL_SERVER
Definition module_id.h:34

◆ model_send()

meshx_err_t meshXGenericClientPropertyServerModel::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< meshXBaseGenericServerModel, meshx_gen_property_send_params_t >.

998{
999if (!params|| !params->model || !params->ctx)
1000 {
1001 return MESHX_INVALID_ARG;
1002 }
1004 // Client Property Server doesn't modify state, just responds with available properties
1005 meshx_gen_srv_state_change_t state_change = {0}; // Empty state change for client properties
1006 meshx_gen_server_send_params_t send_params = {
1007 .p_model = params->model,
1008 .p_ctx = params->ctx,
1009 .state_change = state_change,
1010 .data_len = 0 // No state data for client properties status
1011 };
1012 return this->get_base_model()->plat_send_msg(&send_params);
1013}
meshx_err_t plat_send_msg(meshx_gen_server_send_params_t *params) override
Sends a status message for the Generic Server model.
Definition meshx_base_model_generic.cpp:401
meshXBaseGenericServerModel * get_base_model(void) const
Definition meshx_model_class.hpp:315
struct meshx_gen_server_send_params { meshx_model_t *p_model; meshx_ctx_t *p_ctx; meshx_gen_srv_state_change_t state_change; size_t data_len; } meshx_gen_server_send_params_t
Definition meshx_base_model_generic.hpp:135
#define MESHX_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS
Definition meshx_ble_mesh_cmn_def.h:330
uint32_t opcode
Definition meshx_ble_mesh_cmn.h:49
meshx_ctx_t * ctx
Definition meshx_model_property.hpp:58
meshx_model_t * model
Definition meshx_model_property.hpp:57

◆ plat_model_create()

meshx_err_t meshXGenericClientPropertyServerModel::plat_model_create ( MESHX_MODEL * p_plat_model_ptr = nullptr)
overrideprivatevirtual

Creates and initializes a server model instance for Generic Client Property Server.

Implements meshXModelIF.

1112{
1113 this->set_plat_model(p_plat_model_ptr);
1114 meshx_ptr_t p_pub = this->get_pub_struct();
1115 meshx_ptr_t p_gen = this->get_gen_struct();
1117
1118 // Client Property Server uses the same platform creation as other property servers but with its own model ID
1119 err = meshx_plat_gen_srv_create(this->get_plat_model(), &p_pub, &p_gen);
1120 if(err)
1121 {
1122 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Failed to create Generic Client Property Server Model");
1123 }
1124 else
1125 {
1126 this->set_pub_struct(p_pub);
1127 this->set_gen_struct(p_gen);
1128 }
1129 return err;
1130}
meshx_ptr_t get_pub_struct(void) const
Get the publication structures.
Definition meshx_model_class.hpp:113
MESHX_MODEL * get_plat_model(void) const
Get the platform-specific model instance.
Definition meshx_model_class.hpp:107
void set_gen_struct(meshx_ptr_t gen)
Set the generic structures.
Definition meshx_model_class.hpp:131
meshx_ptr_t get_gen_struct(void) const
Get the generic structures.
Definition meshx_model_class.hpp:119
void set_pub_struct(meshx_ptr_t pub)
Set the publication structures.
Definition meshx_model_class.hpp:125
void set_plat_model(MESHX_MODEL *p_model) override
Definition meshx_model_class.cpp:92
void * meshx_ptr_t
Definition meshx_ble_mesh_cmn_def.h:636
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43

◆ plat_model_delete()

meshx_err_t meshXGenericClientPropertyServerModel::plat_model_delete ( void )
overrideprivatevirtual

Deletes the Generic Client Property Server model.

Implements meshXModelIF.

1138{
1139 meshx_ptr_t p_pub = this->get_pub_struct();
1140 meshx_ptr_t p_gen = this->get_gen_struct();
1141
1142 meshx_err_t err = meshx_plat_gen_srv_delete(&p_pub, &p_gen);
1143 if (err)
1144 {
1145 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Failed to delete Generic Client Property Server Model");
1146 }
1147 else
1148 {
1149 this->set_pub_struct(nullptr);
1150 this->set_gen_struct(nullptr);
1151 }
1152 return err;
1153}
meshx_err_t meshx_plat_gen_srv_delete(void **p_pub, void **p_srv)
Deletes the Generic OnOff Server model and its associated resources.

◆ prepare_element_msg()

meshx_err_t meshXGenericClientPropertyServerModel::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 if it has been prepared

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.

1089{
1090 if (!msg_ptr || !msg_size)
1091 {
1092 return MESHX_INVALID_ARG;
1093 }
1094
1096 {
1097 return MESHX_NOT_SUPPORTED;
1098 }
1099
1100 *msg_ptr = &element_msg;
1101 *msg_size = sizeof(element_msg);
1102
1103 return MESHX_SUCCESS;
1104}
@ MESHX_NOT_SUPPORTED
Definition meshx_err.h:51

Field Documentation

◆ element_msg

meshx_property_srv_el_msg_t meshXGenericClientPropertyServerModel::element_msg
private

◆ element_msg_prepared

bool meshXGenericClientPropertyServerModel::element_msg_prepared = false
private

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