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

A template class for creating Generic Default Transition Time Server models. More...

#include <meshx_model_def_trans_time.hpp>

Inheritance diagram for meshXGenericDefTransTimeServerModel:
meshXServerModel< meshXBaseGenericServerModel, meshx_gen_def_trans_time_send_params_t > meshXModel< meshXBaseGenericServerModel, meshx_gen_def_trans_time_send_params_t > meshXModelIF

Public Member Functions

meshx_err_t model_send (meshx_gen_def_trans_time_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 Default Transition Time Server Model.
meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override
 Prepare message for element notification.
meshx_err_t element_state_change_handle (void) override
 Handle state change request from element.
 meshXGenericDefTransTimeServerModel (meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
 Constructor for Generic Default Transition Time Server Model.
 ~meshXGenericDefTransTimeServerModel ()=default
Public Member Functions inherited from meshXServerModel< meshXBaseGenericServerModel, meshx_gen_def_trans_time_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_def_trans_time_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
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 Default Transition Time Server.
meshx_err_t plat_model_delete (void) override
 Deletes the Generic Default Transition Time Server model and its associated resources.

Private Attributes

meshx_gen_def_trans_time_model_state_t model_state
meshx_def_trans_time_srv_el_msg_t element_msg
bool element_msg_prepared = false

Additional Inherited Members

Protected Member Functions inherited from meshXServerModel< meshXBaseGenericServerModel, meshx_gen_def_trans_time_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 Default Transition Time Server models.

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

Constructor & Destructor Documentation

◆ meshXGenericDefTransTimeServerModel()

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

Constructor for Generic Default Transition Time 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.
394{}
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_DEF_TRANS_TIME_SRV
Definition meshx_ble_mesh_cmn_def.h:74

◆ ~meshXGenericDefTransTimeServerModel()

meshXGenericDefTransTimeServerModel::~meshXGenericDefTransTimeServerModel ( )
default

Member Function Documentation

◆ element_state_change_handle()

meshx_err_t meshXGenericDefTransTimeServerModel::element_state_change_handle ( void )
overridevirtual

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
  • MESHX_INVALID_STATE: No state change detected

Implements meshXModelIF.

355{
356 auto *el_state =
358
359 if (!el_state) {
360 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Invalid parameter in element_state_change_handle");
361 return MESHX_INVALID_ARG;
362 }
363
364 if(memcmp(&model_state, el_state, sizeof(meshx_gen_def_trans_time_model_state_t)) != 0)
365 {
367 "Def Trans Time state change request: trans_time=%d",
368 el_state->trans_time);
369 // Update the model state
370 *el_state = model_state;
371 }
372 else
373 {
374 return MESHX_INVALID_STATE;
375 }
376 return MESHX_SUCCESS;
377}
meshx_gen_def_trans_time_model_state_t model_state
Definition meshx_model_def_trans_time.hpp:130
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_def_trans_time_model_state meshx_gen_def_trans_time_model_state_t
Definition meshx_model_def_trans_time.hpp:37
**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_from_ble_cb()

meshx_err_t meshXGenericDefTransTimeServerModel::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 Default Transition Time 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_def_trans_time_send_params_t >.

283{
284 if(!params || !p_dev)
285 {
286 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Invalid parameters");
287 return MESHX_INVALID_ARG;
288 }
290 {
291 /* Callback triggered not for this model */
292 return MESHX_SUCCESS;
293 }
294
295 auto *param = static_cast<meshx_gen_srv_cb_param_t *>(params);
296
297 // Store the message in member variable for later use by prepare_element_msg
298 element_msg = {
299 .header = {
300 .model = param->model,
301 .element_state_change = MESHX_SUCCESS,
302 },
303 .state = {
304 .trans_time = param->state_change.def_trans_time_set.trans_time
305 }
306 };
307
309 return MESHX_SUCCESS;
310}
bool element_msg_prepared
Definition meshx_model_def_trans_time.hpp:136
meshx_def_trans_time_srv_el_msg_t element_msg
Definition meshx_model_def_trans_time.hpp:133
struct meshx_gen_srv_cb_param meshx_gen_srv_cb_param_t

◆ model_send()

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

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

Implements meshXModel< meshXBaseGenericServerModel, meshx_gen_def_trans_time_send_params_t >.

248{
249if (!params|| !params->model || !params->ctx)
250 {
251 return MESHX_INVALID_ARG;
252 }
254 meshx_gen_srv_state_change_t state_change = {
255 .def_trans_time_set = {
256 .trans_time = params->trans_time
257 }
258 };
259 meshx_gen_server_send_params_t send_params = {
260 .p_model = params->model,
261 .p_ctx = params->ctx,
262 .state_change = state_change,
263 .data_len = sizeof(meshx_state_change_gen_def_trans_time_set_t)
264 };
265 return this->get_base_model()->plat_send_msg(&send_params);
266}
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_DEF_TRANS_TIME_STATUS
Definition meshx_ble_mesh_cmn_def.h:260
uint32_t opcode
Definition meshx_ble_mesh_cmn.h:49
meshx_ctx_t * ctx
Definition meshx_model_def_trans_time.hpp:45
meshx_model_t * model
Definition meshx_model_def_trans_time.hpp:44

◆ plat_model_create()

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

Creates and initializes a server model instance for Generic Default Transition Time Server.

This function handles the platform-specific model creation process for Generic Default Transition Time Server models. It initializes server-specific features and cannot be overridden by derived classes.

Returns
meshx_err_t Returns an error code indicating the result of the operation.
  • MESHX_SUCCESS on successful model creation and initialization
  • MESHX_ERR_NO_MEM if memory allocation fails
  • Other error codes for platform-specific failures
Note
This is a final function and cannot be overridden by derived classes.

Implements meshXModelIF.

412{
413 if (p_plat_model_ptr) {
414 this->set_plat_model(p_plat_model_ptr);
415 }
416 meshx_ptr_t p_pub = this->get_pub_struct();
417 meshx_ptr_t p_gen = this->get_gen_struct();
419
420 err = meshx_plat_def_trans_time_gen_srv_create(this->get_plat_model(), &p_pub, &p_gen);
421 if(err)
422 {
423 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Failed to create Generic Default Transition Time Server Model");
424 }
425 else
426 {
427 this->set_pub_struct(p_pub);
428 this->set_gen_struct(p_gen);
429 }
430 return err;
431}
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_plat_def_trans_time_gen_srv_create(void *p_model, void **p_pub, void **p_trans_time_srv)
Creates a Generic Default Transition Time Server model and its publication context.
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43

◆ plat_model_delete()

meshx_err_t meshXGenericDefTransTimeServerModel::plat_model_delete ( void )
overrideprivatevirtual

Deletes the Generic Default Transition Time Server model and its associated resources.

This function frees the memory allocated for the Generic Default Transition Time Server and sets the pointer to NULL. It also deletes the model publication resources associated with the server.

Returns
  • MESHX_SUCCESS: Model and publication deleted successfully.
  • MESHX_FAIL: Failed to delete the model or publication.

Implements meshXModelIF.

447{
448 meshx_ptr_t p_pub = this->get_pub_struct();
449 meshx_ptr_t p_gen = this->get_gen_struct();
450
451 meshx_err_t err = meshx_plat_gen_srv_delete(&p_pub, &p_gen);
452 if (err)
453 {
454 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Failed to delete Generic Default Transition Time Server Model");
455 }
456 else
457 {
458 this->set_pub_struct(nullptr);
459 this->set_gen_struct(nullptr);
460 }
461 return err;
462}
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 meshXGenericDefTransTimeServerModel::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.

323{
324 if (!msg_ptr || !msg_size)
325 {
326 return MESHX_INVALID_ARG;
327 }
328
330 {
331 return MESHX_NOT_SUPPORTED;
332 }
333
334 *msg_ptr = &element_msg;
335 *msg_size = sizeof(element_msg);
336
337 return MESHX_SUCCESS;
338}
@ MESHX_NOT_SUPPORTED
Definition meshx_err.h:51

Field Documentation

◆ element_msg

meshx_def_trans_time_srv_el_msg_t meshXGenericDefTransTimeServerModel::element_msg
private

◆ element_msg_prepared

bool meshXGenericDefTransTimeServerModel::element_msg_prepared = false
private

◆ model_state

meshx_gen_def_trans_time_model_state_t meshXGenericDefTransTimeServerModel::model_state
private

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