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
Go to the documentation of this file.
1
10
11#include "meshx.h"
12
13#define CONFIG_MESHX_NVS_SAVE_PERIOD_MS 1000
14
15static meshx_err_t meshx_app_data_cb(const meshx_app_element_msg_header_t *msg_hdr, const meshx_data_payload_t *data_payload_u);
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};
30
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};
45
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}
63
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}
117
119{
120 return MESHX_SUCCESS;
121}
static element_comp_t element_comp_arr[]
Array of element components with their respective types and counts.
Definition main.c:24
void CONFIG_APP_MAIN(void)
Main application entry point.
Definition main.c:52
#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
This file contains the headers for meshx.c.
struct element_comp element_comp_t
struct meshx_config meshx_config_t
meshx_err_t meshx_init(meshx_config_t const *config)
MeshX initialisation function.
Definition meshx.c:231
union meshx_data_payload meshx_data_payload_t
Structure for the BLE Mesh application control message.
union meshx_ctrl_payload meshx_ctrl_payload_t
Structure defines the payload for meshx_ctrl_payload.
struct meshx_ctrl_msg_header meshx_ctrl_msg_header_t
Structure for the BLE Mesh application control message header.
#define MESHX_ELEMENT_FUNC_ID_LIGHT_CWWW_SERVER_ONN_OFF
Definition meshx_api.h:24
struct meshx_app_element_msg_header meshx_app_element_msg_header_t
Structure for the BLE Mesh application element message header.
#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
#define MESHX_UUID_EMPTY
#define CONFIG_PID_ID
#define CONFIG_CID_ID
Application Main.
#define CONFIG_PRODUCT_NAME
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:39
@ MESHX_SUCCESS
Definition meshx_err.h:40
@ 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
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:73
@ MODULE_ID_COMMON
Definition module_id.h:32
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
Structure for MeshX configuration.
Definition meshx.h:61
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