Skip to content

Commit

Permalink
- Fix bugs in bmsmonitor
Browse files Browse the repository at this point in the history
- Add note README to CAN interface setup
- Add test scenario testing no load state with power on, off
  • Loading branch information
jonans committed Oct 1, 2020
1 parent eacab67 commit 0dae665
Show file tree
Hide file tree
Showing 4 changed files with 311 additions and 18 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ pipenv install
pipenv shell
```

Setup your can interface:

```
ip link set can0 type can bitrate 100000
ip link set can0 txqueuelen 1000 up
```

## What can you do ?

- Analyze the test scenarios and see what you can decode.
Expand All @@ -105,3 +112,10 @@ We can dump all the data and compare the differences under various testing condi
1. [cold-3.csv](tests/cold-3.csv) - 45 min after, room temp 23c
1. [cold-4.csv](tests/cold-4.csv) - 60 min after, room temp 23c

### Testing no load state with power off / on

- Dump BMS at idle with power on then off

1. [idle-power-off.csv](test/idle-power-off.csv) - Power off
1. [idle-power-on.csv](test/idle-power-on.csv) - Power on

136 changes: 136 additions & 0 deletions tests/idle-power-off.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
Index, SubIndex, Data, IntData_LE, BytesData, Access
0x1000,0x00,43414E42 ,1112424771 ,b'CANB',

0x1001,0x00,00 ,0 ,b'\x00',

0x100A,0x00,000A0001 ,16779776 ,b'\x00\n\x00\x01',

0x1017,0x00,E803 ,1000 ,b'\xe8\x03',

0x1018,0x00,05 ,5 ,b'\x05',
0x1018,0x01,B150B150 ,1353797809 ,b'\xb1P\xb1P',
0x1018,0x02,06000000 ,6 ,b'\x06\x00\x00\x00',
0x1018,0x03,0A000000 ,10 ,b'\n\x00\x00\x00',
0x1018,0x04,00000000 ,0 ,b'\x00\x00\x00\x00',
0x1018,0x05,11F7CA23 ,600504081 ,b'\x11\xf7\xca#',

0x101C,0x00,E803 ,1000 ,b'\xe8\x03',

0x1800,0x00,05 ,5 ,b'\x05',
0x1800,0x01,B0010000 ,432 ,b'\xb0\x01\x00\x00',
0x1800,0x02,FF ,255 ,b'\xff',
0x1800,0x03,0000 ,0 ,b'\x00\x00',
0x1800,0x04,0000 ,0 ,b'\x00\x00',
0x1800,0x05,E803 ,1000 ,b'\xe8\x03',

0x1801,0x00,05 ,5 ,b'\x05',
0x1801,0x01,B0020000 ,688 ,b'\xb0\x02\x00\x00',
0x1801,0x02,FF ,255 ,b'\xff',
0x1801,0x03,0000 ,0 ,b'\x00\x00',
0x1801,0x04,0000 ,0 ,b'\x00\x00',
0x1801,0x05,E803 ,1000 ,b'\xe8\x03',

0x1802,0x00,05 ,5 ,b'\x05',
0x1802,0x01,00000080 ,2147483648 ,b'\x00\x00\x00\x80',
0x1802,0x02,00 ,0 ,b'\x00',
0x1802,0x03,0000 ,0 ,b'\x00\x00',
0x1802,0x04,0000 ,0 ,b'\x00\x00',
0x1802,0x05,0000 ,0 ,b'\x00\x00',

0x1803,0x00,05 ,5 ,b'\x05',
0x1803,0x01,00000080 ,2147483648 ,b'\x00\x00\x00\x80',
0x1803,0x02,00 ,0 ,b'\x00',
0x1803,0x03,0000 ,0 ,b'\x00\x00',
0x1803,0x04,0000 ,0 ,b'\x00\x00',
0x1803,0x05,0000 ,0 ,b'\x00\x00',

0x1A00,0x00,00 ,0 ,b'\x00',

0x1A01,0x00,00 ,0 ,b'\x00',

0x1A02,0x00,00 ,0 ,b'\x00',

0x1A03,0x00,00 ,0 ,b'\x00',

0x2000,0x00,04 ,4 ,b'\x04',
0x2000,0x01,9C86 ,34460 ,b'\x9c\x86',
0x2000,0x02,EF09 ,2543 ,b'\xef\t',
0x2000,0x03,F2FF ,65522 ,b'\xf2\xff',
0x2000,0x04,A605 ,1446 ,b'\xa6\x05',

0x2001,0x00,00 ,0 ,b'\x00',

0x2010,0x00,0E ,14 ,b'\x0e',
0x2010,0x01,0C ,12 ,b'\x0c',
0x2010,0x02,802B ,11136 ,b'\x80+',
0x2010,0x03,00 ,0 ,b'\x00',
0x2010,0x04,00 ,0 ,b'\x00',
0x2010,0x05,00 ,0 ,b'\x00',
0x2010,0x06,01 ,1 ,b'\x01',
0x2010,0x07,00 ,0 ,b'\x00',
0x2010,0x08,01 ,1 ,b'\x01',
0x2010,0x09,00 ,0 ,b'\x00',
0x2010,0x0A,0000 ,0 ,b'\x00\x00',
0x2010,0x0B,00000000 ,0 ,b'\x00\x00\x00\x00',
0x2010,0x0C,8809 ,2440 ,b'\x88\t',
0x2010,0x0D,3D09 ,2365 ,b'=\t',

0x2100,0x00,00 ,0 ,b'\x00',

0x2101,0x00,00 ,0 ,b'\x00',

0x2102,0x00,00 ,0 ,b'\x00',

0x2103,0x00,00 ,0 ,b'\x00',

0x2104,0x00,00 ,0 ,b'\x00',

0x2105,0x00,00 ,0 ,b'\x00',

0x2200,0x00,03 ,3 ,b'\x03',
0x2200,0x01,00 ,0 ,b'\x00',
0x2200,0x02,00 ,0 ,b'\x00',
0x2200,0x03,01000000 ,1 ,b'\x01\x00\x00\x00',

0x2201,0x00,02 ,2 ,b'\x02',
0x2201,0x01,01 ,1 ,b'\x01',
0x2201,0x02,00 ,0 ,b'\x00',

0x2202,0x00,02 ,2 ,b'\x02',
0x2202,0x01,00 ,0 ,b'\x00',

0x2300,0x00,03 ,3 ,b'\x03',
0x2300,0x01,00 ,0 ,b'\x00',
0x2300,0x02,00000000 ,0 ,b'\x00\x00\x00\x00',
0x2300,0x03,00000000 ,0 ,b'\x00\x00\x00\x00',

0x2301,0x00,05 ,5 ,b'\x05',
0x2301,0x01,0000 ,0 ,b'\x00\x00',
0x2301,0x02,0000 ,0 ,b'\x00\x00',
0x2301,0x03,0000 ,0 ,b'\x00\x00',
0x2301,0x04,0000 ,0 ,b'\x00\x00',
0x2301,0x05,00 ,0 ,b'\x00',

0x2400,0x00,00000000 ,0 ,b'\x00\x00\x00\x00',

0x2401,0x00,00000000 ,0 ,b'\x00\x00\x00\x00',

0x5000,0x00,02 ,2 ,b'\x02',
0x5000,0x01,00 ,0 ,b'\x00',
0x5000,0x02,00 ,0 ,b'\x00',

0x5100,0x00,04 ,4 ,b'\x04',
0x5100,0x01,16ED0808 ,134802710 ,b'\x16\xed\x08\x08',
0x5100,0x02,00004D53 ,1397555200 ,b'\x00\x00MS',
0x5100,0x03,DC77FB5B ,1543206876 ,b'\xdcw\xfb[',
0x5100,0x04,020000F5 ,4110417922 ,b'\x02\x00\x00\xf5',

0x5101,0x00,01 ,1 ,b'\x01',
0x5101,0x01,00 ,0 ,b'\x00',

0x5102,0x00,02 ,2 ,b'\x02',
0x5102,0x01,00000000 ,0 ,b'\x00\x00\x00\x00',
0x5102,0x02,00000000 ,0 ,b'\x00\x00\x00\x00',

0x5103,0x00,00 ,0 ,b'\x00',
0x5103,0x01,04000000 ,4 ,b'\x04\x00\x00\x00',
136 changes: 136 additions & 0 deletions tests/idle-power-on.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
Index, SubIndex, Data, IntData_LE, BytesData, Access
0x1000,0x00,43414E42 ,1112424771 ,b'CANB',

0x1001,0x00,00 ,0 ,b'\x00',

0x100A,0x00,000A0001 ,16779776 ,b'\x00\n\x00\x01',

0x1017,0x00,E803 ,1000 ,b'\xe8\x03',

0x1018,0x00,05 ,5 ,b'\x05',
0x1018,0x01,B150B150 ,1353797809 ,b'\xb1P\xb1P',
0x1018,0x02,06000000 ,6 ,b'\x06\x00\x00\x00',
0x1018,0x03,0A000000 ,10 ,b'\n\x00\x00\x00',
0x1018,0x04,00000000 ,0 ,b'\x00\x00\x00\x00',
0x1018,0x05,11F7CA23 ,600504081 ,b'\x11\xf7\xca#',

0x101C,0x00,E803 ,1000 ,b'\xe8\x03',

0x1800,0x00,05 ,5 ,b'\x05',
0x1800,0x01,B0010000 ,432 ,b'\xb0\x01\x00\x00',
0x1800,0x02,FF ,255 ,b'\xff',
0x1800,0x03,0000 ,0 ,b'\x00\x00',
0x1800,0x04,0000 ,0 ,b'\x00\x00',
0x1800,0x05,E803 ,1000 ,b'\xe8\x03',

0x1801,0x00,05 ,5 ,b'\x05',
0x1801,0x01,B0020000 ,688 ,b'\xb0\x02\x00\x00',
0x1801,0x02,FF ,255 ,b'\xff',
0x1801,0x03,0000 ,0 ,b'\x00\x00',
0x1801,0x04,0000 ,0 ,b'\x00\x00',
0x1801,0x05,E803 ,1000 ,b'\xe8\x03',

0x1802,0x00,05 ,5 ,b'\x05',
0x1802,0x01,00000080 ,2147483648 ,b'\x00\x00\x00\x80',
0x1802,0x02,00 ,0 ,b'\x00',
0x1802,0x03,0000 ,0 ,b'\x00\x00',
0x1802,0x04,0000 ,0 ,b'\x00\x00',
0x1802,0x05,0000 ,0 ,b'\x00\x00',

0x1803,0x00,05 ,5 ,b'\x05',
0x1803,0x01,00000080 ,2147483648 ,b'\x00\x00\x00\x80',
0x1803,0x02,00 ,0 ,b'\x00',
0x1803,0x03,0000 ,0 ,b'\x00\x00',
0x1803,0x04,0000 ,0 ,b'\x00\x00',
0x1803,0x05,0000 ,0 ,b'\x00\x00',

0x1A00,0x00,00 ,0 ,b'\x00',

0x1A01,0x00,00 ,0 ,b'\x00',

0x1A02,0x00,00 ,0 ,b'\x00',

0x1A03,0x00,00 ,0 ,b'\x00',

0x2000,0x00,04 ,4 ,b'\x04',
0x2000,0x01,9C86 ,34460 ,b'\x9c\x86',
0x2000,0x02,080A ,2568 ,b'\x08\n',
0x2000,0x03,E2FF ,65506 ,b'\xe2\xff',
0x2000,0x04,A605 ,1446 ,b'\xa6\x05',

0x2001,0x00,00 ,0 ,b'\x00',

0x2010,0x00,0E ,14 ,b'\x0e',
0x2010,0x01,0C ,12 ,b'\x0c',
0x2010,0x02,802B ,11136 ,b'\x80+',
0x2010,0x03,00 ,0 ,b'\x00',
0x2010,0x04,00 ,0 ,b'\x00',
0x2010,0x05,00 ,0 ,b'\x00',
0x2010,0x06,01 ,1 ,b'\x01',
0x2010,0x07,00 ,0 ,b'\x00',
0x2010,0x08,01 ,1 ,b'\x01',
0x2010,0x09,00 ,0 ,b'\x00',
0x2010,0x0A,0000 ,0 ,b'\x00\x00',
0x2010,0x0B,00000000 ,0 ,b'\x00\x00\x00\x00',
0x2010,0x0C,9709 ,2455 ,b'\x97\t',
0x2010,0x0D,4C09 ,2380 ,b'L\t',

0x2100,0x00,00 ,0 ,b'\x00',

0x2101,0x00,00 ,0 ,b'\x00',

0x2102,0x00,00 ,0 ,b'\x00',

0x2103,0x00,00 ,0 ,b'\x00',

0x2104,0x00,00 ,0 ,b'\x00',

0x2105,0x00,00 ,0 ,b'\x00',

0x2200,0x00,03 ,3 ,b'\x03',
0x2200,0x01,01 ,1 ,b'\x01',
0x2200,0x02,01 ,1 ,b'\x01',
0x2200,0x03,00000000 ,0 ,b'\x00\x00\x00\x00',

0x2201,0x00,02 ,2 ,b'\x02',
0x2201,0x01,01 ,1 ,b'\x01',
0x2201,0x02,00 ,0 ,b'\x00',

0x2202,0x00,02 ,2 ,b'\x02',
0x2202,0x01,00 ,0 ,b'\x00',

0x2300,0x00,03 ,3 ,b'\x03',
0x2300,0x01,00 ,0 ,b'\x00',
0x2300,0x02,00000000 ,0 ,b'\x00\x00\x00\x00',
0x2300,0x03,00000000 ,0 ,b'\x00\x00\x00\x00',

0x2301,0x00,05 ,5 ,b'\x05',
0x2301,0x01,0000 ,0 ,b'\x00\x00',
0x2301,0x02,0000 ,0 ,b'\x00\x00',
0x2301,0x03,0000 ,0 ,b'\x00\x00',
0x2301,0x04,0000 ,0 ,b'\x00\x00',
0x2301,0x05,00 ,0 ,b'\x00',

0x2400,0x00,00000000 ,0 ,b'\x00\x00\x00\x00',

0x2401,0x00,00000000 ,0 ,b'\x00\x00\x00\x00',

0x5000,0x00,02 ,2 ,b'\x02',
0x5000,0x01,01 ,1 ,b'\x01',
0x5000,0x02,01 ,1 ,b'\x01',

0x5100,0x00,04 ,4 ,b'\x04',
0x5100,0x01,16ED0808 ,134802710 ,b'\x16\xed\x08\x08',
0x5100,0x02,00004D53 ,1397555200 ,b'\x00\x00MS',
0x5100,0x03,DC77FB5B ,1543206876 ,b'\xdcw\xfb[',
0x5100,0x04,020000F5 ,4110417922 ,b'\x02\x00\x00\xf5',

0x5101,0x00,01 ,1 ,b'\x01',
0x5101,0x01,00 ,0 ,b'\x00',

0x5102,0x00,02 ,2 ,b'\x02',
0x5102,0x01,00000000 ,0 ,b'\x00\x00\x00\x00',
0x5102,0x02,00000000 ,0 ,b'\x00\x00\x00\x00',

0x5103,0x00,00 ,0 ,b'\x00',
0x5103,0x01,04000000 ,4 ,b'\x04\x00\x00\x00',
43 changes: 25 additions & 18 deletions tools/bmsmonitor
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import canopen

logging.basicConfig(level=logging.WARNING)

EVENT_TIMER=5000
BMSINFO = {}


Expand All @@ -26,15 +27,17 @@ def eprint(*args, **kwargs):
def set_defaults():
" Set default values for BMSINFO "

names = ['voltage',
'unknown_2000_04',
'unknown_2010_02',
'unknown',
names = ['power',
'voltage',
'temp1',
'temp2',
'temp3',
'unknown_2000_03']

'unknown_2000_03',
'unknown_2000_04',
'unknown_2010_01',
'unknown_2010_02',
]

# Set default value for all variables
for var in names:
BMSINFO.setdefault(var, "")
Expand All @@ -46,7 +49,7 @@ def show_status(info):
msg = """
Updated : {last_update}
Power : {output}
Power : {power}
Voltage : {voltage}v
Temp 1 : {temp1} degrees C
Temp 2 : {temp2} degrees C
Expand All @@ -63,23 +66,26 @@ def show_status(info):

print(msg)

def strhexint(data):
return "%s (%s)" % (data.hex(),int.from_bytes(data,'little'))

def hardway_handle_tpdo(canid, data, tstamp):
""" Manually decode incoming TPDO messages """

if canid == 0x1b0:
if canid == 0x1b0: # Decode TPDO 1
BMSINFO['voltage'] = int.from_bytes(data[0:2], 'little') / 1000.0
BMSINFO['unknown_2000_04'] = int.from_bytes(data[2:4], 'little')
BMSINFO['unknown_2010_02'] = int.from_bytes(data[4:6], 'little')
BMSINFO['unknown_2010_01'] = data[6:7].hex()
BMSINFO['output'] = 'on' if ord(data[7:8]) else 'off'
elif canid == 0x2b0:
BMSINFO['unknown_2000_04'] = strhexint(data[2:4])
BMSINFO['unknown_2010_02'] = strhexint(data[4:6])
BMSINFO['unknown_2010_01'] = strhexint(data[6:7])
BMSINFO['power'] = 'on' if ord(data[7:8]) else 'off'
elif canid == 0x2b0: # Decode TPDO 2
BMSINFO['temp1'] = int.from_bytes(data[0:2], 'little') / 100.0
BMSINFO['temp2'] = int.from_bytes(data[2:4], 'little') / 100.0
BMSINFO['temp3'] = int.from_bytes(data[4:6], 'little') / 100.0
BMSINFO['unknown_2000_03'] = int.from_bytes(data[0:2], 'little')
BMSINFO['unknown_2000_03'] = strhexint(data[6:8])

BMSINFO['last_update'] = str(datetime.datetime.fromtimestamp(tstamp))
BMSINFO['last_update'] = datetime.datetime.fromtimestamp(tstamp).\
isoformat(' ',timespec='seconds')
show_status(BMSINFO)


Expand All @@ -106,9 +112,10 @@ def the_hard_way(network):
node.sdo.download(0x1800, 0x3, bytes.fromhex('0000'))
node.sdo.download(0x1801, 0x3, bytes.fromhex('0000'))

# Configure event interval to 5 seconds
node.sdo.download(0x1800, 0x5, bytes.fromhex('8813'))
node.sdo.download(0x1801, 0x5, bytes.fromhex('8813'))
# Configure event interval to EVENT_TIMER
interval = EVENT_TIMER.to_bytes(2,byteorder='little')
node.sdo.download(0x1800, 0x5, interval)
node.sdo.download(0x1801, 0x5, interval)

# Enable TPDO 1 & 2
node.sdo.download(0x1800, 0x1, bytes.fromhex('b0010000'))
Expand Down

0 comments on commit 0dae665

Please sign in to comment.