5
5
# in the background files.
6
6
7
7
# Expects the CSV file to be in the format from can_logger.py
8
+ # Bus,MessageID,Message,MessageLength
9
+ # 0,0x292,0x040000001068,6
10
+
11
+ # The old can_logger.py format is also supported:
8
12
# Bus,MessageID,Message
9
13
# 0,344,c000c00000000000
10
14
15
+
11
16
import binascii
12
17
import csv
13
18
import sys
@@ -32,7 +37,7 @@ def printBitDiff(self, other):
32
37
if new_zeros :
33
38
print 'id %s new zero at byte %d bitmask %d' % (
34
39
self .message_id , i , new_zeros )
35
-
40
+
36
41
37
42
class Info ():
38
43
"""A collection of Messages."""
@@ -46,8 +51,14 @@ def load(self, filename):
46
51
reader = csv .reader (input )
47
52
next (reader , None ) # skip the CSV header
48
53
for row in reader :
49
- message_id = row [1 ]
50
- data = row [2 ]
54
+ if row [1 ].startswith ('0x' ):
55
+ message_id = row [1 ][2 :] # remove leading '0x'
56
+ else :
57
+ message_id = hex (int (row [1 ]))[2 :] # old message IDs are in decimal
58
+ if row [1 ].startswith ('0x' ):
59
+ data = row [2 ][2 :] # remove leading '0x'
60
+ else :
61
+ data = row [2 ]
51
62
if message_id not in self .messages :
52
63
self .messages [message_id ] = Message (message_id )
53
64
message = self .messages [message_id ]
@@ -71,8 +82,8 @@ def PrintUnique(interesting_file, background_files):
71
82
else :
72
83
interesting .messages [message_id ].printBitDiff (
73
84
background .messages [message_id ])
74
-
75
-
85
+
86
+
76
87
if __name__ == "__main__" :
77
88
if len (sys .argv ) < 3 :
78
89
print 'Usage:\n %s interesting.csv background*.csv' % sys .argv [0 ]
0 commit comments