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

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

#include <meshx_base_model_generic.hpp>

Inheritance diagram for meshXBaseGenericClientModel:
meshXBaseClientModel< meshXBaseGenericClientModel, meshx_gen_client_send_params_t, meshx_gen_cli_cb_param_t > meshXBaseModel< meshx_gen_client_send_params_t >

Public Member Functions

meshx_err_t plat_model_init (void) override
 Initialization function for the Generic OnOff Client model.
meshx_err_t validate_client_model_id (uint32_t model_id) override
 Validates if the given model ID corresponds to a supported Generic Client model.
meshx_err_t plat_send_msg (meshx_gen_client_send_params_t *params) override
 Send a message using the generic client model.
 meshXBaseGenericClientModel ()=delete
 meshXBaseGenericClientModel (uint32_t model_id, meshx_ptr_t p_plat_model, const control_msg_cb &from_ble_cb)
 Constructor for the meshXBaseGenericClientModel class.
virtual ~meshXBaseGenericClientModel ()=default
Public Member Functions inherited from meshXBaseClientModel< meshXBaseGenericClientModel, meshx_gen_client_send_params_t, meshx_gen_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_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_gen_client_txcm_fn_model_send (meshx_gen_client_msg_ctx_t *msg_param, size_t msg_param_len)
 Send a message using the generic client model.

Additional Inherited Members

Static Protected Member Functions inherited from meshXBaseClientModel< meshXBaseGenericClientModel, meshx_gen_client_send_params_t, meshx_gen_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_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< meshXBaseGenericClientModel, meshx_gen_client_send_params_t, meshx_gen_cli_cb_param_t >
meshx_ptr_t p_plat_model
Protected Attributes inherited from meshXBaseModel< meshx_gen_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< meshXBaseGenericClientModel, meshx_gen_client_send_params_t, meshx_gen_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 Generic BLE mesh models.

This class provides a concrete implementation of the template-based meshXBaseClientModel specifically designed for Generic BLE mesh client 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 meshXBaseClientModel
  • Provides Generic-specific opcode validation and message handling
  • Implements platform-specific message sending via TXCM integration
  • 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 SET/GET operations
  • Generic Level SET/GET operations
  • Generic Power Level operations
  • Generic Battery status operations
  • Generic Location operations
  • Property-based operations (Manufacturer, Admin, User)
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_cli_cb_param_t for callback parameter structure.
meshx_gen_client_send_params_t for send parameter structure.

Constructor & Destructor Documentation

◆ meshXBaseGenericClientModel() [1/2]

meshXBaseGenericClientModel::meshXBaseGenericClientModel ( )
delete

◆ meshXBaseGenericClientModel() [2/2]

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

Constructor for the meshXBaseGenericClientModel class.

Parameters
[in]model_idThe model ID associated with the generic client model
[in]p_plat_modelPointer to the platform model instance
[in]from_ble_cbThe control task message handle associated with the generic client model
210{
212 {
213 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Invalid model_id: %08" PRIx32, model_id);
215 return;
216 }
217
219 if (get_status() != MESHX_SUCCESS)
220 {
221 MESHX_LOGE(MODULE_ID_COMMON, "plat_model_init failed");
222 return;
223 }
224}
meshx_err_t validate_client_model_id(uint32_t model_id) override
Validates if the given model ID corresponds to a supported Generic Client model.
Definition meshx_base_model_generic.cpp:65
meshx_err_t plat_model_init(void) override
Initialization function for the Generic OnOff Client model.
Definition meshx_base_model_generic.cpp:238
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

◆ ~meshXBaseGenericClientModel()

virtual meshXBaseGenericClientModel::~meshXBaseGenericClientModel ( )
virtualdefault

Member Function Documentation

◆ meshx_gen_client_txcm_fn_model_send()

meshx_err_t meshXBaseGenericClientModel::meshx_gen_client_txcm_fn_model_send ( meshx_gen_client_msg_ctx_t * msg_param,
size_t msg_param_len )
static

Send a message using the generic client model.

This function sends a message from a Generic 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.
182{
183 if(msg_param == nullptr || msg_param_len != sizeof(meshx_gen_client_msg_ctx_t))
184 {
185 return MESHX_INVALID_ARG;
186 }
187
189 msg_param->model,
190 &msg_param->state,
191 msg_param->opcode,
192 msg_param->addr,
193 msg_param->net_idx,
194 msg_param->app_idx,
195 (meshx_is_get_req_opcode(msg_param->opcode) == MESHX_SUCCESS)
196 );
197}
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_generic.cpp:144
struct meshx_gen_client_msg_ctx { meshx_ptr_t model; uint16_t opcode; uint16_t addr; uint16_t net_idx; uint16_t app_idx; meshx_gen_cli_set_t state; } meshx_gen_client_msg_ctx_t
Definition meshx_base_model_generic.hpp:58
meshx_err_t meshx_plat_gen_cli_send_msg(meshx_ptr_t p_model, meshx_gen_cli_set_t *p_set, uint16_t opcode, uint16_t addr, uint16_t net_idx, uint16_t app_idx, bool is_get_opcode)
Sends a Generic Client message over BLE Mesh.

◆ meshx_is_get_req_opcode()

meshx_err_t meshXBaseGenericClientModel::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 generic client model.

Parameters
[in]opcodeOpcode to check.
Returns
MESHX_SUCCESS if the opcode is a GET request opcode, MESHX_FAIL otherwise.
145{
146 switch(opcode)
147 {
162 return MESHX_SUCCESS;
163 default:
164 return MESHX_FAIL;
165 }
166}
#define MESHX_MODEL_OP_GEN_USER_PROPERTIES_GET
Definition meshx_ble_mesh_cmn_def.h:321
#define MESHX_MODEL_OP_GEN_MANUFACTURER_PROPERTIES_GET
Definition meshx_ble_mesh_cmn_def.h:305
#define MESHX_MODEL_OP_GEN_BATTERY_GET
Definition meshx_ble_mesh_cmn_def.h:289
#define MESHX_MODEL_OP_GEN_CLIENT_PROPERTIES_GET
Definition meshx_ble_mesh_cmn_def.h:329
#define MESHX_MODEL_OP_GEN_LOC_LOCAL_GET
Definition meshx_ble_mesh_cmn_def.h:295
#define MESHX_MODEL_OP_GEN_MANUFACTURER_PROPERTY_GET
Definition meshx_ble_mesh_cmn_def.h:307
#define MESHX_MODEL_OP_GEN_POWER_LEVEL_GET
Definition meshx_ble_mesh_cmn_def.h:271
#define MESHX_MODEL_OP_GEN_LEVEL_GET
Definition meshx_ble_mesh_cmn_def.h:247
#define MESHX_MODEL_OP_GEN_USER_PROPERTY_GET
Definition meshx_ble_mesh_cmn_def.h:323
#define MESHX_MODEL_OP_GEN_ADMIN_PROPERTIES_GET
Definition meshx_ble_mesh_cmn_def.h:313
#define MESHX_MODEL_OP_GEN_ONOFF_GET
Definition meshx_ble_mesh_cmn_def.h:241
#define MESHX_MODEL_OP_GEN_ADMIN_PROPERTY_GET
Definition meshx_ble_mesh_cmn_def.h:315
#define MESHX_MODEL_OP_GEN_LOC_GLOBAL_GET
Definition meshx_ble_mesh_cmn_def.h:293
#define MESHX_MODEL_OP_GEN_ONPOWERUP_GET
Definition meshx_ble_mesh_cmn_def.h:263
@ MESHX_FAIL
Definition meshx_err.h:45

◆ meshx_is_unack_opcode()

meshx_err_t meshXBaseGenericClientModel::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 Generic 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_GEN_ONOFF_SET_UNACK: Generic OnOff Set Unacknowledged
  • MESHX_MODEL_OP_GEN_LEVEL_SET_UNACK: Generic Level Set Unacknowledged
  • MESHX_MODEL_OP_GEN_ONPOWERUP_SET_UNACK: Generic OnPowerUp Set Unacknowledged
  • MESHX_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK: Generic Power Level Set Unacknowledged
  • MESHX_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK: Generic Location Global Set Unacknowledged
  • MESHX_MODEL_OP_GEN_LOC_LOCAL_SET_UNACK: Generic Location Local Set Unacknowledged
  • MESHX_MODEL_OP_GEN_MANUFACTURER_PROPERTY_SET_UNACK: Manufacturer Property Set Unacknowledged
  • MESHX_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK: Admin Property Set Unacknowledged
  • MESHX_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK: User 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.
114{
115 switch(opcode)
116 {
126 return MESHX_SUCCESS;
127 default:
128 return MESHX_FAIL;
129 }
130}
#define MESHX_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:325
#define MESHX_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:317
#define MESHX_MODEL_OP_GEN_ONOFF_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:243
#define MESHX_MODEL_OP_GEN_MANUFACTURER_PROPERTY_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:309
#define MESHX_MODEL_OP_GEN_LEVEL_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:249
#define MESHX_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:273
#define MESHX_MODEL_OP_GEN_LOC_LOCAL_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:302
#define MESHX_MODEL_OP_GEN_ONPOWERUP_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:268
#define MESHX_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK
Definition meshx_ble_mesh_cmn_def.h:300

◆ plat_model_init()

meshx_err_t meshXBaseGenericClientModel::plat_model_init ( void )
overridevirtual

Initialization function for the Generic OnOff Client model.

This function is responsible for initializing the Generic OnOff 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_client_send_params_t >.

239{
241 std::call_once(plat_client_init_flag, [&]() {
243 if (err == MESHX_SUCCESS) {
245 }
246 });
247
248 return err;
249}
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_cli_init(void)
Initialize the meshxuction generic client.
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 meshXBaseGenericClientModel::plat_send_msg ( meshx_gen_client_send_params_t * params)
overridevirtual

Send a message using the generic client model.

This function sends a message from a generic 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_client_send_params_t >.

264{
265 if (!params || !params->model || !params->state)
266 {
267 return MESHX_INVALID_ARG;
268 }
269
271 bool is_unack = meshx_is_unack_opcode(params->opcode) == MESHX_SUCCESS;
272 /* Broadcast / Multicast will not be sending an ACK. Hence, it is not required to queue */
273 meshx_txcm_sig_t req_type = (is_unack || (MESHX_ADDR_IS_UNICAST(params->addr) == false)) ?
275
277
278 send_msg.model = params->model;
279 send_msg.opcode = params->opcode;
280 send_msg.addr = params->addr;
281 send_msg.net_idx = params->net_idx;
282 send_msg.app_idx = params->app_idx;
283
284 memcpy(&send_msg.state, params->state, sizeof(send_msg.state));
285
287 req_type,
288 send_msg.addr,
289 &send_msg,
290 sizeof(send_msg),
292 );
293 if(err)
294 {
295 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Failed to send message: %p", (meshx_ptr_t) err);
296 }
297 return err;
298}
static meshx_err_t meshx_gen_client_txcm_fn_model_send(meshx_gen_client_msg_ctx_t *msg_param, size_t msg_param_len)
Send a message using the generic client model.
Definition meshx_base_model_generic.cpp:181
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_generic.cpp:113
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_gen_cli.h:299
uint16_t net_idx
Definition meshx_ble_mesh_gen_cli.h:300
meshx_gen_cli_set_t * state
Definition meshx_ble_mesh_gen_cli.h:302
meshx_ptr_t model
Definition meshx_ble_mesh_gen_cli.h:297
uint16_t opcode
Definition meshx_ble_mesh_gen_cli.h:298
uint16_t app_idx
Definition meshx_ble_mesh_gen_cli.h:301

◆ validate_client_model_id()

meshx_err_t meshXBaseGenericClientModel::validate_client_model_id ( uint32_t model_id)
overridevirtual

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

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

Supported Generic Client Model IDs:

  • MESHX_MODEL_ID_GEN_ONOFF_CLI: Generic OnOff Client
  • MESHX_MODEL_ID_GEN_LEVEL_CLI: Generic Level Client
  • MESHX_MODEL_ID_GEN_BATTERY_CLI: Generic Battery Client
  • MESHX_MODEL_ID_GEN_LOCATION_CLI: Generic Location Client
  • MESHX_MODEL_ID_GEN_POWER_ONOFF_CLI: Generic Power OnOff Client
  • MESHX_MODEL_ID_GEN_POWER_LEVEL_CLI: Generic Power Level Client
Parameters
[in]model_idThe 32-bit model ID to validate against supported Generic 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 Generic models. Other client types (Lighting, Sensor, etc.) will have their own implementations with different supported model IDs.

Implements meshXBaseClientModel< meshXBaseGenericClientModel, meshx_gen_client_send_params_t, meshx_gen_cli_cb_param_t >.

66{
67 switch (model_id)
68 {
75 // Add more Generic client model IDs as needed
76 return MESHX_SUCCESS;
77 default:
78 MESHX_LOGW(MODULE_ID_MODEL_CLIENT, "Invalid Generic client model ID: %08" PRIx32, model_id);
79 return MESHX_FAIL;
80 }
81}
#define MESHX_MODEL_ID_GEN_POWER_ONOFF_CLI
Definition meshx_ble_mesh_cmn_def.h:78
#define MESHX_MODEL_ID_GEN_BATTERY_CLI
Definition meshx_ble_mesh_cmn_def.h:83
#define MESHX_MODEL_ID_GEN_ONOFF_CLI
Definition meshx_ble_mesh_cmn_def.h:71
#define MESHX_MODEL_ID_GEN_LEVEL_CLI
Definition meshx_ble_mesh_cmn_def.h:73
#define MESHX_MODEL_ID_GEN_POWER_LEVEL_CLI
Definition meshx_ble_mesh_cmn_def.h:81
#define MESHX_MODEL_ID_GEN_LOCATION_CLI
Definition meshx_ble_mesh_cmn_def.h:86
#define MESHX_LOGW(module_id, format,...)
Definition meshx_log.h:120

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