Controllers

Contains the abstract interface for sending commands back to a vehicle interface.

class openxc.controllers.base.CommandResponseReceiver(queue, request)

A receiver that matches the ‘command’ field in responses to the original request.

Construct a new ResponseReceiver.

queue - A multithreading queue that this receiver will pull potential responses from. request - The request we are trying to match up with a response.

class openxc.controllers.base.Controller

A Controller is a physical vehicle interface that accepts commands to be send back to the vehicle. This class is abstract, and implementations of the interface must define at least the write_bytes method.

COMMAND_RESPONSE_TIMEOUT_S = 0.2
complex_request(request, wait_for_first_response=True)

Send a compound command request to the interface over the normal data channel.

request - A dict storing the request to send to the VI. It will be
serialized to JSON, as that is the only supported format for commands on the VI in the current firmware.
wait_for_first_response - If true, this function will block waiting for
a response from the VI and return it to the caller. Otherwise, it will send the command and return immediately and any response will be lost.
device_id()

Request the unique device ID of the attached VI.

diagnostic_request(message_id, mode, bus=None, pid=None, frequency=None, payload=None, wait_for_first_response=False)

Send a new diagnostic message request to the VI

Required:

message_id - The message ID (arbitration ID) for the request. mode - the diagnostic mode (or service).

Optional:

bus - The address of the CAN bus controller to send the request, either
1 or 2 for current VI hardware.
pid - The parameter ID, or PID, for the request (e.g. for a mode 1
request).
frequency - The frequency in hertz to add this as a recurring diagnostic
requests. If None or 0, it will be a one-time request.
payload - A bytearray to send as the request’s optional payload. Only
single frame diagnostic requests are supported by the VI firmware in the current version, so the payload has a maximum length of 6.
wait_for_first_response - If True, this function will block waiting for
a response to be received for the request. It will return either after timing out or after 1 matching response is received - there may be more responses to functional broadcast requests that arrive after returning.
version()

Request a firmware version identifier from the VI.

write(**kwargs)

Serialize a raw or translated write request as JSON and send it to the VI, following the OpenXC message format.

write_bytes(data)

Write the bytes in data to the controller interface.

write_raw(message_id, data, bus=None)

Send a raw write request to the VI.

write_translated(name, value, event)

Send a translated write request to the VI.

exception openxc.controllers.base.ControllerError
class openxc.controllers.base.DiagnosticResponseReceiver(queue, request)

A receiver that matches the bus, ID, mode and PID from a diagnostic request to an incoming response.

class openxc.controllers.base.ResponseReceiver(queue, request)

All commands to a vehicle interface are asynchronous. This class is used to wait for the response for a particular request in a thread. Before making a request, a ResponseReceiver is created to wait for the response. All responses received from the VI (which may or may not be in response to this particular command) are passed to the ResponseReceiver, until it either times out waiting or finds a matching response.

The synchronization mechanism is a multiprocessing Queue. The ResponseReceiver blocks waiting on a new response to be added to the queue, and the vehicle interface class puts newly received responses in the queues of ResponseReceivers as they arrive.

Construct a new ResponseReceiver.

queue - A multithreading queue that this receiver will pull potential responses from. request - The request we are trying to match up with a response.

wait_for_command_response()

Block and wait for a response to this object’s original request, or until a timeout (Controller.COMMAND_RESPONSE_TIMEOUT_S).

This function is handy to use as the target function for a thread.

The response received (or None if none was received before the timeout) is stored at self.response and also returned from this function.

Controller implementation for a virtual serial device.

class openxc.controllers.serial.SerialControllerMixin

An implementation of a Controller type that connects to a virtual serial device.

This class acts as a mixin, and expects self.device to be an instance of serial.Serial.

TODO Bah, this is kind of weird. refactor the relationship between sources/controllers.

WAITIED_FOR_CONNECTION = False
complex_request(request, blocking=True)
write_bytes(data)

Controller implementation for an OpenXC USB device.

class openxc.controllers.usb.UsbControllerMixin

An implementation of a Controller type that connects to an OpenXC USB device.

This class acts as a mixin, and expects self.device to be an instance of usb.Device.

TODO bah, this is kind of weird. refactor the relationship between sources/controllers.

COMPLEX_CONTROL_COMMAND = 131
DEVICE_ID_CONTROL_COMMAND = 130
VERSION_CONTROL_COMMAND = 128
device_id()

Request the unique device ID of the attached VI with a USB control request.

diagnostic_request(message_id, mode, bus=None, pid=None, frequency=None, payload=None, wait_for_first_response=False)

Send a new diagnostic request to the VI with a USB control request.

out_endpoint

Open a reference to the USB device’s only OUT endpoint. This method assumes that the USB device configuration has already been set.

version()

Request the firmware version identifier from the VI via USB control request.

write_bytes(data)