Skip to content

Commit dfc210d

Browse files
committed
Merge branch 'feature/aeg-1987' into 'master'
feat(ble_services): Support User Data Service Closes AEG-1987 See merge request ae_group/esp-iot-solution!1174
2 parents 2fa346b + 005f18b commit dfc210d

File tree

31 files changed

+815
-9
lines changed

31 files changed

+815
-9
lines changed

.gitlab/ci/build.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,19 @@ build_example_bluetooth_ble_services_ble_dis:
198198
variables:
199199
EXAMPLE_DIR: examples/bluetooth/ble_services/ble_dis
200200

201+
build_example_bluetooth_ble_services_ble_bcs:
202+
extends:
203+
- .build_examples_template
204+
- .rules:build:example_bluetooth_ble_services
205+
parallel:
206+
matrix:
207+
- IMAGE: espressif/idf:release-v4.4
208+
- IMAGE: espressif/idf:release-v5.0
209+
- IMAGE: espressif/idf:release-v5.1
210+
- IMAGE: espressif/idf:release-v5.2
211+
variables:
212+
EXAMPLE_DIR: examples/bluetooth/ble_services/ble_bcs
213+
201214
build_example_bluetooth_ble_services_ble_hrs:
202215
extends:
203216
- .build_examples_template
@@ -237,6 +250,19 @@ build_example_bluetooth_ble_services_ble_tps:
237250
variables:
238251
EXAMPLE_DIR: examples/bluetooth/ble_services/ble_tps
239252

253+
build_example_bluetooth_ble_services_ble_uds:
254+
extends:
255+
- .build_examples_template
256+
- .rules:build:example_bluetooth_ble_services
257+
parallel:
258+
matrix:
259+
- IMAGE: espressif/idf:release-v4.4
260+
- IMAGE: espressif/idf:release-v5.0
261+
- IMAGE: espressif/idf:release-v5.1
262+
- IMAGE: espressif/idf:release-v5.2
263+
variables:
264+
EXAMPLE_DIR: examples/bluetooth/ble_services/ble_uds
265+
240266
build_example_bluetooth_ble_ota:
241267
extends:
242268
- .build_examples_template

components/bluetooth/ble_services/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ list(APPEND srcs "bcs/src/esp_bcs.c")
3939
list(APPEND include "bcs/include")
4040
endif()
4141

42+
if(CONFIG_BLE_UDS)
43+
list(APPEND srcs "uds/src/esp_uds.c")
44+
list(APPEND include "uds/include")
45+
endif()
46+
4247
list(APPEND req "ble_conn_mgr")
4348

4449
idf_component_register(SRCS "${srcs}"

components/bluetooth/ble_services/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ menu "BLE Standard Services"
77
orsource "./hrs/Kconfig.in"
88
orsource "./hts/Kconfig.in"
99
orsource "./tps/Kconfig.in"
10+
orsource "./uds/Kconfig.in"
1011

1112
endmenu

components/bluetooth/ble_services/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The example will be downloaded to the current folder. You can navigate into it f
3333
5. [ble_hrs](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_hrs)
3434
6. [ble_hts](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_hts)
3535
7. [ble_tps](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_tps)
36+
8. [ble_uds](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_uds)
3637

3738
### Q&A
3839

components/bluetooth/ble_services/bcs/Kconfig.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if BLE_BCS
77

88
config BLE_BCS_FEATURE_INDICATE_ENABLE
99
bool "Body Composition Feature Indication"
10-
default n
10+
default y
1111
help
1212
Set y to support Indication or n to disable it.
1313

components/bluetooth/ble_services/bcs/src/esp_bcs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "esp_ble_conn_mgr.h"
1414
#include "esp_bcs.h"
15+
#include "esp_log.h"
1516

1617
typedef struct {
1718
uint8_t len;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# User Data Service
2+
3+
menuconfig BLE_UDS
4+
bool "GATT User Data Service"
5+
6+
if BLE_UDS
7+
8+
config BLE_UDS_CHARACTERISTIC_ENABLE
9+
bool "User Data Service Characteristic"
10+
default n
11+
help
12+
Set y to support UDS characteristic or n to disable it.
13+
14+
config BLE_UDS_FEATURE_DB_CHG_NTF_ENABLE
15+
bool "UDS Databash change Increment Notification"
16+
default n
17+
help
18+
Set y to support Notification or n to disable it.
19+
20+
config BLE_UDS_REGISTER_USER_ENABLE
21+
bool "Body Composition Feature Indication"
22+
default n
23+
help
24+
Set y to support Registered or n to disable it.
25+
26+
endif # BLE_UDS
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include <stdbool.h>
10+
#include <stdint.h>
11+
12+
#include "esp_err.h"
13+
#include "esp_event_base.h"
14+
15+
#ifdef __cplusplus
16+
extern "C"
17+
{
18+
#endif
19+
20+
/** @cond **/
21+
/* BLE UDS EVENTS BASE */
22+
ESP_EVENT_DECLARE_BASE(BLE_UDS_EVENTS);
23+
/** @endcond **/
24+
25+
/* UDS Characteristic Value Length */
26+
#define BLE_UDS_ATT_VAL_LEN 20 /*!< Attribute value length */
27+
#define BLE_UDS_USER_CTRL_POINT_PARAM_LEN 18 /*!< User control point param length */
28+
29+
/* 16 Bit USER DATA Service UUID */
30+
#define BLE_UDS_UUID16 0x181C
31+
32+
/* 16 Bit User Data Characteristics UUIDs */
33+
#define BLE_UDS_CHR_UUID16_DATABASH_CHG 0x2A99
34+
#define BLE_UDS_CHR_UUID16_USER_INDEX 0x2A9A
35+
#define BLE_UDS_CHR_UUID16_USER_CTRL 0x2A9F
36+
#define BLE_UDS_CHR_UUID16_REG_USER 0x2B37
37+
38+
/* User Control Point characteristic OP-Code */
39+
#define BLE_UDS_USER_CTRL_REG_NEW_OP 0x01
40+
#define BLE_UDS_USER_CTRL_CONSENT_OP 0x02
41+
#define BLE_UDS_USER_CTRL_DEL_DATA_OP 0x03
42+
#define BLE_UDS_USER_CTRL_LIST_ALL_OP 0x04
43+
#define BLE_UDS_USER_CTRL_DEL_USER_OP 0x05
44+
#define BLE_UDS_USER_CTRL_RSP_OP 0x20
45+
46+
/**
47+
* @brief Database Change Increment
48+
*/
49+
typedef struct {
50+
uint8_t len; /*!< Database buffer length */
51+
uint8_t db_buf[BLE_UDS_ATT_VAL_LEN]; /*!< Database buffer */
52+
} esp_ble_uds_db_t;
53+
54+
/**
55+
* @brief Register User Characteristic
56+
*/
57+
typedef struct {
58+
struct {
59+
uint8_t first_segment: 1; /*!< 0: False, 1: True */
60+
uint8_t last_segment: 1; /*!< 0: False, 1: True */
61+
uint8_t rolling_segment_number: 6; /*!< When the Rolling segment number is equal to 63, the value is reset to 0 the next time it is incremented */
62+
} header; /*!< The structure of the Segmentation Header field */
63+
64+
struct {
65+
uint8_t user_name_present: 1; /*!< 0: False, 1: True */
66+
uint8_t user_name_truncated: 1; /*!< 0: False, 1: True */
67+
} flag; /*!< Defines the value of the flags field that a server shall use when the register user characteristic is indicate */
68+
69+
uint8_t user_index; /*!< User ID Index*/
70+
uint8_t user_name[BLE_UDS_ATT_VAL_LEN]; /*!< User name*/
71+
} __attribute__((packed)) esp_ble_uds_reg_user_t;
72+
73+
/**
74+
* @brief User Control Point
75+
*/
76+
typedef struct {
77+
uint8_t op_code; /*!< User control point opcode */
78+
uint8_t param_len; /*!< Parameter buffer length */
79+
uint8_t parameter[BLE_UDS_USER_CTRL_POINT_PARAM_LEN]; /*!< Parameter depend on opcode */
80+
} esp_ble_uds_user_ctrl_t;
81+
82+
/**
83+
* @brief Read the value of Database Change Increment characteristic.
84+
*
85+
* @param[in] out_val The pointer to store the Database Change Increment.
86+
*
87+
* @return
88+
* - ESP_OK on successful
89+
* - ESP_ERR_INVALID_ARG on wrong parameter
90+
*/
91+
esp_err_t esp_ble_uds_get_db_incre(esp_ble_uds_db_t *out_val);
92+
93+
/**
94+
* @brief Set the Database Change Increment characteristic value.
95+
*
96+
* @param[in] in_val The pointer to store the Database Change Increment Information.
97+
*
98+
* @param[in] need_send If set to true, the User Data Info will send to remote client.
99+
*
100+
* @return
101+
* - ESP_OK on successful
102+
* - ESP_ERR_INVALID_ARG on wrong initialization
103+
* - ESP_FAIL on error
104+
*/
105+
esp_err_t esp_ble_uds_set_db_incre(esp_ble_uds_db_t *in_val, bool need_send);
106+
107+
/**
108+
* @brief Read the value of User Control characteristic.
109+
*
110+
* @param[in] out_val The pointer to store the User Control value.
111+
*
112+
* @return
113+
* - ESP_OK on successful
114+
* - ESP_ERR_INVALID_ARG on wrong parameter
115+
*/
116+
esp_err_t esp_ble_uds_get_user_ctrl(esp_ble_uds_user_ctrl_t *out_val);
117+
118+
/**
119+
* @brief Set the User Control Point characteristic value.
120+
*
121+
* @param[in] in_val The pointer to store the User Control Value.
122+
*
123+
* @param[in] need_send If set to true, the User Control Value will send to remote client.
124+
*
125+
* @return
126+
* - ESP_OK on successful
127+
* - ESP_ERR_INVALID_ARG on wrong initialization
128+
* - ESP_FAIL on error
129+
*/
130+
esp_err_t esp_ble_uds_set_user_ctrl(esp_ble_uds_user_ctrl_t *in_val, bool need_send);
131+
132+
/**
133+
* @brief Read the value of Register User characteristic.
134+
*
135+
* @param[in] out_val The pointer to store the Register User value.
136+
*
137+
* @return
138+
* - ESP_OK on successful
139+
* - ESP_ERR_INVALID_ARG on wrong parameter
140+
*/
141+
esp_err_t esp_ble_uds_get_reg_user(esp_ble_uds_reg_user_t *out_val);
142+
143+
/**
144+
* @brief Set the Register User characteristic value.
145+
*
146+
* @param[in] in_val The pointer to store the Register User Value.
147+
*
148+
* @param[in] need_send If set to true, the Register User Value will send to remote client.
149+
*
150+
* @return
151+
* - ESP_OK on successful
152+
* - ESP_ERR_INVALID_ARG on wrong initialization
153+
* - ESP_FAIL on error
154+
*/
155+
esp_err_t esp_ble_uds_set_reg_user(esp_ble_uds_reg_user_t *in_val, bool need_send);
156+
157+
/**
158+
* @brief Initialization User Data Service
159+
*
160+
* @return
161+
* - ESP_OK on successful
162+
* - ESP_ERR_INVALID_ARG on wrong initialization
163+
* - ESP_FAIL on error
164+
*/
165+
esp_err_t esp_ble_uds_init(void);
166+
167+
#ifdef __cplusplus
168+
}
169+
#endif

0 commit comments

Comments
 (0)