Search in sources :

Example 1 with Command

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

the class FtcEventLoop method handleCommandScan.

/**
 * @see FtcConfigurationActivity#doUSBScanAndUpdateUI()
 */
protected void handleCommandScan(String extra) throws RobotCoreException, InterruptedException {
    RobotLog.vv(FtcConfigurationActivity.TAG, "handling command SCAN");
    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<ScannedDevices> future = usbScanManager.startDeviceScanIfNecessary();
    // Actually carry out the scan in a worker thread so that we don't hold up the receive loop for
    // half-second or so that carrying out the scan will take.
    ThreadPool.getDefault().execute(new Runnable() {

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

Example 2 with Command

use of com.qualcomm.robotcore.robocol.Command 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 3 with Command

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

the class FtcEventLoopBase method handleCommandRequestConfigurations.

/**
 * Serialize the entire list of config file metadata and send to the driver station
 */
protected void handleCommandRequestConfigurations() {
    ArrayList<RobotConfigFile> fileList = robotCfgFileMgr.getXMLFiles();
    String objsSerialized = RobotConfigFileManager.serializeXMLConfigList(fileList);
    networkConnectionHandler.sendCommand(new Command(CommandList.CMD_REQUEST_CONFIGURATIONS_RESP, objsSerialized));
}
Also used : RobotConfigFile(com.qualcomm.ftccommon.configuration.RobotConfigFile) Command(com.qualcomm.robotcore.robocol.Command)

Example 4 with Command

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

the class FtcEventLoopBase method handleCommandRequestRememberedGroups.

/**
 * Serialize the list of remembered Wifi Direct groups and send it to the driver station
 */
protected void handleCommandRequestRememberedGroups() {
    WifiDirectPersistentGroupManager manager = new WifiDirectPersistentGroupManager(WifiDirectAgent.getInstance());
    String serialized = WifiDirectGroupName.serializeNames(manager.getPersistentGroups());
    networkConnectionHandler.sendCommand(new Command(CommandList.CMD_REQUEST_REMEMBERED_GROUPS_RESP, serialized));
}
Also used : Command(com.qualcomm.robotcore.robocol.Command) WifiDirectPersistentGroupManager(org.firstinspires.ftc.robotcore.internal.network.WifiDirectPersistentGroupManager)

Example 5 with Command

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

the class FtcEventLoopBase method handleCommandGetCandidateLynxFirmwareImages.

protected void handleCommandGetCandidateLynxFirmwareImages(Command commandRequest) {
    // We return the full path to files with a .bin extension, case insensitive
    final Pattern pattern = Pattern.compile("(?i).*\\.bin");
    // We look for files in the file system on the robot controller
    File firmwareDir = AppUtil.LYNX_FIRMWARE_UPDATE_DIR;
    File[] candidateFiles = firmwareDir.listFiles(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            Assert.assertTrue(pathname.isAbsolute());
            return pattern.matcher(pathname.getName()).matches();
        }
    });
    CommandList.LynxFirmwareImagesResp respParams = new CommandList.LynxFirmwareImagesResp();
    respParams.firstFolder = AppUtil.FIRST_FOLDER;
    for (File candidate : candidateFiles) {
        respParams.firmwareImages.add(new CommandList.FWImage(candidate, false));
    }
    // We also look for files in our assets
    try {
        File fromBase = new File(firmwareDir.getParentFile().getName(), firmwareDir.getName());
        String[] firmwareAssets = activityContext.getAssets().list(fromBase.getPath());
        for (String firmwareAsset : firmwareAssets) {
            if (pattern.matcher(firmwareAsset).matches()) {
                File file = new File(fromBase, firmwareAsset);
                Assert.assertTrue(!file.isAbsolute());
                respParams.firmwareImages.add(new CommandList.FWImage(file, true));
            }
        }
    } catch (IOException ignore) {
    }
    // Return all those, unsorted
    networkConnectionHandler.sendReply(commandRequest, new Command(CommandList.CMD_GET_CANDIDATE_LYNX_FIRMWARE_IMAGES_RESP, respParams.serialize()));
}
Also used : Pattern(java.util.regex.Pattern) RobotCoreCommandList(org.firstinspires.ftc.robotcore.internal.network.RobotCoreCommandList) IOException(java.io.IOException) Command(com.qualcomm.robotcore.robocol.Command) FileFilter(java.io.FileFilter) ReadWriteFile(com.qualcomm.robotcore.util.ReadWriteFile) RobotConfigFile(com.qualcomm.ftccommon.configuration.RobotConfigFile) File(java.io.File)

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