This module is contains the Vehicle class, which is the main entry point for using the Python library to access vehicle data programatically. Most users will want to interact with an instance of Vehicle, and won’t need to deal with other parts of the library directly (besides measurement types).
- class openxc.vehicle.Vehicle(interface=None)¶
The Vehicle class is the main entry point for the OpenXC Python library. A Vehicle represents a connection to at least one vehicle data source and zero or 1 vehicle controllers, which can accept commands to send back to the vehicle. A Vehicle instance can have more than one data source (e.g. if the computer using this library has a secondary GPS data source).
Most applications will either request synchronous vehicle data measurements using the get method or or with a callback function passed to listen.
More advanced applications that want access to all raw vehicle data may want to register a DataSink with a Vehicle.
Construct a new Vehicle instance, optionally providing an vehicle interface from openxc.interface to user for I/O.
Add a vehicle data sink to the instance. sink should be a sub-class of DataSink or at least have a receive(message, **kwargs) method.
The sink will be started if it is startable. (i.e. it has a start() method).
Add a vehicle data source to the instance.
The Vehicle instance will be set as the callback of the source, and the source will be started if it is startable. (i.e. it has a start() method).
Return the latest measurement for the given class or None if nothing has been received from the vehicle.
- listen(measurement_class, callback)¶
Register the callback function to be called whenever a new measurement of the given class is received from the vehicle data sources.
If the callback is already registered for measurements of the given type, this method will have no effect.
- unlisten(measurement_class, callback)¶
Stop notifying the given callback of new values of the measurement type.
If the callback was not previously registered as a listener, this method will have no effect.