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

Template specialization of meshXBaseClientModel for Light BLE mesh models. More...

#include <meshx_base_model_light.hpp>

Inheritance diagram for meshXBaseLightClientModel:
meshXBaseClientModel< meshXBaseLightClientModel, meshx_gen_light_client_send_params_t, meshx_gen_light_cli_cb_param_t > meshXBaseModel< meshx_gen_light_client_send_params_t >

Public Member Functions

meshx_err_t plat_model_init (void) override
 Initialization function for the Light Client model.
meshx_err_t validate_client_model_id (uint32_t model_id) override
 Validates if the given model ID corresponds to a supported Light Client model.
meshx_err_t plat_send_msg (meshx_gen_light_client_send_params_t *params) override
 Send a message using the light client model.
 meshXBaseLightClientModel ()=delete
 meshXBaseLightClientModel (uint32_t model_id, meshx_ptr_t p_plat_model, const control_msg_cb &from_ble_cb)
 Constructor for the meshXBaseLightClientModel class.
virtual ~meshXBaseLightClientModel ()=default
Public Member Functions inherited from meshXBaseClientModel< meshXBaseLightClientModel, meshx_gen_light_client_send_params_t, meshx_gen_light_cli_cb_param_t >
 meshXBaseClientModel ()=delete
 ~meshXBaseClientModel ()=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_light_client_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.

Static Public Member Functions

static meshx_err_t meshx_is_unack_opcode (uint32_t opcode)
 Validates if a given opcode corresponds to an unacknowledged (SET_UNACK) message.
static meshx_err_t meshx_is_get_req_opcode (uint16_t opcode)
 Checks if a given opcode is a GET request opcode.
static meshx_err_t meshx_light_client_txcm_fn_model_send (meshx_light_client_msg_ctx_t *msg_param, size_t msg_param_len)
 Send a message using the light client model.

Additional Inherited Members

Static Protected Member Functions inherited from meshXBaseClientModel< meshXBaseLightClientModel, meshx_gen_light_client_send_params_t, meshx_gen_light_cli_cb_param_t >
static constexpr const char * get_client_type_name ()
static meshx_err_t base_txcm_handle_ack (uint16_t src_addr)
 Resend an acknowledgement message for the given source address.
static meshx_err_t base_txcm_handle_resend (uint16_t model_id, const meshx_gen_light_cli_cb_param_t *param)
 Resend a message for the given model ID and parameter.
static meshx_err_t base_from_ble_msg_handle (dev_struct_t *pdev, control_task_msg_evt_t evt, meshx_ptr_t params)
 Template-based static message handler for BLE Mesh Generic Client models.
static meshx_err_t base_handle_txcm_msg (dev_struct_t *pdev, control_task_msg_evt_t evt, base_client_model_resend_ctx_t *param)
 Template-based TXCM (Transmission Control Module) message handler for timeout scenarios.
Protected Attributes inherited from meshXBaseClientModel< meshXBaseLightClientModel, meshx_gen_light_client_send_params_t, meshx_gen_light_cli_cb_param_t >
meshx_ptr_t p_plat_model
Protected Attributes inherited from meshXBaseModel< meshx_gen_light_client_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 meshXBaseClientModel< meshXBaseLightClientModel, meshx_gen_light_client_send_params_t, meshx_gen_light_cli_cb_param_t >
static std::once_flag plat_client_init_flag
static std::forward_list< base_client_model_cb_reg_tbase_client_model_cb_list

Detailed Description

Template specialization of meshXBaseClientModel for Light BLE mesh models.

This class provides a concrete implementation of the template-based meshXBaseClientModel specifically designed for Light BLE mesh client 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 meshXBaseClientModel
  • Provides Light-specific opcode validation and message handling
  • Implements platform-specific message sending via TXCM integration
  • Supports all Light model types (Lightness, CTL, HSL, XYL, LC)
  • Enhanced error handling and debugging with template type identification
  • Static wrapper functions for C-style callback compatibility

Template Parameters:

Supported Operations:

  • Light Lightness SET/GET operations
  • Light CTL SET/GET operations
  • Light HSL SET/GET operations
  • Light XYL SET/GET operations
  • Light LC (Light Control) operations
Note
This class uses private inheritance to maintain encapsulation while providing access to base functionality through friendship.
See also
meshXBaseClientModel for base template functionality.
meshx_gen_light_cli_cb_param_t for callback parameter structure.
meshx_gen_light_client_send_params_t for send parameter structure.

Constructor & Destructor Documentation

◆ meshXBaseLightClientModel() [1/2]

meshXBaseLightClientModel::meshXBaseLightClientModel ( )
delete

◆ meshXBaseLightClientModel() [2/2]

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

Constructor for the meshXBaseLightClientModel class.

Parameters
[in]model_idThe model ID for the light client model
[in]p_plat_modelPointer to the platform-specific model structure.
[in]from_ble_cbControl task message callback function
188{
190 {
191 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Invalid model_id: %08" PRIx32, model_id);
193 return;
194 }
195
197 if (get_status() != MESHX_SUCCESS)
198 {
199 MESHX_LOGE(MODULE_ID_COMMON, "plat_model_init failed");
200 return;
201 }
202}
meshx_err_t plat_model_init(void) override
Initialization function for the Light Client model.
Definition meshx_base_model_light.cpp:214
meshx_err_t validate_client_model_id(uint32_t model_id) override
Validates if the given model ID corresponds to a supported Light Client model.
Definition meshx_base_model_light.cpp:61
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
@ 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_COMMON
Definition module_id.h:36
@ MODULE_ID_MODEL_CLIENT
Definition module_id.h:35

◆ ~meshXBaseLightClientModel()

virtual meshXBaseLightClientModel::~meshXBaseLightClientModel ( )
virtualdefault

Member Function Documentation

◆ meshx_is_get_req_opcode()

meshx_err_t meshXBaseLightClientModel::meshx_is_get_req_opcode ( uint16_t opcode)
static

Checks if a given opcode is a GET request opcode.

This function checks if a given opcode is a GET request opcode for the light client model.

Parameters
[in]opcodeOpcode to check.
Returns
MESHX_SUCCESS if the opcode is a GET request opcode, MESHX_FAIL otherwise.
134{
135 switch(opcode)
136 {
145 return MESHX_SUCCESS;
146 default:
147 return MESHX_FAIL;
148 }
149}
#define MESHX_MODEL_OP_LIGHT_LC_PROPERTY_GET
Definition meshx_ble_mesh_cmn_def.h:491
#define MESHX_MODEL_OP_LIGHT_LC_OM_GET
Definition meshx_ble_mesh_cmn_def.h:483
#define MESHX_MODEL_OP_LIGHT_LC_MODE_GET
Definition meshx_ble_mesh_cmn_def.h:479
#define MESHX_MODEL_OP_LIGHT_HSL_GET
Definition meshx_ble_mesh_cmn_def.h:435
#define MESHX_MODEL_OP_LIGHT_XYL_GET
Definition meshx_ble_mesh_cmn_def.h:461
#define MESHX_MODEL_OP_LIGHT_CTL_GET
Definition meshx_ble_mesh_cmn_def.h:415
#define MESHX_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_GET
Definition meshx_ble_mesh_cmn_def.h:487
#define MESHX_MODEL_OP_LIGHT_LIGHTNESS_GET
Definition meshx_ble_mesh_cmn_def.h:393
@ MESHX_FAIL
Definition meshx_err.h:45

◆ meshx_is_unack_opcode()

meshx_err_t meshXBaseLightClientModel::meshx_is_unack_opcode ( uint32_t opcode)
static

Validates if a given opcode corresponds to an unacknowledged (SET_UNACK) message.

This function performs opcode validation to determine if the specified opcode represents a SET_UNACK operation for Light BLE mesh models. Unacknowledged messages do not require a response from the server, making them suitable for broadcast operations and scenarios where reliability is less critical than performance.

Supported Unacknowledged Opcodes:

  • MESHX_MODEL_OP_LIGHT_LIGHTNESS_SET_UNACK: Light Lightness Set Unacknowledged
  • MESHX_MODEL_OP_LIGHT_CTL_SET_UNACK: Light CTL Set Unacknowledged
  • MESHX_MODEL_OP_LIGHT_HSL_SET_UNACK: Light HSL Set Unacknowledged
  • MESHX_MODEL_OP_LIGHT_XYL_SET_UNACK: Light XYL Set Unacknowledged
  • MESHX_MODEL_OP_LIGHT_LC_MODE_SET_UNACK: Light LC Mode Set Unacknowledged
  • MESHX_MODEL_OP_LIGHT_LC_OM_SET_UNACK: Light LC Occupancy Mode Set Unacknowledged
  • MESHX_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET_UNACK: Light LC Light OnOff Set Unacknowledged
  • MESHX_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK: Light LC Property Set Unacknowledged
Parameters
[in]opcodeThe 32-bit BLE mesh model opcode to validate.
Return values
MESHX_SUCCESSThe opcode is a valid unacknowledged SET operation.
MESHX_FAILThe opcode is not an unacknowledged SET operation.
Note
This function is used internally for transmission control and reliability decisions.
Unacknowledged messages are typically used for broadcast/multicast scenarios.
See also
meshx_is_get_req_opcode() for GET request validation.
106{
107 switch(opcode)
108 {
117 return MESHX_SUCCESS;
118 default:
119 return MESHX_FAIL;
120 }
121}
#define MESHX_MODEL_OP_LIGHT_XYL_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:463
#define MESHX_MODEL_OP_LIGHT_LIGHTNESS_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:395
#define MESHX_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:489
#define MESHX_MODEL_OP_LIGHT_LC_MODE_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:481
#define MESHX_MODEL_OP_LIGHT_HSL_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:445
#define MESHX_MODEL_OP_LIGHT_CTL_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:417
#define MESHX_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:493
#define MESHX_MODEL_OP_LIGHT_LC_OM_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:485

◆ meshx_light_client_txcm_fn_model_send()

meshx_err_t meshXBaseLightClientModel::meshx_light_client_txcm_fn_model_send ( meshx_light_client_msg_ctx_t * msg_param,
size_t msg_param_len )
static

Send a message using the light client model.

This function sends a message from a Light Client model to a specified address within the BLE Mesh network, using the provided opcode and parameters.

Parameters
[in]msg_paramPointer to the message parameters structure.
[in]msg_param_lenLength of the message parameters structure in bytes.
Returns
meshx_err_t Result of the operation. Returns MESHX_OK on success or an error code on failure.
163{
164 if(msg_param == nullptr || msg_param_len != sizeof(meshx_light_client_msg_ctx_t))
165 {
166 return MESHX_INVALID_ARG;
167 }
168
170 msg_param->model,
171 &msg_param->state,
172 msg_param->opcode,
173 msg_param->addr,
174 msg_param->net_idx,
175 msg_param->app_idx,
176 (meshx_is_get_req_opcode(msg_param->opcode) == MESHX_SUCCESS)
177 );
178}
static meshx_err_t meshx_is_get_req_opcode(uint16_t opcode)
Checks if a given opcode is a GET request opcode.
Definition meshx_base_model_light.cpp:133
struct meshx_light_client_msg_ctx { meshx_ptr_t model; uint16_t opcode; uint16_t addr; uint16_t net_idx; uint16_t app_idx; meshx_light_client_set_state_t state; } meshx_light_client_msg_ctx_t
Definition meshx_base_model_light.hpp:59
meshx_err_t meshx_plat_light_client_send_msg(meshx_ptr_t p_model, meshx_light_client_set_state_t *p_set, uint16_t opcode, uint16_t addr, uint16_t net_idx, uint16_t app_idx, bool is_get_opcode)
Sends a Light Client message over BLE Mesh.

◆ plat_model_init()

meshx_err_t meshXBaseLightClientModel::plat_model_init ( void )
overridevirtual

Initialization function for the Light Client model.

This function is responsible for initializing the Light Client 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_light_client_send_params_t >.

215{
217 std::call_once(plat_client_init_flag, [&]() {
219 if (err == MESHX_SUCCESS) {
221 }
222 });
223
224 return err;
225}
static meshx_err_t base_handle_txcm_msg(dev_struct_t *pdev, control_task_msg_evt_t evt, base_client_model_resend_ctx_t *param)
Definition meshx_base_model_class.cpp:469
meshx_err_t meshx_plat_gen_light_client_init(void)
Initialize the Generic Light Client Model. This function sets up the necessary parameters and resourc...
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
control_task_msg_handle_t meshx_txcm_cb_t
Definition meshx_txcm.h:49
meshx_err_t meshx_txcm_event_cb_reg(meshx_txcm_cb_t event_cb)
Registers a callback function for handling Tx Control module events.
Definition meshx_txcm.c:734

◆ plat_send_msg()

meshx_err_t meshXBaseLightClientModel::plat_send_msg ( meshx_gen_light_client_send_params_t * params)
overridevirtual

Send a message using the light client model.

This function sends a message from a light client model to a specified address within the BLE Mesh network, using the provided opcode and parameters.

Parameters
[in]paramsPointer to the structure containing the message parameters to set.
Returns
meshx_err_t containing the result of the send operation. Returns MESHX_OK on success or an error code on failure.

Implements meshXBaseModel< meshx_gen_light_client_send_params_t >.

238{
239 if (!params || !params->model || !params->state)
240 {
241 return MESHX_INVALID_ARG;
242 }
243
245 bool is_unack = meshx_is_unack_opcode(params->opcode) == MESHX_SUCCESS;
246 /* Broadcast / Multicast will not be sending an ACK. Hence, it is not required to queue */
247 meshx_txcm_sig_t req_type = (is_unack || (MESHX_ADDR_IS_UNICAST(params->addr) == false)) ?
249
251
252 send_msg.model = params->model;
253 send_msg.opcode = params->opcode;
254 send_msg.addr = params->addr;
255 send_msg.net_idx = params->net_idx;
256 send_msg.app_idx = params->app_idx;
257
258 memcpy(&send_msg.state, params->state, sizeof(send_msg.state));
259
261 req_type,
262 send_msg.addr,
263 &send_msg,
264 sizeof(send_msg),
266 );
267 if(err)
268 {
269 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Failed to send message: %p", (meshx_ptr_t) err);
270 }
271 return err;
272}
static meshx_err_t meshx_is_unack_opcode(uint32_t opcode)
Validates if a given opcode corresponds to an unacknowledged (SET_UNACK) message.
Definition meshx_base_model_light.cpp:105
static meshx_err_t meshx_light_client_txcm_fn_model_send(meshx_light_client_msg_ctx_t *msg_param, size_t msg_param_len)
Send a message using the light client model.
Definition meshx_base_model_light.cpp:162
void * meshx_ptr_t
Definition meshx_ble_mesh_cmn_def.h:636
#define MESHX_ADDR_IS_UNICAST(_addr)
Definition meshx_ble_mesh_cmn_def.h:25
meshx_err_t meshx_txcm_request_send(meshx_txcm_sig_t request_type, uint16_t dest_addr, meshx_cptr_t msg_param, uint16_t msg_param_len, meshx_txcm_fn_model_send_t send_fn)
Sends a request to the Tx Control module.
Definition meshx_txcm.c:672
meshx_txcm_sig_t
Enumeration of signal types for the Tx Control Module.
Definition meshx_txcm.h:57
@ MESHX_TXCM_SIG_ENQ_SEND
Definition meshx_txcm.h:58
@ MESHX_TXCM_SIG_DIRECT_SEND
Definition meshx_txcm.h:59
meshx_err_t(* meshx_txcm_fn_model_send_t)(meshx_cptr_t msg_param, size_t msg_param_len)
Function pointer the Model client layer needs to provide for the msg to be sent for both MESHX_TXCM_S...
Definition meshx_txcm.h:94
uint16_t addr
Definition meshx_ble_mesh_light_cli.h:527
meshx_ptr_t model
Definition meshx_ble_mesh_light_cli.h:525
uint16_t net_idx
Definition meshx_ble_mesh_light_cli.h:528
uint16_t app_idx
Definition meshx_ble_mesh_light_cli.h:529
uint16_t opcode
Definition meshx_ble_mesh_light_cli.h:526
meshx_light_client_set_state_t * state
Definition meshx_ble_mesh_light_cli.h:530

◆ validate_client_model_id()

meshx_err_t meshXBaseLightClientModel::validate_client_model_id ( uint32_t model_id)
overridevirtual

Validates if the given model ID corresponds to a supported Light Client model.

This function performs validation of model IDs to ensure they correspond to supported Light Client models in the MeshX BLE mesh framework. This is the Light-specific implementation of the virtual validate_client_model_id function.

Supported Light Client Model IDs:

  • MESHX_MODEL_ID_LIGHT_LIGHTNESS_CLI: Light Lightness Client
  • MESHX_MODEL_ID_LIGHT_CTL_CLI: Light CTL Client
  • MESHX_MODEL_ID_LIGHT_HSL_CLI: Light HSL Client
  • MESHX_MODEL_ID_LIGHT_XYL_CLI: Light XYL Client
  • MESHX_MODEL_ID_LIGHT_LC_CLI: Light LC (Light Control) Client
Parameters
[in]model_idThe 32-bit model ID to validate against supported Light client models.
Return values
MESHX_SUCCESSThe model ID is valid and supported.
MESHX_FAILThe model ID is not supported or invalid.
Note
This function is specific to Light models. Other client types (Generic, Sensor, etc.) will have their own implementations with different supported model IDs.

Implements meshXBaseClientModel< meshXBaseLightClientModel, meshx_gen_light_client_send_params_t, meshx_gen_light_cli_cb_param_t >.

62{
63 switch (model_id)
64 {
70 // Add more Light client model IDs as needed
71 return MESHX_SUCCESS;
72 default:
73 MESHX_LOGW(MODULE_ID_MODEL_CLIENT, "Invalid Light client model ID: %08" PRIx32, model_id);
74 return MESHX_FAIL;
75 }
76}
#define MESHX_MODEL_ID_LIGHT_CTL_CLI
Definition meshx_ble_mesh_cmn_def.h:109
#define MESHX_MODEL_ID_LIGHT_XYL_CLI
Definition meshx_ble_mesh_cmn_def.h:118
#define MESHX_MODEL_ID_LIGHT_LC_CLI
Definition meshx_ble_mesh_cmn_def.h:121
#define MESHX_MODEL_ID_LIGHT_HSL_CLI
Definition meshx_ble_mesh_cmn_def.h:113
#define MESHX_MODEL_ID_LIGHT_LIGHTNESS_CLI
Definition meshx_ble_mesh_cmn_def.h:106
#define MESHX_LOGW(module_id, format,...)
Definition meshx_log.h:120

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