|
| 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