nidas  v1.2-1520
Packets.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  ** 2006, 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_ISFF_PACKETS_H
28 #define NIDAS_DYNLD_ISFF_PACKETS_H
29 
30 #include <nidas/util/UTime.h>
32 
33 #include <sys/types.h>
34 #include <regex.h>
35 #include <iostream>
36 
37 namespace nidas { namespace dynld { namespace isff {
38 
39 class PacketInfo {
40 public:
41  virtual ~PacketInfo() {}
42  virtual const char * header() const = 0;
43 
44  virtual bool scan(const char*) = 0;
45 
46  virtual std::ostream& print(std::ostream &) const = 0;
47  virtual float getSignalStrength() const = 0;
48  virtual float getFreqOffset() const = 0;
49  virtual int getChannel() const = 0;
50  virtual int getStatusInt() const = 0;
51  virtual int getLength() const = 0;
52 };
53 
54 inline std::ostream& operator<<(std::ostream& s, const PacketInfo& q)
55 {
56  return q.print(s);
57 }
58 
59 class NESDISPacketInfo : public PacketInfo {
60 public:
62 
68  bool scan(const char *);
69 
70  std::ostream& print(std::ostream &) const;
71 
75  const char* header() const;
76 
77  float getSignalStrength() const { return (float) _sigdbm; }
78  float getFreqOffset() const { return (float) _freqError * 50; }
79  int getChannel() const {
80  return _EW == 'E' ? _channel : _EW == 'W' ? -_channel : -99999; }
81  int getStatusInt() const;
82  int getLength() const { return _len; }
83 
84 private:
86  int _sigdbm;
88  char _modIndex;
90  int _channel;
91  char _EW;
92  int _len;
93 
94 };
95 
96 class SutronPacketInfo : public PacketInfo {
97 public:
98 
100 
101  bool scan(const char *);
102 
103  std::ostream& print(std::ostream &) const;
104 
108  const char* header() const;
109 
110  float getSignalStrength() const { return _sigdbm; }
111  float getFreqOffset() const { return (float) _freqError; }
112  int getChannel() const { return -99999; }
113  int getStatusInt() const { return 0; }
114  int getLength() const { return _len; }
115 
116 private:
118  float _sigdbm;
121  float _SNratio;
122  int _len;
123 
124 };
125 
127 public:
128 
130 
131  ~PacketParser();
132 
134 
136 
137  enum packet_type parse(const char*) throw(nidas::util::ParseException);
138 
139  const nidas::util::UTime& getPacketTime() const
140  {
141  return _packetTime;
142  }
143 
144  const PacketInfo* getPacketInfo() const
145  {
146  return _packetInfo;
147  }
148 
149  int getStationId() const
150  {
151  return _stationId;
152  }
153 
154  int getConfigId() const
155  {
156  return _configId;
157  }
158 
159  int getSampleId() const
160  {
161  return _sampleId;
162  }
163 
164  void parseData(float*,int nvars);
165 
166 private:
167 
168  static ::regex_t** _packetPreg;
169 
170  static ::regex_t** _infoPreg;
171 
173 
175 
179  const size_t _nmatch;
180 
185  ::regmatch_t *_pmatch;
186 
188 
190 
192 
194 
196 
200  const char* _packetPtr;
201 
205  const char* _endOfPacket;
206 
208 
210 
212  PacketParser(const PacketParser&);
213 
216 
217 };
218 
219 }}} // namespace nidas namespace dynld namespace isff
220 
221 #endif
static nidas::util::Mutex _pregMutex
Definition: Packets.h:187
virtual const char * header() const =0
int _sigdbm
Definition: Packets.h:86
nidas::util::UTime _packetTime
Definition: Packets.h:193
A class for parsing, formatting and doing operations on time, based on Unix time conventions, where leap seconds are ignored, so that there are always 60 seconds in a minute, 3600 seconds in an hour and 86400 seconds in a day.
Definition: UTime.h:76
int _modNumber
Definition: Packets.h:117
virtual int getStatusInt() const =0
::regex_t ** _packetPreg
Definition: Packets.h:168
int _nInfoTypes
Definition: Packets.h:174
const char * header() const
Header for a printed listing of SutronPacketInfo&#39;s.
Definition: Packets.cc:329
float getFreqOffset() const
Definition: Packets.h:111
int getStatusInt() const
Definition: Packets.h:113
const size_t _nmatch
Max number of parenthesized expressions in any regular expression.
Definition: Packets.h:179
SutronPacketInfo()
Definition: Packets.cc:317
virtual ~PacketInfo()
Definition: Packets.h:41
virtual float getFreqOffset() const =0
PacketInfo * _packetInfo
Definition: Packets.h:189
~PacketParser()
Definition: Packets.cc:114
Definition: Packets.h:126
float _sigdbm
Definition: Packets.h:118
std::ostream & print(std::ostream &) const
Definition: Packets.cc:304
char _messageStatus
Definition: Packets.h:85
virtual std::ostream & print(std::ostream &) const =0
::regmatch_t * _pmatch
Array for returning pointer to beginning of the match to each parenthesized expression.
Definition: Packets.h:185
int getLength() const
Definition: Packets.h:114
Definition: Packets.h:39
int getChannel() const
Definition: Packets.h:112
int getConfigId() const
Definition: Packets.h:154
enum packet_type parse(const char *)
Definition: Packets.cc:119
float getSignalStrength() const
Definition: Packets.h:110
const PacketInfo * getPacketInfo() const
Definition: Packets.h:144
char _EW
Definition: Packets.h:91
int _modPhase
Definition: Packets.h:120
const char * header() const
Header for a printed listing of NESDISPacketInfo&#39;s.
Definition: Packets.cc:300
int _channel
Definition: Packets.h:90
void parseData(float *, int nvars)
Definition: Packets.cc:232
NESDISPacketInfo()
Definition: Packets.cc:246
int _len
Definition: Packets.h:92
int getStationId() const
Definition: Packets.h:149
char _modIndex
Definition: Packets.h:88
char _dataQuality
Definition: Packets.h:89
int _freqError
Definition: Packets.h:87
float getFreqOffset() const
Definition: Packets.h:78
const nidas::util::UTime & getPacketTime() const
Definition: Packets.h:139
int _len
Definition: Packets.h:122
float _SNratio
Definition: Packets.h:121
::regex_t ** _infoPreg
Definition: Packets.h:170
int getSampleId() const
Definition: Packets.h:159
int getChannel() const
Definition: Packets.h:79
PacketParser()
Definition: Packets.cc:50
float getSignalStrength() const
Definition: Packets.h:77
Definition: Packets.h:59
const char * _endOfPacket
One past the end of the current packet.
Definition: Packets.h:205
Definition: Packets.h:96
int _sampleId
Definition: Packets.h:209
bool scan(const char *)
Scan a string for info fields.
Definition: Packets.cc:253
const char * _packetPtr
Pointer into the current packet.
Definition: Packets.h:200
virtual int getLength() const =0
PacketParser & operator=(const PacketParser &)
No assignment.
int getLength() const
Definition: Packets.h:82
int getStatusInt() const
Definition: Packets.cc:261
virtual int getChannel() const =0
int _infoType
Definition: Packets.h:191
A C++ wrapper for a POSIX mutex.
Definition: ThreadSupport.h:154
int _nPacketTypes
Definition: Packets.h:172
int _configId
Definition: Packets.h:207
int _stationId
Definition: Packets.h:195
packet_type
Definition: Packets.h:133
std::ostream & print(std::ostream &) const
Definition: Packets.cc:332
virtual float getSignalStrength() const =0
std::ostream & operator<<(std::ostream &s, const PacketInfo &q)
Definition: Packets.h:54
info_type
Definition: Packets.h:135
int _freqError
Definition: Packets.h:119
virtual bool scan(const char *)=0
bool scan(const char *)
Definition: Packets.cc:323
Definition: ParseException.h:36