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, waitForConnectiongetContextgetCallback, handleMessage, onPipelineActivated, onPipelineDeactivated, setCallback, waitForCallbackclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitsetCallbackonPipelineActivated, onPipelineDeactivatedreceivepublic static final java.lang.String DEVICE_NAME_PREFIX
public BluetoothVehicleInterface(SourceCallback callback, android.content.Context context, java.lang.String address) throws DataSourceException
DataSourceExceptionpublic BluetoothVehicleInterface(android.content.Context context,
java.lang.String address)
throws DataSourceException
DataSourceExceptionpublic 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
VehicleInterfacesetResource in interface VehicleInterfaceotherAddress - The new resource to use for the interface.DataSourceExceptionpublic boolean isConnected()
VehicleDataSourceisConnected in interface VehicleInterfaceisConnected in interface VehicleDataSourceisConnected in class BytestreamDataSourcepublic void stop()
BaseVehicleDataSourcestop in interface VehicleDataSinkstop in interface VehicleDataSourcestop in class BytestreamDataSourcepublic java.lang.String toString()
toString in class java.lang.Objectprotected void connect()
BytestreamDataSourceconnect in class BytestreamDataSourceprotected int read(byte[] bytes)
throws java.io.IOException
BytestreamDataSourceread in class BytestreamDataSourcebytes - 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 BytestreamDataSourceprotected void disconnect()
BytestreamDataSourcedisconnect in class BytestreamDataSourceprotected java.lang.String getTag()
BaseVehicleDataSourcegetTag in class BaseVehicleDataSource