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
main.c File Reference

Main application file. More...

#include "meshx.h"
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define CONFIG_MESHX_NVS_SAVE_PERIOD_MS   1000
 

Functions

static meshx_err_t meshx_app_data_cb (const meshx_app_element_msg_header_t *msg_hdr, const meshx_data_payload_t *data_payload_u)
 
static meshx_err_t meshx_app_ctrl_cb (const meshx_ctrl_msg_header_t *msg_hdr, const meshx_ctrl_payload_t *msg)
 
void CONFIG_APP_MAIN (void)
 Main application entry point.
 

Variables

static element_comp_t element_comp_arr []
 Array of element components with their respective types and counts.
 
static const meshx_config_t meshx_config
 Configuration for the MeshX library.
 

Detailed Description

Main application file.

Copyright © 2024 - 2025 MeshX

This file contains the entry point for the application which initializes the MeshX library and handles any initialization errors.

Definition in file main.c.

Macro Definition Documentation

◆ CONFIG_MESHX_NVS_SAVE_PERIOD_MS

#define CONFIG_MESHX_NVS_SAVE_PERIOD_MS   1000

Definition at line 13 of file main.c.

Function Documentation

◆ CONFIG_APP_MAIN()

void CONFIG_APP_MAIN ( void )

Main application entry point.

This function initializes the MeshX library and logs an error message if the initialization fails.

Definition at line 52 of file main.c.

53{
54 meshx_err_t err;
55
57 if (err)
58 {
59 MESHX_LOGE(MODULE_ID_COMMON, "MeshX Init failed (err: 0x%x)", err);
60 return;
61 }
62}
meshx_err_t meshx_init(meshx_config_t const *config)
MeshX initialisation function.
Definition meshx.c:231
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:39
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:73
@ MODULE_ID_COMMON
Definition module_id.h:32
Structure for MeshX configuration.
Definition meshx.h:61
Here is the call graph for this function:

◆ meshx_app_ctrl_cb()

static meshx_err_t meshx_app_ctrl_cb ( const meshx_ctrl_msg_header_t * msg_hdr,
const meshx_ctrl_payload_t * msg )
static

Definition at line 118 of file main.c.

119{
120 return MESHX_SUCCESS;
121}
@ MESHX_SUCCESS
Definition meshx_err.h:40

◆ meshx_app_data_cb()

static meshx_err_t meshx_app_data_cb ( const meshx_app_element_msg_header_t * msg_hdr,
const meshx_data_payload_t * data_payload_u )
static

Definition at line 64 of file main.c.

65{
66 if (!msg_hdr || !data_payload_u)
67 return MESHX_INVALID_ARG;
68
69 switch (msg_hdr->element_type)
70 {
72 MESHX_LOGI(MODULE_ID_COMMON, "Relay Server Element ID: %d, Func ID: %d, Data: %d", msg_hdr->element_id, msg_hdr->func_id, data_payload_u->relay_server_evt.on_off);
73 break;
75 MESHX_LOGI(MODULE_ID_COMMON, "Relay Client Element ID: %d, Func ID: %d, Data: %d, Error: %d", msg_hdr->element_id, msg_hdr->func_id, data_payload_u->relay_client_evt.on_off, data_payload_u->relay_client_evt.err_code);
76 break;
78 switch (msg_hdr->func_id)
79 {
81 MESHX_LOGI(MODULE_ID_COMMON, "Light CW-WW Server Element ID: %d, Func ID: %d, Data: %d", msg_hdr->element_id, msg_hdr->func_id,
83 break;
85 MESHX_LOGI(MODULE_ID_COMMON, "Light CW-WW Server Element ID: %d, Func ID: %d, Data: %d|%d", msg_hdr->element_id, msg_hdr->func_id,
88 break;
89 default:
90 MESHX_LOGW(MODULE_ID_COMMON, "Unhandled function ID: %d", msg_hdr->func_id);
91 break;
92 }
93 break;
95 switch (msg_hdr->func_id)
96 {
98 MESHX_LOGI(MODULE_ID_COMMON, "Light CW-WW Client Element ID: %d, Func ID: %d, Data: %d, Error: %d", msg_hdr->element_id, msg_hdr->func_id,
100 break;
102 MESHX_LOGI(MODULE_ID_COMMON, "Light CW-WW Client Element ID: %d, Func ID: %d, Data: %d|%d", msg_hdr->element_id, msg_hdr->func_id,
105 break;
106 default:
107 MESHX_LOGW(MODULE_ID_COMMON, "Unhandled function ID: %d", msg_hdr->func_id);
108 break;
109 }
110 break;
111 default:
112 MESHX_LOGW(MODULE_ID_COMMON, "Unhandled element type: %d", msg_hdr->element_type);
113 break;
114 }
115 return MESHX_SUCCESS;
116}
#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_SERVER_ONN_OFF
Definition meshx_api.h:24
#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_SERVER_CTL
Definition meshx_api.h:25
@ MESHX_ELEMENT_TYPE_LIGHT_CWWW_CLIENT
Definition meshx_api.h:47
@ MESHX_ELEMENT_TYPE_RELAY_CLIENT
Definition meshx_api.h:45
@ MESHX_ELEMENT_TYPE_LIGHT_CWWW_SERVER
Definition meshx_api.h:46
@ MESHX_ELEMENT_TYPE_RELAY_SERVER
Definition meshx_api.h:44
#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_CLIENT_ONN_OFF
Definition meshx_api.h:28
#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_CLIENT_CTL
Definition meshx_api.h:29
@ MESHX_INVALID_ARG
Definition meshx_err.h:42
#define MESHX_LOGW(module_id, format,...)
Definition meshx_log.h:87
#define MESHX_LOGI(module_id, format,...)
Definition meshx_log.h:100
struct meshx_api_light_cwww_client_evt::@347235105244230326232000270243372246073133053316::@202375373323027037070222212050326072162342057303 on_off
struct meshx_api_light_cwww_client_evt::@347235105244230326232000270243372246073133053316::@153162234125000074275266213156212277206313354032 ctl
union meshx_api_light_cwww_client_evt::@347235105244230326232000270243372246073133053316 state_change
union meshx_api_light_cwww_server_evt::@257165005032013366004013204037032016036030275264 state_change
struct meshx_api_light_cwww_server_evt::@257165005032013366004013204037032016036030275264::@375004001161356005102054253202024137247030164222 on_off
struct meshx_api_light_cwww_server_evt::@257165005032013366004013204037032016036030275264::@245341060156102221224175046143367317210200103050 ctl
meshx_api_relay_server_evt_t relay_server_evt
Definition meshx_api.h:121
meshx_api_relay_client_evt_t relay_client_evt
Definition meshx_api.h:120
meshx_api_light_cwww_client_evt_t light_cwww_client_evt
Definition meshx_api.h:122
meshx_api_light_cwww_server_evt_t light_cwww_server_evt
Definition meshx_api.h:123

Variable Documentation

◆ element_comp_arr

element_comp_t element_comp_arr[]
static
Initial value:

Array of element components with their respective types and counts.

This array holds the configuration for different types of elements in the MeshX application. Each entry in the array consists of an element type and the corresponding count defined in the configuration.

Definition at line 24 of file main.c.

24 {
25 {MESHX_ELEMENT_TYPE_RELAY_SERVER, CONFIG_RELAY_SERVER_COUNT},
26 {MESHX_ELEMENT_TYPE_RELAY_CLIENT, CONFIG_RELAY_CLIENT_COUNT},
27 {MESHX_ELEMENT_TYPE_LIGHT_CWWW_SERVER, CONFIG_LIGHT_CWWW_SRV_COUNT},
28 {MESHX_ELEMENT_TYPE_LIGHT_CWWW_CLIENT, CONFIG_LIGHT_CWWW_CLIENT_COUNT}
29};

◆ meshx_config

const meshx_config_t meshx_config
static
Initial value:
= {
.cid = CONFIG_CID_ID,
.pid = CONFIG_PID_ID,
.product_name = CONFIG_PRODUCT_NAME,
.app_ctrl_cb = &meshx_app_ctrl_cb,
.app_element_cb = &meshx_app_data_cb,
.meshx_uuid_addr = MESHX_UUID_EMPTY,
.element_comp_arr = element_comp_arr,
.element_comp_arr_len = ARRAY_SIZE(element_comp_arr),
.meshx_nvs_save_period = CONFIG_MESHX_NVS_SAVE_PERIOD_MS,
}
#define CONFIG_MESHX_NVS_SAVE_PERIOD_MS
Definition main.c:13
static meshx_err_t meshx_app_data_cb(const meshx_app_element_msg_header_t *msg_hdr, const meshx_data_payload_t *data_payload_u)
Definition main.c:64
static meshx_err_t meshx_app_ctrl_cb(const meshx_ctrl_msg_header_t *msg_hdr, const meshx_ctrl_payload_t *msg)
Definition main.c:118
#define MESHX_UUID_EMPTY
#define CONFIG_PID_ID
#define CONFIG_CID_ID
Application Main.
#define CONFIG_PRODUCT_NAME
element_comp_t * element_comp_arr
Definition meshx.h:67

Configuration for the MeshX library.

Definition at line 34 of file main.c.

34 {
35 .cid = CONFIG_CID_ID,
36 .pid = CONFIG_PID_ID,
37 .product_name = CONFIG_PRODUCT_NAME,
38 .app_ctrl_cb = &meshx_app_ctrl_cb,
39 .app_element_cb = &meshx_app_data_cb,
40 .meshx_uuid_addr = MESHX_UUID_EMPTY, /* UUID address to be filled internally for MeshX */
41 .element_comp_arr = element_comp_arr,
42 .element_comp_arr_len = ARRAY_SIZE(element_comp_arr),
43 .meshx_nvs_save_period = CONFIG_MESHX_NVS_SAVE_PERIOD_MS,
44};
static element_comp_t element_comp_arr[]
Array of element components with their respective types and counts.
Definition main.c:24