Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion canard/hw/cantact.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import serial
import time

from .. import can

Expand All @@ -12,6 +13,7 @@ def _dev_write(self, string):

def start(self):
self._dev_write('O\r')
self.start_time = time.time()

def stop(self):
self._dev_write('C\r')
Expand Down Expand Up @@ -42,7 +44,12 @@ def recv(self):
# receive characters until a newline (\r) is hit
rx_str = ""
while rx_str == "" or rx_str[-1] != '\r':
rx_str = rx_str + self.ser.read().decode('ascii')
rx = self.ser.read().decode('ascii')
if rx == "":
# Read timeout from pySerial
return None
else:
rx_str = rx_str + rx

# check frame type
if rx_str[0] == 'T':
Expand Down Expand Up @@ -79,6 +86,7 @@ def recv(self):
data.append(int(rx_str[data_offset+i*2:(data_offset+2)+i*2], 16))
frame.data = data

frame.timestamp = time.time() - self.start_time
return frame

def send(self, frame):
Expand Down
12 changes: 10 additions & 2 deletions canard/hw/logplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@
class LogPlayer:
running = False
def __init__(self, log_filename):
self.logfile = open(log_filename, 'r')
self.log_filename = log_filename
self.logfile = None

def start(self):
assert not self.running, 'cannot start, already running'
self.logfile = open(self.log_filename, 'r')
self.start_timestamp = time.time()
self.running = True

def stop(self):
if self.logfile:
self.logfile.close()
self.running = False

def recv(self):
assert self.running, 'not running'
last_timestamp = 0
Expand All @@ -31,7 +38,8 @@ def _log_to_frame(self, line):
fields = line.split(' ')

id = int(fields[1], 0)
frame = can.Frame(id)
ext_id = id > 0x7FF and id <= 0x1FFFFFFF
frame = can.Frame(id, is_extended_id=ext_id)

frame.timestamp = float(fields[0])

Expand Down