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;
}
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);
}
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;
}
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)));
}
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;
}
Aggregations