nidas v1.2.3
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
39namespace nidas { namespace dynld { namespace raf {
40
52typedef unsigned char DMT_UShort[2];
53
54inline unsigned short UnpackDMT_UShort(DMT_UShort dmtval)
55{
56 unsigned short val = (dmtval[1] << 8) | dmtval[0];
57 return val;
58}
59
60inline void PackDMT_UShort(DMT_UShort dmtval, unsigned short val)
61{
62 dmtval[0] = val & 0xff;
63 dmtval[1] = (val >> 8) & 0xff;
64}
65
66
78typedef unsigned char DMT_ULong[4];
79
80inline 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
87inline 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
100{
101public:
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
116 void validate();
117
121 static const int MAX_CHANNELS = 40;
122
123protected:
128 virtual int packetLen() const = 0;
129
139 virtual void
140 sendInitPacketAndCheckAck(void * packet, int len, int return_len = 2);
141
158 virtual int appendDataAndFindGood(const Sample* sample);
159
163 double convert(dsm_time_t tt,double val,unsigned int ivar)
164 {
165 if (_converters.empty()) return val;
166 assert(ivar < _converters.size());
167 if (!_converters[ivar]) return val;
168 return _converters[ivar]->convert(tt,val);
169 }
170
172 unsigned short _model;
173
178
183
184 std::string _probeName;
185
186 unsigned short _range;
187
188 unsigned short _triggerThreshold;
189
191
196
203 unsigned short _recDelimiter; // only used if _dataType == Delimited
204
206
214 unsigned char* _waitingData; // size will be 2 * packetLen()
215 unsigned short _nWaitingData;
216 int _skippedBytes; // how much skipped looking for a good record?
219
223 struct reqPckt
224 {
225 char esc; // 0x1b
226 char id; // 0x02
227 DMT_UShort cksum; // 0x001d
228 };
229
234 // unsigned int _sampleRate;
235
237
248
254 std::vector<nidas::core::VariableConverter*> _converters;
255
256private:
257
260
263
264};
265
266}}} // namespace nidas namespace dynld raf
267
268#endif
Interface to a data sample.
Definition Sample.h:190
A sensor connected to a serial port.
Definition DSMSerialSensor.h:39
Base class for many DMT Probes, including SPP100, SPP200, SPP300 and the CDP.
Definition SppSerial.h:100
virtual int appendDataAndFindGood(const Sample *sample)
Append _packetLen bytes of data to _waitingData, and find the earliest "good" record possible,...
Definition SppSerial.cc:245
virtual int packetLen() const =0
Return the expected data packet length in bytes based on the number of channels being used.
unsigned short _recDelimiter
Definition SppSerial.h:203
bool _outputDeltaT
Stash sample-rate.
Definition SppSerial.h:242
DataTermination
Definition SppSerial.h:103
@ FixedLength
Definition SppSerial.h:104
@ Delimited
Definition SppSerial.h:105
static const int MAX_CHANNELS
Max # for array sizing.
Definition SppSerial.h:121
unsigned short _nWaitingData
Definition SppSerial.h:215
unsigned short _triggerThreshold
Definition SppSerial.h:188
DataTermination _dataType
Whether we are using fixed length data with checkSum (true), or the modified chips with message termi...
Definition SppSerial.h:202
~SppSerial()
Definition SppSerial.cc:46
SppSerial & operator=(const SppSerial &)
No assignment.
unsigned short _range
Definition SppSerial.h:186
dsm_time_t _prevTime
Store previous time tag.
Definition SppSerial.h:246
size_t _totalRecordCount
Definition SppSerial.h:218
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
int _noutValues
Total number of floats in the processed output sample.
Definition SppSerial.h:195
std::string _probeName
Definition SppSerial.h:184
unsigned short computeCheckSum(const unsigned char *pkt, int len)
Definition SppSerial.cc:79
unsigned short _model
Possibly not needed...
Definition SppSerial.h:172
std::vector< nidas::core::VariableConverter * > _converters
VariableConverters which may have been defined for each output housekeeping variable.
Definition SppSerial.h:254
int _nHskp
Number of housekeeping variables added to output data.
Definition SppSerial.h:182
unsigned short _opcThreshold[MAX_CHANNELS]
Definition SppSerial.h:190
SppSerial(const SppSerial &)
No copying.
void validate()
Definition SppSerial.cc:89
unsigned char * _waitingData
Buffer to hold incoming data until we find a chunk that looks like a valid DMT100 data packet.
Definition SppSerial.h:214
int _skippedBytes
Definition SppSerial.h:216
size_t _checkSumErrorCnt
Definition SppSerial.h:205
size_t _skippedRecordCount
Definition SppSerial.h:217
int _nChannels
Number of channels requested to be recorded.
Definition SppSerial.h:177
double convert(dsm_time_t tt, double val, unsigned int ivar)
Apply a VariableConversion to an output value.
Definition SppSerial.h:163
SppSerial(const std::string &probe)
Definition SppSerial.cc:56
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
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:62
unsigned short UnpackDMT_UShort(DMT_UShort dmtval)
Definition SppSerial.h:54
unsigned long UnpackDMT_ULong(DMT_ULong dmtval)
Definition SppSerial.h:80
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
void PackDMT_ULong(DMT_ULong dmtval, unsigned long val)
Definition SppSerial.h:87
void PackDMT_UShort(DMT_UShort dmtval, unsigned short val)
Definition SppSerial.h:60
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
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31
int len
Definition sing.cc:948
Here more for documentation.
Definition SppSerial.h:224
char id
Definition SppSerial.h:226
char esc
Definition SppSerial.h:225
DMT_UShort cksum
Definition SppSerial.h:227