nidas  v1.2-1520
SppSerial.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 
27 #ifndef NIDAS_DYNLD_RAF_SPPSERIAL_H
28 #define NIDAS_DYNLD_RAF_SPPSERIAL_H
29 
32 
33 //
34 // Add a bogus zeroth bin to the data to match historical behavior.
35 // Remove all traces of this after the netCDF file refactor.
36 //
37 #define ZERO_BIN_HACK
38 
39 namespace nidas { namespace dynld { namespace raf {
40 
52 typedef unsigned char DMT_UShort[2];
53 
54 inline unsigned short UnpackDMT_UShort(DMT_UShort dmtval)
55 {
56  unsigned short val = (dmtval[1] << 8) | dmtval[0];
57  return val;
58 }
59 
60 inline void PackDMT_UShort(DMT_UShort dmtval, unsigned short val)
61 {
62  dmtval[0] = val & 0xff;
63  dmtval[1] = (val >> 8) & 0xff;
64 }
65 
66 
78 typedef unsigned char DMT_ULong[4];
79 
80 inline unsigned long UnpackDMT_ULong(DMT_ULong dmtval)
81 {
82  unsigned long val = dmtval[1] << 24 | dmtval[0] << 16 |
83  dmtval[3] << 8 | dmtval[2]; // DMT byte order is 2301
84  return val;
85 }
86 
87 inline void PackDMT_ULong(DMT_ULong dmtval, unsigned long val)
88 {
89  dmtval[0] = (val >> 16) & 0xff; // 2
90  dmtval[1] = (val >> 24) & 0xff; // 3
91  dmtval[2] = val & 0xff; // 0
92  dmtval[3] = (val >> 8) & 0xff; // 1
93 }
94 
95 
99 class SppSerial : public DSMSerialSensor
100 {
101 public:
103  {
104  FixedLength, // CheckSum
106  };
107 
108  SppSerial(const std::string & probe);
109  ~SppSerial();
110 
111  unsigned short computeCheckSum(const unsigned char *pkt, int len);
112 
113  void validate()
114  throw(nidas::util::InvalidParameterException);
115 
119  static const int MAX_CHANNELS = 40;
120 
121 protected:
126  virtual int packetLen() const = 0;
127 
135  virtual void
136  sendInitPacketAndCheckAck(void * packet, int len, int return_len = 2) throw(nidas::util::IOException);
137 
154  virtual int appendDataAndFindGood(const Sample* sample);
155 
159  double convert(dsm_time_t tt,double val,unsigned int ivar)
160  {
161  if (_converters.empty()) return val;
162  assert(ivar < _converters.size());
163  if (!_converters[ivar]) return val;
164  return _converters[ivar]->convert(tt,val);
165  }
166 
168  unsigned short _model;
169 
174 
178  int _nHskp;
179 
180  std::string _probeName;
181 
182  unsigned short _range;
183 
184  unsigned short _triggerThreshold;
185 
186  unsigned short _opcThreshold[MAX_CHANNELS];
187 
192 
199  unsigned short _recDelimiter; // only used if _dataType == Delimited
200 
202 
210  unsigned char* _waitingData; // size will be 2 * packetLen()
211  unsigned short _nWaitingData;
212  int _skippedBytes; // how much skipped looking for a good record?
215 
219  struct reqPckt
220  {
221  char esc; // 0x1b
222  char id; // 0x02
223  DMT_UShort cksum; // 0x001d
224  };
225 
230  // unsigned int _sampleRate;
231 
233 
244 
250  std::vector<nidas::core::VariableConverter*> _converters;
251 
252 private:
253 
255  SppSerial(const SppSerial&);
256 
258  SppSerial& operator=(const SppSerial&);
259 
260 };
261 
262 }}} // namespace nidas namespace dynld raf
263 
264 #endif
unsigned short computeCheckSum(const unsigned char *pkt, int len)
Definition: SppSerial.cc:79
int _noutValues
Total number of floats in the processed output sample.
Definition: SppSerial.h:191
unsigned char * _waitingData
Buffer to hold incoming data until we find a chunk that looks like a valid DMT100 data packet...
Definition: SppSerial.h:210
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
Here more for documentation.
Definition: SppSerial.h:219
std::vector< nidas::core::VariableConverter * > _converters
VariableConverters which may have been defined for each output housekeeping variable.
Definition: SppSerial.h:250
int _skippedBytes
Definition: SppSerial.h:212
DataTermination
Definition: SppSerial.h:102
size_t _checkSumErrorCnt
Definition: SppSerial.h:201
SppSerial & operator=(const SppSerial &)
No assignment.
virtual int appendDataAndFindGood(const Sample *sample)
Append _packetLen bytes of data to _waitingData, and find the earliest &quot;good&quot; record possible...
Definition: SppSerial.cc:246
int _nHskp
Number of housekeeping variables added to output data.
Definition: SppSerial.h:178
std::string _probeName
Definition: SppSerial.h:180
unsigned short _range
Definition: SppSerial.h:182
char esc
Definition: SppSerial.h:221
DMT_UShort cksum
Definition: SppSerial.h:223
static const int MAX_CHANNELS
Max # for array sizing.
Definition: SppSerial.h:119
virtual void sendInitPacketAndCheckAck(void *packet, int len, int return_len=2)
Send pre-packaged initialization packet to SPP probe and wait for acknowledge packet.
Definition: SppSerial.cc:183
unsigned short UnpackDMT_UShort(DMT_UShort dmtval)
Definition: SppSerial.h:54
DataTermination _dataType
Whether we are using fixed length data with checkSum (true), or the modified chips with message termi...
Definition: SppSerial.h:198
int len
Definition: sing.cc:934
Interface to a data sample.
Definition: Sample.h:189
bool _outputDeltaT
Stash sample-rate.
Definition: SppSerial.h:238
A sensor connected to a serial port.
Definition: DSMSerialSensor.h:38
void validate()
Implementation of DSMSensor::validate for a Character Sensor.
Definition: SppSerial.cc:89
Base class for many DMT Probes, including SPP100, SPP200, SPP300 and the CDP.
Definition: SppSerial.h:99
Definition: IOException.h:37
unsigned short _triggerThreshold
Definition: SppSerial.h:184
unsigned short _nWaitingData
Definition: SppSerial.h:211
Definition: SppSerial.h:105
unsigned short _recDelimiter
Definition: SppSerial.h:199
int _nChannels
Number of channels requested to be recorded.
Definition: SppSerial.h:173
unsigned char DMT_UShort[2]
DMT 2-byte ints are packed with byte order 01, where byte 0 is the low-order byte.
Definition: SppSerial.h:52
unsigned short _model
Possibly not needed...
Definition: SppSerial.h:168
~SppSerial()
Definition: SppSerial.cc:46
unsigned char DMT_ULong[4]
DMT 4-byte ints are packed with byte order 2301, where byte 0 is the low-order byte.
Definition: SppSerial.h:78
double convert(dsm_time_t tt, double val, unsigned int ivar)
Apply a VariableConversion to an output value.
Definition: SppSerial.h:159
dsm_time_t _prevTime
Store previous time tag.
Definition: SppSerial.h:242
size_t _totalRecordCount
Definition: SppSerial.h:214
void PackDMT_UShort(DMT_UShort dmtval, unsigned short val)
Definition: SppSerial.h:60
SppSerial(const std::string &probe)
Definition: SppSerial.cc:56
char id
Definition: SppSerial.h:222
size_t _skippedRecordCount
Definition: SppSerial.h:213
unsigned short _opcThreshold[MAX_CHANNELS]
Definition: SppSerial.h:186
virtual int packetLen() const =0
Return the expected data packet length in bytes based on the number of channels being used...
unsigned long UnpackDMT_ULong(DMT_ULong dmtval)
Definition: SppSerial.h:80
void PackDMT_ULong(DMT_ULong dmtval, unsigned long val)
Definition: SppSerial.h:87
Definition: InvalidParameterException.h:35