use of com.qualcomm.robotcore.util.SerialNumber 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