Search in sources :

Example 1 with LynxModuleMeta

use of com.qualcomm.robotcore.hardware.LynxModuleMeta 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);
    }
}
Also used : LynxModuleMeta(com.qualcomm.robotcore.hardware.LynxModuleMeta) LynxModuleMetaList(com.qualcomm.robotcore.hardware.LynxModuleMetaList) LinkedList(java.util.LinkedList)

Example 2 with LynxModuleMeta

use of com.qualcomm.robotcore.hardware.LynxModuleMeta in project robotcode by OutoftheBoxFTC.

the class LynxUsbDeviceImpl method onLynxDiscoveryResponseReceived.

protected void onLynxDiscoveryResponseReceived(LynxDatagram datagram) {
    LynxDiscoveryResponse incomingResponse = new LynxDiscoveryResponse();
    incomingResponse.setSerialization(datagram);
    incomingResponse.loadFromSerialization();
    RobotLog.vv(TAG, "onLynxDiscoveryResponseReceived()... module#=%d isParent=%s", incomingResponse.getDiscoveredModuleAddress(), Boolean.toString(incomingResponse.isParent()));
    try {
        // Be paranoid about duplicates
        synchronized (this.discoveredModules) {
            if (!this.discoveredModules.containsKey(datagram.getSourceModuleAddress())) {
                RobotLog.vv(TAG, "discovered lynx module#=%d isParent=%s", incomingResponse.getDiscoveredModuleAddress(), Boolean.toString(incomingResponse.isParent()));
                LynxModuleMeta meta = new LynxModuleMeta(incomingResponse.getDiscoveredModuleAddress(), incomingResponse.isParent());
                discoveredModules.put(meta.getModuleAddress(), meta);
            }
        }
    } finally {
        RobotLog.vv(TAG, "...onLynxDiscoveryResponseReceived()");
    }
}
Also used : LynxModuleMeta(com.qualcomm.robotcore.hardware.LynxModuleMeta) LynxDiscoveryResponse(com.qualcomm.hardware.lynx.commands.standard.LynxDiscoveryResponse)

Example 3 with LynxModuleMeta

use of com.qualcomm.robotcore.hardware.LynxModuleMeta 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>();
    }
}
Also used : USBScanManager(com.qualcomm.ftccommon.configuration.USBScanManager) ThreadPool(com.qualcomm.robotcore.util.ThreadPool) ArrayList(java.util.ArrayList) LynxModuleMetaList(com.qualcomm.robotcore.hardware.LynxModuleMetaList) ScannedDevices(com.qualcomm.ftccommon.configuration.ScannedDevices) SerialNumber(com.qualcomm.robotcore.util.SerialNumber) LynxModuleMeta(com.qualcomm.robotcore.hardware.LynxModuleMeta) RobotCoreLynxUsbDevice(com.qualcomm.robotcore.hardware.RobotCoreLynxUsbDevice) Map(java.util.Map)

Aggregations

LynxModuleMeta (com.qualcomm.robotcore.hardware.LynxModuleMeta)3 LynxModuleMetaList (com.qualcomm.robotcore.hardware.LynxModuleMetaList)2 ScannedDevices (com.qualcomm.ftccommon.configuration.ScannedDevices)1 USBScanManager (com.qualcomm.ftccommon.configuration.USBScanManager)1 LynxDiscoveryResponse (com.qualcomm.hardware.lynx.commands.standard.LynxDiscoveryResponse)1 RobotCoreLynxUsbDevice (com.qualcomm.robotcore.hardware.RobotCoreLynxUsbDevice)1 SerialNumber (com.qualcomm.robotcore.util.SerialNumber)1 ThreadPool (com.qualcomm.robotcore.util.ThreadPool)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1