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.Callback
HardwareDevice.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, wait
getRobotUsbDevice
arm, armOrPretend, close, disarm, pretend
getArmingState, getSerialNumber, registerCallback, unregisterCallback
clearGlobalWarning, getGlobalWarning, setGlobalWarning, suppressGlobalWarning
close
close
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 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
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 HardwareDevice.Manufacturer getManufacturer()
HardwareDevice
getManufacturer
in interface HardwareDevice
public java.lang.String getDeviceName()
HardwareDevice
getDeviceName
in interface HardwareDevice
public java.lang.String getConnectionInfo()
HardwareDevice
getConnectionInfo
in interface HardwareDevice
public void resetDeviceConfigurationForOpMode()
HardwareDevice
resetDeviceConfigurationForOpMode
in interface HardwareDevice
public int getVersion()
HardwareDevice
getVersion
in interface HardwareDevice
public ShutdownReason getShutdownReason()
protected boolean hasShutdownAbnormally()
public void setOwner(RobotUsbModule owner)
public RobotUsbModule getOwner()
public void engage()
Engagable
public void disengage()
Engagable
public boolean isEngaged()
Engagable
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
failSafe
in interface RobotCoreLynxUsbDevice
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 void addConfiguredModule(LynxModule module) throws RobotCoreException, java.lang.InterruptedException, LynxNackException
addConfiguredModule
in interface LynxUsbDevice
RobotCoreException
java.lang.InterruptedException
LynxNackException
public LynxModule getConfiguredModule(int moduleAddress)
getConfiguredModule
in interface LynxUsbDevice
public void removeConfiguredModule(LynxModule module)
removeConfiguredModule
in interface LynxUsbDevice
public LynxModuleMetaList discoverModules() throws RobotCoreException, java.lang.InterruptedException
discoverModules
in interface LynxUsbDevice
discoverModules
in interface RobotCoreLynxUsbDevice
RobotCoreException
java.lang.InterruptedException
public 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 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()
lockNetworkLockAcquisitions
in interface RobotCoreLynxUsbDevice
public void setThrowOnNetworkLockAcquisition(boolean shouldThrow)
setThrowOnNetworkLockAcquisition
in interface RobotCoreLynxUsbDevice
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 static boolean enterFirmwareUpdateModeUSB(RobotUsbDevice robotUsbDevice)
public static boolean enterFirmwareUpdateModeControlHub()