public class LynxModule extends LynxCommExceptionHandler implements LynxModuleIntf
LynxModule
represents the connection between the host and a particular
Lynx controller module. Multiple Lynx controller modules may be chained together over RS-485
and share a common USB connection.LynxUsbDeviceImpl
Modifier and Type | Class and Description |
---|---|
static interface |
LynxModule.BlinkerPolicy
LynxModule.BlinkerPolicy embodies the various blinker patterns exhibited by LynxModule s
The policy can be changed, globally, by setting the variable blinkerPolicy . |
static class |
LynxModule.BreathingBlinkerPolicy |
static class |
LynxModule.BulkCachingMode
Bulk caching mode that controls the behavior of certain read commands.
|
static class |
LynxModule.BulkData
Container for the values retrieved with a bulk read.
|
static class |
LynxModule.CountModuleAddressBlinkerPolicy |
static class |
LynxModule.DebugGroup |
static class |
LynxModule.DebugVerbosity |
protected static class |
LynxModule.MessageClassAndCtor
A
Class for one of the Lynx messages together with a cached constructor thereto |
Modifier and Type | Field and Description |
---|---|
protected java.util.concurrent.Future<?> |
attentionRequiredFuture |
static LynxModule.BlinkerPolicy |
blinkerPolicy |
protected java.util.Map<java.lang.String,java.util.List<LynxDekaInterfaceCommand<?>>> |
bulkCachingHistory |
protected java.lang.Object |
bulkCachingLock |
protected LynxModule.BulkCachingMode |
bulkCachingMode |
protected java.util.concurrent.ConcurrentHashMap<java.lang.Integer,LynxModule.MessageClassAndCtor> |
commandClasses
for all the commands we know about (standard + QueryInterface), maps command number to
class which implements same.
|
protected java.util.List<LynxController> |
controllers |
protected java.util.ArrayList<Step> |
currentSteps
State for maintaining stack of blinker patterns
|
protected java.lang.Object |
engagementLock |
protected java.util.concurrent.ScheduledExecutorService |
executor |
protected boolean |
ftdiResetWatchdogActive |
protected boolean |
ftdiResetWatchdogActiveWhenEngaged |
protected java.lang.Object |
futureLock |
protected java.lang.Object |
i2cLock
This lock prevents concurrency problems that would arrive from
interleaving messages of the (asynchronous) i2c protocol.
|
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,LynxInterface> |
interfacesQueried |
protected boolean |
isEngaged |
protected boolean |
isNotResponding |
protected boolean |
isOpen |
protected boolean |
isParent |
protected boolean |
isSystemSynthetic |
protected boolean |
isUserModule |
protected boolean |
isVisuallyIdentifying |
protected LynxModule.BulkData |
lastBulkData |
protected LynxUsbDevice |
lynxUsbDevice |
protected int |
moduleAddress |
protected SerialNumber |
moduleSerialNumber |
protected static int |
msInitialContact |
protected static int |
msKeepAliveTimeout |
protected java.util.concurrent.atomic.AtomicInteger |
nextMessageNumber |
protected java.util.concurrent.Future<?> |
pingFuture |
protected java.util.Deque<java.util.ArrayList<Step>> |
previousSteps |
protected static java.util.Map<java.lang.Class<? extends LynxCommand>,LynxModule.MessageClassAndCtor> |
responseClasses |
protected static java.util.Map<java.lang.Integer,LynxModule.MessageClassAndCtor> |
standardMessages |
protected java.lang.Object |
startStopLock |
protected java.util.Set<java.lang.Class<? extends LynxCommand>> |
supportedCommands |
static java.lang.String |
TAG |
protected java.util.concurrent.ConcurrentHashMap<java.lang.Integer,LynxRespondable> |
unfinishedCommands
maps message number to command we've issued with said number
|
tag
Constructor and Description |
---|
LynxModule(LynxUsbDevice lynxUsbDevice,
int moduleAddress,
boolean isParent,
boolean isUserModule) |
Modifier and Type | Method and Description |
---|---|
void |
abandonUnfinishedCommands() |
<T> T |
acquireI2cLockWhile(Supplier<T> supplier) |
void |
acquireNetworkTransmissionLock(LynxMessage message) |
protected static void |
addStandardMessage(java.lang.Class<? extends LynxMessage> clazz) |
void |
clearBulkCache()
Clears the bulk read cache.
|
void |
close() |
static void |
correlateResponse(java.lang.Class<? extends LynxCommand> commandClass,
java.lang.Class<? extends LynxResponse> responseClass) |
protected static void |
correlateStandardResponse(java.lang.Class<? extends LynxCommand> commandClass) |
void |
disengage() |
void |
enablePhoneCharging(boolean enable) |
void |
engage() |
void |
failSafe() |
void |
finishedWithMessage(LynxMessage message) |
protected void |
forgetLastKnown() |
ARMINGSTATE |
getArmingState() |
double |
getAuxiliaryVoltage(VoltageUnit unit)
Returns the auxiliary (5V) voltage.
|
int |
getBlinkerPatternMaxLength() |
LynxModule.BulkCachingMode |
getBulkCachingMode()
Returns the current bulk caching mode.
|
LynxModule.BulkData |
getBulkData()
Gets the bulk data for this module and clears the cache.
|
java.lang.String |
getConnectionInfo() |
double |
getCurrent(CurrentUnit unit)
Returns the current consumption of the whole module.
|
java.lang.String |
getDeviceName() |
java.lang.String |
getFirmwareVersionString() |
java.util.List<java.lang.String> |
getGlobalWarnings()
Returns any global warnings from this device.
|
double |
getGpioBusCurrent(CurrentUnit unit)
Returns the current consumption of the GPIO bus.
|
static java.lang.String |
getHealthStatusWarningMessage(HardwareDeviceHealth hardwareDeviceHealth)
Returns a status warning message indicative of the health of the indicated device, or an
empty string if no such message is currently applicable.
|
double |
getI2cBusCurrent(CurrentUnit unit)
Returns the current consumption of the I2C bus.
|
double |
getInputVoltage(VoltageUnit unit)
Returns the input (battery) voltage.
|
LynxInterface |
getInterface(java.lang.String interfaceName)
Returns null if the interface has not been queried or is not supported
|
Manufacturer |
getManufacturer() |
int |
getModuleAddress() |
SerialNumber |
getModuleSerialNumber() |
protected int |
getMsModulePingInterval() |
protected byte |
getNewMessageNumber() |
java.lang.String |
getNullableFirmwareVersionString() |
java.util.Collection<Step> |
getPattern() |
SerialNumber |
getSerialNumber() |
protected java.lang.String |
getTag() |
double |
getTemperature(TempUnit unit)
Returns the module temperature.
|
int |
getVersion() |
protected void |
initializeDebugLogging() |
protected void |
initializeLEDS() |
protected void |
internalPushPattern(java.util.Collection<Step> steps) |
boolean |
isCommandSupported(java.lang.Class<? extends LynxCommand> clazz)
Answers as to whether the command is actively supported by the module, at least in SOME
interface, or as a standard command
|
boolean |
isEngaged() |
boolean |
isNotResponding() |
boolean |
isOpen() |
boolean |
isParent() |
boolean |
isPhoneChargingEnabled() |
boolean |
isSystemSynthetic() |
boolean |
isUserModule() |
protected void |
nackUnfinishedCommands() |
void |
noteAttentionRequired() |
void |
noteController(LynxController controller) |
void |
noteDatagramReceived() |
void |
noteNotResponding() |
void |
onIncomingDatagramReceived(LynxDatagram datagram) |
void |
onModuleStateChange(RobotArmingStateNotifier module,
ARMINGSTATE state) |
boolean |
patternStackNotEmpty() |
protected void |
ping() |
protected void |
ping(boolean initialPing) |
void |
pingAndQueryKnownInterfacesAndEtc()
Do all the stuff we need to do when we've become aware that this module is in fact
attached to its USB device.
|
protected void |
pingInitialContact() |
boolean |
popPattern() |
void |
pretendFinishExtantCommands() |
void |
pushPattern(java.util.Collection<Step> steps) |
protected boolean |
queryInterface(LynxInterface theInterface)
Issues a query interface for the indicated interface and processes the results.
|
void |
registerCallback(Callback callback,
boolean doInitialCallback) |
void |
releaseNetworkTransmissionLock(LynxMessage message) |
protected void |
resendCurrentPattern() |
void |
resetDeviceConfigurationForOpMode() |
void |
resetPingTimer(LynxMessage message) |
void |
retransmit(LynxMessage message) |
void |
sendCommand(LynxMessage command)
Sends a command to the module, scheduling retransmissions as necessary.
|
protected void |
sendGetModuleStatusAndProcessResponse(boolean clearStatus) |
void |
setBulkCachingMode(LynxModule.BulkCachingMode mode)
Sets the bulk caching mode.
|
void |
setConstant(int color) |
void |
setDebug(LynxModule.DebugGroup group,
LynxModule.DebugVerbosity verbosity) |
protected void |
setFtdiResetWatchdog(boolean enabled) |
void |
setNewModuleAddress(int newModuleAddress) |
void |
setPattern(java.util.Collection<Step> steps) |
void |
setSystemSynthetic(boolean systemSynthetic) |
void |
setUserModule(boolean isUserModule) |
protected void |
startExecutor() |
protected void |
startFtdiResetWatchdog() |
protected void |
startPingTimer() |
protected void |
stopAttentionRequired() |
void |
stopBlinking() |
protected void |
stopExecutor() |
protected void |
stopFtdiResetWatchdog() |
protected void |
stopFtdiResetWatchdog(boolean disengaging) |
protected void |
stopPingTimer(boolean wait) |
java.lang.String |
toString() |
void |
unregisterCallback(Callback callback) |
void |
validateCommand(LynxMessage lynxMessage) |
void |
visuallyIdentify(boolean shouldIdentify) |
handleException, handleSpecificException, handleSpecificException
public static final java.lang.String TAG
public static LynxModule.BlinkerPolicy blinkerPolicy
protected static final int msInitialContact
protected static final int msKeepAliveTimeout
protected static java.util.Map<java.lang.Integer,LynxModule.MessageClassAndCtor> standardMessages
protected static java.util.Map<java.lang.Class<? extends LynxCommand>,LynxModule.MessageClassAndCtor> responseClasses
protected LynxUsbDevice lynxUsbDevice
protected java.util.List<LynxController> controllers
protected int moduleAddress
protected SerialNumber moduleSerialNumber
protected java.util.concurrent.atomic.AtomicInteger nextMessageNumber
protected boolean isParent
protected volatile boolean isSystemSynthetic
protected volatile boolean isUserModule
protected boolean isEngaged
protected final java.lang.Object engagementLock
protected volatile boolean isOpen
protected volatile boolean isNotResponding
protected final java.lang.Object startStopLock
protected final java.util.concurrent.ConcurrentHashMap<java.lang.Integer,LynxRespondable> unfinishedCommands
protected final java.util.concurrent.ConcurrentHashMap<java.lang.Integer,LynxModule.MessageClassAndCtor> commandClasses
protected final java.util.Set<java.lang.Class<? extends LynxCommand>> supportedCommands
protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,LynxInterface> interfacesQueried
protected final java.lang.Object i2cLock
protected java.util.ArrayList<Step> currentSteps
protected java.util.Deque<java.util.ArrayList<Step>> previousSteps
protected boolean isVisuallyIdentifying
protected java.util.concurrent.ScheduledExecutorService executor
protected java.util.concurrent.Future<?> pingFuture
protected java.util.concurrent.Future<?> attentionRequiredFuture
protected final java.lang.Object futureLock
protected boolean ftdiResetWatchdogActive
protected boolean ftdiResetWatchdogActiveWhenEngaged
protected final java.lang.Object bulkCachingLock
protected LynxModule.BulkCachingMode bulkCachingMode
protected java.util.Map<java.lang.String,java.util.List<LynxDekaInterfaceCommand<?>>> bulkCachingHistory
protected LynxModule.BulkData lastBulkData
public LynxModule(LynxUsbDevice lynxUsbDevice, int moduleAddress, boolean isParent, boolean isUserModule)
protected java.lang.String getTag()
getTag
in class LynxCommExceptionHandler
protected static void addStandardMessage(java.lang.Class<? extends LynxMessage> clazz)
protected static void correlateStandardResponse(java.lang.Class<? extends LynxCommand> commandClass)
public static void correlateResponse(java.lang.Class<? extends LynxCommand> commandClass, java.lang.Class<? extends LynxResponse> responseClass) throws java.lang.NoSuchMethodException
java.lang.NoSuchMethodException
public java.lang.String toString()
toString
in class java.lang.Object
public void close()
public boolean isOpen()
isOpen
in interface LynxModuleIntf
public boolean isUserModule()
public void setUserModule(boolean isUserModule)
public boolean isSystemSynthetic()
public void setSystemSynthetic(boolean systemSynthetic)
public void noteController(LynxController controller)
public int getModuleAddress()
public void setNewModuleAddress(int newModuleAddress)
protected byte getNewMessageNumber()
public void noteAttentionRequired()
noteAttentionRequired
in interface LynxModuleIntf
public void noteDatagramReceived()
noteDatagramReceived
in interface LynxModuleIntf
public void noteNotResponding()
noteNotResponding
in interface LynxModuleIntf
public boolean isNotResponding()
isNotResponding
in interface LynxModuleIntf
protected void stopAttentionRequired()
protected void sendGetModuleStatusAndProcessResponse(boolean clearStatus)
protected void forgetLastKnown()
public Manufacturer getManufacturer()
public java.lang.String getDeviceName()
public java.lang.String getFirmwareVersionString()
public java.lang.String getNullableFirmwareVersionString()
public java.lang.String getConnectionInfo()
public int getVersion()
public void resetDeviceConfigurationForOpMode()
public java.util.List<java.lang.String> getGlobalWarnings()
public static java.lang.String getHealthStatusWarningMessage(HardwareDeviceHealth hardwareDeviceHealth)
public SerialNumber getModuleSerialNumber()
public SerialNumber getSerialNumber()
public ARMINGSTATE getArmingState()
public void registerCallback(Callback callback, boolean doInitialCallback)
public void unregisterCallback(Callback callback)
public void onModuleStateChange(RobotArmingStateNotifier module, ARMINGSTATE state)
public void engage()
public void disengage()
public boolean isEngaged()
public void visuallyIdentify(boolean shouldIdentify)
public int getBlinkerPatternMaxLength()
public void setConstant(int color)
public void stopBlinking()
public void setPattern(java.util.Collection<Step> steps)
public java.util.Collection<Step> getPattern()
protected void resendCurrentPattern()
public void pushPattern(java.util.Collection<Step> steps)
protected void internalPushPattern(java.util.Collection<Step> steps)
public boolean patternStackNotEmpty()
public boolean popPattern()
public boolean isParent()
public void pingAndQueryKnownInterfacesAndEtc() throws RobotCoreException, java.lang.InterruptedException
RobotCoreException
java.lang.InterruptedException
protected void initializeLEDS()
protected void initializeDebugLogging() throws RobotCoreException, java.lang.InterruptedException
RobotCoreException
java.lang.InterruptedException
protected void pingInitialContact() throws RobotCoreException, java.lang.InterruptedException
RobotCoreException
java.lang.InterruptedException
public void validateCommand(LynxMessage lynxMessage) throws LynxUnsupportedCommandException
validateCommand
in interface LynxModuleIntf
LynxUnsupportedCommandException
public boolean isCommandSupported(java.lang.Class<? extends LynxCommand> clazz)
isCommandSupported
in interface LynxModuleIntf
protected boolean queryInterface(LynxInterface theInterface) throws java.lang.InterruptedException
java.lang.InterruptedException
public LynxInterface getInterface(java.lang.String interfaceName)
getInterface
in interface LynxModuleIntf
protected void ping()
protected void ping(boolean initialPing) throws RobotCoreException, java.lang.InterruptedException, LynxNackException
RobotCoreException
java.lang.InterruptedException
LynxNackException
protected int getMsModulePingInterval()
public void resetPingTimer(LynxMessage message)
resetPingTimer
in interface LynxModuleIntf
protected void startPingTimer()
protected void stopPingTimer(boolean wait)
protected void startFtdiResetWatchdog()
protected void stopFtdiResetWatchdog()
protected void stopFtdiResetWatchdog(boolean disengaging)
protected void setFtdiResetWatchdog(boolean enabled)
protected void startExecutor()
protected void stopExecutor()
public LynxModule.BulkData getBulkData()
getBulkCachingMode()
public LynxModule.BulkCachingMode getBulkCachingMode()
public void setBulkCachingMode(LynxModule.BulkCachingMode mode)
mode
- new bulk caching modepublic void clearBulkCache()
public void failSafe() throws RobotCoreException, java.lang.InterruptedException, LynxNackException
RobotCoreException
java.lang.InterruptedException
LynxNackException
public void enablePhoneCharging(boolean enable) throws RobotCoreException, java.lang.InterruptedException, LynxNackException
RobotCoreException
java.lang.InterruptedException
LynxNackException
public boolean isPhoneChargingEnabled() throws RobotCoreException, java.lang.InterruptedException, LynxNackException
RobotCoreException
java.lang.InterruptedException
LynxNackException
public double getCurrent(CurrentUnit unit)
unit
- current unitspublic double getGpioBusCurrent(CurrentUnit unit)
unit
- current unitspublic double getI2cBusCurrent(CurrentUnit unit)
unit
- current unitspublic double getInputVoltage(VoltageUnit unit)
unit
- voltage unitspublic double getAuxiliaryVoltage(VoltageUnit unit)
unit
- voltage unitspublic double getTemperature(TempUnit unit)
unit
- temperature unitspublic void setDebug(LynxModule.DebugGroup group, LynxModule.DebugVerbosity verbosity) throws java.lang.InterruptedException
java.lang.InterruptedException
public <T> T acquireI2cLockWhile(Supplier<T> supplier) throws java.lang.InterruptedException, RobotCoreException, LynxNackException
acquireI2cLockWhile
in interface LynxModuleIntf
java.lang.InterruptedException
RobotCoreException
LynxNackException
public void acquireNetworkTransmissionLock(LynxMessage message) throws java.lang.InterruptedException
acquireNetworkTransmissionLock
in interface LynxModuleIntf
java.lang.InterruptedException
public void releaseNetworkTransmissionLock(LynxMessage message) throws java.lang.InterruptedException
releaseNetworkTransmissionLock
in interface LynxModuleIntf
java.lang.InterruptedException
public void sendCommand(LynxMessage command) throws java.lang.InterruptedException, LynxUnsupportedCommandException
sendCommand
in interface LynxModuleIntf
java.lang.InterruptedException
LynxUnsupportedCommandException
public void retransmit(LynxMessage message) throws java.lang.InterruptedException
retransmit
in interface LynxModuleIntf
java.lang.InterruptedException
public void finishedWithMessage(LynxMessage message)
finishedWithMessage
in interface LynxModuleIntf
public void pretendFinishExtantCommands() throws java.lang.InterruptedException
java.lang.InterruptedException
public void onIncomingDatagramReceived(LynxDatagram datagram)
public void abandonUnfinishedCommands()
protected void nackUnfinishedCommands()