dso.h
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 //---------------------------------------------------------------------------
15 
16 #ifndef dsoH
17 #define dsoH
18 //---------------------------------------------------------------------------
19 #include "primarydriverwiththread.h"
20 #include "xnodeconnector.h"
21 #include <complex>
22 
23 class XScalarEntry;
24 class FIR;
25 class XSG;
26 
27 class QMainWindow;
28 class Ui_FrmDSO;
30 #include "xwavengraph.h"
31 
32 //! Base class for digital storage oscilloscope.
33 class DECLSPEC_SHARED XDSO : public XPrimaryDriverWithThread {
34 public:
35  XDSO(const char *name, bool runtime,
36  Transaction &tr_meas, const shared_ptr<XMeasure> &meas);
37  //! usually nothing to do.
38  virtual ~XDSO() {}
39  //! Shows all forms belonging to driver.
40  virtual void showForms();
41 protected:
42  //! This function will be called when raw data are written.
43  //! Implement this function to convert the raw data to the record (Payload).
44  //! \sa analyze()
45  virtual void analyzeRaw(RawDataReader &reader, Transaction &tr) throw (XRecordError&);
46  //! This function is called after committing XPrimaryDriver::analyzeRaw() or XSecondaryDriver::analyze().
47  //! This might be called even if the record is invalid (time() == false).
48  virtual void visualize(const Snapshot &shot);
49 
50  //! driver specific part below
51 public:
52  const shared_ptr<XUIntNode> &average() const {return m_average;}
53  //! If true, an acquisition will be paused with a averaging count.
54  const shared_ptr<XBoolNode> &singleSequence() const {return m_singleSequence;}
55  const shared_ptr<XComboNode> &trigSource() const {return m_trigSource;}
56  const shared_ptr<XDoubleNode> &trigPos() const {return m_trigPos;}
57  const shared_ptr<XDoubleNode> &trigLevel() const {return m_trigLevel;}
58  const shared_ptr<XBoolNode> &trigFalling() const {return m_trigFalling;}
59  const shared_ptr<XDoubleNode> &timeWidth() const {return m_timeWidth;}
60  const shared_ptr<XComboNode> &vFullScale1() const {return m_vFullScale1;}
61  const shared_ptr<XComboNode> &vFullScale2() const {return m_vFullScale2;}
62  const shared_ptr<XComboNode> &vFullScale3() const {return m_vFullScale3;}
63  const shared_ptr<XComboNode> &vFullScale4() const {return m_vFullScale4;}
64  const shared_ptr<XDoubleNode> &vOffset1() const {return m_vOffset1;}
65  const shared_ptr<XDoubleNode> &vOffset2() const {return m_vOffset2;}
66  const shared_ptr<XDoubleNode> &vOffset3() const {return m_vOffset3;}
67  const shared_ptr<XDoubleNode> &vOffset4() const {return m_vOffset4;}
68  const shared_ptr<XUIntNode> &recordLength() const {return m_recordLength;}
69  const shared_ptr<XTouchableNode> &forceTrigger() const {return m_forceTrigger;}
70  const shared_ptr<XTouchableNode> &restart() const {return m_restart;}
71 
72  const shared_ptr<XComboNode> &trace1() const {return m_trace1;}
73  const shared_ptr<XComboNode> &trace2() const {return m_trace2;}
74  const shared_ptr<XComboNode> &trace3() const {return m_trace3;}
75  const shared_ptr<XComboNode> &trace4() const {return m_trace4;}
76 
77  const shared_ptr<XComboNode> &fetchMode() const {return m_fetchMode;}
78 
79  const shared_ptr<XBoolNode> &firEnabled() const {return m_firEnabled;}
80  const shared_ptr<XDoubleNode> &firBandWidth() const {return m_firBandWidth;} ///< [kHz]
81  const shared_ptr<XDoubleNode> &firCenterFreq() const {return m_firCenterFreq;} ///< [kHz]
82  const shared_ptr<XDoubleNode> &firSharpness() const {return m_firSharpness;}
83 
84  enum DRFMODE {DRFMODE_OFF = 0, DRFMODE_GIVEN_FREQ = 1, DRFMODE_FREQ_BY_SG = 2, DRFMODE_COHERENT_SG = 3};
85  const shared_ptr<XComboNode> &dRFMode() const {return m_dRFMode;}
86  const shared_ptr<XItemNode<XDriverList, XSG> > &dRFSG() const {return m_dRFSG;}
87  const shared_ptr<XDoubleNode> &dRFFreq() const {return m_dRFFreq;}
88 
89  struct DECLSPEC_SHARED Payload : public XPrimaryDriver::Payload {
90  Payload() : m_rawDisplayOnly(false), m_numChannelsDisp(0) {}
91  double trigPos() const {return m_trigPos;} ///< unit is interval
92  unsigned int numChannels() const {return m_numChannels;}
93  double timeInterval() const {return m_timeInterval;} //! [sec]
94  unsigned int length() const;
95  const double *wave(unsigned int ch) const;
96 
97  void setParameters(unsigned int channels, double startpos, double interval, unsigned int length);
98  //! For displaying.
99  unsigned int lengthDisp() const;
100  double *waveDisp(unsigned int ch);
101  const double *waveDisp(unsigned int ch) const;
102  double trigPosDisp() const {return m_trigPosDisp;} ///< unit is interval
103  unsigned int numChannelsDisp() const {return m_numChannelsDisp;}
104  double timeIntervalDisp() const {return m_timeIntervalDisp;} //! [sec]
105  private:
106  friend class XDSO;
107  double m_trigPos; ///< unit is interval
108  unsigned int m_numChannels;
109  double m_timeInterval; //! [sec]
110  std::vector<double> m_waves;
111 
112  //! for displaying.
113  bool m_rawDisplayOnly; ///< flag for skipping to record.
114  double m_trigPosDisp; ///< unit is interval
115  unsigned int m_numChannelsDisp;
116  double m_timeIntervalDisp; //! [sec]
117  std::vector<double> m_wavesDisp;
118 
119  shared_ptr<FIR> m_fir;
120  shared_ptr<std::vector<std::complex<double> > > m_dRFRefWave; ///< exp(i omega t)
121  };
122 protected:
123  virtual void onTrace1Changed(const Snapshot &shot, XValueNodeBase *) = 0;
124  virtual void onTrace2Changed(const Snapshot &shot, XValueNodeBase *) = 0;
125  virtual void onTrace3Changed(const Snapshot &shot, XValueNodeBase *) = 0;
126  virtual void onTrace4Changed(const Snapshot &shot, XValueNodeBase *) = 0;
127  virtual void onAverageChanged(const Snapshot &shot, XValueNodeBase *) = 0;
128  virtual void onSingleChanged(const Snapshot &shot, XValueNodeBase *) = 0;
129  virtual void onTrigSourceChanged(const Snapshot &shot, XValueNodeBase *) = 0;
130  virtual void onTrigPosChanged(const Snapshot &shot, XValueNodeBase *) = 0;
131  virtual void onTrigLevelChanged(const Snapshot &shot, XValueNodeBase *) = 0;
132  virtual void onTrigFallingChanged(const Snapshot &shot, XValueNodeBase *) = 0;
133  virtual void onTimeWidthChanged(const Snapshot &shot, XValueNodeBase *) = 0;
134  virtual void onVFullScale1Changed(const Snapshot &shot, XValueNodeBase *) = 0;
135  virtual void onVFullScale2Changed(const Snapshot &shot, XValueNodeBase *) = 0;
136  virtual void onVFullScale3Changed(const Snapshot &shot, XValueNodeBase *) = 0;
137  virtual void onVFullScale4Changed(const Snapshot &shot, XValueNodeBase *) = 0;
138  virtual void onVOffset1Changed(const Snapshot &shot, XValueNodeBase *) = 0;
139  virtual void onVOffset2Changed(const Snapshot &shot, XValueNodeBase *) = 0;
140  virtual void onVOffset3Changed(const Snapshot &shot, XValueNodeBase *) = 0;
141  virtual void onVOffset4Changed(const Snapshot &shot, XValueNodeBase *) = 0;
142  virtual void onRecordLengthChanged(const Snapshot &shot, XValueNodeBase *) = 0;
143  virtual void onForceTriggerTouched(const Snapshot &shot, XTouchableNode *) = 0;
144  virtual void onRestartTouched(const Snapshot &shot, XTouchableNode *);
145 
146  virtual double getTimeInterval() = 0;
147 
148  //! Clears the count or starts a sequence measurement
149  virtual void startSequence() = 0;
150 
151  //! \param seq_busy true if the sequence is not finished.
152  virtual int acqCount(bool *seq_busy) = 0;
153 
154  //! Loads waveforms and settings from the instrument.
155  virtual void getWave(shared_ptr<RawData> &writer, std::deque<XString> &channels) = 0;
156  //! Converts the raw to a display-able style.
157  //! In the coherent SG mode, real and imaginary parts should be stored in \a Payload::waveDisp().
158  virtual void convertRaw(RawDataReader &reader, Transaction &tr) throw (XRecordError&) = 0;
159 
160  virtual bool isDRFCoherentSGSupported() const {return false;}
161 
162  //! Calculates RF phase for coherent detection, at given count.
163  double phaseOfRF(const Snapshot &shot_of_this, uint64_t count, double interval);
164 
165  const shared_ptr<XStatusPrinter> &statusPrinter() const {return m_statusPrinter;}
166 
167  shared_ptr<XListener> m_lsnOnTrigSourceChanged;
168 private:
169  enum {FETCHMODE_NEVER = 0, FETCHMODE_AVG = 1, FETCHMODE_SEQ = 2};
170 
171  const shared_ptr<XWaveNGraph> &waveForm() const {return m_waveForm;}
172 
173  const shared_ptr<XUIntNode> m_average;
174  //! If true, pause acquision after averaging count
175  const shared_ptr<XBoolNode> m_singleSequence;
176  const shared_ptr<XComboNode> m_trigSource;
177  const shared_ptr<XBoolNode> m_trigFalling;
178  const shared_ptr<XDoubleNode> m_trigPos;
179  const shared_ptr<XDoubleNode> m_trigLevel;
180  const shared_ptr<XDoubleNode> m_timeWidth;
181  const shared_ptr<XComboNode> m_vFullScale1;
182  const shared_ptr<XComboNode> m_vFullScale2;
183  const shared_ptr<XComboNode> m_vFullScale3;
184  const shared_ptr<XComboNode> m_vFullScale4;
185  const shared_ptr<XDoubleNode> m_vOffset1;
186  const shared_ptr<XDoubleNode> m_vOffset2;
187  const shared_ptr<XDoubleNode> m_vOffset3;
188  const shared_ptr<XDoubleNode> m_vOffset4;
189  const shared_ptr<XUIntNode> m_recordLength;
190  const shared_ptr<XTouchableNode> m_forceTrigger;
191  const shared_ptr<XTouchableNode> m_restart;
192  const shared_ptr<XComboNode> m_trace1;
193  const shared_ptr<XComboNode> m_trace2;
194  const shared_ptr<XComboNode> m_trace3;
195  const shared_ptr<XComboNode> m_trace4;
196  const shared_ptr<XComboNode> m_fetchMode;
197  const shared_ptr<XBoolNode> m_firEnabled;
198  const shared_ptr<XDoubleNode> m_firBandWidth; ///< [kHz]
199  const shared_ptr<XDoubleNode> m_firCenterFreq; ///< [kHz]
200  const shared_ptr<XDoubleNode> m_firSharpness;
201 
202  const shared_ptr<XComboNode> m_dRFMode;
203  const shared_ptr<XItemNode<XDriverList, XSG> > m_dRFSG;
204  const shared_ptr<XDoubleNode> m_dRFFreq;
205 
206  const qshared_ptr<FrmDSO> m_form;
207  const shared_ptr<XWaveNGraph> m_waveForm;
208 
209  //! Converts the raw to a display-able style and performs extra digital processing.
210  void convertRawToDisp(RawDataReader &reader, Transaction &tr) throw (XRecordError&);
211  //! Digital direct conversion.
212  void demodulateDisp(Transaction &tr) throw (XRecordError&);
213 
214  shared_ptr<XListener> m_lsnOnSingleChanged;
215  shared_ptr<XListener> m_lsnOnAverageChanged;
216  shared_ptr<XListener> m_lsnOnTrigPosChanged;
217  shared_ptr<XListener> m_lsnOnTrigLevelChanged;
218  shared_ptr<XListener> m_lsnOnTrigFallingChanged;
219  shared_ptr<XListener> m_lsnOnTimeWidthChanged;
220  shared_ptr<XListener> m_lsnOnTrace1Changed;
221  shared_ptr<XListener> m_lsnOnTrace2Changed;
222  shared_ptr<XListener> m_lsnOnTrace3Changed;
223  shared_ptr<XListener> m_lsnOnTrace4Changed;
224  shared_ptr<XListener> m_lsnOnVFullScale1Changed;
225  shared_ptr<XListener> m_lsnOnVFullScale2Changed;
226  shared_ptr<XListener> m_lsnOnVFullScale3Changed;
227  shared_ptr<XListener> m_lsnOnVFullScale4Changed;
228  shared_ptr<XListener> m_lsnOnVOffset1Changed;
229  shared_ptr<XListener> m_lsnOnVOffset2Changed;
230  shared_ptr<XListener> m_lsnOnVOffset3Changed;
231  shared_ptr<XListener> m_lsnOnVOffset4Changed;
232  shared_ptr<XListener> m_lsnOnRecordLengthChanged;
233  shared_ptr<XListener> m_lsnOnForceTriggerTouched;
234  shared_ptr<XListener> m_lsnOnRestartTouched;
235  shared_ptr<XListener> m_lsnOnCondChanged;
236  shared_ptr<XListener> m_lsnOnDRFCondChanged;
237 
238  void onCondChanged(const Snapshot &shot, XValueNodeBase *);
239  void onDRFCondChanged(const Snapshot &shot, XValueNodeBase *);
240 
241  std::deque<xqcon_ptr> m_conUIs;
242 
243  const shared_ptr<XStatusPrinter> m_statusPrinter;
244 
245  void *execute(const atomic<bool> &);
246 
247  static const char *s_trace_names[];
248  static const unsigned int s_trace_colors[];
249 
250  atomic<XTime> m_timeSequenceStarted;
251 };
252 
253 //---------------------------------------------------------------------------
254 
255 #endif

Generated for KAME4 by  doxygen 1.8.3