nidas v1.2.3
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
31
32#include <nidas/linux/a2d.h>
33
34#include <vector>
35#include <map>
36#include <set>
37
38
39namespace nidas { namespace dynld {
40
41using namespace nidas::core;
42
46class A2DSensor : public DSMSensor {
47
48public:
49
51
55 A2DSensor(int nchan);
56
57 virtual ~A2DSensor();
58
65 void open(int flags);
66
70 void init();
71
72 /*
73 * Close the device connected to the sensor.
74 *
75 * @throws nidas::util::IOException
76 **/
77 void close();
78
82 void validate();
83
84 void setScanRate(int val) { _scanRate = val; }
85
86 int getScanRate() const { return _scanRate; }
87
94 bool process(const Sample* insamp,std::list<const Sample*>& results) throw();
95
100 int getMaxNumChannels() const { return _maxNumChannels; }
101
107 virtual void setGainBipolar(int ichan,int gain,int bipolar);
108
112 int getGain(int ichan) const
113 {
114 if (ichan < 0 || ichan >= getMaxNumChannels()) return 0;
115 return getFinalConverter()->getGain(ichan);
116 }
117
122 int getBipolar(int ichan) const
123 {
124 if (ichan < 0 || ichan >= getMaxNumChannels()) return -1;
125 return getFinalConverter()->getBipolar(ichan);
126 }
127
133 virtual A2DConverter* getInitialConverter() const = 0;
134
142 virtual A2DConverter* getFinalConverter() const = 0;
143
147 virtual void getDefaultConversion(int chan, float& intercept, float& slope) const = 0;
148
154 void setOutputMode(OutputMode mode) { _outputMode = mode; }
155
157
158protected:
159
161
167
172
180 {
181 public:
183 virtual ~A2DSampleConfig() {}
184 virtual nidas_a2d_sample_config& cfg() { return _cfg; }
185 private:
187 // No copying or assignment
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*)&npts);
205 cfg().nFilterData = sizeof(int);
206 }
207 int npts;
208 private:
209 // No copying or assignment
212 };
213
219 {
220 public:
222 {
223 // make sure there is no padding or extra bytes
224 // between the end of nidas_a2d_sample_config and npts.
225 // The driver C code will interpret npts as filterData[].
226 assert((void*)&(cfg().filterData[0]) == (void*)&rate);
227 cfg().nFilterData = sizeof(int);
228 }
229 int rate;
230 private:
231 // No copying or assignment
234 };
235
236 std::vector<A2DSampleConfig*> _sampleCfgs;
237
243 {
244 public:
246 : nvars(n),nvalues(0),stag(0),channels(nvars) {}
252 {
253 if (&rhs != this) {
254 nvars = rhs.nvars;
255 nvalues = rhs.nvalues;
256 stag = rhs.stag;
257 channels = rhs.channels;
258 }
259 return *this;
260 }
261
263 int nvars;
266 std::vector<int> channels;
267 };
268
269 std::vector<A2DSampleInfo> _sampleInfos;
270
275
276private:
281
283
286
289};
290
291}} // namespace nidas namespace dynld
292
293#endif
Virtual class with methods for performing conversions from integer A2D counts to floating point volta...
Definition A2DConverter.h:61
A class for reading ASCII files containing a time series of calibration data.
Definition CalFile.h:166
DSMSensor provides the basic support for reading, processing and distributing samples from a sensor a...
Definition DSMSensor.h:88
Class describing a group of variables that are sampled and handled together.
Definition SampleTag.h:88
Interface to a data sample.
Definition Sample.h:190
A2D configuration for box-car averaging of A2D samples.
Definition A2DSensor.h:197
A2DBoxcarConfig(const A2DBoxcarConfig &x)
A2DBoxcarConfig(int n)
Definition A2DSensor.h:199
int npts
Definition A2DSensor.h:207
A2DBoxcarConfig & operator=(const A2DBoxcarConfig &rhs)
A2D configuration information that is sent to the A2D device module.
Definition A2DSensor.h:180
virtual nidas_a2d_sample_config & cfg()
Definition A2DSensor.h:184
virtual ~A2DSampleConfig()
Definition A2DSensor.h:183
A2DSampleConfig & operator=(const A2DSampleConfig &rhs)
nidas_a2d_sample_config _cfg
Definition A2DSensor.h:186
A2DSampleConfig(const A2DSampleConfig &x)
A2DSampleConfig()
Definition A2DSensor.h:182
Information needed to intepret the samples that are received from the A2D device.
Definition A2DSensor.h:243
SampleTag * stag
Definition A2DSensor.h:265
std::vector< int > channels
Definition A2DSensor.h:266
~A2DSampleInfo()
Definition A2DSensor.h:262
int nvalues
Definition A2DSensor.h:264
A2DSampleInfo & operator=(const A2DSampleInfo &rhs)
Definition A2DSensor.h:251
A2DSampleInfo(const A2DSampleInfo &x)
Definition A2DSensor.h:247
int nvars
Definition A2DSensor.h:263
A2DSampleInfo(int n)
Definition A2DSensor.h:245
A2D configuration for time-based averaging of A2D samples.
Definition A2DSensor.h:219
A2DTimeAvgConfig(int n)
Definition A2DSensor.h:221
A2DTimeAvgConfig(const A2DTimeAvgConfig &x)
A2DTimeAvgConfig & operator=(const A2DTimeAvgConfig &rhs)
int rate
Definition A2DSensor.h:229
Virtual base class for supporting sensors attached to an A2D.
Definition A2DSensor.h:46
virtual A2DConverter * getInitialConverter() const =0
Initial A2DConverter, which typically contains a default linear conversion from counts to volts based...
void setScanRate(int val)
Definition A2DSensor.h:84
void validate()
Definition A2DSensor.cc:176
size_t _badRawSamples
Counter of number of raw samples of wrong size.
Definition A2DSensor.h:274
int _maxNumChannels
Definition A2DSensor.h:160
void close()
close my associated device.
Definition A2DSensor.cc:66
bool process(const Sample *insamp, std::list< const Sample * > &results)
Create processed A2D samples.
Definition A2DSensor.cc:86
int getBipolar(int ichan) const
Get the polarity parameter for a channel.
Definition A2DSensor.h:122
int getScanRate() const
Definition A2DSensor.h:86
int getMaxNumChannels() const
Return the number of A2D channels on this device, set in the constructor.
Definition A2DSensor.h:100
virtual A2DConverter * getFinalConverter() const =0
Final A2DConverter, updated from the CalFile, and applied after the initial conversion.
OutputMode getOutputMode() const
Definition A2DSensor.h:156
CalFile * _calFile
CalFile for the final A2DConverter.
Definition A2DSensor.h:166
A2DSensor & operator=(const A2DSensor &)
No assignment.
int _prevChan
Definition A2DSensor.h:282
A2DSensor(const A2DSensor &)
No copying.
void setOutputMode(OutputMode mode)
Whether to output samples as counts, volts or engineering units.
Definition A2DSensor.h:154
virtual void getDefaultConversion(int chan, float &intercept, float &slope) const =0
Get the default linear conversion for a channel.
OutputMode
Definition A2DSensor.h:50
@ Engineering
Definition A2DSensor.h:50
@ Counts
Definition A2DSensor.h:50
@ Volts
Definition A2DSensor.h:50
virtual void setGainBipolar(int ichan, int gain, int bipolar)
Set the gain and bipolar parameters for a channel.
Definition A2DSensor.cc:79
A2DSensor(int nchan)
Sub-class constructors know how many channels are on the A2D.
Definition A2DSensor.cc:45
std::vector< A2DSampleConfig * > _sampleCfgs
Definition A2DSensor.h:236
virtual ~A2DSensor()
Definition A2DSensor.cc:55
int _scanRate
Requested A2D sample rate before decimation.
Definition A2DSensor.h:280
void open(int flags)
Open the device connected to the sensor.
Definition A2DSensor.cc:61
void init()
Definition A2DSensor.cc:71
OutputMode _outputMode
Definition A2DSensor.h:171
int getGain(int ichan) const
Get the gain for a channel.
Definition A2DSensor.h:112
std::vector< A2DSampleInfo > _sampleInfos
Definition A2DSensor.h:269
The essential core classes of nidas.
Definition A2DConverter.h:31
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition Sample.cc:70
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31
Information for configuring a sample from an A2D.
Definition a2d.h:72