Search in sources :

Example 1 with ReadXMLFileHandler

use of com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler in project robotcode by OutoftheBoxFTC.

the class FtcEventLoopBase method handleCommandRequestParticularConfiguration.

/*
     * The driver station wants the contents of the configuration file.
     */
protected void handleCommandRequestParticularConfiguration(String data) {
    RobotConfigFile file = robotCfgFileMgr.getConfigFromString(data);
    ReadXMLFileHandler parser = new ReadXMLFileHandler();
    if (file.isNoConfig()) {
        // don't try to parse if there's no file
        return;
    }
    try {
        WriteXMLFileHandler writeXMLFileHandler = new WriteXMLFileHandler(activityContext);
        ArrayList<ControllerConfiguration> deviceList = (ArrayList<ControllerConfiguration>) parser.parse(file.getXml());
        String xmlData = writeXMLFileHandler.toXml(deviceList);
        RobotLog.vv(FtcConfigurationActivity.TAG, "FtcEventLoop: handleCommandRequestParticularConfigFile, data: " + xmlData);
        networkConnectionHandler.sendCommand(new Command(CommandList.CMD_REQUEST_PARTICULAR_CONFIGURATION_RESP, xmlData));
    } catch (RobotCoreException e) {
        e.printStackTrace();
    }
}
Also used : ReadXMLFileHandler(com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler) RobotConfigFile(com.qualcomm.ftccommon.configuration.RobotConfigFile) Command(com.qualcomm.robotcore.robocol.Command) ArrayList(java.util.ArrayList) RobotCoreException(com.qualcomm.robotcore.exception.RobotCoreException) ControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration) WriteXMLFileHandler(com.qualcomm.robotcore.hardware.configuration.WriteXMLFileHandler)

Example 2 with ReadXMLFileHandler

use of com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler in project robotcode by OutoftheBoxFTC.

the class FtcConfigurationActivity method handleCommandRequestParticularConfigurationResp.

protected CallbackResult handleCommandRequestParticularConfigurationResp(String extra) throws RobotCoreException {
    ReadXMLFileHandler readXMLFileHandler = new ReadXMLFileHandler();
    List<ControllerConfiguration> controllerList = readXMLFileHandler.parse(new StringReader(extra));
    buildControllersFromXMLResults(controllerList);
    populateListAndWarnDevices();
    return CallbackResult.HANDLED;
}
Also used : ReadXMLFileHandler(com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler) StringReader(java.io.StringReader) 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)

Example 3 with ReadXMLFileHandler

use of com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler in project robotcode by OutoftheBoxFTC.

the class HardwareFactory method createHardwareMap.

// ------------------------------------------------------------------------------------------------
// Hardware management
// ------------------------------------------------------------------------------------------------
/**
 * Create a hardware map
 *
 * @return HardwareMap
 */
public HardwareMap createHardwareMap(EventLoopManager manager) throws RobotCoreException, InterruptedException {
    // We synchronize with scanning so that there's only one thread trying to open *new* FTDI devices at a time
    synchronized (HardwareDeviceManager.scanDevicesLock) {
        RobotLog.vv(TAG, "createHardwareMap()");
        // Clear notion of embedded lynx module that we currently have. We'll discovery a new one,
        // if he's there, when we go through the below.
        WifiDirectInviteDialogMonitor.clearUILynxModule();
        HardwareMap map = new HardwareMap(context);
        if (xmlPullParser != null) {
            DeviceManager deviceMgr = new HardwareDeviceManager(context, manager);
            ReadXMLFileHandler readXmlFileHandler = new ReadXMLFileHandler();
            List<ControllerConfiguration> ctrlConfList = readXmlFileHandler.parse(xmlPullParser);
            for (ControllerConfiguration ctrlConf : ctrlConfList) {
                ConfigurationType type = ctrlConf.getConfigurationType();
                if (type == BuiltInConfigurationType.MOTOR_CONTROLLER) {
                    mapUsbMotorController(map, deviceMgr, (MotorControllerConfiguration) ctrlConf);
                } else if (type == BuiltInConfigurationType.SERVO_CONTROLLER) {
                    mapUsbServoController(map, deviceMgr, (ServoControllerConfiguration) ctrlConf);
                } else if (type == BuiltInConfigurationType.LEGACY_MODULE_CONTROLLER) {
                    mapUsbLegacyModule(map, deviceMgr, (LegacyModuleControllerConfiguration) ctrlConf);
                } else if (type == BuiltInConfigurationType.DEVICE_INTERFACE_MODULE) {
                    mapCoreInterfaceDeviceModule(map, deviceMgr, (DeviceInterfaceModuleConfiguration) ctrlConf);
                } else if (type == BuiltInConfigurationType.LYNX_USB_DEVICE) {
                    mapLynxUsbDevice(map, deviceMgr, (LynxUsbDeviceConfiguration) ctrlConf);
                } else {
                    RobotLog.ee(TAG, "Unexpected controller type while parsing XML: " + type.toString());
                }
            }
        } else {
            // no XML to parse, just return empty map
            RobotLog.vv(TAG, "no xml to parse: using empty map");
        }
        return map;
    }
}
Also used : ConfigurationType(com.qualcomm.robotcore.hardware.configuration.ConfigurationType) BuiltInConfigurationType(com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType) UserConfigurationType(com.qualcomm.robotcore.hardware.configuration.UserConfigurationType) HardwareMap(com.qualcomm.robotcore.hardware.HardwareMap) ReadXMLFileHandler(com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler) DeviceInterfaceModuleConfiguration(com.qualcomm.robotcore.hardware.configuration.DeviceInterfaceModuleConfiguration) ServoControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration) DeviceManager(com.qualcomm.robotcore.hardware.DeviceManager) 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) MatrixControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration)

Example 4 with ReadXMLFileHandler

use of com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler in project robotcode by OutoftheBoxFTC.

the class FtcConfigurationActivity method readFile.

/**
 * This method parses the XML of the active configuration file, and calls methods to populate
 * the appropriate data structures to the configuration information can be displayed to the
 * user.
 */
private void readFile() {
    try {
        XmlPullParser xmlPullParser = currentCfgFile.getXml();
        if (xmlPullParser == null) {
            throw new RobotCoreException("can't access configuration");
        }
        // 
        ReadXMLFileHandler parser = new ReadXMLFileHandler();
        List<ControllerConfiguration> controllerList = parser.parse(xmlPullParser);
        buildControllersFromXMLResults(controllerList);
        populateListAndWarnDevices();
    // 
    } catch (Exception e) {
        String message = String.format(getString(R.string.errorParsingConfiguration), currentCfgFile.getName());
        RobotLog.ee(TAG, e, message);
        appUtil.showToast(UILocation.ONLY_LOCAL, context, message);
    }
}
Also used : ReadXMLFileHandler(com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler) XmlPullParser(org.xmlpull.v1.XmlPullParser) 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) DuplicateNameException(com.qualcomm.robotcore.exception.DuplicateNameException) RobotCoreException(com.qualcomm.robotcore.exception.RobotCoreException) IOException(java.io.IOException)

Example 5 with ReadXMLFileHandler

use of com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler in project robotcode by OutoftheBoxFTC.

the class ConfigureFromTemplateActivity method instantiateTemplate.

RobotConfigMap instantiateTemplate(RobotConfigFile templateMeta, XmlPullParser xmlPullParser) throws RobotCoreException {
    awaitScannedDevices();
    // 
    ReadXMLFileHandler readXMLFileHandler = new ReadXMLFileHandler();
    List<ControllerConfiguration> controllerList = readXMLFileHandler.parse(xmlPullParser);
    RobotConfigMap robotConfigMap = new RobotConfigMap(controllerList);
    robotConfigMap.bindUnboundControllers(scannedDevices);
    // 
    return robotConfigMap;
}
Also used : ReadXMLFileHandler(com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler) ControllerConfiguration(com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration)

Aggregations

ControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration)5 ReadXMLFileHandler (com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler)5 LegacyModuleControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.LegacyModuleControllerConfiguration)3 MotorControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.MotorControllerConfiguration)3 ServoControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.ServoControllerConfiguration)3 RobotCoreException (com.qualcomm.robotcore.exception.RobotCoreException)2 RobotConfigFile (com.qualcomm.ftccommon.configuration.RobotConfigFile)1 DuplicateNameException (com.qualcomm.robotcore.exception.DuplicateNameException)1 DeviceManager (com.qualcomm.robotcore.hardware.DeviceManager)1 HardwareMap (com.qualcomm.robotcore.hardware.HardwareMap)1 BuiltInConfigurationType (com.qualcomm.robotcore.hardware.configuration.BuiltInConfigurationType)1 ConfigurationType (com.qualcomm.robotcore.hardware.configuration.ConfigurationType)1 DeviceInterfaceModuleConfiguration (com.qualcomm.robotcore.hardware.configuration.DeviceInterfaceModuleConfiguration)1 MatrixControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.MatrixControllerConfiguration)1 UserConfigurationType (com.qualcomm.robotcore.hardware.configuration.UserConfigurationType)1 WriteXMLFileHandler (com.qualcomm.robotcore.hardware.configuration.WriteXMLFileHandler)1 Command (com.qualcomm.robotcore.robocol.Command)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1