use of com.qualcomm.robotcore.hardware.LynxModuleMetaList in project robotcode by OutoftheBoxFTC.
the class FtcEventLoop method handleCommandDiscoverLynxModules.
protected void handleCommandDiscoverLynxModules(String extra) throws RobotCoreException, InterruptedException {
RobotLog.vv(FtcConfigurationActivity.TAG, "handling command DiscoverLynxModules");
final SerialNumber serialNumber = new SerialNumber(extra);
final USBScanManager usbScanManager = startUsbScanMangerIfNecessary();
// Start a scan and wait for it to complete, but if a scan is already in progress, then just wait for that one to finish
final ThreadPool.SingletonResult<LynxModuleMetaList> future = this.usbScanManager.startLynxModuleEnumerationIfNecessary(serialNumber);
// Actually carry out the scan in a worker thread so that we don't hold up the receive loop for
// full second or more that carrying out the discovery will take.
ThreadPool.getDefault().execute(new Runnable() {
@Override
public void run() {
try {
LynxModuleMetaList lynxModules = future.await();
if (lynxModules == null) {
lynxModules = new LynxModuleMetaList(serialNumber);
}
// Package up the raw module list and send that back to the DS
String data = usbScanManager.packageCommandResponse(lynxModules);
RobotLog.vv(FtcConfigurationActivity.TAG, "DiscoverLynxModules data='%s'", data);
networkConnectionHandler.sendCommand(new Command(CommandList.CMD_DISCOVER_LYNX_MODULES_RESP, data));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
});
}
use of com.qualcomm.robotcore.hardware.LynxModuleMetaList in project robotcode by OutoftheBoxFTC.
the class FtcEventLoopBase method getUSBAccessibleLynxDevices.
protected List<USBAccessibleLynxModule> getUSBAccessibleLynxDevices(boolean includeModuleAddresses) throws RobotCoreException {
RobotLog.vv(TAG, "getUSBAccessibleLynxDevices()...");
// We do a raw, low level scan, not caring what's in the current hardware map, if anything.
// This is important: a module might, for example, be in a state where it previously had a
// failed firmware update, and all that's running is its bootloader. Such a beast would be
// unable to respond to
USBScanManager scanManager = startUsbScanMangerIfNecessary();
final ThreadPool.SingletonResult<ScannedDevices> future = scanManager.startDeviceScanIfNecessary();
try {
ScannedDevices scannedDevices = future.await();
List<USBAccessibleLynxModule> result = new ArrayList<USBAccessibleLynxModule>();
// Return everything returned by the scan
for (Map.Entry<SerialNumber, DeviceManager.DeviceType> entry : scannedDevices.entrySet()) {
if (entry.getValue() == DeviceManager.DeviceType.LYNX_USB_DEVICE) {
SerialNumber serialNumber = entry.getKey();
// For the moment, serial numbers of the embedded module must be one. If the
// embedded/synthetic module was discovered rather than assuming its address
// to always one, this could be relaxed.
result.add(new USBAccessibleLynxModule(serialNumber, !serialNumber.equals(LynxConstants.SERIAL_NUMBER_EMBEDDED)));
}
}
// Return the embedded module if we're supposed to and if it wasn't already there (which it will be, I think, always, now)
if (LynxConstants.enableLynxFirmwareUpdateForDragonboard()) {
boolean found = false;
for (USBAccessibleLynxModule module : result) {
if (module.getSerialNumber().equals(LynxConstants.SERIAL_NUMBER_EMBEDDED)) {
found = true;
break;
}
}
if (!found) {
result.add(new USBAccessibleLynxModule(LynxConstants.SERIAL_NUMBER_EMBEDDED, false));
}
}
// Add module addresses if asked
if (includeModuleAddresses) {
for (int i = 0; i < result.size(); ) {
USBAccessibleLynxModule usbModule = result.get(i);
RobotCoreLynxUsbDevice device = scanManager.getDeviceManager().createLynxUsbDevice(usbModule.getSerialNumber(), null);
try {
LynxModuleMetaList lynxModuleMetas = device.discoverModules();
boolean foundParent = false;
boolean foundChild = false;
for (LynxModuleMeta meta : lynxModuleMetas) {
if (meta.getModuleAddress() == 0) {
// paranoia
continue;
}
if (meta.isParent()) {
usbModule.setModuleAddress(meta.getModuleAddress());
foundParent = true;
} else {
// We've got child modules connected: these are unsafe to update
foundChild = true;
}
}
if (foundParent && !foundChild) {
i++;
} else {
RobotLog.vv(TAG, "lynx module %s not actually accessible", usbModule.getSerialNumber());
result.remove(i);
}
} finally {
if (device != null) {
device.close();
}
}
}
}
RobotLog.vv(TAG, "...getUSBAccessibleLynxDevices(): %d modules found", result.size());
return result;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return new ArrayList<USBAccessibleLynxModule>();
}
}
Aggregations