public class BluetoothVehicleInterface extends BytestreamDataSource implements VehicleInterface
This class tries to connect to a previously paired Bluetooth device with a given MAC address. If found, it opens a socket to the device and streams both read and write OpenXC messages.
This class requires both the android.permission.BLUETOOTH and android.permission.BLUETOOTH_ADMIN permissions.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEVICE_NAME_PREFIX |
mConnectionLock, mDataFormatValue, mDeviceChanged, RECONNECTION_ATTEMPT_WAIT_TIME_S, SLOW_RECONNECTION_ATTEMPT_WAIT_TIME_S
Constructor and Description |
---|
BluetoothVehicleInterface(android.content.Context context,
java.lang.String address) |
BluetoothVehicleInterface(SourceCallback callback,
android.content.Context context,
java.lang.String address) |
Modifier and Type | Method and Description |
---|---|
protected void |
connect()
Initiate a connection to the vehicle interface.
|
protected void |
disconnect()
Perform any cleanup necessary to disconnect from the interface.
|
protected java.lang.String |
getTag()
Return a string suitable as a tag for logging.
|
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.
|
protected int |
read(byte[] bytes)
Read data from the source into the given array.
|
void |
setPollingStatus(boolean enabled)
Control whether periodic polling is used to detect a Bluetooth VI.
|
boolean |
setResource(java.lang.String otherAddress)
Change the resource used by the instance to connect to the interface,
restarting any necessary services.
|
void |
stop()
Clear the callback so no further updates are sent.
|
java.lang.String |
toString() |
protected boolean |
write(byte[] bytes) |
connected, disconnected, isRunning, receive, run, setFastPolling, start, stopConnectionAttempts, waitForConnection
getContext
getCallback, handleMessage, onPipelineActivated, onPipelineDeactivated, setCallback, waitForCallback
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
setCallback
onPipelineActivated, onPipelineDeactivated
receive
public static final java.lang.String DEVICE_NAME_PREFIX
public BluetoothVehicleInterface(SourceCallback callback, android.content.Context context, java.lang.String address) throws DataSourceException
DataSourceException
public BluetoothVehicleInterface(android.content.Context context, java.lang.String address) throws DataSourceException
DataSourceException
public void setPollingStatus(boolean enabled)
This class opens a Bluetooth socket and will accept incoming connections from a VI that can act as the Bluetooth master. For VIs that are only able to act as slave, we have to poll for a connection occasionally to see if it's within range.
public boolean setResource(java.lang.String otherAddress) throws DataSourceException
VehicleInterface
setResource
in interface VehicleInterface
otherAddress
- The new resource to use for the interface.DataSourceException
public boolean isConnected()
VehicleDataSource
isConnected
in interface VehicleInterface
isConnected
in interface VehicleDataSource
isConnected
in class BytestreamDataSource
public void stop()
BaseVehicleDataSource
stop
in interface VehicleDataSink
stop
in interface VehicleDataSource
stop
in class BytestreamDataSource
public java.lang.String toString()
toString
in class java.lang.Object
protected void connect()
BytestreamDataSource
connect
in class BytestreamDataSource
protected int read(byte[] bytes) throws java.io.IOException
BytestreamDataSource
read
in class BytestreamDataSource
bytes
- the destination array for bytes from the data source.java.io.IOException
- if the source is unexpectedly closed or returns an
error.protected boolean write(byte[] bytes)
write
in class BytestreamDataSource
protected void disconnect()
BytestreamDataSource
disconnect
in class BytestreamDataSource
protected java.lang.String getTag()
BaseVehicleDataSource
getTag
in class BaseVehicleDataSource