source: ntrip/trunk/BNC/RTCM3/RTCM3Decoder.cpp@ 1080

Last change on this file since 1080 was 1080, checked in by weber, 16 years ago

* empty log message *

File size: 9.8 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: RTCM3Decoder
30 *
31 * Purpose: RTCM3 Decoder
32 *
33 * Author: L. Mervart
34 *
35 * Created: 24-Aug-2006
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42#include <math.h>
43#include <string.h>
44
45#include "RTCM3Decoder.h"
46#include "RTCM3coDecoder.h"
47#include "bncconst.h"
48#include "bncapp.h"
49#include "bncutils.h" /* Weber, for latencies */
50
51using namespace std;
52
53#ifndef isinf
54# define isinf(x) 0
55#endif
56
57// Error Handling
58////////////////////////////////////////////////////////////////////////////
59void RTCM3Error(const char*, ...) {
60}
61
62// Constructor
63////////////////////////////////////////////////////////////////////////////
64RTCM3Decoder::RTCM3Decoder(const QString& staID) : GPSDecoder() {
65
66 const int LEAPSECONDS = 14; /* only needed for approx. time */
67
68 QSettings settings;
69 _checkMountPoint = settings.value("messTypes").toString();
70 _corrLate = settings.value("corrLate").toInt();
71 _staID = staID;
72
73 // Ensure, that the Decoder uses the "old" convention for the data structure for Rinex2. Perlt
74 _Parser.rinex3 = 0;
75
76 time_t tim;
77 tim = time(0) - ((10*365+2+5)*24*60*60 + LEAPSECONDS);
78
79 memset(&_Parser, 0, sizeof(_Parser));
80 _Parser.GPSWeek = tim/(7*24*60*60);
81 _Parser.GPSTOW = tim%(7*24*60*60);
82
83 connect(this, SIGNAL(newGPSEph(gpsephemeris*)),
84 (bncApp*) qApp, SLOT(slotNewGPSEph(gpsephemeris*)));
85 connect(this, SIGNAL(newGlonassEph(glonassephemeris*)),
86 (bncApp*) qApp, SLOT(slotNewGlonassEph(glonassephemeris*)));
87
88 // Sub-Decoder for Clock and Orbit Corrections
89 // -------------------------------------------
90 _coDecoder = new RTCM3coDecoder(staID);
91
92 // Mode can be either observations or corrections
93 // ----------------------------------------------
94 _mode = unknown;
95}
96
97// Destructor
98////////////////////////////////////////////////////////////////////////////
99RTCM3Decoder::~RTCM3Decoder() {
100 delete _coDecoder;
101}
102
103//
104////////////////////////////////////////////////////////////////////////////
105t_irc RTCM3Decoder::Decode(char* buffer, int bufLen) {
106
107 bool decoded = false;
108
109 // Try to decode Clock and Orbit Corrections
110 // -----------------------------------------
111 if (_mode == unknown || _mode == corrections) {
112 if ( _coDecoder->Decode(buffer, bufLen) == success ) {
113 decoded = true;
114
115 // Latency, Weber
116 // -------
117 if ( _corrLate == 2 ) {
118 if (0<_coDecoder->_epochList.size()) {
119 for (int ii=0;ii<_coDecoder->_epochList.size();ii++) {
120 int week;
121 double sec;
122 double secGPS = _coDecoder->_epochList[ii];
123 leapsecGPSWeeks(week, sec);
124 double dt = fabs(sec - secGPS);
125 const double secPerWeek = 7.0 * 24.0 * 3600.0;
126 if (dt > 0.5 * secPerWeek) {
127 if (sec > secGPS) {
128 sec -= secPerWeek;
129 } else {
130 sec += secPerWeek;
131 }
132 }
133 QString late;
134 late = QString("%1 ").arg(int((sec - secGPS)*100.)/100.);
135 if (late != "") {
136 emit(newMessage(QString(_staID + ": Latency " + late + "sec").toAscii() ) );
137 }
138 }
139 }
140 }
141 _coDecoder->_epochList.clear();
142
143 if (_mode == unknown) {
144 _mode = corrections;
145// emit(newMessage( (_staID + " : mode set to corrections").toAscii() ));
146 }
147 }
148 }
149
150 // Remaining part decodes the Observations
151 // ---------------------------------------
152 if (_mode == unknown || _mode == observations || _checkMountPoint == _staID || _checkMountPoint == "ALL") {
153 for (int ii = 0; ii < bufLen; ii++) {
154
155 _Parser.Message[_Parser.MessageSize++] = buffer[ii];
156 if (_Parser.MessageSize >= _Parser.NeedBytes) {
157
158 // RTCM message types
159 // ------------------
160 for (int kk = 0; kk < _Parser.typeSize; kk++) {
161 _typeList.push_back(_Parser.typeList[kk]);
162 }
163 _Parser.typeSize = 0;
164
165 while(int rr = RTCM3Parser(&_Parser)) {
166
167 // GNSS Observations
168 // -----------------
169 if (rr == 1 || rr == 2) {
170 decoded = true;
171
172 if (!_Parser.init) {
173 HandleHeader(&_Parser);
174 _Parser.init = 1;
175 }
176
177 if (rr == 2) {
178// std::cerr << "No valid RINEX! All values are modulo 299792.458!\n";
179 emit(newMessage( (_staID + ": No valid RINEX! All values are modulo 299792.458!").toAscii() ));
180 }
181
182 for (int ii = 0; ii < _Parser.Data.numsats; ii++) {
183 p_obs obs = new t_obs();
184 _obsList.push_back(obs);
185 if (_Parser.Data.satellites[ii] <= PRN_GPS_END) {
186 obs->_o.satSys = 'G';
187 obs->_o.satNum = _Parser.Data.satellites[ii];
188 }
189 else if (_Parser.Data.satellites[ii] <= PRN_GLONASS_END) {
190 obs->_o.satSys = 'R';
191 obs->_o.satNum = _Parser.Data.satellites[ii] - PRN_GLONASS_START + 1;
192 }
193 else {
194 obs->_o.satSys = 'S';
195 obs->_o.satNum = _Parser.Data.satellites[ii] - PRN_WAAS_START + 20;
196 }
197 obs->_o.GPSWeek = _Parser.Data.week;
198 obs->_o.GPSWeeks = _Parser.Data.timeofweek / 1000.0;
199
200 for (int jj = 0; jj < _Parser.numdatatypesGPS; jj++) {
201 int v = 0;
202 // sepearated declaration and initalization of df and pos. Perlt
203 int df;
204 int pos;
205 df = _Parser.dataflag[jj];
206 pos = _Parser.datapos[jj];
207 if ( (_Parser.Data.dataflags[ii] & df)
208 && !isnan(_Parser.Data.measdata[ii][pos])
209 && !isinf(_Parser.Data.measdata[ii][pos])) {
210 v = 1;
211 }
212 else {
213 df = _Parser.dataflagGPS[jj];
214 pos = _Parser.dataposGPS[jj];
215 if ( (_Parser.Data.dataflags[ii] & df)
216 && !isnan(_Parser.Data.measdata[ii][pos])
217 && !isinf(_Parser.Data.measdata[ii][pos])) {
218 v = 1;
219 }
220 }
221 if (!v) {
222 continue;
223 }
224 else
225 {
226 int isat = (_Parser.Data.satellites[ii] < 120
227 ? _Parser.Data.satellites[ii]
228 : _Parser.Data.satellites[ii] - 80);
229
230 // variables df and pos are used consequently. Perlt
231 if (df & GNSSDF_C1DATA) {
232 obs->_o.C1 = _Parser.Data.measdata[ii][pos];
233 }
234 else if (df & GNSSDF_C2DATA) {
235 obs->_o.C2 = _Parser.Data.measdata[ii][pos];
236 }
237 else if (df & GNSSDF_P1DATA) {
238 obs->_o.P1 = _Parser.Data.measdata[ii][pos];
239 }
240 else if (df & GNSSDF_P2DATA) {
241 obs->_o.P2 = _Parser.Data.measdata[ii][pos];
242 }
243 else if (df & (GNSSDF_L1CDATA|GNSSDF_L1PDATA)) {
244 obs->_o.L1 = _Parser.Data.measdata[ii][pos];
245 obs->_o.SNR1 = _Parser.Data.snrL1[ii];
246 obs->_o.lock_timei_L1 = _Parser.lastlockl1[isat];
247 }
248 else if (df & (GNSSDF_L2CDATA|GNSSDF_L2PDATA)) {
249 obs->_o.L2 = _Parser.Data.measdata[ii][pos];
250 obs->_o.SNR2 = _Parser.Data.snrL2[ii];
251 obs->_o.lock_timei_L2 = _Parser.lastlockl2[isat];
252 }
253 else if (df & (GNSSDF_S1CDATA|GNSSDF_S1PDATA)) {
254 obs->_o.S1 = _Parser.Data.measdata[ii][pos];
255 }
256 else if (df & (GNSSDF_S2CDATA|GNSSDF_S2PDATA)) {
257 obs->_o.S2 = _Parser.Data.measdata[ii][pos];
258 }
259 }
260 }
261 }
262 }
263
264 // GPS Ephemeris
265 // -------------
266 else if (rr == 1019) {
267 decoded = true;
268 gpsephemeris* ep = new gpsephemeris(_Parser.ephemerisGPS);
269 emit newGPSEph(ep);
270 }
271
272 // GLONASS Ephemeris
273 // -----------------
274 else if (rr == 1020) {
275 decoded = true;
276 glonassephemeris* ep = new glonassephemeris(_Parser.ephemerisGLONASS);
277 emit newGlonassEph(ep);
278 }
279 }
280 }
281 }
282 if (_mode == unknown && decoded) {
283 _mode = observations;
284// emit(newMessage( (_staID + " : mode set to observations").toAscii() ));
285 }
286 }
287
288 if (decoded) {
289 return success;
290 }
291 else {
292 return failure;
293 }
294}
Note: See TracBrowser for help on using the repository browser.