use of com.qualcomm.robotcore.util.SerialNumber in project robotcode by OutoftheBoxFTC.
the class FtcEventLoop method getSerialNumberOfUsbDevice.
protected SerialNumber getSerialNumberOfUsbDevice(UsbDevice usbDevice) {
FtDevice ftDevice = null;
SerialNumber serialNumber = null;
try {
// note: we're not supposed to close this
FtDeviceManager manager = FtDeviceManager.getInstance(this.activityContext);
ftDevice = manager.openByUsbDevice(this.activityContext, usbDevice);
if (ftDevice != null) {
serialNumber = new SerialNumber(ftDevice.getDeviceInfo().serialNumber);
}
} catch (RuntimeException | FtDeviceIOException e) {
// RuntimeException is paranoia
// ignored
} finally {
if (ftDevice != null) {
ftDevice.close();
}
}
return serialNumber;
}
use of com.qualcomm.robotcore.util.SerialNumber in project robotcode by OutoftheBoxFTC.
the class ReadXMLFileHandler method handleDeviceInterfaceModule.
private ControllerConfiguration handleDeviceInterfaceModule() throws IOException, XmlPullParserException, RobotCoreException {
String name = parser.getAttributeValue(null, DeviceConfiguration.XMLATTR_NAME);
String serialNumber = parser.getAttributeValue(null, ControllerConfiguration.XMLATTR_SERIAL_NUMBER);
// add empty device configuration objects to the lists.
List<DeviceConfiguration> pwmDevices = buildEmptyDevices(0, ModernRoboticsConstants.NUMBER_OF_PWM_CHANNELS, BuiltInConfigurationType.PULSE_WIDTH_DEVICE);
List<DeviceConfiguration> i2cDevices = buildEmptyDevices(0, ModernRoboticsConstants.NUMBER_OF_I2C_CHANNELS, BuiltInConfigurationType.I2C_DEVICE);
List<DeviceConfiguration> analogInputDevices = buildEmptyDevices(0, ModernRoboticsConstants.NUMBER_OF_ANALOG_INPUTS, BuiltInConfigurationType.ANALOG_INPUT);
List<DeviceConfiguration> digitalDevices = buildEmptyDevices(0, ModernRoboticsConstants.NUMBER_OF_DIGITAL_IOS, BuiltInConfigurationType.DIGITAL_DEVICE);
List<DeviceConfiguration> analogOutputDevices = buildEmptyDevices(0, ModernRoboticsConstants.NUMBER_OF_ANALOG_OUTPUTS, BuiltInConfigurationType.ANALOG_OUTPUT);
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 <DEVICE> </> closing tag
continue;
}
if (DEBUG) {
RobotLog.e("[handleDeviceInterfaceModule] tagname: " + configurationType);
}
if (configurationType == BuiltInConfigurationType.DEVICE_INTERFACE_MODULE) {
// end of loop...
noteExistingName(BuiltInConfigurationType.DEVICE_INTERFACE_MODULE, name);
DeviceInterfaceModuleConfiguration deviceInterfaceModuleConfiguration = new DeviceInterfaceModuleConfiguration(name, new SerialNumber(serialNumber));
deviceInterfaceModuleConfiguration.setPwmOutputs(pwmDevices);
deviceInterfaceModuleConfiguration.setI2cDevices(i2cDevices);
deviceInterfaceModuleConfiguration.setAnalogInputDevices(analogInputDevices);
deviceInterfaceModuleConfiguration.setDigitalDevices(digitalDevices);
deviceInterfaceModuleConfiguration.setAnalogOutputDevices(analogOutputDevices);
deviceInterfaceModuleConfiguration.setEnabled(true);
return deviceInterfaceModuleConfiguration;
}
}
if (eventType == XmlPullParser.START_TAG) {
if (configurationType == BuiltInConfigurationType.ANALOG_INPUT || configurationType == BuiltInConfigurationType.MR_ANALOG_TOUCH_SENSOR || configurationType == BuiltInConfigurationType.OPTICAL_DISTANCE_SENSOR) {
DeviceConfiguration dev = handleDevice();
analogInputDevices.set(dev.getPort(), dev);
}
if (configurationType == BuiltInConfigurationType.PULSE_WIDTH_DEVICE) {
DeviceConfiguration dev = handleDevice();
pwmDevices.set(dev.getPort(), dev);
}
if (configurationType.isDeviceFlavor(UserConfigurationType.Flavor.I2C)) {
DeviceConfiguration dev = handleDevice();
i2cDevices.set(dev.getPort(), dev);
}
if (configurationType == BuiltInConfigurationType.ANALOG_OUTPUT) {
DeviceConfiguration dev = handleDevice();
analogOutputDevices.set(dev.getPort(), dev);
}
if (configurationType == BuiltInConfigurationType.DIGITAL_DEVICE || configurationType == BuiltInConfigurationType.TOUCH_SENSOR || configurationType == BuiltInConfigurationType.LED) {
DeviceConfiguration dev = handleDevice();
digitalDevices.set(dev.getPort(), dev);
}
}
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 ReadXMLFileHandler method handleLynxUsbDevice.
private ControllerConfiguration handleLynxUsbDevice() throws IOException, XmlPullParserException, RobotCoreException {
String name = parser.getAttributeValue(null, DeviceConfiguration.XMLATTR_NAME);
String serialNumber = parser.getAttributeValue(null, ControllerConfiguration.XMLATTR_SERIAL_NUMBER);
String parentModuleAddrAttr = parser.getAttributeValue(null, LynxUsbDeviceConfiguration.XMLATTR_PARENT_MODULE_ADDRESS);
int parentModuleAddress = Integer.parseInt(parentModuleAddrAttr == null ? Integer.toString(LynxUsbDeviceConfiguration.DEFAULT_PARENT_MODULE_ADDRESS) : parentModuleAddrAttr);
List<LynxModuleConfiguration> modules = new LinkedList<LynxModuleConfiguration>();
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 closing tag
continue;
}
if (configurationType == BuiltInConfigurationType.LYNX_USB_DEVICE) {
// end of loop...
noteExistingName(BuiltInConfigurationType.LYNX_USB_DEVICE, name);
LynxUsbDeviceConfiguration newController = new LynxUsbDeviceConfiguration(name, modules, new SerialNumber(serialNumber));
newController.setEnabled(true);
return newController;
}
}
if (eventType == XmlPullParser.START_TAG) {
if (configurationType == BuiltInConfigurationType.LYNX_MODULE) {
LynxModuleConfiguration moduleConfiguration = handleLynxModule(parentModuleAddress);
modules.add(moduleConfiguration);
}
}
eventType = parser.next();
configurationType = deform(parser.getName());
}
LynxUsbDeviceConfiguration newController = new LynxUsbDeviceConfiguration(name, modules, new SerialNumber(serialNumber));
return newController;
}
use of com.qualcomm.robotcore.util.SerialNumber in project robotcode by OutoftheBoxFTC.
the class ReadXMLFileHandler method handleServoController.
private ControllerConfiguration handleServoController(boolean isUsbDevice) throws IOException, XmlPullParserException {
String name = parser.getAttributeValue(null, DeviceConfiguration.XMLATTR_NAME);
// USB devices have serial numbers instead of ports.
int controllerPort = -1;
String serialNumber = new SerialNumber().toString();
if (isUsbDevice) {
serialNumber = parser.getAttributeValue(null, ControllerConfiguration.XMLATTR_SERIAL_NUMBER);
} else {
controllerPort = Integer.parseInt(parser.getAttributeValue(null, DeviceConfiguration.XMLATTR_PORT));
}
List<ServoConfiguration> servos = buildEmptyServos(ModernRoboticsConstants.INITIAL_SERVO_PORT, ModernRoboticsConstants.NUMBER_OF_SERVOS);
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.SERVO_CONTROLLER) {
// end of loop...
noteExistingName(BuiltInConfigurationType.SERVO_CONTROLLER, name);
ServoControllerConfiguration newController = new ServoControllerConfiguration(name, 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);
}
}
eventType = parser.next();
configurationType = deform(parser.getName());
}
ServoControllerConfiguration newController = new ServoControllerConfiguration(name, servos, new SerialNumber(serialNumber));
newController.setPort(controllerPort);
return newController;
}
use of com.qualcomm.robotcore.util.SerialNumber in project robotcode by OutoftheBoxFTC.
the class ReadXMLFileHandler method handleMotorController.
private ControllerConfiguration handleMotorController(boolean isUsbDevice) throws IOException, XmlPullParserException {
String name = parser.getAttributeValue(null, DeviceConfiguration.XMLATTR_NAME);
// USB devices have serial numbers instead of ports.
int controllerPort = -1;
String serialNumber = new SerialNumber().toString();
if (isUsbDevice) {
serialNumber = parser.getAttributeValue(null, ControllerConfiguration.XMLATTR_SERIAL_NUMBER);
} else {
controllerPort = Integer.parseInt(parser.getAttributeValue(null, DeviceConfiguration.XMLATTR_PORT));
}
List<MotorConfiguration> motors = buildEmptyMotors(ModernRoboticsConstants.INITIAL_MOTOR_PORT, ModernRoboticsConstants.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 <MOTOR> </> closing tag
continue;
}
if (configurationType == BuiltInConfigurationType.MOTOR_CONTROLLER) {
// end of loop...
noteExistingName(BuiltInConfigurationType.MOTOR_CONTROLLER, name);
MotorControllerConfiguration newController = new MotorControllerConfiguration(name, motors, new SerialNumber(serialNumber));
newController.setPort(controllerPort);
newController.setEnabled(true);
return newController;
}
}
if (eventType == XmlPullParser.START_TAG) {
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() - ModernRoboticsConstants.INITIAL_MOTOR_PORT, motor);
}
}
eventType = parser.next();
configurationType = deform(parser.getName());
}
MotorControllerConfiguration newController = new MotorControllerConfiguration(name, motors, new SerialNumber(serialNumber));
newController.setPort(controllerPort);
return newController;
}
Aggregations