use of com.qualcomm.robotcore.hardware.LynxModuleMetaList in project robotcode by OutoftheBoxFTC.
the class ConfigurationUtility method buildNewLynxUsbDevice.
public LynxUsbDeviceConfiguration buildNewLynxUsbDevice(SerialNumber serialNumber, DeviceManager deviceManager, ThreadPool.SingletonResult<LynxModuleMetaList> discoveryFuture) throws RobotCoreException, InterruptedException {
RobotLog.vv(TAG, "buildNewLynxUsbDevice(%s)...", serialNumber);
try {
LynxModuleMetaList metas = discoveryFuture.await();
if (metas == null) {
metas = new LynxModuleMetaList(serialNumber);
}
RobotLog.vv(TAG, "buildLynxUsbDevice(): discovered lynx modules: %s", metas);
//
List<LynxModuleConfiguration> modules = new LinkedList<LynxModuleConfiguration>();
for (LynxModuleMeta meta : metas) {
modules.add(buildNewLynxModule(meta.getModuleAddress(), meta.isParent(), true));
}
DeviceConfiguration.sortByName(modules);
RobotLog.vv(TAG, "buildNewLynxUsbDevice(%s): %d modules", serialNumber, modules.size());
String name = createUniqueName(BuiltInConfigurationType.LYNX_USB_DEVICE, R.string.counted_lynx_usb_device_name);
LynxUsbDeviceConfiguration result = new LynxUsbDeviceConfiguration(name, modules, serialNumber);
return result;
} finally {
RobotLog.vv(TAG, "...buildNewLynxUsbDevice(%s): ", serialNumber);
}
}
use of com.qualcomm.robotcore.hardware.LynxModuleMetaList in project robotcode by OutoftheBoxFTC.
the class USBScanManager method awaitLynxModules.
@NonNull
public LynxModuleMetaList awaitLynxModules(SerialNumber serialNumber) throws InterruptedException {
LynxModuleDiscoveryState discoveryState = getDiscoveryState(serialNumber);
LynxModuleMetaList result = discoveryState.lynxDiscoverySingleton.await();
if (result == null) {
RobotLog.vv(TAG, "USBScanManager.awaitLynxModules() returning made-up result");
result = new LynxModuleMetaList(serialNumber);
}
return result;
}
use of com.qualcomm.robotcore.hardware.LynxModuleMetaList in project robotcode by OutoftheBoxFTC.
the class USBScanManager method handleCommandDiscoverLynxModulesResponse.
public void handleCommandDiscoverLynxModulesResponse(String extra) throws RobotCoreException {
RobotLog.vv(TAG, "handleCommandDiscoverLynxModulesResponse()...");
LynxModuleMetaList lynxModules = LynxModuleMetaList.fromSerializationString(extra);
LynxModuleDiscoveryState discoveryState = getDiscoveryState(lynxModules.serialNumber);
synchronized (discoveryState.remoteLynxDiscoveryLock) {
discoveryState.remoteLynxModules = lynxModules;
discoveryState.lynxDiscoverySequence.advanceNext();
}
RobotLog.vv(TAG, "...handleCommandDiscoverLynxModulesResponse()");
}
use of com.qualcomm.robotcore.hardware.LynxModuleMetaList in project robotcode by OutoftheBoxFTC.
the class LynxUsbDeviceImpl method discoverModules.
@Override
public LynxModuleMetaList discoverModules() throws RobotCoreException, InterruptedException {
RobotLog.vv(TAG, "lynx discovery beginning...transmitting LynxDiscoveryCommand()...");
// Initialize our set of known modules and send out discovery requests
this.discoveredModules.clear();
// Make ourselves a fake module so that we can (mostly) use the normal transmission infrastructure
LynxModule fakeModule = new LynxModule(this, 0, /*ignored*/
false);
try {
// Make a discovery command and send it out
LynxDiscoveryCommand discoveryCommand = new LynxDiscoveryCommand(fakeModule);
discoveryCommand.send();
// Wait an interval sufficient so as to guarantee that we'll see all the replies
// that are there to see
long nsPerModuleInterval = 3 * ElapsedTime.MILLIS_IN_NANO;
int maxNumberOfModules = 254;
// "entire packet must be received within 50ms from the first Frame Byte"
long nsPacketTimeMax = 50 * ElapsedTime.MILLIS_IN_NANO;
// should be oodles
long nsSlop = 200 * ElapsedTime.MILLIS_IN_NANO;
long nsWait = nsPerModuleInterval * maxNumberOfModules + nsPacketTimeMax + nsSlop;
long msWait = (nsWait / ElapsedTime.MILLIS_IN_NANO);
nsWait = nsWait - msWait * ElapsedTime.MILLIS_IN_NANO;
RobotLog.vv(TAG, "discovery waiting %dms and %dns", msWait, nsWait);
Thread.sleep(msWait, (int) nsWait);
RobotLog.vv(TAG, "discovery waiting complete: #modules=%d", discoveredModules.size());
} catch (LynxNackException e) {
throw e.wrap();
} finally {
// Tidy up
fakeModule.close();
}
LynxModuleMetaList result = new LynxModuleMetaList(serialNumber, discoveredModules.values());
RobotLog.vv(TAG, "...lynx discovery completed");
return result;
}
use of com.qualcomm.robotcore.hardware.LynxModuleMetaList in project robotcode by OutoftheBoxFTC.
the class FtcConfigurationActivity method buildRobotConfigMapFromScanned.
private RobotConfigMap buildRobotConfigMapFromScanned(RobotConfigMap existingControllers, ScannedDevices scannedDevices) {
// Initialize deviceControllers using the set of serial numbers in the ScannedDevices. If the serial
// number appears in our existing map, then just carry that configuration over; otherwise, make us
// a new configuration appropriate for the type of the controller.
RobotConfigMap newRobotConfigMap = new RobotConfigMap();
configurationUtility.resetNameUniquifiers();
for (Map.Entry<SerialNumber, DeviceManager.DeviceType> entry : scannedDevices.entrySet()) {
SerialNumber serialNumber = entry.getKey();
ControllerConfiguration controllerConfiguration = null;
if (carryOver(serialNumber, existingControllers)) {
RobotLog.vv(TAG, "carrying over %s", serialNumber);
controllerConfiguration = existingControllers.get(serialNumber);
} else {
switch(entry.getValue()) {
case MODERN_ROBOTICS_USB_DC_MOTOR_CONTROLLER:
controllerConfiguration = configurationUtility.buildNewModernMotorController(serialNumber);
break;
case MODERN_ROBOTICS_USB_SERVO_CONTROLLER:
controllerConfiguration = configurationUtility.buildNewModernServoController(serialNumber);
break;
case MODERN_ROBOTICS_USB_LEGACY_MODULE:
controllerConfiguration = configurationUtility.buildNewLegacyModule(serialNumber);
break;
case MODERN_ROBOTICS_USB_DEVICE_INTERFACE_MODULE:
controllerConfiguration = configurationUtility.buildNewDeviceInterfaceModule(serialNumber);
break;
case LYNX_USB_DEVICE:
try {
RobotLog.vv(TAG, "buildRobotConfigMapFromScanned(%s)...", serialNumber);
HardwareDeviceManager deviceManager = new HardwareDeviceManager(utility.getActivity(), null);
ThreadPool.SingletonResult<LynxModuleMetaList> discoveryFuture = this.usbScanManager.startLynxModuleEnumerationIfNecessary(serialNumber);
controllerConfiguration = configurationUtility.buildNewLynxUsbDevice(serialNumber, deviceManager, discoveryFuture);
RobotLog.vv(TAG, "...buildRobotConfigMapFromScanned(%s)", serialNumber);
} catch (InterruptedException e) {
RobotLog.ee(TAG, "interrupt in buildRobotConfigMapFromScanned(%s)", serialNumber);
Thread.currentThread().interrupt();
} catch (RobotCoreException e) {
RobotLog.ee(TAG, e, "exception in buildRobotConfigMapFromScanned(%s)", serialNumber);
controllerConfiguration = null;
}
break;
}
}
if (controllerConfiguration != null) {
controllerConfiguration.setKnownToBeAttached(true);
newRobotConfigMap.put(serialNumber, controllerConfiguration);
}
}
return newRobotConfigMap;
}
Aggregations