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

Template specialization of meshXBaseServerModel for Generic BLE mesh models. More...

#include <meshx_base_model_generic.hpp>

Inheritance diagram for meshXBaseGenericServerModel:
meshXBaseServerModel< meshXBaseGenericServerModel, meshx_gen_server_send_params_t, meshx_gen_server_restore_params_t, meshx_gen_srv_cb_param_t > meshXBaseModel< meshx_gen_server_send_params_t >

Public Member Functions

meshx_err_t plat_model_init (void) override
 Initialization function for the Generic OnOff Server model.
meshx_err_t validate_server_status_opcode (uint16_t opcode) override
 Validate a server status opcode.
meshx_err_t server_state_restore (meshx_gen_server_restore_params_t *param) override
 Restores the state of the Generic Server model.
meshx_err_t plat_send_msg (meshx_gen_server_send_params_t *params) override
 Sends a status message for the Generic Server model.
 meshXBaseGenericServerModel (uint32_t model_id, meshx_ptr_t p_plat_model, const control_msg_cb &from_ble_cb)
 Constructor for the meshXBaseGenericServerModel class.
 meshXBaseGenericServerModel ()=delete
 ~meshXBaseGenericServerModel () final=default
Public Member Functions inherited from meshXBaseServerModel< meshXBaseGenericServerModel, meshx_gen_server_send_params_t, meshx_gen_server_restore_params_t, meshx_gen_srv_cb_param_t >
 meshXBaseServerModel ()=delete
virtual ~meshXBaseServerModel ()=default
meshx_err_t from_ble_dereg_cb (void) const override
 Deregister BLE message callback for this model.
void set_plat_model_ptr (meshx_ptr_t p_model)
 Set the platform model pointer and update the registration list.
Public Member Functions inherited from meshXBaseModel< meshx_gen_server_send_params_t >
meshx_err_t from_ble_reg_cb (void) const
 Register BLE message callback for this model.
meshx_err_t get_status (void) const
 Get the current status of the model.
uint32_t get_model_id (void) const
 Get the model identifier.
control_task_msg_handle_t get_from_ble_cb (void) const
 Get the BLE message callback function.
meshXBaseModelType_t get_model_type (void) const
 Get the model type (server/client).
void set_status (meshx_err_t err)
 Set the model status.
void set_model_id (uint32_t id)
 Set the model identifier.
void set_from_ble_cb (control_task_msg_handle_t cb)
 Set the BLE message callback function.
void set_model_type (meshXBaseModelType_t type)
 Set the model type.
 meshXBaseModel (uint32_t model_id, control_task_msg_handle_t from_ble_cb, meshXBaseModelType_t model_type)
 Construct a new meshXBaseModel object.
virtual ~meshXBaseModel ()
 Virtual destructor for meshXBaseModel.

Additional Inherited Members

Static Protected Member Functions inherited from meshXBaseServerModel< meshXBaseGenericServerModel, meshx_gen_server_send_params_t, meshx_gen_server_restore_params_t, meshx_gen_srv_cb_param_t >
static meshx_err_t base_from_ble_msg_handle (dev_struct_t *pdev, control_task_msg_evt_t evt, meshx_ptr_t params)
 Sends a BLE message from a server model.
Protected Attributes inherited from meshXBaseServerModel< meshXBaseGenericServerModel, meshx_gen_server_send_params_t, meshx_gen_server_restore_params_t, meshx_gen_srv_cb_param_t >
meshx_ptr_t p_plat_model
Protected Attributes inherited from meshXBaseModel< meshx_gen_server_send_params_t >
uint32_t model_id
meshXBaseModelType_t model_type
control_task_msg_handle_t from_ble_cb
meshx_err_t status
Static Protected Attributes inherited from meshXBaseServerModel< meshXBaseGenericServerModel, meshx_gen_server_send_params_t, meshx_gen_server_restore_params_t, meshx_gen_srv_cb_param_t >
static std::once_flag plat_server_init_flag
static std::forward_list< base_server_model_cb_reg_tbase_server_model_cb_list

Detailed Description

Template specialization of meshXBaseServerModel for Generic BLE mesh models.

This class provides a concrete implementation of the template-based meshXBaseServerModel specifically designed for Generic BLE mesh server models. It inherits all the template benefits including type safety, static callback dispatching, and enhanced debugging while providing Generic-specific functionality.

Key Features:

  • Inherits template-based architecture from meshXBaseServerModel
  • Provides Generic-specific opcode validation and message handling
  • Implements platform-specific message sending
  • Supports all Generic model types (OnOff, Level, Power, Battery, Location)
  • Enhanced error handling and debugging with template type identification
  • Static wrapper functions for C-style callback compatibility

Template Parameters:

Supported Operations:

  • Generic OnOff status updates
  • Generic Level status updates
  • Generic Power Level status updates
  • Generic Battery status updates
  • Generic Location status updates
  • Property-based status updates (Manufacturer, Admin, User)
Note
This class uses private inheritance to maintain encapsulation while providing access to base functionality through friendship.
See also
meshXBaseServerModel for base template functionality.
meshx_gen_server_send_params_t for send parameter structure.

Constructor & Destructor Documentation

◆ meshXBaseGenericServerModel() [1/2]

meshXBaseGenericServerModel::meshXBaseGenericServerModel ( uint32_t model_id,
meshx_ptr_t p_plat_model,
const control_msg_cb & from_ble_cb )

Constructor for the meshXBaseGenericServerModel class.

Parameters
[in]model_idThe model ID associated with the generic server model.
[in]p_plat_modelPointer to the platform model instance
[in]from_ble_cbThe control task message handle associated with the generic server model.
320{
322 if (get_status() != MESHX_SUCCESS)
323 {
324 MESHX_LOGE(MODULE_ID_COMMON, "plat_model_init failed");
325 return;
326 }
327}
meshx_err_t plat_model_init(void) override
Initialization function for the Generic OnOff Server model.
Definition meshx_base_model_generic.cpp:341
uint32_t model_id
Definition meshx_base_model_class.hpp:52
control_task_msg_handle_t from_ble_cb
Definition meshx_base_model_class.hpp:54
meshx_err_t get_status(void) const
Definition meshx_base_model_class.hpp:123
void set_status(meshx_err_t err)
Definition meshx_base_model_class.hpp:147
#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_COMMON
Definition module_id.h:36

◆ meshXBaseGenericServerModel() [2/2]

meshXBaseGenericServerModel::meshXBaseGenericServerModel ( )
delete

◆ ~meshXBaseGenericServerModel()

meshXBaseGenericServerModel::~meshXBaseGenericServerModel ( )
finaldefault

Member Function Documentation

◆ plat_model_init()

meshx_err_t meshXBaseGenericServerModel::plat_model_init ( void )
overridevirtual

Initialization function for the Generic OnOff Server model.

This function is responsible for initializing the Generic OnOff Server model. It checks if the model has been initialized before, and if not, it registers the callback function for transaction control messages and calls the platform specific initialization function.

Returns
meshx_err_t containing the result of the initialization operation.

Implements meshXBaseModel< meshx_gen_server_send_params_t >.

342{
344 std::call_once(plat_server_init_flag, [&]() {
346 });
347 return err;
348}
meshx_err_t meshx_plat_gen_srv_init(void)
Initialize the generic server model platform.
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43

◆ plat_send_msg()

meshx_err_t meshXBaseGenericServerModel::plat_send_msg ( meshx_gen_server_send_params_t * params)
overridevirtual

Sends a status message for the Generic Server model.

This function sends a status message for the Generic Server model to the BLE Mesh network. It checks if the provided model and context are valid, and if the opcode is within the range of supported Generic Server opcodes.

Parameters
[in]paramsPointer to the Generic Server sending params
Returns
  • MESHX_SUCCESS: Successfully sent the status message.
  • MESHX_INVALID_ARG: Invalid argument provided.
  • MESHX_ERR_PLAT: Platform-specific error occurred.

Implements meshXBaseModel< meshx_gen_server_send_params_t >.

402{
403 if ( params == nullptr
404 || params->p_model == nullptr
405 || params->p_ctx == nullptr
406 || params->data_len == 0
407 || params->p_ctx->dst_addr == MESHX_ADDR_UNASSIGNED
408 )
409 {
410 return MESHX_INVALID_ARG;
411 }
412 if (validate_server_status_opcode((uint16_t)params->p_ctx->opcode) != MESHX_SUCCESS)
413 {
414 return MESHX_INVALID_ARG;
415 }
416
418 params->p_model,
419 params->p_ctx,
420 &params->state_change,
421 params->data_len
422 );
423}
meshx_err_t validate_server_status_opcode(uint16_t opcode) override
Validate a server status opcode.
Definition meshx_base_model_generic.cpp:362
#define MESHX_ADDR_UNASSIGNED
Definition meshx_ble_mesh_cmn_def.h:30
meshx_err_t meshx_plat_gen_srv_send_status(meshx_model_t *p_model, meshx_ctx_t *p_ctx, meshx_ptr_t p_data, uint32_t data_len)
Send a status message from the Generic Server model.
@ MESHX_INVALID_ARG
Definition meshx_err.h:46

◆ server_state_restore()

meshx_err_t meshXBaseGenericServerModel::server_state_restore ( meshx_gen_server_restore_params_t * param)
overridevirtual

Restores the state of the Generic Server model.

This function sets the user data of the specified model to the given state. It checks if the model pointer is valid before proceeding with the operation.

Parameters
[in]paramPointer to the structure containing the model and state to be restored.
Returns
  • MESHX_SUCCESS: State restored successfully.
  • MESHX_INVALID_ARG: Invalid model pointer.

Implements meshXBaseServerModel< meshXBaseGenericServerModel, meshx_gen_server_send_params_t, meshx_gen_server_restore_params_t, meshx_gen_srv_cb_param_t >.

440{
441 if(!param || !param->p_model)
442 {
443 return MESHX_INVALID_ARG;
444 }
445
446 uint16_t state_len = 0;
447 switch(this->get_model_id())
448 {
450 state_len = sizeof(param->state_change.onoff);
451 break;
453 state_len = sizeof(param->state_change.level);
454 break;
456 state_len = sizeof(param->state_change.onpowerup);
457 break;
459 state_len = sizeof(param->state_change.power_level);
460 break;
462 state_len = sizeof(param->state_change.battery);
463 break;
465 state_len = sizeof(param->state_change.location);
466 break;
468 state_len = sizeof(param->state_change.def_trans_time);
469 break;
470 default:
471 return MESHX_NOT_SUPPORTED;
472 }
473 return meshx_plat_set_gen_srv_state(param->p_model, &param->state_change, state_len);
474}
uint32_t get_model_id(void) const
Definition meshx_base_model_class.hpp:129
#define MESHX_MODEL_ID_GEN_POWER_ONOFF_SRV
Definition meshx_ble_mesh_cmn_def.h:76
#define MESHX_MODEL_ID_GEN_LOCATION_SRV
Definition meshx_ble_mesh_cmn_def.h:84
#define MESHX_MODEL_ID_GEN_LEVEL_SRV
Definition meshx_ble_mesh_cmn_def.h:72
#define MESHX_MODEL_ID_GEN_BATTERY_SRV
Definition meshx_ble_mesh_cmn_def.h:82
#define MESHX_MODEL_ID_GEN_POWER_LEVEL_SRV
Definition meshx_ble_mesh_cmn_def.h:79
#define MESHX_MODEL_ID_GEN_ONOFF_SRV
Definition meshx_ble_mesh_cmn_def.h:70
#define MESHX_MODEL_ID_GEN_DEF_TRANS_TIME_SRV
Definition meshx_ble_mesh_cmn_def.h:74
meshx_err_t meshx_plat_set_gen_srv_state(void *p_model, const meshx_gen_server_state_t *state, uint16_t state_len)
Set the state of a generic server model.
@ MESHX_NOT_SUPPORTED
Definition meshx_err.h:51

◆ validate_server_status_opcode()

meshx_err_t meshXBaseGenericServerModel::validate_server_status_opcode ( uint16_t opcode)
overridevirtual

Validate a server status opcode.

This function determines whether the provided opcode corresponds to a status message in the Generic Server group in the MeshX protocol.

Parameters
[in]opcodeThe opcode to validate.
Returns
meshx_err_t containing the result of the validation operation. Returns MESHX_SUCCESS if the opcode is valid, or an error code otherwise.

Implements meshXBaseServerModel< meshXBaseGenericServerModel, meshx_gen_server_send_params_t, meshx_gen_server_restore_params_t, meshx_gen_srv_cb_param_t >.

363{
364 switch(opcode)
365 {
379 return MESHX_SUCCESS;
380 default:
381 return MESHX_FAIL;
382 }
383}
#define MESHX_MODEL_OP_GEN_LOC_LOCAL_STATUS
Definition meshx_ble_mesh_cmn_def.h:296
#define MESHX_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS
Definition meshx_ble_mesh_cmn_def.h:260
#define MESHX_MODEL_OP_GEN_LOC_GLOBAL_STATUS
Definition meshx_ble_mesh_cmn_def.h:294
#define MESHX_MODEL_OP_GEN_ONPOWERUP_STATUS
Definition meshx_ble_mesh_cmn_def.h:264
#define MESHX_MODEL_OP_GEN_BATTERY_STATUS
Definition meshx_ble_mesh_cmn_def.h:290
#define MESHX_MODEL_OP_GEN_ONOFF_STATUS
Definition meshx_ble_mesh_cmn_def.h:244
#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_POWER_RANGE_STATUS
Definition meshx_ble_mesh_cmn_def.h:280
#define MESHX_MODEL_OP_GEN_POWER_DEFAULT_STATUS
Definition meshx_ble_mesh_cmn_def.h:278
#define MESHX_MODEL_OP_GEN_POWER_LEVEL_STATUS
Definition meshx_ble_mesh_cmn_def.h:274
#define MESHX_MODEL_OP_GEN_LEVEL_STATUS
Definition meshx_ble_mesh_cmn_def.h:250
#define MESHX_MODEL_OP_GEN_POWER_LAST_STATUS
Definition meshx_ble_mesh_cmn_def.h:276
@ MESHX_FAIL
Definition meshx_err.h:45

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