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 LynxModules
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.ManufacturerRobotArmingStateNotifier.ARMINGSTATE, RobotArmingStateNotifier.CallbackBlinker.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.Steps 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, handleSpecificExceptionpublic 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 LynxCommExceptionHandlerprotected 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.NoSuchMethodExceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic void close()
HardwareDeviceclose in interface HardwareDevicepublic 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 RobotCoreLynxModulepublic void setNewModuleAddress(int newModuleAddress)
protected byte getNewMessageNumber()
public void noteAttentionRequired()
noteAttentionRequired in interface LynxModuleIntfpublic void noteDatagramReceived()
noteDatagramReceived in interface LynxModuleIntfpublic void noteNotResponding()
noteNotResponding in interface LynxModuleIntfpublic boolean isNotResponding()
isNotResponding in interface LynxModuleIntfprotected void stopAttentionRequired()
protected void sendGetModuleStatusAndProcessResponse(boolean clearStatus)
protected void forgetLastKnown()
public HardwareDevice.Manufacturer getManufacturer()
HardwareDevicegetManufacturer in interface HardwareDevicepublic java.lang.String getDeviceName()
HardwareDevicegetDeviceName in interface HardwareDevicepublic java.lang.String getFirmwareVersionString()
getFirmwareVersionString in interface RobotCoreLynxModulepublic java.lang.String getNullableFirmwareVersionString()
getNullableFirmwareVersionString in interface RobotCoreLynxModulepublic java.lang.String getConnectionInfo()
HardwareDevicegetConnectionInfo in interface HardwareDevicepublic int getVersion()
HardwareDevicegetVersion in interface HardwareDevicepublic void resetDeviceConfigurationForOpMode()
HardwareDeviceresetDeviceConfigurationForOpMode in interface HardwareDevicepublic void removeAsConfigured()
public java.util.List<java.lang.String> getGlobalWarnings()
public static java.lang.String getHealthStatusWarningMessage(HardwareDeviceHealth hardwareDeviceHealth)
public SerialNumber getModuleSerialNumber()
public SerialNumber getSerialNumber()
RobotArmingStateNotifiergetSerialNumber in interface RobotCoreLynxModulegetSerialNumber in interface RobotArmingStateNotifierpublic RobotArmingStateNotifier.ARMINGSTATE getArmingState()
RobotArmingStateNotifiergetArmingState in interface RobotArmingStateNotifierpublic void registerCallback(RobotArmingStateNotifier.Callback callback, boolean doInitialCallback)
RobotArmingStateNotifierregisterCallback in interface RobotArmingStateNotifierRobotArmingStateNotifier.unregisterCallback(Callback)public void unregisterCallback(RobotArmingStateNotifier.Callback callback)
RobotArmingStateNotifierunregisterCallback in interface RobotArmingStateNotifierRobotArmingStateNotifier.registerCallback(Callback, boolean)public void onModuleStateChange(RobotArmingStateNotifier module, RobotArmingStateNotifier.ARMINGSTATE state)
RobotArmingStateNotifier.CallbackonModuleStateChange in interface RobotArmingStateNotifier.Callbackmodule - the module whose state has changedstate - the state into which that module has transitioned#registerCallback(Callback)public void engage()
Engagablepublic void disengage()
Engagablepublic boolean isEngaged()
Engagablepublic void visuallyIdentify(boolean shouldIdentify)
VisuallyIdentifiableHardwareDevicevisuallyIdentify in interface VisuallyIdentifiableHardwareDevicepublic int getBlinkerPatternMaxLength()
BlinkerBlinker.Steps that can be present in a patterngetBlinkerPatternMaxLength in interface BlinkerBlinker.Steps that can be present in a patternpublic void setConstant(int color)
BlinkersetConstant in interface Blinkercolor - the color with which the LED or light should be illuminatedpublic void stopBlinking()
BlinkerstopBlinking in interface Blinkerpublic void setPattern(java.util.Collection<Blinker.Step> steps)
BlinkersetPattern in interface Blinkersteps - the pattern of colors and durations that the LED or light should illuminate itself withpublic java.util.Collection<Blinker.Step> getPattern()
BlinkergetPattern in interface Blinkerprotected void resendCurrentPattern()
public void pushPattern(java.util.Collection<Blinker.Step> steps)
BlinkerpushPattern in interface Blinkersteps - the new pattern to be displayedprotected void internalPushPattern(java.util.Collection<Blinker.Step> steps)
public boolean patternStackNotEmpty()
BlinkerpatternStackNotEmpty in interface Blinkerpublic boolean popPattern()
BlinkerpopPattern in interface Blinkerpublic boolean isParent()
isParent in interface RobotCoreLynxModulepublic void pingAndQueryKnownInterfacesAndEtc(long randSeed)
throws RobotCoreException,
java.lang.InterruptedException
RobotCoreExceptionjava.lang.InterruptedExceptionprotected void initializeLEDS()
protected void initializeDebugLogging()
throws RobotCoreException,
java.lang.InterruptedException
RobotCoreExceptionjava.lang.InterruptedExceptionprotected void pingInitialContact()
throws RobotCoreException,
java.lang.InterruptedException
RobotCoreExceptionjava.lang.InterruptedExceptionpublic void validateCommand(LynxMessage lynxMessage) throws LynxUnsupportedCommandException
validateCommand in interface LynxModuleIntfLynxUnsupportedCommandExceptionpublic boolean isCommandSupported(java.lang.Class<? extends LynxCommand> clazz)
isCommandSupported in interface LynxModuleIntfprotected boolean queryInterface(LynxInterface theInterface) throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic int getInterfaceBaseCommandNumber(java.lang.String interfaceName)
getInterfaceBaseCommandNumber in interface LynxModuleIntfprotected void ping()
protected void ping(boolean initialPing)
throws RobotCoreException,
java.lang.InterruptedException,
LynxNackException
RobotCoreExceptionjava.lang.InterruptedExceptionLynxNackExceptionprotected int getMsModulePingInterval()
public void resetPingTimer(LynxMessage message)
resetPingTimer in interface LynxModuleIntfprotected 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
RobotCoreExceptionjava.lang.InterruptedExceptionLynxNackExceptionpublic void enablePhoneCharging(boolean enable)
throws RobotCoreException,
java.lang.InterruptedException,
LynxNackException
RobotCoreExceptionjava.lang.InterruptedExceptionLynxNackExceptionpublic boolean isPhoneChargingEnabled()
throws RobotCoreException,
java.lang.InterruptedException,
LynxNackException
RobotCoreExceptionjava.lang.InterruptedExceptionLynxNackExceptionpublic 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.InterruptedExceptionpublic <T> T acquireI2cLockWhile(Supplier<T> supplier) throws java.lang.InterruptedException, RobotCoreException, LynxNackException
acquireI2cLockWhile in interface LynxModuleIntfjava.lang.InterruptedExceptionRobotCoreExceptionLynxNackExceptionpublic void acquireNetworkTransmissionLock(LynxMessage message) throws java.lang.InterruptedException
acquireNetworkTransmissionLock in interface LynxModuleIntfjava.lang.InterruptedExceptionpublic void releaseNetworkTransmissionLock(LynxMessage message) throws java.lang.InterruptedException
releaseNetworkTransmissionLock in interface LynxModuleIntfjava.lang.InterruptedExceptionpublic void sendCommand(LynxMessage command) throws java.lang.InterruptedException, LynxUnsupportedCommandException
sendCommand in interface LynxModuleIntfjava.lang.InterruptedExceptionLynxUnsupportedCommandExceptionpublic void retransmit(LynxMessage message) throws java.lang.InterruptedException
retransmit in interface LynxModuleIntfjava.lang.InterruptedExceptionpublic void finishedWithMessage(LynxMessage message)
finishedWithMessage in interface LynxModuleIntfpublic void pretendFinishExtantCommands()
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic void onIncomingDatagramReceived(LynxDatagram datagram)
public void abandonUnfinishedCommands()
protected void nackUnfinishedCommands()