@@ -103,21 +103,117 @@ def insertion_time(self):
103
103
def session_state (self ):
104
104
states = [None , 'REMOVED' , 'EXPIRED' , 'RESIDUAL_DEVIATION' ,
105
105
'COUNTS_DEVIATION' , 'SECOND_SESSION' , 'OFF_TIME_LOSS' ,
106
- 'STARTED' , 'BAD_TRANSMITTER' , 'MANUFACTURING_MODE' ]
106
+ 'STARTED' , 'BAD_TRANSMITTER' , 'MANUFACTURING_MODE' ,
107
+ 'UNKNOWN1' , 'UNKNOWN2' , 'UNKNOWN3' , 'UNKNOWN4' , 'UNKNOWN5' ,
108
+ 'UNKNOWN6' , 'UNKNOWN7' , 'UNKNOWN8' ]
107
109
return states [ord (self .data [3 ])]
108
110
109
111
def __repr__ (self ):
110
112
return '%s: state=%s' % (self .display_time , self .session_state )
111
113
114
+ class G5InsertionRecord (InsertionRecord ):
115
+ FORMAT = '<3Ic10BH'
112
116
113
117
class Calibration (GenericTimestampedRecord ):
118
+ FORMAT = '<2Iddd3cdb'
119
+ # CAL_FORMAT = '<2Iddd3cdb'
120
+ FIELDS = [ 'slope' , 'intercept' , 'scale' , 'decay' , 'numsub' , 'raw' ]
114
121
@property
115
- def raw (self ):
116
- return binascii .hexlify (bytearray (self .data ))
122
+ def raw (self ):
123
+ return binascii .hexlify (self .raw_data )
124
+ @property
125
+ def slope (self ):
126
+ return self .data [2 ]
127
+ @property
128
+ def intercept (self ):
129
+ return self .data [3 ]
130
+ @property
131
+ def scale (self ):
132
+ return self .data [4 ]
133
+ @property
134
+ def decay (self ):
135
+ return self .data [8 ]
136
+ @property
137
+ def numsub (self ):
138
+ return int (self .data [9 ])
117
139
118
140
def __repr__ (self ):
119
141
return '%s: CAL SET:%s' % (self .display_time , self .raw )
120
142
143
+ LEGACY_SIZE = 148
144
+ REV_2_SIZE = 249
145
+ @classmethod
146
+ def _ClassSize (cls ):
147
+
148
+ return cls .REV_2_SIZE
149
+
150
+ @classmethod
151
+ def Create (cls , data , record_counter ):
152
+ offset = record_counter * cls ._ClassSize ()
153
+ cal_size = struct .calcsize (cls .FORMAT )
154
+ raw_data = data [offset :offset + cls ._ClassSize ()]
155
+
156
+ cal_data = data [offset :offset + cal_size ]
157
+ unpacked_data = cls ._ClassFormat ().unpack (cal_data )
158
+ return cls (unpacked_data , raw_data )
159
+
160
+ def __init__ (self , data , raw_data ):
161
+ self .page_data = raw_data
162
+ self .raw_data = raw_data
163
+ self .data = data
164
+ subsize = struct .calcsize (SubCal .FORMAT )
165
+ offset = self .numsub * subsize
166
+ calsize = struct .calcsize (self .FORMAT )
167
+ caldata = raw_data [:calsize ]
168
+ subdata = raw_data [calsize :calsize + offset ]
169
+ crcdata = raw_data [calsize + offset :calsize + offset + 2 ]
170
+
171
+ subcals = [ ]
172
+ for i in xrange (self .numsub ):
173
+ offset = i * subsize
174
+ raw_sub = subdata [offset :offset + subsize ]
175
+ sub = SubCal (raw_sub , self .data [1 ])
176
+ subcals .append (sub )
177
+
178
+ self .subcals = subcals
179
+
180
+ self .check_crc ()
181
+ def to_dict (self ):
182
+ res = super (Calibration , self ).to_dict ( )
183
+ res ['subrecords' ] = [ sub .to_dict ( ) for sub in self .subcals ]
184
+ return res
185
+ @property
186
+ def crc (self ):
187
+ return struct .unpack ('H' , self .raw_data [- 2 :])[0 ]
188
+
189
+ class LegacyCalibration (Calibration ):
190
+ @classmethod
191
+ def _ClassSize (cls ):
192
+
193
+ return cls .LEGACY_SIZE
194
+
195
+
196
+ class SubCal (GenericTimestampedRecord ):
197
+ FORMAT = '<IIIIc'
198
+ BASE_FIELDS = [ ]
199
+ FIELDS = [ 'entered' , 'meter' , 'sensor' , 'applied' , ]
200
+ def __init__ (self , raw_data , displayOffset = None ):
201
+ self .raw_data = raw_data
202
+ self .data = self ._ClassFormat ().unpack (raw_data )
203
+ self .displayOffset = displayOffset
204
+ @property
205
+ def entered (self ):
206
+ return util .ReceiverTimeToTime (self .data [0 ])
207
+ @property
208
+ def meter (self ):
209
+ return int (self .data [1 ])
210
+ @property
211
+ def sensor (self ):
212
+ return int (self .data [2 ])
213
+ @property
214
+ def applied (self ):
215
+ return util .ReceiverTimeToTime (self .data [3 ])
216
+
121
217
class MeterRecord (GenericTimestampedRecord ):
122
218
FORMAT = '<2IHIH'
123
219
FIELDS = ['meter_glucose' , 'meter_time' ]
@@ -133,6 +229,8 @@ def meter_time(self):
133
229
def __repr__ (self ):
134
230
return '%s: Meter BG:%s' % (self .display_time , self .meter_glucose )
135
231
232
+ class G5MeterRecord (MeterRecord ):
233
+ FORMAT = '<2IHI5BH'
136
234
137
235
class EventRecord (GenericTimestampedRecord ):
138
236
# sys_time,display_time,glucose,meter_time,crc
@@ -230,3 +328,11 @@ def __repr__(self):
230
328
else :
231
329
return '%s: CGM BG:%s (%s) DO:%s' % (self .display_time , self .glucose ,
232
330
self .trend_arrow , self .display_only )
331
+
332
+ class G5EGVRecord (EGVRecord ):
333
+ FORMAT = '<2IHBBBBBBBBBcBH'
334
+ @property
335
+ def full_trend (self ):
336
+ return self .data [12 ]
337
+
338
+
0 commit comments