use of org.firstinspires.ftc.robotcore.internal.network.CallbackResult in project robotcode by OutoftheBoxFTC.
the class FtcEventLoopBase method processCommand.
// ----------------------------------------------------------------------------------------------
// Commands
// ----------------------------------------------------------------------------------------------
@Override
public CallbackResult processCommand(Command command) throws InterruptedException, RobotCoreException {
CallbackResult result = CallbackResult.HANDLED;
String name = command.getName();
String extra = command.getExtra();
if (name.equals(CommandList.CMD_RESTART_ROBOT)) {
handleCommandRestartRobot();
} else if (name.equals(CommandList.CMD_REQUEST_CONFIGURATIONS)) {
handleCommandRequestConfigurations();
} else if (name.equals(CommandList.CMD_REQUEST_REMEMBERED_GROUPS)) {
handleCommandRequestRememberedGroups();
} else if (name.equals(CommandList.CMD_CLEAR_REMEMBERED_GROUPS)) {
handleCommandClearRememberedGroups();
} else if (name.equals(CommandList.CMD_LYNX_FIRMWARE_UPDATE)) {
handleCommandLynxFirmwareUpdate(command);
} else if (name.equals(CommandList.CMD_GET_USB_ACCESSIBLE_LYNX_MODULES)) {
handleCommandGetUSBAccessibleLynxModules(command);
} else if (name.equals(CommandList.CMD_LYNX_ADDRESS_CHANGE)) {
handleCommandLynxChangeModuleAddresses(command);
} else if (name.equals(CommandList.CMD_GET_CANDIDATE_LYNX_FIRMWARE_IMAGES)) {
handleCommandGetCandidateLynxFirmwareImages(command);
} else if (name.equals(CommandList.CMD_REQUEST_INSPECTION_REPORT)) {
handleCommandRequestInspectionReport();
} else if (name.equals(CommandList.CMD_DISCONNECT_FROM_WIFI_DIRECT)) {
handleCommandDisconnectWifiDirect();
} else if (name.equals(CommandList.CMD_REQUEST_CONFIGURATION_TEMPLATES)) {
handleCommandRequestConfigurationTemplates();
} else if (name.equals(CommandList.CMD_REQUEST_PARTICULAR_CONFIGURATION)) {
handleCommandRequestParticularConfiguration(extra);
} else if (name.equals(CommandList.CMD_ACTIVATE_CONFIGURATION)) {
handleCommandActivateConfiguration(extra);
} else if (name.equals(CommandList.CMD_REQUEST_UI_STATE)) {
sendUIState();
} else if (name.equals(CommandList.CMD_SAVE_CONFIGURATION)) {
handleCommandSaveConfiguration(extra);
} else if (name.equals(CommandList.CMD_DELETE_CONFIGURATION)) {
handleCommandDeleteConfiguration(extra);
} else if (name.equals(CommandList.CMD_START_PROGRAMMING_MODE)) {
handleCommandStartProgrammingMode();
} else if (name.equals(CommandList.CMD_START_DS_PROGRAM_AND_MANAGE)) {
handleCommandStartDriverStationProgramAndManage();
} else if (name.equals(CommandList.CMD_STOP_PROGRAMMING_MODE)) {
handleCommandStopProgrammingMode();
} else if (name.equals(CommandList.CMD_SHOW_TOAST)) {
handleCommandShowToast(command);
} else if (name.equals(CommandList.CMD_SHOW_DIALOG)) {
handleCommandShowDialog(command);
} else if (name.equals(CommandList.CMD_DISMISS_DIALOG)) {
handleCommandDismissDialog(command);
} else if (name.equals(CommandList.CMD_DISMISS_ALL_DIALOGS)) {
handleCommandDismissAllDialogs(command);
} else if (name.equals(CommandList.CMD_SHOW_PROGRESS)) {
handleCommandShowProgress(command);
} else if (name.equals(CommandList.CMD_DISMISS_PROGRESS)) {
handleCommandDismissProgress(command);
} else if (name.equals(CommandList.CMD_ROBOT_CONTROLLER_PREFERENCE)) {
result = PreferenceRemoterRC.getInstance().handleCommandRobotControllerPreference(extra);
} else {
result = CallbackResult.NOT_HANDLED;
}
return result;
}
use of org.firstinspires.ftc.robotcore.internal.network.CallbackResult 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 org.firstinspires.ftc.robotcore.internal.network.CallbackResult in project robotcode by OutoftheBoxFTC.
the class FtcConfigurationActivity method commandEvent.
@Override
public CallbackResult commandEvent(Command command) {
CallbackResult result = CallbackResult.NOT_HANDLED;
try {
String name = command.getName();
String extra = command.getExtra();
if (name.equals(CommandList.CMD_SCAN_RESP)) {
result = handleCommandScanResp(extra);
} else if (name.equals(CommandList.CMD_DISCOVER_LYNX_MODULES_RESP)) {
result = handleCommandDiscoverLynxModulesResp(extra);
} else if (name.equals(CommandList.CMD_REQUEST_PARTICULAR_CONFIGURATION_RESP)) {
result = handleCommandRequestParticularConfigurationResp(extra);
}
} catch (RobotCoreException e) {
RobotLog.logStacktrace(e);
}
return result;
}
use of org.firstinspires.ftc.robotcore.internal.network.CallbackResult in project robotcode by OutoftheBoxFTC.
the class FtcLoadFileActivity method commandEvent.
// ------------------------------------------------------------------------------------------------
// Remote handling
// ------------------------------------------------------------------------------------------------
@Override
public CallbackResult commandEvent(Command command) {
CallbackResult result = CallbackResult.NOT_HANDLED;
try {
String name = command.getName();
String extra = command.getExtra();
if (name.equals(CommandList.CMD_REQUEST_CONFIGURATIONS_RESP)) {
result = handleCommandRequestConfigFilesResp(extra);
} else if (name.equals(CommandList.CMD_NOTIFY_ACTIVE_CONFIGURATION)) {
result = handleCommandNotifyActiveConfig(extra);
}
} catch (RobotCoreException e) {
RobotLog.logStacktrace(e);
}
return result;
}
use of org.firstinspires.ftc.robotcore.internal.network.CallbackResult in project robotcode by OutoftheBoxFTC.
the class FtcRobotControllerService method onNetworkConnectionEvent.
@Override
public CallbackResult onNetworkConnectionEvent(NetworkConnection.Event event) {
CallbackResult result = CallbackResult.NOT_HANDLED;
switch(event) {
case CONNECTED_AS_GROUP_OWNER:
RobotLog.ii(TAG, "Wifi Direct - connected as group owner");
if (!NetworkConnection.isDeviceNameValid(networkConnection.getDeviceName())) {
RobotLog.ee(TAG, "Network Connection device name contains non-printable characters");
ConfigWifiDirectActivity.launch(getBaseContext(), ConfigWifiDirectActivity.Flag.WIFI_DIRECT_DEVICE_NAME_INVALID);
result = CallbackResult.HANDLED;
}
break;
case CONNECTED_AS_PEER:
RobotLog.ee(TAG, "Wifi Direct - connected as peer, was expecting Group Owner");
ConfigWifiDirectActivity.launch(getBaseContext(), ConfigWifiDirectActivity.Flag.WIFI_DIRECT_FIX_CONFIG);
result = CallbackResult.HANDLED;
break;
case CONNECTION_INFO_AVAILABLE:
RobotLog.ii(TAG, "Network Connection Passphrase: " + networkConnection.getPassphrase());
// modified for turbo: don't start the webserver here
break;
case ERROR:
RobotLog.ee(TAG, "Network Connection Error: " + networkConnection.getFailureReason());
break;
case AP_CREATED:
RobotLog.ii(TAG, "Network Connection created: " + networkConnection.getConnectionOwnerName());
default:
break;
}
updateNetworkConnectionStatus(event);
return result;
}
Aggregations