123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- #ifndef BLE_GLS_H__
- #define BLE_GLS_H__
- #include <stdint.h>
- #include <stdbool.h>
- #include "ble.h"
- #include "ble_srv_common.h"
- #include "ble_date_time.h"
- #include "nrf_ble_gq.h"
- #include "nrf_sdh_ble.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define BLE_GLS_DEF(_name) \
- static ble_gls_t _name; \
- NRF_SDH_BLE_OBSERVER(_name ## _obs, \
- BLE_GLS_BLE_OBSERVER_PRIO, \
- ble_gls_on_ble_evt, &_name)
- #define BLE_GLS_FEATURE_LOW_BATT 0x0001
- #define BLE_GLS_FEATURE_MALFUNC 0x0002
- #define BLE_GLS_FEATURE_SAMPLE_SIZE 0x0004
- #define BLE_GLS_FEATURE_INSERT_ERR 0x0008
- #define BLE_GLS_FEATURE_TYPE_ERR 0x0010
- #define BLE_GLS_FEATURE_RES_HIGH_LOW 0x0020
- #define BLE_GLS_FEATURE_TEMP_HIGH_LOW 0x0040
- #define BLE_GLS_FEATURE_READ_INT 0x0080
- #define BLE_GLS_FEATURE_GENERAL_FAULT 0x0100
- #define BLE_GLS_FEATURE_TIME_FAULT 0x0200
- #define BLE_GLS_FEATURE_MULTI_BOND 0x0400
- #define BLE_GLS_MEAS_FLAG_TIME_OFFSET 0x01
- #define BLE_GLS_MEAS_FLAG_CONC_TYPE_LOC 0x02
- #define BLE_GLS_MEAS_FLAG_UNITS_KG_L 0x00
- #define BLE_GLS_MEAS_FLAG_UNITS_MOL_L 0x04
- #define BLE_GLS_MEAS_FLAG_SENSOR_STATUS 0x08
- #define BLE_GLS_MEAS_FLAG_CONTEXT_INFO 0x10
- #define BLE_GLS_MEAS_TYPE_CAP_BLOOD 1
- #define BLE_GLS_MEAS_TYPE_CAP_PLASMA 2
- #define BLE_GLS_MEAS_TYPE_VEN_BLOOD 3
- #define BLE_GLS_MEAS_TYPE_VEN_PLASMA 4
- #define BLE_GLS_MEAS_TYPE_ART_BLOOD 5
- #define BLE_GLS_MEAS_TYPE_ART_PLASMA 6
- #define BLE_GLS_MEAS_TYPE_UNDET_BLOOD 7
- #define BLE_GLS_MEAS_TYPE_UNDET_PLASMA 8
- #define BLE_GLS_MEAS_TYPE_FLUID 9
- #define BLE_GLS_MEAS_TYPE_CONTROL 10
- #define BLE_GLS_MEAS_LOC_FINGER 1
- #define BLE_GLS_MEAS_LOC_AST 2
- #define BLE_GLS_MEAS_LOC_EAR 3
- #define BLE_GLS_MEAS_LOC_CONTROL 4
- #define BLE_GLS_MEAS_LOC_NOT_AVAIL 15
- #define BLE_GLS_MEAS_STATUS_BATT_LOW 0x0001
- #define BLE_GLS_MEAS_STATUS_SENSOR_FAULT 0x0002
- #define BLE_GLS_MEAS_STATUS_SAMPLE_SIZE 0x0004
- #define BLE_GLS_MEAS_STATUS_STRIP_INSERT 0x0008
- #define BLE_GLS_MEAS_STATUS_STRIP_TYPE 0x0010
- #define BLE_GLS_MEAS_STATUS_RESULT_HIGH 0x0020
- #define BLE_GLS_MEAS_STATUS_RESULT_LOW 0x0040
- #define BLE_GLS_MEAS_STATUS_TEMP_HIGH 0x0080
- #define BLE_GLS_MEAS_STATUS_TEMP_LOW 0x0100
- #define BLE_GLS_MEAS_STATUS_STRIP_PULL 0x0200
- #define BLE_GLS_MEAS_STATUS_GENERAL_FAULT 0x0400
- #define BLE_GLS_MEAS_STATUS_TIME_FAULT 0x0800
- #define BLE_GLS_CONTEXT_FLAG_CARB 0x01
- #define BLE_GLS_CONTEXT_FLAG_MEAL 0x02
- #define BLE_GLS_CONTEXT_FLAG_TESTER 0x04
- #define BLE_GLS_CONTEXT_FLAG_EXERCISE 0x08
- #define BLE_GLS_CONTEXT_FLAG_MED 0x10
- #define BLE_GLS_CONTEXT_FLAG_MED_KG 0x00
- #define BLE_GLS_CONTEXT_FLAG_MED_L 0x20
- #define BLE_GLS_CONTEXT_FLAG_HBA1C 0x40
- #define BLE_GLS_CONTEXT_FLAG_EXT 0x80
- #define BLE_GLS_CONTEXT_CARB_BREAKFAST 1
- #define BLE_GLS_CONTEXT_CARB_LUNCH 2
- #define BLE_GLS_CONTEXT_CARB_DINNER 3
- #define BLE_GLS_CONTEXT_CARB_SNACK 4
- #define BLE_GLS_CONTEXT_CARB_DRINK 5
- #define BLE_GLS_CONTEXT_CARB_SUPPER 6
- #define BLE_GLS_CONTEXT_CARB_BRUNCH 7
- #define BLE_GLS_CONTEXT_MEAL_PREPRANDIAL 1
- #define BLE_GLS_CONTEXT_MEAL_POSTPRANDIAL 2
- #define BLE_GLS_CONTEXT_MEAL_FASTING 3
- #define BLE_GLS_CONTEXT_MEAL_CASUAL 4
- #define BLE_GLS_CONTEXT_MEAL_BEDTIME 5
- #define BLE_GLS_CONTEXT_TESTER_SELF 1
- #define BLE_GLS_CONTEXT_TESTER_PRO 2
- #define BLE_GLS_CONTEXT_TESTER_LAB 3
- #define BLE_GLS_CONTEXT_TESTER_NOT_AVAIL 15
- #define BLE_GLS_CONTEXT_HEALTH_MINOR 1
- #define BLE_GLS_CONTEXT_HEALTH_MAJOR 2
- #define BLE_GLS_CONTEXT_HEALTH_MENSES 3
- #define BLE_GLS_CONTEXT_HEALTH_STRESS 4
- #define BLE_GLS_CONTEXT_HEALTH_NONE 5
- #define BLE_GLS_CONTEXT_HEALTH_NOT_AVAIL 15
- #define BLE_GLS_CONTEXT_MED_RAPID 1
- #define BLE_GLS_CONTEXT_MED_SHORT 2
- #define BLE_GLS_CONTEXT_MED_INTERMED 3
- #define BLE_GLS_CONTEXT_MED_LONG 4
- #define BLE_GLS_CONTEXT_MED_PREMIX 5
- typedef struct
- {
- int8_t exponent;
- int16_t mantissa;
- } sfloat_t;
- typedef enum
- {
- BLE_GLS_EVT_NOTIFICATION_ENABLED,
- BLE_GLS_EVT_NOTIFICATION_DISABLED
- } ble_gls_evt_type_t;
- typedef struct
- {
- ble_gls_evt_type_t evt_type;
- } ble_gls_evt_t;
- typedef struct ble_gls_s ble_gls_t;
- typedef void (*ble_gls_evt_handler_t)(ble_gls_t * p_gls, ble_gls_evt_t * p_evt);
- typedef struct
- {
- uint8_t flags;
- uint16_t sequence_number;
- ble_date_time_t base_time;
- int16_t time_offset;
- sfloat_t glucose_concentration;
- uint8_t type;
- uint8_t sample_location;
- uint16_t sensor_status_annunciation;
- } ble_gls_meas_t;
- typedef struct
- {
- uint8_t flags;
- uint8_t extended_flags;
- uint8_t carbohydrate_id;
- sfloat_t carbohydrate;
- uint8_t meal;
- uint8_t tester_and_health;
- uint16_t exercise_duration;
- uint8_t exercise_intensity;
- uint8_t medication_id;
- sfloat_t medication;
- uint16_t hba1c;
- } ble_gls_meas_context_t;
- typedef struct
- {
- ble_gls_meas_t meas;
- ble_gls_meas_context_t context;
- } ble_gls_rec_t;
- typedef struct
- {
- ble_gls_evt_handler_t evt_handler;
- ble_srv_error_handler_t error_handler;
- uint16_t feature;
- bool is_context_supported;
- security_req_t gl_meas_cccd_wr_sec;
- security_req_t gl_feature_rd_sec;
- security_req_t racp_cccd_wr_sec;
- security_req_t racp_wr_sec;
- nrf_ble_gq_t * p_gatt_queue;
- } ble_gls_init_t;
- struct ble_gls_s
- {
- ble_gls_evt_handler_t evt_handler;
- ble_srv_error_handler_t error_handler;
- uint16_t service_handle;
- ble_gatts_char_handles_t glm_handles;
- ble_gatts_char_handles_t glm_context_handles;
- ble_gatts_char_handles_t glf_handles;
- ble_gatts_char_handles_t racp_handles;
- uint16_t conn_handle;
- nrf_ble_gq_t * p_gatt_queue;
- uint16_t feature;
- bool is_context_supported;
- };
- uint32_t ble_gls_init(ble_gls_t * p_gls, ble_gls_init_t const * p_gls_init);
- void ble_gls_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context);
- uint32_t ble_gls_glucose_new_meas(ble_gls_t * p_gls, ble_gls_rec_t * p_rec);
- #ifdef __cplusplus
- }
- #endif
- #endif
|