nidas v1.2.3
WisardMote.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 ** 2009, 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
28 Sensor class supporting EOL "Wisard" motes.
29
30 This code handles the serial messages from a base radio for a set of motes.
31
32 The raw messages from each mote have a general format of
33
34 ID N ':' version msgtype data CRC terminator
35
36 ID is a non-numeric string of ASCII characters, typically "ID".
37
38 N is one or more ascii decimal digits, specifying the number of the
39 originating mote. Each mote's number should be unique for the set of motes
40 being acquired by a data system. As explained below the mote
41 number should be in the range 1-127.
42
43 version is a 1 byte integer indicating the message format version
44 number.
45
46 msgtype is another 1 byte integer, where 1 indicates a data message.
47
48 The data portion is a concatenation of one or more sensor data
49 fields. Each sensor data field consists of a 8 bit sensor type
50 followed by the data for that sensor type, where the format and
51 length of the data is defined for each sensor type.
52
53 The full id of the raw samples will contain the DSM id in the top 16
54 bits, with the DSM sensor id in the low order 16 bits.
55 By convention we use a DSM sensor id of 0x8000 for all base motes
56 attached to a data system.
57
58 The process() method of this class unpacks the raw samples, generating
59 a floating point sample for each sensor data field found in the raw
60 message.
61
62 The NIDAS sample id provides 16 bits to uniquely identify a sample
63 on a DSM. In order to manage these ids we have established a convention
64 where the processed samples will have a DSM sensor id of 0x8000,
65 leaving 7 bits for the mote number (1-127), and 8 bits for the sensor type.
66
67 Mote number of 0 is used in the configuration to specify variable names
68 for a sensor type which should be used for all motes. Therefore
69 a physical mote should not have an id of 0.
70
71 */
72
73#ifndef NIDAS_DYNLD_ISFF_WISARDMOTE_H
74#define NIDAS_DYNLD_ISFF_WISARDMOTE_H
75
77#include <nidas/core/Sample.h>
80
81#include <vector>
82#include <map>
83#include <string>
84#include <iostream>
85#include <exception>
86
87//#include <sstream>
88#include <list>
89
90namespace nidas { namespace dynld { namespace isff {
91
92using namespace nidas::core;
93
94struct VarInfo
95{
96 const char *name;
97 const char *units;
98 const char *longname;
99 const char *plotrange;
100};
101
112
124
126{
127public:
128 WisardMote();
129
130 virtual ~ WisardMote();
131
132 bool process(const Sample* insamp,
133 std::list<const Sample*>& results);
134
135 void validate();
136
144 };
145
150 typedef const char *(WisardMote::*unpack_t)
151 (const char *cp, const char *eos,
152 unsigned int nfields,
153 const struct MessageHeader* hdr,
154 SampleTag* stag, SampleT< float >* osamp);
155
157
158private:
159
166 void createSampleTags(const SampleTag* stag,const std::vector<int>& motes,std::list<SampleTag*>& newtags);
167
172 void addImpliedSampleTags(const std::vector<int>& motes);
173
181 void checkLessUsedSensors(void);
182
187 void addMoteSampleTag(SampleTag* tag);
188
192 SampleTag* createSampleTag(SampInfo& sinfo,int mote, int stype);
193
198 const char *checkEOM(const char *cp,
199 const char *eom, nidas::core::dsm_time_t ttag);
200
205 const char *checkCRC(const char *cp,
206 const char *eom, nidas::core::dsm_time_t ttag);
207
212 bool readHead(const char *&cp,const char *eom, dsm_time_t ttag,
213 struct MessageHeader*);
214
219 int readMoteId(const char* &cp, const char*eos);
220
225 void convert(SampleTag* stag, SampleT<float>* osamp, float* results=0);
226
227 const char* unpackPicTime(const char *, const char *,
228 unsigned int, const struct MessageHeader*,
229 SampleTag*, SampleT<float>*);
230
231 const char* unpackUint16(const char *, const char *,
232 unsigned int, const struct MessageHeader*,
233 SampleTag*, SampleT<float>*);
234
235 const char* unpackInt16(const char *, const char *,
236 unsigned int, const struct MessageHeader*,
237 SampleTag*, SampleT<float>*);
238
239 const char* unpackUint32(const char *, const char *,
240 unsigned int, const struct MessageHeader*,
241 SampleTag*, SampleT<float>*);
242
243 const char* unpackInt32(const char *, const char *,
244 unsigned int, const struct MessageHeader*,
245 SampleTag*, SampleT<float>*);
246
247 const char* unpackAccumSec(const char *, const char *,
248 unsigned int, const struct MessageHeader*,
249 SampleTag*, SampleT<float>*);
250
251 const char* unpack100thSec(const char *, const char *,
252 unsigned int, const struct MessageHeader*,
253 SampleTag*, SampleT<float>*);
254
255 const char* unpack10thSec(const char *, const char *,
256 unsigned int, const struct MessageHeader*,
257 SampleTag*, SampleT<float>*);
258
259 const char* unpackPicTimeFields(const char *, const char *,
260 unsigned int, const struct MessageHeader*,
261 SampleTag*, SampleT<float>*);
262
263 const char* unpackTRH(const char *, const char *,
264 unsigned int, const struct MessageHeader*,
265 SampleTag*, SampleT<float>*);
266
267 const char* unpackTsoil(const char *, const char *,
268 unsigned int, const struct MessageHeader*,
269 SampleTag*, SampleT<float>*);
270
271 const char* unpackGsoil(const char *, const char *,
272 unsigned int, const struct MessageHeader*,
273 SampleTag*, SampleT<float>*);
274
275 const char* unpackQsoil(const char *, const char *,
276 unsigned int, const struct MessageHeader*,
277 SampleTag*, SampleT<float>*);
278
279 const char* unpackTP01(const char *, const char *,
280 unsigned int, const struct MessageHeader*,
281 SampleTag*, SampleT<float>*);
282
283 const char* unpackStatus(const char *, const char *,
284 unsigned int, const struct MessageHeader*,
285 SampleTag*, SampleT<float>*);
286
287 const char* unpackXbee(const char *, const char *,
288 unsigned int, const struct MessageHeader*,
289 SampleTag*, SampleT<float>*);
290
291 const char* unpackPower(const char *, const char *,
292 unsigned int, const struct MessageHeader*,
293 SampleTag*, SampleT<float>*);
294
295 const char* unpackRnet(const char *, const char *,
296 unsigned int, const struct MessageHeader*,
297 SampleTag*, SampleT<float>*);
298
299 const char* unpackRsw(const char *, const char *,
300 unsigned int, const struct MessageHeader*,
301 SampleTag*, SampleT<float>*);
302
303 const char* unpackRlw(const char *, const char *,
304 unsigned int, const struct MessageHeader*,
305 SampleTag*, SampleT<float>*);
306
307 const char* unpackRlwKZ(const char *, const char *,
308 unsigned int, const struct MessageHeader*,
309 SampleTag*, SampleT<float>*);
310
311 const char* unpackCNR2(const char *, const char *,
312 unsigned int, const struct MessageHeader*,
313 SampleTag*, SampleT<float>*);
314
315 const char* unpackNR01(const char *, const char *,
316 unsigned int, const struct MessageHeader*,
317 SampleTag*, SampleT<float>*);
318
319 const char* unpackRsw2(const char *, const char *,
320 unsigned int, const struct MessageHeader*,
321 SampleTag*, SampleT<float>*);
322
334 static std::map<dsm_sample_id_t, WisardMote*> _processorSensors;
335
336 static SampInfo _samps[];
337
338 static bool _functionsMapped;
339
343 static std::map<int, std::pair<unpack_t,unsigned int> > _unpackMap;
344
345 static std::map<int, std::string> _typeNames;
346
347 static void initFuncMap();
348
353 std::map<dsm_sample_id_t, SampleTag*> _sampleTagsById;
354
362
366 std::map<int, std::map<int, int > > _sensorSerialNumbersByMoteIdAndType;
367
368 std::map<int, int> _sequenceNumbersByMoteId;
369
370 std::map<int, unsigned int> _badCRCsByMoteId;
371
372 std::map<int, int> _tdiffByMoteId;
373
377 std::map <int, std::map<int, unsigned int> > _numBadSensorTypes;
378
379 std::map<int, unsigned int> _unconfiguredMotes;
380
381 std::map <int, std::map<int, unsigned int> > _noSampleTags;
382
383 std::set<int> _ignoredSensorTypes;
384
385 std::set<int> _nowarnSensorTypes;
386
387 static const unsigned int NTSOILS = 4;
388
392 {
393 public:
397 {
398 for (unsigned int i = 0; i < sizeof(tempLast)/sizeof(tempLast[0]); i++) {
400 }
401 }
402 };
403 std::map<dsm_sample_id_t, TsoilData> _tsoilData;
404
407
410
411};
412}}} // nidas::dynld::isff
413#endif /* WISARDMOTE_H_ */
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
Support for a sensor that is sending packets on a TCP socket, a UDP socket, a Bluetooth RF Comm socke...
Definition SerialSensor.h:65
dsm_time_t timeLast[NTSOILS]
Definition WisardMote.h:395
TsoilData()
Definition WisardMote.h:396
float tempLast[NTSOILS]
Definition WisardMote.h:394
Definition WisardMote.h:126
static std::map< int, std::string > _typeNames
Definition WisardMote.h:345
void addMoteSampleTag(SampleTag *tag)
Private method to add tags of processed samples to this WisardMote.
Definition WisardMote.cc:243
const char * unpackRnet(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:1288
const char * unpackTRH(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:1026
static std::map< int, std::pair< unpack_t, unsigned int > > _unpackMap
Mapping between sensor type and function which parses the data.
Definition WisardMote.h:343
void addImpliedSampleTags(const std::vector< int > &motes)
Add processed sample tags for all sensor types indicated as WST_IMPLIED in _samps.
Definition WisardMote.cc:260
const char * unpackQsoil(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:1152
const char * unpackXbee(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:1236
static bool _functionsMapped
Definition WisardMote.h:338
const char * unpackInt16(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:780
WisardMote * _processorSensor
Pointer to the WisardMote that does the processing for the samples with this sensor id.
Definition WisardMote.h:361
static std::map< dsm_sample_id_t, WisardMote * > _processorSensors
Because the Wisard mote data has internal identifiers, more than one WisardMote can be declared with ...
Definition WisardMote.h:334
std::map< int, std::map< int, int > > _sensorSerialNumbersByMoteIdAndType
Sensor serial numbers, from message.
Definition WisardMote.h:366
const char * unpackRsw(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:1305
const char * unpackInt32(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:816
std::map< int, int > _tdiffByMoteId
Definition WisardMote.h:372
const char * unpackTsoil(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:1065
std::map< int, unsigned int > _unconfiguredMotes
Definition WisardMote.h:379
static SampInfo _samps[]
Definition WisardMote.h:336
const char * unpack10thSec(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:897
const char * checkEOM(const char *cp, const char *eom, nidas::core::dsm_time_t ttag)
Check for correct EOM.
Definition WisardMote.cc:549
void convert(SampleTag *stag, SampleT< float > *osamp, float *results=0)
After unpacking data from the Wisard block, pass it through the usual Variable conversions and option...
Definition WisardMote.cc:458
std::map< int, std::map< int, unsigned int > > _noSampleTags
Definition WisardMote.h:381
WisardMote & operator=(const WisardMote &)
No assignment.
void validate()
Implementation of DSMSensor::validate for a Character Sensor.
Definition WisardMote.cc:91
const char * unpackPower(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:1253
bool readHead(const char *&cp, const char *eom, dsm_time_t ttag, struct MessageHeader *)
Read initial portion of a Wisard message, filling in struct MessageHeader.
Definition WisardMote.cc:488
const char * unpackAccumSec(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:834
std::map< int, unsigned int > _badCRCsByMoteId
Definition WisardMote.h:370
void createSampleTags(const SampleTag *stag, const std::vector< int > &motes, std::list< SampleTag * > &newtags)
Create SampleTags from the configuration SampleTag.
Definition WisardMote.cc:159
std::map< int, std::map< int, unsigned int > > _numBadSensorTypes
For each mote id, the number of unrecognized sensor types.
Definition WisardMote.h:377
std::set< int > _nowarnSensorTypes
Definition WisardMote.h:385
static void initFuncMap()
Definition WisardMote.cc:1432
std::set< int > _ignoredSensorTypes
Definition WisardMote.h:383
const char * unpackPicTime(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:742
const char * unpackGsoil(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:1135
const char * unpackPicTimeFields(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:965
void checkLessUsedSensors(void)
Create sets of WST_IGNORED and WST_NOWARN sensors, by looping over _samps, and checking the type fiel...
Definition WisardMote.cc:280
SampleTag * createSampleTag(SampInfo &sinfo, int mote, int stype)
create a SampleTag from contents of a SampInfo object
Definition WisardMote.cc:304
std::map< int, int > _sequenceNumbersByMoteId
Definition WisardMote.h:368
const char * unpackRlw(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:1322
const char * unpackRsw2(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:1387
const char * unpackCNR2(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:1369
const char * unpackRlwKZ(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:1346
const char * unpackUint32(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:798
static const nidas::util::EndianConverter * fromLittle
Definition WisardMote.h:156
WisardMote(const WisardMote &)
No copying.
const char * checkCRC(const char *cp, const char *eom, nidas::core::dsm_time_t ttag)
Verify crc.
Definition WisardMote.cc:578
int readMoteId(const char *&cp, const char *eos)
read mote id from a Wisard message.
Definition WisardMote.cc:466
bool process(const Sample *insamp, std::list< const Sample * > &results)
Process a raw sample, which in this case means do a sscanf on the character string contents,...
Definition WisardMote.cc:359
const char *(WisardMote::* unpack_t)(const char *cp, const char *eos, unsigned int nfields, const struct MessageHeader *hdr, SampleTag *stag, SampleT< float > *osamp)
typedef for the functions that parse the message data for each sensor type.
Definition WisardMote.h:151
WisardMote()
Definition WisardMote.cc:70
const char * unpackUint16(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:762
const char * unpackTP01(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:1169
const char * unpackNR01(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:1405
const char * unpack100thSec(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:879
const char * unpackStatus(const char *, const char *, unsigned int, const struct MessageHeader *, SampleTag *, SampleT< float > *)
Definition WisardMote.cc:1210
std::map< dsm_sample_id_t, SampleTag * > _sampleTagsById
The processed sample tags for each id.
Definition WisardMote.h:353
std::map< dsm_sample_id_t, TsoilData > _tsoilData
Definition WisardMote.h:403
static const unsigned int NTSOILS
Definition WisardMote.h:387
Virtual base class declaring methods for converting numeric values between little-endian and big-endi...
Definition EndianConverter.h:304
The essential core classes of nidas.
Definition A2DConverter.h:31
const float floatNAN
Value of a float NAN for general use.
Definition Sample.cc: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
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
WISARD_SAMPLE_TYPE
WST_IMPLIED: create sample tags for these sensor types, even if they aren't found in the XML.
Definition WisardMote.h:111
@ WST_NORMAL
Definition WisardMote.h:111
@ WST_IGNORED
Definition WisardMote.h:111
@ WST_NOWARN
Definition WisardMote.h:111
@ WST_IMPLIED
Definition WisardMote.h:111
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31
Definition WisardMote.h:114
enum WISARD_SAMPLE_TYPE type
Definition WisardMote.h:122
int lastst
Definition WisardMote.h:120
struct VarInfo variables[9]
Definition WisardMote.h:121
int firstst
firstst and lastst are the range of sensor types containing the list of variables.
Definition WisardMote.h:119
Definition WisardMote.h:95
const char * name
Definition WisardMote.h:96
const char * units
Definition WisardMote.h:97
const char * longname
Definition WisardMote.h:98
const char * plotrange
Definition WisardMote.h:99
Extracted fields from the initial portion of a Wisard message.
Definition WisardMote.h:140
int messageType
Definition WisardMote.h:143
int version
Definition WisardMote.h:142
int moteId
Definition WisardMote.h:141