Skip to content

Commit

Permalink
Merge pull request commaai#70 from adhintz/master
Browse files Browse the repository at this point in the history
  update can_unique.py for new can_logger.py format
  • Loading branch information
geohot committed Nov 21, 2017
2 parents 8863433 + a5f99b5 commit 5f026d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
14 changes: 7 additions & 7 deletions examples/can_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from panda import Panda

def can_logger():

try:
print("Trying to connect to Panda over USB...")
p = Panda()

except AssertionError:
print("USB connection failed. Trying WiFi...")

try:
p = Panda("WIFI")
except:
Expand All @@ -26,24 +26,24 @@ def can_logger():
#Write Header
csvwriter.writerow(['Bus', 'MessageID', 'Message', 'MessageLength'])
print("Writing csv file output.csv. Press Ctrl-C to exit...\n")

bus0_msg_cnt = 0
bus1_msg_cnt = 0
bus2_msg_cnt = 0

while True:
can_recv = p.can_recv()

for address, _, dat, src in can_recv:
csvwriter.writerow([str(src), str(hex(address)), "0x" + binascii.hexlify(dat), len(dat)])

if src == 0:
bus0_msg_cnt += 1
elif src == 1:
bus1_msg_cnt += 1
elif src == 2:
bus2_msg_cnt += 1

print("Message Counts... Bus 0: " + str(bus0_msg_cnt) + " Bus 1: " + str(bus1_msg_cnt) + " Bus 2: " + str(bus2_msg_cnt), end='\r')

except KeyboardInterrupt:
Expand Down
21 changes: 16 additions & 5 deletions examples/can_unique.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
# in the background files.

# Expects the CSV file to be in the format from can_logger.py
# Bus,MessageID,Message,MessageLength
# 0,0x292,0x040000001068,6

# The old can_logger.py format is also supported:
# Bus,MessageID,Message
# 0,344,c000c00000000000


import binascii
import csv
import sys
Expand All @@ -32,7 +37,7 @@ def printBitDiff(self, other):
if new_zeros:
print 'id %s new zero at byte %d bitmask %d' % (
self.message_id, i, new_zeros)


class Info():
"""A collection of Messages."""
Expand All @@ -46,8 +51,14 @@ def load(self, filename):
reader = csv.reader(input)
next(reader, None) # skip the CSV header
for row in reader:
message_id = row[1]
data = row[2]
if row[1].startswith('0x'):
message_id = row[1][2:] # remove leading '0x'
else:
message_id = hex(int(row[1]))[2:] # old message IDs are in decimal
if row[1].startswith('0x'):
data = row[2][2:] # remove leading '0x'
else:
data = row[2]
if message_id not in self.messages:
self.messages[message_id] = Message(message_id)
message = self.messages[message_id]
Expand All @@ -71,8 +82,8 @@ def PrintUnique(interesting_file, background_files):
else:
interesting.messages[message_id].printBitDiff(
background.messages[message_id])


if __name__ == "__main__":
if len(sys.argv) < 3:
print 'Usage:\n%s interesting.csv background*.csv' % sys.argv[0]
Expand Down

0 comments on commit 5f026d7

Please sign in to comment.