Skip to content

Commit 5031c50

Browse files
committed
Merge branch 'feature/aeg-1989' into 'master'
feat(ble_services): Support Body Composition Service Closes AEG-1989 See merge request ae_group/esp-iot-solution!1173
2 parents 7fdbb77 + 26328df commit 5031c50

File tree

29 files changed

+638
-13
lines changed

29 files changed

+638
-13
lines changed

.gitlab/ci/rules.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@
331331
- "components/bluetooth/ble_hci/include/ble_hci.h"
332332
- "components/bluetooth/ble_services/ans/include/esp_ans.h"
333333
- "components/bluetooth/ble_services/bas/include/esp_bas.h"
334+
- "components/bluetooth/ble_services/bcs/include/esp_bcs.h"
334335
- "components/bluetooth/ble_services/dis/include/esp_dis.h"
335336
- "components/bluetooth/ble_services/hrs/include/esp_hrs.h"
336337
- "components/bluetooth/ble_services/hts/include/esp_hts.h"

components/bluetooth/ble_services/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v0.2.0 - 2024.10.31
2+
3+
Features:
4+
- BCS: Support Body Composition Service
5+
16
## v0.1.0
27

38
This is the first release version for BLE services component in Espressif Component Registry, more detailed descriptions about the project, please refer to [User_Guide](https://docs.espressif.com/projects/espressif-esp-iot-solution/en/latest/bluetooth/ble_services.html).

components/bluetooth/ble_services/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ list(APPEND srcs "tps/src/esp_tps.c")
3434
list(APPEND include "tps/include")
3535
endif()
3636

37+
if(CONFIG_BLE_BCS)
38+
list(APPEND srcs "bcs/src/esp_bcs.c")
39+
list(APPEND include "bcs/include")
40+
endif()
41+
3742
list(APPEND req "ble_conn_mgr")
3843

3944
idf_component_register(SRCS "${srcs}"

components/bluetooth/ble_services/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
menu "BLE Standard Services"
22

33
orsource "./ans/Kconfig.in"
4-
orsource "./dis/Kconfig.in"
54
orsource "./bas/Kconfig.in"
5+
orsource "./bcs/Kconfig.in"
6+
orsource "./dis/Kconfig.in"
67
orsource "./hrs/Kconfig.in"
78
orsource "./hts/Kconfig.in"
89
orsource "./tps/Kconfig.in"

components/bluetooth/ble_services/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ The example will be downloaded to the current folder. You can navigate into it f
2828
> You can use this command to download other examples. Or you can download examples from esp-iot-solution repository:
2929
1. [ble_ans](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_ans)
3030
2. [ble_bas](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_bas)
31-
3. [ble_dis](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_dis)
32-
4. [ble_hrs](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_hrs)
33-
5. [ble_hts](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_hts)
34-
5. [ble_tps](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_tps)
31+
3. [ble_bcs](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_bcs)
32+
4. [ble_dis](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_dis)
33+
5. [ble_hrs](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_hrs)
34+
6. [ble_hts](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_hts)
35+
7. [ble_tps](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_tps)
3536

3637
### Q&A
3738

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Body Composition Service
2+
3+
menuconfig BLE_BCS
4+
bool "GATT Body Composition Service"
5+
6+
if BLE_BCS
7+
8+
config BLE_BCS_FEATURE_INDICATE_ENABLE
9+
bool "Body Composition Feature Indication"
10+
default n
11+
help
12+
Set y to support Indication or n to disable it.
13+
14+
endif # BLE_BCS
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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 "esp_err.h"
10+
11+
#ifdef __cplusplus
12+
extern "C"
13+
{
14+
#endif
15+
16+
/* Maximum Attribute Value Length */
17+
#define BLE_BCS_MAX_VAL_LEN 100
18+
19+
/* 16 Bit Body Composition Service UUID */
20+
#define BLE_BCS_UUID16 0x181B
21+
22+
/* 16 Bit Body Composition Characteristic UUIDs */
23+
#define BLE_BCS_CHR_UUID16_FEATURE 0x2A9B
24+
#define BLE_BCS_CHR_UUID16_MEASUREMENT 0x2A9C
25+
26+
/* Body Composition Feature Bit Masks */
27+
#define BLE_BCS_FEAT_TIME_STAMP (0x1 << 0) //bit0 Time Stamp(0-Don't support, 1-Support)
28+
#define BLE_BCS_FEAT_MULTI_USER (0x1 << 1) //bit1 User ID(0-Don't support, 1-Support)
29+
#define BLE_BCS_FEAT_BASAL_METABOLISM (0x1 << 2) //bit2 Basal Metabolism(0-Don't support, 1-Support)
30+
#define BLE_BCS_FEAT_MUSCLE_PERCENTAGE (0x1 << 3) //bit3 Muscle Percentage(0-Don't support, 1-Support)
31+
#define BLE_BCS_FEAT_MUSCLE_MASS (0x1 << 4) //bit4 Muscle Mass(0-Don't support, 1-Support)
32+
#define BLE_BCS_FEAT_FAT_FREE_MASS (0x1 << 5) //bit5 Fat Free Mass(0-Don't support, 1-Support)
33+
#define BLE_BCS_FEAT_SOFT_LEAN_MASS (0x1 << 6) //bit6 Soft Lean Mass(0-Don't support, 1-Support)
34+
#define BLE_BCS_FEAT_BODY_WATER_MASS (0x1 << 7) //bit7 Body Water Mass(0-Don't support, 1-Support)
35+
#define BLE_BCS_FEAT_IMPEDENCE (0x1 << 8) //bit8 Impedance(0-Don't support, 1-Support)
36+
#define BLE_BCS_FEAT_WEIGHT (0x1 << 9) //bit9 Weight(0-Don't support, 1-Support)
37+
#define BLE_BCS_FEAT_HEIGHT (0x1 << 10) //bit10 Height(0-Don't support, 1-Support)
38+
#define BLE_BCS_FEAT_MASS_MEASUREMENT_RESOLUTION (0x1 << 11) //bit11-bit14 Weight Resolution (000-undefine, 001-0.5kg or 1lb, 002-0.2kg or 0.5lb, 003-0.1kg or 0.2lb, 004-0.05kg or 0.1lb, 005-0.02kg or 0.05lb, 006-0.01kg or 0.02lb, 007-0.005kg or 0.01lb);
39+
#define BLE_BCS_FEAT_HEIGHT_RESOLUTION (0x1 << 15) //bit15-bit17 Height Resolution (000-undefine, 001-0.01m or 1ft, 002-0.005m or 0.5ft, 003-0.001m or 0.1ft);
40+
41+
/* Body Composition Measurement Flags Bit Masks */
42+
#define BLE_BCS_FLAG_MEASUREMENT_UNITS (0x1 << 0) //bit0 Measurement Units
43+
#define BLE_BCS_FLAG_TIME_STAMP (0x1 << 1) //bit1 Time Stamp
44+
#define BLE_BCS_FLAG_MULTI_USER (0x1 << 2) //bit2 User ID
45+
#define BLE_BCS_FLAG_BASAL_METABOLISM (0x1 << 3) //bit3 Basal Metabolism
46+
#define BLE_BCS_FLAG_MUSCLE_PERCENTAGE (0x1 << 4) //bit4 Muscle Percentage
47+
#define BLE_BCS_FLAG_MUSCLE_MASS (0x1 << 5) //bit5 Muscle Mass
48+
#define BLE_BCS_FLAG_FAT_FREE_MASS (0x1 << 6) //bit6 Fat Free Mass
49+
#define BLE_BCS_FLAG_SOFT_LEAN_MASS (0x1 << 7) //bit7 Soft Lean Mass
50+
#define BLE_BCS_FLAG_BODY_WATER_MASS (0x1 << 8) //bit8 Body Water Mass
51+
#define BLE_BCS_FLAG_IMPEDENCE (0x1 << 9) //bit9 Impedance
52+
#define BLE_BCS_FLAG_WEIGHT (0x1 << 10) //bit10 Weight
53+
#define BLE_BCS_FLAG_HEIGHT (0x1 << 11) //bit11 Height
54+
#define BLE_BCS_FLAG_MULTIPLE_PACKET (0x1 << 12) //bit12 Multiple Packet
55+
56+
/**
57+
* @brief Body Composition Measurement Characteristic
58+
*/
59+
typedef struct {
60+
uint32_t bcs_flag; /*!< Body Composition flag field */
61+
62+
struct {
63+
uint16_t year; /*!< Year as defined by the Gregorian calendar, Valid range 1582 to 9999 */
64+
uint8_t month; /*!< Month of the year as defined by the Gregorian calendar, Valid range 1 (January) to 12 (December) */
65+
uint8_t day; /*!< Day of the month as defined by the Gregorian calendar, Valid range 1 to 31 */
66+
uint8_t hours; /*!< Number of hours past midnight, Valid range 0 to 23 */
67+
uint8_t minutes; /*!< Number of minutes since the start of the hour. Valid range 0 to 59 */
68+
uint8_t seconds; /*!< Number of seconds since the start of the minute. Valid range 0 to 59 */
69+
} __attribute__((packed)) timestamp; /*!< The date and time */
70+
71+
uint8_t user_id; /*!< User ID field */
72+
uint16_t basal_metabolism; /*!< Basal Metabolism field */
73+
uint16_t muscle_percentage; /*!< Muscle Percentage field */
74+
uint16_t muscle_mass; /*!< Muscle Mass field */
75+
uint16_t fat_free_mass; /*!< Fat Free Mass field */
76+
uint16_t soft_lean_mass; /*!< Soft Lean Mass field */
77+
uint16_t body_water_mass; /*!< Body Water Mass field */
78+
uint8_t impedance; /*!< Impedance field */
79+
uint16_t weight; /*!< Weight field */
80+
uint16_t height; /*!< Height field */
81+
} __attribute__((packed)) esp_bcs_val_t;
82+
83+
/**
84+
* @brief Set the Body Componsition value.
85+
*
86+
* @param[in] in_val The pointer to store the Body Componsition Information.
87+
*
88+
* @param[in] need_send If set to true, the Body Componsition Info will send to remote client.
89+
*
90+
* @return
91+
* - ESP_OK on successful
92+
* - ESP_ERR_INVALID_ARG on wrong initialization
93+
* - ESP_FAIL on error
94+
*/
95+
esp_err_t esp_ble_bcs_set_measurement(esp_bcs_val_t *in_val, bool need_send);
96+
97+
/**
98+
* @brief Initialization Body Componsion Service
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_bcs_init(void);
106+
107+
#ifdef __cplusplus
108+
}
109+
#endif

0 commit comments

Comments
 (0)