-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcantldr.py
executable file
·45 lines (43 loc) · 2.45 KB
/
cantldr.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
#!/usr/bin/env python3
# cantldr.py by jerkey
# opens ks_can2serial canbus logs generated by https://github.com/jerkey/ks_can/blob/teslalog/ks_can2serial.ino
inFile = open('/tmp/can2serial.txt')
RESET = '\033[0m' # https://misc.flogisoft.com/bash/tip_colors_and_formatting
GREEN = '\033[32m'
RED = '\033[31m'
YELLOW = '\033[33m'
# cat /tmp/can2serial.txt | cut -d":" -f1 | sort | uniq
# ids = [0x610,0x618,0x612,0x613,0x614] # list of CAN IDs we care about for brusa
ids = [] # list of CAN IDs we care about
# sent by L3CC board to Mobi charger
ids.append(0x500); # L3CC information reporting ID
ids.append(0x109); # YELLOWBEE_CONTROL_REQ
ids.append(0x10C); # YELLOWBEE_STATUS_REQ
# sent by Zekalabs Yellowbee LB-1071-01-01
ids.append(0x409); # YELLOWBEE_CONTROL_RSP
ids.append(0x40C); # YELLOWBEE_STATUS_RSP
lastMsg = [' '] * len(ids) # empty so it's not too short to compare with
for line in inFile: # '268:00000000B3000000 16\n' is what a line looks like
if line.find(':')==3: # ignore invalid lines from ks_can2serial.ino
id = int(line.split(':')[0],16)
if id in ids: # we ignore CAN IDs not in our list
idIndex = ids.index(id)
data = line.split(' ')[0][4:20]
data = data[0:4]+' '+data[4:8]+' '+data[8:12]+' '+data[12:16] # add spaces for readability
if lastMsg[idIndex] != data: # ignore messages that haven't changed since we last saw them
print(hex(id)+'\t',end='')
for i in range(len(data)): # print character by character, colored according to same or changed
if lastMsg[idIndex][i]==data[i]:
print(RESET+data[i],end='')
else:
print(RED+data[i],end='')
for i in range(len(data),20): # pad data with spaces out to 20 characters
print(' ',end='')
linetime = int(line[:-1].split(' ')[1]) # get the time in milliseconds from the log
mins = int(linetime / (1000*60))
secs = linetime % 60000 / 1000
lastMsg[idIndex] = data # store the latest data to compare with for next time
print('\t'+YELLOW+str(mins).zfill(3)+':',end='') # print the number of minutes:
if secs < 10:
print('0',end='')
print(str(secs)+RESET) # print the number of seconds (a float) and ANSI RESET