Mercurial > ~darius > hgwebdir.cgi > epro
annotate epro.py @ 2:ffd0dcce19ed
Add copy of comms spec
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 20 Jul 2015 17:17:58 +0930 |
parents | 1de08e57774f |
children | 6d0fe22566ab |
rev | line source |
---|---|
0
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
2 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
3 # View facing ePro from the back |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
4 # +---+ |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
5 # +-| |-| |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
6 # | | |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
7 # | | |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
8 # +-------+ |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
9 # 1 ... 6 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
10 # |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
11 # RJ12 plug (Jaycar cable colours) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
12 # 1 white temp out |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
13 # 2 black temp in |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
14 # 3 red GND |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
15 # 4 green TX TTL (5V) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
16 # 5 yellow RX TTL (5V) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
17 # 6 blue VCC (12V) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
18 # |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
19 # 2400bps 8E1 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
20 # s = serial.Serial('/dev/cu.usbserial-AM01Z7TZ', 2400, parity='E') |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
21 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
22 class Packet(object): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
23 MSGTYPE = -1 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
24 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
25 def __init__(self, dstadr, srcadr, devid, msgtype, data): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
26 self.dstadr = dstadr |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
27 self.srcadr = srcadr |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
28 self.devid = devid |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
29 self.msgtype = msgtype |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
30 self.data = data |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
31 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
32 def __repr__(self): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
33 hdr = "Src: 0x%02x Dst: 0x%02x DevID: 0x%02x MsgType: 0x%02x" % ( |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
34 self.dstadr, self.srcadr, self.devid, self.msgtype) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
35 # MSGTYPE is overridden for subclasses which also have their own repr so don't dumb data here |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
36 if self.MSGTYPE == -1: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
37 hdr += " Data:" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
38 for d in self.data: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
39 hdr += " 0x%02x" % (d) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
40 else: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
41 hdr += " Name: " + self.MSGNAME |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
42 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
43 return hdr |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
44 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
45 class MainVoltage(Packet): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
46 """Main Battery Voltage""" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
47 MSGTYPE = 0x60 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
48 MSGNAME = "Main Voltage" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
49 LEN = 3 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
50 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
51 def __init__(self, dstadr, srcadr, devid, msgtype, data): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
52 super(MainVoltage, self).__init__(dstadr, srcadr, devid, msgtype, data) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
53 self.volts = (data[2] & 0x7f | (data[1] & 0x7f) << 7 | (data[0] & 0x03) << 14) / 100.0 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
54 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
55 def __repr__(self): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
56 s = super(MainVoltage, self).__repr__() |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
57 s += ": %.2f V" % (self.volts) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
58 return s |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
59 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
60 class BatteryCurrent(Packet): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
61 """Main Battery Current""" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
62 MSGTYPE = 0x61 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
63 MSGNAME = "Battery Current" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
64 LEN = 3 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
65 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
66 def __init__(self, dstadr, srcadr, devid, msgtype, data): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
67 super(BatteryCurrent, self).__init__(dstadr, srcadr, devid, msgtype, data) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
68 self.amps = (data[2] & 0x7f | (data[1] & 0x7f) << 7 | (data[0] & 0x3f) << 14) / 100.0 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
69 if data[2] & 0x40: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
70 self.amps *= -1 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
71 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
72 def __repr__(self): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
73 s = super(BatteryCurrent, self).__repr__() |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
74 s += ": %.2f A" % (self.amps) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
75 return s |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
76 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
77 class AmpHours(Packet): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
78 """Number of amp hours removed from the battery""" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
79 MSGTYPE = 0x62 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
80 MSGNAME = "Amp Hours" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
81 LEN = 3 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
82 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
83 def __init__(self, dstadr, srcadr, devid, msgtype, data): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
84 super(AmpHours, self).__init__(dstadr, srcadr, devid, msgtype, data) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
85 self.amphrs = (data[2] & 0x7f | (data[1] & 0x7f) << 7 | (data[0] & 0x3f) << 14) / 100.0 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
86 if data[2] & 0x40: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
87 self.amphrs *= -1 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
88 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
89 def __repr__(self): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
90 s = super(AmpHours, self).__repr__() |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
91 s += ": %.2f Ah" % (self.amphrs) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
92 return s |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
93 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
94 class StateOfCharge(Packet): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
95 """State of battery charge""" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
96 MSGTYPE = 0x64 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
97 MSGNAME = "State Of Charge" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
98 LEN = 3 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
99 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
100 def __init__(self, dstadr, srcadr, devid, msgtype, data): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
101 super(StateOfCharge, self).__init__(dstadr, srcadr, devid, msgtype, data) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
102 self.soc = (data[2] & 0x7f | (data[1] & 0x7f) << 7 | (data[0] & 0x03) << 14) / 10.0 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
103 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
104 def __repr__(self): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
105 s = super(StateOfCharge, self).__repr__() |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
106 s += ": %.2f%%" % (self.soc) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
107 return s |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
108 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
109 class TimeRemaining(Packet): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
110 """Time remaining until battery needs charging""" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
111 MSGTYPE = 0x65 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
112 MSGNAME = "Time remaining" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
113 LEN = 3 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
114 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
115 def __init__(self, dstadr, srcadr, devid, msgtype, data): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
116 super(TimeRemaining, self).__init__(dstadr, srcadr, devid, msgtype, data) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
117 self.time = (data[2] & 0x7f | (data[1] & 0x7f) << 7 | (data[0] & 0x3f) << 14) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
118 if data[2] & 0x40: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
119 self.time *= -1 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
120 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
121 def __repr__(self): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
122 s = super(TimeRemaining, self).__repr__() |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
123 s += ": %.2f min" % (self.time) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
124 return s |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
125 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
126 class BatteryTemperature(Packet): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
127 """Battery temperature (degrees Celcius)""" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
128 MSGTYPE = 0x66 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
129 MSGNAME = "Battery Temperature" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
130 LEN = 3 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
131 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
132 def __init__(self, dstadr, srcadr, devid, msgtype, data): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
133 super(BatteryTemperature, self).__init__(dstadr, srcadr, devid, msgtype, data) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
134 self.time = (data[2] & 0x7f | (data[1] & 0x7f) << 7 | (data[0] & 0x3f) << 14) / 10.0 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
135 if data[2] & 0x40: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
136 self.time *= -1 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
137 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
138 def __repr__(self): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
139 s = super(BatteryTemperature, self).__repr__() |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
140 s += ": %.2f degC" % (self.time) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
141 return s |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
142 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
143 class MonitorStatus(Packet): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
144 """Monitor status""" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
145 MSGTYPE = 0x67 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
146 MSGNAME = "Monitor Status" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
147 LEN = 3 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
148 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
149 def __init__(self, dstadr, srcadr, devid, msgtype, data): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
150 super(MonitorStatus, self).__init__(dstadr, srcadr, devid, msgtype, data) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
151 self.autosyncvolt = data[0] & 0x10 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
152 self.autosyncamp = data[0] & 0x08 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
153 self.autosyncchrg = data[0] & 0x04 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
154 self.e501compat = data[0] & 0x02 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
155 self.alarmtst = data[0] & 0x01 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
156 self.backlight = data[1] & 0x40 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
157 self.disptst = data[1] & 0x20 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
158 self.tempsense = data[1] & 0x10 # Seems to be inverted from data sheet |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
159 self.auxhv = data[1] & 0x08 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
160 self.auxlv = data[1] & 0x04 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
161 self.lock = data[1] & 0x02 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
162 self.mainhv = data[1] & 0x01 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
163 self.mainlv = data[2] & 0x40 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
164 self.lowbatalarm = data[2] & 0x20 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
165 self.batflat = data[2] & 0x10 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
166 self.batfull = data[2] & 0x08 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
167 self.charged = data[2] & 0x04 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
168 self.nosync = data[2] & 0x02 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
169 self.monreset = data[2] & 0x01 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
170 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
171 def __repr__(self): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
172 s = super(MonitorStatus, self).__repr__() |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
173 stats = ( ( "ASV", self.autosyncvolt ), ( "ASA", self.autosyncamp ), ( "ASC" , self.autosyncchrg ), |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
174 ( "E501", self.e501compat ), ( "Alarm test", self.alarmtst ), ( "Light", self.backlight ), |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
175 ( "Temperature Sensor", self.tempsense ), ( "Aux HV", self.auxhv ), ( "Aux LV", self.auxlv ), |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
176 ( "Lock", self.lock ), ( "Main HV", self.mainhv ), ( "Main LV", self.mainlv ), |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
177 ( "Low Battery", self.lowbatalarm ), ( "Battery Flat", self.batfull ), |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
178 ( "Battery Full", self.batfull ), ( "Battery Charged", self.charged ), |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
179 ( "No Sync", self.nosync ), ( "Monitor Reset", self.monreset ) ) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
180 for (short, var) in stats: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
181 if var: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
182 s += " %s : True" % (short) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
183 else: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
184 s += " %s : False" % (short) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
185 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
186 return s |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
187 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
188 class AuxVoltage(Packet): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
189 """Aux Battery Voltage""" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
190 MSGTYPE = 0x68 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
191 MSGNAME = "Aux Voltage" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
192 LEN = 3 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
193 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
194 def __init__(self, dstadr, srcadr, devid, msgtype, data): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
195 super(AuxVoltage, self).__init__(dstadr, srcadr, devid, msgtype, data) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
196 self.volts = (data[2] & 0x7f | (data[1] & 0x7f) << 7 | (data[0] & 0x03) << 14) / 100.0 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
197 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
198 def __repr__(self): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
199 s = super(AuxVoltage, self).__repr__() |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
200 s += ": %.2f V" % (self.volts) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
201 return s |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
202 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
203 class Processor(object): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
204 PKT_TYPES = { MainVoltage.MSGTYPE : MainVoltage, BatteryCurrent.MSGTYPE : BatteryCurrent, |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
205 AmpHours.MSGTYPE : AmpHours, StateOfCharge.MSGTYPE : StateOfCharge, |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
206 TimeRemaining.MSGTYPE : TimeRemaining, BatteryTemperature.MSGTYPE : BatteryTemperature, |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
207 MonitorStatus.MSGTYPE : MonitorStatus, AuxVoltage.MSGTYPE : AuxVoltage } |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
208 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
209 def __init__(self): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
210 self.state = 0 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
211 self.packets = [] |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
212 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
213 def process(self, dat): |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
214 for d in dat: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
215 d = ord(d) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
216 if d == 0xff and self.state != 4: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
217 print "Packet corruption" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
218 continue |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
219 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
220 if self.state == 0: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
221 # Waiting for destination address (MSB set but not 0xff as that is EOM) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
222 if d == 0xff or d & 0x80 == 0: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
223 print "Skipping byte" |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
224 continue |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
225 self.dstadr = d & 0x7f |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
226 self.data = [] |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
227 self.state += 1 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
228 elif self.state == 1: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
229 # Source address |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
230 self.srcadr = d |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
231 self.state += 1 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
232 elif self.state == 2: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
233 # Device ID |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
234 self.devid = d |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
235 self.state += 1 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
236 elif self.state == 3: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
237 # Message type |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
238 self.msgtype = d |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
239 self.state += 1 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
240 elif self.state == 4: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
241 # Data |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
242 if d != 0xff: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
243 self.data.append(d) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
244 continue |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
245 self.state = 0 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
246 if self.msgtype in Processor.PKT_TYPES: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
247 t = self.PKT_TYPES[self.msgtype] |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
248 if len(self.data) != t.LEN: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
249 print "Packet length incorrect, expected %d got %d" % (t.LEN, len(self.data)) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
250 continue |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
251 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
252 p = self.PKT_TYPES[self.msgtype](self.dstadr, self.srcadr, self.devid, self.msgtype, self.data) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
253 else: |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
254 p = Packet(self.dstadr, self.srcadr, self.devid, self.msgtype, self.data) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
255 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
256 print p |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
257 self.packets.append(p) |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
258 |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
259 if __name__ == '__main__': |
1de08e57774f
Initial comit of code to talk to EnerDrive ePro battery monitor
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
260 main() |