Search in sources :

Example 16 with SerialNumber

use of com.qualcomm.robotcore.util.SerialNumber in project robotcode by OutoftheBoxFTC.

the class EditUSBDeviceActivity method fixConfiguration.

protected void fixConfiguration() {
    SerialNumber candidate = getFixableCandidate();
    boolean isFixable = candidate != null;
    if (isFixable) {
        robotConfigMap.setSerialNumber(controllerConfiguration, candidate);
        controllerConfiguration.setKnownToBeAttached(true);
        determineExtraUSBDevices();
    } else {
        String format = getString(R.string.fixFailNoneAvailable);
        String name = controllerConfiguration.getName();
        String type = displayNameOfConfigurationType(ConfigurationType.DisplayNameFlavor.Normal, controllerConfiguration.getConfigurationType());
        appUtil.showToast(UILocation.ONLY_LOCAL, context, String.format(format, name, type));
    }
    refreshAfterFix();
}
Also used : SerialNumber(com.qualcomm.robotcore.util.SerialNumber)

Example 17 with SerialNumber

use of com.qualcomm.robotcore.util.SerialNumber 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;
}
Also used : SerialNumber(com.qualcomm.robotcore.util.SerialNumber) ThreadPool(com.qualcomm.robotcore.util.ThreadPool) RobotCoreException(com.qualcomm.robotcore.exception.RobotCoreException) LegacyModuleControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.LegacyModuleControllerConfiguration) ControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration) ServoControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration) MotorControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration) Map(java.util.Map) HardwareDeviceManager(com.qualcomm.hardware.HardwareDeviceManager) LynxModuleMetaList(com.qualcomm.robotcore.hardware.LynxModuleMetaList)

Example 18 with SerialNumber

use of com.qualcomm.robotcore.util.SerialNumber in project robotcode by OutoftheBoxFTC.

the class ScannedDevices method fromSerializationString.

public static ScannedDevices fromSerializationString(String string) {
    ScannedDevices result = new ScannedDevices();
    // 
    // paranoia
    string = string.trim();
    if (string.length() > 0) {
        String[] pairs = string.split(pairSeparatorSplit);
        for (String pair : pairs) {
            String[] keyValue = pair.split(keyValueSeparatorSplit);
            SerialNumber serialNumber = new SerialNumber(keyValue[0]);
            DeviceManager.DeviceType deviceType = DeviceManager.DeviceType.valueOf(keyValue[1]);
            result.put(serialNumber, deviceType);
        }
    }
    // 
    return result;
}
Also used : SerialNumber(com.qualcomm.robotcore.util.SerialNumber) DeviceManager(com.qualcomm.robotcore.hardware.DeviceManager)

Example 19 with SerialNumber

use of com.qualcomm.robotcore.util.SerialNumber in project robotcode by OutoftheBoxFTC.

the class EditLegacyModuleControllerActivity method createController.

/**
 * If the drop-down spinner-selected item is a Controller (Motor- or Servo-), we need to create
 * an empty Controller with the proper number of motors/servos.
 *
 * @param port    - the port where this controller got added
 * @param newType - the type of controller we're creating
 */
private void createController(int port, ConfigurationType newType) {
    DeviceConfiguration currentModule = devices.get(port);
    String name = currentModule.getName();
    SerialNumber serialNumber = new SerialNumber();
    ConfigurationType currentType = currentModule.getConfigurationType();
    if (!(currentType == newType)) {
        // only update the controller if it's a new choice.
        ControllerConfiguration newModule;
        if (newType == BuiltInConfigurationType.MOTOR_CONTROLLER) {
            ArrayList<MotorConfiguration> motors = new ArrayList<MotorConfiguration>();
            for (int motorPortNumber = ModernRoboticsConstants.INITIAL_MOTOR_PORT; motorPortNumber <= ModernRoboticsConstants.NUMBER_OF_MOTORS; motorPortNumber++) {
                motors.add(new MotorConfiguration(motorPortNumber));
            }
            newModule = new MotorControllerConfiguration(name, motors, serialNumber);
            newModule.setPort(port);
        } else if (newType == BuiltInConfigurationType.SERVO_CONTROLLER) {
            ArrayList<ServoConfiguration> servos = new ArrayList<ServoConfiguration>();
            for (int servoPortNumber = ModernRoboticsConstants.INITIAL_SERVO_PORT; servoPortNumber <= ModernRoboticsConstants.NUMBER_OF_SERVOS; servoPortNumber++) {
                servos.add(new ServoConfiguration(servoPortNumber));
            }
            newModule = new ServoControllerConfiguration(name, servos, serialNumber);
            newModule.setPort(port);
        } else if (newType == BuiltInConfigurationType.MATRIX_CONTROLLER) {
            ArrayList<MotorConfiguration> motors = new ArrayList<MotorConfiguration>();
            for (int motorPortNumber = MatrixConstants.INITIAL_MOTOR_PORT; motorPortNumber <= MatrixConstants.NUMBER_OF_MOTORS; motorPortNumber++) {
                motors.add(new MotorConfiguration(motorPortNumber));
            }
            ArrayList<ServoConfiguration> servos = new ArrayList<ServoConfiguration>();
            for (int servoPortNumber = MatrixConstants.INITIAL_SERVO_PORT; servoPortNumber <= MatrixConstants.NUMBER_OF_SERVOS; servoPortNumber++) {
                servos.add(new ServoConfiguration(servoPortNumber));
            }
            newModule = new MatrixControllerConfiguration(name, motors, servos, serialNumber);
            newModule.setPort(port);
        } else {
            newModule = null;
        }
        if (newModule != null) {
            newModule.setEnabled(true);
            setModule(newModule);
        }
    }
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) MotorControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration) ArrayList(java.util.ArrayList) MatrixControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration) SerialNumber(com.qualcomm.robotcore.util.SerialNumber) ServoConfiguration(com.qualcomm.robotcore.hardware.configuration.ServoConfiguration) ServoControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration) MotorControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration) ControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration) ServoControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration) MatrixControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration) MotorConfiguration(com.qualcomm.robotcore.hardware.configuration.MotorConfiguration) DeviceConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceConfiguration)

Example 20 with SerialNumber

use of com.qualcomm.robotcore.util.SerialNumber 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();
            }
        }
    });
}
Also used : SerialNumber(com.qualcomm.robotcore.util.SerialNumber) USBScanManager(com.qualcomm.ftccommon.configuration.USBScanManager) Command(com.qualcomm.robotcore.robocol.Command) ThreadPool(com.qualcomm.robotcore.util.ThreadPool) LynxModuleMetaList(com.qualcomm.robotcore.hardware.LynxModuleMetaList)

Aggregations

SerialNumber (com.qualcomm.robotcore.util.SerialNumber)21 ControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration)6 Map (java.util.Map)6 LynxModuleMetaList (com.qualcomm.robotcore.hardware.LynxModuleMetaList)3 BuiltInConfigurationType (com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType)3 ConfigurationType (com.qualcomm.robotcore.hardware.configuration.ConfigurationType)3 ThreadPool (com.qualcomm.robotcore.util.ThreadPool)3 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 USBScanManager (com.qualcomm.ftccommon.configuration.USBScanManager)2 RobotCoreException (com.qualcomm.robotcore.exception.RobotCoreException)2 DeviceManager (com.qualcomm.robotcore.hardware.DeviceManager)2 MotorControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration)2 ServoControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration)2 HashMap (java.util.HashMap)2 Nullable (android.support.annotation.Nullable)1 ScannedDevices (com.qualcomm.ftccommon.configuration.ScannedDevices)1 HardwareDeviceManager (com.qualcomm.hardware.HardwareDeviceManager)1 LynxModuleMeta (com.qualcomm.robotcore.hardware.LynxModuleMeta)1 RobotCoreLynxUsbDevice (com.qualcomm.robotcore.hardware.RobotCoreLynxUsbDevice)1