/** * If the given message contains tags, this method can be used * to parse its contents. * @param sampleMsgString the contents of the message */ private void parseMessageWithTags(ByteString sampleMsgString) { logger.info("Tag recorder: got a tag!"); final SvarogProtocol.Tag tagMsg; try { tagMsg = SvarogProtocol.Tag.parseFrom(sampleMsgString); } catch (Exception e) { logger.error("", e); return; } // TODO: By now we ignore field channels and assume that tag if for all channels final double tagLen = tagMsg.getEndTimestamp() - tagMsg.getStartTimestamp(); TagStyle style = tagSet.getStyle(SignalSelectionType.CHANNEL, tagMsg.getName()); if (style == null) { style = stylesGenerator.getSmartStyleFor(tagMsg.getName(), tagLen, -1); tagSet.addStyle(style); } final MonitorTag tag = new MonitorTag(style, tagMsg.getStartTimestamp(), tagLen, -1); for (SvarogProtocol.Variable v : tagMsg.getDesc().getVariablesList()) { if (v.getKey().equals("annotation")) { tag.setAnnotation(v.getValue()); } else { tag.addAttributeToTag(v.getKey(), v.getValue()); } } publish(tag); }
@Override protected void process(List<Object> objs) { for (Object o : objs) { if (o instanceof NewSamplesData) { NewSamplesData data = (NewSamplesData) o; sampleSource.lock(); tagSet.lock(); sampleSource.addSamples(data.getSampleValues()); tagSet.newSample(data.getSamplesTimestamp()); tagSet.unlock(); sampleSource.unlock(); // set first sample timestamp for the tag recorder if (tagRecorderWorker != null && !tagRecorderWorker.isStartRecordingTimestampSet()) { tagRecorderWorker.setStartRecordingTimestamp(data.getSamplesTimestamp()); } // sends chunks to the signal recorder if (signalRecorderWorker != null) { signalRecorderWorker.offerChunk(data.getSampleValues()); if (!signalRecorderWorker.isFirstSampleTimestampSet()) signalRecorderWorker.setFirstSampleTimestamp(data.getSamplesTimestamp()); } } else { MonitorTag tag = (MonitorTag) o; tagSet.lock(); tagSet.addTag(tag); tagSet.unlock(); //record tag if (tagRecorderWorker != null) { tagRecorderWorker.offerTag(tag); } firePropertyChange("newTag", null, (MonitorTag) o); } } }