levelmeter.cpp
1 /***************************************************************************
2  Copyright (C) 2002-2015 Kentaro Kitagawa
3  kitagawa@phys.s.u-tokyo.ac.jp
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  You should have received a copy of the GNU Library General
11  Public License and a list of authors along with this program;
12  see the files COPYING and AUTHORS.
13 ***************************************************************************/
14 #include "levelmeter.h"
15 #include "interface.h"
16 #include "analyzer.h"
17 
18 XLevelMeter::XLevelMeter(const char *name, bool runtime,
19  Transaction &tr_meas, const shared_ptr<XMeasure> &meas) :
20  XPrimaryDriverWithThread(name, runtime, ref(tr_meas), meas) {
21 }
22 void
24 //! impliment form->show() here
25 }
26 
27 void
29  for(unsigned int ch = 0; ch < tr[ *this].m_levels.size(); ch++) {
30  tr[ *this].m_levels[ch] = reader.pop<double>();
31  m_entries[ch]->value(tr, tr[ *this].m_levels[ch]);
32  }
33 }
34 void
36 }
37 
38 void
39 XLevelMeter::createChannels(Transaction &tr_meas, const shared_ptr<XMeasure> &meas,
40  const char **channel_names) {
41  shared_ptr<XScalarEntryList> entries(meas->scalarEntries());
42 
43  for(int i = 0; channel_names[i]; i++) {
44  shared_ptr<XScalarEntry> entry(create<XScalarEntry>(
45  channel_names[i], false,
46  dynamic_pointer_cast<XDriver>(shared_from_this()), "%.4g"));
47  m_entries.push_back(entry);
48  entries->insert(tr_meas, entry);
49  }
50  iterate_commit([=](Transaction &tr){
51  tr[ *this].m_levels.resize(m_entries.size());
52  });
53 }
54 
55 void *
56 XLevelMeter::execute(const atomic<bool> &terminated) {
57  while( !terminated) {
58  msecsleep(100);
59 
60  auto writer = std::make_shared<RawData>();
61  // try/catch exception of communication errors
62  try {
63  unsigned int num = m_entries.size();
64  for(unsigned int ch = 0; ch < num; ch++)
65  writer->push((double)getLevel(ch));
66  }
67  catch (XKameError &e) {
68  e.print(getLabel());
69  continue;
70  }
71 
72  finishWritingRaw(writer, XTime::now(), XTime::now());
73  }
74  return NULL;
75 }

Generated for KAME4 by  doxygen 1.8.3