bcs.h
Go to the documentation of this file.
1
59 #ifndef _BCS_H_
60 #define _BCS_H_
61
62 #include "gr55xx_sys.h"
63 #include "custom_config.h"
64 #include "ble_prf_utils.h"
65 #include <stdint.h>
66 #include <stdbool.h>
67
72 #define BCS_CONNECTION_MAX (10 < CFG_MAX_CONNECTIONS ?\
73 10 : CFG_MAX_CONNECTIONS)
74 #define BCS_MEAS_VAL_LEN_MAX 20
75 #define BCS_FEAT_VAL_LEN_MAX 4
77 #define INDI_PAYLOAD_HEADER_LEN 3
89 #define NUM_PACKETS 2
90 #define MEAS_PACKET_FIRST 0
91 #define MEAS_PACKET_SUB 1
94 #define BCS_CACHE_MEAS_NUM_MAX 25
96 #define BCS_MEAS_UNSUCCESS 0xFFFF
103 #define BCS_CHAR_FEAT_MANDATORY 0x3F
117 enum bcs_meas_flag_bits
118 {
119 BCS_MEAS_FLAG_UNIT_SI = 0x0000,
120 BCS_MEAS_FLAG_UNIT_IMPERIAL = 0x0001,
121 BCS_MEAS_FLAG_DATE_TIME_PRESENT = 0x0002,
122 BCS_MEAS_FLAG_USER_ID_PRESENT = 0x0004,
123 BCS_MEAS_FLAG_BASAL_METABOLISM = 0x0008,
124 BCS_MEAS_FLAG_MUSCLE_PERCENTAGE = 0x0010,
125 BCS_MEAS_FLAG_MUSCLE_MASS = 0x0020,
126 BCS_MEAS_FLAG_FAT_FREE_MASS = 0x0040,
127 BCS_MEAS_FLAG_SOFT_LEAN_MASS = 0x0080,
128 BCS_MEAS_FLAG_BODY_WATER_MASS = 0x0100,
129 BCS_MEAS_FLAG_IMPEDANCE = 0x0200,
130 BCS_MEAS_FLAG_WEIGHT = 0x0400,
131 BCS_MEAS_FLAG_HEIGHT = 0x0800,
132 BCS_MEAS_FLAG_MUTI_PACKET = 0x1000,
133 };
137 typedef enum
138 {
139 /* Supported Flags */
140 BCS_FEAT_TIME_STAMP = 0x00000001,
141 BCS_FEAT_MULTI_USER = 0x00000002,
142 BCS_FEAT_BASAL_METABOLISM = 0x00000004,
143 BCS_FEAT_MUSCLE_PERCENTAGE = 0x00000008,
144 BCS_FEAT_MUSCLE_MASS = 0x00000010,
145 BCS_FEAT_FAT_FREE_MASS = 0x00000020,
146 BCS_FEAT_SOFT_LEAN_MASS = 0x00000040,
147 BCS_FEAT_BODY_WATER_MASS = 0x00000080,
148 BCS_FEAT_IMPEDANCE = 0x00000100,
149 BCS_FEAT_WEIGHT = 0x00000200,
150 BCS_FEAT_HEIGHT = 0x00000400,
152 /* Mass Resolution */
153 BCS_FEAT_MASS_RES_500G = 0x00000800,
154 BCS_FEAT_MASS_RES_200G = 0x00001000,
155 BCS_FEAT_MASS_RES_100G = 0x00001800,
156 BCS_FEAT_MASS_RES_50G = 0x00002000,
157 BCS_FEAT_MASS_RES_20G = 0x00002800,
158 BCS_FEAT_MASS_RES_10G = 0x00003000,
159 BCS_FEAT_MASS_RES_5G = 0x00003800,
161 /* Height Resolution */
162 BCS_FEAT_HEIGHT_RES_10MM = 0x00008000,
163 BCS_FEAT_HEIGHT_RES_5MM = 0x00010000,
164 BCS_FEAT_HEIGHT_RES_1MM = 0x00018000,
166 BCS_FEAT_FULL_BIT = 0x0001BFFF,
167 } bcs_feature_t;
168
170 typedef enum
171 {
172 BCS_MASS_RES_500G,
173 BCS_MASS_RES_200G,
174 BCS_MASS_RES_100G,
175 BCS_MASS_RES_50G,
176 BCS_MASS_RES_20G,
177 BCS_MASS_RES_10G,
178 BCS_MASS_RES_5G,
179 } bcs_mass_res_t;
180
182 typedef enum
183 {
184 BCS_HEIGHT_RES_10MM,
185 BCS_HEIGHT_RES_5MM,
186 BCS_HEIGHT_RES_1MM,
187 } bcs_height_res_t;
188
190 typedef enum
191 {
192 BCS_UNIT_SI,
193 BCS_UNIT_IMPERIAL,
194 } bcs_unit_t;
195
197 typedef enum
198 {
199 BCS_EVT_INVALID,
200 BCS_EVT_MEAS_INDICATION_ENABLE,
201 BCS_EVT_MEAS_INDICATION_DISABLE,
202 BCS_EVT_MEAS_INDICATION_CPLT,
203 BCS_EVT_MEAS_READ_CHARACTERISTIC,
204 } bcs_evt_type_t;
212 typedef struct
213 {
214 uint8_t time_stamp_present :1;
215 uint8_t user_id_present :1;
216 uint8_t basal_metabolism_present :1;
217 uint8_t muscle_percentage_present :1;
218 uint8_t muscle_mass_present :1;
219 uint8_t fat_free_mass_present :1;
220 uint8_t soft_lean_mass_present :1;
221 uint8_t body_water_mass_present :1;
222 uint8_t impedance_present :1;
223 uint8_t weight_present :1;
224 uint8_t height_present :1;
225 } bcs_meas_flag_t;
226
228 typedef struct
229 {
230 uint16_t body_fat_percentage;
231 prf_date_time_t time_stamp;
232 uint8_t user_id;
233 uint16_t basal_metabolism;
234 uint16_t muscle_percentage;
235 uint16_t muscle_mass;
236 uint16_t fat_free_mass;
237 uint16_t soft_lean_mass;
238 uint16_t body_water_mass;
239 uint16_t impedance;
240 uint16_t weight;
241 uint16_t height;
242 } bcs_meas_val_t;
243
245 typedef struct
246 {
247 bcs_evt_type_t evt_type;
248 uint8_t conn_idx;
249 const uint8_t *p_data;
250 uint16_t length;
251 } bcs_evt_t;
259 typedef void (*bcs_evt_handler_t)(bcs_evt_t *p_evt);
267 typedef struct
268 {
269 bcs_evt_handler_t evt_handler;
270 uint32_t feature;
271 uint8_t char_mask;
272 bcs_unit_t bcs_unit;
273 bcs_meas_flag_t bcs_meas_flags;
274 bcs_mass_res_t bcs_mass_res;
275 bcs_height_res_t bcs_height_res;
276 } bcs_init_t;
292 sdk_err_t bcs_service_init(bcs_init_t *p_bcs_init);
293
304 sdk_err_t bcs_measurement_send(uint8_t conn_idx, bcs_meas_val_t *p_meas, uint8_t cache_num);
305
308 #endif
309
bcs_meas_val_t::height
uint16_t height
Definition: bcs.h:241
BCS_MEAS_FLAG_SOFT_LEAN_MASS
@ BCS_MEAS_FLAG_SOFT_LEAN_MASS
Definition: bcs.h:127
bcs_meas_flag_t::basal_metabolism_present
uint8_t basal_metabolism_present
Definition: bcs.h:216
bcs_init_t::char_mask
uint8_t char_mask
Definition: bcs.h:271
BCS_MEAS_FLAG_HEIGHT
@ BCS_MEAS_FLAG_HEIGHT
Definition: bcs.h:131
bcs_feature_t
bcs_feature_t
Body Composition Feature characteristic bit values.
Definition: bcs.h:138
BCS_MASS_RES_500G
@ BCS_MASS_RES_500G
Definition: bcs.h:172
bcs_unit_t
bcs_unit_t
BCS unit types.
Definition: bcs.h:191
bcs_evt_t::p_data
const uint8_t * p_data
Definition: bcs.h:249
bcs_init_t::bcs_meas_flags
bcs_meas_flag_t bcs_meas_flags
Definition: bcs.h:273
BCS_MEAS_FLAG_FAT_FREE_MASS
@ BCS_MEAS_FLAG_FAT_FREE_MASS
Definition: bcs.h:126
bcs_mass_res_t
bcs_mass_res_t
BCS Weight Measurement resolutions.
Definition: bcs.h:171
BCS_MEAS_FLAG_MUSCLE_PERCENTAGE
@ BCS_MEAS_FLAG_MUSCLE_PERCENTAGE
Definition: bcs.h:124
bcs_meas_flag_t::time_stamp_present
uint8_t time_stamp_present
Definition: bcs.h:214
bcs_evt_type_t
bcs_evt_type_t
Body Composition Service event type.
Definition: bcs.h:198
bcs_evt_t
Body Composition Service event.
Definition: bcs.h:246
BCS_HEIGHT_RES_10MM
@ BCS_HEIGHT_RES_10MM
Definition: bcs.h:184
BCS_MEAS_FLAG_UNIT_IMPERIAL
@ BCS_MEAS_FLAG_UNIT_IMPERIAL
Definition: bcs.h:120
gr55xx_sys.h
GR55XX System API.
bcs_init_t::bcs_mass_res
bcs_mass_res_t bcs_mass_res
Definition: bcs.h:274
bcs_evt_t::evt_type
bcs_evt_type_t evt_type
Definition: bcs.h:247
BCS_MASS_RES_5G
@ BCS_MASS_RES_5G
Definition: bcs.h:178
BCS_FEAT_HEIGHT_RES_1MM
@ BCS_FEAT_HEIGHT_RES_1MM
Definition: bcs.h:164
BCS_HEIGHT_RES_5MM
@ BCS_HEIGHT_RES_5MM
Definition: bcs.h:185
bcs_meas_val_t::impedance
uint16_t impedance
Definition: bcs.h:239
BCS_MEAS_FLAG_UNIT_SI
@ BCS_MEAS_FLAG_UNIT_SI
Definition: bcs.h:119
BCS_FEAT_MASS_RES_20G
@ BCS_FEAT_MASS_RES_20G
Definition: bcs.h:157
BCS_FEAT_MASS_RES_200G
@ BCS_FEAT_MASS_RES_200G
Definition: bcs.h:154
bcs_measurement_send
sdk_err_t bcs_measurement_send(uint8_t conn_idx, bcs_meas_val_t *p_meas, uint8_t cache_num)
Send Body Composition Measurement indication.
bcs_init_t::bcs_height_res
bcs_height_res_t bcs_height_res
Definition: bcs.h:275
BCS_EVT_MEAS_INDICATION_ENABLE
@ BCS_EVT_MEAS_INDICATION_ENABLE
Definition: bcs.h:200
bcs_init_t
Body Composition Service Init variable.
Definition: bcs.h:268
bcs_meas_flag_t::fat_free_mass_present
uint8_t fat_free_mass_present
Definition: bcs.h:219
BCS_FEAT_MUSCLE_MASS
@ BCS_FEAT_MUSCLE_MASS
Definition: bcs.h:144
BCS_FEAT_MASS_RES_10G
@ BCS_FEAT_MASS_RES_10G
Definition: bcs.h:158
bcs_meas_val_t::weight
uint16_t weight
Definition: bcs.h:240
BCS_MEAS_FLAG_USER_ID_PRESENT
@ BCS_MEAS_FLAG_USER_ID_PRESENT
Definition: bcs.h:122
bcs_meas_flag_t::soft_lean_mass_present
uint8_t soft_lean_mass_present
Definition: bcs.h:220
BCS_FEAT_HEIGHT_RES_10MM
@ BCS_FEAT_HEIGHT_RES_10MM
Definition: bcs.h:162
BCS_MEAS_FLAG_MUSCLE_MASS
@ BCS_MEAS_FLAG_MUSCLE_MASS
Definition: bcs.h:125
bcs_meas_val_t::time_stamp
prf_date_time_t time_stamp
Definition: bcs.h:231
BCS_FEAT_MASS_RES_100G
@ BCS_FEAT_MASS_RES_100G
Definition: bcs.h:155
bcs_meas_val_t::muscle_mass
uint16_t muscle_mass
Definition: bcs.h:235
bcs_meas_val_t::body_water_mass
uint16_t body_water_mass
Definition: bcs.h:238
BCS_FEAT_MASS_RES_50G
@ BCS_FEAT_MASS_RES_50G
Definition: bcs.h:156
BCS_MASS_RES_200G
@ BCS_MASS_RES_200G
Definition: bcs.h:173
sdk_err_t
uint16_t sdk_err_t
SDK API result type.
Definition: ble_error.h:243
BCS_FEAT_WEIGHT
@ BCS_FEAT_WEIGHT
Definition: bcs.h:149
bcs_meas_flag_t
Body composition Measurement flag data.
Definition: bcs.h:213
BCS_FEAT_TIME_STAMP
@ BCS_FEAT_TIME_STAMP
Definition: bcs.h:140
bcs_evt_handler_t
void(* bcs_evt_handler_t)(bcs_evt_t *p_evt)
Body Composition Service event handler type.
Definition: bcs.h:259
bcs_meas_flag_t::impedance_present
uint8_t impedance_present
Definition: bcs.h:222
prf_date_time_t
The date and time structure. The packed size is 7 bytes.
Definition: ble_prf_types.h:101
bcs_meas_flag_t::muscle_percentage_present
uint8_t muscle_percentage_present
Definition: bcs.h:217
BCS_MEAS_FLAG_BASAL_METABOLISM
@ BCS_MEAS_FLAG_BASAL_METABOLISM
Definition: bcs.h:123
bcs_evt_t::conn_idx
uint8_t conn_idx
Definition: bcs.h:248
BCS_MASS_RES_10G
@ BCS_MASS_RES_10G
Definition: bcs.h:177
BCS_UNIT_SI
@ BCS_UNIT_SI
Definition: bcs.h:192
bcs_meas_flag_t::body_water_mass_present
uint8_t body_water_mass_present
Definition: bcs.h:221
BCS_FEAT_MULTI_USER
@ BCS_FEAT_MULTI_USER
Definition: bcs.h:141
BCS_FEAT_MASS_RES_5G
@ BCS_FEAT_MASS_RES_5G
Definition: bcs.h:159
bcs_meas_val_t::user_id
uint8_t user_id
Definition: bcs.h:232
BCS_FEAT_SOFT_LEAN_MASS
@ BCS_FEAT_SOFT_LEAN_MASS
Definition: bcs.h:146
BCS_FEAT_MUSCLE_PERCENTAGE
@ BCS_FEAT_MUSCLE_PERCENTAGE
Definition: bcs.h:143
BCS_MEAS_FLAG_WEIGHT
@ BCS_MEAS_FLAG_WEIGHT
Definition: bcs.h:130
BCS_UNIT_IMPERIAL
@ BCS_UNIT_IMPERIAL
Definition: bcs.h:193
BCS_EVT_MEAS_READ_CHARACTERISTIC
@ BCS_EVT_MEAS_READ_CHARACTERISTIC
Definition: bcs.h:203
BCS_MEAS_FLAG_MUTI_PACKET
@ BCS_MEAS_FLAG_MUTI_PACKET
Definition: bcs.h:132
BCS_FEAT_BASAL_METABOLISM
@ BCS_FEAT_BASAL_METABOLISM
Definition: bcs.h:142
bcs_init_t::feature
uint32_t feature
Definition: bcs.h:270
BCS_FEAT_IMPEDANCE
@ BCS_FEAT_IMPEDANCE
Definition: bcs.h:148
bcs_height_res_t
bcs_height_res_t
BCS Height Measurement resolutions.
Definition: bcs.h:183
bcs_init_t::evt_handler
bcs_evt_handler_t evt_handler
Definition: bcs.h:269
BCS_MASS_RES_50G
@ BCS_MASS_RES_50G
Definition: bcs.h:175
bcs_meas_flag_t::weight_present
uint8_t weight_present
Definition: bcs.h:223
BCS_EVT_MEAS_INDICATION_DISABLE
@ BCS_EVT_MEAS_INDICATION_DISABLE
Definition: bcs.h:201
bcs_evt_t::length
uint16_t length
Definition: bcs.h:250
ble_prf_utils.h
Profile/Service Utilities API.
bcs_meas_val_t::muscle_percentage
uint16_t muscle_percentage
Definition: bcs.h:234
BCS_FEAT_HEIGHT_RES_5MM
@ BCS_FEAT_HEIGHT_RES_5MM
Definition: bcs.h:163
bcs_meas_val_t::fat_free_mass
uint16_t fat_free_mass
Definition: bcs.h:236
BCS_MEAS_FLAG_BODY_WATER_MASS
@ BCS_MEAS_FLAG_BODY_WATER_MASS
Definition: bcs.h:128
bcs_meas_flag_t::height_present
uint8_t height_present
Definition: bcs.h:224
bcs_meas_val_t
Body composition Measurement data.
Definition: bcs.h:229
bcs_meas_val_t::body_fat_percentage
uint16_t body_fat_percentage
Definition: bcs.h:230
BCS_FEAT_MASS_RES_500G
@ BCS_FEAT_MASS_RES_500G
Definition: bcs.h:153
bcs_meas_val_t::soft_lean_mass
uint16_t soft_lean_mass
Definition: bcs.h:237
BCS_MASS_RES_20G
@ BCS_MASS_RES_20G
Definition: bcs.h:176
bcs_meas_val_t::basal_metabolism
uint16_t basal_metabolism
Definition: bcs.h:233
BCS_MEAS_FLAG_IMPEDANCE
@ BCS_MEAS_FLAG_IMPEDANCE
Definition: bcs.h:129
bcs_init_t::bcs_unit
bcs_unit_t bcs_unit
Definition: bcs.h:272
BCS_FEAT_BODY_WATER_MASS
@ BCS_FEAT_BODY_WATER_MASS
Definition: bcs.h:147
BCS_FEAT_FAT_FREE_MASS
@ BCS_FEAT_FAT_FREE_MASS
Definition: bcs.h:145
BCS_FEAT_HEIGHT
@ BCS_FEAT_HEIGHT
Definition: bcs.h:150
BCS_MEAS_FLAG_DATE_TIME_PRESENT
@ BCS_MEAS_FLAG_DATE_TIME_PRESENT
Definition: bcs.h:121
bcs_service_init
sdk_err_t bcs_service_init(bcs_init_t *p_bcs_init)
Initialize a Body Composition Service instance and add in the DB.
bcs_meas_flag_t::muscle_mass_present
uint8_t muscle_mass_present
Definition: bcs.h:218
bcs_meas_flag_t::user_id_present
uint8_t user_id_present
Definition: bcs.h:215
BCS_HEIGHT_RES_1MM
@ BCS_HEIGHT_RES_1MM
Definition: bcs.h:186
BCS_EVT_INVALID
@ BCS_EVT_INVALID
Definition: bcs.h:199
BCS_EVT_MEAS_INDICATION_CPLT
@ BCS_EVT_MEAS_INDICATION_CPLT
Definition: bcs.h:202
BCS_MASS_RES_100G
@ BCS_MASS_RES_100G
Definition: bcs.h:174