public class ModernRoboticsReaderWriter
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
COMM_ERROR_READ |
static java.lang.String |
COMM_ERROR_WRITE |
static java.lang.String |
COMM_FAILURE_READ |
static java.lang.String |
COMM_FAILURE_WRITE |
static java.lang.String |
COMM_PAYLOAD_ERROR_READ |
static java.lang.String |
COMM_PAYLOAD_ERROR_WRITE |
static java.lang.String |
COMM_SYNC_LOST |
static java.lang.String |
COMM_TIMEOUT_READ |
static java.lang.String |
COMM_TIMEOUT_WRITE |
static java.lang.String |
COMM_TYPE_ERROR_READ |
static java.lang.String |
COMM_TYPE_ERROR_WRITE |
static boolean |
DEBUG |
protected RobotUsbDevice |
device |
protected boolean |
isSynchronized |
static int |
MAX_SEQUENTIAL_USB_ERROR_COUNT |
static int |
MS_COMM_ERROR_WAIT |
static int |
MS_FAILURE_WAIT |
static int |
MS_GARBAGE_COLLECTION_SPURT
We run on a garbage collected system.
|
static int |
MS_INTER_BYTE_TIMEOUT
The timeouts defined by the MR USB spec are subtle.
|
static int |
MS_MAX_TIMEOUT |
static int |
MS_REQUEST_RESPONSE_TIMEOUT |
static int |
MS_RESYNCH_TIMEOUT
We made this up: we want to be very generous in trying to recover from failures as we
read through possibly-old data trying to synchronize, and there's little harm in doing so
|
static int |
MS_USB_HUB_LATENCY |
protected int |
msUsbReadRetryInterval |
protected int |
msUsbWriteRetryInterval |
protected ModernRoboticsDatagram.AllocationContext<ModernRoboticsRequest> |
requestAllocationContext |
protected ModernRoboticsDatagram.AllocationContext<ModernRoboticsResponse> |
responseAllocationContext |
protected Deadline |
responseDeadline |
static java.lang.String |
TAG |
protected int |
usbReadRetryCount |
protected int |
usbSequentialCommReadErrorCount |
protected int |
usbSequentialCommWriteErrorCount |
protected int |
usbWriteRetryCount |
Constructor and Description |
---|
ModernRoboticsReaderWriter(RobotUsbDevice device) |
Modifier and Type | Method and Description |
---|---|
protected static java.lang.String |
bufferToString(byte[] buffer) |
void |
close() |
protected void |
doExceptionBookkeeping() |
protected void |
logAndRethrowTimeout(RobotUsbTimeoutException e,
ModernRoboticsRequest request,
java.lang.String message) |
protected void |
logAndThrowProtocol(ModernRoboticsRequest request,
ModernRoboticsResponse response,
java.lang.String message) |
protected void |
logAndThrowProtocol(java.lang.String format,
java.lang.Object... args) |
void |
read(boolean retry,
int address,
byte[] buffer,
TimeWindow payloadTimeWindow) |
protected void |
readIncomingBytes(byte[] buffer,
int ibFirst,
int cbToRead,
int msExtraTimeout,
TimeWindow timeWindow,
java.lang.String debugContext) |
protected void |
readOnce(int address,
byte[] buffer,
TimeWindow payloadTimeWindow) |
protected ModernRoboticsResponse |
readResponse(ModernRoboticsRequest request,
TimeWindow payloadTimeWindow) |
protected byte |
readSingleByte(byte[] buffer,
int msExtraTimeout,
TimeWindow timeWindow,
java.lang.String debugContext) |
void |
throwIfTooManySequentialCommErrors() |
protected java.lang.String |
timeoutMessage(java.lang.String root,
RobotUsbTimeoutException e) |
void |
write(int address,
byte[] buffer) |
protected void |
writeOnce(int address,
byte[] buffer) |
public static final java.lang.String TAG
public static boolean DEBUG
public static int MS_INTER_BYTE_TIMEOUT
public static int MS_USB_HUB_LATENCY
public static int MS_REQUEST_RESPONSE_TIMEOUT
public static int MS_GARBAGE_COLLECTION_SPURT
public static int MS_RESYNCH_TIMEOUT
public static int MS_FAILURE_WAIT
public static int MS_COMM_ERROR_WAIT
public static int MS_MAX_TIMEOUT
public static int MAX_SEQUENTIAL_USB_ERROR_COUNT
public static final java.lang.String COMM_FAILURE_READ
public static final java.lang.String COMM_FAILURE_WRITE
public static final java.lang.String COMM_TIMEOUT_READ
public static final java.lang.String COMM_TIMEOUT_WRITE
public static final java.lang.String COMM_ERROR_READ
public static final java.lang.String COMM_ERROR_WRITE
public static final java.lang.String COMM_SYNC_LOST
public static final java.lang.String COMM_PAYLOAD_ERROR_READ
public static final java.lang.String COMM_PAYLOAD_ERROR_WRITE
public static final java.lang.String COMM_TYPE_ERROR_READ
public static final java.lang.String COMM_TYPE_ERROR_WRITE
protected final RobotUsbDevice device
protected int usbSequentialCommReadErrorCount
protected int usbSequentialCommWriteErrorCount
protected int usbReadRetryCount
protected int usbWriteRetryCount
protected int msUsbReadRetryInterval
protected int msUsbWriteRetryInterval
protected boolean isSynchronized
protected Deadline responseDeadline
protected ModernRoboticsDatagram.AllocationContext<ModernRoboticsRequest> requestAllocationContext
protected ModernRoboticsDatagram.AllocationContext<ModernRoboticsResponse> responseAllocationContext
public ModernRoboticsReaderWriter(RobotUsbDevice device)
public void throwIfTooManySequentialCommErrors() throws RobotUsbTooManySequentialErrorsException
RobotUsbTooManySequentialErrorsException
public void close()
public void read(boolean retry, int address, byte[] buffer, TimeWindow payloadTimeWindow) throws RobotUsbException, java.lang.InterruptedException
RobotUsbException
java.lang.InterruptedException
protected void readOnce(int address, byte[] buffer, TimeWindow payloadTimeWindow) throws RobotUsbException, java.lang.InterruptedException
RobotUsbException
java.lang.InterruptedException
public void write(int address, byte[] buffer) throws RobotUsbException, java.lang.InterruptedException
RobotUsbException
java.lang.InterruptedException
protected void writeOnce(int address, byte[] buffer) throws RobotUsbException, java.lang.InterruptedException
RobotUsbException
java.lang.InterruptedException
protected ModernRoboticsResponse readResponse(ModernRoboticsRequest request, TimeWindow payloadTimeWindow) throws RobotUsbException, java.lang.InterruptedException
RobotUsbException
java.lang.InterruptedException
protected void readIncomingBytes(byte[] buffer, int ibFirst, int cbToRead, int msExtraTimeout, TimeWindow timeWindow, java.lang.String debugContext) throws RobotUsbException, java.lang.InterruptedException
RobotUsbException
java.lang.InterruptedException
protected byte readSingleByte(byte[] buffer, int msExtraTimeout, TimeWindow timeWindow, java.lang.String debugContext) throws RobotUsbException, java.lang.InterruptedException
RobotUsbException
java.lang.InterruptedException
protected java.lang.String timeoutMessage(java.lang.String root, RobotUsbTimeoutException e)
protected void doExceptionBookkeeping()
protected void logAndRethrowTimeout(RobotUsbTimeoutException e, ModernRoboticsRequest request, java.lang.String message) throws RobotUsbTimeoutException
RobotUsbTimeoutException
protected void logAndThrowProtocol(java.lang.String format, java.lang.Object... args) throws RobotUsbProtocolException
RobotUsbProtocolException
protected void logAndThrowProtocol(ModernRoboticsRequest request, ModernRoboticsResponse response, java.lang.String message) throws RobotUsbProtocolException
RobotUsbProtocolException
protected static java.lang.String bufferToString(byte[] buffer)