nidas  v1.2-1520
A2DSensor.h
Go to the documentation of this file.
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2 // vim: set shiftwidth=4 softtabstop=4 expandtab:
3 /*
4  ********************************************************************
5  ** NIDAS: NCAR In-situ Data Acquistion Software
6  **
7  ** 2007, Copyright University Corporation for Atmospheric Research
8  **
9  ** This program is free software; you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation; either version 2 of the License, or
12  ** (at your option) any later version.
13  **
14  ** This program is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** The LICENSE.txt file accompanying this software contains
20  ** a copy of the GNU General Public License. If it is not found,
21  ** write to the Free Software Foundation, Inc.,
22  ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  **
24  ********************************************************************
25 */
26 #ifndef NIDAS_DYNLD_A2DSENSOR_H
27 #define NIDAS_DYNLD_A2DSENSOR_H
28 
29 #include <nidas/core/DSMSensor.h>
30 
31 #include <nidas/linux/a2d.h>
32 
33 #include <vector>
34 #include <map>
35 #include <set>
36 
37 
38 namespace nidas { namespace dynld {
39 
40 using namespace nidas::core;
41 
45 class A2DSensor : public DSMSensor {
46 
47 public:
48 
49  A2DSensor();
50  ~A2DSensor();
51 
55  void open(int flags) throw(nidas::util::IOException,
57 
58  void init() throw(nidas::util::InvalidParameterException);
59 
60  /*
61  * Close the device connected to the sensor.
62  */
63  void close() throw(nidas::util::IOException);
64 
65  void validate() throw(nidas::util::InvalidParameterException);
66 
67  void setScanRate(int val) { _scanRate = val; }
68 
69  int getScanRate() const { return _scanRate; }
70 
71  bool process(const Sample* insamp,std::list<const Sample*>& results) throw();
72 
78  virtual int getMaxNumChannels() const = 0;
79 
88  virtual void setA2DParameters(int ichan,int gain,int bipolar)
90 
94  virtual void getA2DParameters(int ichan,int& gain,int& bipolar) const;
95 
99  int getGain(int ichan) const;
100 
105  int getBipolar(int ichan) const;
106 
113  virtual void getBasicConversion(int ichan,float& intercept, float& slope) const = 0;
114 
120  virtual void setConversionCorrection(int ichan,float intercept,
121  float slope) throw(nidas::util::InvalidParameterException);
122 
123 
127  void getConversion(int ichan,float& intercept, float& slope) const;
128 
133  float getSlope(int ichan) const
134  {
135  if (ichan < 0 || ichan >= _maxNChannels) return floatNAN;
136  return _convSlopes[ichan];
137  }
138 
143  float getIntercept(int ichan) const
144  {
145  if (ichan < 0 || ichan >= _maxNChannels) return floatNAN;
146  return _convIntercepts[ichan];
147  }
148 
149 protected:
150 
158  {
159  public:
160  A2DSampleConfig(): _cfg() {}
161  virtual ~A2DSampleConfig() {}
162  virtual nidas_a2d_sample_config& cfg() { return _cfg; }
163  private:
165  // No copying or assignment
167  A2DSampleConfig& operator=(const A2DSampleConfig& rhs);
168  };
169 
175  {
176  public:
178  {
179  // make sure there is no padding or extra bytes
180  // between the end of nidas_a2d_sample_config and npts.
181  // The driver C code will interpret npts as filterData[].
182  assert((void*)&(cfg().filterData[0]) == (void*)&npts);
183  cfg().nFilterData = sizeof(int);
184  }
185  int npts;
186  private:
187  // No copying or assignment
189  A2DBoxcarConfig& operator=(const A2DBoxcarConfig& rhs);
190  };
191 
197  {
198  public:
200  {
201  // make sure there is no padding or extra bytes
202  // between the end of nidas_a2d_sample_config and npts.
203  // The driver C code will interpret npts as filterData[].
204  assert((void*)&(cfg().filterData[0]) == (void*)&rate);
205  cfg().nFilterData = sizeof(int);
206  }
207  int rate;
208  private:
209  // No copying or assignment
211  A2DTimeAvgConfig& operator=(const A2DTimeAvgConfig& rhs);
212  };
213 
214  std::vector<A2DSampleConfig*> _sampleCfgs;
215 
221  {
222  public:
224  : nvars(n),nvalues(0),stag(0),channels(nvars) {}
225  A2DSampleInfo(const A2DSampleInfo& x): nvars(x.nvars),nvalues(x.nvalues),
226  stag(x.stag),channels(x.channels)
227  {
228  }
229  A2DSampleInfo& operator= (const A2DSampleInfo& rhs)
230  {
231  if (&rhs != this) {
232  nvars = rhs.nvars;
233  nvalues = rhs.nvalues;
234  stag = rhs.stag;
235  channels = rhs.channels;
236  }
237  return *this;
238  }
239 
241  int nvars;
242  int nvalues;
244  std::vector<int> channels;
245  };
246 
247  std::vector<A2DSampleInfo> _sampleInfos;
248 
253 
254 protected:
255  void initParameters();
256 
258 
266  float* _convSlopes;
267 
275 
276 private:
281 
283 
284  int* _gains;
285 
286  int* _bipolars;
287 
289  A2DSensor(const A2DSensor&);
290 
292  A2DSensor& operator=(const A2DSensor&);
293 };
294 
295 }} // namespace nidas namespace dynld
296 
297 #endif
A2D configuration information that is sent to the A2D device module.
Definition: A2DSensor.h:157
A2DBoxcarConfig(int n)
Definition: A2DSensor.h:177
A2DSampleConfig()
Definition: A2DSensor.h:160
SampleTag * stag
Definition: A2DSensor.h:243
std::vector< A2DSampleInfo > _sampleInfos
Definition: A2DSensor.h:247
float * _convIntercepts
Conversion offset for each A2D channel when converting from A2D counts to voltage.
Definition: A2DSensor.h:274
float getIntercept(int ichan) const
Get the current conversion intercept, which includes any correction as set by setConversionCorrection...
Definition: A2DSensor.h:143
std::vector< int > channels
Definition: A2DSensor.h:244
float * _convSlopes
Conversion factor for each channel when converting from A2D counts to voltage.
Definition: A2DSensor.h:266
int _scanRate
Requested A2D sample rate before decimation.
Definition: A2DSensor.h:280
int _prevChan
Definition: A2DSensor.h:282
nidas_a2d_sample_config _cfg
Definition: A2DSensor.h:164
~A2DSampleInfo()
Definition: A2DSensor.h:240
A2D configuration for box-car averaging of A2D samples.
Definition: A2DSensor.h:174
const float floatNAN
Value of a float NAN for general use.
Definition: Sample.cc:31
int _maxNChannels
Definition: A2DSensor.h:257
int npts
Definition: A2DSensor.h:185
float getSlope(int ichan) const
Get the current conversion slope, which includes any correction as set by setConversionCorrection().
Definition: A2DSensor.h:133
Information for configuring a sample from an A2D.
Definition: a2d.h:71
A2D configuration for time-based averaging of A2D samples.
Definition: A2DSensor.h:196
std::vector< A2DSampleConfig * > _sampleCfgs
Definition: A2DSensor.h:214
A2DSampleInfo(int n)
Definition: A2DSensor.h:223
Information needed to intepret the samples that are received from the A2D device. ...
Definition: A2DSensor.h:220
size_t _badRawSamples
Counter of number of raw samples of wrong size.
Definition: A2DSensor.h:252
A2DSampleInfo(const A2DSampleInfo &x)
Definition: A2DSensor.h:225
Interface to a data sample.
Definition: Sample.h:189
DSMSensor provides the basic support for reading, processing and distributing samples from a sensor a...
Definition: DSMSensor.h:87
static float rate
Definition: sing.cc:53
Definition: IOException.h:37
A2DTimeAvgConfig(int n)
Definition: A2DSensor.h:199
Class describing a group of variables that are sampled and handled together.
Definition: SampleTag.h:87
int getScanRate() const
Definition: A2DSensor.h:69
One or more sensors connected to an A2D.
Definition: A2DSensor.h:45
int * _bipolars
Definition: A2DSensor.h:286
int nvalues
Definition: A2DSensor.h:242
int rate
Definition: A2DSensor.h:207
int * _gains
Definition: A2DSensor.h:284
void setScanRate(int val)
Definition: A2DSensor.h:67
int nvars
Definition: A2DSensor.h:241
virtual ~A2DSampleConfig()
Definition: A2DSensor.h:161
virtual nidas_a2d_sample_config & cfg()
Definition: A2DSensor.h:162
Definition: InvalidParameterException.h:35