add support to can_unique.py for Cabana CSV format.
* add support to can_unique.py for Cabana CSV format.
also fix python3 issue where open() was in binary mode, but we want text
mode.
* consolidate duplicated code
* fix typo caught by the linter
# messages, print which bits in the interesting file have never appeared
# in the background files.
-# Expects the CSV file to be in the format from can_logger.py
+# Expects the CSV file to be in one of the following formats:
+
+# can_logger.py
# Bus,MessageID,Message,MessageLength
# 0,0x292,0x040000001068,6
# Bus,MessageID,Message
# 0,344,c000c00000000000
+# Cabana "Save Log" format
+# time,addr,bus,data
+# 240.47911496100002,53,0,0acc0ade0074bf9e
+
import csv
import sys
@@ -45,9 +51,23 @@ class Info():
def load(self, filename):
"""Given a CSV file, adds information about message IDs and their values."""
- with open(filename, 'rb') as input:
+ with open(filename, 'r') as input:
reader = csv.reader(input)
- next(reader, None) # skip the CSV header
+ header = next(reader, None)
+ if header[0] == 'time':
+ self.cabana(reader)
+ else:
+ self.logger(reader)
+
+ def cabana(self, reader):
+ for row in reader:
+ bus = row[2]
+ message_id = hex(int(row[1]))[2:]
+ message_id = '%s:%s' % (bus, message_id)
+ data = row[3]
+ self.store(message_id, data)
+
+ def logger(self, reader):
for row in reader:
bus = row[0]
if row[1].startswith('0x'):
@@ -59,6 +79,9 @@ class Info():
data = row[2][2:] # remove leading '0x'
else:
data = row[2]
+ self.store(message_id, data)
+
+ def store(self, message_id, data):
if message_id not in self.messages:
self.messages[message_id] = Message(message_id)
message = self.messages[message_id]
@@ -70,6 +93,8 @@ class Info():
# Inverts the data and masks it to a byte to get the zeros as ones.
message.zeros[i] = message.zeros[i] | ( (~int(bytes[i])) & 0xff)
+
+
def PrintUnique(interesting_file, background_files):
background = Info()
for background_file in background_files:
