private ControllerConfiguration parseMatrixController() throws IOException, XmlPullParserException, RobotCoreException { String name = this.parser.getAttributeValue(null, "name"); SerialNumber serialNumber = ControllerConfiguration.NO_SERIAL_NUMBER; int port = Integer.parseInt(this.parser.getAttributeValue(null, "port")); ArrayList<DeviceConfiguration> servoConfigurations = createDeviceConfigurationList(MATRIX_SERVO_PORTS, ConfigurationType.SERVO); ArrayList<DeviceConfiguration> motorConfigurations = createDeviceConfigurationList(MATRIX_MOTOR_PORTS, ConfigurationType.MOTOR); int next = this.parser.next(); ConfigurationType type = getConfigurationType(this.parser.getName()); while (next != XmlPullParser.END_DOCUMENT) { if ((next == XmlPullParser.END_TAG) && (type == ConfigurationType.MATRIX_CONTROLLER)) { ControllerConfiguration matrixControllerConfiguration = new MatrixControllerConfiguration( name, motorConfigurations, servoConfigurations, serialNumber); matrixControllerConfiguration.setPort(port); matrixControllerConfiguration.setEnabled(true); return matrixControllerConfiguration; } else if (next == XmlPullParser.START_TAG) { if ((type == ConfigurationType.SERVO) || (type == ConfigurationType.MOTOR)) { int devicePort = Integer.parseInt(this.parser.getAttributeValue(null, "port")); String deviceName = this.parser.getAttributeValue(null, "name"); DeviceConfiguration deviceConfiguration = new DeviceConfiguration(devicePort, type, deviceName, true); if (type == ConfigurationType.SERVO) { servoConfigurations.set(devicePort - 1, deviceConfiguration); } else { motorConfigurations.set(devicePort - 1, deviceConfiguration); } } } next = this.parser.next(); type = getConfigurationType(this.parser.getName()); } RobotLog.logAndThrow("Reached the end of the XML file while parsing."); return null; }
private ControllerConfiguration parseDeviceInterfaceModule() throws IOException, XmlPullParserException, RobotCoreException { String name = this.parser.getAttributeValue(null, "name"); SerialNumber serialNumber = new SerialNumber(this.parser.getAttributeValue(null, "serialNumber")); ArrayList<DeviceConfiguration> pwdConfigurations = createDeviceConfigurationList(PWD_PORTS, ConfigurationType.PULSE_WIDTH_DEVICE); ArrayList<DeviceConfiguration> i2cConfigurations = createDeviceConfigurationList(I2C_PORTS, ConfigurationType.I2C_DEVICE); ArrayList<DeviceConfiguration> analogInputConfigurations = createDeviceConfigurationList(ANALOG_INPUT_PORTS, ConfigurationType.ANALOG_INPUT); ArrayList<DeviceConfiguration> digitalDeviceConfigurations = createDeviceConfigurationList(DIGITAL_PORTS, ConfigurationType.DIGITAL_DEVICE); ArrayList<DeviceConfiguration> analogOutputConfigurations = createDeviceConfigurationList(ANALOG_OUTPUT_PORTS, ConfigurationType.ANALOG_OUTPUT); int next = this.parser.next(); ConfigurationType type = getConfigurationType(this.parser.getName()); while (next != XmlPullParser.END_DOCUMENT) { if ((next == XmlPullParser.END_TAG) && (type != null)) { if (DEBUG) { RobotLog.e("[handleDeviceInterfaceModule] tagname: " + type); } if (type == ConfigurationType.DEVICE_INTERFACE_MODULE) { DeviceInterfaceModuleConfiguration deviceInterfaceModuleConfiguration = new DeviceInterfaceModuleConfiguration(name, serialNumber); deviceInterfaceModuleConfiguration.setPwmDevices(pwdConfigurations); deviceInterfaceModuleConfiguration.setI2cDevices(i2cConfigurations); deviceInterfaceModuleConfiguration.setAnalogInputDevices(analogInputConfigurations); deviceInterfaceModuleConfiguration.setDigitalDevices(digitalDeviceConfigurations); deviceInterfaceModuleConfiguration.setAnalogOutputDevices(analogOutputConfigurations); deviceInterfaceModuleConfiguration.setEnabled(true); return deviceInterfaceModuleConfiguration; } } if (next == XmlPullParser.START_TAG) { DeviceConfiguration deviceConfiguration; if ((type == ConfigurationType.ANALOG_INPUT) || (type == ConfigurationType.OPTICAL_DISTANCE_SENSOR)) { deviceConfiguration = parseDeviceConfiguration(); analogInputConfigurations.set(deviceConfiguration.getPort(), deviceConfiguration); } if (type == ConfigurationType.PULSE_WIDTH_DEVICE) { deviceConfiguration = parseDeviceConfiguration(); pwdConfigurations.set(deviceConfiguration.getPort(), deviceConfiguration); } if ((type == ConfigurationType.I2C_DEVICE) || (type == ConfigurationType.IR_SEEKER_V3) || (type == ConfigurationType.ADAFRUIT_COLOR_SENSOR) || (type == ConfigurationType.COLOR_SENSOR) || (type == ConfigurationType.GYRO)) { deviceConfiguration = parseDeviceConfiguration(); i2cConfigurations.set(deviceConfiguration.getPort(), deviceConfiguration); } if (type == ConfigurationType.ANALOG_OUTPUT) { deviceConfiguration = parseDeviceConfiguration(); analogOutputConfigurations.set(deviceConfiguration.getPort(), deviceConfiguration); } if ((type == ConfigurationType.DIGITAL_DEVICE) || (type == ConfigurationType.TOUCH_SENSOR) || (type == ConfigurationType.LED)) { DeviceConfiguration c2 = parseDeviceConfiguration(); digitalDeviceConfigurations.set(c2.getPort(), c2); } } next = this.parser.next(); type = getConfigurationType(this.parser.getName()); } RobotLog.logAndThrow("Reached the end of the XML file while parsing."); return null; }