public class UsbVehicleInterface extends BytestreamDataSource implements VehicleInterface
UsbDeviceUtilities.
According to Android's USB device usage requirements, this class requests
permission for the USB device from the user before accessing it. This may
cause a pop-up dialog that the user must dismiss before the data source will
become active.| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ACTION_USB_DEVICE_ATTACHED |
static java.lang.String |
ACTION_USB_PERMISSION |
static java.lang.String |
BROADCAST_USB_DISCONNECTED |
mConnectionLock, mDataFormatValue, mDeviceChanged, RECONNECTION_ATTEMPT_WAIT_TIME_S, SLOW_RECONNECTION_ATTEMPT_WAIT_TIME_S| Constructor and Description |
|---|
UsbVehicleInterface(android.content.Context context) |
UsbVehicleInterface(android.content.Context context,
java.lang.String uriString) |
UsbVehicleInterface(SourceCallback callback,
android.content.Context context)
Construct an instance of UsbVehicleInterface with a receiver callback
and the default device URI.
|
UsbVehicleInterface(SourceCallback callback,
android.content.Context context,
java.net.URI deviceUri)
Construct an instance of UsbVehicleInterface with a receiver callback
and custom device URI.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
connect()
Initiate a connection to the vehicle interface.
|
static java.net.URI |
createUri(java.lang.String uriString) |
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.
|
protected void |
sendUSBDisconnectBroadcast() |
boolean |
setResource(java.lang.String otherUri)
Change the resource used by the instance to connect to the interface,
restarting any necessary services.
|
void |
start() |
void |
stop()
Unregister USB device intent broadcast receivers and stop waiting for a
connection.
|
java.lang.String |
toString() |
protected boolean |
write(byte[] bytes) |
connected, disconnected, isRunning, receive, run, setFastPolling, stopConnectionAttempts, waitForConnectiongetContextgetCallback, handleMessage, onPipelineActivated, onPipelineDeactivated, setCallback, waitForCallbackclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitsetCallbackonPipelineActivated, onPipelineDeactivatedreceivepublic static final java.lang.String BROADCAST_USB_DISCONNECTED
public static final java.lang.String ACTION_USB_PERMISSION
public static final java.lang.String ACTION_USB_DEVICE_ATTACHED
public UsbVehicleInterface(SourceCallback callback, android.content.Context context, java.net.URI deviceUri) throws DataSourceException
context - The Activity or Service context, used to get access to the
Android UsbManager.callback - An object implementing the
SourceCallback that should receive data as it is
received and parsed.deviceUri - a USB device URI (see UsbDeviceUtilities for the
format) to look for.DataSourceException - If the URI doesn't have the correct
formatpublic UsbVehicleInterface(SourceCallback callback, android.content.Context context) throws DataSourceException
UsbDeviceUtilities.context - The Activity or Service context, used to get access to the
Android UsbManager.callback - An object implementing the
SourceCallback that should receive data as it is
received and parsed.DataSourceException - in exceptional circumstances, i.e.
only if the default device URI is malformed.public UsbVehicleInterface(android.content.Context context)
throws DataSourceException
DataSourceExceptionpublic UsbVehicleInterface(android.content.Context context,
java.lang.String uriString)
throws DataSourceException
DataSourceExceptionpublic void start()
start in class BytestreamDataSourcepublic boolean isConnected()
VehicleDataSourceisConnected in interface VehicleInterfaceisConnected in interface VehicleDataSourceisConnected in class BytestreamDataSourcepublic void stop()
stop in interface VehicleDataSinkstop in interface VehicleDataSourcestop in class BytestreamDataSourcepublic boolean setResource(java.lang.String otherUri)
throws DataSourceException
VehicleInterfacesetResource in interface VehicleInterfaceotherUri - The new resource to use for the interface.DataSourceExceptionpublic java.lang.String toString()
toString in class java.lang.Objectprotected 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 java.lang.String getTag()
BaseVehicleDataSourcegetTag in class BaseVehicleDataSourceprotected boolean write(byte[] bytes)
write in class BytestreamDataSourceprotected void connect()
throws DataSourceException
BytestreamDataSourceconnect in class BytestreamDataSourceDataSourceExceptionprotected void disconnect()
BytestreamDataSourcedisconnect in class BytestreamDataSourcepublic static java.net.URI createUri(java.lang.String uriString)
throws DataSourceException
DataSourceExceptionprotected void sendUSBDisconnectBroadcast()