-
Notifications
You must be signed in to change notification settings - Fork 12
/
cl2.py
executable file
·894 lines (741 loc) · 20.7 KB
/
cl2.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
#!/usr/bin/python
import user
#import struct
import sys
import serial
import time
import logging
from pprint import pprint, pformat
#from insulaudit.core import Command
from insulaudit.clmm.usbstick import *
from insulaudit import lib
logging.basicConfig( stream=sys.stdout )
log = logging.getLogger( 'auditor' )
log.setLevel( logging.DEBUG )
log.info( 'hello world' )
io = logging.getLogger( 'auditor.io' )
io.setLevel( logging.DEBUG )
"""
######################
#
# ComLink2
# pseudocode analysis of critical procedures
# there is some implicit OO going on
#
execute(command):
usbcommand.execute(self)
############################
#
# USB(Pump) Command Stuff
#
packSerialNumber:
return makePackedBCD(serial)
"""
"""
######################
#
# Pump
#
# every command needs:
# code, retries, params, length, pages
initDevice:
# cmdPowerControl Command(93, "rf power on", 2)
# cmdPowerControl.params = [ 1, 1 ]
# cmdPowerControl.retries = 0
# cmdReadErrorStatus = Command(117, "read pump error status")
# cmdReadState = Command(131, "Read Pump State")
# cmdReadTempBasal = Command(152, "Read Temporary Basal")
initDevice2
iniDevice2:
detectActiveBolus = Command(76, "set temp basal rate (bolus detection only)", 3)
detectActiveBolus.params = [ 0, 0, 0 ]
detectActiveBolus.retries = 0
detectActiveBolus:
# cmdDetectBolus
shutDownPump
if suspended:
shutDownPump2()
cmdCancelSuspend()
# turn rf power off
# retries 0
cmdOff = Command(93, "rf power off", [ 0 ], 2)
cmdOff.execute
shutDownPump2:
Command(91, "keypad push (ack)", [ 2 ], 1).execute
time.sleep(.500)
Command(91, "keypad push (esc)", [ 1 ], 1).execute
time.sleep(.500)
getNAKDescription:
# pass
# 2 params
Command(code, descr)
# 5: code, descr, bytesPerRecord, maxRecords, maxRetries
return Command(code, descr, 64, 1, 0)
# 3 params
Command(code, descr, paramCount):
# 5
#
com = Command(code, descr, 0, 1, 11)
com.paramCount = paramCount
numblocks = paramCount / 64 + 1
# 4 params
Command(code, descr, params, tail)
# 5
com = Command(code, descr, 0, 1, 11)
com.params = params
#com.paramCount
# 5 params
Command(code, descr, bytesPerRecord, maxRecords, ??):
# likely decompile error
# 7
Command(code, descr, bytesPerRecord, maxRecords, 0, 0, paramCount)
dataOffset = 0
cmdLength = 2
# 7 params
Command(code, descr, bytesPerRecord, maxRecords, address, addressLength, arg8):
offset = 2
if addressLength == 1:
cmdLength = 2 + addressLength
else:
cmdLength = 2 + addressLength + 1
retries = 2
# 511
execute:
result = None
for i in xrange(maxRetries)
# reset bytes read
response = usb.execute(self)
# handle stack trace
if response: break
return result
"""
"""
"""
class Link( core.CommBuffer ):
class ID:
VENDOR = 0x0a21
PRODUCT = 0x8001
timeout = .100
def __init__( self, port, timeout=None ):
super(type(self), self).__init__(port, timeout)
def setTimeout(self, timeout):
self.serial.setTimeout(timeout)
def getTimeout(self):
return self.serial.getTimeout()
def initUSBComms(self):
self.initCommunicationsIO()
#self.initDevice()
def getSignalStrength(self):
result = self.readSignalStrength()
signal = result[0]
def readSignalStrength(self):
result = self.sendComLink2Command(6, 0)
# result[0] is signal strength
log.info('%r:readSignalStrength:%s' % (self, int(result[0])))
return result
def initCommunicationsIO(self):
# close/open serial
self.readProductInfo( )
sig = 0
while sig < 50:
sig = self.readSignalStrength()
def endCommunicationsIO(self):
self.readSignalStrength()
self.readInterfaceStatistics()
# close port
self.close()
def readProductInfo(self):
result = self.sendComLink2Command(4)
# 1/0/255
log.info('readProductInfo:result')
freq = result[5]
info = self.decodeProductInfo(result)
log.info('product info: %s' % pformat(info))
# decodeInterface stats
def decodeProductInfo(self, data):
class F:
body = data
comm = USBProductInfo()
comm.reply = F()
comm.onACK()
return comm.info
def sendComLink2Command(self, msg, a2=0x00, a3=0x00):
# generally commands are 3 bytes, most often CMD, 0x00, 0x00
msg = bytearray([ msg, a2, a3 ])
io.info('sendComLink2Command:write')
self.write(msg)
return self.checkAck()
# throw local usb exception
def checkAck(self):
time.sleep(.050)
result = bytearray(self.read(64))
io.info('checkAck:read')
commStatus = result[0]
# usable response
assert commStatus == 1
status = result[1]
# status == 102 'f' NAK, look up NAK
if status == 85: # 'U'
log.info('ACK OK')
return result[3:]
assert False, "NAK!!"
def decodeIFaceStats(self, data):
class F:
body = data
comm = InterfaceStats()
comm.reply = F()
comm.onACK()
return comm.info
def readInterfaceStatistics(self):
# decode and log stats
result = self.sendComLink2Command(5, 0)
info = self.decodeIFaceStats(result)
log.info("read radio Interface Stats: %s" % pformat(info))
result = self.sendComLink2Command(5, 1)
info = self.decodeIFaceStats(result)
log.info("read stick Interface Stats: %s" % pformat(info))
#######################
#
#
#
def CRC8(data):
return lib.CRC8.compute(data)
################################
# Remote Stuff
#
class BaseCommand(object):
code = 0x00
descr = "(error)"
retries = 2
timeout = 3
params = [ ]
bytesPerRecord = 0
maxRecords = 0
effectTime = 1
def __init__(self, code, descr, *args):
self.code = code
self.descr = descr
self.params = [ ]
def format(self):
pass
def allocateRawData(self):
self.raw = self.bytesPerRecord * self.maxRecords
class Device(object):
def __init__(self, link):
self.link = link
def execute(self, command):
self.command = command
self.allocateRawData()
self.sendAndRead()
def sendAndRead(self):
self.sendDeviceCommand()
time.sleep(self.command.effectTime)
if self.expectedLength > 0:
# in original code, this modifies the length tested in the previous if
# statement
self.command.data = self.readDeviceData()
def sendDeviceCommand(self):
packet = self.buildTransmitPacket()
io.info('sendDeviceCommand:write:%r' % (self.command))
self.link.write(packet)
time.sleep(.010)
code = self.command.code
params = self.command.params
if code != 93 or params[0] != 0:
self.link.checkAck()
def allocateRawData(self):
self.command.allocateRawData()
self.expectedLength = self.command.bytesPerRecord * self.command.maxRecords
def readDeviceData(self):
self.eod = False
results = bytearray( )
while not self.eod:
data = self.readDeviceDataIO( )
results.extend(data)
return results
def readDeviceDataIO(self):
results = self.readData()
lb, hb = results[5] & 0x7F, results[6]
self.eod = (results[5] & 0x80) > 0
resLength = lib.BangInt((lb, hb))
log.info('XXX resLength: %s' % resLength)
#assert resLength < 64, ("cmd low byte count:\n%s" % lib.hexdump(results))
data = results[13:13+resLength]
assert len(data) == resLength
crc = results[-1]
# crc check
log.info('readDeviceDataIO:msgCRC:%r:expectedCRC:%r:data:%r' % (crc, CRC8(data), data))
assert crc == CRC8(data)
return data
def readData(self):
bytesAvailable = self.getNumBytesAvailable()
packet = [12, 0, lib.HighByte(bytesAvailable), lib.LowByte(bytesAvailable)]
packet.append( CRC8(packet) )
response = self.writeAndRead(packet, bytesAvailable)
# assert response.length > 14
assert (int(response[0]) == 2), repr(response)
# response[1] != 0 # interface number !=0
# response[2] == 5 # timeout occurred
# response[2] == 2 # NAK
# response[2] # should be within 0..4
log.info("readData ACK")
return response
def writeAndRead(self, msg, length):
io.info("writeAndRead:")
self.link.write(bytearray(msg))
time.sleep(.300)
self.link.setTimeout(self.command.timeout)
return bytearray(self.link.read(length))
def getNumBytesAvailable(self):
result = self.readStatus( )
start = time.time()
i = 0
while result == 0 and time.time() - start < 1:
log.debug('%r:getNumBytesAvailable:attempt:%s' % (self, i))
result = self.readStatus( )
time.sleep(.10)
i += 1
log.info('getNumBytesAvailable:%s' % result)
return result
def readStatus(self):
result = self.link.sendComLink2Command(3)
commStatus = result[0] # 0 indicates success
assert commStatus == 0
status = result[2]
lb, hb = result[3], result[4]
bytesAvailable = lib.BangInt((lb, hb))
self.status = status
if (status & 0x1) > 0:
return bytesAvailable
return 0
def buildTransmitPacket(self):
return self.command.format( )
class PumpCommand(BaseCommand):
#serial = '665455'
#serial = '206525'
serial = '208850'
params = [ ]
bytesPerRecord = 64
maxRecords = 1
retries = 2
__fields__ = ['maxRecords', 'code', 'descr',
'serial', 'bytesPerRecord', 'params']
def __init__(self, **kwds):
for k in self.__fields__:
value = kwds.get(k, getattr(self, k))
setattr(self, k, value)
def getData(self):
return self.data
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))
io.info(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 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 = 17
effectTime = 17
class PowerControlOff(PowerControl):
params = [ 0x00, 0x0A ]
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').format() == ReadHistoryData._test_ok
True
"""
_test_ok = bytearray([ 0x01, 0x00, 0xA7, 0x01, 0x20, 0x88, 0x50, 0x80,
0x01, 0x00, 0x02, 0x02, 0x00, 0x80, 0x9B, 0x03,
0x36, ])
code = 128
descr = "Read History Data"
params = [ 0x00 ]
retries = 2
maxRecords = 2
effectTime = .100
def getData(self):
data = self.data
log.info("XXX: READ HISTORY DATA!!:\n%s" % lib.hexdump(data))
return data
class ReadCurPageNumber(PumpCommand):
"""
"""
code = 157
descr = "Read Cur 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))
return lib.BangLong(data[0:4])
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' : 2000 + (data[4] & 0x0F),
'month' : int(data[5]),
'day' : int(data[6]),
}
return "%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s:%(second)s" % (d)
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
def getData(self):
data = self.data
log.info("READ remaining insulin:\n%s" % lib.hexdump(data))
return lib.BangInt(data[0:2])/10.0
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
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 ReadBasalTemp(PumpCommand):
"""
MM511 - 120
MM512 and up - opcode 152
# strokes per basalunit = 40 - mm12, 10 in mm11
"""
code = 152
descr = "Read Temp Basal"
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 ReadContrast(PumpCommand):
"""
"""
code = 195
descr = "Read Contrast"
params = [ ]
retries = 2
maxRecords = 1
def getData(self):
data = self.data
log.info("READ contrast:\n%s" % lib.hexdump(data))
return data
class ReadSettings(PumpCommand):
"""
XXX: changed in MM512 to 192
"""
code = 192
descr = "Read Settings"
params = [ ]
retries = 2
maxRecords = 1
def alarm(self, alarm):
d = { 'volume': alarm, 'mode': 2 }
if alarm == 4:
d = { 'volume': -1, 'mode': 1 }
return d
def getData(self):
data = self.data
log.info("READ pump settings:\n%s" % lib.hexdump(data))
auto_off_duration_hrs = data[0]
alarm = self.alarm(data[1])
audio_bolus_enable = data[2] == 1
audio_bolus_size = 0
if audio_bolus_enable:
audio_bolus_size = data[3] / 10.0
variable_bolus_enable = data[4] == 1
#MM23 is different
maxBolus = data[5]/ 10.0
# MM512 and up
maxBasal = lib.BangInt(data[6:8]) / 40
timeformat = data[8]
insulinConcentration = {0: 100, 1: 50}[data[9]]
patterns_enabled = data[10] == 1
selected_pattern = data[11]
rf_enable = data[12] == 1
block_enable = data[13] == 1
"""
# MM12
insulin_action_type = data[17] == 0 and 'Fast' or 'Regular'
"""
#MM15
insulin_action_type = data[17]
low_reservoir_warn_type = data[18]
low_reservoir_warn_point = data[19]
keypad_lock_status = data[20]
return locals( )
class ReadPumpState(PumpCommand):
"""
>>> ReadPumpState(serial='665455').format() == ReadPumpState._test_ok
True
"""
_test_ok = bytearray([ 0x01, 0x00, 0xA7, 0x01, 0x66, 0x54, 0x55, 0x80,
0x00, 0x00, 0x02, 0x01, 0x00, 0x83, 0x2E, 0x00 ])
code = 131
descr = "Read Pump State"
params = [ ]
retries = 2
maxRecords = 1
class ReadGlucoseHistory(PumpCommand):
"""
"""
descr = "Read glucose history"
code = 131
params = [ ]
retries = 2
class ReadPumpModel(PumpCommand):
"""
>>> ReadPumpModel(serial='665455').format() == ReadPumpModel._test_ok
True
"""
code = 141
descr = "Read Pump Model Number"
params = [ ]
retries = 2
maxRecords = 1
_test_ok = bytearray([ 0x01, 0x00, 0xA7, 0x01, 0x66, 0x54, 0x55, 0x80,
0x00, 0x00, 0x02, 0x01, 0x00, 0x8D, 0x5B, 0x00 ])
def getData(self):
data = self.data
length = data[0]
msg = data[1:1+length]
self.model = msg
return str(msg)
def initDevice(link):
device = Device(link)
#comm = PowerControl()
#device.execute(comm)
#log.info('comm:%s:data:%s' % (comm, getattr(comm, 'data', None)))
comm = ReadErrorStatus()
device.execute(comm)
log.info('comm:%s:data:%s' % (comm, getattr(comm, 'data', None)))
comm = ReadPumpState()
device.execute(comm)
log.info('comm:%s:data:%s' % (comm, getattr(comm, 'data', None)))
return device
def do_commands(device):
comm = ReadPumpModel( )
device.execute(comm)
log.info('comm:%s:data:%s' % (comm, getattr(comm.getData( ), 'data', None)))
log.info('REMOTE PUMP MODEL NUMBER: %s' % comm.getData( ))
log.info("READ RTC")
comm = ReadRTC( )
device.execute(comm)
log.info('comm:RTC:%s' % (comm.getData( )))
log.info("READ PUMP ID")
comm = ReadPumpID( )
device.execute(comm)
log.info('comm:READ PUMP ID: ID: %s' % (comm.getData( )))
log.info("Battery Status")
comm = ReadBatteryStatus( )
device.execute(comm)
log.info('comm:READ Battery Status: %r' % (comm.getData( )))
log.info("Firmware Version")
comm = ReadFirmwareVersion( )
device.execute(comm)
log.info('comm:READ Firmware Version: %r' % (comm.getData( )))
log.info("remaining insulin")
comm = ReadRemainingInsulin( )
device.execute(comm)
log.info('comm:READ Remaining Insulin: %r' % (comm.getData( )))
log.info("read totals today")
comm = ReadTotalsToday( )
device.execute(comm)
log.info('comm:READ totals today: %r' % (comm.getData( )))
log.info("read remote IDS")
comm = ReadRadioCtrlACL( )
device.execute(comm)
log.info('comm:READ radio ACL: %r' % (comm.getData( )))
log.info("read temporary basal")
comm = ReadBasalTemp( )
device.execute(comm)
log.info('comm:READ temp basal: %r' % (comm.getData( )))
log.info("read settings")
comm = ReadSettings( )
device.execute(comm)
log.info('comm:READ settings!: %r' % (comm.getData( )))
log.info("read contrast")
comm = ReadContrast( )
device.execute(comm)
log.info('comm:READ contrast: %r' % (comm.getData( )))
log.info("read cur page number")
comm = ReadCurPageNumber( )
device.execute(comm)
log.info('comm:READ page number!!!: %r' % (comm.getData( )))
log.info("read HISTORY DATA")
comm = ReadHistoryData( )
device.execute(comm)
#log.info('comm:READ history data!!!: %r' % (comm.getData( )))
def get_pages(device):
log.info("read cur page number")
comm = ReadCurPageNumber( )
device.execute(comm)
pages = comm.getData( )
log.info('attempting to read %s pages of history' % pages)
for x in range(pages + 1):
log.info('comm:READ HISTORY DATA page number: %r' % (x))
comm = ReadHistoryData( params=[ x ] )
device.execute(comm)
comm.getData( )
#log.info('comm:READ history data!!!: %r' % (comm.getData( )))
def shutdownDevice(device):
comm = PowerControlOff()
device.execute(comm)
log.info('comm:%s:data:%s' % (comm, getattr(comm, 'data', None)))
if __name__ == '__main__':
io.info("hello world")
import doctest
doctest.testmod( )
port = None
try:
port = sys.argv[1]
except IndexError, e:
print "usage:\n%s /dev/ttyUSB0" % sys.argv[0]
sys.exit(1)
link = Link(port)
link.initUSBComms()
device = initDevice(link)
#do_commands(device)
get_pages(device)
#shutdownDevice(device)
link.endCommunicationsIO()
#pprint( carelink( USBProductInfo( ) ).info )
#####
# EOF