Last active
March 4, 2018 18:09
-
-
Save gregjhogan/6793b60747e40356f684be7af3546286 to your computer and use it in GitHub Desktop.
replay a cabana log through a panda
This file contains hidden or 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() | |
| except: | |
| pass | |
| p.set_safety_mode(Panda.SAFETY_ALLOUTPUT) | |
| 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