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, 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 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
DataSourceException
public UsbVehicleInterface(android.content.Context context, java.lang.String uriString) throws DataSourceException
DataSourceException
public void start()
start
in class BytestreamDataSource
public boolean isConnected()
VehicleDataSource
isConnected
in interface VehicleInterface
isConnected
in interface VehicleDataSource
isConnected
in class BytestreamDataSource
public void stop()
stop
in interface VehicleDataSink
stop
in interface VehicleDataSource
stop
in class BytestreamDataSource
public boolean setResource(java.lang.String otherUri) throws DataSourceException
VehicleInterface
setResource
in interface VehicleInterface
otherUri
- The new resource to use for the interface.DataSourceException
public java.lang.String toString()
toString
in class java.lang.Object
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 java.lang.String getTag()
BaseVehicleDataSource
getTag
in class BaseVehicleDataSource
protected boolean write(byte[] bytes)
write
in class BytestreamDataSource
protected void connect() throws DataSourceException
BytestreamDataSource
connect
in class BytestreamDataSource
DataSourceException
protected void disconnect()
BytestreamDataSource
disconnect
in class BytestreamDataSource
public static java.net.URI createUri(java.lang.String uriString) throws DataSourceException
DataSourceException
protected void sendUSBDisconnectBroadcast()