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_txcm.h
Go to the documentation of this file.
1/**
2 * @copyright Copyright © 2024 - 2025 MeshX
3 *
4 * @file meshx_txcm.h
5 * @brief MeshX Tx Control Module
6 * This header file contains the definitions and function prototypes for the MeshX Tx Control Module,
7 * which is responsible for managing transmission control in the MeshX BLE Mesh stack.
8 *
9 * @author Pranjal Chanda
10 *
11 */
12
13#ifndef __MESHX_TXCM_H__
14#define __MESHX_TXCM_H__
15
16#include <stdint.h>
17#include <stddef.h>
18#include "meshx_err.h"
19#include "meshx_common.h"
20#include "meshx_control_task.h"
22
23/**
24 * @brief Maximum number of retries for a message.
25 */
26#ifndef MESHX_TXCM_MSG_RETRY_MAX
27#define MESHX_TXCM_MSG_RETRY_MAX 3
28#endif /* MESHX_TXCM_MSG_RETRY_MAX */
29
30/**
31 * @brief Maximum length of the message parameters in bytes.
32 */
33#ifndef MESHX_TXCM_MSG_PARAM_MAX_LEN
34#define MESHX_TXCM_MSG_PARAM_MAX_LEN 64
35#endif /* MESHX_TXCM_MSG_PARAM_MAX_LEN */
36
37/**
38 * @brief Maximum number of transmission items in the Tx queue.
39 */
40#ifndef MESHX_TXCM_TX_Q_LEN
41#define MESHX_TXCM_TX_Q_LEN 10
42#endif
43
44/**
45 * @brief Depth (size) of each transmission queue entry.
46 */
47#define MESHX_TXCM_TX_Q_DEPTH sizeof(meshx_txcm_tx_q_t)
48
50/**
51 * @brief Enumeration of signal types for the Tx Control Module.
52 *
53 * This enumeration defines the different types of signals that can be sent to the Tx Control Module,
54 * each representing a different type of transmission command.
55 */
56typedef enum
57{
58 MESHX_TXCM_SIG_ENQ_SEND = 0, /**< Signal to enqueue a transmission command */
59 MESHX_TXCM_SIG_DIRECT_SEND = 1, /**< Signal to directly send a transmission command without queuing */
60 MESHX_TXCM_SIG_RESEND = 2, /**< Signal to resend the last transmission queued message */
61 MESHX_TXCM_SIG_ACK = 3, /**< Signal to acknowledge the last transmission message */
62 MESHX_TXCM_SIG_MAX, /**< Maximum signal type value */
64
65/**
66 * @brief Enumeration of message states for the Tx Control Module.
67 *
68 * This enumeration defines the different states a message can be in during transmission,
69 * including new messages, waiting for acknowledgment, acknowledged messages, and the maximum state value.
70 */
71typedef enum
72{
73 MESHX_TXCM_MSG_STATE_NONE = 0, /**< New message state */
74 MESHX_TXCM_MSG_STATE_NEW = 1, /**< New message state */
75 MESHX_TXCM_MSG_STATE_SENDING = 2, /**< Message sending state */
76 MESHX_TXCM_MSG_STATE_WAITING_ACK = 3, /**< Message waiting for acknowledgment state */
77 MESHX_TXCM_MSG_STATE_ACK = 4, /**< Message acknowledged state */
78 MESHX_TXCM_MSG_STATE_NACK = 5, /**< Message not acknowledged state */
81
88/**
89 * @brief Function pointer the Model client layer needs to provide for the msg to be sent for both MESHX_TXCM_SIG_ENQ_SEND and MESHX_TXCM_SIG_DIRECT_SEND
90 *
91 * @param[in] msg_param Pointer to the model specific parameter structure
92 * @param[in] msg_param_len Length of the msg_param
93 */
94typedef meshx_err_t (*meshx_txcm_fn_model_send_t)(meshx_cptr_t msg_param, size_t msg_param_len);
95
96/**
97 * @brief Structure for Tx Control module requests.
98 *
99 * This structure holds the details of a transmission request, including the type of signal,
100 * the send function callback, and parameters for the message to be transmitted.
101 */
102typedef struct meshx_txcm_request
103{
104 uint16_t dest_addr; /**< Destination address of the message */
105 uint16_t msg_param_len; /**< Length of the msg_param */
106 meshx_ptr_t msg_param; /**< Pointer to model specific parameter structure */
107 meshx_txcm_sig_t request_type; /**< Type of transmission command request */
108 meshx_txcm_fn_model_send_t send_fn; /**< Function pointer to the model-specific send function */
110
111#ifdef __cplusplus
112extern "C" {
113#endif
114
115/**
116 * @brief Initializes the MeshX Tx Control Module.
117 *
118 * This function sets up the transmission control module for MeshX. It checks if the module
119 * has already been initialized using an initialization magic value. If not initialized,
120 * it sets the magic value, assigns the provided device structure to the task argument,
121 * and creates the Tx Control task.
122 *
123 * @param[in] pdev Pointer to the device structure to be used by the Tx Control Module.
124 *
125 * @return
126 * - MESHX_SUCCESS on successful initialization or if already initialized.
127 * - Error code (meshx_err_t) if task creation fails.
128 */
130
131/**
132 * @brief Sends a request to the Tx Control module.
133 *
134 * This function sends a request to the Tx Control module with the specified parameters.
135 * It creates a new request structure, copies the message parameters, and sends the request
136 * to the signal queue of the Tx Control module.
137 *
138 * @param[in] request_type Type of the request (ACK, RESEND, ENQ_SEND, DIRECT_SEND)
139 * @param[in] dest_addr Destination address of the message
140 * @param[in] msg_param Pointer to the message parameters
141 * @param[in] msg_param_len Length of the message parameters
142 * @param[in] send_fn Function pointer to the send function to be used for the request
143 *
144 * @return meshx_err_t
145 */
147 meshx_txcm_sig_t request_type,
148 uint16_t dest_addr,
149 meshx_cptr_t msg_param,
150 uint16_t msg_param_len,
152);
153
154/**
155 * @brief Registers a callback function for handling Tx Control module events.
156 *
157 * This function registers a callback function to handle specific events from the Tx Control module.
158 * The callback will be invoked when the specified event occurs.
159 *
160 * @param[in] event_cb Pointer to the callback function to be registered for event handling.
161 *
162 * @return meshx_err_t
163 * - MESHX_SUCCESS on successful registration.
164 * - Error code (meshx_err_t) if registration fails.
165 */
167
168#ifdef __cplusplus
169}
170#endif
171
172#endif /* __MESHX_TXCM_H__ */
Common definitions for BLE Mesh models and opcodes in the MeshX framework.
void * meshx_ptr_t
Definition meshx_ble_mesh_cmn_def.h:636
const void * meshx_cptr_t
Definition meshx_ble_mesh_cmn_def.h:637
Common application definitions and includes for BLE Mesh Node.
struct dev_struct dev_struct_t
Structure representing the device composition and elements.
Header file for the control task in the BLE mesh node application.
meshx_err_t(* control_task_msg_handle_t)(dev_struct_t *pdev, control_task_msg_evt_t evt, void *params)
Function pointer type for control task message handler.
Definition meshx_control_task.h:188
MeshX Error Codes.
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
meshx_err_t meshx_txcm_init(dev_struct_t *pdev)
Initializes the MeshX Tx Control Module.
Definition meshx_txcm.c:628
meshx_err_t meshx_txcm_request_send(meshx_txcm_sig_t request_type, uint16_t dest_addr, meshx_cptr_t msg_param, uint16_t msg_param_len, meshx_txcm_fn_model_send_t send_fn)
Sends a request to the Tx Control module.
Definition meshx_txcm.c:672
control_task_msg_handle_t meshx_txcm_cb_t
Definition meshx_txcm.h:49
struct meshx_txcm_request meshx_txcm_request_t
Structure for Tx Control module requests.
meshx_txcm_sig_t
Enumeration of signal types for the Tx Control Module.
Definition meshx_txcm.h:57
@ MESHX_TXCM_SIG_ENQ_SEND
Definition meshx_txcm.h:58
@ MESHX_TXCM_SIG_DIRECT_SEND
Definition meshx_txcm.h:59
@ MESHX_TXCM_SIG_ACK
Definition meshx_txcm.h:61
@ MESHX_TXCM_SIG_RESEND
Definition meshx_txcm.h:60
@ MESHX_TXCM_SIG_MAX
Definition meshx_txcm.h:62
meshx_txcm_msg_state_t
Enumeration of message states for the Tx Control Module.
Definition meshx_txcm.h:72
@ MESHX_TXCM_MSG_STATE_SENDING
Definition meshx_txcm.h:75
@ MESHX_TXCM_MSG_STATE_NACK
Definition meshx_txcm.h:78
@ MESHX_TXCM_MSG_STATE_NONE
Definition meshx_txcm.h:73
@ MESHX_TXCM_MSG_STATE_NEW
Definition meshx_txcm.h:74
@ MESHX_TXCM_MSG_STATE_ACK
Definition meshx_txcm.h:77
@ MESHX_TXCM_MSG_STATE_WAITING_ACK
Definition meshx_txcm.h:76
@ MESHX_TXCM_MSG_STATE_MAX
Definition meshx_txcm.h:79
meshx_txcm_msg_type_t
Definition meshx_txcm.h:83
@ MESHX_TXCM_MSG_TYPE_UNACKED
Definition meshx_txcm.h:85
@ MESHX_TXCM_MSG_TYPE_MAX
Definition meshx_txcm.h:86
@ MESHX_TXCM_MSG_TYPE_ACKED
Definition meshx_txcm.h:84
meshx_err_t(* meshx_txcm_fn_model_send_t)(meshx_cptr_t msg_param, size_t msg_param_len)
Function pointer the Model client layer needs to provide for the msg to be sent for both MESHX_TXCM_S...
Definition meshx_txcm.h:94
meshx_err_t meshx_txcm_event_cb_reg(meshx_txcm_cb_t event_cb)
Registers a callback function for handling Tx Control module events.
Definition meshx_txcm.c:734
Structure for Tx Control module requests.
Definition meshx_txcm.h:103
uint16_t dest_addr
Definition meshx_txcm.h:104
meshx_ptr_t msg_param
Definition meshx_txcm.h:106
meshx_txcm_sig_t request_type
Definition meshx_txcm.h:107
meshx_txcm_fn_model_send_t send_fn
Definition meshx_txcm.h:108
uint16_t msg_param_len
Definition meshx_txcm.h:105