nidas  v1.2-1520
A2D_Serial.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  ** 2008, 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 
27 #ifndef _nidas_dynld_raf_a2d_serial_h_
28 #define _nidas_dynld_raf_a2d_serial_h_
29 
31 
33 
34 
35 // change this later to a const or something
36 #define NUM_A2D_CHANNELS 4
37 
38 
39 namespace nidas { namespace dynld { namespace raf {
40 
41 using namespace nidas::core;
42 
49 class A2D_Serial : public SerialSensor
50 {
51 
52 public:
53  enum OutputMode { Counts, Volts, Engineering };
54 
55  A2D_Serial();
56  ~A2D_Serial();
57 
61  void open(int flags) throw(nidas::util::IOException);
62 
66  void init() throw(nidas::util::InvalidParameterException);
67 
68  virtual Sample* nextSample()
69  {
71 
72  if (samp) {
73  const char *input = (const char *)samp->getConstVoidDataPtr();
74  if (input[0] == 'H') // header packet
75  extractStatus(input, samp->getDataByteLength());
76  }
77  return samp;
78  }
79 
80  void extractStatus(const char *msg, int len);
81 
82  void printStatus(std::ostream& ostr) throw();
83 
84 
85  bool process(const Sample* samp,std::list<const Sample*>& results)
86  throw();
87 
88  void validate() throw(nidas::util::InvalidParameterException);
89 
90  int getMaxNumChannels() const { return NUM_A2D_CHANNELS; }
91 
95  int getGain(int ichan) const;
96 
101  int getBipolar(int ichan) const;
102 
107  virtual void setConversionCorrection(int ichan, const float d[],
109 
110  void setOutputMode(OutputMode mode) { _outputMode = mode; }
111 
112  OutputMode getOutputMode() const { return _outputMode; }
113 
114 
115 protected:
119  void readConfig() throw(nidas::util::IOException);
120 
124  void parseConfigLine(const char *data);
125 
126  void dumpConfig() const;
127 
128 
133  bool checkCkSum(const Sample *samp, const char *data);
134 
138  bool samplingChannel(int channel) const;
139 
144  void readCalFile(dsm_time_t tt) throw();
145 
150  float applyCalibration(float value, const std::vector<float> &cals) const;
151 
152 
156  int _nVars;
157 
158  size_t _sampleRate;
159 
163  size_t _deltaT; // in usecs
164 
170  size_t _staticLag; // in usecs.
171 
172  int _boardID; // serial number
173  bool _haveCkSum; // Will packets have checksum
174 
179  CalFile *_calFile;
180 
186  OutputMode _outputMode;
187 
194  size_t _havePPS;
195 
201  int _channels[NUM_A2D_CHANNELS];
202 
203  // read these in from XML, use to validate against
204  int _ifsr[NUM_A2D_CHANNELS]; // 0 = +-10, 1 = +-5 Vdc
205  int _ipol[NUM_A2D_CHANNELS];
206 
207  // We will need these to map to cal files.
208  int _gains[NUM_A2D_CHANNELS]; // map _ifsr to this; 0->1, 1->2
209  int _polarity[NUM_A2D_CHANNELS]; // true
210 
211 
219  std::map<std::string, int> configStatus;
220 
221  // A/D calibration coefficients
222  std::vector<float> _polyCals[NUM_A2D_CHANNELS];
223 
224  size_t _shortPacketCnt;
225  size_t _badCkSumCnt;
226  size_t _largeTimeStampOffset;
227 
228 int headerLines;
229 
230 private:
231 
233  A2D_Serial(const A2D_Serial&);
234 
236  A2D_Serial& operator=(const A2D_Serial&);
237 
238 };
239 
240 }}} // namespace nidas namespace dynld namespace raf
241 
242 #endif
A class for reading ASCII files containing a time series of calibration data.
Definition: CalFile.h:164
#define NUM_A2D_CHANNELS
Definition: A2D_Serial.h:36
Support for a sensor that is sending packets on a TCP socket, a UDP socket, a Bluetooth RF Comm socke...
Definition: SerialSensor.h:64
long long dsm_time_t
Posix time in microseconds, the number of non-leap microseconds since 1970 Jan 1 00:00 UTC...
Definition: Sample.h:61
Definition: A2D_Serial.h:53
OutputMode getOutputMode() const
Definition: A2D_Serial.h:112
virtual const void * getConstVoidDataPtr() const =0
Get a const void* pointer to the data portion of the sample.
OutputMode
Definition: A2D_Serial.h:53
int len
Definition: sing.cc:934
Interface to a data sample.
Definition: Sample.h:189
Definition: IOException.h:37
unsigned int getDataByteLength() const
Get the number of bytes in data portion of sample.
Definition: Sample.h:256
virtual Sample * nextSample()
Extract the next sample from the buffer.
Definition: DSMSensor.h:707
A2D Serial Sensor.
Definition: A2D_Serial.h:49
void setOutputMode(OutputMode mode)
Definition: A2D_Serial.h:110
Definition: InvalidParameterException.h:35