Search in sources :

Example 1 with IssueCommandRequest

use of org.yamcs.protobuf.Rest.IssueCommandRequest in project yamcs-studio by yamcs.

the class ArmCommandHandler method armCommand.

private void armCommand(Shell activeShell, CommandStackView view, StackedCommand command) throws ExecutionException {
    IssueCommandRequest req = command.toIssueCommandRequest().setDryRun(true).build();
    CommandingCatalogue catalogue = CommandingCatalogue.getInstance();
    String qname;
    try {
        qname = command.getSelectedAliasEncoded();
    } catch (UnsupportedEncodingException e1) {
        throw new ExecutionException(e1.getMessage());
    }
    catalogue.sendCommand("realtime", qname, req).whenComplete((data, exc) -> {
        if (exc == null) {
            Display.getDefault().asyncExec(() -> {
                boolean doArm = false;
                SignificanceInfo significance = command.getMetaCommand().getSignificance();
                switch(significance.getConsequenceLevel()) {
                    case WATCH:
                    case WARNING:
                    case DISTRESS:
                    case CRITICAL:
                    case SEVERE:
                        String level = Character.toUpperCase(significance.getConsequenceLevel().toString().charAt(0)) + significance.getConsequenceLevel().toString().substring(1);
                        if (MessageDialog.openConfirm(activeShell, "Confirm", level + ": Are you sure you want to arm this command?\n" + "    " + command.toStyledString(view).getString() + "\n\n" + significance.getReasonForWarning())) {
                            doArm = true;
                        }
                        break;
                    case NONE:
                        doArm = true;
                        break;
                    default:
                        throw new IllegalStateException("Unexpected significance level " + significance.getConsequenceLevel());
                }
                if (doArm) {
                    log.info(String.format("Command armed %s", command));
                    command.setStackedState(StackedState.ARMED);
                    view.refreshState();
                }
            });
        } else {
            Display.getDefault().asyncExec(() -> {
                command.setStackedState(StackedState.REJECTED);
                view.clearArm();
                view.refreshState();
            });
        }
    });
}
Also used : SignificanceInfo(org.yamcs.protobuf.Mdb.SignificanceInfo) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CommandingCatalogue(org.yamcs.studio.core.model.CommandingCatalogue) ExecutionException(org.eclipse.core.commands.ExecutionException) IssueCommandRequest(org.yamcs.protobuf.Rest.IssueCommandRequest)

Example 2 with IssueCommandRequest

use of org.yamcs.protobuf.Rest.IssueCommandRequest in project yamcs-studio by yamcs.

the class IssueCommandHandler method issueCommand.

private void issueCommand(Shell activeShell, CommandStackView view, StackedCommand command) throws ExecutionException {
    IssueCommandRequest req = command.toIssueCommandRequest().build();
    CommandingCatalogue catalogue = CommandingCatalogue.getInstance();
    String qname;
    try {
        qname = command.getSelectedAliasEncoded();
    } catch (UnsupportedEncodingException e1) {
        throw new ExecutionException(e1.getMessage());
    }
    catalogue.sendCommand("realtime", qname, req).whenComplete((data, exc) -> {
        if (exc == null) {
            Display.getDefault().asyncExec(() -> {
                log.info(String.format("Command issued. %s", req));
                command.setStackedState(StackedState.ISSUED);
                view.selectActiveCommand();
                view.refreshState();
            });
        } else {
            Display.getDefault().asyncExec(() -> {
                command.setStackedState(StackedState.REJECTED);
                view.refreshState();
            });
        }
    });
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) CommandingCatalogue(org.yamcs.studio.core.model.CommandingCatalogue) ExecutionException(org.eclipse.core.commands.ExecutionException) IssueCommandRequest(org.yamcs.protobuf.Rest.IssueCommandRequest)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 IssueCommandRequest (org.yamcs.protobuf.Rest.IssueCommandRequest)2 CommandingCatalogue (org.yamcs.studio.core.model.CommandingCatalogue)2 SignificanceInfo (org.yamcs.protobuf.Mdb.SignificanceInfo)1