Search in sources :

Example 6 with SerialNumber

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

the class ReadXMLFileHandler method handleMatrixController.

private ControllerConfiguration handleMatrixController() throws IOException, XmlPullParserException, RobotCoreException {
    String name = parser.getAttributeValue(null, DeviceConfiguration.XMLATTR_NAME);
    // USB devices have serial numbers instead of ports.
    String serialNumber = new SerialNumber().toString();
    int controllerPort = Integer.parseInt(parser.getAttributeValue(null, DeviceConfiguration.XMLATTR_PORT));
    List<ServoConfiguration> servos = buildEmptyServos(MatrixConstants.INITIAL_SERVO_PORT, MatrixConstants.NUMBER_OF_SERVOS, BuiltInConfigurationType.SERVO);
    List<MotorConfiguration> motors = buildEmptyMotors(MatrixConstants.INITIAL_MOTOR_PORT, MatrixConstants.NUMBER_OF_MOTORS, MotorConfigurationType.getUnspecifiedMotorType());
    int eventType = parser.next();
    ConfigurationType configurationType = deform(parser.getName());
    while (eventType != XmlPullParser.END_DOCUMENT) {
        // we shouldn't reach the end of the document here anyway...
        if (eventType == XmlPullParser.END_TAG) {
            if (configurationType == null) {
                // just an empty <SERVO> </> closing tag
                continue;
            }
            if (configurationType == BuiltInConfigurationType.MATRIX_CONTROLLER) {
                // end of loop...
                noteExistingName(BuiltInConfigurationType.MATRIX_CONTROLLER, name);
                MatrixControllerConfiguration newController = new MatrixControllerConfiguration(name, motors, servos, new SerialNumber(serialNumber));
                newController.setPort(controllerPort);
                newController.setEnabled(true);
                return newController;
            }
        }
        if (eventType == XmlPullParser.START_TAG) {
            if (configurationType == BuiltInConfigurationType.SERVO || configurationType == BuiltInConfigurationType.CONTINUOUS_ROTATION_SERVO) {
                ServoConfiguration servo = handleServo(configurationType);
                // ModernRobotics HW is indexed by 1, but internally this code indexes by 0.
                servos.set(servo.getPort() - 1, servo);
            } else if (configurationType.isDeviceFlavor(UserConfigurationType.Flavor.MOTOR)) {
                MotorConfiguration motor = handleMotor();
                // ModernRobotics HW is indexed by 1, but internally this code indexes by 0.
                motors.set(motor.getPort() - 1, motor);
            }
        }
        eventType = parser.next();
        configurationType = deform(parser.getName());
    }
    // we should never reach the end of the document while parsing this part. If we do, it's an error.
    RobotLog.logAndThrow("Reached the end of the XML file while parsing.");
    return null;
}
Also used : SerialNumber(com.qualcomm.robotcore.util.SerialNumber)

Example 7 with SerialNumber

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

the class RobotUsbManagerCombining method getDeviceSerialNumberByIndex.

@Override
public synchronized SerialNumber getDeviceSerialNumberByIndex(final int initialIndex) throws RobotCoreException {
    int index = initialIndex;
    for (ManagerInfo info : managers) {
        if (index < info.scanCount) {
            // Remember who served up which serial numbers so we know who to ask to open again later
            SerialNumber serialNumber = info.manager.getDeviceSerialNumberByIndex(index);
            enumeratedSerialNumbers.put(serialNumber, info);
            return serialNumber;
        }
        index -= info.scanCount;
    }
    throw new IndexOutOfBoundsException("index too large: " + initialIndex);
}
Also used : SerialNumber(com.qualcomm.robotcore.util.SerialNumber)

Example 8 with SerialNumber

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

the class EditUSBDeviceActivity method completeSwapConfiguration.

protected boolean completeSwapConfiguration(int requestCodeValue, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        RequestCode requestCode = RequestCode.fromValue(requestCodeValue);
        if (requestCode == EditSwapUsbDevices.requestCode) {
            // Find out whom the user picked to swap with. Be careful about object identities
            EditParameters returnedParameters = EditParameters.fromIntent(this, data);
            SerialNumber swappeeSerialNumber = ((ControllerConfiguration) returnedParameters.getConfiguration()).getSerialNumber();
            ControllerConfiguration swappee = getRobotConfigMap().get(swappeeSerialNumber);
            if (swappee != null) {
                // He swapped with something already in the configuration
                robotConfigMap.swapSerialNumbers(controllerConfiguration, swappee);
            } else {
                // He must have swapped with an extra device
                robotConfigMap.setSerialNumber(controllerConfiguration, swappeeSerialNumber);
                controllerConfiguration.setKnownToBeAttached(true);
            }
            // Adjust 'extraDevices' to accommodate the swap
            determineExtraUSBDevices();
            // Update the UI
            refreshAfterSwap();
            return true;
        }
    }
    return false;
}
Also used : SerialNumber(com.qualcomm.robotcore.util.SerialNumber) ControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration)

Example 9 with SerialNumber

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

the class EditUSBDeviceActivity method isSwappable.

protected boolean isSwappable() {
    List<ControllerConfiguration> swapCandidates = getRobotConfigMap().getEligibleSwapTargets(controllerConfiguration, scannedDevices, this);
    SerialNumber fixCandidate = getFixableCandidate();
    // We need swap candidates, but not just the one that we'd automatically 'fix' to
    return !swapCandidates.isEmpty() && (fixCandidate == null || !(swapCandidates.size() == 1 && swapCandidates.get(0).getSerialNumber().equals(fixCandidate)));
}
Also used : SerialNumber(com.qualcomm.robotcore.util.SerialNumber) ControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration)

Example 10 with SerialNumber

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

the class EditUSBDeviceActivity method getFixableCandidate.

@Nullable
protected SerialNumber getFixableCandidate() {
    SerialNumber candidate = null;
    // If it's already attached, no fixing is needed
    if (controllerConfiguration.isKnownToBeAttached()) {
        return null;
    }
    boolean isFixable = false;
    DeviceManager.DeviceType deviceType = controllerConfiguration.toUSBDeviceType();
    // Match up extraDevices by type
    for (Map.Entry<SerialNumber, DeviceManager.DeviceType> pair : extraUSBDevices.entrySet()) {
        if (pair.getValue() == deviceType) {
            if (candidate != null) {
                // More than one candidate: ambiguous
                isFixable = false;
                break;
            }
            // Found a first candidate: fixable
            candidate = pair.getKey();
            isFixable = true;
        }
    }
    return isFixable ? candidate : null;
}
Also used : SerialNumber(com.qualcomm.robotcore.util.SerialNumber) DeviceManager(com.qualcomm.robotcore.hardware.DeviceManager) Map(java.util.Map) Nullable(android.support.annotation.Nullable)

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