@@ -111,13 +111,99 @@ def __repr__(self):
111
111
112
112
113
113
class Calibration (GenericTimestampedRecord ):
114
+ FORMAT = '<2Iddd3cdb'
115
+ # CAL_FORMAT = '<2Iddd3cdb'
116
+ FIELDS = [ 'slope' , 'intercept' , 'scale' , 'decay' , 'numsub' , 'raw' ]
114
117
@property
115
- def raw (self ):
116
- return binascii .hexlify (bytearray (self .data ))
118
+ def raw (self ):
119
+ return binascii .hexlify (self .raw_data )
120
+ @property
121
+ def slope (self ):
122
+ return self .data [2 ]
123
+ @property
124
+ def intercept (self ):
125
+ return self .data [3 ]
126
+ @property
127
+ def scale (self ):
128
+ return self .data [4 ]
129
+ @property
130
+ def decay (self ):
131
+ return self .data [8 ]
132
+ @property
133
+ def numsub (self ):
134
+ return int (self .data [9 ])
117
135
118
136
def __repr__ (self ):
119
137
return '%s: CAL SET:%s' % (self .display_time , self .raw )
120
138
139
+ LEGACY_SIZE = 148
140
+ REV_2_SIZE = 249
141
+ @classmethod
142
+ def _ClassSize (cls ):
143
+
144
+ return cls .REV_2_SIZE
145
+
146
+ @classmethod
147
+ def Create (cls , data , record_counter ):
148
+ offset = record_counter * cls ._ClassSize ()
149
+ cal_size = struct .calcsize (cls .FORMAT )
150
+ raw_data = data [offset :offset + cls ._ClassSize ()]
151
+
152
+ cal_data = data [offset :offset + cal_size ]
153
+ unpacked_data = cls ._ClassFormat ().unpack (cal_data )
154
+ return cls (unpacked_data , raw_data )
155
+
156
+ def __init__ (self , data , raw_data ):
157
+ self .page_data = raw_data
158
+ self .raw_data = raw_data
159
+ self .data = data
160
+ subsize = struct .calcsize (SubCal .FORMAT )
161
+ offset = self .numsub * subsize
162
+ calsize = struct .calcsize (self .FORMAT )
163
+ caldata = raw_data [:calsize ]
164
+ subdata = raw_data [calsize :calsize + offset ]
165
+ crcdata = raw_data [calsize + offset :calsize + offset + 2 ]
166
+
167
+ subcals = [ ]
168
+ for i in xrange (self .numsub ):
169
+ offset = i * subsize
170
+ raw_sub = subdata [offset :offset + subsize ]
171
+ sub = SubCal (raw_sub , self .data [1 ])
172
+ subcals .append (sub )
173
+
174
+ self .subcals = subcals
175
+
176
+ self .check_crc ()
177
+ def to_dict (self ):
178
+ res = super (Calibration , self ).to_dict ( )
179
+ res ['subrecords' ] = [ sub .to_dict ( ) for sub in self .subcals ]
180
+ return res
181
+ @property
182
+ def crc (self ):
183
+ return struct .unpack ('H' , self .raw_data [- 2 :])[0 ]
184
+
185
+
186
+ class SubCal (GenericTimestampedRecord ):
187
+ FORMAT = '<IIIIc'
188
+ BASE_FIELDS = [ ]
189
+ FIELDS = [ 'entered' , 'meter' , 'sensor' , 'applied' , ]
190
+ def __init__ (self , raw_data , displayOffset = None ):
191
+ self .raw_data = raw_data
192
+ self .data = self ._ClassFormat ().unpack (raw_data )
193
+ self .displayOffset = displayOffset
194
+ @property
195
+ def entered (self ):
196
+ return util .ReceiverTimeToTime (self .data [0 ])
197
+ @property
198
+ def meter (self ):
199
+ return int (self .data [1 ])
200
+ @property
201
+ def sensor (self ):
202
+ return int (self .data [2 ])
203
+ @property
204
+ def applied (self ):
205
+ return util .ReceiverTimeToTime (self .data [3 ])
206
+
121
207
class MeterRecord (GenericTimestampedRecord ):
122
208
FORMAT = '<2IHIH'
123
209
FIELDS = ['meter_glucose' , 'meter_time' ]
0 commit comments