Data Sources¶
Abstract base interface for vehicle data sources.
-
class
openxc.sources.base.
BytestreamDataSource
(**kwargs)¶ A source that receives data is a series of bytes, with discrete messages separated by a newline character.
Subclasses of this class need only to implement the
read
method.-
run
()¶ Continuously read data from the source and attempt to parse a valid message from the buffer of bytes. When a message is parsed, passes it off to the callback if one is set.
-
-
class
openxc.sources.base.
DataSource
(callback=None, log_mode=None, payload_format=None)¶ Interface for all vehicle data sources. This inherits from Thread and when a source is added to a vehicle it attempts to call the
start()
method if it exists. If an implementer of DataSource needs some background process to read data, it’s just a matter of defining arun()
method.A data source requires a callback method to be specified. Whenever new data is received, it will pass it to that callback.
Construct a new DataSource.
By default, DataSource threads are marked as
daemon
threads, so they will die as soon as all other non-daemon threads in the process have quit.- Kwargs:
- callback - function to call with any new data received
-
bytes_received
¶
-
format
¶
-
formatter
¶
-
read
(timeout=None)¶ Read data from the source.
- Kwargs:
- timeout (float) - if the source implementation could potentially
- block, timeout after this number of seconds.
-
read_logs
(timeout=None)¶ Read log data from the source.
- Kwargs:
- timeout (float) - if the source implementation could potentially
- block, timeout after this number of seconds.
-
start
()¶ Start the thread’s activity.
It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.
This method will raise a RuntimeError if called more than once on the same thread object.
-
stop
()¶
-
streamer
¶
-
exception
openxc.sources.base.
DataSourceError
¶
-
exception
openxc.sources.base.
MissingPayloadFormatError
¶
-
class
openxc.sources.base.
SourceLogger
(source, mode='off')¶ -
FILENAME_TEMPLATE
= '%d-%m-%Y.%H-%M-%S'¶
-
record
(message)¶
-
run
()¶ Continuously read data from the source and attempt to parse a valid message from the buffer of bytes. When a message is parsed, passes it off to the callback if one is set.
-
stop
()¶
-
A virtual serial port data source.
-
class
openxc.sources.serial.
SerialDataSource
(port=None, baudrate=None, **kwargs)¶ A data source reading from a serial port, which could be implemented with a USB to Serial or Bluetooth adapter.
Initialize a connection to the serial device.
- Kwargs:
- port - optionally override the default virtual COM port baudrate - optionally override the default baudrate
- Raises:
- DataSourceError if the serial device cannot be opened.
-
DEFAULT_BAUDRATE
= 230400¶
-
DEFAULT_PORT
= '/dev/ttyUSB0'¶
-
read
()¶ Read data from the source.
- Kwargs:
- timeout (float) - if the source implementation could potentially
- block, timeout after this number of seconds.
A USB vehicle interface data source.
-
class
openxc.sources.usb.
UsbDataSource
(vendor_id=None, product_id=None, **kwargs)¶ A source to receive data from an OpenXC vehicle interface via USB.
Initialize a connection to the USB device’s IN endpoint.
- Kwargs:
- vendor_id (str or int) - optionally override the USB device vendor
- ID we will attempt to connect to, if not using the OpenXC hardware.
- product_id (str or int) - optionally override the USB device product
- ID we will attempt to connect to, if not using the OpenXC hardware.
- log_mode - optionally record or print logs from the USB device, which
- are on a separate channel.
- Raises:
- DataSourceError if the USB device with the given vendor ID is not connected.
-
DEFAULT_INTERFACE_NUMBER
= 0¶
-
DEFAULT_PRODUCT_ID
= 1¶
-
DEFAULT_READ_REQUEST_SIZE
= 512¶
-
DEFAULT_READ_TIMEOUT
= 200¶
-
DEFAULT_VENDOR_ID
= 7108¶
-
LOG_IN_ENDPOINT
= 11¶
-
VEHICLE_DATA_IN_ENDPOINT
= 2¶
-
read
(timeout=None)¶ Read data from the source.
- Kwargs:
- timeout (float) - if the source implementation could potentially
- block, timeout after this number of seconds.
-
read_logs
(timeout=None)¶ Read log data from the source.
- Kwargs:
- timeout (float) - if the source implementation could potentially
- block, timeout after this number of seconds.
-
stop
()¶
A data source for reading from pre-recorded OpenXC trace files.
-
class
openxc.sources.trace.
TraceDataSource
(filename=None, realtime=True, loop=True, **kwargs)¶ A class to replay a previously recorded OpenXC vehicle data trace file. For details on the trace file format, see http://openxcplatform.com/android/testing.html.
Construct the source and attempt to open the trace file.
filename - the full absolute path to the trace file
realtime - if
True
, the trace will be replayed at approximately the same cadence as it was recorded. Otherwise, the trace file will be replayed as fast as possible (likely much faster than any vehicle).loop - if
True
, the trace file will be looped and will provide data until the process exist or the source is stopped.-
read
()¶ Read a line of data from the input source at a time.
-
A network socket data source.
-
class
openxc.sources.network.
NetworkDataSource
(host=None, port=None, **kwargs)¶ A data source reading from a network socket, as implemented in the openxc-vehicle-simulator .
Initialize a connection to the network socket.
- Kwargs:
- host - optionally override the default network host (default is local machine) port - optionally override the default network port (default is 50001) log_mode - optionally record or print logs from the network source
- Raises:
- DataSourceError if the socket connection cannot be opened.
-
DEFAULT_PORT
= 50001¶