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));
}
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();
}
});
}
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();
}
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;
}
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())));
}
Aggregations