public class ReadWriteRunnableStandard extends java.lang.Object implements ReadWriteRunnable
Note that this implementation is specific to Modern Robotics, as it has knowledge of the Modern Robotics datagram formats, etc.
ReadWriteRunnable.BlockingState, ReadWriteRunnable.Callback, ReadWriteRunnable.EmptyCallback| Modifier and Type | Field and Description |
|---|---|
protected boolean |
acceptingWrites |
protected java.lang.Object |
acceptingWritesLock |
protected byte[] |
activeBuffer |
protected TimeWindow |
activeBufferTimeWindow |
protected ReadWriteRunnable.Callback |
callback |
protected Context |
context |
protected static boolean |
DEBUG_SEGMENTS |
protected boolean |
debugLogging |
protected boolean |
fullWriteNeeded |
protected int |
ibActiveFirst |
protected byte[] |
localDeviceReadCache |
protected byte[] |
localDeviceWriteCache |
protected int |
monitorLength |
protected RobotUsbModule |
owner |
protected boolean |
pruneBufferAfterRead |
protected java.lang.Object |
readSupressionLock |
protected RobotUsbDevice |
robotUsbDevice |
protected boolean |
running |
protected java.util.concurrent.CountDownLatch |
runningInterlock |
protected java.util.concurrent.ConcurrentLinkedQueue<java.lang.Integer> |
segmentReadQueue |
protected java.util.Map<java.lang.Integer,ReadWriteRunnableSegment> |
segments |
protected java.util.concurrent.ConcurrentLinkedQueue<java.lang.Integer> |
segmentWriteQueue |
protected SerialNumber |
serialNumber |
protected boolean |
shutdownComplete |
protected ShutdownReason |
shutdownReason |
protected int |
startAddress |
protected boolean |
suppressReads |
static java.lang.String |
TAG |
protected ModernRoboticsReaderWriter |
usbHandler |
MAX_BUFFER_SIZE| Constructor and Description |
|---|
ReadWriteRunnableStandard(Context context,
SerialNumber serialNumber,
RobotUsbDevice device,
int monitorLength,
int startAddress,
boolean debug)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
awaitRunning() |
void |
close()
Close this read-write-runnable
|
ReadWriteRunnableSegment |
createSegment(int key,
int address,
int size) |
void |
destroySegment(int key) |
protected void |
doReadCycle() |
protected void |
doWriteCycle() |
void |
drainPendingWrites() |
protected void |
dumpBuffers(java.lang.String name,
byte[] byteArray) |
void |
executeUsing(java.util.concurrent.ExecutorService service) |
boolean |
getAcceptingWrites() |
RobotUsbModule |
getOwner() |
ReadWriteRunnableSegment |
getSegment(int key) |
ShutdownReason |
getShutdownReason() |
protected boolean |
isFullActive() |
protected void |
queueIfNotAlreadyQueued(int key,
java.util.concurrent.ConcurrentLinkedQueue<java.lang.Integer> queue) |
void |
queueSegmentRead(int key) |
void |
queueSegmentWrite(int key) |
byte[] |
read(int address,
int size)
Read from device
|
byte[] |
readFromWriteCache(int address,
int size)
Read from the device write cache
|
void |
resetWriteNeeded() |
void |
run()
Main read / write loop
|
void |
setAcceptingWrites(boolean acceptingWrites) |
void |
setCallback(ReadWriteRunnable.Callback callback) |
protected void |
setFullActive() |
void |
setOwner(RobotUsbModule owner) |
protected void |
setSuffixActive() |
void |
suppressReads(boolean suppress) |
void |
write(int address,
byte[] data)
Write to device
|
boolean |
writeNeeded() |
public static final java.lang.String TAG
protected final byte[] localDeviceReadCache
protected final byte[] localDeviceWriteCache
protected java.util.Map<java.lang.Integer,ReadWriteRunnableSegment> segments
protected java.util.concurrent.ConcurrentLinkedQueue<java.lang.Integer> segmentReadQueue
protected java.util.concurrent.ConcurrentLinkedQueue<java.lang.Integer> segmentWriteQueue
protected final Context context
protected final SerialNumber serialNumber
protected RobotUsbDevice robotUsbDevice
protected ModernRoboticsReaderWriter usbHandler
protected int startAddress
protected int monitorLength
protected boolean pruneBufferAfterRead
protected volatile boolean fullWriteNeeded
protected int ibActiveFirst
protected byte[] activeBuffer
protected TimeWindow activeBufferTimeWindow
protected java.util.concurrent.CountDownLatch runningInterlock
protected volatile boolean running
protected volatile ShutdownReason shutdownReason
protected volatile boolean shutdownComplete
protected final java.lang.Object acceptingWritesLock
protected volatile boolean acceptingWrites
protected volatile boolean suppressReads
protected final java.lang.Object readSupressionLock
protected ReadWriteRunnable.Callback callback
protected RobotUsbModule owner
protected final boolean debugLogging
protected static boolean DEBUG_SEGMENTS
public ReadWriteRunnableStandard(Context context,
SerialNumber serialNumber,
RobotUsbDevice device,
int monitorLength,
int startAddress,
boolean debug)
serialNumber - USB serial numberdevice - FTDI devicemonitorLength - length of memory map to continually monitorstartAddress - starting address of changing buffer values.public void setCallback(ReadWriteRunnable.Callback callback)
setCallback in interface ReadWriteRunnablepublic void setOwner(RobotUsbModule owner)
public RobotUsbModule getOwner()
public boolean writeNeeded()
writeNeeded in interface ReadWriteRunnablepublic void resetWriteNeeded()
resetWriteNeeded in interface ReadWriteRunnablepublic void write(int address,
byte[] data)
write in interface ReadWriteRunnableaddress - address to writedata - data to writepublic void suppressReads(boolean suppress)
suppressReads in interface ReadWriteRunnablepublic byte[] readFromWriteCache(int address,
int size)
readFromWriteCache in interface ReadWriteRunnableaddress - address of byte to readsize - number of bytes to readpublic byte[] read(int address,
int size)
read in interface ReadWriteRunnableaddress - address to readsize - number of bytes to readpublic void executeUsing(java.util.concurrent.ExecutorService service)
executeUsing in interface ReadWriteRunnablepublic void close()
close in interface ReadWriteRunnablepublic ReadWriteRunnableSegment createSegment(int key, int address, int size)
createSegment in interface ReadWriteRunnablepublic void destroySegment(int key)
destroySegment in interface ReadWriteRunnablepublic ReadWriteRunnableSegment getSegment(int key)
getSegment in interface ReadWriteRunnablepublic void queueSegmentRead(int key)
queueSegmentRead in interface ReadWriteRunnablepublic void queueSegmentWrite(int key)
queueSegmentWrite in interface ReadWriteRunnableprotected void awaitRunning()
protected void setFullActive()
protected boolean isFullActive()
protected void setSuffixActive()
public void run()
run in interface ReadWriteRunnablerun in interface java.lang.Runnableprotected void doReadCycle()
throws java.lang.InterruptedException,
RobotUsbException
java.lang.InterruptedExceptionRobotUsbExceptionprotected void doWriteCycle()
throws java.lang.InterruptedException,
RobotUsbException
java.lang.InterruptedExceptionRobotUsbExceptionpublic ShutdownReason getShutdownReason()
public void drainPendingWrites()
drainPendingWrites in interface ReadWriteRunnablepublic void setAcceptingWrites(boolean acceptingWrites)
setAcceptingWrites in interface ReadWriteRunnablepublic boolean getAcceptingWrites()
getAcceptingWrites in interface ReadWriteRunnableprotected void dumpBuffers(java.lang.String name,
byte[] byteArray)
protected void queueIfNotAlreadyQueued(int key,
java.util.concurrent.ConcurrentLinkedQueue<java.lang.Integer> queue)