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.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 <any> |
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 com.qualcomm.hardware.lynx.LynxFirmwareUpdater |
lynxFirmwareUpdater |
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 boolean |
resetAttempted |
protected static java.lang.String |
SEPARATOR |
static java.lang.String |
TAG |
protected boolean |
wasPollingWhenEngaged |
Modifier | Constructor and Description |
---|---|
protected |
LynxUsbDeviceImpl(android.content.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) |
LynxModule |
addConfiguredModule(LynxModule module)
Returns a LynxModule instance that is equivalent to (but not guaranteed to be the same as)
the one passed in as a parameter, which is registered with this LynxUsbDevice.
|
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(boolean checkForImus)
Discover all the lynx modules that are accessible through this Lynx USB device.
|
void |
disengage() |
protected void |
doClose() |
protected void |
doCloseFromArmed() |
protected void |
doCloseFromOther() |
protected void |
doPretend() |
void |
engage() |
void |
failSafe() |
protected LynxModule |
findKnownModule(int moduleAddress) |
static LynxUsbDevice |
findOrCreateAndArm(android.content.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() |
LynxUsbDeviceImpl |
getDelegationTarget() |
java.lang.String |
getDeviceName() |
protected java.util.Collection<LynxModule> |
getKnownModules() |
Manufacturer |
getManufacturer() |
RobotUsbModule |
getOwner() |
ShutdownReason |
getShutdownReason() |
protected java.lang.String |
getTag() |
int |
getVersion() |
protected boolean |
hasShutdownAbnormally() |
boolean |
isEngaged() |
boolean |
isSystemSynthetic() |
void |
lockNetworkLockAcquisitions() |
void |
noteMissingModule(LynxModule module,
java.lang.String moduleName) |
protected void |
onLynxDiscoveryResponseReceived(LynxDatagram datagram) |
void |
performSystemOperationOnConnectedModule(int moduleAddress,
boolean isParent,
<any> moduleConsumer) |
protected void |
pingAndQueryKnownInterfaces() |
protected void |
pretendFinishExtantCommands() |
void |
releaseNetworkTransmissionLock(LynxMessage message) |
void |
removeConfiguredModule(LynxModule module)
Should ONLY be called by LynxModule.close()
|
static void |
resetDevice(RobotUsbDevice robotUsbDevice)
Issues a hardware reset to the lynx module.
|
void |
resetDeviceConfigurationForOpMode() |
protected void |
resetNetworkTransmissionLock() |
void |
setOwner(RobotUsbModule owner) |
void |
setSystemSynthetic(boolean systemSynthetic) |
void |
setThrowOnNetworkLockAcquisition(boolean shouldThrow) |
boolean |
setupControlHubEmbeddedModule()
Verifies that we can communicate with the Control Hub's embedded module, and that its address
is set to
LynxConstants#CH_EMBEDDED_MODULE_ADDRESS . |
protected void |
shutdownAbnormally() |
protected void |
startPollingForIncomingDatagrams() |
protected void |
startRegularPinging() |
protected boolean |
stopPollingForIncomingDatagrams() |
void |
transmit(LynxMessage message) |
RobotCoreCommandList.LynxFirmwareUpdateResp |
updateFirmware(RobotCoreCommandList.FWImage image,
java.lang.String requestId,
<any> progressConsumer) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getRobotUsbDevice
public 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 final <any> 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 final com.qualcomm.hardware.lynx.LynxFirmwareUpdater lynxFirmwareUpdater
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(android.content.Context context, SerialNumber serialNumber, SyncdDevice.Manager manager, com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDevice.OpenRobotUsbDevice openRobotUsbDevice)
protected java.lang.String getTag()
public static LynxUsbDevice findOrCreateAndArm(android.content.Context context, SerialNumber serialNumber, SyncdDevice.Manager manager, com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDevice.OpenRobotUsbDevice openRobotUsbDevice) throws RobotCoreException, java.lang.InterruptedException
RobotCoreException
java.lang.InterruptedException
public LynxUsbDeviceImpl getDelegationTarget()
getDelegationTarget
in interface LynxUsbDevice
public boolean isSystemSynthetic()
isSystemSynthetic
in interface LynxUsbDevice
public void setSystemSynthetic(boolean systemSynthetic)
setSystemSynthetic
in interface LynxUsbDevice
protected void doClose()
public Manufacturer getManufacturer()
public java.lang.String getDeviceName()
public java.lang.String getConnectionInfo()
public void resetDeviceConfigurationForOpMode()
public int getVersion()
public ShutdownReason getShutdownReason()
protected boolean hasShutdownAbnormally()
public void setOwner(RobotUsbModule owner)
public RobotUsbModule getOwner()
public void engage()
public void disengage()
public boolean isEngaged()
protected void doPretend() throws RobotCoreException, java.lang.InterruptedException
RobotCoreException
java.lang.InterruptedException
protected void armDevice(RobotUsbDevice device) throws RobotCoreException, java.lang.InterruptedException
RobotCoreException
java.lang.InterruptedException
protected void disarmDevice() throws java.lang.InterruptedException
java.lang.InterruptedException
protected void doCloseFromArmed() throws RobotCoreException, java.lang.InterruptedException
RobotCoreException
java.lang.InterruptedException
protected void doCloseFromOther() throws RobotCoreException, java.lang.InterruptedException
RobotCoreException
java.lang.InterruptedException
protected void closeModules()
public void failSafe()
failSafe
in interface LynxUsbDevice
protected 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 LynxUsbDevice
public void noteMissingModule(LynxModule module, java.lang.String moduleName)
noteMissingModule
in interface LynxUsbDevice
protected java.lang.String composeGlobalWarning()
public LynxModule addConfiguredModule(LynxModule module) throws java.lang.InterruptedException, RobotCoreException
addConfiguredModule
in interface LynxUsbDevice
RobotCoreException
- if trying to communicate with this module was unsuccessful.java.lang.InterruptedException
public LynxModule getConfiguredModule(int moduleAddress)
getConfiguredModule
in interface LynxUsbDevice
public void removeConfiguredModule(LynxModule module)
removeConfiguredModule
in interface LynxUsbDevice
public void performSystemOperationOnConnectedModule(int moduleAddress, boolean isParent, <any> moduleConsumer) throws RobotCoreException, java.lang.InterruptedException
performSystemOperationOnConnectedModule
in interface LynxUsbDevice
RobotCoreException
java.lang.InterruptedException
public LynxModuleMetaList discoverModules(boolean checkForImus) throws RobotCoreException, java.lang.InterruptedException
discoverModules
in interface LynxUsbDevice
checkForImus
- Whether we should check if each discovered module has an onboard BNO055 IMURobotCoreException
java.lang.InterruptedException
public boolean setupControlHubEmbeddedModule() throws java.lang.InterruptedException, RobotCoreException
LynxConstants#CH_EMBEDDED_MODULE_ADDRESS
. If we can't communicate with it,
an attempt will be made to flash new firmware to it. If its address is incorrect, it will be
set to the correct value.setupControlHubEmbeddedModule
in interface LynxUsbDevice
java.lang.InterruptedException
RobotCoreException
protected void onLynxDiscoveryResponseReceived(LynxDatagram datagram)
protected void pingAndQueryKnownInterfaces() throws RobotCoreException, java.lang.InterruptedException
RobotCoreException
java.lang.InterruptedException
public void lockNetworkLockAcquisitions()
public void setThrowOnNetworkLockAcquisition(boolean shouldThrow)
protected void resetNetworkTransmissionLock() throws java.lang.InterruptedException
java.lang.InterruptedException
public void acquireNetworkTransmissionLock(LynxMessage message) throws java.lang.InterruptedException
acquireNetworkTransmissionLock
in interface LynxUsbDevice
java.lang.InterruptedException
public void releaseNetworkTransmissionLock(LynxMessage message) throws java.lang.InterruptedException
releaseNetworkTransmissionLock
in interface LynxUsbDevice
java.lang.InterruptedException
protected void startPollingForIncomingDatagrams()
protected boolean stopPollingForIncomingDatagrams()
protected void startRegularPinging()
public void transmit(LynxMessage message) throws java.lang.InterruptedException
transmit
in interface LynxUsbDevice
java.lang.InterruptedException
protected void shutdownAbnormally()
protected void pretendFinishExtantCommands() throws java.lang.InterruptedException
java.lang.InterruptedException
protected void abandonUnfinishedCommands()
protected static RobotUsbDeviceFtdi accessCBus(RobotUsbDevice robotUsbDevice)
public static void resetDevice(RobotUsbDevice robotUsbDevice)
public RobotCoreCommandList.LynxFirmwareUpdateResp updateFirmware(RobotCoreCommandList.FWImage image, java.lang.String requestId, <any> progressConsumer)
updateFirmware
in interface LynxUsbDevice