Class UsbCloverManager<T>
java.lang.Object
com.clover.remote.client.transport.usb.UsbCloverManager<T>
- Direct Known Subclasses:
RemoteUsbManager,UsbAccessorySetupUsbManager
This class is designed to be a reusable USB communication manager for devices that bulk transfer data.
Instances of this class should be singletons.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumstatic classstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intprotected static final intprotected android.hardware.usb.UsbDeviceConnectionprotected static final intprotected static final intprotected static final intprotected static final booleanprotected static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidstatic android.hardware.usb.UsbDevicefindDevice(android.hardware.usb.UsbManager usbManager, android.util.Pair<Integer, Integer>[] vendorProductIds) protected abstract intprotected abstract intprotected intReturns the amount of time to wait before read fails, 0 means wait forever.protected booleanfinal booleanprotected booleanisInterfaceMatch(android.hardware.usb.UsbInterface usbInterface) static booleanisMatch(android.hardware.usb.UsbDevice device, android.util.Pair<Integer, Integer>[] vendorProductIds) protected voidCalled after disconnect is complete, does nothing by default and may be overridden.protected voidCalled before a connection is attempted, does nothing by default and may be overridden.protected voidCalled when a transfer error occurs, does nothing by default and may be overridden.voidopen()Open a connection to the USB device and begin a session.protected final com.clover.remote.client.transport.usb.UsbCloverManager.DeviceStatuspostStatusChange(com.clover.remote.client.transport.usb.UsbCloverManager.DeviceStatus status) protected UsbCloverManager.InputResultprocessInputData(byte[] inputData, ByteArrayOutputStream outputStream, T params) Optionally override this method to perform data processing on the input data bytes before they are returned.protected byte[]processOutputData(byte[] outputData, T params) Optionally override this method to perform data processing on the output bytes before they are sent.byte[]protected byte[]unwrapReadPacket(ByteBuffer inDataBuffer) protected byte[]wrapWritePacket(ByteBuffer outDataBuffer, int numBytesToTransfer) int
-
Field Details
-
VERBOSE
protected static final boolean VERBOSE- See Also:
-
CONNECTION_TIMEOUT_MS
protected static final int CONNECTION_TIMEOUT_MS- See Also:
-
CONNECTION_RETRY_WAIT_MS
protected static final int CONNECTION_RETRY_WAIT_MS- See Also:
-
SETUP_TIMEOUT_MS
protected static final int SETUP_TIMEOUT_MS- See Also:
-
SETUP_RETRY_WAIT_MS
protected static final int SETUP_RETRY_WAIT_MS- See Also:
-
READ_TIMEOUT_MS
protected static final int READ_TIMEOUT_MS- See Also:
-
WRITE_TIMEOUT_MS
protected static final int WRITE_TIMEOUT_MS- See Also:
-
mConnection
protected android.hardware.usb.UsbDeviceConnection mConnection
-
-
Constructor Details
-
UsbCloverManager
public UsbCloverManager(android.content.Context context)
-
-
Method Details
-
open
Open a connection to the USB device and begin a session. Only one session may be opened at a time.- Throws:
UsbCloverManager.UsbConnectException- if connecting to the device failed
-
getReadSize
protected abstract int getReadSize() -
getMaxWriteDataSize
protected abstract int getMaxWriteDataSize() -
onPreConnect
protected void onPreConnect()Called before a connection is attempted, does nothing by default and may be overridden. -
findDevice
-
getVendorProductIds
-
isMatch
-
isBulkInterface
protected boolean isBulkInterface() -
isInterfaceMatch
protected boolean isInterfaceMatch(android.hardware.usb.UsbInterface usbInterface) -
disconnect
public void disconnect() -
onPostDisconnect
protected void onPostDisconnect()Called after disconnect is complete, does nothing by default and may be overridden. -
isConnected
public final boolean isConnected() -
write
- Throws:
IOExceptionInterruptedException
-
read
- Throws:
IOExceptionInterruptedException
-
onTransferError
protected void onTransferError()Called when a transfer error occurs, does nothing by default and may be overridden. -
wrapWritePacket
-
unwrapReadPacket
-
getReadTimeOut
protected int getReadTimeOut()Returns the amount of time to wait before read fails, 0 means wait forever. -
processOutputData
Optionally override this method to perform data processing on the output bytes before they are sent. The returned byte array is used for the data transfer, the implementation may choose to modify the byte array parameter or return a new byte array. -
processInputData
protected UsbCloverManager.InputResult processInputData(byte[] inputData, ByteArrayOutputStream outputStream, T params) Optionally override this method to perform data processing on the input data bytes before they are returned. The implementation must write the desired output bytes to the ByteArrayOutputStream. UnlikeprocessOutputData(byte[], T)this function may be called multiple times in a single transfer depending on the return value of this function- Parameters:
inputData- buffer containing bytes read from the USB deviceoutputStream- stream containing bytes that will be returned to the callerparams- additional parameters which may allow the implementation to modify the way the byte array is interpreted- Returns:
- CONTINUE to request more USB device data, COMPLETE to return the received data or ERROR if something is wrong
-
postStatusChange
protected final com.clover.remote.client.transport.usb.UsbCloverManager.DeviceStatus postStatusChange(com.clover.remote.client.transport.usb.UsbCloverManager.DeviceStatus status)
-