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

Implementation of meshXBaseServerModel for Light BLE mesh models. More...

#include <meshx_base_model_light.hpp>

Inheritance diagram for meshXBaseLightServerModel:
meshXBaseServerModel< meshXBaseLightServerModel, meshx_light_server_send_params_t, meshx_light_server_restore_params_t, meshx_lighting_server_cb_param_t > meshXBaseModel< meshx_light_server_send_params_t >

Public Member Functions

meshx_err_t plat_model_init (void) override
 Initialization function for the Light Server model.
meshx_err_t validate_server_status_opcode (uint16_t opcode) override
 Validate a light server status opcode.
meshx_err_t server_state_restore (meshx_light_server_restore_params_t *param) override
 Restores the state of the Light Server model.
meshx_err_t plat_send_msg (meshx_light_server_send_params_t *params) override
 Sends a status message for the Light Server model.
 meshXBaseLightServerModel (uint32_t model_id, meshx_ptr_t p_plat_model, const control_msg_cb &from_ble_cb)
 Constructor for the meshXBaseLightServerModel class.
 meshXBaseLightServerModel ()=delete
 ~meshXBaseLightServerModel () final=default
Public Member Functions inherited from meshXBaseServerModel< meshXBaseLightServerModel, meshx_light_server_send_params_t, meshx_light_server_restore_params_t, meshx_lighting_server_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_light_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< meshXBaseLightServerModel, meshx_light_server_send_params_t, meshx_light_server_restore_params_t, meshx_lighting_server_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< meshXBaseLightServerModel, meshx_light_server_send_params_t, meshx_light_server_restore_params_t, meshx_lighting_server_cb_param_t >
meshx_ptr_t p_plat_model
Protected Attributes inherited from meshXBaseModel< meshx_light_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< meshXBaseLightServerModel, meshx_light_server_send_params_t, meshx_light_server_restore_params_t, meshx_lighting_server_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

Implementation of meshXBaseServerModel for Light BLE mesh models.

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

Key Features:

  • Inherits template-based architecture from meshXBaseServerModel
  • Provides Light-specific opcode validation and message handling
  • Implements platform-specific message sending for Light models
  • Supports all Light server model types (Lightness, CTL, HSL, XYL, LC)
  • Enhanced error handling and debugging with template type identification

Supported Operations:

  • Light Lightness status operations
  • Light CTL status operations
  • Light HSL status operations
  • Light XYL status operations
  • Light LC (Light Control) status operations
See also
meshXBaseServerModel for base template functionality.
meshx_light_server_send_params_t for send parameter structure.

Constructor & Destructor Documentation

◆ meshXBaseLightServerModel() [1/2]

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

Constructor for the meshXBaseLightServerModel class.

Parameters
[in]model_idThe unique identifier for the Light Server model.
[in]p_plat_modelPointer to the platform-specific model structure.
[in]from_ble_cbCallback function for handling incoming BLE messages.
292{
294 if (get_status() != MESHX_SUCCESS)
295 {
296 MESHX_LOGE(MODULE_ID_COMMON, "plat_model_init failed");
297 return;
298 }
299}
meshx_err_t plat_model_init(void) override
Initialization function for the Light Server model.
Definition meshx_base_model_light.cpp:310
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

◆ meshXBaseLightServerModel() [2/2]

meshXBaseLightServerModel::meshXBaseLightServerModel ( )
delete

◆ ~meshXBaseLightServerModel()

meshXBaseLightServerModel::~meshXBaseLightServerModel ( )
finaldefault

Member Function Documentation

◆ plat_model_init()

meshx_err_t meshXBaseLightServerModel::plat_model_init ( void )
overridevirtual

Initialization function for the Light Server model.

This function is responsible for initializing the Light Server model. It checks if the model has been initialized before, and if not, it calls the platform specific initialization function.

Returns
meshx_err_t containing the result of the initialization operation.

Implements meshXBaseModel< meshx_light_server_send_params_t >.

311{
313 std::call_once(plat_server_init_flag, [&]() {
315 });
316 return err;
317}
meshx_err_t meshx_plat_light_srv_init(void)
Initialize the platform-specific Light Server.
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43

◆ plat_send_msg()

meshx_err_t meshXBaseLightServerModel::plat_send_msg ( meshx_light_server_send_params_t * params)
overridevirtual

Sends a status message for the Light Server model.

This function sends a status message for the Light 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 Light Server opcodes.

Parameters
[in]paramsPointer to the Light 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_light_server_send_params_t >.

376{
377 if (!params || !params->p_model || !params->p_ctx || params->p_ctx->dst_addr == MESHX_ADDR_UNASSIGNED)
378 {
379 return MESHX_INVALID_ARG;
380 }
381 if (validate_server_status_opcode((uint16_t)params->p_ctx->opcode) != MESHX_SUCCESS)
382 {
383 return MESHX_INVALID_ARG;
384 }
385
387 params->p_model,
388 params->p_ctx,
389 params->state_change
390 );
391}
meshx_err_t validate_server_status_opcode(uint16_t opcode) override
Validate a light server status opcode.
Definition meshx_base_model_light.cpp:329
#define MESHX_ADDR_UNASSIGNED
Definition meshx_ble_mesh_cmn_def.h:30
meshx_err_t meshx_plat_gen_light_srv_send_status(const meshx_model_t *p_model, const meshx_ctx_t *p_ctx, const meshx_lighting_server_state_change_t *state_change)
Send a status message from the Light Server. This function constructs and sends a status message cont...
@ MESHX_INVALID_ARG
Definition meshx_err.h:46
uint32_t opcode
Definition meshx_ble_mesh_cmn.h:49
uint16_t dst_addr
Definition meshx_ble_mesh_cmn.h:51
meshx_lighting_server_state_change_t * state_change
Definition meshx_ble_mesh_light_srv.h:573
meshx_model_t * p_model
Definition meshx_ble_mesh_light_srv.h:571
meshx_ctx_t * p_ctx
Definition meshx_ble_mesh_light_srv.h:572

◆ server_state_restore()

meshx_err_t meshXBaseLightServerModel::server_state_restore ( meshx_light_server_restore_params_t * param)
overridevirtual

Restores the state of the Light Server model.

This function restores the state of the Light Server model using the provided restore parameters. It validates the model ID and state type before calling the platform-specific function to set the server state.

Parameters
[in]paramPointer to the structure containing the restore parameters.
Returns
meshx_err_t containing the result of the restore operation.
  • MESHX_SUCCESS: State restored successfully
  • MESHX_INVALID_ARG: Invalid parameters provided
  • MESHX_NOT_SUPPORTED: Model ID not supported
  • MESHX_INVALID_STATE: Invalid or unrecognized state

Implements meshXBaseServerModel< meshXBaseLightServerModel, meshx_light_server_send_params_t, meshx_light_server_restore_params_t, meshx_lighting_server_cb_param_t >.

409{
410 if (!param || !param->p_model)
411 {
412 return MESHX_INVALID_ARG;
413 }
414
415 uint16_t state_len = 0;
416
417 // Determine the model ID and handle each state type
418 switch (this->get_model_id())
419 {
420 // Light Lightness Server Model (0x1300)
422 state_len = sizeof(meshx_light_lightness_state_t);
423 break;
426 state_len = sizeof(meshx_light_ctl_state_t);
427 break;
430 state_len = sizeof(meshx_light_hsl_state_t);
431 break;
434 state_len = sizeof(meshx_light_xyl_state_t);
435 break;
437 state_len = sizeof(meshx_light_lc_state_t);
438 break;
439 default:
440 return MESHX_NOT_SUPPORTED;
441 }
442
443 if (state_len == 0)
444 {
445 return MESHX_INVALID_STATE;
446 }
447
448 return meshx_plat_light_srv_restore(param->p_model, &param->state_change, state_len);
449}
uint32_t get_model_id(void) const
Definition meshx_base_model_class.hpp:129
#define MESHX_MODEL_ID_LIGHT_XYL_SRV
Definition meshx_ble_mesh_cmn_def.h:116
#define MESHX_MODEL_ID_LIGHT_LC_SRV
Definition meshx_ble_mesh_cmn_def.h:119
#define MESHX_MODEL_ID_LIGHT_CTL_SETUP_SRV
Definition meshx_ble_mesh_cmn_def.h:108
#define MESHX_MODEL_ID_LIGHT_LIGHTNESS_SRV
Definition meshx_ble_mesh_cmn_def.h:104
#define MESHX_MODEL_ID_LIGHT_CTL_SRV
Definition meshx_ble_mesh_cmn_def.h:107
#define MESHX_MODEL_ID_LIGHT_HSL_SRV
Definition meshx_ble_mesh_cmn_def.h:111
#define MESHX_MODEL_ID_LIGHT_XYL_SETUP_SRV
Definition meshx_ble_mesh_cmn_def.h:117
#define MESHX_MODEL_ID_LIGHT_HSL_SETUP_SRV
Definition meshx_ble_mesh_cmn_def.h:112
meshx_err_t meshx_plat_light_srv_restore(meshx_ptr_t p_model, const meshx_lighting_server_state_t *state, uint16_t state_len)
Restore the Light Server model state from persistent storage.
@ MESHX_NOT_SUPPORTED
Definition meshx_err.h:51
@ MESHX_INVALID_STATE
Definition meshx_err.h:49

◆ validate_server_status_opcode()

meshx_err_t meshXBaseLightServerModel::validate_server_status_opcode ( uint16_t opcode)
overridevirtual

Validate a light server status opcode.

This function determines whether the provided opcode corresponds to a status message in the Light 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< meshXBaseLightServerModel, meshx_light_server_send_params_t, meshx_light_server_restore_params_t, meshx_lighting_server_cb_param_t >.

330{
331 switch(opcode)
332 {
355 return MESHX_SUCCESS;
356 default:
357 return MESHX_FAIL;
358 }
359}
#define MESHX_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS
Definition meshx_ble_mesh_cmn_def.h:421
#define MESHX_MODEL_OP_LIGHT_LC_PROPERTY_STATUS
Definition meshx_ble_mesh_cmn_def.h:494
#define MESHX_MODEL_OP_LIGHT_CTL_STATUS
Definition meshx_ble_mesh_cmn_def.h:418
#define MESHX_MODEL_OP_LIGHT_LIGHTNESS_STATUS
Definition meshx_ble_mesh_cmn_def.h:396
#define MESHX_MODEL_OP_LIGHT_LIGHTNESS_LAST_STATUS
Definition meshx_ble_mesh_cmn_def.h:402
#define MESHX_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS
Definition meshx_ble_mesh_cmn_def.h:468
#define MESHX_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS
Definition meshx_ble_mesh_cmn_def.h:490
#define MESHX_MODEL_OP_LIGHT_XYL_RANGE_STATUS
Definition meshx_ble_mesh_cmn_def.h:470
#define MESHX_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS
Definition meshx_ble_mesh_cmn_def.h:406
#define MESHX_MODEL_OP_LIGHT_HSL_RANGE_STATUS
Definition meshx_ble_mesh_cmn_def.h:452
#define MESHX_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS
Definition meshx_ble_mesh_cmn_def.h:426
#define MESHX_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS
Definition meshx_ble_mesh_cmn_def.h:424
#define MESHX_MODEL_OP_LIGHT_LC_OM_STATUS
Definition meshx_ble_mesh_cmn_def.h:486
#define MESHX_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS
Definition meshx_ble_mesh_cmn_def.h:450
#define MESHX_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS
Definition meshx_ble_mesh_cmn_def.h:400
#define MESHX_MODEL_OP_LIGHT_XYL_TARGET_STATUS
Definition meshx_ble_mesh_cmn_def.h:466
#define MESHX_MODEL_OP_LIGHT_HSL_STATUS
Definition meshx_ble_mesh_cmn_def.h:446
#define MESHX_MODEL_OP_LIGHT_HSL_HUE_STATUS
Definition meshx_ble_mesh_cmn_def.h:439
#define MESHX_MODEL_OP_LIGHT_LC_MODE_STATUS
Definition meshx_ble_mesh_cmn_def.h:482
#define MESHX_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS
Definition meshx_ble_mesh_cmn_def.h:404
#define MESHX_MODEL_OP_LIGHT_XYL_STATUS
Definition meshx_ble_mesh_cmn_def.h:464
#define MESHX_MODEL_OP_LIGHT_HSL_SATURATION_STATUS
Definition meshx_ble_mesh_cmn_def.h:443
@ MESHX_FAIL
Definition meshx_err.h:45

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