Mercurial > ~darius > hgwebdir.cgi > giant
annotate giant.py @ 0:1f3c12ba927d default tip
Rework code for USB interface
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Sun, 19 Nov 2017 18:10:23 +1030 |
parents | |
children |
rev | line source |
---|---|
0
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
2 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
3 # pip install --user pyusb pycrc |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
4 import crc16 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
5 import exceptions |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
6 import os |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
7 import usb.core, usb.util, usb.control # https://github.com/pyusb/pyusb |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
8 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
9 # USB details |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
10 # Borrowed from http://allican.be/blog/2017/01/28/reverse-engineering-cypress-serial-usb.html |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
11 vendorId = 0x0665 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
12 productId = 0x5161 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
13 interface = 0 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
14 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
15 # Have to add one to these CRCs values before sending |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
16 badvals = [0x28, 0x0d, 0x0a] |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
17 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
18 class Timeout(exceptions.BaseException): |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
19 pass |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
20 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
21 class FramingError(exceptions.BaseException): |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
22 pass |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
23 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
24 class CRCError(exceptions.BaseException): |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
25 pass |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
26 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
27 class GiantIPS(object): |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
28 PIWS = ['Reserved', 'InverterFault', 'BusOver', 'BusUnder', 'BusSoftFail', 'LineFail', 'OPVShort', 'InverterVoltsLow', |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
29 'InverterVoltsHigh', 'OverTemp', 'FanLocked', 'BattVoltsHigh', 'BattLowAlarm', 'Reserved(Overcharge)', |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
30 'BatterySHutdown', 'Reserved(BattDerate)', 'Overload', 'EEPROM', 'InverterOverCurrent', 'SelfTest', |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
31 'OPDCVoltsOver', 'BattOpen', 'CurrentSenseFail', 'BatteryShort', 'PowerLimit', 'PVVoltsHigh1', |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
32 'MPPTOverload', 'MPPTOverloadWarn', 'BattTooLowChrg', 'PVVoltsHigh2', 'MPPTOverload2', 'MPPTOverloadWarn2', |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
33 'BattTooLowChrg2', 'PVVoltsHigh3', 'MPPTOverload3', 'MPPTOverloadWarn3', 'BattTooLowChrg3'] |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
34 def __init__(self): |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
35 dev = usb.core.find(idVendor = vendorId, idProduct = productId) |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
36 if dev.is_kernel_driver_active(interface): |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
37 dev.detach_kernel_driver(interface) |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
38 dev.set_interface_altsetting(0, 0) |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
39 self.dev = dev |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
40 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
41 def compose_msg(self, data): |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
42 crc = crc16.crc16xmodem(data) |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
43 crclow = crc & 0xff |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
44 crchigh = crc >> 8 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
45 if crclow in badvals: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
46 crclow += 1 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
47 if crchigh in badvals: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
48 crchigh += 1 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
49 data = data + chr(crchigh) + chr(crclow) + chr(0x0d) |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
50 while len(data) < 8: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
51 data = data + b'\0' |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
52 return data |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
53 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
54 def tx_msg(self, data): |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
55 self.dev.ctrl_transfer(0x21, 0x9, 0x200, 0, self.compose_msg(data)) |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
56 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
57 def rx_msg(self): |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
58 res = '' |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
59 tries = 200 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
60 while tries > 0 and '\r' not in res: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
61 try: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
62 d = self.dev.read(0x81, 8, 10) |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
63 res += ''.join([chr(i) for i in d if i != 0x00]) |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
64 except usb.core.USBError as e: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
65 if e.errno == 110: # timeout |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
66 tries -= 1 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
67 pass |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
68 else: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
69 raise |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
70 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
71 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
72 if tries == 0: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
73 raise Timeout() |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
74 if res[0] != '(' or res[-1] != '\r': |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
75 raise FramingError() |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
76 crc = crc16.crc16xmodem(res[0:-3]) |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
77 crclow = crc & 0xff |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
78 crchigh = crc >> 8 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
79 if ord(res[-3]) != crchigh or ord(res[-2]) != crclow: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
80 #raise CRCError() |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
81 print('CRC error') |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
82 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
83 return res[1:-3] |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
84 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
85 def cmd(self, cmd): |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
86 self.tx_msg(cmd) |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
87 return self.rx_msg() |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
88 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
89 def getStatus(self): |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
90 d = self.cmd('QPIGS').split() |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
91 status = {} |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
92 if d[16][0] == '1': |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
93 status['SBUPrio'] = True |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
94 else: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
95 status['SBUPrio'] = False |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
96 if d[16][1] == '1': |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
97 status['ConfigChg'] = True |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
98 else: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
99 status['ConfigChg'] = False |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
100 if d[16][2] == '1': |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
101 status['BattVoltSteady'] = True |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
102 else: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
103 status['BattVoltSteady'] = False |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
104 if d[16][3] == '1': |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
105 status['Charging'] = True |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
106 else: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
107 status['Charging'] = False |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
108 if d[16][4] == '1': |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
109 status['SCC1Charging'] = True |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
110 else: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
111 status['SCC1Charging'] = False |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
112 if d[16][5:] == '110': |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
113 status['ChargeType'] = 'SCC1' |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
114 elif d[16][5:] == '101': |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
115 status['ChargeType'] = 'AC' |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
116 else: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
117 status['ChargeType'] = 'Both' |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
118 if d[20][0] == '1': |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
119 status['FloatCharge'] = True |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
120 else: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
121 status['FloatCharge'] = False |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
122 if d[20][1] == '1': |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
123 status['Switch'] = True |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
124 else: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
125 status['Switch'] = False |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
126 return { |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
127 'GridVolts' : float(d[0]), |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
128 'GridFreq' : float(d[1]), |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
129 'ACVolts' : float(d[2]), |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
130 'ACFreq' : float(d[3]), |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
131 'ACAppPower' : float(d[4]), |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
132 'ACActPower' : float(d[5]), |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
133 'LoadPct' : float(d[6]), |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
134 'BusVolts' : float(d[7]), |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
135 'BattVolts' : float(d[8]), |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
136 'BattChrCurr' : float(d[9]), |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
137 'BattCap' : float(d[10]), |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
138 'HSTemp' : float(d[11]), |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
139 'PVCurr1' : float(d[12]), |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
140 'PVVolt1' : float(d[13]), |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
141 'SCC1Volt' : float(d[14]), |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
142 'BattDisCurr' : float(d[15]), |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
143 'Status' : status, |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
144 'BattVoltOfs' : float(d[17]) / 0.01, # 10mV |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
145 'PVChrgPow1' : float(d[19]), |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
146 } |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
147 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
148 def getAlarms(self): |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
149 d = self.cmd('QPIWS') |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
150 res = {} |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
151 for i in range(min(len(d), len(self.PIWS))): |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
152 if d[i] == '1': |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
153 res[self.PIWS[i]] = True |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
154 else: |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
155 res[self.PIWS[i]] = False |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
156 return res |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
157 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
158 def main(): |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
159 ips = GiantIPS() |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
160 print(ips.cmd('QPI')) |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
161 |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
162 if __name__ == '__main__': |
1f3c12ba927d
Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
163 main() |