9 from __future__
import division, absolute_import, print_function, unicode_literals
14 from logging
import getLogger
16 from .common
import DriverError, TxQueueFullError, CANFrame, AbstractDriver
17 from .timestamp_estimator
import TimestampEstimator
25 logger = getLogger(__name__)
40 self.
_bus = can.interface.Bus()
42 self.
_bus = can.interface.Bus(channel=channel, bustype=_extras[
'bustype'], bitrate=_extras[
'bitrate'])
43 except Exception
as ex:
44 logger.exception(
"Could not instantiate a python-can driver")
57 ppm =
lambda x: x / 1e6
58 milliseconds =
lambda x: x * 1e-3
63 max_rate_error=ppm(100),
64 fixed_delay=milliseconds(0.001),
65 max_phase_error_to_resync=milliseconds(50),
69 mono = time.monotonic()
72 mono_to_real_offset = est_real - mono
73 return value - mono_to_real_offset
86 arbitration_id=frame.id,
87 extended_id=frame.extended,
89 data=list(frame.data),
92 self.
_bus.flush_tx_buffer()
94 frame.ts_monotonic = time.monotonic()
95 frame.ts_real = time.time()
98 if ex.errno == errno.ENOBUFS:
104 except Exception
as ex:
113 if isinstance(item, Exception):
116 if isinstance(item, CANFrame):
119 raise DriverError(
"Unexpected item in write feedback queue: %r" % item)
129 timeout = -1
if timeout
is None else (timeout * 1000)
132 msg = self.
_bus.recv(timeout=timeout)
134 ts_mono = time.monotonic()
135 ts_real = time.time()
137 if ts_real
and not ts_mono:
145 ts_monotonic=ts_mono,
150 except Exception
as ex:
151 logger.error(
"Receive exception", exc_info=
True)
153 def send(self, message_id, message, extended=False):