public class LynxUsbDeviceImpl extends ArmableUsbDevice implements LynxUsbDevice
LynxUsbDeviceImpl controls the USB communication to one or more Lynx Modules.
It polls for incoming traffic and sorts same according to the module address involved.RobotArmingStateNotifier.ARMINGSTATE, RobotArmingStateNotifier.CallbackHardwareDevice.Manufacturer| Modifier and Type | Field and Description |
|---|---|
protected static int |
cbusBothAsserted |
protected static int |
cbusMask |
protected static int |
cbusNeitherAsserted |
protected static int |
cbusNProg |
protected static int |
cbusNReset |
protected static int |
cbusProgAsserted |
protected static int |
cbusResetAsserted |
static boolean |
DEBUG_LOG_DATAGRAMS |
static boolean |
DEBUG_LOG_DATAGRAMS_FINISH |
static boolean |
DEBUG_LOG_DATAGRAMS_LOCK |
static boolean |
DEBUG_LOG_MESSAGES |
protected java.util.concurrent.ConcurrentHashMap<java.lang.Integer,LynxModuleMeta> |
discoveredModules |
protected java.lang.Object |
engageLock |
protected static LynxCommExceptionHandler |
exceptionHandler |
protected static WeakReferenceSet<LynxUsbDeviceImpl> |
extantDevices |
protected boolean |
hasShutdownAbnormally |
protected java.util.concurrent.ExecutorService |
incomingDatagramPoller |
protected boolean |
isEngaged |
protected boolean |
isSystemSynthetic |
protected java.util.concurrent.ConcurrentHashMap<java.lang.Integer,LynxModule> |
knownModules |
protected java.util.concurrent.ConcurrentHashMap<java.lang.Integer,LynxModule> |
knownModulesChanging |
protected java.util.concurrent.ConcurrentHashMap<java.lang.Integer,java.lang.String> |
missingModules |
protected static int |
msCbusWiggle |
protected static int |
msNetworkTransmissionLockAcquisitionTimeMax |
protected static int |
msResetRecovery |
protected MessageKeyedLock |
networkTransmissionLock |
protected static long |
randSeed |
protected boolean |
resetAttempted |
protected static java.lang.String |
SEPARATOR |
static java.lang.String |
TAG |
protected boolean |
wasPollingWhenEngaged |
| Modifier | Constructor and Description |
|---|---|
protected |
LynxUsbDeviceImpl(Context context,
SerialNumber serialNumber,
SyncdDevice.Manager manager,
com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDevice.OpenRobotUsbDevice openRobotUsbDevice)
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
abandonUnfinishedCommands() |
protected static RobotUsbDeviceFtdi |
accessCBus(RobotUsbDevice robotUsbDevice)
A simple, cursory test to see whether we can get access to the cbus FTDI functionality.
|
void |
acquireNetworkTransmissionLock(LynxMessage message) |
void |
addConfiguredModule(LynxModule module) |
protected void |
armDevice(RobotUsbDevice device) |
void |
changeModuleAddress(LynxModule module,
int newAddress,
java.lang.Runnable runnable) |
protected void |
closeModules() |
protected java.lang.String |
composeGlobalWarning()
For lynx modules, in addition to reporting arming issues, we also need to report
any issues having to do with configured modules which are absent.
|
protected void |
disarmDevice() |
LynxModuleMetaList |
discoverModules()
Discover all the lynx modules that are accessible through this Lynx USB device.
|
void |
disengage()
Disengage the object from underlying services it uses to render its function.
|
protected void |
doClose() |
protected void |
doCloseFromArmed() |
protected void |
doCloseFromOther() |
protected void |
doPretend() |
void |
engage()
(Re)enage the object with its underlying services.
|
static boolean |
enterFirmwareUpdateModeControlHub()
If we are a Control Hub, then this causes the combo-Lynx to enter firmware update * mode.
|
static boolean |
enterFirmwareUpdateModeUSB(RobotUsbDevice robotUsbDevice)
If we are a USB-attached Lynx, then cause us to enter firmware update mode
|
void |
failSafe() |
protected LynxModule |
findKnownModule(int moduleAddress) |
static LynxUsbDevice |
findOrCreateAndArm(Context context,
SerialNumber serialNumber,
SyncdDevice.Manager manager,
com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDevice.OpenRobotUsbDevice openRobotUsbDevice)
Either finds an already-open device with the indicated serial number and returns same, as-is,
or creates a new device and arms or pretends it, as the case may be.
|
java.util.List<java.lang.String> |
getAllModuleFirmwareVersions()
getAllModuleFirmwareVersions
|
LynxModule |
getConfiguredModule(int moduleAddress) |
java.lang.String |
getConnectionInfo()
Get connection information about this device in a human readable format
|
LynxUsbDeviceImpl |
getDelegationTarget() |
java.lang.String |
getDeviceName()
Returns a string suitable for display to the user as to the type of device.
|
protected java.util.Collection<LynxModule> |
getKnownModules() |
HardwareDevice.Manufacturer |
getManufacturer()
Returns an indication of the manufacturer of this device.
|
RobotUsbModule |
getOwner() |
ShutdownReason |
getShutdownReason() |
protected java.lang.String |
getTag() |
int |
getVersion()
Version
|
protected boolean |
hasShutdownAbnormally() |
boolean |
isEngaged()
Returns whether the object is currently in the engaged state.
|
boolean |
isSystemSynthetic() |
void |
lockNetworkLockAcquisitions() |
void |
noteMissingModule(LynxModule module,
java.lang.String moduleName) |
protected void |
onLynxDiscoveryResponseReceived(LynxDatagram datagram) |
protected void |
pingAndQueryKnownInterfaces() |
protected void |
pretendFinishExtantCommands() |
void |
releaseNetworkTransmissionLock(LynxMessage message) |
void |
removeConfiguredModule(LynxModule module) |
static void |
resetDevice(RobotUsbDevice robotUsbDevice)
Issues a hardware reset to the lynx module.
|
void |
resetDeviceConfigurationForOpMode()
Resets the device's configuration to that which is expected at the beginning of an OpMode.
|
protected void |
resetNetworkTransmissionLock() |
boolean |
setControlHubModuleAddressIfNecessary()
Checks if the Control Hub has a module with an address of
LynxConstants.CH_EMBEDDED_MODULE_ADDRESS,
and sets the Control Hub's embedded parent module address to such if necessary. |
void |
setOwner(RobotUsbModule owner) |
void |
setSystemSynthetic(boolean systemSynthetic) |
void |
setThrowOnNetworkLockAcquisition(boolean shouldThrow) |
protected void |
shutdownAbnormally() |
protected void |
startPollingForIncomingDatagrams() |
protected void |
startRegularPinging() |
protected boolean |
stopPollingForIncomingDatagrams() |
void |
transmit(LynxMessage message) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetRobotUsbDevicearm, armOrPretend, close, disarm, pretendgetArmingState, getSerialNumber, registerCallback, unregisterCallbackclearGlobalWarning, getGlobalWarning, setGlobalWarning, suppressGlobalWarningcloseclosepublic static final java.lang.String TAG
public static boolean DEBUG_LOG_MESSAGES
public static boolean DEBUG_LOG_DATAGRAMS
public static boolean DEBUG_LOG_DATAGRAMS_FINISH
public static boolean DEBUG_LOG_DATAGRAMS_LOCK
protected static long randSeed
protected static final WeakReferenceSet<LynxUsbDeviceImpl> extantDevices
protected static final LynxCommExceptionHandler exceptionHandler
protected final java.util.concurrent.ConcurrentHashMap<java.lang.Integer,LynxModule> knownModules
protected final java.util.concurrent.ConcurrentHashMap<java.lang.Integer,LynxModule> knownModulesChanging
protected final java.util.concurrent.ConcurrentHashMap<java.lang.Integer,LynxModuleMeta> discoveredModules
protected final java.util.concurrent.ConcurrentHashMap<java.lang.Integer,java.lang.String> missingModules
protected final MessageKeyedLock networkTransmissionLock
protected java.util.concurrent.ExecutorService incomingDatagramPoller
protected boolean resetAttempted
protected boolean hasShutdownAbnormally
protected boolean isSystemSynthetic
protected boolean isEngaged
protected boolean wasPollingWhenEngaged
protected final java.lang.Object engageLock
protected static final int cbusNReset
protected static final int cbusNProg
protected static final int cbusMask
protected static final int cbusNeitherAsserted
protected static final int cbusBothAsserted
protected static final int cbusProgAsserted
protected static final int cbusResetAsserted
protected static final int msNetworkTransmissionLockAcquisitionTimeMax
protected static final int msCbusWiggle
protected static final int msResetRecovery
protected static final java.lang.String SEPARATOR
protected LynxUsbDeviceImpl(Context context,
SerialNumber serialNumber,
SyncdDevice.Manager manager,
com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDevice.OpenRobotUsbDevice openRobotUsbDevice)
protected java.lang.String getTag()
public static LynxUsbDevice findOrCreateAndArm(Context context, SerialNumber serialNumber, SyncdDevice.Manager manager, com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDevice.OpenRobotUsbDevice openRobotUsbDevice) throws RobotCoreException, java.lang.InterruptedException
RobotCoreExceptionjava.lang.InterruptedExceptionpublic LynxUsbDeviceImpl getDelegationTarget()
getDelegationTarget in interface LynxUsbDevicepublic boolean isSystemSynthetic()
isSystemSynthetic in interface LynxUsbDevicepublic void setSystemSynthetic(boolean systemSynthetic)
setSystemSynthetic in interface LynxUsbDeviceprotected void doClose()
public HardwareDevice.Manufacturer getManufacturer()
HardwareDevicegetManufacturer in interface HardwareDevicepublic java.lang.String getDeviceName()
HardwareDevicegetDeviceName in interface HardwareDevicepublic java.lang.String getConnectionInfo()
HardwareDevicegetConnectionInfo in interface HardwareDevicepublic void resetDeviceConfigurationForOpMode()
HardwareDeviceresetDeviceConfigurationForOpMode in interface HardwareDevicepublic int getVersion()
HardwareDevicegetVersion in interface HardwareDevicepublic ShutdownReason getShutdownReason()
protected boolean hasShutdownAbnormally()
public void setOwner(RobotUsbModule owner)
public RobotUsbModule getOwner()
public void engage()
Engagablepublic void disengage()
Engagablepublic boolean isEngaged()
Engagableprotected void doPretend()
throws RobotCoreException,
java.lang.InterruptedException
RobotCoreExceptionjava.lang.InterruptedExceptionprotected void armDevice(RobotUsbDevice device) throws RobotCoreException, java.lang.InterruptedException
RobotCoreExceptionjava.lang.InterruptedExceptionprotected void disarmDevice()
throws java.lang.InterruptedException
java.lang.InterruptedExceptionprotected void doCloseFromArmed()
throws RobotCoreException,
java.lang.InterruptedException
RobotCoreExceptionjava.lang.InterruptedExceptionprotected void doCloseFromOther()
throws RobotCoreException,
java.lang.InterruptedException
RobotCoreExceptionjava.lang.InterruptedExceptionprotected void closeModules()
public void failSafe()
failSafe in interface LynxUsbDevicefailSafe in interface RobotCoreLynxUsbDeviceprotected java.util.Collection<LynxModule> getKnownModules()
protected LynxModule findKnownModule(int moduleAddress)
public java.util.List<java.lang.String> getAllModuleFirmwareVersions()
public void changeModuleAddress(LynxModule module, int newAddress, java.lang.Runnable runnable)
changeModuleAddress in interface LynxUsbDevicepublic void noteMissingModule(LynxModule module, java.lang.String moduleName)
noteMissingModule in interface LynxUsbDeviceprotected java.lang.String composeGlobalWarning()
public void addConfiguredModule(LynxModule module) throws RobotCoreException, java.lang.InterruptedException, LynxNackException
addConfiguredModule in interface LynxUsbDeviceRobotCoreExceptionjava.lang.InterruptedExceptionLynxNackExceptionpublic LynxModule getConfiguredModule(int moduleAddress)
getConfiguredModule in interface LynxUsbDevicepublic void removeConfiguredModule(LynxModule module)
removeConfiguredModule in interface LynxUsbDevicepublic LynxModuleMetaList discoverModules() throws RobotCoreException, java.lang.InterruptedException
discoverModules in interface LynxUsbDevicediscoverModules in interface RobotCoreLynxUsbDeviceRobotCoreExceptionjava.lang.InterruptedExceptionpublic boolean setControlHubModuleAddressIfNecessary()
throws java.lang.InterruptedException,
RobotCoreException
LynxConstants.CH_EMBEDDED_MODULE_ADDRESS,
and sets the Control Hub's embedded parent module address to such if necessary.setControlHubModuleAddressIfNecessary in interface LynxUsbDevicejava.lang.InterruptedExceptionRobotCoreExceptionprotected void onLynxDiscoveryResponseReceived(LynxDatagram datagram)
protected void pingAndQueryKnownInterfaces()
throws RobotCoreException,
java.lang.InterruptedException
RobotCoreExceptionjava.lang.InterruptedExceptionpublic void lockNetworkLockAcquisitions()
lockNetworkLockAcquisitions in interface RobotCoreLynxUsbDevicepublic void setThrowOnNetworkLockAcquisition(boolean shouldThrow)
setThrowOnNetworkLockAcquisition in interface RobotCoreLynxUsbDeviceprotected void resetNetworkTransmissionLock()
throws java.lang.InterruptedException
java.lang.InterruptedExceptionpublic void acquireNetworkTransmissionLock(LynxMessage message) throws java.lang.InterruptedException
acquireNetworkTransmissionLock in interface LynxUsbDevicejava.lang.InterruptedExceptionpublic void releaseNetworkTransmissionLock(LynxMessage message) throws java.lang.InterruptedException
releaseNetworkTransmissionLock in interface LynxUsbDevicejava.lang.InterruptedExceptionprotected void startPollingForIncomingDatagrams()
protected boolean stopPollingForIncomingDatagrams()
protected void startRegularPinging()
public void transmit(LynxMessage message) throws java.lang.InterruptedException
transmit in interface LynxUsbDevicejava.lang.InterruptedExceptionprotected void shutdownAbnormally()
protected void pretendFinishExtantCommands()
throws java.lang.InterruptedException
java.lang.InterruptedExceptionprotected void abandonUnfinishedCommands()
protected static RobotUsbDeviceFtdi accessCBus(RobotUsbDevice robotUsbDevice)
public static void resetDevice(RobotUsbDevice robotUsbDevice)
public static boolean enterFirmwareUpdateModeUSB(RobotUsbDevice robotUsbDevice)
public static boolean enterFirmwareUpdateModeControlHub()