public abstract class

BytestreamDataSource

extends ContextualVehicleDataSource
implements Runnable
java.lang.Object
   ↳ com.openxc.sources.BaseVehicleDataSource
     ↳ com.openxc.sources.ContextualVehicleDataSource
       ↳ com.openxc.sources.BytestreamDataSource
Known Direct Subclasses

Class Overview

Common functionality for data sources that read a stream of newline-separated messages in a separate thread from the main activity.

Summary

Constants
int RECONNECTION_ATTEMPT_WAIT_TIME_S
int SLOW_RECONNECTION_ATTEMPT_WAIT_TIME_S
Fields
protected final ReadWriteLock mConnectionLock
protected final Condition mDeviceChanged
Public Constructors
BytestreamDataSource(SourceCallback callback, Context context)
Public Methods
boolean isConnected()
Return true if the data source is actively connected to its target, be it a USB endpoint, a Bluetooth channel, a trace file, etc.
void receive(VehicleMessage command)
void run()
void start()
void stop()
Clear the callback so no further updates are sent.
Protected Methods
abstract void connect()
Initiate a connection to the vehicle interface.
void connected()
Must have the connection lock before calling this function
abstract void disconnect()
Perform any cleanup necessary to disconnect from the interface.
void disconnected()
Must have the connection lock before calling this function
boolean isRunning()
Returns true if this source should be running, or if it should die.
abstract int read(byte[] bytes)
Read data from the source into the given array.
void setFastPolling(boolean enabled)
void stopConnectionAttempts()
void waitForConnection()
If not already connected to the data source, initiate the connection and block until ready to be read.
abstract boolean write(byte[] bytes)
[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

Constants

protected static final int RECONNECTION_ATTEMPT_WAIT_TIME_S

Constant Value: 10 (0x0000000a)

protected static final int SLOW_RECONNECTION_ATTEMPT_WAIT_TIME_S

Constant Value: 60 (0x0000003c)

Fields

protected final ReadWriteLock mConnectionLock

protected final Condition mDeviceChanged

Public Constructors

public BytestreamDataSource (SourceCallback callback, Context context)

Public Methods

public boolean isConnected ()

Return true if the data source is actively connected to its target, be it a USB endpoint, a Bluetooth channel, a trace file, etc. The source is capable of providing new vehicle data. Returns true if connected, false otherwise.

public void receive (VehicleMessage command)

public void run ()

public void start ()

public void stop ()

Clear the callback so no further updates are sent. Subclasses should be sure to call super.stop() so they also stop sending updates when killed by a user.

Protected Methods

protected abstract void connect ()

Initiate a connection to the vehicle interface.

protected void connected ()

Must have the connection lock before calling this function

protected abstract void disconnect ()

Perform any cleanup necessary to disconnect from the interface.

protected void disconnected ()

Must have the connection lock before calling this function

protected boolean isRunning ()

Returns true if this source should be running, or if it should die. This is different than isConnected - they just happen to return the same thing in this base data source.

protected abstract int read (byte[] bytes)

Read data from the source into the given array. No more than bytes.length bytes will be read, and there is no guarantee that any bytes will be read at all.

Parameters
bytes the destination array for bytes from the data source.
Returns
  • the number of bytes that were actually copied into bytes.
Throws
IOException if the source is unexpectedly closed or returns an error.

protected void setFastPolling (boolean enabled)

protected void stopConnectionAttempts ()

protected void waitForConnection ()

If not already connected to the data source, initiate the connection and block until ready to be read. You must have the mConnectionLock locked before calling this function.

Throws
InterruptedException if the interrupted while blocked -- probably shutting down.

protected abstract boolean write (byte[] bytes)