Skip to content

Commit

Permalink
Merge branch 'feature/aeg-1989' into 'master'
Browse files Browse the repository at this point in the history
feat(ble_services): Support Body Composition Service

Closes AEG-1989

See merge request ae_group/esp-iot-solution!1173
  • Loading branch information
lhespress committed Dec 20, 2024
2 parents 7fdbb77 + 26328df commit 5031c50
Show file tree
Hide file tree
Showing 29 changed files with 638 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitlab/ci/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@
- "components/bluetooth/ble_hci/include/ble_hci.h"
- "components/bluetooth/ble_services/ans/include/esp_ans.h"
- "components/bluetooth/ble_services/bas/include/esp_bas.h"
- "components/bluetooth/ble_services/bcs/include/esp_bcs.h"
- "components/bluetooth/ble_services/dis/include/esp_dis.h"
- "components/bluetooth/ble_services/hrs/include/esp_hrs.h"
- "components/bluetooth/ble_services/hts/include/esp_hts.h"
Expand Down
5 changes: 5 additions & 0 deletions components/bluetooth/ble_services/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v0.2.0 - 2024.10.31

Features:
- BCS: Support Body Composition Service

## v0.1.0

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).
Expand Down
5 changes: 5 additions & 0 deletions components/bluetooth/ble_services/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ list(APPEND srcs "tps/src/esp_tps.c")
list(APPEND include "tps/include")
endif()

if(CONFIG_BLE_BCS)
list(APPEND srcs "bcs/src/esp_bcs.c")
list(APPEND include "bcs/include")
endif()

list(APPEND req "ble_conn_mgr")

idf_component_register(SRCS "${srcs}"
Expand Down
3 changes: 2 additions & 1 deletion components/bluetooth/ble_services/Kconfig
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
menu "BLE Standard Services"

orsource "./ans/Kconfig.in"
orsource "./dis/Kconfig.in"
orsource "./bas/Kconfig.in"
orsource "./bcs/Kconfig.in"
orsource "./dis/Kconfig.in"
orsource "./hrs/Kconfig.in"
orsource "./hts/Kconfig.in"
orsource "./tps/Kconfig.in"
Expand Down
9 changes: 5 additions & 4 deletions components/bluetooth/ble_services/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ The example will be downloaded to the current folder. You can navigate into it f
> You can use this command to download other examples. Or you can download examples from esp-iot-solution repository:
1. [ble_ans](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_ans)
2. [ble_bas](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_bas)
3. [ble_dis](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_dis)
4. [ble_hrs](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_hrs)
5. [ble_hts](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_hts)
5. [ble_tps](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_tps)
3. [ble_bcs](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_bcs)
4. [ble_dis](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_dis)
5. [ble_hrs](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_hrs)
6. [ble_hts](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_hts)
7. [ble_tps](https://github.com/espressif/esp-iot-solution/tree/master/examples/bluetooth/ble_services/ble_tps)

### Q&A

Expand Down
14 changes: 14 additions & 0 deletions components/bluetooth/ble_services/bcs/Kconfig.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Body Composition Service

menuconfig BLE_BCS
bool "GATT Body Composition Service"

if BLE_BCS

config BLE_BCS_FEATURE_INDICATE_ENABLE
bool "Body Composition Feature Indication"
default n
help
Set y to support Indication or n to disable it.

endif # BLE_BCS
109 changes: 109 additions & 0 deletions components/bluetooth/ble_services/bcs/include/esp_bcs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include "esp_err.h"

#ifdef __cplusplus
extern "C"
{
#endif

/* Maximum Attribute Value Length */
#define BLE_BCS_MAX_VAL_LEN 100

/* 16 Bit Body Composition Service UUID */
#define BLE_BCS_UUID16 0x181B

/* 16 Bit Body Composition Characteristic UUIDs */
#define BLE_BCS_CHR_UUID16_FEATURE 0x2A9B
#define BLE_BCS_CHR_UUID16_MEASUREMENT 0x2A9C

/* Body Composition Feature Bit Masks */
#define BLE_BCS_FEAT_TIME_STAMP (0x1 << 0) //bit0 Time Stamp(0-Don't support, 1-Support)
#define BLE_BCS_FEAT_MULTI_USER (0x1 << 1) //bit1 User ID(0-Don't support, 1-Support)
#define BLE_BCS_FEAT_BASAL_METABOLISM (0x1 << 2) //bit2 Basal Metabolism(0-Don't support, 1-Support)
#define BLE_BCS_FEAT_MUSCLE_PERCENTAGE (0x1 << 3) //bit3 Muscle Percentage(0-Don't support, 1-Support)
#define BLE_BCS_FEAT_MUSCLE_MASS (0x1 << 4) //bit4 Muscle Mass(0-Don't support, 1-Support)
#define BLE_BCS_FEAT_FAT_FREE_MASS (0x1 << 5) //bit5 Fat Free Mass(0-Don't support, 1-Support)
#define BLE_BCS_FEAT_SOFT_LEAN_MASS (0x1 << 6) //bit6 Soft Lean Mass(0-Don't support, 1-Support)
#define BLE_BCS_FEAT_BODY_WATER_MASS (0x1 << 7) //bit7 Body Water Mass(0-Don't support, 1-Support)
#define BLE_BCS_FEAT_IMPEDENCE (0x1 << 8) //bit8 Impedance(0-Don't support, 1-Support)
#define BLE_BCS_FEAT_WEIGHT (0x1 << 9) //bit9 Weight(0-Don't support, 1-Support)
#define BLE_BCS_FEAT_HEIGHT (0x1 << 10) //bit10 Height(0-Don't support, 1-Support)
#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);
#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);

/* Body Composition Measurement Flags Bit Masks */
#define BLE_BCS_FLAG_MEASUREMENT_UNITS (0x1 << 0) //bit0 Measurement Units
#define BLE_BCS_FLAG_TIME_STAMP (0x1 << 1) //bit1 Time Stamp
#define BLE_BCS_FLAG_MULTI_USER (0x1 << 2) //bit2 User ID
#define BLE_BCS_FLAG_BASAL_METABOLISM (0x1 << 3) //bit3 Basal Metabolism
#define BLE_BCS_FLAG_MUSCLE_PERCENTAGE (0x1 << 4) //bit4 Muscle Percentage
#define BLE_BCS_FLAG_MUSCLE_MASS (0x1 << 5) //bit5 Muscle Mass
#define BLE_BCS_FLAG_FAT_FREE_MASS (0x1 << 6) //bit6 Fat Free Mass
#define BLE_BCS_FLAG_SOFT_LEAN_MASS (0x1 << 7) //bit7 Soft Lean Mass
#define BLE_BCS_FLAG_BODY_WATER_MASS (0x1 << 8) //bit8 Body Water Mass
#define BLE_BCS_FLAG_IMPEDENCE (0x1 << 9) //bit9 Impedance
#define BLE_BCS_FLAG_WEIGHT (0x1 << 10) //bit10 Weight
#define BLE_BCS_FLAG_HEIGHT (0x1 << 11) //bit11 Height
#define BLE_BCS_FLAG_MULTIPLE_PACKET (0x1 << 12) //bit12 Multiple Packet

/**
* @brief Body Composition Measurement Characteristic
*/
typedef struct {
uint32_t bcs_flag; /*!< Body Composition flag field */

struct {
uint16_t year; /*!< Year as defined by the Gregorian calendar, Valid range 1582 to 9999 */
uint8_t month; /*!< Month of the year as defined by the Gregorian calendar, Valid range 1 (January) to 12 (December) */
uint8_t day; /*!< Day of the month as defined by the Gregorian calendar, Valid range 1 to 31 */
uint8_t hours; /*!< Number of hours past midnight, Valid range 0 to 23 */
uint8_t minutes; /*!< Number of minutes since the start of the hour. Valid range 0 to 59 */
uint8_t seconds; /*!< Number of seconds since the start of the minute. Valid range 0 to 59 */
} __attribute__((packed)) timestamp; /*!< The date and time */

uint8_t user_id; /*!< User ID field */
uint16_t basal_metabolism; /*!< Basal Metabolism field */
uint16_t muscle_percentage; /*!< Muscle Percentage field */
uint16_t muscle_mass; /*!< Muscle Mass field */
uint16_t fat_free_mass; /*!< Fat Free Mass field */
uint16_t soft_lean_mass; /*!< Soft Lean Mass field */
uint16_t body_water_mass; /*!< Body Water Mass field */
uint8_t impedance; /*!< Impedance field */
uint16_t weight; /*!< Weight field */
uint16_t height; /*!< Height field */
} __attribute__((packed)) esp_bcs_val_t;

/**
* @brief Set the Body Componsition value.
*
* @param[in] in_val The pointer to store the Body Componsition Information.
*
* @param[in] need_send If set to true, the Body Componsition Info will send to remote client.
*
* @return
* - ESP_OK on successful
* - ESP_ERR_INVALID_ARG on wrong initialization
* - ESP_FAIL on error
*/
esp_err_t esp_ble_bcs_set_measurement(esp_bcs_val_t *in_val, bool need_send);

/**
* @brief Initialization Body Componsion Service
*
* @return
* - ESP_OK on successful
* - ESP_ERR_INVALID_ARG on wrong initialization
* - ESP_FAIL on error
*/
esp_err_t esp_ble_bcs_init(void);

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit 5031c50

Please sign in to comment.