-
Notifications
You must be signed in to change notification settings - Fork 52
/
commands.py
1819 lines (1538 loc) · 47.5 KB
/
commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import logging
import time
import lib
class BadResponse (Exception):
pass
"""
Implementation and decoding of lots of commands.
Each command inherits from :py:`BaseCommand`, which takes care of the
basic logic for informing the stick if we have recieved all the data
we expect to recieve.
Many commands are supported by Medtronic but not listed here.
Examples would include setting profiles and rates.
(One theory is that these commands are turned into setters with
correct arguments.)
"""
log = logging.getLogger( ).getChild(__name__)
def CRC8(data):
return lib.CRC8.compute(data)
class BaseCommand(object):
code = 0x00
descr = "(error)"
retries = 2
timeout = 3
params = [ ]
bytesPerRecord = 0
maxRecords = 0
effectTime = 0
responded = False
def __init__(self, code, descr, *args):
self.code = code
self.descr = descr
self.params = [ ]
def done(self):
found = len(self.data or [ ])
expect = int(self.maxRecords * self.bytesPerRecord)
expect_size = "found[{}] expected[{}]".format(found, expect)
log.info("%s:download:done?explain=%s" % (self, expect_size))
return found >= expect
def format(self):
pass
def respond(self, data):
if getattr(self, 'data', None):
self.data.extend(data)
else:
self.data = data
self.getData( )
self.responded = True
def hexdump (self):
return lib.hexdump(self.data)
class FieldChecker (object):
def __init__ (self, msg, required=[]):
self.msg = msg
self.required = required
def check_fields (self, data):
for field in self.required:
if field not in data:
raise BadResponse( )
def __call__ (self, data):
self.msg.validate(data)
self.check_fields(data)
return True
class PumpCommand(BaseCommand):
#serial = '665455'
#serial = '206525'
serial = '208850'
params = [ ]
bytesPerRecord = 64
maxRecords = 1
retries = 2
effectTime = .500
data = bytearray( )
Validator = FieldChecker
output_fields = [ ]
__fields__ = ['maxRecords', 'code', 'descr',
'serial', 'bytesPerRecord', 'retries', 'params']
def __init__(self, **kwds):
for k in self.__fields__:
value = kwds.get(k, getattr(self, k))
setattr(self, k, value)
self.allocateRawData( )
self.data = bytearray( )
self.name = self.log_name( )
self.checker = self.Validator(self, required=self.output_fields)
def log_name(self, prefix=''):
return prefix + '{}.data'.format(self.__class__.__name__)
def save(self, prefix=''):
name = '{}'.format(self.log_name(prefix))
handle = open(name, 'wb')
handle.write(self.data)
handle.close( )
def __str__(self):
if self.responded:
return '{}:size[{}]:data:{}'.format(self.__class__.__name__,
self.size, repr(self.getData( )))
return '{}:data:unknown'.format(self.__class__.__name__)
def __repr__(self):
return '<{0}>'.format( self)
def validate (self, data):
return True
def check_output (self, data):
return self.checker(data)
def getData(self):
return self.data
def allocateRawData(self):
self.size = self.bytesPerRecord * self.maxRecords
def format(self):
params = self.params
code = self.code
maxRetries = self.retries
serial = list(bytearray(self.serial.decode('hex')))
paramsCount = len(params)
head = [ 1, 0, 167, 1 ]
# serial
packet = head + serial
# paramCount 2 bytes
packet.extend( [ (0x80 | lib.HighByte(paramsCount)),
lib.LowByte(paramsCount) ] )
# not sure what this byte means
button = 0
# special case command 93
if code == 93:
button = 85
packet.append(button)
packet.append(maxRetries)
# how many packets/frames/pages/flows will this take?
responseSize = self.calcRecordsRequired()
# really only 1 or 2?
pages = responseSize
if responseSize > 1:
pages = 2
packet.append(pages)
packet.append(0)
# command code goes here
packet.append(code)
packet.append(CRC8(packet))
packet.extend(params)
packet.append(CRC8(params))
log.debug(packet)
return bytearray(packet)
def calcRecordsRequired(self):
length = self.bytesPerRecord * self.maxRecords
i = length / 64
j = length % 64
if j > 0:
return i + 1
return i
class ManualCommand(PumpCommand):
def __init__(self, **kwds):
self.name = kwds.get('name', self.__class__.__name__)
super(type(self), self).__init__(**kwds)
self.kwds = kwds
self.name = kwds.get('name', self.__class__.__name__)
def __str__(self):
if self.responded:
return '{}:{}:size[{}]:'.format(self.name, self.kwds,
self.size)
return '{}:{}:data:unknown'.format(self.name, self.kwds)
def log_name(self, prefix=''):
return prefix + '{}.data'.format(self.name)
def __repr__(self):
return '<{0}>'.format(self)
def getData(self):
return self.hexdump( )
class PowerControl(PumpCommand):
"""
>>> PowerControl(serial='665455').format() == PowerControl._test_ok
True
"""
_test_ok = bytearray( [ 0x01, 0x00, 0xA7, 0x01, 0x66, 0x54, 0x55, 0x80,
0x02, 0x55, 0x00, 0x00, 0x00, 0x5D, 0xE6, 0x01,
0x0A, 0xA2 ] )
code = 93
descr = "RF Power On"
params = [ 0x01, 0x0A ]
retries = 0
maxRecords = 0
#timeout = 1
# effectTime = 7
effectTime = 12
def __init__(self, minutes=None, **kwds):
if minutes is not None:
self.minutes = int(minutes)
kwds['params'] = [ 0x01, self.minutes ]
super(PowerControl, self).__init__(**kwds)
class PowerControlOff(PowerControl):
"""
Here's an example where arguments clearly modify behavior.
"""
params = [ 0x00, 0x00 ]
# MMPump???/ CMD_???????? 69 0x45 ('E') ??
class PumpExperiment_OP69 (PumpCommand):
code = 69
# MMPump???/ CMD_???????? 70 0x46 ('F') ??
class PumpExperiment_OP70 (PumpCommand):
code = 70
# MMPump???/ CMD_???????? 71 0x47 ('G') ??
class PumpExperiment_OP71 (PumpCommand):
code = 71
# MMPump???/ CMD_???????? 72 0x48 ('H') ??
class PumpExperiment_OP72 (PumpCommand):
code = 72
# MMPump???/ CMD_???????? 73 0x49 ('I') ??
class PumpExperiment_OP73 (PumpCommand):
code = 73
# MMPump???/ SelectBasalProfile 74 0x4a ('J') OK
class SelectBasalProfile (PumpCommand):
code = 74
class SelectBasalProfileSTD (SelectBasalProfile):
params = [ 0 ]
class SelectBasalProfileA (SelectBasalProfile):
params = [ 1 ]
class SelectBasalProfileB (SelectBasalProfile):
params = [ 2 ]
# MMPump???/ CMD_???????? 75 0x4b ('K') ??
class PumpExperiment_OP75 (PumpCommand):
code = 75
class TempBasal(PumpCommand):
"""
"""
code = 76
descr = "Set temp basal"
params = [ 0x00, 0x00, 0x00 ]
retries = 0
#maxRecords = 0
#timeout = 1
def getData(self):
status = { 0: 'absolute' }
received = True if (len(self.data) > 0 and self.data[0] is 0) else False
return dict(recieved=received, temp=status.get(self.params[0], 'percent'))
@classmethod
def Program (klass, rate=None, duration=None, temp=None, **kwds):
assert duration % 30 is 0, "duration {0} is not a whole multiple of 30".format(duration)
assert temp in [ 'percent', 'absolute' ], "temp field <{0}> should be one of {1}".format(temp, ['percent', 'absolute' ])
if temp in [ 'percent' ]:
return TempBasalPercent(params=klass.format_percent_params(rate, duration), **kwds)
return klass(params=klass.format_params(rate, duration), **kwds)
@classmethod
def format_percent_params (klass, rate, duration):
duration = int(duration / 30)
rate = int(rate)
params = [rate, duration]
return params
@classmethod
def format_params (klass, rate, duration):
duration = duration / 30
rate = int(rate / 0.025)
params = [0x00, rate, duration]
return params
class SetSuspend(PumpCommand):
code = 77
descr = "Set Pump Suspend/Resume status"
params = [ ]
retries = 2
maxRecords = 1
def getData(self):
status = { 0: 'resumed', 1: 'suspended' }
received = True if self.data[0] is 0 else False
return dict(recieved=received, status=status.get(self.params[0]))
class PumpSuspend(SetSuspend):
descr = "Suspend pump"
params = [ 1 ]
class PumpResume(SetSuspend):
descr = "Resume pump (cancel suspend)"
params = [ 0 ]
class SetAutoOff (PumpCommand):
code = 78
maxRecords = 0
class SetEnabledEasyBolus (PumpCommand):
code = 79
maxRecords = 0
class SetBasalType (PumpCommand):
code = 104
class TempBasalPercent (TempBasal):
"""
"""
code = 105
descr = "Set temp basal by percent"
params = [ 0x00, 0x00 ]
retries = 0
#maxRecords = 0
#timeout = 1
class KeypadPush(PumpCommand):
code = 91
descr = "Press buttons on the keypad"
params = [ ]
retries = 1
maxRecords = 0
@classmethod
def ACT(klass, **kwds):
return klass(params=[0x02], **kwds)
@classmethod
def ESC(klass, **kwds):
return klass(params=[0x01], **kwds)
@classmethod
def DOWN(klass, **kwds):
return klass(params=[0x04], **kwds)
@classmethod
def UP(klass, **kwds):
return klass(params=[0x03], **kwds)
@classmethod
def EASY(klass, **kwds):
return klass(params=[0x00], **kwds)
def PushACT (**kwds):
return KeypadPush.ACT(**kwds)
def PushESC (**kwds):
return KeypadPush.ESC(**kwds)
def PushDOWN (**kwds):
return KeypadPush.DOWN(**kwds)
def PushUP (**kwds):
return KeypadPush.UP(**kwds)
def PushEASY (**kwds):
return KeypadPush.EASY(**kwds)
class ReadErrorStatus508 (PumpCommand):
"""
"""
code = 38
descr = "error status"
params = [ ]
class ReadBolusHistory (PumpCommand):
"""
"""
code = 39
descr = "bolus history"
params = [ ]
class ReadDailyTotals (PumpCommand):
"""
"""
code = 40
descr = "..."
params = [ ]
class ReadPrimeBoluses (PumpCommand):
"""
"""
code = 41
descr = "..."
params = [ ]
class ReadAlarms (PumpCommand):
"""
"""
code = 42
descr = "..."
params = [ ]
class ReadProfileSets (PumpCommand):
"""
"""
code = 43
descr = "..."
params = [ ]
class ReadUserEvents (PumpCommand):
"""
"""
code = 44
descr = "..."
params = [ ]
class ReadRemoteControlID (PumpCommand):
"""
"""
code = 46
descr = "..."
params = [ ]
class Read128KMem (PumpCommand):
"""
"""
code = 55
descr = "..."
params = [ ]
class Read256KMem (PumpCommand):
"""
"""
code = 56
descr = "..."
params = [ ]
class Bolus (PumpCommand):
"""
Bolus some insulin.
XXX: Be careful please.
Best trying this not connected to the pump until you trust it.
"""
code = 66
descr = "Bolus"
params = [ ]
def getData(self):
received = True if self.data[0] is 0x0c else False
return dict(recieved=received, _type='BolusRequest')
class ReadErrorStatus(PumpCommand):
"""
>>> ReadErrorStatus(serial='665455').format() == ReadErrorStatus._test_ok
True
"""
_test_ok = bytearray([ 0x01, 0x00, 0xA7, 0x01, 0x66, 0x54, 0x55, 0x80,
0x00, 0x00, 0x02, 0x01, 0x00, 0x75, 0xD7, 0x00 ])
code = 117
descr = "Read Error Status any current alarms set?"
params = [ ]
retries = 2
maxRecords = 1
class ReadHistoryData(PumpCommand):
"""
>>> ReadHistoryData(serial='208850', params=[ 0x03 ]).format() == ReadHistoryData._test_ok
True
>>> ReadHistoryData(params=[ 0x01 ]).params
[1]
>>> ReadHistoryData(params=[ 0x02 ]).params
[2]
>>> ReadHistoryData(params=[ 0x03 ]).params
[3]
>>> ReadHistoryData(page=0x01).params
[1]
>>> ReadHistoryData(page=0x02).params
[2]
>>> ReadHistoryData(page=0x03).params
[3]
"""
__fields__ = PumpCommand.__fields__ + ['page']
_test_ok = bytearray([ 0x01, 0x00, 0xA7, 0x01, 0x20, 0x88, 0x50, 0x80, 0x01, 0x00, 0x02, 0x02, 0x00, 0x80, 0x9B, 0x03, 0x36, ])
page = None
def __init__(self, page=None, **kwds):
if page is None and kwds.get('params', [ ]):
page = kwds.pop('params')[0] or 0
if page is not None:
self.page = int(page)
kwds['params'] = [ self.page ]
super(ReadHistoryData, self).__init__(**kwds)
def log_name(self, prefix=''):
return prefix + '{}-page-{}.data'.format(self.__class__.__name__, self.page)
def __str__(self):
base = ''.join([ self.__class__.__name__,
':size[%s]:' % self.size,
'[page][%s]' % self.page ])
return '{}:data[{}]:'.format(base, len(self.data))
def done(self):
eod = False
found = len(self.data or [ ])
expect = int(self.maxRecords * self.bytesPerRecord)
expect_crc = CRC8(self.data[:-1])
expect_size = "size check found[{}] expected[{}]".format(found, expect)
found_crc = 0
if self.responded and len(self.data) > 5:
found_crc = self.data[-1]
self.eod = eod = (self.data[5] & 0x80) > 0
explain_crc = "CRC ACK check found[{}] expected[{}]".format(found_crc, expect_crc)
is_eod = 'and has eod set? %s' % (eod)
log.info("%s:download:done %s:%s:%s" % (self, expect_size, explain_crc, is_eod))
return found >= expect
def respond(self, raw):
log.info('{} extending original {} with found {}'.format(str(self), len(self.data), len(raw)))
if len(raw) == self.size:
log.info('{} download respond replace original {} with found {}'.format(str(self), len(self.data), len(raw)))
self.data = raw
elif len(self.data) == self.size:
log.info('{} download respond original {}, XXX IGNORE found {}'.format(str(self), len(self.data), len(raw)))
pass
else:
log.info('{} download respond extend original {} with found {}'.format(str(self), len(self.data), len(raw)))
self.data.extend(raw)
self.responded = True
code = 128
descr = "Read History Data"
params = [ ]
retries = 2
maxRecords = 16
effectTime = .100
data = bytearray( )
def getData(self):
data = self.data
# log.info("XXX: READ HISTORY DATA!!:\n%s" % lib.hexdump(data))
return self.hexdump( )
class ReadCurPageNumber(PumpCommand):
"""
"""
code = 157
descr = "Read Cur Page Number"
params = [ ]
retries = 2
maxRecords = 1
pages = 'unknown'
def __str__(self):
return ':pages:'.join([self.__class__.__name__, str(self.pages) ])
def respond(self, data):
self.data = data
self.pages = self.getData( )
self.responded = True
def getData(self):
data = self.data
log.info("XXX: READ cur page number:\n%s" % lib.hexdump(data))
# MM12 does not support this command, but has 31 pages
# Thanks to @amazaheri
page = 32
if len(data) == 1:
return int(data[0])
if len(data) > 3:
page = lib.BangLong(data[0:4])
# https://bitbucket.org/bewest/carelink/src/419fbf23495a/ddmsDTWApplet.src/minimed/ddms/deviceportreader/MMX15.java#cl-157
if page <= 0 or page > 36:
page = 36
return page
# MMX22/ CMD_READ_CURRENT_GLUCOSE_HISTORY_PAGE_NUMBER 205 0xcd ('\xcd') OK
class ReadCurGlucosePageNumber(PumpCommand):
"""
"""
code = 205
descr = "Read Cur Glucose Page Number"
params = [ ]
retries = 2
maxRecords = 1
def getData(self):
data = self.data
log.info("XXX: READ cur page number:\n%s" % lib.hexdump(data))
if len(data) == 1:
return int(data[0])
return dict(page= lib.BangLong(data[0:4]), glucose=data[5], isig=data[7])
class ReadRTC(PumpCommand):
"""
"""
code = 112
descr = "Read RTC"
params = [ ]
retries = 2
maxRecords = 1
def getData(self):
data = self.data
d = {
'hour' : int(data[0]),
'minute': int(data[1]),
'second': int(data[2]),
# XXX
'year' : lib.BangInt([data[3], data[4]]),
'month' : int(data[5]),
'day' : int(data[6]),
}
return "{year:#04}-{month:#02}-{day:#02}T{hour:#02}:{minute:#02}:{second:#02}".format(**d)
class SetRTC (PumpCommand):
"""
Set clock
"""
code = 64
descr = "Set RTC"
retries = 2
maxRecords = 0
__fields__ = PumpCommand.__fields__ + ['clock']
def __init__(self, clock=None, **kwds):
params = kwds.get('params', [ ])
self.clock = kwds.get('clock', None)
if len(params) == 0:
params.extend(SetRTC.fmt_datetime(clock))
kwds['params'] = params
super(SetRTC, self).__init__(**kwds)
@classmethod
def fmt_datetime (klass, dt):
return [dt.hour, dt.minute, dt.second, lib.HighByte(dt.year), lib.LowByte(dt.year), dt.month, dt.day]
class ReadPumpID(PumpCommand):
"""
"""
code = 113
descr = "Read Pump ID"
params = [ ]
retries = 2
maxRecords = 1
def getData(self):
data = self.data
return str(data[0:6])
class ReadBatteryStatus(PumpCommand):
"""
"""
code = 114
descr = "Read Battery Status"
params = [ ]
retries = 2
maxRecords = 1
def getData(self):
data = self.data
bd = bytearray(data)
volt = lib.BangInt((bd[1], bd[2]))
indicator = bd[0]
battery = {'status': {0: 'normal', 1: 'low'}[indicator], 'voltage': volt/100.0 }
return battery
class ReadFirmwareVersion(PumpCommand):
"""
"""
code = 116
descr = "Read Firmware Version"
params = [ ]
retries = 2
maxRecords = 1
def getData(self):
data = self.data
log.debug("READ FIRMWARE HEX:\n%s" % lib.hexdump(data))
return str(data.split( chr(0x0b) )[0]).strip( )
class ReadRemainingInsulin(PumpCommand):
"""
"""
code = 115
descr = "Read Remaining Insulin"
params = [ ]
retries = 2
maxRecords = 1
basalStrokes = 10.0
startByte = 0
endByte = 2
def getData(self):
data = self.data
log.info("READ remaining insulin:\n%s" % lib.hexdump(data))
return lib.BangInt(data[self.startByte:self.endByte])/self.basalStrokes
class ReadRemainingInsulin523(ReadRemainingInsulin):
"""
"""
basalStrokes = 40.0
startByte = 2
endByte = 4
class ReadBasalTemp508 (PumpCommand):
"""
"""
code = 64
descr = "Read Temp Basal 508 (old)"
params = [ ]
retries = 2
maxRecords = 1
def getData(self):
data = self.data
rate = lib.BangInt(data[2:4])/40.0
duration = lib.BangInt(data[4:6])
log.info("READ temporary basal:\n%s" % lib.hexdump(data))
return { 'rate': rate, 'duration': duration }
class ReadTodayTotals508 (PumpCommand):
"""
"""
code = 65
descr = "Read Totals Today"
params = [ ]
retries = 2
maxRecords = 1
def getData(self):
data = self.data
log.info("READ totals today:\n%s" % lib.hexdump(data))
totals = {
'today': lib.BangInt(data[0:2]) / 10.0,
'yesterday': lib.BangInt(data[2:4]) / 10.0
}
return totals
# MMPump511/ ReadTotalsToday 121 0x79 ('y') OK
class ReadTotalsToday(PumpCommand):
"""
"""
code = 121
descr = "Read Totals Today"
params = [ ]
retries = 2
maxRecords = 1
def getData(self):
data = self.data
log.info("READ totals today:\n%s" % lib.hexdump(data))
totals = {
'today': lib.BangInt(data[0:2]) / 10.0,
'yesterday': lib.BangInt(data[2:4]) / 10.0
}
return totals
# MMPump511/ ReadProfiles_STD 122 0x7a ('z') OK
class ReadProfiles511_STD (PumpCommand):
code = 122
# MMPump511/ ReadProfiles_A 123 0x7b ('{') ??
class ReadProfiles511_A (PumpCommand):
code = 123
# MMPump511/ ReadProfiles_B 124 0x7c ('|') ??
class ReadProfiles511_B (PumpCommand):
code = 124
# MMPump???/ CMD_????? 125 0x7d ('}') ??
class Model511_ExperimentOP125 (PumpCommand):
code = 125
# MMPump???/ CMD_????? 126 0x7e ('~') ??
class Model511_ExperimentOP126 (PumpCommand):
code = 126
# MMPump511/ ReadSettings 127 0x7f DEL
class ReadSettings511 (PumpCommand):
code = 127
# MMX11/ CMD_ENABLE_DISABLE_DETAIL_TRACE 160 0x9f ('\x9f') ??
class PumpTraceSelect (PumpCommand):
code = 160
class PumpEnableDetailTrace (PumpTraceSelect):
params = [ 1 ]
class PumpDisableDetailTrace (PumpTraceSelect):
params = [ 0 ]
class Experiment_OP161 (PumpCommand):
code = 161
class Experiment_OP162 (PumpCommand):
code = 162
# MMPump511/ ReadPumpTrace 163 0xa3 ('\xa3') ??
class ReadPumpTrace (PumpCommand):
code = 163
maxRecords = 16
# MMPump511/ ReadDetailTrace 164 0xa4 ('\xa4') ??
class ReadDetailTrace (PumpCommand):
code = 164
maxRecords = 16
# MMPump11??/ CMD_???????????? 165 0xa5 0xa5 ??
class Model511_Experiment_OP165 (PumpCommand):
code = 165
# MMPump511/ ReadNewTraceAlarm 166 0xa6 ('\xa6') ??
class ReadNewTraceAlarm (PumpCommand):
code = 166
maxRecords = 16
# MMPump511/ ReadOldTraceAlarm 167 0xa7 ('\xa7') ??
class ReadOldTraceAlarm (PumpCommand):
maxRecords = 16
code = 167
# MMPump???/ CMD_????? 36 0x24 ('$') ??
class PumpExperimentSelfCheck_OP36 (PumpCommand):
code = 36
# MMX22/ CMD_WRITE_GLUCOSE_HISTORY_TIMESTAMP 40 0x28 ('(') ??
class WriteGlucoseHistoryTimestamp (PumpCommand):
code = 40
class ReadRadioCtrlACL(PumpCommand):
"""
"""
code = 118
descr = "Read Radio ACL"
params = [ ]
retries = 2
maxRecords = 1
def getData(self):
data = self.data
ids = [ ]
ids.append( str(data[0:6]) )
ids.append( str(data[6:12]) )
ids.append( str(data[12:18]) )
log.info("READ radio ACL:\n%s" % lib.hexdump(data))
return ids
class Model511_Experiment_OP119 (PumpCommand):
code = 119
class Model511_Experiment_OP120 (PumpCommand):
code = 120
class Model511_Experiment_OP121 (PumpCommand):
code = 121
class Model511_Experiment_OP122 (PumpCommand):
code = 122
class Model511_Experiment_OP123 (PumpCommand):
code = 123
class Model511_Experiment_OP124 (PumpCommand):
code = 124
class Model511_Experiment_OP125 (PumpCommand):
code = 125
class Model511_Experiment_OP126 (PumpCommand):
code = 126
class Model511_Experiment_OP127 (PumpCommand):
code = 127
class Model511_Experiment_OP128 (PumpCommand):
code = 128
class Model511_Experiment_OP129 (PumpCommand):
code = 129
class Model511_Experiment_OP130 (PumpCommand):
code = 130
# MMPump512/ CMD_READ_LANGUAGE 134 0x86 ('\x86') ??
class ReadLanguage (PumpCommand):
code = 134
# MMPump512/ CMD_READ_BOLUS_WIZARD_SETUP_STATUS 135 0x87 ('\x87') ??
class ReadBolusWizardSetupStatus (PumpCommand):
code = 135
# MMPump512/ CMD_READ_CARB_UNITS 136 0x88 ('\x88') OK
class ReadCarbUnits (PumpCommand):
code = 136
def getData (self):
labels = { 1 : 'grams', 2: 'exchanges' }
return dict(carb_units=labels.get(self.data[0], self.data[0]))
# MMPump512/ CMD_READ_BG_UNITS 137 0x89 ('\x89') ??
class ReadBGUnits (PumpCommand):
code = 137
def getData (self):
labels = { 1 : 'mg/dL', 2: 'mmol/L' }
return dict(bg_units=labels.get(self.data[0], self.data[0]))
# MMPump512/ CMD_READ_CARB_RATIOS 138 0x8a ('\x8a') OK
class ReadCarbRatios512 (PumpCommand):
code = 138
output_fields = ['units', 'schedule' ]
def getData (self):
# return self.model.decode_carb_ratios(self.data[:])
units = self.data[0]
labels = { 1 : 'grams', 2: 'exchanges' }
fixed = self.data[1]
data = self.data[1:1+(8 *2)]
return dict(schedule=self.decode_ratios(data[0:], units=units), units=labels.get(units), first=self.data[0], raw=' '.join('0x{:02x}'.format(x) for x in self.data))
item_size = 2
num_items = 8
@classmethod
def decode_ratios (klass, data, units=0):
data = data[0:(8 *2)]
schedule = [ ]
for x in range(len(data)/ 2):
start = x * 2
end = start + 2
(i, r) = data[start:end]
if x > 0 and i == 0:
break
ratio = int(r)
if units == 2:
ratio = r / 10.0
schedule.append(dict(x=x, i=i, start=lib.basal_time(i), offset=i*30, ratio=ratio, r=r))
return schedule
class ReadCarbRatios (PumpCommand):
code = 138
item_size = 3
num_items = 8
output_fields = ['units', 'schedule' ]
def getData (self):
units = self.data[0]
labels = { 1 : 'grams', 2: 'exchanges' }
fixed = self.data[1]
data = self.data[2:2+(fixed *3)]
return dict(schedule=self.decode_ratios(data, units=units), units=labels.get(units), first=self.data[0])
@classmethod
def decode_ratios (klass, data, units=0):
schedule = [ ]
for x in range(len(data)/ 3):
start = x * 3
end = start + 3
(i, q, r) = data[start:end]
if x > 0 and i == 0:
break
ratio = r/10.0