CGM Simulator  0.1.3
A CGM simulator to demonstrate the BLE CGM profile v1.1
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
cgmservice.h
Go to the documentation of this file.
1 
17 #ifndef CGMSERVICE_H
18 #define CGMSERVICE_H
19 #ifdef __cplusplus
20 extern "C"
21 {
22 #endif
23 
24 /*
25  * INCLUDES
26  */
27 #include "OSAL_clock.h"
28 
29 /*
30  * CONSTANTS
31  */
32 
33 //ATT level constants. They can be allocated in "TEXAS INSTRUMENTS\BLE-CC254X-1.4.0\COMPONENTS\ble\include\att.h"
34 #ifndef ATT_ERR_MISSING_CRC
35 #define ATT_ERR_MISSING_CRC 0x80
36 #endif
37 #ifndef ATT_ERR_INVALID_CRC
38 #define ATT_ERR_INVALID_CRC 0x81
39 #endif
40 #ifndef ATT_ERR_INVALID_VALUE
41 #define ATT_ERR_INVALID_VALUE 0x82
42 #endif
43 #ifndef ATT_ERR_INVALID_OPCP_OPCODE
44 #define ATT_ERR_INVALID_OPCP_OPCODE 0x83
45 #endif
46 
47 // Glucose Service bit fields
48 #define CGM_SERVICE 0x00000001
49 
50 // Characteristic Value sizes
51 #define CGM_CTL_PNT_MIN_SIZE 1
52 #define CGM_CTL_PNT_MAX_SIZE 20
53 #define CGM_RACP_MIN_SIZE 2
54 #define CGM_RACP_MAX_SIZE 20
55 
56 //CGM Callback events
57 #define CGM_MEAS_NTF_ENABLED 1
58 #define CGM_MEAS_NTF_DISABLED 2
59 #define CGM_CONTEXT_NTF_ENABLED 3
60 #define CGM_CONTEXT_NTF_DISABLED 4
61 #define CGM_CTL_PNT_IND_ENABLED 5
62 #define CGM_CTL_PNT_IND_DISABLED 6
63 #define CGM_CTL_PNT_CMD 7
64 #define CGM_RACP_CTL_PNT_CMD 8
65 #define CGM_SESSION_START_TIME_CHANGED 9
66 #define CGM_FEATURE_READ_REQUEST 10
67 #define CGM_STATUS_READ_REQUEST 11
68 #define CGM_START_TIME_READ_REQUEST 12
69 #define CGM_RUN_TIME_READ_REQUEST 13
70 #define CGM_START_TIME_WRITE_REQUEST 14
71 #define CGM_RACP_IND_DISABLED 15
72 #define CGM_RACP_IND_ENABLED 16
73 
74 // ATT status values
75 #define CGM_ERR_IN_PROGRESS 0xFE
76 #define CGM_ERR_CCC_CONFIG 0xFD
77 
78 // CGM Service UUID
79 #define CGM_SERV_UUID 0x181F
80 
81 // CGM Service Characteristic UUID
82 #define CGM_MEAS_UUID 0x2AA7
83 #define CGM_FEATURE_UUID 0x2AA8
84 #define CGM_STATUS_UUID 0x2AA9
85 #define CGM_SES_START_TIME_UUID 0x2AAA
86 #define CGM_SES_RUN_TIME_UUID 0x2AAB
87 #define REC_ACCESS_CTRL_PT_UUID 0x2A52
88 #define CGM_SPEC_OPS_CTRL_PT_UUID 0x2AAC
89 
90 // values for CGM meas flags
91 #define CGM_TREND_INFO_PRES 0x01
92 #define CGM_QUALITY_PRES 0x02
93 #define CGM_STATUS_ANNUNC_WARNING_OCT 0x20
94 #define CGM_STATUS_ANNUNC_CAL_TEMP_OCT 0x40
95 #define CGM_STATUS_ANNUNC_STATUS_OCT 0x80
96 
97 // value for CGM status annuciation field
98 #define CGM_STATUS_ANNUNC_SES_STOP 0x000001
99 #define CGM_STATUS_ANNUNC_BAT_LOW 0x000002
100 #define CGM_STATUS_ANNUNC_WRONG_SENSOR_TYPE 0x000004
101 #define CGM_STATUS_ANNUNC_SENSOR_MALFUNC 0x000008
102 #define CGM_STATUS_ANNUNC_DEVICE_SPEC_ALERT 0x000010
103 #define CGM_STATUS_ANNUNC_GNERAL_DEVICE_FAULT 0x000020
104 #define CGM_STATUS_ANNUNC_REQ_TIME_SYNC 0x000100
105 #define CGM_STATUS_ANNUNC_NOT_ALLOWED_CAL 0x000200
106 #define CGM_STATUS_ANNUNC_RECOM_CAL 0x000400
107 #define CGM_STATUS_ANNUNC_REQ_CAL 0x000800
108 #define CGM_STATUS_ANNUNC_HIGH_TEMP 0x001000
109 #define CGM_STATUS_ANNUNC_LOW_TEMP 0x002000
110 #define CGM_STATUS_ANNUNC_LOW_PATIENT 0x010000
111 #define CGM_STATUS_ANNUNC_HIGH_PATIRNT 0x020000
112 #define CGM_STATUS_ANNUNC_LOW_HYPO 0x040000
113 #define CGM_STATUS_ANNUNC_HIGH_HYPER 0x080000
114 #define CGM_STATUS_ANNUNC_EXCEEDED_DESC_RATE 0x100000
115 #define CGM_STATUS_ANNUNC_EXCEEDED_INCR_RATE 0x200000
116 #define CGM_STATUS_ANNUNC_LOW_NIR 0x400000
117 #define CGM_STATUS_ANNUNC_HIGH_NIR 0x800000
118 
119 // value for CGM feature flag org.bluetooth.characteristic.cgm_feature.xml
120 #define CGM_FEATURE_CAL 0x000001
121 #define CGM_FEATURE_ALERTS_HIGH_LOW 0x000002
122 #define CGM_FEATURE_ALERTS_HYPO 0x000004
123 #define CGM_FEATURE_ALERTS_HYPER 0x000008
124 #define CGM_FEATURE_ALERTS_INC_DEC 0x000010
125 #define CGM_FEATURE_ALERTS_DEVICE_SPEC 0x000020
126 #define CGM_FEATURE_DETECTION_SENSOR_MALFUNC 0x000040
127 #define CGM_FEATURE_DETECTION_TEMP_HIGH_LOW 0x000080
128 #define CGM_FEATURE_DETECTION_RESULT_HIGH_LOW 0x000100
129 #define CGM_FEATURE_DETECTION_BAT_LOW 0x000200
130 #define CGM_FEATURE_DETECTION_SENSOR_TYPE_ERR 0x000400
131 #define CGM_FEATURE_FAULT_GENERAL_DEVICE 0x000800
132 #define CGM_FEATURE_E2E_CRC 0x001000
133 #define CGM_FEATURE_MULTI_BOND 0x002000
134 #define CGM_FEATURE_MULTI_SES 0x004000
135 #define CGM_FEATURE_TREND_INFO 0x008000
136 #define CGM_FEATURE_QUALITY 0x010000
137 
138 // CGM Type-Sample byte
139 // values for CGM type information flag 4 bit lower nimble
140 #define CGM_TYPE_CAPILLARY_WHOLE_BLOOD 0x01
141 #define CGM_TYPE_CAPILLARY_PLASMA 0x02
142 #define CGM_TYPE_CAPILLARY_WHOLE_BLOOD2 0x03
143 #define CGM_TYPE_VENOUS_PLASMA 0x04
144 #define CGM_TYPE_ARTERIAL_WHOLE_BLOOD 0x05
145 #define CGM_TYPE_ARTERIAL_PLASMA 0x06
146 #define CGM_TYPE_UNDET_WHOLE_BLOOD 0x07
147 #define CGM_TYPE_UNDET_PLASMA 0x08
148 #define CGM_TYPE_ISF 0x09
149 #define CGM_TYPE_CTRL_SOLUTION 0x0A
150 
151 // values for CGM sample location 4 bit higher nimble
152 #define CGM_SAMPLE_LOC_FINGER 0x01
153 #define CGM_SAMPLE_LOC_AST 0x02
154 #define CGM_SAMPLE_LOC_EARLOB 0X03
155 #define CGM_SAMPLE_LOC_CTRL_SOLUTION 0x04
156 #define CGM_SAMPLE_LOC_SUBCUT_TISSUE 0x05
157 #define CGM_SAMPLE_LOC_UNAVAIL 0x0F
158 
159 // The time value for start time/ run time etc. is obviously implemented
160 // https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.date_time.xml
161 // Time Zone Infomation sint8
162 #define TIME_ZONE_UTC_M12 -48
163 #define TIME_ZONE_UTC_M11 -44
164 #define TIME_ZONE_UTC_M10 -40
165 #define TIME_ZONE_UTC_M9p5 -38
166 #define TIME_ZONE_UTC_M9 -36
167 #define TIME_ZONE_UTC_M8 -32
168 #define TIME_ZONE_UTC_M7 -28
169 #define TIME_ZONE_UTC_M6 -24
170 #define TIME_ZONE_UTC_M5 -20
171 #define TIME_ZONE_UTC_M4p5 -18
172 #define TIME_ZONE_UTC_M4 -16
173 #define TIME_ZONE_UTC_M3p5 -14
174 #define TIME_ZONE_UTC_M3 -12
175 #define TIME_ZONE_UTC_M2 -8
176 #define TIME_ZONE_UTC_M1 -4
177 #define TIME_ZONE_UTC_P0 0
178 #define TIME_ZONE_UTC_P1 4
179 #define TIME_ZONE_UTC_P2 8
180 #define TIME_ZONE_UTC_P3 12
181 #define TIME_ZONE_UTC_P3p5 14
182 #define TIME_ZONE_UTC_P4 16
183 #define TIME_ZONE_UTC_P4p5 18
184 #define TIME_ZONE_UTC_P5 20
185 #define TIME_ZONE_UTC_P5p5 22
186 #define TIME_ZONE_UTC_P5p75 23
187 #define TIME_ZONE_UTC_P6 24
188 #define TIME_ZONE_UTC_P6p5 26
189 #define TIME_ZONE_UTC_P7 28
190 #define TIME_ZONE_UTC_P8 32
191 #define TIME_ZONE_UTC_P8p75 35
192 #define TIME_ZONE_UTC_P9 36
193 #define TIME_ZONE_UTC_P9p5 38
194 #define TIME_ZONE_UTC_P10 40
195 #define TIME_ZONE_UTC_P10p5 42
196 #define TIME_ZONE_UTC_P11 44
197 #define TIME_ZONE_UTC_P11p5 46
198 #define TIME_ZONE_UTC_P12 48
199 #define TIME_ZONE_UTC_P12p75 51
200 #define TIME_ZONE_UTC_P13 52
201 #define TIME_ZONE_UTC_P14 56
202 #define TIME_ZONE_UNKNOWN -128
203 
204 // DST Offset information uint8
205 // https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.dst_offset.xml
206 #define DST_STANDARD_TIME 0x00
207 #define DST_HALF_HOUR_DAYLIGHT 0x02
208 #define DST_ONE_HOUR_DAYLIGHT 0x04
209 #define DST_DOUBLE_HOUR_DAYLIGHT 0x08
210 #define DST_UNKNOWN 0xFF
211 
212 // Record Control Access Point
213 //Record Control Point values OP Codes
214 //https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.record_access_control_point.xml
215 #define CTL_PNT_OP_REQ 0x01
216 #define CTL_PNT_OP_CLR 0x02
217 #define CTL_PNT_OP_ABORT 0x03
218 #define CTL_PNT_OP_GET_NUM 0x04
219 #define CTL_PNT_OP_NUM_RSP 0x05
220 #define CTL_PNT_OP_REQ_RSP 0x06
221 
222 //Record Control Point operator
223 #define CTL_PNT_OPER_NULL 0x00
224 #define CTL_PNT_OPER_ALL 0x01
225 #define CTL_PNT_OPER_LESS_EQUAL 0x02
226 #define CTL_PNT_OPER_GREATER_EQUAL 0x03
227 #define CTL_PNT_OPER_RANGE 0x04
228 #define CTL_PNT_OPER_FIRST 0x05
229 #define CTL_PNT_OPER_LAST 0x06
230 
231 //Record Control Point Response Codes
232 #define CTL_PNT_RSP_SUCCESS 0x01
233 #define CTL_PNT_RSP_OPCODE_NOT_SUPPORTED 0x02
234 #define CTL_PNT_RSP_OPER_INVALID 0x03
235 #define CTL_PNT_RSP_OPER_NOT_SUPPORTED 0x04
236 #define CTL_PNT_RSP_OPERAND_INVALID 0x05
237 #define CTL_PNT_RSP_NO_RECORDS 0x06
238 #define CTL_PNT_RSP_ABORT_FAILED 0x07
239 #define CTL_PNT_RSP_PROC_NOT_CMPL 0x08
240 #define CTL_PNT_RSP_FILTER_NOT_SUPPORTED 0x09
241 
242 //Record Control Point Resposne Filter
243 #define CTL_PNT_FILTER_TIME_OFFSET 0x01
244 // CGM Specific operation codes
245 #define CGM_SPEC_OP_SET_INTERVAL 1
246 #define CGM_SPEC_OP_GET_INTERVAL 2
247 #define CGM_SPEC_OP_RESP_INTERVAL 3
248 #define CGM_SPEC_OP_SET_CAL 4
249 #define CGM_SPEC_OP_GET_CAL 5
250 #define CGM_SPEC_OP_RESP_CAL 6
251 #define CGM_SPEC_OP_SET_ALERT_HIGH 7
252 #define CGM_SPEC_OP_GET_ALERT_HIGH 8
253 #define CGM_SPEC_OP_RESP_ALERT_HIGH 9
254 #define CGM_SPEC_OP_SET_ALERT_LOW 10
255 #define CGM_SPEC_OP_GET_ALERT_LOW 11
256 #define CGM_SPEC_OP_RESP_ALERT_LOW 12
257 #define CGM_SPEC_OP_SET_ALERT_HYPO 13
258 #define CGM_SPEC_OP_GET_ALERT_HYPO 14
259 #define CGM_SPEC_OP_RESP_ALERT_HYPO 15
260 #define CGM_SPEC_OP_SET_ALERT_HYPER 16
261 #define CGM_SPEC_OP_GET_ALERT_HYPER 17
262 #define CGM_SPEC_OP_RESP_ALERT_HYPER 18
263 #define CGM_SPEC_OP_SET_ALERT_RATE_DECREASE 19
264 #define CGM_SPEC_OP_GET_ALERT_RATE_DECREASE 20
265 #define CGM_SPEC_OP_RESP_ALERT_RATE_DECREASE 21
266 #define CGM_SPEC_OP_SET_ALERT_RATE_INCREASE 22
267 #define CGM_SPEC_OP_GET_ALERT_RATE_INCREASE 23
268 #define CGM_SPEC_OP_RESP_ALERT_RATE_INCREASE 24
269 #define CGM_SPEC_OP_RESET_ALERT_DEVICE_SPEC 25
270 #define CGM_SPEC_OP_START_SES 26
271 #define CGM_SPEC_OP_STOP_SES 27
272 #define CGM_SPEC_OP_RESP_CODE 28
273 
274 // CGM specific op code - resposne codes
275 #define CGM_SPEC_OP_RESP_SUCCESS 1
276 #define CGM_SPEC_OP_RESP_OP_NOT_SUPPORT 2
277 #define CGM_SPEC_OP_RESP_OPERAND_INVALID 3
278 #define CGM_SPEC_OP_RESP_PROCEDURE_NOT_COMPLETE 4
279 #define CGM_SPEC_OP_RESP_PARAM_NIR 5
280 
281 // CGM Calibration Status
282 #define CGM_CALIBRATION_REJECT 0x01
283 #define CGM_CALIBRATION_NIR 0x02
284 #define CGM_CALIBRATION_PENDING 0x04
285 #define CGM_CALIBRATION_CLEAR 0x00
286 
287 // Unit UUID
288 #define UNIT_MASSDENSITY_MG_PER_DL 0x27B1
289 #define UNIT_TIME_MIN 0x2760
290 
291 // The following definition is inferred from the CGM profile specification
292 #define CGM_CHAR_VAL_SIZE_FEATURE 6
293 #define CGM_CHAR_VAL_SIZE_STATUS 5
294 #define CGM_CHAR_VAL_SIZE_START_TIME 9
295 #define CGM_CHAR_VAL_SIZE_RUN_TIME 2
296 
297 /*
298  * TYPEDEFS
299  */
300 // Glucose Service callback function
301 typedef void (*CGMServiceCB_t)(uint8 event, uint8* data, uint8 *dataLen,uint8 *result);
302 
303 /*
304  * MACROS
305  */
306 
307 /*
308  * Profile Callbacks
309  */
310 
311 /*
312  * API FUNCTIONS
313  */
314 
315 extern bStatus_t CGM_AddService( uint32 services );
316 
317 extern void CGM_Register( CGMServiceCB_t pfnServiceCB);
318 
326 extern bStatus_t CGM_MeasSend( uint16 connHandle, attHandleValueNoti_t *pNoti, uint8 taskId );
327 
335 extern bStatus_t CGM_ContextSend( uint16 connHandle, attHandleValueNoti_t *pNoti, uint8 taskId );
336 
345 extern bStatus_t CGM_CtlPntIndicate( uint16 connHandle, attHandleValueInd_t *pInd, uint8 taskId );
346 
355 extern bStatus_t CGM_RACPIndicate( uint16 connHandle, attHandleValueInd_t *pInd, uint8 taskId );
356 
362 extern bool CGM_SetSendState(bool input);
363 
364 #ifdef __cplusplus
365 }
366 #endif
367 
368 #endif /* CGMSERVICE_H */
bStatus_t CGM_MeasSend(uint16 connHandle, attHandleValueNoti_t *pNoti, uint8 taskId)
Send a CGM measurement via the CGM measurement notification.
Definition: cgmservice.c:351
void(* CGMServiceCB_t)(uint8 event, uint8 *data, uint8 *dataLen, uint8 *result)
Definition: cgmservice.h:301
void CGM_Register(CGMServiceCB_t pfnServiceCB)
Register a callback function with the CGM Service.
Definition: cgmservice.c:338
bStatus_t CGM_CtlPntIndicate(uint16 connHandle, attHandleValueInd_t *pInd, uint8 taskId)
Send an indication containing a CGM measurement.
Definition: cgmservice.c:375
bStatus_t CGM_AddService(uint32 services)
Initializes the CGM service by registering GATT attributes with the GATT server.
Definition: cgmservice.c:316
bool CGM_SetSendState(bool input)
Set the state of the CGM database transmission indicator.
Definition: cgmservice.c:619
bStatus_t CGM_RACPIndicate(uint16 connHandle, attHandleValueInd_t *pInd, uint8 taskId)
Send an indication to the RACP characteristic.
Definition: cgmservice.c:396
bStatus_t CGM_ContextSend(uint16 connHandle, attHandleValueNoti_t *pNoti, uint8 taskId)
Send a CGM measurement context.