MeshX 0.3
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_elements.h>
#include <interface/meshx_platform.h>
#include <unit_test.h>
Include dependency graph for meshx.h:
This graph shows which files directly or indirectly include this file:

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

Definition in file meshx.h.

Macro Definition Documentation

◆ CID_ESP

#define CID_ESP   CONFIG_CID_ID

Definition at line 44 of file meshx.h.

◆ 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; \
}
@ MESHX_SUCCESS
Definition meshx_err.h:40
@ MODULE_ID_COMMON
Definition module_id.h:32

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

Definition at line 37 of file meshx.h.

37#define MESHX_ERR_PRINT_RET(_e_str, _err) \
38 if (_err != MESHX_SUCCESS) \
39 { \
40 MESHX_LOGE(MODULE_ID_COMMON, _e_str " (err 0x%x)", _err); \
41 return _err; \
42 }

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

Definition at line 231 of file meshx.c.

232{
233 /* Check if the configuration is valid */
234 if(!config)
235 return MESHX_INVALID_ARG;
236
238
239 /* Copy the configuration to the global config structure */
240 memcpy(&g_config, config, sizeof(meshx_config_t));
241
242 meshx_logging_t logging_cfg;
243
244 logging_cfg.def_log_level = config->meshx_log_level == MESHX_LOG_VERBOSE ?
245 CONFIG_MESHX_DEFAULT_LOG_LEVEL : config->meshx_log_level;
246
247 err = meshx_logging_init(&logging_cfg);
248 MESHX_ERR_PRINT_RET("Logging init failed", err);
249
250 /* Initialise Platform deps */
251 err = meshx_platform_init();
252 MESHX_ERR_PRINT_RET("Platform init failed", err);
253
254 /* Initialize OS timer */
255 err = meshx_os_timer_init();
256 MESHX_ERR_PRINT_RET("OS Timer Init failed", err);
257
258 /* Initialize MeshX NVS */
259 err = meshx_nvs_init();
260 MESHX_ERR_PRINT_RET("MeshX NVS Init failed", err);
261
262 /* Initialize application tasks */
263 err = meshx_tasks_init(&g_dev);
264 MESHX_ERR_PRINT_RET("Tasks initialization failed", err);
265
266 /* Register application element callback */
267 err = meshx_app_reg_element_callback(g_config.app_element_cb);
268 MESHX_ERR_PRINT_RET("Failed to register app element callback", err);
269
270 /* Register application control callback */
272 MESHX_ERR_PRINT_RET("Failed to register app control callback", err);
273
274 /* Initialize the Bluetooth Mesh Subsystem */
276 MESHX_ERR_PRINT_RET("Bluetooth mesh init failed", err);
277
278 /* Print the MeshX banner */
279 CONFIG_MESHX_LOG_PRINTF(LOG_ANSI_COLOR_REGULAR(LOG_ANSI_COLOR_CYAN) "%s" LOG_ANSI_COLOR_RESET, meshX_banner);
280
281#if CONFIG_ENABLE_UNIT_TEST
282 /* Register unit test command */
283 err = register_ut_command();
284 MESHX_ERR_PRINT_RET("Failed to register unit test command", err);
285
286 /* Initialize unit test console */
288 MESHX_ERR_PRINT_RET("Failed to initialize production console", err);
289#endif /* CONFIG_ENABLE_UNIT_TEST */
290
291 return err;
292}
static meshx_config_t g_config
Definition meshx.c:57
static const char meshX_banner[]
Definition meshx.c:34
static meshx_err_t meshx_tasks_init(dev_struct_t *pdev)
Initializes application tasks.
Definition meshx.c:151
static meshx_err_t meshx_ble_mesh_init(meshx_config_t *config)
Initializes the BLE Mesh subsystem.
Definition meshx.c:194
static dev_struct_t g_dev
Definition meshx.c:55
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:37
meshx_err_t meshx_app_reg_element_callback(meshx_app_data_cb_t cb)
Registers the BLE Mesh application callback.
Definition meshx_api.c:148
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:176
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:39
@ MESHX_INVALID_ARG
Definition meshx_err.h:42
meshx_err_t meshx_logging_init(const meshx_logging_t *config)
Initializes the MeshX logging system with the provided configuration.
Definition meshx_log.c:61
#define MESHX_LOG_VERBOSE
Definition meshx_log.h:39
#define CONFIG_MESHX_DEFAULT_LOG_LEVEL
Definition meshx_log.h:23
struct meshx_logging meshx_logging_t
#define CONFIG_MESHX_LOG_PRINTF
Macro to define printf function.
Definition meshx_log.h:19
meshx_err_t meshx_nvs_init(void)
MeshX NVS Initialisation.
Definition meshx_nvs.c:135
meshx_err_t meshx_os_timer_init(void)
Initialize the OS timer module.
meshx_err_t meshx_platform_init(void)
Initializes the MeshX platform.
unsigned def_log_level
Definition meshx_log.h:53
meshx_err_t register_ut_command()
Registers the unit test (ut) command with the ESP console.
Definition unit_test.c:81
meshx_err_t init_unit_test_console()
Initialize the production console.
Definition unit_test.c:100
Here is the call graph for this function:
Here is the caller graph for this function: