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

Derived class for the root element. More...

#include <meshx_root_element.hpp>

Inheritance diagram for meshXRootElement:
meshXElementServer meshXElement< meshx_srv_model_send_param_header_t > meshXElementIF

Public Member Functions

 meshXRootElement ()
 Constructs a new meshXRootElement instance.
Public Member Functions inherited from meshXElementServer
 meshXElementServer ()=default
 meshXElementServer (uint16_t element_idx, uint8_t no_of_sig_models=0, uint8_t no_of_ven_models=0)
Public Member Functions inherited from meshXElement< meshx_srv_model_send_param_header_t >
void set_element_type (meshxElementType_t type)
meshxElementType_t get_element_type (void) const final
 Get the element type.
void set_element_variant (meshx_element_type_t variant)
meshx_element_type_t get_element_variant (void) const final
 Get the element variant.
void set_no_of_sig_models (uint8_t cnt)
uint8_t get_no_of_sig_models (void) const final
 Get the number of SIG models supported by the element.
void set_no_of_ven_models (uint8_t cnt)
uint8_t get_no_of_ven_models (void) const final
 Get the number of Vendor models supported by the element.
std::vector< std::unique_ptr< meshXModelIF > > & get_sig_models (void) final
 Get the SIG models vector.
std::vector< std::unique_ptr< meshXModelIF > > & get_ven_models (void) final
 Get the Vendor models vector.
void register_element_ctx (meshx_ptr_t ctx, size_t ctx_size)
 Register element context structure.
meshx_ptr_t get_element_ctx (void) const override
 Get the element context structure.
size_t get_element_ctx_size (void) const override
 Get the size of the element context structure.
meshx_err_t sig_plat_model_array_allocate (void)
 Allocate memory for SIG model platform array.
meshx_err_t ven_plat_model_array_allocate (void)
 Allocate memory for Vendor model platform array.
std::vector< uint8_t > & get_sig_model_array (void)
 Get the SIG model array.
std::vector< uint8_t > & get_ven_model_array (void)
 Get the Vendor model array.
meshx_err_t add_sig_model (ConstructorsArgs &&... args)
 Add a SIG model to the element.
meshx_err_t add_ven_model (ConstructorsArgs &&... args)
 Add a Vendor model to the element.
uint8_t get_sig_model_count (void) const
 Get the number of SIG models currently added to the element.
uint8_t get_ven_model_count (void) const
 Get the number of Vendor models currently added to the element.
meshx_err_t add_sig_models (void)
 Add multiple SIG models to the element.
meshx_err_t add_ven_models (void)
 Add multiple Vendor models to the element.
meshx_err_t add_models (void)
 Add both SIG and Vendor models to the element.
MESHX_MODEL * get_sig_plat_model_array (void)
 Get the platform model array for SIG models.
MESHX_MODEL * get_ven_plat_model_array (void)
 Get the platform model array for Vendor models.
 meshXElement (void)
 Default constructor for meshXElement.
meshx_err_t initialize (void) override
 Initialize the element.
meshx_err_t reset (void) override
 Reset the element.
bool is_initialized (void) const override
 Check if the element is initialized.
meshx_err_t restore_nvs_context (void) override
 Restore the element's context from NVS.
bool has_model (uint16_t model_id) const override
 Check if the element contains a specific model by ID.
void on_baked (uint16_t index) override
 Called when the composition is baked to update the element's index.
 ~meshXElement () override
Public Member Functions inherited from meshXElementIF
void set_element_idx (uint16_t idx)
uint16_t get_element_idx (void) const
 meshXElementIF ()=delete
 meshXElementIF (uint16_t element_idx)
virtual ~meshXElementIF ()=default

Private Member Functions

uint8_t list_sig_models () override
 Lists and initializes SIG models for Root Element.
uint8_t list_ven_models () override
 Lists and creates all required Vendor models for the element.
const char * get_element_name (void) const override
 Get the name of the element.
meshx_err_t element_state_change_notify (meshx_ptr_t param, size_t param_size) override
 Handle model callback from child models.
void sync (control_task_msg_evt_t evt) override
 Synchronize element state (Status broadcast or GET request).
void handle_config (control_task_msg_evt_t evt, const meshx_config_srv_cb_param_t *params) override
 Handle configuration server events (AppKey bind, Publication, etc.).
template<typename ModelT>
void add_sig_model_if_present (uint16_t trigger_model_id, const char *log_name)

Additional Inherited Members

Static Public Member Functions inherited from meshXElement< meshx_srv_model_send_param_header_t >
static meshx_err_t static_prov_srv_cb (const dev_struct_t *pdev, control_task_msg_evt_t evt, const void *params)
 Global static provisioning callback for Server elements.
static meshx_err_t static_prov_cli_cb (const dev_struct_t *pdev, control_task_msg_evt_t evt, const void *params)
 Global static provisioning callback for Client elements.
static meshx_err_t static_config_cb (const dev_struct_t *pdev, control_task_msg_evt_t evt, const meshx_config_srv_cb_param_t *params)
 Global static configuration callback.
static void register_global_callbacks (void)
 Register the global callbacks with the provisioning server.

Detailed Description

Derived class for the root element.

Constructor & Destructor Documentation

◆ meshXRootElement()

meshXRootElement::meshXRootElement ( )

Constructs a new meshXRootElement instance.

Constructor for Root Element.

The meshXRootElement represents the primary element in the MeshX BLE mesh network. It automatically initializes and configures all required SIG models for the root element, including the Configuration Server model and other essential models.

The constructor follows these steps:

  1. Creates the root element with the predefined index
  2. Determines the number of required SIG models
  3. Allocates memory for the SIG models
  4. Adds all required SIG models to the element

This constructor initializes a Root Element with the predefined element index. All required SIG models are added in list_sig_models() method. Auto initialization is taken care by meshXElement constructor.

34{
35 // All required SIG models are added in list_sig_models()
36 // Auto initialisation taken care by meshXElement constructor
37}
meshXElementServer()=default
constexpr uint16_t MESHX_ROOT_ELEMENT_INDEX
Definition meshx_root_element.cpp:19

Member Function Documentation

◆ add_sig_model_if_present()

template<typename ModelT>
template void meshXRootElement::add_sig_model_if_present< meshXLightCTLSetupServerModel > ( uint16_t trigger_model_id,
const char * log_name )
private
78 {
79 if (meshXComposition::get_instance().has_model(trigger_model_id)) {
80 MESHX_LOGI(MODULE_ID_BLE_MESH_ELEMENT, "Root: %s dependency detected. Adding Setup Server.", log_name);
81 this->get_sig_models().push_back(std::make_unique<ModelT>(this, nullptr, 0));
82 }
83}
static meshXComposition & get_instance()
Get the singleton instance.
Definition meshx_composition.cpp:29
bool has_model(uint16_t model_id) const override
Definition meshx_element_class.cpp:384
std::vector< std::unique_ptr< meshXModelIF > > & get_sig_models(void) final
Definition meshx_element_class.hpp:78
#define MESHX_LOGI(module_id, format,...)
Definition meshx_log.h:126
@ MODULE_ID_BLE_MESH_ELEMENT
Definition module_id.h:39

◆ element_state_change_notify()

meshx_err_t meshXRootElement::element_state_change_notify ( meshx_ptr_t param,
size_t param_size )
overrideprivatevirtual

Handle model callback from child models.

This function is called by child models when a state change occurs. It handles the state change by logging the event. The root element only has a Configuration Server model.

Parameters
[in]paramPointer to the model callback parameter
[in]param_sizeSize of the parameter structure
Returns
  • MESHX_SUCCESS: State change handled successfully
  • MESHX_INVALID_ARG: Invalid parameter

Reimplemented from meshXElement< meshx_srv_model_send_param_header_t >.

109{
110 if (!param) {
111 MESHX_LOGE(MODULE_ID_ELEMENT_ROOT, "Invalid parameter in element_state_change_notify");
112 return MESHX_INVALID_ARG;
113 }
114
115 // Root element currently only has Config Server model
116 // Config model events are logged but not processed further
117 MESHX_LOGI(MODULE_ID_ELEMENT_ROOT, "Root element received model callback");
118
119 // For now, just log the event and return success
120
121 return MESHX_SUCCESS;
122}
@ 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_ELEMENT_ROOT
Definition module_id.h:38

◆ get_element_name()

const char * meshXRootElement::get_element_name ( void ) const
overrideprivatevirtual

Get the name of the element.

Returns
String literal representing the element name.

Reimplemented from meshXElement< meshx_srv_model_send_param_header_t >.

73{
74 return "Root Element";
75}

◆ handle_config()

void meshXRootElement::handle_config ( control_task_msg_evt_t evt,
const meshx_config_srv_cb_param_t * params )
overrideprivatevirtual

Handle configuration server events (AppKey bind, Publication, etc.).

Parameters
evtThe configuration event code
paramsPointer to the configuration parameters

Implements meshXElementIF.

130{
131 MESHX_LOGD(MODULE_ID_ELEMENT_ROOT, "Root Element config event: %d", evt);
132}
#define MESHX_LOGD(module_id, format,...)
Definition meshx_log.h:132

◆ list_sig_models()

uint8_t meshXRootElement::list_sig_models ( void )
overrideprivatevirtual

Lists and initializes SIG models for Root Element.

This function creates and adds the Configuration Server model to the element's SIG models list. The Configuration Server model is always required for root elements in the BLE mesh network.

Returns
uint8_t Number of SIG models added to the element

Reimplemented from meshXElement< meshx_srv_model_send_param_header_t >.

49{
50 // 1. Initialize platform Config Server
52
53 // 2. Create Configuration Server model (always required)
54 auto config_model = std::make_unique<meshXConfigModel>(
55 this,
56 nullptr,
58 );
59 this->get_sig_models().push_back(std::move(config_model));
60
61#if CONFIG_ENABLE_LIGHT_CTL_SERVER
63#endif
64
65 return (uint8_t)this->get_sig_models().size();
66}
void add_sig_model_if_present(uint16_t trigger_model_id, const char *log_name)
Definition meshx_root_element.cpp:78
#define MESHX_MODEL_ID_LIGHT_CTL_SRV
Definition meshx_ble_mesh_cmn_def.h:107
meshx_err_t meshx_init_config_server(void)
Definition meshx_model_config.cpp:284
@ MESHX_ROOT_ELEMENT_COMP_CONFIG_SERVER
Definition meshx_root_element.hpp:28

◆ list_ven_models()

uint8_t meshXRootElement::list_ven_models ( void )
overrideprivatevirtual

Lists and creates all required Vendor models for the element.

This function is responsible for creating and populating the ven_models vector with all essential Vendor models that the element must have.

The function can be extended to include additional models based on configuration flags or specific requirements.

Returns
uint8_t The total number of Vendor models created and added to the root_sig_models vector

Reimplemented from meshXElement< meshx_srv_model_send_param_header_t >.

68 {
69 return 0; // Root element usually has no vendor models
70}

◆ sync()

void meshXRootElement::sync ( control_task_msg_evt_t evt)
overrideprivatevirtual

Synchronize element state (Status broadcast or GET request).

Parameters
evtThe event trigger (STACK_READY or FRESH_BOOT)

Implements meshXElementIF.

125{
126 MESHX_LOGD(MODULE_ID_ELEMENT_ROOT, "Root Element sync event: %d", evt);
127}

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