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
meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t > Class Template Referenceabstract

#include <meshx_base_model_class.hpp>

Inheritance diagram for meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >:
meshXBaseModel< ble_mesh_send_msg_params_t >

Public Member Functions

 meshXBaseClientModel ()=delete
 ~meshXBaseClientModel ()=default
 meshXBaseClientModel (uint32_t model_id, meshx_ptr_t p_plat_model, const control_msg_cb &from_ble_cb)
 Constructor for the meshXBaseClientModel template class.
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< ble_mesh_send_msg_params_t >
meshx_err_t from_ble_reg_cb (void) const
 Register BLE message callback for this model.
virtual meshx_err_t plat_model_init (void)=0
 Initialize platform model.
virtual meshx_err_t plat_send_msg (ble_mesh_send_msg_params_t *params)=0
 Send message through the 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.
 meshXBaseModel ()=delete
virtual ~meshXBaseModel ()
 Virtual destructor for meshXBaseModel.

Protected Member Functions

virtual meshx_err_t validate_client_model_id (uint32_t model_id)=0

Static Protected Member Functions

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 ble_mesh_plat_model_cb_params_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

meshx_ptr_t p_plat_model
Protected Attributes inherited from meshXBaseModel< ble_mesh_send_msg_params_t >
uint32_t model_id
meshXBaseModelType_t model_type
control_task_msg_handle_t from_ble_cb
meshx_err_t status = MESHX_SUCCESS

Static Protected Attributes

static std::once_flag plat_client_init_flag
static std::forward_list< base_client_model_cb_reg_tbase_client_model_cb_list

Private Types

using base_client_model_cb_reg_t
using base_client_model_resend_ctx_t

Member Typedef Documentation

◆ base_client_model_cb_reg_t

template<typename baseClientModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_model_cb_params_t>
using meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >::base_client_model_cb_reg_t
private
Initial value:
struct base_client_model_cb_reg
{
uint16_t model_id;
}
meshXBaseClientModel()=delete
meshx_ptr_t p_plat_model
Definition meshx_base_model_class.hpp:261
uint32_t model_id
Definition meshx_base_model_class.hpp:52
std::function< meshx_err_t(dev_struct_t *, control_task_msg_evt_t, meshx_ptr_t)> control_msg_cb
Definition meshx_base_model_class.hpp:32
void * meshx_ptr_t
Definition meshx_ble_mesh_cmn_def.h:636
249 {
250 uint16_t model_id; /**< Model ID associated with the registration. */
251 meshx_ptr_t p_plat_model; /**< Platform model pointer for instance verification. */
252 control_msg_cb cb; /**< Callback function associated with the registration. */
253 meshXBaseClientModel *instance; /**< Instance pointer for registration management. */
254 };
Definition meshx_base_model_class.hpp:244

◆ base_client_model_resend_ctx_t

template<typename baseClientModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_model_cb_params_t>
using meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >::base_client_model_resend_ctx_t
private
Initial value:
struct base_client_model_resend_ctx
{
uint16_t model_id;
ble_mesh_plat_model_cb_params_t param;
}
256 {
257 uint16_t model_id; /**< Model ID associated with the re-sending. */
258 ble_mesh_plat_model_cb_params_t param; /**< Params received from Platform callback */
259 };

Constructor & Destructor Documentation

◆ meshXBaseClientModel() [1/2]

template<typename baseClientModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_model_cb_params_t>
meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >::meshXBaseClientModel ( )
delete

◆ ~meshXBaseClientModel()

template<typename baseClientModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_model_cb_params_t>
meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >::~meshXBaseClientModel ( )
default

◆ meshXBaseClientModel() [2/2]

template<typename baseClientModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_model_cb_params_t>
meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >::meshXBaseClientModel ( uint32_t model_id,
meshx_ptr_t p_plat_model,
const control_msg_cb & from_ble_cb )

Constructor for the meshXBaseClientModel template class.

Parameters
[in]model_idThe unique 32-bit identifier of the Generic Client model.
[in]p_plat_modelPointer to the platform-specific model structure.
[in]from_ble_cbThe callback function to handle BLE mesh messages.
260{
262 // Validate model ID and callback - consistent with C implementation
263 if (!from_ble_cb)
264 {
265 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Invalid callback");
267 return;
268 }
269
271 MESHX_LOGD(MODULE_ID_MODEL_CLIENT, "First-time initialization for client template");
272 });
273
275 this->status = MESHX_SUCCESS;
276}
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.
Definition meshx_base_model_class.cpp:364
static std::once_flag plat_client_init_flag
Definition meshx_base_model_class.hpp:263
static std::forward_list< base_client_model_cb_reg_t > base_client_model_cb_list
Definition meshx_base_model_class.hpp:264
meshx_err_t status
Definition meshx_base_model_class.hpp:55
control_task_msg_handle_t from_ble_cb
Definition meshx_base_model_class.hpp:54
meshXBaseModel()=delete
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:114
#define MESHX_LOGD(module_id, format,...)
Definition meshx_log.h:132

Member Function Documentation

◆ base_from_ble_msg_handle()

template<typename baseClientModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_model_cb_params_t>
meshx_err_t meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >::base_from_ble_msg_handle ( dev_struct_t * pdev,
control_task_msg_evt_t evt,
meshx_ptr_t params )
staticprotected

Template-based static message handler for BLE Mesh Generic Client models.

This is the core static message handling function that processes incoming BLE mesh messages for all instances of a specific template instantiation. It provides a centralized dispatch mechanism with enhanced debugging, validation, and error handling.

Key Features:

  • Template-specific static dispatch (one handler per template instantiation)
  • Model ID validation against supported Generic Client models
  • Enhanced logging with template type identification
  • Timeout and error handling with automatic retry mechanism
  • ACK handling for reliable message delivery
  • Callback routing based on registered model IDs

Message Processing Flow:

  1. Validates input parameters and model ID
  2. Searches the template-specific callback list for matching model ID
  3. Handles timeout/error cases with retry mechanism via TXCM
  4. Processes successful messages and handles ACK
  5. Invokes the registered application callback
Template Parameters
baseClientModelDerived_tThe derived client model class type
ble_mesh_plat_model_cb_params_tPlatform-specific callback parameter type
ble_mesh_send_msg_params_tPlatform-specific send message parameter type
Parameters
[in]pdevPointer to the device structure associated with the BLE Mesh node. Must not be NULL.
[in]evtControl task message event type (typically contains model context).
[in]paramsPointer to platform-specific message parameters structure. Must not be NULL and contain valid model_id.
Return values
MESHX_SUCCESSMessage processed successfully by registered callback.
MESHX_INVALID_ARGInvalid parameters or unsupported model ID.
OtherError codes from callback execution or TXCM operations.
Note
This function is automatically registered as the message handler during construction.
Each template instantiation gets its own static instance of this function.
Enhanced with template type identification for improved debugging.
See also
base_txcm_handle_resend() for retry mechanism details.
base_txcm_handle_ack() for ACK processing details.
366{
367 if (pdev == nullptr || params == nullptr)
368 {
369 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Invalid parameters");
370 return MESHX_INVALID_ARG;
371 }
372
373 // Enhanced logging with template type identification
374 MESHX_LOGD(MODULE_ID_MODEL_CLIENT, "Handling message for model_id: %04x", (uint32_t)evt);
375
377 auto *param = static_cast<ble_mesh_plat_model_cb_params_t*>(params);
378 meshx_ptr_t plat_model = param->model.p_model;
379 bool cb_invoked = false;
380
381 for (auto &node : base_client_model_cb_list)
382 {
383 if ((uint16_t)evt == node.model_id)
384 {
385 /* Only invoke if the platform model matches this instance */
387 {
388 continue;
389 }
390
392 "op|src|dst:%04" PRIx32 "|%04x|%04x",
393 param->ctx.opcode, param->ctx.src_addr, param->ctx.dst_addr);
394
395 if (node.cb == nullptr)
396 {
397 MESHX_LOGW(MODULE_ID_MODEL_CLIENT, "Callback is NULL for model_id: %04x", node.model_id);
398 continue;
399 }
400
401 if (param->evt == static_cast<decltype(param->evt)>(meshx_base_cli_evt::MESHX_BASE_CLI_TIMEOUT) || param->err_code != MESHX_SUCCESS)
402 {
403 MESHX_LOGW(MODULE_ID_MODEL_CLIENT, "Message timeout or error, retrying...");
405 if (err != MESHX_SUCCESS)
406 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Resend failed: %d", err);
407 }
408 else
409 {
410 err = base_txcm_handle_ack(param->ctx.src_addr);
411 if (err != MESHX_SUCCESS)
412 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Ack failed: %d", err);
413
414 err = node.cb(pdev, evt, param);
415 }
416
417 cb_invoked = true;
418 }
419 }
420
421 if (!cb_invoked)
422 MESHX_LOGW(MODULE_ID_MODEL_CLIENT, "No registered client handled model_id=%04" PRIx32, (uint32_t)evt);
423
424 return err;
425}
static meshx_err_t base_txcm_handle_resend(uint16_t model_id, const ble_mesh_plat_model_cb_params_t *param)
Resend a message for the given model ID and parameter.
Definition meshx_base_model_class.cpp:305
static meshx_err_t base_txcm_handle_ack(uint16_t src_addr)
Resend an acknowledgement message for the given source address.
Definition meshx_base_model_class.cpp:288
#define MESHX_LOGW(module_id, format,...)
Definition meshx_log.h:120

◆ base_handle_txcm_msg()

template<typename baseClientModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_model_cb_params_t>
meshx_err_t meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >::base_handle_txcm_msg ( dev_struct_t * pdev,
control_task_msg_evt_t evt,
base_client_model_resend_ctx_t * param )
staticprotected

Template-based TXCM (Transmission Control Module) message handler for timeout scenarios.

This function handles control task messages from the Transmission Control Module (TXCM), specifically for timeout and resend scenarios in Generic Client models. It processes timeout events by setting appropriate error codes and invoking registered callbacks to notify the application layer of transmission failures.

Key Responsibilities:

  • Processes TXCM timeout notifications for failed message transmissions
  • Sets timeout error codes (MESHX_TIMEOUT, MESHX_BASE_CLI_TIMEOUT)
  • Routes timeout events to registered application callbacks
  • Provides template-specific error logging and debugging
  • Maintains consistency with C implementation error handling patterns

Timeout Processing Flow:

  1. Searches template-specific callback list for matching model ID
  2. Sets timeout error codes in the parameter structure
  3. Validates callback function is not null
  4. Invokes registered callback with timeout notification
  5. Returns gracefully if no callback is registered (consistent with C impl)
Template Parameters
baseClientModelDerived_tThe derived client model class type
ble_mesh_plat_model_cb_params_tPlatform-specific callback parameter type
ble_mesh_send_msg_params_tPlatform-specific send message parameter type
Parameters
[in]pdevPointer to the device structure associated with the BLE Mesh node. Must not be NULL.
[in]evtControl task message event type (unused in current implementation).
[in]paramPointer to resend context containing model ID and callback parameters. Must not be NULL and contain valid model_id.
Return values
MESHX_SUCCESSTimeout processed successfully or no callback registered.
OtherError codes from callback execution.
Note
This function is called by the TXCM when message transmission timeouts occur.
Each template instantiation maintains its own callback list and handler.
Enhanced with template type identification for debugging purposes.
See also
base_from_ble_msg_handle() for normal message processing.
base_txcm_handle_resend() for retry mechanism details.
470{
473 bool cb_invoked = false;
474 for (auto &node : base_client_model_cb_list)
475 {
476 if (param->model_id == node.model_id)
477 {
478 /* Only invoke if the platform model matches this instance */
479 if (node.p_plat_model != nullptr && node.p_plat_model != param->param.model.p_model)
480 {
481 continue;
482 }
483
484 param->param.err_code = MESHX_TIMEOUT;
486 if(node.cb == nullptr)
487 {
488 MESHX_LOGW(MODULE_ID_MODEL_CLIENT, "Callback is NULL for model_id: %04x", node.model_id);
489 continue;
490 }
491 err = node.cb(pdev, param->model_id, &param->param);
492 cb_invoked = true;
493 }
494 }
495
496 if (!cb_invoked)
497 {
498 MESHX_LOGW(MODULE_ID_MODEL_CLIENT, "No registered client handled model_id=%04x", param->model_id);
499 return MESHX_SUCCESS; // Consistent with C implementation - graceful handling
500 }
501
502 return err;
503}
#define MESHX_UNUSED(x)
Definition meshx_err.h:19

◆ base_txcm_handle_ack()

template<typename baseClientModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_model_cb_params_t>
meshx_err_t meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >::base_txcm_handle_ack ( uint16_t src_addr)
staticprotected

Resend an acknowledgement message for the given source address.

This function resends an acknowledgement message for the given source address.

Parameters
[in]src_addrThe source address associated with the acknowledgement message.
Return values
MESHX_SUCCESSif the acknowledgement message was resent successfully, otherwise an error code.
289{
292 return err;
293}
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

◆ base_txcm_handle_resend()

template<typename baseClientModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_model_cb_params_t>
meshx_err_t meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >::base_txcm_handle_resend ( uint16_t model_id,
const ble_mesh_plat_model_cb_params_t * param )
staticprotected

Resend a message for the given model ID and parameter.

This function resends a message for the given model ID and parameter.

Parameters
[in]model_idThe unique identifier of the generic client model.
[in]paramThe parameter associated with the re-sending.
Return values
MESHX_SUCCESSif the message was resent successfully, otherwise an error code.
306{
308 .model_id = model_id,
309 .param = {}
310 };
312
316 &ctx,
318 NULL);
319}
struct base_client_model_resend_ctx { uint16_t model_id; ble_mesh_plat_model_cb_params_t param; } base_client_model_resend_ctx_t
Definition meshx_base_model_class.hpp:255

◆ from_ble_dereg_cb()

template<typename baseClientModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_model_cb_params_t>
meshx_err_t meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >::from_ble_dereg_cb ( void ) const
overridevirtual

Deregister BLE message callback for this model.

Deregisters a callback function associated with a model ID.

Automatically called during model destruction to remove the callback function that handles BLE messages for this model's ID.

Returns
MESHX_SUCCESS if deregistration successful, error code otherwise

This function deregisters the callback function associated with the given model ID, allowing the server to stop handling events or messages related to that model.

Returns
meshx_err_t Returns an error code indicating the result of the deregistration. Possible values include success or specific error codes.

Reimplemented from meshXBaseModel< ble_mesh_send_msg_params_t >.

507{
508 // First, unsubscribe from control task
510
511 // Then, remove from our static callback list to prevent dangling pointers
513 return node.p_plat_model == this->p_plat_model;
514 });
515
516 return err;
517}
struct base_client_model_cb_reg { uint16_t model_id; meshx_ptr_t p_plat_model; control_msg_cb cb; meshXBaseClientModel *instance; } base_client_model_cb_reg_t
Definition meshx_base_model_class.hpp:248
meshx_err_t control_task_msg_unsubscribe(control_task_msg_code_t msg_code, control_task_msg_evt_t evt_bmap, control_task_msg_handle_t callback)
Deregister a callback for a specific message code and event bitmap.
Definition meshx_control_task.c:172

◆ get_client_type_name()

template<typename baseClientModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_model_cb_params_t>
constexpr const char * meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >::get_client_type_name ( )
inlinestaticconstexprprotected
267 {
268 return __PRETTY_FUNCTION__;
269 }

◆ set_plat_model_ptr()

template<typename baseClientModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_model_cb_params_t>
void meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >::set_plat_model_ptr ( meshx_ptr_t p_model)

Set the platform model pointer and update the registration list.

Parameters
[in]p_modelPointer to the platform model instance.
521{
522 this->p_plat_model = p_model;
523 for (auto &node : base_client_model_cb_list)
524 {
525 if (node.instance == this)
526 {
528 break;
529 }
530 }
531}

◆ validate_client_model_id()

template<typename baseClientModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_model_cb_params_t>
virtual meshx_err_t meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >::validate_client_model_id ( uint32_t model_id)
protectedpure virtual

Field Documentation

◆ base_client_model_cb_list

template<typename baseClientModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_model_cb_params_t>
std::forward_list<base_client_model_cb_reg_t> meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >::base_client_model_cb_list
staticprotected

◆ p_plat_model

template<typename baseClientModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_model_cb_params_t>
meshx_ptr_t meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >::p_plat_model
protected

◆ plat_client_init_flag

template<typename baseClientModelDerived_t, typename ble_mesh_send_msg_params_t, typename ble_mesh_plat_model_cb_params_t>
std::once_flag meshXBaseClientModel< baseClientModelDerived_t, ble_mesh_send_msg_params_t, ble_mesh_plat_model_cb_params_t >::plat_client_init_flag
staticprotected

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