public class LynxModule extends LynxCommExceptionHandler implements LynxModuleIntf, RobotArmingStateNotifier, RobotArmingStateNotifier.Callback, Blinker, VisuallyIdentifiableHardwareDevice
LynxModule
represents the connection between the host and a particular
Lynx controller module. Multiple Lynx controller modules may be chained together over RS485
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 |
HardwareDevice.Manufacturer
RobotArmingStateNotifier.ARMINGSTATE, RobotArmingStateNotifier.Callback
Blinker.Step
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<Blinker.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<Blinker.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) |
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()
Closes this device
|
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()
Disengage the object from underlying services it uses to render its function.
|
void |
enablePhoneCharging(boolean enable) |
void |
engage()
(Re)enage the object with its underlying services.
|
void |
failSafe() |
void |
finishedWithMessage(LynxMessage message) |
protected void |
forgetLastKnown() |
RobotArmingStateNotifier.ARMINGSTATE |
getArmingState()
Returns the current arming state of the object.
|
double |
getAuxiliaryVoltage(VoltageUnit unit)
Returns the auxiliary (5V) voltage.
|
int |
getBlinkerPatternMaxLength()
Returns the maximum number of
Blinker.Step s that can be present in a pattern |
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()
Get connection information about this device in a human readable format
|
double |
getCurrent(CurrentUnit unit)
Returns the current consumption of the whole module.
|
java.lang.String |
getDeviceName()
Returns a string suitable for display to the user as to the type of device.
|
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.
|
int |
getInterfaceBaseCommandNumber(java.lang.String interfaceName)
Returns the first command number to use for the given interface.
|
HardwareDevice.Manufacturer |
getManufacturer()
Returns an indication of the manufacturer of this device.
|
int |
getModuleAddress() |
SerialNumber |
getModuleSerialNumber() |
protected int |
getMsModulePingInterval() |
protected byte |
getNewMessageNumber() |
java.lang.String |
getNullableFirmwareVersionString() |
java.util.Collection<Blinker.Step> |
getPattern()
Returns the current blinking pattern
|
SerialNumber |
getSerialNumber()
Returns the serial number of this USB module
|
protected java.lang.String |
getTag() |
double |
getTemperature(TempUnit unit)
Returns the module temperature.
|
int |
getVersion()
Version
|
protected void |
initializeDebugLogging() |
protected void |
initializeLEDS() |
protected void |
internalPushPattern(java.util.Collection<Blinker.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()
Returns whether the object is currently in the engaged state.
|
boolean |
isNotResponding() |
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,
RobotArmingStateNotifier.ARMINGSTATE state)
Notifies the callback that a module with which it has registered for notifications
has undergone a change of state.
|
boolean |
patternStackNotEmpty()
Returns whether the pattern stack is currently nonempty.
|
protected void |
ping() |
protected void |
ping(boolean initialPing) |
void |
pingAndQueryKnownInterfacesAndEtc(long randSeed)
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()
Pops the next pattern off of the stack of saved patterns, if any.
|
void |
pretendFinishExtantCommands() |
void |
pushPattern(java.util.Collection<Blinker.Step> steps)
Saves the existing pattern such that it can be later restored, then calls setPattern().
|
protected boolean |
queryInterface(LynxInterface theInterface)
Issues a query interface for the indicated interface and processes the results.
|
void |
registerCallback(RobotArmingStateNotifier.Callback callback,
boolean doInitialCallback)
Registers a callback for arming state notifications from this module.
|
void |
releaseNetworkTransmissionLock(LynxMessage message) |
void |
removeAsConfigured() |
protected void |
resendCurrentPattern() |
void |
resetDeviceConfigurationForOpMode()
Resets the device's configuration to that which is expected at the beginning of an OpMode.
|
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)
Sets the blinker pattern to be a single, unchanging color
|
void |
setDebug(LynxModule.DebugGroup group,
LynxModule.DebugVerbosity verbosity) |
protected void |
setFtdiResetWatchdog(boolean enabled) |
void |
setNewModuleAddress(int newModuleAddress) |
void |
setPattern(java.util.Collection<Blinker.Step> steps)
Sets the pattern with which this LED or light should illuminate.
|
void |
setSystemSynthetic(boolean systemSynthetic) |
void |
setUserModule(boolean isUserModule) |
protected void |
startExecutor() |
protected void |
startFtdiResetWatchdog() |
protected void |
startPingTimer() |
protected void |
stopAttentionRequired() |
void |
stopBlinking()
Sets the blinker to constant black and frees any internal resources
|
protected void |
stopExecutor() |
protected void |
stopFtdiResetWatchdog() |
protected void |
stopFtdiResetWatchdog(boolean disengaging) |
protected void |
stopPingTimer(boolean wait) |
java.lang.String |
toString() |
void |
unregisterCallback(RobotArmingStateNotifier.Callback callback)
Unregister a callback which has been registered for notifications with this module.
|
void |
validateCommand(LynxMessage lynxMessage) |
void |
visuallyIdentify(boolean shouldIdentify)
idempotent
|
handleException, handleSpecificException, handleSpecificException, 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 boolean isSystemSynthetic
protected boolean isUserModule
protected boolean isEngaged
protected final java.lang.Object engagementLock
protected 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<Blinker.Step> currentSteps
protected java.util.Deque<java.util.ArrayList<Blinker.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)
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()
HardwareDevice
close
in interface HardwareDevice
public boolean isUserModule()
public void setUserModule(boolean isUserModule)
public boolean isSystemSynthetic()
public void setSystemSynthetic(boolean systemSynthetic)
public void noteController(LynxController controller)
public int getModuleAddress()
getModuleAddress
in interface RobotCoreLynxModule
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 HardwareDevice.Manufacturer getManufacturer()
HardwareDevice
getManufacturer
in interface HardwareDevice
public java.lang.String getDeviceName()
HardwareDevice
getDeviceName
in interface HardwareDevice
public java.lang.String getFirmwareVersionString()
getFirmwareVersionString
in interface RobotCoreLynxModule
public java.lang.String getNullableFirmwareVersionString()
getNullableFirmwareVersionString
in interface RobotCoreLynxModule
public java.lang.String getConnectionInfo()
HardwareDevice
getConnectionInfo
in interface HardwareDevice
public int getVersion()
HardwareDevice
getVersion
in interface HardwareDevice
public void resetDeviceConfigurationForOpMode()
HardwareDevice
resetDeviceConfigurationForOpMode
in interface HardwareDevice
public void removeAsConfigured()
public java.util.List<java.lang.String> getGlobalWarnings()
public static java.lang.String getHealthStatusWarningMessage(HardwareDeviceHealth hardwareDeviceHealth)
public SerialNumber getModuleSerialNumber()
public SerialNumber getSerialNumber()
RobotArmingStateNotifier
getSerialNumber
in interface RobotCoreLynxModule
getSerialNumber
in interface RobotArmingStateNotifier
public RobotArmingStateNotifier.ARMINGSTATE getArmingState()
RobotArmingStateNotifier
getArmingState
in interface RobotArmingStateNotifier
public void registerCallback(RobotArmingStateNotifier.Callback callback, boolean doInitialCallback)
RobotArmingStateNotifier
registerCallback
in interface RobotArmingStateNotifier
RobotArmingStateNotifier.unregisterCallback(Callback)
public void unregisterCallback(RobotArmingStateNotifier.Callback callback)
RobotArmingStateNotifier
unregisterCallback
in interface RobotArmingStateNotifier
RobotArmingStateNotifier.registerCallback(Callback, boolean)
public void onModuleStateChange(RobotArmingStateNotifier module, RobotArmingStateNotifier.ARMINGSTATE state)
RobotArmingStateNotifier.Callback
onModuleStateChange
in interface RobotArmingStateNotifier.Callback
module
- the module whose state has changedstate
- the state into which that module has transitioned#registerCallback(Callback)
public void engage()
Engagable
public void disengage()
Engagable
public boolean isEngaged()
Engagable
public void visuallyIdentify(boolean shouldIdentify)
VisuallyIdentifiableHardwareDevice
visuallyIdentify
in interface VisuallyIdentifiableHardwareDevice
public int getBlinkerPatternMaxLength()
Blinker
Blinker.Step
s that can be present in a patterngetBlinkerPatternMaxLength
in interface Blinker
Blinker.Step
s that can be present in a patternpublic void setConstant(int color)
Blinker
setConstant
in interface Blinker
color
- the color with which the LED or light should be illuminatedpublic void stopBlinking()
Blinker
stopBlinking
in interface Blinker
public void setPattern(java.util.Collection<Blinker.Step> steps)
Blinker
setPattern
in interface Blinker
steps
- the pattern of colors and durations that the LED or light should illuminate itself withpublic java.util.Collection<Blinker.Step> getPattern()
Blinker
getPattern
in interface Blinker
protected void resendCurrentPattern()
public void pushPattern(java.util.Collection<Blinker.Step> steps)
Blinker
pushPattern
in interface Blinker
steps
- the new pattern to be displayedprotected void internalPushPattern(java.util.Collection<Blinker.Step> steps)
public boolean patternStackNotEmpty()
Blinker
patternStackNotEmpty
in interface Blinker
public boolean popPattern()
Blinker
popPattern
in interface Blinker
public boolean isParent()
isParent
in interface RobotCoreLynxModule
public void pingAndQueryKnownInterfacesAndEtc(long randSeed) 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 int getInterfaceBaseCommandNumber(java.lang.String interfaceName)
getInterfaceBaseCommandNumber
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()