Last active
July 4, 2019 16:00
-
-
Save energee/df273ef2fd9976a57156c260be5e08e3 to your computer and use it in GitHub Desktop.
CAN Replay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import time | |
import struct | |
from panda import Panda | |
DEBUG = False | |
def main(): | |
logfile = sys.argv[1] | |
print "open log file {}".format(logfile) | |
with open(logfile,'r') as log: | |
print "wait for panda ..." | |
p = None | |
while not p: | |
time.sleep(0.1) | |
try: | |
p = Panda('000015800f51363038363036') | |
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT) | |
except: | |
pass | |
start_time = time.time() | |
print "replay log ..." | |
log.readline() # skip header | |
for line in log: | |
line = line.rstrip() | |
if not line: continue | |
# parse the log line | |
t, addr, bus, data = line.split(',') | |
bus = int(bus) | |
if (bus >= 100): continue # skip forwarded messages | |
t = float(t) + start_time | |
addr = int(addr) | |
data = data.rstrip().decode("hex") | |
# wait for the correct moment to send the message | |
tdiff = time.time() - t | |
while (tdiff <= 0): | |
tdiff = time.time() - t | |
if tdiff > .1: print "lagged {}".format(tdiff) | |
p.can_send(addr, data, bus) | |
if DEBUG: print line | |
print "\nDone!" | |
p.close() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment