Search in sources :

Example 1 with ParameterCatalogue

use of org.yamcs.studio.core.model.ParameterCatalogue in project yamcs-studio by yamcs.

the class ShowPVInfoAction method loadParameterInfoAndShowDialog.

/**
 * Gets detailed information on yamcs parameters. We do this one-by-one,
 * because otherwise we risk having one invalid parameter spoil the whole
 * bunch. Idealy we would rewrite this API a bit on yamcs server, so we
 * avoid the use of a latch.
 */
private void loadParameterInfoAndShowDialog(List<PVInfo> pvInfos) {
    List<PVInfo> yamcsPvs = new ArrayList<>();
    for (PVInfo pvInfo : pvInfos) if (pvInfo.isYamcsParameter())
        yamcsPvs.add(pvInfo);
    // Start a worker thread that will show the dialog when a response for
    // all yamcs parameters arrived
    new Thread() {

        @Override
        public void run() {
            CountDownLatch latch = new CountDownLatch(yamcsPvs.size());
            // Another reason why we should have futures
            for (PVInfo pvInfo : pvInfos) {
                if (!pvInfo.isYamcsParameter()) {
                    latch.countDown();
                    continue;
                }
                ParameterCatalogue catalogue = ParameterCatalogue.getInstance();
                catalogue.requestParameterDetail(pvInfo.getYamcsQualifiedName()).whenComplete((data, exc) -> {
                    if (exc == null) {
                        try {
                            ParameterInfo response = ParameterInfo.parseFrom(data);
                            pvInfo.setParameterInfo(response);
                            latch.countDown();
                        } catch (InvalidProtocolBufferException e) {
                            log.log(Level.SEVERE, "Failed to decode server message", e);
                        }
                    } else {
                        pvInfo.setParameterInfoException(exc.getMessage());
                        latch.countDown();
                    }
                });
            }
            try {
                latch.await();
                targetPart.getSite().getShell().getDisplay().asyncExec(() -> showDialog(pvInfos));
            } catch (InterruptedException e) {
                targetPart.getSite().getShell().getDisplay().asyncExec(() -> {
                    log.log(Level.SEVERE, "Could not fetch Yamcs parameter info", e);
                    MessageDialog.openError(null, "Could Not Fetch Yamcs Parameter Info", "Interrupted while fetching yamcs parameter info");
                });
            }
        }
    }.start();
}
Also used : InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) IAction(org.eclipse.jface.action.IAction) ParameterInfo(org.yamcs.protobuf.Mdb.ParameterInfo) Logger(java.util.logging.Logger) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) ParameterCatalogue(org.yamcs.studio.core.model.ParameterCatalogue) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Collections(java.util.Collections) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IObjectActionDelegate(org.eclipse.ui.IObjectActionDelegate) ParameterCatalogue(org.yamcs.studio.core.model.ParameterCatalogue) ArrayList(java.util.ArrayList) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ParameterInfo(org.yamcs.protobuf.Mdb.ParameterInfo) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 2 with ParameterCatalogue

use of org.yamcs.studio.core.model.ParameterCatalogue in project yamcs-studio by yamcs.

the class YamcsPlugin method start.

@Override
public void start(BundleContext context) throws Exception {
    super.start(context);
    plugin = this;
    TimeEncoding.setUp();
    yamcsClient = new YamcsClient(getProductString(), true);
    yamcsClient.addConnectionListener(new UIConnectionListener());
    ManagementCatalogue managementCatalogue = new ManagementCatalogue();
    catalogues.put(ManagementCatalogue.class, managementCatalogue);
    addYamcsConnectionListener(managementCatalogue);
    registerCatalogue(new TimeCatalogue());
    registerCatalogue(new ParameterCatalogue());
    registerCatalogue(new CommandingCatalogue());
    registerCatalogue(new AlarmCatalogue());
    registerCatalogue(new EventCatalogue());
    registerCatalogue(new LinkCatalogue());
    registerCatalogue(new ArchiveCatalogue());
}
Also used : ManagementCatalogue(org.yamcs.studio.core.model.ManagementCatalogue) YamcsClient(org.yamcs.studio.core.client.YamcsClient) TimeCatalogue(org.yamcs.studio.core.model.TimeCatalogue) ParameterCatalogue(org.yamcs.studio.core.model.ParameterCatalogue) AlarmCatalogue(org.yamcs.studio.core.model.AlarmCatalogue) EventCatalogue(org.yamcs.studio.core.model.EventCatalogue) CommandingCatalogue(org.yamcs.studio.core.model.CommandingCatalogue) LinkCatalogue(org.yamcs.studio.core.model.LinkCatalogue) ArchiveCatalogue(org.yamcs.studio.core.model.ArchiveCatalogue)

Example 3 with ParameterCatalogue

use of org.yamcs.studio.core.model.ParameterCatalogue in project yamcs-studio by yamcs.

the class YamcsVType method getUnits.

@Override
public String getUnits() {
    ParameterCatalogue catalogue = ParameterCatalogue.getInstance();
    String unit = catalogue.getCombinedUnit(pval.getId());
    return (unit == null) ? "" : unit;
}
Also used : ParameterCatalogue(org.yamcs.studio.core.model.ParameterCatalogue)

Aggregations

ParameterCatalogue (org.yamcs.studio.core.model.ParameterCatalogue)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)1 IAction (org.eclipse.jface.action.IAction)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IObjectActionDelegate (org.eclipse.ui.IObjectActionDelegate)1 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)1 ParameterInfo (org.yamcs.protobuf.Mdb.ParameterInfo)1 YamcsClient (org.yamcs.studio.core.client.YamcsClient)1 AlarmCatalogue (org.yamcs.studio.core.model.AlarmCatalogue)1 ArchiveCatalogue (org.yamcs.studio.core.model.ArchiveCatalogue)1 CommandingCatalogue (org.yamcs.studio.core.model.CommandingCatalogue)1