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_common.h
Go to the documentation of this file.
1/**
2 * Copyright © 2024 - 2025 MeshX
3 *
4 * @file meshx_common.h
5 * @brief Common application definitions and includes for BLE Mesh Node.
6 *
7 * This header file contains common definitions, includes, and data structures
8 * used across the BLE Mesh Node application.
9 *
10 * @author Pranjal Chanda
11 *
12 */
13
14#pragma once
15
16#include <stdio.h>
17#include <string.h>
18#include <inttypes.h>
19#include <meshx_err.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/**
29 * @brief Enumeration for the BLE Mesh application control event.
30 */
31typedef enum {
32 MESHX_CTRL_EVT_NODE_RESET = 0x01, /* Node Reset */
33 MESHX_CTRL_EVT_PROV_COMP, /* Provisioning Completed */
34 MESHX_CTRL_EVT_PROV_FAILED, /* Provisioning Failed */
35 MESHX_CTRL_EVT_PROV_START, /* Provisioning Started */
36 MESHX_CTRL_EVT_IDENTIFY_START, /* Identification Started */
37 MESHX_CTRL_EVT_IDENTIFY_STOP, /* Identification Stopped */
39
40
41/*********************************************************************
42 * FEATURE CONFIGURATION
43 * *******************************************************************/
44
45/**
46 * @brief Enable Element Table registration using Linker script.
47 * @note This feature is disabled by default.
48 */
49#ifndef CONFIG_SECTION_ENABLE_ELEMENT_TABLE
50#define CONFIG_SECTION_ENABLE_ELEMENT_TABLE 0
51#endif /* CONFIG_SECTION_ENABLE_ELEMENT_TABLE */
52
53#define MAX_ELE_CNT CONFIG_MAX_ELEMENT_COUNT
54#define MESHX_NVS_STORE "meshx_store"
55
56/**
57 * @brief Structure to store mesh application data.
58 */
59typedef struct meshx_app_store
60{
61 uint16_t net_key_id; /**< Network key identifier */
62 uint16_t node_addr; /**< Node address */
64
65/**
66 * @brief Structure representing the device composition and elements.
67 */
68typedef struct dev_struct
69{
70 uint8_t uuid[16]; /**< Device UUID */
71 size_t element_idx; /**< Index of the current element */
72 void *composition; /**< Device composition */
73 MESHX_ELEMENT *elements; /**< Pointer to array of elements */
74 size_t element_cnt; /**< Total number of elements */
75 meshx_app_store_t meshx_store; /**< Mesh application store */
77
78/**
79 * @struct meshx_model
80 * @brief Structure as Interface for meshx models.
81 */
83{
84 /* meshx_sig to be deplicated post C++ migration */
85 meshx_ptr_t meshx_sig; /**< SIG model pointer */
86 meshx_ptr_t meshx_pub; /**< publication structures */
87 meshx_ptr_t meshx_gen; /**< generic structures */
89
90/**
91 * @brief MeshX Compostion init Function Pointer
92 * @typedef element_comp_fn_t
93 *
94 * @param[in] pdev Pointer to the device structure.
95 * @param[in] element_cnt Number of elements.
96 *
97 * @return meshx_err_t
98 */
99typedef meshx_err_t (*element_comp_fn_t)(dev_struct_t *pdev, uint16_t element_cnt);
100
101/**
102 * @struct element_comp_table
103 * @brief Structure to store element composition functions.
104 */
105typedef struct element_comp_table
106{
107 uint8_t idx; /**< Index of the element type */
108 element_comp_fn_t element_comp_fn; /**< Element composition function */
110
111#if CONFIG_SECTION_ENABLE_ELEMENT_TABLE
112
113/**
114 * @brief Register an element composition function.
115 *
116 * This macro registers an element composition function to the element table.
117 *
118 * @param _name Name of the element composition function.
119 * @param _type Type of the element.
120 * @param _fn Element composition function.
121 */
122#define REG_MESHX_ELEMENT_FN(_name, _type, _fn) \
123 __section(".element_table") const element_comp_table_t _name = { \
124 .idx = _type, \
125 .element_comp_fn = &_fn, \
126 }
127
128#else
129
130/**
131 * @brief Register an element composition function.
132 * @note Currently feature is disabled using CONFIG_SECTION_ENABLE_ELEMENT_TABLE
133 *
134 * This macro registers an element composition function to the element table.
135 *
136 * @param _name Name of the element composition function.
137 * @param _type Type of the element.
138 * @param _fn Element composition function.
139 */
140#define REG_MESHX_ELEMENT_FN(_name, _type, _fn)
141
142#endif /* CONFIG_SECTION_ENABLE_ELEMENT_TABLE */
143
144#ifdef __cplusplus
145}
146#endif
void * meshx_ptr_t
Definition meshx_ble_mesh_cmn_def.h:636
meshx_ctrl_evt_t
Enumeration for the BLE Mesh application control event.
Definition meshx_common.h:31
@ MESHX_CTRL_EVT_PROV_START
Definition meshx_common.h:35
@ MESHX_CTRL_EVT_PROV_COMP
Definition meshx_common.h:33
@ MESHX_CTRL_EVT_NODE_RESET
Definition meshx_common.h:32
@ MESHX_CTRL_EVT_IDENTIFY_STOP
Definition meshx_common.h:37
@ MESHX_CTRL_EVT_PROV_FAILED
Definition meshx_common.h:34
@ MESHX_CTRL_EVT_IDENTIFY_START
Definition meshx_common.h:36
struct element_comp_table element_comp_table_t
struct dev_struct dev_struct_t
Structure representing the device composition and elements.
meshx_err_t(* element_comp_fn_t)(dev_struct_t *pdev, uint16_t element_cnt)
MeshX Compostion init Function Pointer.
Definition meshx_common.h:99
struct meshx_app_store meshx_app_store_t
Structure to store mesh application data.
struct meshx_model_interface meshx_model_interface_t
Internal configuration settings for MeshX.
MeshX Error Codes.
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
Logging interface for MeshX with color-coded output.
Platform abstraction layer for MeshX.
Structure representing the device composition and elements.
Definition meshx_common.h:69
void * composition
Definition meshx_common.h:72
meshx_app_store_t meshx_store
Definition meshx_common.h:75
size_t element_idx
Definition meshx_common.h:71
MESHX_ELEMENT * elements
Definition meshx_common.h:73
uint8_t uuid[16]
Definition meshx_common.h:70
size_t element_cnt
Definition meshx_common.h:74
Structure to store element composition functions.
Definition meshx_common.h:106
uint8_t idx
Definition meshx_common.h:107
element_comp_fn_t element_comp_fn
Definition meshx_common.h:108
Structure to store mesh application data.
Definition meshx_common.h:60
uint16_t net_key_id
Definition meshx_common.h:61
uint16_t node_addr
Definition meshx_common.h:62
Definition meshx_common.h:83
meshx_ptr_t meshx_sig
Definition meshx_common.h:85
meshx_ptr_t meshx_gen
Definition meshx_common.h:87
meshx_ptr_t meshx_pub
Definition meshx_common.h:86