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
meshx.h File Reference

This file contains the headers for meshx.c. More...

#include <meshx_common.h>
#include <meshx_nvs.h>
#include <meshx_api.h>
#include <meshx_err.h>
#include <meshx_os_timer.h>
#include <meshx_prov_srv.h>
#include <meshx_config_server.h>
#include "meshx_serial.h"
#include <meshx_txcm.h>
#include <interface/meshx_platform.h>
#include <meshx_builder_api.h>
#include <unit_test.h>

Go to the source code of this file.

Data Structures

struct  element_comp
 Structure for element composition. More...
struct  meshx_config
 Structure for MeshX configuration. More...

Macros

#define MESHX_ERR_PRINT_RET(_e_str, _err)
 Print and return error message if an error occurs.
#define CID_ESP   CONFIG_CID_ID

Typedefs

typedef struct element_comp element_comp_t
typedef struct meshx_config meshx_config_t

Functions

meshx_err_t meshx_init (meshx_config_t const *config)
 MeshX initialisation function.

Detailed Description

This file contains the headers for meshx.c.

Copyright © 2024 - 2025 MeshX

Author
Pranjal Chanda

Macro Definition Documentation

◆ CID_ESP

#define CID_ESP   CONFIG_CID_ID

◆ MESHX_ERR_PRINT_RET

#define MESHX_ERR_PRINT_RET ( _e_str,
_err )
Value:
if (_err != MESHX_SUCCESS) \
{ \
MESHX_LOGE(MODULE_ID_COMMON, _e_str " (err 0x%x)", _err); \
return _err; \
}
**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

Print and return error message if an error occurs.

This macro prints an error message and returns the error code if an error occurs.

Parameters
_e_strError string to print
_errError code to return
Returns
Error code
41#define MESHX_ERR_PRINT_RET(_e_str, _err) \
42 if (_err != MESHX_SUCCESS) \
43 { \
44 MESHX_LOGE(MODULE_ID_COMMON, _e_str " (err 0x%x)", _err); \
45 return _err; \
46 }

Typedef Documentation

◆ element_comp_t

typedef struct element_comp element_comp_t

◆ meshx_config_t

typedef struct meshx_config meshx_config_t

Function Documentation

◆ meshx_init()

meshx_err_t meshx_init ( meshx_config_t const * config)

MeshX initialisation function.

This function initialises the MeshX stack with the given configuration.

Parameters
[in]configPointer to the configuration structure
Returns
MESHX_SUCCESS, Success
244{
245 /* Check if the configuration is valid */
246 if(!config)
247 return MESHX_INVALID_ARG;
248
250
251 /* Copy the configuration to the global config structure */
252 memcpy(&g_config, config, sizeof(meshx_config_t));
253
254 /* Initialise Platform deps */
255 err = meshx_platform_init();
256 MESHX_ERR_PRINT_RET("Platform init failed", err);
257
258 meshx_logging_t logging_cfg;
259 logging_cfg.def_log_level = config->meshx_log_level == MESHX_LOG_VERBOSE ?
260 CONFIG_MESHX_DEFAULT_LOG_LEVEL : config->meshx_log_level;
261
262 err = meshx_logging_init(&logging_cfg);
263 MESHX_ERR_PRINT_RET("Logging init failed", err);
264
265 MESHX_LOGI(MODULE_ID_COMMON, "MeshX Logging Initialized successfully");
266
267 /* Load Persistent Configuration and apply UUID/Product Info */
268 err = meshx_load_persistent_config(config);
269 MESHX_ERR_PRINT_RET("Failed to load persistent configuration", err);
270
271 /* Initialise Control Task messaging early (required for NVS and OS Timers) */
272 err = control_task_init();
273 MESHX_ERR_PRINT_RET("Control Task Init failed", err);
274
275 /* Initialize OS timer */
276 err = meshx_os_timer_init();
277 MESHX_ERR_PRINT_RET("OS Timer Init failed", err);
278
279 /* Initialize MeshX NVS */
280 err = meshx_nvs_init();
281 MESHX_ERR_PRINT_RET("MeshX NVS Init failed", err);
282
283 /* Restore the device state and open NVS (Required before element constructors run) */
285 MESHX_ERR_PRINT_RET("Device restore failed", err);
286
287 /* Initialize application tasks */
288 err = meshx_tasks_init(&g_dev);
289 MESHX_ERR_PRINT_RET("Tasks initialization failed", err);
290
291 /* Register application element callback */
292 err = meshx_app_reg_element_callback(g_config.app_element_cb);
293 MESHX_ERR_PRINT_RET("Failed to register app element callback", err);
294
295 /* Register application control callback */
297 MESHX_ERR_PRINT_RET("Failed to register app control callback", err);
298
299 /* Initialize the Bluetooth Mesh Subsystem */
301 MESHX_ERR_PRINT_RET("Bluetooth mesh init failed", err);
302
303 /* Initialize Hosted Serial Protocol */
304 err = meshx_serial_init();
305 MESHX_ERR_PRINT_RET("Serial init failed", err);
306
307#if CONFIG_ENABLE_UNIT_TEST
308 /* Initialize unit test console (this also registers the 'ut' command) */
310 MESHX_ERR_PRINT_RET("Failed to initialize unit test console", err);
311#endif /* CONFIG_ENABLE_UNIT_TEST */
312
313 return err;
314}
static meshx_config_t g_config
Definition meshx.c:35
static meshx_err_t meshx_load_persistent_config(meshx_config_t const *config)
Load persistent read-only configuration from flash and apply it.
Definition meshx.c:181
static meshx_err_t meshx_dev_restore(dev_struct_t *pdev, meshx_config_t const *config)
Restore the device state from the NVS.
Definition meshx.c:115
static meshx_err_t meshx_tasks_init(dev_struct_t *pdev)
Initializes application tasks.
Definition meshx.c:92
static meshx_err_t meshx_ble_mesh_init(meshx_config_t *config)
Initializes the BLE Mesh subsystem.
Definition meshx.c:139
static dev_struct_t g_dev
Definition meshx.c:33
struct meshx_config meshx_config_t
#define MESHX_ERR_PRINT_RET(_e_str, _err)
Print and return error message if an error occurs.
Definition meshx.h:41
meshx_err_t meshx_app_reg_element_callback(meshx_app_data_cb_t cb)
Registers the BLE Mesh application callback.
Definition meshx_api.c:206
meshx_err_t meshx_app_reg_system_events_callback(meshx_app_ctrl_cb_t cb)
Registers the BLE Mesh application control callback.
Definition meshx_api.c:234
meshx_err_t control_task_init(void)
Initialize the control task messaging system.
Definition meshx_control_task.c:45
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
@ MESHX_INVALID_ARG
Definition meshx_err.h:46
meshx_err_t meshx_logging_init(const meshx_logging_t *config)
Definition meshx_log.c:88
#define MESHX_LOGI(module_id, format,...)
Definition meshx_log.h:126
#define MESHX_LOG_VERBOSE
Definition meshx_log.h:31
#define CONFIG_MESHX_DEFAULT_LOG_LEVEL
Definition meshx_log.h:66
meshx_err_t meshx_nvs_init(void)
MeshX NVS Initialisation.
Definition meshx_nvs.c:142
meshx_err_t meshx_os_timer_init(void)
Initialize the OS timer module.
Definition meshx_os_timer.c:227
meshx_err_t meshx_platform_init(void)
Initializes the MeshX platform.
Definition esp_platform.c:60
meshx_err_t meshx_serial_init(void)
Initialize the MeshX Serial Protocol handler.
Definition meshx_serial.c:517
Definition meshx_log.h:37
meshx_log_level_t def_log_level
Definition meshx_log.h:38
meshx_err_t init_unit_test_console(void)
Initialize the unit test console.
Definition unit_test.c:103