/** * Called for each value received from PV. * * <p>Base class remembers the <code>most_recent_value</code>, and asserts that one 'first' sample * is archived. Derived class <b>must</b> call <code>super()</code>. * * @param value Value received from PV * @return true if the value was already written because it's the first value after startup or * error, so there's no need to write that sample again. */ protected boolean handleNewValue(final VType value) { synchronized (this) { ++received_value_count; most_recent_value = value; } // NaN test if (value instanceof VNumber) { if (Double.isNaN(VTypeHelper.toDouble(value))) trouble_sample_log.log("'" + getName() + "': NaN " + VTypeHelper.toString(value)); } if (!enabled) return false; // Did we recover from write errors? if (need_write_error_sample && SampleBuffer.isInErrorState() == false) { need_write_error_sample = false; Activator.getLogger().log(Level.FINE, "Wrote error sample for {0}", getName()); addInfoToBuffer(ValueButcher.createWriteError()); need_first_sample = true; } // Is this the first sample after startup or an error? if (!need_first_sample) return false; need_first_sample = false; // Try to add as-is, but time stamp will be corrected to fit in final VType added = addInfoToBuffer(value); Activator.getLogger() .log(Level.FINE, "Wrote first sample for {0}: {1}", new Object[] {getName(), added}); return true; }
/** Enable or disable groups based on received value */ private final void handleEnablement(final VType value) { if (enablement == Enablement.Passive) throw new Error("Not to be called when passive"); // $NON-NLS-1$ // Get boolean value (true <==> >0.0) final double number = VTypeHelper.toDouble(value); final boolean yes = number > 0.0; // Do we enable or disable based on that value? final boolean enable = enablement == Enablement.Enabling ? yes : !yes; // Check which group needs to _change_ for (ArchiveGroup group : groups) { if (group.isEnabled() != enable) group.enable(enable); } }
/** {@inheritDoc} */ @Override protected void performExport(final IProgressMonitor monitor, final PrintStream out) throws Exception { final DateFormat date_format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS"); int count = 0; for (ModelItem item : model.getItems()) { // Item header if (count > 0) out.println(); printItemInfo(out, item); // Get data monitor.subTask(NLS.bind("Fetching data for {0}", item.getName())); final ValueIterator values = createValueIterator(item); // Dump all values MatlabQualityHelper qualities = new MatlabQualityHelper(); long line_count = 0; out.println("clear t;"); out.println("clear v;"); out.println("clear q;"); while (values.hasNext() && !monitor.isCanceled()) { final VType value = values.next(); ++line_count; // t(1)='2010/03/15 13:30:10.123'; out.println( "t{" + line_count + "}='" + date_format.format(VTypeHelper.getTimestamp(value).toDate()) + "';"); // v(1)=4.125; final double num = VTypeHelper.toDouble(value); if (Double.isNaN(num) || Double.isInfinite(num)) out.println("v(" + line_count + ")=NaN;"); else out.println("v(" + line_count + ")=" + num + ";"); // q(1)=0; out.println( "q(" + line_count + ")=" + qualities.getQualityCode( VTypeHelper.getSeverity(value), VTypeHelper.getMessage(value)) + ";"); if (line_count % PROGRESS_UPDATE_LINES == 0) monitor.subTask(NLS.bind("{0}: Wrote {1} samples", item.getName(), line_count)); } out.println(comment + "Convert time stamps into 'date numbers'"); out.println("tn=datenum(t, 'yyyy/mm/dd HH:MM:SS.FFF');"); out.println(comment + "Prepare patched data because"); out.println(comment + "timeseries() cannot handle duplicate time stamps"); out.println("[xx, idx]=unique(tn, 'last');"); out.println("pt=tn(idx);"); out.println("pv=v(idx);"); out.println("pq=q(idx);"); out.println("clear xx idx"); out.println(comment + "Convert into time series and plot"); // Patch "_" in name because Matlab plot will interprete it as LaTeX sub-script final String channel_name = item.getDisplayName().replace("_", "\\_"); out.println( "channel" + count + "=timeseries(pv', pt', pq', 'IsDatenum', true, 'Name', '" + channel_name + "');"); out.print("channel" + count + ".QualityInfo.Code=["); for (int q = 0; q < qualities.getNumCodes(); ++q) out.print(" " + q); out.println(" ];"); out.print("channel" + count + ".QualityInfo.Description={"); for (int q = 0; q < qualities.getNumCodes(); ++q) out.print(" '" + qualities.getQuality(q) + "'"); out.println(" };"); out.println(); ++count; } out.println(comment + "Example for plotting the data"); for (int i = 0; i < count; ++i) { out.println("subplot(1, " + count + ", " + (i + 1) + ");"); out.println("plot(channel" + i + ");"); } }