public class

TraceVehicleDataSource

extends ContextualVehicleDataSource
implements Runnable
java.lang.Object
   ↳ com.openxc.sources.BaseVehicleDataSource
     ↳ com.openxc.sources.ContextualVehicleDataSource
       ↳ com.openxc.sources.trace.TraceVehicleDataSource

Class Overview

A vehicle data source that reads measurements from a pre-recorded trace file. This class is primarily for testing - a pre-recorded trace of the output from an OpenXC vehicle interface is played back line by line into the library. Everything from the VehicleService on up the chain is identical to when operating in a live vehicle. The trace file format is defined in the OpenXC message format specification: https://github.com/openxc/openxc-message-format The trace file to use is specified via the constructor as an Android-style resource URI, e.g. "resource://42", "file:///storage/traces/trace.json" or a plain file path (e.g. "/sdcard/com.openxc/trace.json" ). When using resources, the ID for the resource is accessed through the generated "R.java" file. For example: URI resource = new URI("resource://" + R.raw.trace) where the trace file is located at res/raw/trace. Regular files are the preferred way to use trace files, and are required when using the OpenXC enabler app. Android apps don't have access to each others' raw resources, so the resource method will not work in that case. The trace file is played back in a continuous loop at roughly the same speed as the original recording (at least according to the timestamps in the file). Playback will not begin until a callback is set, either via a constructor or the setCallback(SourceCallback) function.

Summary

Public Constructors
TraceVehicleDataSource(SourceCallback callback, Context context, URI filename)
Construct a trace data source with the given context, callback and trace file resource URI.
TraceVehicleDataSource(SourceCallback callback, Context context, URI filename, boolean loop)
TraceVehicleDataSource(Context context, URI filename)
TraceVehicleDataSource(Context context, String filename)
TraceVehicleDataSource(Context context, URI filename, boolean loop)
Public Methods
boolean isConnected()
Consider the trace source "connected" if it's running and at least 1 measurement was parsed successfully from the file.
void run()
While running, continuously read from the trace file and send messages to the callback.
boolean sameFilename(String filename)
void stop()
Stop trace file playback and the playback thread.
String toString()
static boolean validatePath(String path)
Protected Methods
String getTag()
Return a string suitable as a tag for logging.
[Expand]
Inherited Methods
From class com.openxc.sources.ContextualVehicleDataSource
From class com.openxc.sources.BaseVehicleDataSource
From class java.lang.Object
From interface com.openxc.DataPipeline.Operator
From interface com.openxc.sources.VehicleDataSource
From interface java.lang.Runnable

Public Constructors

public TraceVehicleDataSource (SourceCallback callback, Context context, URI filename)

Construct a trace data source with the given context, callback and trace file resource URI. If the callback is not null, playback will begin immediately.

Parameters
callback An object implementing the SourceCallback interface that should receive data as it is received and parsed.
context the Activity or Service context, used to access the raw trace file resource via Android.
filename a raw file resource URI of the format "resource://resource_id"
Throws
DataSourceException if no filename is specified

public TraceVehicleDataSource (SourceCallback callback, Context context, URI filename, boolean loop)

public TraceVehicleDataSource (Context context, URI filename)

public TraceVehicleDataSource (Context context, String filename)

public TraceVehicleDataSource (Context context, URI filename, boolean loop)

Public Methods

public boolean isConnected ()

Consider the trace source "connected" if it's running and at least 1 measurement was parsed successfully from the file. This will catch errors e.g. if the trace is totally corrupted, but it won't give you any indication if it is partially corrupted.

public void run ()

While running, continuously read from the trace file and send messages to the callback. If the callback is not set, this function will exit immediately and the thread will die a quick death.

public boolean sameFilename (String filename)

public void stop ()

Stop trace file playback and the playback thread.

public String toString ()

public static boolean validatePath (String path)

Protected Methods

protected String getTag ()

Return a string suitable as a tag for logging.