gls.h
Go to the documentation of this file.
1
60 #ifndef __GLS_H__
61 #define __GLS_H__
62
63 /*
64 * INCLUDE FILES
65 ****************************************************************************************
66 */
67 #include "gr55xx_sys.h"
68 #include "custom_config.h"
69 #include "ble_prf_utils.h"
70 #include <stdint.h>
71 #include <stdbool.h>
72
77 #define GLS_CONNECTION_MAX (10 < CFG_MAX_CONNECTIONS ?\
78 10 : CFG_MAX_CONNECTIONS)
79 #define GLS_MEAS_VAL_LEN_MAX 20
80 #define GLS_MEAS_CTX_LEN_MAX 20
81 #define GLS_REC_ACCESS_CTRL_LEN_MIN 2
82 #define GLS_REC_ACCESS_CTRL_LEN_MAX 21
85 #define GLS_NTF_OF_NULL 0x00
86 #define GLS_NTF_OF_MEAS 0x01
87 #define GLS_NTF_OF_MEAS_CTX 0x10
89 #define GLS_ERROR_PROC_IN_PROCESS 0x80
90 #define GLS_ERROR_CCCD_INVALID 0x81
97 #define GLS_CHAR_MANDATORY 0x0f8f
98 #define GLS_CHAR_MEAS_CTX_SUP 0x0070
99 #define GLS_CHAR_FULL 0x0fff
107 #define GLS_FEAT_LOW_BATT (0x01 << 0)
108 #define GLS_FEAT_MALFUNC (0x01 << 1)
109 #define GLS_FEAT_SAMPLE_SIZE (0x01 << 2)
110 #define GLS_FEAT_INSERT_ERR (0x01 << 3)
111 #define GLS_FEAT_TYPE_ERR (0x01 << 4)
112 #define GLS_FEAT_RES_HIGH_LOW (0x01 << 5)
113 #define GLS_FEAT_TEMP_HIGH_LOW (0x01 << 6)
114 #define GLS_FEAT_READ_INT (0x01 << 7)
115 #define GLS_FEAT_GENERAL_FAULT (0x01 << 8)
116 #define GLS_FEAT_TIME_FAULT (0x01 << 9)
117 #define GLS_FEAT_MULTI_BOND (0x01 << 10)
118 #define GLS_FEAT_FULL (0x07ff)
127 #define GLS_MEAS_FLAG_TIME_OFFSET 0x01
128 #define GLS_MEAS_FLAG_CONC_TYPE_LOC 0x02
129 #define GLS_MEAS_FLAG_UNITS_KG_L 0x00
130 #define GLS_MEAS_FLAG_UNITS_MOL_L 0x04
131 #define GLS_MEAS_FLAG_SENSOR_STATUS 0x08
132 #define GLS_MEAS_FLAG_CONTEXT_INFO 0x10
140 #define GLS_MEAS_CTX_FLAG_CARB (0x01 << 0)
141 #define GLS_MEAS_CTX_FLAG_MEAL (0x01 << 1)
142 #define GLS_MEAS_CTX_FLAG_TESTER (0x01 << 2)
143 #define GLS_MEAS_CTX_FLAG_EXERCISE (0x01 << 3)
144 #define GLS_MEAS_CTX_FLAG_MED (0x01 << 4)
145 #define GLS_MEAS_CTX_FLAG_MED_KG (0x01 << 5)
146 #define GLS_MEAS_CTX_FLAG_MED_L (0x01 << 6)
147 #define GLS_MEAS_CTX_FLAG_HBA1C (0x01 << 7)
148 #define GLS_MEAS_CTX_FLAG_EXT (0x01 << 8)
156 #define GLS_MEAS_STATUS_BATT_LOW (0x01 << 0)
157 #define GLS_MEAS_STATUS_SENSOR_FAULT (0x01 << 1)
158 #define GLS_MEAS_STATUS_SAMPLE_SIZE (0x01 << 2)
159 #define GLS_MEAS_STATUS_STRIP_INSERT (0x01 << 3)
160 #define GLS_MEAS_STATUS_STRIP_TYPE (0x01 << 4)
161 #define GLS_MEAS_STATUS_RESULT_HIGH (0x01 << 5)
162 #define GLS_MEAS_STATUS_RESULT_LOW (0x01 << 6)
163 #define GLS_MEAS_STATUS_TEMP_HIGH (0x01 << 7)
164 #define GLS_MEAS_STATUS_TEMP_LOW (0x01 << 8)
165 #define GLS_MEAS_STATUS_STRIP_PULL (0x01 << 9)
166 #define GLS_MEAS_STATUS_GENERAL_FAULT (0x01 << 10)
167 #define GLS_MEAS_STATUS_TIME_FAULT (0x01 << 11)
176 typedef enum
177 {
178 GLS_MEAS_TYPE_CAP_BLOOD = 0x01,
179 GLS_MEAS_TYPE_CAP_PLASMA,
180 GLS_MEAS_TYPE_VEN_BLOOD,
181 GLS_MEAS_TYPE_VEN_PLASMA,
182 GLS_MEAS_TYPE_ART_BLOOD,
183 GLS_MEAS_TYPE_ART_PLASMA,
184 GLS_MEAS_TYPE_UNDET_BLOOD,
185 GLS_MEAS_TYPE_UNDET_PLASMA,
186 GLS_MEAS_TYPE_FLUID,
187 GLS_MEAS_TYPE_CONTROL,
188 } gls_meas_type_t;
189
191 typedef enum
192 {
193 GLS_MEAS_LOC_FINGER = 0x01,
194 GLS_MEAS_LOC_AST,
195 GLS_MEAS_LOC_EAR,
196 GLS_MEAS_LOC_CONTROL,
197 GLS_MEAS_LOC_NOT_AVAIL = 0x0f,
198 } gls_meas_loc_t;
199
201 typedef enum
202 {
203 GLS_MEAS_CTX_CARB_BREAKFAST = 0x01,
204 GLS_MEAS_CTX_CARB_LUNCH,
205 GLS_MEAS_CTX_CARB_DINNER,
206 GLS_MEAS_CTX_CARB_SNACK,
207 GLS_MEAS_CTX_CARB_DRINK,
208 GLS_MEAS_CTX_CARB_SUPPER,
209 GLS_MEAS_CTX_CARB_BRUNCH,
210 } gls_meas_ctx_carb_id_t;
211
213 typedef enum
214 {
215 GLS_MEAS_CTX_MEAL_PREPRANDIAL = 0x01,
216 GLS_MEAS_CTX_MEAL_POSTPRANDIAL,
217 GLS_MEAS_CTX_MEAL_FASTING,
218 GLS_MEAS_CTX_MEAL_CASUAL,
219 GLS_MEAS_CTX_MEAL_BEDTIME,
220 } gls_meas_ctx_meal_t;
221
223 typedef enum
224 {
225 GLS_MEAS_CTX_TESTER_SELF = 0x01,
226 GLS_MEAS_CTX_TESTER_PRO,
227 GLS_MEAS_CTX_TESTER_LAB,
228 GLS_MEAS_CTX_TESTER_NOT_AVAIL = 0x0f,
229 } gls_meas_ctx_tester_t;
230
232 typedef enum
233 {
234 GLS_MEAS_CTX_HEALTH_MINOR = 0x01,
235 GLS_MEAS_CTX_HEALTH_MAJOR,
236 GLS_MEAS_CTX_HEALTH_MENSES,
237 GLS_MEAS_CTX_HEALTH_STRESS,
238 GLS_MEAS_CTX_HEALTH_NONE,
239 GLS_MEAS_CTX_HEALTH_NOT_AVAIL = 0x0f,
240 } gls_meas_ctx_health_t;
241
243 typedef enum
244 {
245 GLS_MEAS_CTX_MED_RAPID = 0x01,
246 GLS_MEAS_CTX_MED_SHORT,
247 GLS_MEAS_CTX_MED_INTERMED,
248 GLS_MEAS_CTX_MED_LONG,
249 GLS_MEAS_CTX_MED_PREMIX,
250 } gls_meas_ctx_medic_id_t;
251
253 typedef enum
254 {
255 GLS_EVT_INVALID = 0x00,
256 GLS_EVT_MEAS_NOTIFICATION_ENABLED,
257 GLS_EVT_MEAS_NOTIFICATION_DISABLED,
258 GLS_EVT_CTX_NOTIFICATION_ENABLED,
259 GLS_EVT_CTX_NOTIFICATION_DISABLED,
260 GLS_EVT_CTRL_INDICATION_ENABLED,
261 GLS_EVT_CTRL_INDICATION_DISABLED,
262 GLS_EVT_CTRL_WRITE,
263 } gls_evt_type_t;
271 typedef struct
272 {
273 int8_t exponent;
274 int16_t mantissa;
275 } ieee_float16_t;
276
278 typedef struct
279 {
280 gls_evt_type_t evt_type;
281 uint8_t conn_idx;
282 const uint8_t *p_data;
283 uint16_t length;
284 } gls_evt_t;
292 typedef void (*gls_evt_handler_t)(gls_evt_t *p_evt);
300 typedef struct
301 {
302 uint8_t flags;
303 uint16_t sequence_number;
304 prf_date_time_t base_time;
305 int16_t time_offset;
306 ieee_float16_t glucose_concentration;
307 uint8_t type;
308 uint8_t sample_location;
309 uint16_t sensor_status_annunciation;
310 } gls_meas_val_t;
311
313 typedef struct
314 {
315 uint8_t flags;
316 uint8_t extended_flags;
317 uint8_t carbohydrate_id;
318 ieee_float16_t carbohydrate;
319 uint8_t meal;
320 uint8_t tester_and_health;
321 uint16_t exercise_duration;
322 uint8_t exercise_intensity;
323 uint8_t medication_id;
324 ieee_float16_t medication;
325 uint16_t hba1c;
326 } gls_meas_ctx_t;
327
329 typedef struct
330 {
331 gls_meas_val_t meas_val;
332 gls_meas_ctx_t meas_ctx;
333 } gls_rec_t;
334
336 typedef struct
337 {
338 gls_evt_handler_t evt_handler;
339 uint16_t char_mask;
340 uint16_t feature;
341 } gls_init_t;
357 sdk_err_t gls_service_init(gls_init_t *p_gls_init);
358
368 bool gls_new_meas_record(gls_rec_t *p_rec);
369
381 sdk_err_t gls_racp_rsp_send(uint8_t conn_idx, uint8_t *p_data, uint16_t length);
384 #endif
385
gls_new_meas_record
bool gls_new_meas_record(gls_rec_t *p_rec)
Record a new glucose measurement.
GLS_MEAS_CTX_TESTER_LAB
@ GLS_MEAS_CTX_TESTER_LAB
Definition: gls.h:227
GLS_MEAS_CTX_CARB_SUPPER
@ GLS_MEAS_CTX_CARB_SUPPER
Definition: gls.h:208
GLS_MEAS_CTX_CARB_BREAKFAST
@ GLS_MEAS_CTX_CARB_BREAKFAST
Definition: gls.h:203
gls_meas_val_t
Glucose Measurement structure. This contains glucose measurement value.
Definition: gls.h:301
GLS_MEAS_LOC_EAR
@ GLS_MEAS_LOC_EAR
Definition: gls.h:195
gls_meas_loc_t
gls_meas_loc_t
Glucose measurement location.
Definition: gls.h:192
gls_meas_ctx_t::carbohydrate
ieee_float16_t carbohydrate
Definition: gls.h:318
gls_meas_val_t::base_time
prf_date_time_t base_time
Definition: gls.h:304
GLS_MEAS_CTX_MED_LONG
@ GLS_MEAS_CTX_MED_LONG
Definition: gls.h:248
gls_evt_t::conn_idx
uint8_t conn_idx
Definition: gls.h:281
GLS_MEAS_TYPE_UNDET_BLOOD
@ GLS_MEAS_TYPE_UNDET_BLOOD
Definition: gls.h:184
gls_evt_t::evt_type
gls_evt_type_t evt_type
Definition: gls.h:280
GLS_EVT_CTRL_INDICATION_ENABLED
@ GLS_EVT_CTRL_INDICATION_ENABLED
Definition: gls.h:260
gls_meas_ctx_t::medication
ieee_float16_t medication
Definition: gls.h:324
gls_evt_handler_t
void(* gls_evt_handler_t)(gls_evt_t *p_evt)
Glucose Service event handler type.
Definition: gls.h:292
gls_meas_val_t::sequence_number
uint16_t sequence_number
Definition: gls.h:303
gr55xx_sys.h
GR55XX System API.
gls_meas_type_t
gls_meas_type_t
Glucose measurement type.
Definition: gls.h:177
GLS_MEAS_CTX_CARB_DRINK
@ GLS_MEAS_CTX_CARB_DRINK
Definition: gls.h:207
gls_meas_val_t::type
uint8_t type
Definition: gls.h:307
GLS_EVT_CTRL_INDICATION_DISABLED
@ GLS_EVT_CTRL_INDICATION_DISABLED
Definition: gls.h:261
gls_init_t::evt_handler
gls_evt_handler_t evt_handler
Definition: gls.h:338
gls_meas_ctx_health_t
gls_meas_ctx_health_t
Glucose measurement context health.
Definition: gls.h:233
GLS_MEAS_CTX_MED_PREMIX
@ GLS_MEAS_CTX_MED_PREMIX
Definition: gls.h:249
GLS_MEAS_TYPE_UNDET_PLASMA
@ GLS_MEAS_TYPE_UNDET_PLASMA
Definition: gls.h:185
GLS_EVT_MEAS_NOTIFICATION_DISABLED
@ GLS_EVT_MEAS_NOTIFICATION_DISABLED
Definition: gls.h:257
GLS_MEAS_CTX_MEAL_PREPRANDIAL
@ GLS_MEAS_CTX_MEAL_PREPRANDIAL
Definition: gls.h:215
GLS_MEAS_CTX_HEALTH_MAJOR
@ GLS_MEAS_CTX_HEALTH_MAJOR
Definition: gls.h:235
gls_meas_ctx_carb_id_t
gls_meas_ctx_carb_id_t
Glucose measurement context carbohydrate ID.
Definition: gls.h:202
gls_meas_ctx_t::flags
uint8_t flags
Definition: gls.h:315
GLS_MEAS_CTX_TESTER_SELF
@ GLS_MEAS_CTX_TESTER_SELF
Definition: gls.h:225
GLS_MEAS_LOC_FINGER
@ GLS_MEAS_LOC_FINGER
Definition: gls.h:193
gls_meas_ctx_t::tester_and_health
uint8_t tester_and_health
Definition: gls.h:320
gls_meas_val_t::glucose_concentration
ieee_float16_t glucose_concentration
Definition: gls.h:306
gls_meas_ctx_t::exercise_duration
uint16_t exercise_duration
Definition: gls.h:321
GLS_MEAS_CTX_MED_RAPID
@ GLS_MEAS_CTX_MED_RAPID
Definition: gls.h:245
GLS_MEAS_TYPE_CONTROL
@ GLS_MEAS_TYPE_CONTROL
Definition: gls.h:187
GLS_MEAS_TYPE_CAP_PLASMA
@ GLS_MEAS_TYPE_CAP_PLASMA
Definition: gls.h:179
GLS_MEAS_LOC_CONTROL
@ GLS_MEAS_LOC_CONTROL
Definition: gls.h:196
GLS_MEAS_CTX_MEAL_CASUAL
@ GLS_MEAS_CTX_MEAL_CASUAL
Definition: gls.h:218
GLS_EVT_CTX_NOTIFICATION_ENABLED
@ GLS_EVT_CTX_NOTIFICATION_ENABLED
Definition: gls.h:258
GLS_MEAS_CTX_MED_INTERMED
@ GLS_MEAS_CTX_MED_INTERMED
Definition: gls.h:247
gls_evt_t
Glucose Service event.
Definition: gls.h:279
gls_meas_ctx_t::exercise_intensity
uint8_t exercise_intensity
Definition: gls.h:322
GLS_MEAS_CTX_CARB_BRUNCH
@ GLS_MEAS_CTX_CARB_BRUNCH
Definition: gls.h:209
GLS_EVT_MEAS_NOTIFICATION_ENABLED
@ GLS_EVT_MEAS_NOTIFICATION_ENABLED
Definition: gls.h:256
GLS_MEAS_CTX_TESTER_PRO
@ GLS_MEAS_CTX_TESTER_PRO
Definition: gls.h:226
gls_racp_rsp_send
sdk_err_t gls_racp_rsp_send(uint8_t conn_idx, uint8_t *p_data, uint16_t length)
Send RACP responce if indication has been enabled.
GLS_MEAS_CTX_CARB_DINNER
@ GLS_MEAS_CTX_CARB_DINNER
Definition: gls.h:205
GLS_MEAS_TYPE_VEN_BLOOD
@ GLS_MEAS_TYPE_VEN_BLOOD
Definition: gls.h:180
GLS_MEAS_TYPE_ART_BLOOD
@ GLS_MEAS_TYPE_ART_BLOOD
Definition: gls.h:182
GLS_MEAS_CTX_HEALTH_MINOR
@ GLS_MEAS_CTX_HEALTH_MINOR
Definition: gls.h:234
sdk_err_t
uint16_t sdk_err_t
SDK API result type.
Definition: ble_error.h:243
gls_meas_val_t::sample_location
uint8_t sample_location
Definition: gls.h:308
gls_service_init
sdk_err_t gls_service_init(gls_init_t *p_gls_init)
Initialize a Glucose Service instance and add in the DB.
GLS_MEAS_CTX_TESTER_NOT_AVAIL
@ GLS_MEAS_CTX_TESTER_NOT_AVAIL
Definition: gls.h:228
prf_date_time_t
The date and time structure. The packed size is 7 bytes.
Definition: ble_prf_types.h:101
GLS_MEAS_CTX_CARB_SNACK
@ GLS_MEAS_CTX_CARB_SNACK
Definition: gls.h:206
GLS_MEAS_CTX_HEALTH_NOT_AVAIL
@ GLS_MEAS_CTX_HEALTH_NOT_AVAIL
Definition: gls.h:239
GLS_MEAS_LOC_AST
@ GLS_MEAS_LOC_AST
Definition: gls.h:194
GLS_MEAS_CTX_HEALTH_MENSES
@ GLS_MEAS_CTX_HEALTH_MENSES
Definition: gls.h:236
gls_meas_val_t::flags
uint8_t flags
Definition: gls.h:302
gls_meas_val_t::time_offset
int16_t time_offset
Definition: gls.h:305
gls_rec_t::meas_val
gls_meas_val_t meas_val
Definition: gls.h:331
GLS_MEAS_TYPE_ART_PLASMA
@ GLS_MEAS_TYPE_ART_PLASMA
Definition: gls.h:183
GLS_MEAS_CTX_HEALTH_NONE
@ GLS_MEAS_CTX_HEALTH_NONE
Definition: gls.h:238
gls_meas_val_t::sensor_status_annunciation
uint16_t sensor_status_annunciation
Definition: gls.h:309
GLS_EVT_CTX_NOTIFICATION_DISABLED
@ GLS_EVT_CTX_NOTIFICATION_DISABLED
Definition: gls.h:259
gls_meas_ctx_tester_t
gls_meas_ctx_tester_t
Glucose measurement context tester.
Definition: gls.h:224
GLS_MEAS_TYPE_CAP_BLOOD
@ GLS_MEAS_TYPE_CAP_BLOOD
Definition: gls.h:178
gls_meas_ctx_t::medication_id
uint8_t medication_id
Definition: gls.h:323
gls_meas_ctx_t::hba1c
uint16_t hba1c
Definition: gls.h:325
GLS_EVT_CTRL_WRITE
@ GLS_EVT_CTRL_WRITE
Definition: gls.h:262
GLS_MEAS_CTX_MEAL_BEDTIME
@ GLS_MEAS_CTX_MEAL_BEDTIME
Definition: gls.h:219
gls_meas_ctx_t::meal
uint8_t meal
Definition: gls.h:319
GLS_MEAS_CTX_CARB_LUNCH
@ GLS_MEAS_CTX_CARB_LUNCH
Definition: gls.h:204
gls_init_t::char_mask
uint16_t char_mask
Definition: gls.h:339
gls_init_t
Glucose Service init stucture. This contains all option and data needed for initialization of the ser...
Definition: gls.h:337
gls_meas_ctx_medic_id_t
gls_meas_ctx_medic_id_t
Glucose measurement context medication ID.
Definition: gls.h:244
gls_meas_ctx_t
Glucose measurement context structure.
Definition: gls.h:314
ble_prf_utils.h
Profile/Service Utilities API.
GLS_MEAS_CTX_MEAL_FASTING
@ GLS_MEAS_CTX_MEAL_FASTING
Definition: gls.h:217
GLS_EVT_INVALID
@ GLS_EVT_INVALID
Definition: gls.h:255
gls_evt_type_t
gls_evt_type_t
Glucose Service event type.
Definition: gls.h:254
gls_meas_ctx_t::carbohydrate_id
uint8_t carbohydrate_id
Definition: gls.h:317
GLS_MEAS_CTX_MEAL_POSTPRANDIAL
@ GLS_MEAS_CTX_MEAL_POSTPRANDIAL
Definition: gls.h:216
ieee_float16_t
SFLOAT format (IEEE-11073 16-bit FLOAT, defined as a 16-bit value with 12-bit mantissa and 4-bit expo...
Definition: bps.h:139
gls_rec_t
Glucose measurement record.
Definition: gls.h:330
gls_init_t::feature
uint16_t feature
Definition: gls.h:340
GLS_MEAS_TYPE_FLUID
@ GLS_MEAS_TYPE_FLUID
Definition: gls.h:186
gls_evt_t::length
uint16_t length
Definition: gls.h:283
GLS_MEAS_TYPE_VEN_PLASMA
@ GLS_MEAS_TYPE_VEN_PLASMA
Definition: gls.h:181
GLS_MEAS_CTX_MED_SHORT
@ GLS_MEAS_CTX_MED_SHORT
Definition: gls.h:246
gls_rec_t::meas_ctx
gls_meas_ctx_t meas_ctx
Definition: gls.h:332
GLS_MEAS_CTX_HEALTH_STRESS
@ GLS_MEAS_CTX_HEALTH_STRESS
Definition: gls.h:237
GLS_MEAS_LOC_NOT_AVAIL
@ GLS_MEAS_LOC_NOT_AVAIL
Definition: gls.h:197
gls_evt_t::p_data
const uint8_t * p_data
Definition: gls.h:282
gls_meas_ctx_meal_t
gls_meas_ctx_meal_t
Glucose measurement context meal.
Definition: gls.h:214
gls_meas_ctx_t::extended_flags
uint8_t extended_flags
Definition: gls.h:316