Search in sources :

Example 6 with Command

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

the class FtcEventLoopBase method handleCommandRequestConfigurationTemplates.

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

Example 7 with Command

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

the class FtcLynxFirmwareUpdateActivity method onUpdateLynxFirmwareClicked.

// ----------------------------------------------------------------------------------------------
// UI interaction
// ----------------------------------------------------------------------------------------------
public void onUpdateLynxFirmwareClicked(View view) {
    // A second push is meaningless once we've entered fw update mode once
    enableUpdateButton = false;
    view.setEnabled(enableUpdateButton);
    // We're running on the UI thread here (of course). And the execution of the command
    // will need to put up dialogs, which means we can't be stuck here inside this method while
    // we do that. So we do the updating in a worker.
    ThreadPool.getDefault().execute(new Runnable() {

        @Override
        public void run() {
            for (USBAccessibleLynxModule module : modulesToUpdate) {
                availableFWUpdateResps.clear();
                RobotLog.vv(TAG, "updating %s with %s", module.getSerialNumber(), firmwareImageFile.getName());
                CommandList.LynxFirmwareUpdate params = new CommandList.LynxFirmwareUpdate();
                params.serialNumber = module.getSerialNumber();
                params.firmwareImageFile = firmwareImageFile;
                sendOrInject(new Command(CommandList.CMD_LYNX_FIRMWARE_UPDATE, SimpleGson.getInstance().toJson(params)));
                CommandList.LynxFirmwareUpdateResp respParams = awaitResponse(availableFWUpdateResps, null, 30, TimeUnit.SECONDS);
                if (respParams != null && respParams.success) {
                    String message = getString(R.string.toastLynxFirmwareUpdateSuccessful, module.getSerialNumber());
                    RobotLog.vv(TAG, "%s", message);
                    AppUtil.getInstance().showToast(UILocation.BOTH, message);
                } else {
                    String message = getString(R.string.alertLynxFirmwareUpdateFailed, module.getSerialNumber());
                    RobotLog.ee(TAG, "%s", message);
                    AppUtil.DialogContext alertDialogContext = AppUtil.getInstance().showAlertDialog(UILocation.BOTH, getString(R.string.alertLynxFirmwareUpdateFailedTitle), message);
                    try {
                        alertDialogContext.dismissed.await();
                        break;
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                    }
                    break;
                }
            }
            FtcLynxFirmwareUpdateActivity.this.finish();
        }
    });
}
Also used : Command(com.qualcomm.robotcore.robocol.Command) RecvLoopRunnable(org.firstinspires.ftc.robotcore.internal.network.RecvLoopRunnable)

Example 8 with Command

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

the class FtcLynxModuleAddressUpdateActivity method onDoneButtonPressed.

public void onDoneButtonPressed(View view) {
    RobotLog.vv(TAG, "onDoneButtonPressed()");
    ArrayList<CommandList.LynxAddressChangeRequest.AddressChange> modulesToChange = new ArrayList<CommandList.LynxAddressChangeRequest.AddressChange>();
    for (USBAccessibleLynxModule module : currentModules) {
        DisplayedModule displayedModule = displayedModuleList.from(module.getSerialNumber());
        if (displayedModule.getStartingAddress() != displayedModule.getCurrentAddress()) {
            CommandList.LynxAddressChangeRequest.AddressChange addressChange = new CommandList.LynxAddressChangeRequest.AddressChange();
            addressChange.serialNumber = displayedModule.getSerialNumber();
            addressChange.oldAddress = displayedModule.getStartingAddress();
            addressChange.newAddress = displayedModule.getCurrentAddress();
            modulesToChange.add(addressChange);
        }
    }
    if (currentModules.size() > 0) {
        if (modulesToChange.size() > 0) {
            CommandList.LynxAddressChangeRequest request = new CommandList.LynxAddressChangeRequest();
            request.modulesToChange = modulesToChange;
            sendOrInject(new Command(CommandList.CMD_LYNX_ADDRESS_CHANGE, request.serialize()));
        } else {
            AppUtil.getInstance().showToast(UILocation.BOTH, getString(R.string.toastLynxAddressChangeNothingToDo));
        }
    }
    finishOk();
}
Also used : Command(com.qualcomm.robotcore.robocol.Command) ArrayList(java.util.ArrayList)

Example 9 with Command

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

the class EventLoopManager method commandEvent.

@Override
public CallbackResult commandEvent(Command command) throws RobotCoreException {
    // called on RecvRunnable.run() thread
    CallbackResult result = CallbackResult.NOT_HANDLED;
    // check if it's in the cache to avoid duplicate executions
    for (Command c : commandRecvCache) {
        if (c != null && c.equals(command)) {
            // no need to continue, just return now
            return CallbackResult.HANDLED;
        }
    }
    // cache the command
    commandRecvCache[(commandRecvCachePosition++) % commandRecvCache.length] = command;
    // start or stop the event loop while it's busy processing a command
    try {
        synchronized (eventLoopLock) {
            result = eventLoop.processCommand(command);
        }
    } catch (Exception e) {
        // we should catch everything, since we don't know what the event loop might throw
        RobotLog.ee(TAG, e, "Event loop threw an exception while processing a command");
    }
    return result;
}
Also used : Command(com.qualcomm.robotcore.robocol.Command) CallbackResult(org.firstinspires.ftc.robotcore.internal.network.CallbackResult) RobotCoreException(com.qualcomm.robotcore.exception.RobotCoreException) CancellationException(java.util.concurrent.CancellationException)

Example 10 with Command

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

the class EventLoopManager method changeState.

private void changeState(@NonNull RobotState state) {
    this.state = state;
    RobotLog.v("EventLoopManager state is " + state.toString());
    if (callback != null) {
        callback.onStateChange(state);
    }
    // Keep the DS informed of robot state in a timely way. See also Heartbeat & TelemetryMessage
    networkConnectionHandler.sendCommand(new Command(RobotCoreCommandList.CMD_NOTIFY_ROBOT_STATE, Integer.toString(state.asByte())));
}
Also used : 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