Search in sources :

Example 21 with Command

use of com.qualcomm.robotcore.robocol.Command in project robotcode by OutoftheBoxFTC.

the class ConfigureFromTemplateActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    this.robotConfigFileManager.updateActiveConfigHeader(this.currentCfgFile);
    if (!remoteConfigure) {
        configurationList = robotConfigFileManager.getXMLFiles();
        templateList = robotConfigFileManager.getXMLTemplates();
        warnIfNoTemplates();
    } else {
        // Ask the RC to send us (the DS) the list of extant configs and templates. Do the configurations
        // first before the templates so that they'll arrive before the user has anything to click on.
        networkConnectionHandler.sendCommand(new Command(CommandList.CMD_REQUEST_CONFIGURATIONS));
        networkConnectionHandler.sendCommand(new Command(CommandList.CMD_REQUEST_CONFIGURATION_TEMPLATES));
    }
    populate();
}
Also used : Command(com.qualcomm.robotcore.robocol.Command)

Example 22 with Command

use of com.qualcomm.robotcore.robocol.Command in project robotcode by OutoftheBoxFTC.

the class ConfigureFromTemplateActivity method getTemplateAndThen.

protected void getTemplateAndThen(final RobotConfigFile templateMeta, final TemplateProcessor processor) {
    if (remoteConfigure) {
        // Look in cache if we have it, otherwise ask for it from RC
        String template = remoteTemplates.get(templateMeta.getName());
        if (template != null) {
            XmlPullParser xmlPullParser = xmlPullParserFromString(template);
            processor.processTemplate(templateMeta, xmlPullParser);
        } else {
            synchronized (receivedConfigProcessors) {
                receivedConfigProcessors.addLast(new StringProcessor() {

                    @Override
                    public void processString(String template) {
                        // Remember it in the cache for next time
                        remoteTemplates.put(templateMeta.getName(), template);
                        // Process it now
                        XmlPullParser xmlPullParser = xmlPullParserFromString(template);
                        processor.processTemplate(templateMeta, xmlPullParser);
                    }
                });
                networkConnectionHandler.sendCommand(new Command(CommandList.CMD_REQUEST_PARTICULAR_CONFIGURATION, templateMeta.toString()));
            }
        }
    } else {
        processor.processTemplate(templateMeta, templateMeta.getXml());
    }
}
Also used : Command(com.qualcomm.robotcore.robocol.Command) XmlPullParser(org.xmlpull.v1.XmlPullParser)

Example 23 with Command

use of com.qualcomm.robotcore.robocol.Command in project robotcode by OutoftheBoxFTC.

the class FtcEventLoop method handleCommandDiscoverLynxModules.

protected void handleCommandDiscoverLynxModules(String extra) throws RobotCoreException, InterruptedException {
    RobotLog.vv(FtcConfigurationActivity.TAG, "handling command DiscoverLynxModules");
    final SerialNumber serialNumber = new SerialNumber(extra);
    final USBScanManager usbScanManager = startUsbScanMangerIfNecessary();
    // Start a scan and wait for it to complete, but if a scan is already in progress, then just wait for that one to finish
    final ThreadPool.SingletonResult<LynxModuleMetaList> future = this.usbScanManager.startLynxModuleEnumerationIfNecessary(serialNumber);
    // Actually carry out the scan in a worker thread so that we don't hold up the receive loop for
    // full second or more that carrying out the discovery will take.
    ThreadPool.getDefault().execute(new Runnable() {

        @Override
        public void run() {
            try {
                LynxModuleMetaList lynxModules = future.await();
                if (lynxModules == null) {
                    lynxModules = new LynxModuleMetaList(serialNumber);
                }
                // Package up the raw module list and send that back to the DS
                String data = usbScanManager.packageCommandResponse(lynxModules);
                RobotLog.vv(FtcConfigurationActivity.TAG, "DiscoverLynxModules data='%s'", data);
                networkConnectionHandler.sendCommand(new Command(CommandList.CMD_DISCOVER_LYNX_MODULES_RESP, data));
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    });
}
Also used : SerialNumber(com.qualcomm.robotcore.util.SerialNumber) USBScanManager(com.qualcomm.ftccommon.configuration.USBScanManager) Command(com.qualcomm.robotcore.robocol.Command) ThreadPool(com.qualcomm.robotcore.util.ThreadPool) LynxModuleMetaList(com.qualcomm.robotcore.hardware.LynxModuleMetaList)

Example 24 with Command

use of com.qualcomm.robotcore.robocol.Command in project robotcode by OutoftheBoxFTC.

the class FtcEventLoopBase method handleCommandRequestInspectionReport.

/**
 * Return an inspection report of this (robot controller) device back to the caller
 */
protected void handleCommandRequestInspectionReport() {
    InspectionState inspectionState = new InspectionState();
    // Modified for OpenRC: Call new initializeForDs method (includes version of OpenRC)
    inspectionState.initializeForDs();
    String serialized = inspectionState.serialize();
    networkConnectionHandler.sendCommand(new Command(CommandList.CMD_REQUEST_INSPECTION_REPORT_RESP, serialized));
}
Also used : Command(com.qualcomm.robotcore.robocol.Command) InspectionState(org.firstinspires.inspection.InspectionState)

Example 25 with Command

use of com.qualcomm.robotcore.robocol.Command in project robotcode by OutoftheBoxFTC.

the class FtcEventLoopBase method sendUIState.

protected void sendUIState() {
    RobotConfigFile configFile = robotCfgFileMgr.getActiveConfig();
    String serialized = configFile.toString();
    networkConnectionHandler.sendCommand(new Command(CommandList.CMD_NOTIFY_ACTIVE_CONFIGURATION, serialized));
    // Send the user device type list
    UserConfigurationTypeManager.getInstance().sendUserDeviceTypes();
    // We might get a request in really soon, before we're fully together. Wait: the driver
    // station doesn't retry if we were to ignore (might not need any more, as we send this
    // state more frequently than we used to)
    this.registeredOpModes.waitOpModesRegistered();
    // Send the opmode list
    String opModeList = SimpleGson.getInstance().toJson(registeredOpModes.getOpModes());
    networkConnectionHandler.sendCommand(new Command(CommandList.CMD_NOTIFY_OP_MODE_LIST, opModeList));
// Subclasses might send other state too
}
Also used : RobotConfigFile(com.qualcomm.ftccommon.configuration.RobotConfigFile) Command(com.qualcomm.robotcore.robocol.Command)

Aggregations

Command (com.qualcomm.robotcore.robocol.Command)25 RobotConfigFile (com.qualcomm.ftccommon.configuration.RobotConfigFile)5 USBScanManager (com.qualcomm.ftccommon.configuration.USBScanManager)2 RobotCoreException (com.qualcomm.robotcore.exception.RobotCoreException)2 ThreadPool (com.qualcomm.robotcore.util.ThreadPool)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ScannedDevices (com.qualcomm.ftccommon.configuration.ScannedDevices)1 LynxModuleMetaList (com.qualcomm.robotcore.hardware.LynxModuleMetaList)1 ControllerConfiguration (com.qualcomm.robotcore.hardware.configuration.ControllerConfiguration)1 ReadXMLFileHandler (com.qualcomm.robotcore.hardware.configuration.ReadXMLFileHandler)1 WriteXMLFileHandler (com.qualcomm.robotcore.hardware.configuration.WriteXMLFileHandler)1 ReadWriteFile (com.qualcomm.robotcore.util.ReadWriteFile)1 SerialNumber (com.qualcomm.robotcore.util.SerialNumber)1 FileFilter (java.io.FileFilter)1 IOException (java.io.IOException)1 CancellationException (java.util.concurrent.CancellationException)1 Pattern (java.util.regex.Pattern)1 CallbackResult (org.firstinspires.ftc.robotcore.internal.network.CallbackResult)1 RecvLoopRunnable (org.firstinspires.ftc.robotcore.internal.network.RecvLoopRunnable)1