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.
|
Implementation of the relay client model for BLE Mesh. More...
#include "meshx_common.h"
#include "meshx_control_task.h"
#include "meshx_nvs.h"
#include "meshx_api.h"
#include "meshx_relay_client_element.h"
#include "meshx_config_server.h"
Go to the source code of this file.
Macros | |
#define | CONFIG_SERVER_CB_MASK |
#define | CONTROL_TASK_MSG_CODE_EVT_MASK CONTROL_TASK_MSG_EVT_TO_BLE_SET_ON_OFF |
#define | MOD_SRC MODULE_ID_ELEMENT_SWITCH_RELAY_CLIENT |
#define | RELAY_CLI_EL_STATE_CH_EVT_MASK CONTROL_TASK_MSG_EVT_EL_STATE_CH_SET_ON_OFF |
#define | GET_RELATIVE_EL_IDX(_element_id) |
#define | IS_EL_IN_RANGE(_element_id) |
#define | RELAY_CLI_EL(_rel_el_id) |
Enumerations | |
enum | relay_cli_cmd_t { RELAY_CLI_CMD_GET = 0x00 , RELAY_CLI_CMD_SET = 0x01 , RELAY_CLI_CMD_SET_UNACK = 0x02 , RELAY_CLI_MAX_CMD } |
Functions | |
static meshx_err_t | meshx_element_struct_init (uint16_t n_max) |
Initializes the mesh element structure. | |
static meshx_err_t | meshx_element_struct_deinit (void) |
Deinitializes the mesh element structure. | |
static meshx_err_t | meshx_dev_create_relay_model_space (dev_struct_t const *pdev, uint16_t n_max) |
Create Dynamic Relay Model Elements. | |
static meshx_err_t | meshx_add_relay_cli_model_to_element_list (dev_struct_t *pdev, uint16_t *start_idx, uint16_t n_max) |
Add relay client models to the element list. | |
static meshx_err_t | relay_client_config_cli_cb (const dev_struct_t *pdev, control_task_msg_evt_t evt, const meshx_config_srv_cb_param_t *params) |
Callback function for configuration client events. | |
static meshx_err_t | relay_cli_prov_srv_msg_handle (const dev_struct_t *pdev, control_task_msg_evt_t evt, const void *params) |
Relay Client Provisioning Server Control Task Message Handler. | |
static meshx_err_t | meshx_relay_cli_send_onoff_msg (const dev_struct_t *pdev, uint16_t element_id, uint8_t set_get, uint8_t ack) |
Sends a relay message over BLE mesh. | |
static meshx_err_t | meshx_relay_client_element_state_change_handler (const dev_struct_t *pdev, control_task_msg_evt_t evt, const meshx_on_off_cli_el_msg_t *param) |
Handles the relay client element message. | |
static meshx_err_t | meshx_relay_client_to_ble_handler (const dev_struct_t *pdev, control_task_msg_evt_t evt, const meshx_gen_on_off_cli_msg_t *msg) |
Relay Client Element Application Request Handler. | |
static meshx_err_t | relay_cli_unit_test_cb_handler (int cmd_id, int argc, char **argv) |
Callback handler for the Relay client unit test command. | |
static meshx_err_t | meshx_relay_cli_reg_app_req_cb () |
Registers a callback handler for relay application requests. | |
static meshx_err_t | meshx_relay_cli_el_state_change_reg_cb () |
Registers a callback for relay element state change events. | |
meshx_err_t | meshx_relay_el_set_state (uint16_t el_id, bool ack) |
Set the On/Off state for a specific element in the BLE mesh network. | |
meshx_err_t | meshx_relay_el_get_state (uint16_t el_id) |
Retrieves the current state of the relay element. | |
meshx_err_t | create_relay_client_elements (dev_struct_t *pdev, uint16_t element_cnt) |
Create Dynamic Relay Model Elements. | |
REG_MESHX_ELEMENT_FN (relay_cli_el, MESHX_ELEMENT_TYPE_RELAY_CLIENT, create_relay_client_elements) | |
Variables | |
static relay_client_element_ctrl_t | relay_element_init_ctrl |
Implementation of the relay client model for BLE Mesh.
Copyright (c) 2024 - 2025 MeshX
This file contains the implementation of the relay client model for BLE Mesh, including initialization, configuration, and event handling.
Definition in file meshx_relay_client.c.
#define CONFIG_SERVER_CB_MASK |
Definition at line 24 of file meshx_relay_client.c.
#define CONTROL_TASK_MSG_CODE_EVT_MASK CONTROL_TASK_MSG_EVT_TO_BLE_SET_ON_OFF |
Definition at line 28 of file meshx_relay_client.c.
#define GET_RELATIVE_EL_IDX | ( | _element_id | ) |
Definition at line 34 of file meshx_relay_client.c.
#define IS_EL_IN_RANGE | ( | _element_id | ) |
Definition at line 35 of file meshx_relay_client.c.
#define MOD_SRC MODULE_ID_ELEMENT_SWITCH_RELAY_CLIENT |
Definition at line 31 of file meshx_relay_client.c.
#define RELAY_CLI_EL | ( | _rel_el_id | ) |
Definition at line 36 of file meshx_relay_client.c.
#define RELAY_CLI_EL_STATE_CH_EVT_MASK CONTROL_TASK_MSG_EVT_EL_STATE_CH_SET_ON_OFF |
Definition at line 32 of file meshx_relay_client.c.
enum relay_cli_cmd_t |
Enumerator | ||
---|---|---|
RELAY_CLI_CMD_GET | 0x00 | |
RELAY_CLI_CMD_SET | 0x01 | |
RELAY_CLI_CMD_SET_UNACK | 0x02 | |
RELAY_CLI_MAX_CMD |
Definition at line 491 of file meshx_relay_client.c.
meshx_err_t create_relay_client_elements | ( | dev_struct_t * | pdev, |
uint16_t | element_cnt ) |
Create Dynamic Relay Model Elements.
[in] | pdev | Pointer to device structure |
[in] | element_cnt | Maximum number of relay models |
Definition at line 635 of file meshx_relay_client.c.
|
static |
Add relay client models to the element list.
Registers the relay client models to the BLE Mesh element list.
[in] | pdev | Pointer to the device structure. |
[in,out] | start_idx | Pointer to the start index of elements. |
[in] | n_max | Maximum number of elements to add. |
Definition at line 172 of file meshx_relay_client.c.
|
static |
Create Dynamic Relay Model Elements.
[in] | pdev | Pointer to device structure |
[in] | n_max | Maximum number of relay models |
Definition at line 145 of file meshx_relay_client.c.
|
static |
Deinitializes the mesh element structure.
This function deinitializes the mesh element structure by freeing the allocated memory.
Definition at line 106 of file meshx_relay_client.c.
|
static |
Initializes the mesh element structure.
This function initializes the mesh element structure with the specified maximum number of elements.
n_max | The maximum number of elements to initialize. |
Definition at line 51 of file meshx_relay_client.c.
|
static |
Registers a callback for relay element state change events.
This function subscribes the provided callback to control task messages related to relay element state changes. It ensures the callback is valid before subscribing.
Definition at line 567 of file meshx_relay_client.c.
|
static |
Registers a callback handler for relay application requests.
This function subscribes the provided callback to control task messages related to BLE events. It ensures the callback is valid before subscribing.
Definition at line 549 of file meshx_relay_client.c.
|
static |
Sends a relay message over BLE mesh.
This function sends a relay message to a specified element in the BLE mesh network.
[in] | pdev | Pointer to the device structure. |
[in] | element_id | The ID of the element to which the message is sent. |
[in] | set_get | Indicates whether the message is a set (0) or get (1) operation. |
[in] | ack | Indicates whether an acknowledgment is required (1) or not (0). |
Definition at line 338 of file meshx_relay_client.c.
|
static |
Handles the relay client element message.
This function processes the relay client element message and updates the state of the relay client model accordingly.
[in] | pdev | Pointer to the device structure. |
[in] | evt | Event type of the control task message. |
[in] | param | Pointer to the parameters of the control task message. |
Definition at line 401 of file meshx_relay_client.c.
|
static |
Relay Client Element Application Request Handler.
This function handles the relay client application requests for setting or getting the On/Off state of the relay element.
[in] | pdev | Pointer to the device structure. |
[in] | evt | Event type of the control task message. |
[in] | msg | Pointer to the parameters of the control task message. |
Definition at line 458 of file meshx_relay_client.c.
meshx_err_t meshx_relay_el_get_state | ( | uint16_t | el_id | ) |
Retrieves the current state of the relay element.
This function constructs a generic On/Off client message to request the current state of a relay element identified by the given element ID. It then publishes this message to the control task for BLE communication.
[in] | el_id | The element ID of the relay whose state is to be retrieved. |
Definition at line 613 of file meshx_relay_client.c.
meshx_err_t meshx_relay_el_set_state | ( | uint16_t | el_id, |
bool | ack ) |
Set the On/Off state for a specific element in the BLE mesh network.
This function sets the On/Off state of the specified element, optionally waiting for an acknowledgment.
[in] | el_id | The ID of the element for which to set the On/Off state. |
[in] | ack | Whether to wait for an acknowledgment (true) or not (false). |
Definition at line 589 of file meshx_relay_client.c.
REG_MESHX_ELEMENT_FN | ( | relay_cli_el | , |
MESHX_ELEMENT_TYPE_RELAY_CLIENT | , | ||
create_relay_client_elements | ) |
|
static |
Relay Client Provisioning Server Control Task Message Handler.
This function handles the CW-WW client control task messages.
[in] | pdev | Pointer to the device structure. |
[in] | evt | Event type of the control task message. |
[in] | params | Pointer to the parameters of the control task message. |
Definition at line 294 of file meshx_relay_client.c.
|
static |
Callback handler for the Relay client unit test command.
This function handles the Relay client unit test command by processing the provided command ID and arguments.
[in] | cmd_id | The command ID to be processed. |
[in] | argc | The number of arguments provided. |
[in] | argv | The array of arguments. |
Definition at line 514 of file meshx_relay_client.c.
|
static |
Callback function for configuration client events.
This function handles events from the configuration client, such as model publication and application binding events.
[in] | pdev | Pointer to the device structure. |
[in] | evt | Event type of the control task message. |
[in] | params | Pointer to the parameters of the control task message. |
Definition at line 231 of file meshx_relay_client.c.
|
static |
Definition at line 38 of file meshx_relay_client.c.