-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_ble_service.h
192 lines (160 loc) · 5.76 KB
/
simple_ble_service.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// based on the ble_peripheral example in RTL8762C-sdk-gcc-v0.0.5.zip
// <https://www.realmcu.com/en/Home/Product/93cc0582-3a3f-4ea8-82ea-76c6504e478a>
// modified by wuwbobo2021 <https://github.com/wuwbobo2021>, <[email protected]>
/* Define to prevent recursive inclusion */
#ifndef _SIMPLE_BLE_SERVICE_H_
#define _SIMPLE_BLE_SERVICE_H_
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* Add Includes here */
#include <profile_server.h>
/** @defgroup SIMP_Service Simple Ble Service
* @brief Simple BLE service
* @{
*/
/*============================================================================*
* Macros
*============================================================================*/
/** @defgroup SIMP_Service_Exported_Macros SIMP Service Exported Macros
* @brief
* @{
*/
/** @defgroup SIMP_UUIDs SIMP UUIDs
* @brief Simple BLE Profile UUID definitions
* @{
*/
#define GATT_UUID_SIMPLE_PROFILE 0xA00A
#define GATT_UUID_CHAR_SIMPLE_V1_CONFIG 0xB001
#define GATT_UUID_CHAR_SIMPLE_V2_WRITE 0xB002
#define GATT_UUID_CHAR_SIMPLE_V3_NOTIFY 0xB003
/** @} End of SIMP_UUIDs */
/** @defgroup SIMP_Service_Application_Parameters SIMP Service Application Parameters
* @brief Type of parameters set/got from application.
* @{
*/
typedef enum
{
SIMPLE_BLE_SERVICE_PARAM_V1_READ_CHAR_VAL = 0x01,
} T_SIMP_PARAM_TYPE;
/** @} */
/** @defgroup SIMP_Service_Upstream_Message SIMP Service Upstream Message
* @brief Upstream message used to inform application.
* @{
*/
/** @defgroup SIMP_Service_Read_Info SIMP Service Config Info
* @brief Parameter for configuration characteristic value.
* @{
*/
#define SIMP_CONFIG_V1 1
/** @} */
/** @defgroup SIMP_Service_Write_Info SIMP Service Write Info
* @brief Parameter for writing characteristic value.
* @{
*/
#define SIMP_WRITE_V2 2
/** @} */
/** @defgroup SIMP_Service_Notify_Indicate_Info SIMP Service Notify Info
* @brief Parameter for enable or disable notification or indication.
* @{
*/
#define SIMP_NOTIFY_V3_ENABLE 1
#define SIMP_NOTIFY_V3_DISABLE 2
/** @} */
#define SIMP_CONFIG_V1_MAX_LEN 300
/** @} End of SIMP_Service_Upstream_Message */
// indexes in the service's attribute table
#define SIMPLE_BLE_SERVICE_CHAR_V1_CONFIG_INDEX 0x02
#define SIMPLE_BLE_SERVICE_CHAR_V2_WRITE_INDEX 0x05
#define SIMPLE_BLE_SERVICE_CHAR_V3_NOTIFY_INDEX 0x07
#define SIMPLE_BLE_SERVICE_CHAR_NOTIFY_CCCD_INDEX (SIMPLE_BLE_SERVICE_CHAR_V3_NOTIFY_INDEX + 1)
/** @} End of SIMP_Service_Exported_Macros */
/*============================================================================*
* Types
*============================================================================*/
/** @defgroup SIMP_Service_Exported_Types SIMP Service Exported Types
* @brief
* @{
*/
/** @defgroup TSIMP_WRITE_MSG TSIMP_WRITE_MSG
* @brief Simple BLE service written msg to application.
* @{
*/
typedef struct
{
uint8_t opcode; //!< ref: @ref SIMP_Service_Write_Info
T_WRITE_TYPE write_type;
uint16_t len;
uint8_t *p_value;
} TSIMP_WRITE_MSG;
/** @} End of TSIMP_WRITE_MSG */
/** @defgroup TSIMP_UPSTREAM_MSG_DATA TSIMP_UPSTREAM_MSG_DATA
* @brief Simple BLE service callback message content.
* @{
*/
typedef union
{
uint8_t notification_indification_index; //!< ref: @ref SIMP_Service_Notify_Indicate_Info
uint8_t read_value_index; //!< ref: @ref SIMP_Service_Read_Info
TSIMP_WRITE_MSG write;
} TSIMP_UPSTREAM_MSG_DATA;
/** @} End of TSIMP_UPSTREAM_MSG_DATA */
/** @defgroup TSIMP_CALLBACK_DATA TSIMP_CALLBACK_DATA
* @brief Simple BLE service data to inform application.
* @{
*/
typedef struct
{
uint8_t conn_id;
T_SERVICE_CALLBACK_TYPE msg_type;
TSIMP_UPSTREAM_MSG_DATA msg_data;
} TSIMP_CALLBACK_DATA;
/** @} End of TSIMP_CALLBACK_DATA */
/** @} End of SIMP_Service_Exported_Types */
/*============================================================================*
* Functions
*============================================================================*/
/** @defgroup SIMP_Service_Exported_Functions SIMP Service Exported Functions
* @brief
* @{
*/
/**
* @brief Add simple BLE service to the BLE stack database.
*
* @param[in] p_func Callback when service attribute was read, write or cccd update.
* @return Service id generated by the BLE stack: @ref T_SERVER_ID.
* @retval 0xFF Operation failure.
* @retval others Service id assigned by stack.
*
*/
T_SERVER_ID simp_ble_service_add_service(void *p_func);
/**
* @brief Set service related data from application.
*
* @param[in] param_type parameter type to set.
* @param[in] len value length to be set.
* @param[in] p_value value to set.
* @return parameter set result.
* @retval 0 false
* @retval 1 true
*/
bool simp_ble_service_set_parameter(T_SIMP_PARAM_TYPE param_type, uint16_t len, void *p_value);
/**
* @brief send notification of simple notify characteristic value.
*
* @param[in] conn_id connection id
* @param[in] service_id service ID of service.
* @param[in] p_value characteristic value to notify
* @param[in] length characteristic value length to notify
* @return notification action result
* @retval 1 true
* @retval 0 false
*/
bool simp_ble_service_send_v3_notify(uint8_t conn_id, T_SERVER_ID service_id,
void *p_value, uint16_t length);
/** @} End of SIMP_Service_Exported_Functions */
/** @} End of SIMP_Service */
#ifdef __cplusplus
}
#endif
#endif /* _SIMPLE_BLE_SERVICE_H_ */