1 /** 2 **************************************************************************************** 3 * 4 * @file wss.h 5 * 6 * @brief Weight Scale Service API. 7 * 8 **************************************************************************************** 9 * @attention 10 #####Copyright (c) 2019 GOODIX 11 All rights reserved. 12 13 Redistribution and use in source and binary forms, with or without 14 modification, are permitted provided that the following conditions are met: 15 * Redistributions of source code must retain the above copyright 16 notice, this list of conditions and the following disclaimer. 17 * Redistributions in binary form must reproduce the above copyright 18 notice, this list of conditions and the following disclaimer in the 19 documentation and/or other materials provided with the distribution. 20 * Neither the name of GOODIX nor the names of its contributors may be used 21 to endorse or promote products derived from this software without 22 specific prior written permission. 23 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 POSSIBILITY OF SUCH DAMAGE. 35 ***************************************************************************************** 36 */ 37 38 /** 39 * @addtogroup BLE_SRV BLE Services 40 * @{ 41 * @brief Definitions and prototypes for the BLE Service interface. 42 */ 43 44 /** 45 * @defgroup BLE_SDK_WSS Weight Scale Service (WSS) 46 * @{ 47 * @brief Weight Scale Service module. 48 * 49 * @details The Weight Scale (WS) Service exposes weight and related data from a weight scale 50 * (Server) intended for consumer healthcare as well as sports/fitness applications. 51 * 52 * After \ref wss_init_t variable is intialized, the application must call \ref wss_service_init() 53 * to add Weight Scale Feature and Weight Measurement characteristics to the BLE Stack database 54 * according to \ref wss_init_t.char_mask. 55 */ 56 57 #ifndef __WSS_H__ 58 #define __WSS_H__ 59 60 #include <stdint.h> 61 #include <stdbool.h> 62 #include "gr55xx_sys.h" 63 #include "custom_config.h" 64 #include "ble_prf_utils.h" 65 66 /** 67 * @defgroup WSS_MACRO Defines 68 * @{ 69 */ 70 #define WSS_CONNECTION_MAX (10 < CFG_MAX_CONNECTIONS ? \ 71 10 : CFG_MAX_CONNECTIONS) /**< Maximum number of Weight Scale Service connections. */ 72 #define WSS_MEAS_VAL_LEN_MAX 15 /**< Maximum length of Weight Measurment value. */ 73 #define WSS_CACHE_MEAS_NUM_MAX 25 /**< Maximum number of cache muasurements value for each user. */ 74 #define WSS_FEAT_VAL_LEN_MAX 1 /**< Maximum length of WS Feature value. */ 75 #define WSS_MEAS_UNSUCCESS 0xFFFF /**< Measurement Unsuccessful. */ 76 /** 77 * @defgroup WSS_CHAR_MASK Characteristics Mask 78 * @{ 79 * @brief Bit masks for the initialization of \ref wss_init_t.char_mask. 80 */ 81 #define WSS_CHAR_FEAT_MANDATORY 0x7F /**< Bit mask for mandatory characteristic in WSS. */ 82 /** @} */ 83 /** @} */ 84 85 /** 86 * @defgroup WSS_ENUM Enumerations 87 * @{ 88 */ 89 /** 90 * @defgroup WSS_MEAS_FLAG_BIT Measurement Flag Bits 91 * @{ 92 * @brief Weight Scale Measurement Flags. 93 */ 94 enum wss_meas_flag_bits { 95 WSS_MEAS_FLAG_UNIT_SI = 0x00, /**< Flag bit for SI Measurement Units Present. */ 96 WSS_MEAS_FLAG_UNIT_IMPERIAL = 0x01, /**< Flag bit for Imperial Measurement Units Present. */ 97 WSS_MEAS_FLAG_DATE_TIME_PRESENT = 0x02, /**< Flag bit for Time Stamp Present. */ 98 WSS_MEAS_FLAG_USER_ID_PRESENT = 0x04, /**< Flag bit for User ID Present. */ 99 WSS_MEAS_FLAG_BMI_HEIGHT_PRESENT = 0x08, /**< Flag bit for BMI and Height Present. */ 100 }; 101 /** @} */ 102 103 /**@brief Weight Scale Feature characteristic bit values.*/ 104 typedef enum { 105 /* Supported Flags */ 106 WSS_FEAT_TIME_STAMP = 0x00000001, /**< Time Stamp supported. */ 107 WSS_FEAT_MULTI_USER = 0x00000002, /**< Multiple Users supported. */ 108 WSS_FEAT_BMI = 0x00000004, /**< BMI supported. */ 109 110 /* Weight Measurement Resolution */ 111 WSS_FEAT_MASS_RES_500G = 0x00000008, /**< Resolution of 0.5kg or 1lb. */ 112 WSS_FEAT_MASS_RES_200G = 0x00000010, /**< Resolution of 0.2kg or 0.5lb. */ 113 WSS_FEAT_MASS_RES_100G = 0x00000018, /**< Resolution of 0.1kg or 0.2lb. */ 114 WSS_FEAT_MASS_RES_50G = 0x00000020, /**< Resolution of 0.05kg or 0.1lb. */ 115 WSS_FEAT_MASS_RES_20G = 0x00000028, /**< Resolution of 0.02kg or 0.05lb. */ 116 WSS_FEAT_MASS_RES_10G = 0x00000030, /**< Resolution of 0.01kg or 0.02lb. */ 117 WSS_FEAT_MASS_RES_5G = 0x00000038, /**< Resolution of 0.005kg or 0.01lb. */ 118 119 /* Height Measurement Resolution */ 120 WSS_FEAT_HEIGHT_RES_10MM = 0x00000080, /**< Resolution of 0.01m or 1in. */ 121 WSS_FEAT_HEIGHT_RES_5MM = 0x00000100, /**< Resolution of 0.005m or 0.5in. */ 122 WSS_FEAT_HEIGHT_RES_1MM = 0x00000180, /**< Resolution of 0.001m or 0.1in. */ 123 124 WSS_FEAT_FULL_BIT = 0x000001BF, 125 } wss_feature_t; 126 127 /**@brief WSS Weight Measurement resolutions. */ 128 typedef enum { 129 WSS_MASS_RES_500G, /**< Resolution of 0.5kg or 1lb. */ 130 WSS_MASS_RES_200G, /**< Resolution of 0.2kg or 0.5lb. */ 131 WSS_MASS_RES_100G, /**< Resolution of 0.1kg or 0.2lb. */ 132 WSS_MASS_RES_50G, /**< Resolution of 0.05kg or 0.1lb. */ 133 WSS_MASS_RES_20G, /**< Resolution of 0.02kg or 0.05lb. */ 134 WSS_MASS_RES_10G, /**< Resolution of 0.01kg or 0.02lb. */ 135 WSS_MASS_RES_5G, /**< Resolution of 0.005kg or 0.01lb. */ 136 } wss_mass_res_t; 137 138 /**@brief WSS Height Measurement resolutions. */ 139 typedef enum { 140 WSS_HEIGHT_RES_10MM, /**< Resolution of 0.01m or 1in. */ 141 WSS_HEIGHT_RES_5MM, /**< Resolution of 0.005m or 0.5in. */ 142 WSS_HEIGHT_RES_1MM, /**< Resolution of 0.001m or 0.1in. */ 143 } wss_height_res_t; 144 145 /**@brief WSS unit types. */ 146 typedef enum { 147 WSS_UNIT_SI, /**< Weight in kilograms and height in meters */ 148 WSS_UNIT_IMPERIAL, /**< Weight in pounds and height in inches */ 149 } wss_unit_t; 150 151 /**@brief Weight Scale Service event type. */ 152 typedef enum { 153 WSS_EVT_INVALID, /**< Indicate that invalid event. */ 154 WSS_EVT_MEAS_INDICATION_ENABLE, /**< Indicate that body composition measurement indication has been enabled. */ 155 WSS_EVT_MEAS_INDICATION_DISABLE, /**< Indicate that body composition measurement indication has been disabled. */ 156 WSS_EVT_MEAS_INDICATION_CPLT, /**< Indicate that BC Measurement has been indicated. */ 157 WSS_EVT_MEAS_READ_CHARACTERISTIC, /**< The peer reads the characteristic. */ 158 } wss_evt_type_t; 159 /** @} */ 160 161 /** 162 * @defgroup WSS_STRUCT Structures 163 * @{ 164 */ 165 /**@brief Weight Scale Measurement data. */ 166 typedef struct { 167 uint16_t weight; /**< Weight. */ 168 prf_date_time_t time_stamp; /**< Time stamp. */ 169 uint8_t user_id; /**< User index. */ 170 uint16_t bmi; /**< Bmi. */ 171 uint16_t height; /**< Height. */ 172 } wss_meas_val_t; 173 174 /**@brief Weight Scale Service event. */ 175 typedef struct { 176 wss_evt_type_t evt_type; /**< The WSS event type. */ 177 uint8_t conn_idx; /**< The index of the connection. */ 178 const uint8_t *p_data; /**< Pointer to event data. */ 179 uint16_t length; /**< Length of event data. */ 180 } wss_evt_t; 181 /** @} */ 182 183 /** 184 * @defgroup WSS_TYPEDEF Typedefs 185 * @{ 186 */ 187 /**@brief Weight Scale Service event handler type. */ 188 typedef void (*wss_evt_handler_t)(wss_evt_t *p_evt); 189 /** @} */ 190 191 /** 192 * @defgroup WSS_STRUCT Structures 193 * @{ 194 */ 195 /**@brief Weight Scale Service Init variable. */ 196 typedef struct { 197 wss_evt_handler_t evt_handler; /**< Weight Scale Service event handler. */ 198 uint32_t feature; /**< Initial value for features. */ 199 uint8_t 200 char_mask; /**< Initial mask of Supported characteristics, and configured with \ref WSS_CHAR_MASK */ 201 wss_unit_t wss_unit; /**< Initial the unit system as SI or Imperial. */ 202 wss_mass_res_t wss_mass_res; /**< Initial resolution of mass value. */ 203 wss_height_res_t wss_height_res; /**< Initial resolution of height value. */ 204 bool multi_user_present; /**< Flag which indicates if multiple user is present. */ 205 bool time_stamp_present; /**< Flag which indicates if time stamp is present. */ 206 bool bmi_present; /**< Flag which indicates if bmi is present. */ 207 } wss_init_t; 208 /** @} */ 209 210 /** 211 * @defgroup WSS_FUNCTION Functions 212 * @{ 213 */ 214 /** 215 ***************************************************************************************** 216 * @brief Initialize a Weight Scale Service instance and add in the DB. 217 * 218 * @param[in] p_wss_init: Pointer to WSS Service initialization variable. 219 * 220 * @return Result of service initialization. 221 ***************************************************************************************** 222 */ 223 sdk_err_t wss_service_init(wss_init_t *p_wss_init, uint16_t *p_bcs_start_handle); 224 225 /** 226 ***************************************************************************************** 227 * @brief Send Weight Scale Measurement indication.. 228 * 229 * @param[in] conn_idx: Connection index. 230 * @param[in] p_meas: Pointer to weight scale measurement data. 231 * @param[in] cache_num: The number of measurement caches. 232 * 233 * @return Result of indicate value. 234 ***************************************************************************************** 235 */ 236 sdk_err_t wss_measurement_send(uint8_t conn_idx, wss_meas_val_t *p_meas, uint8_t cache_num); 237 238 /** @} */ 239 240 #endif 241 /** @} */ 242 /** @} */ 243 244