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

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

* empty log message *

File size: 9.6 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 "bncconst.h"
47#include "bncapp.h"
48#include "bncutils.h"
49#include "bncsettings.h"
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 bncSettings settings;
67 _checkMountPoint = settings.value("miscMount").toString();
68 _staID = staID;
69
70 // Ensure, that the Decoder uses the "old" convention for the data structure for Rinex2. Perlt
71 _Parser.rinex3 = 0;
72
73 memset(&_Parser, 0, sizeof(_Parser));
74
75 double secGPS;
76 currentGPSWeeks(_Parser.GPSWeek, secGPS);
77 _Parser.GPSTOW = int(secGPS);
78
79 connect(this, SIGNAL(newGPSEph(gpsephemeris*)),
80 (bncApp*) qApp, SLOT(slotNewGPSEph(gpsephemeris*)));
81 connect(this, SIGNAL(newGlonassEph(glonassephemeris*)),
82 (bncApp*) qApp, SLOT(slotNewGlonassEph(glonassephemeris*)));
83
84 // Sub-Decoder for Clock and Orbit Corrections
85 // -------------------------------------------
86 _coDecoder = new RTCM3coDecoder(staID);
87
88 // Mode can be either observations or corrections
89 // ----------------------------------------------
90 _mode = unknown;
91}
92
93// Destructor
94////////////////////////////////////////////////////////////////////////////
95RTCM3Decoder::~RTCM3Decoder() {
96 delete _coDecoder;
97}
98
99//
100////////////////////////////////////////////////////////////////////////////
101t_irc RTCM3Decoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
102
103 errmsg.clear();
104
105 bool decoded = false;
106
107 // Try to decode Clock and Orbit Corrections
108 // -----------------------------------------
109 if (_mode == unknown || _mode == corrections) {
110 if ( _coDecoder->Decode(buffer, bufLen, errmsg) == success ) {
111 decoded = true;
112 if (_mode == unknown) {
113 _mode = corrections;
114 }
115 }
116 }
117
118 // Remaining part decodes the Observations
119 // ---------------------------------------
120 if (_mode == unknown || _mode == observations || _checkMountPoint == _staID || _checkMountPoint == "ALL") {
121
122 for (int ii = 0; ii < bufLen; ii++) {
123 _Parser.Message[_Parser.MessageSize++] = buffer[ii];
124
125 if (_Parser.MessageSize >= _Parser.NeedBytes) {
126
127 while(int rr = RTCM3Parser(&_Parser)) {
128
129 // RTCMv3 message types
130 // --------------------
131 _typeList.push_back(_Parser.blocktype);
132
133 // RTCMv3 antenna descriptor
134 // -------------------------
135 if(rr == 1007 || rr == 1008 || rr == 1033)
136 {
137 _antType.push_back(_Parser.antenna); /* correct ? */
138 }
139
140 // RTCMv3 antenna XYZ
141 // ------------------
142 else if(rr == 1005)
143 {
144 _antList.push_back(t_antInfo());
145 _antList.back().type = t_antInfo::ARP;
146 _antList.back().xx = _Parser.antX * 1e-4;
147 _antList.back().yy = _Parser.antY * 1e-4;
148 _antList.back().zz = _Parser.antZ * 1e-4;
149 _antList.back().message = rr;
150 }
151
152 // RTCMv3 antenna XYZ-H
153 // --------------------
154 else if(rr == 1006)
155 {
156 _antList.push_back(t_antInfo());
157 _antList.back().type = t_antInfo::ARP;
158 _antList.back().xx = _Parser.antX * 1e-4;
159 _antList.back().yy = _Parser.antY * 1e-4;
160 _antList.back().zz = _Parser.antZ * 1e-4;
161 _antList.back().height = _Parser.antH * 1e-4;
162 _antList.back().height_f = true;
163 _antList.back().message = rr;
164 }
165
166 // GNSS Observations
167 // -----------------
168 else if (rr == 1 || rr == 2) {
169 decoded = true;
170
171 if (!_Parser.init) {
172 HandleHeader(&_Parser);
173 _Parser.init = 1;
174 }
175
176 if (rr == 2) {
177 emit(newMessage( (_staID + ": No valid RINEX! All values are modulo 299792.458!").toAscii(), true));
178 }
179
180 for (int ii = 0; ii < _Parser.Data.numsats; ii++) {
181 p_obs obs = new t_obs();
182 _obsList.push_back(obs);
183 if (_Parser.Data.satellites[ii] <= PRN_GPS_END) {
184 obs->_o.satSys = 'G';
185 obs->_o.satNum = _Parser.Data.satellites[ii];
186 }
187 else if (_Parser.Data.satellites[ii] <= PRN_GLONASS_END) {
188 obs->_o.satSys = 'R';
189 obs->_o.satNum = _Parser.Data.satellites[ii] - PRN_GLONASS_START + 1;
190 }
191 else {
192 obs->_o.satSys = 'S';
193 obs->_o.satNum = _Parser.Data.satellites[ii] - PRN_WAAS_START + 20;
194 }
195 obs->_o.GPSWeek = _Parser.Data.week;
196 obs->_o.GPSWeeks = _Parser.Data.timeofweek / 1000.0;
197
198 for (int jj = 0; jj < _Parser.numdatatypesGPS; jj++) {
199 int v = 0;
200 // sepearated declaration and initalization of df and pos. Perlt
201 int df;
202 int pos;
203 df = _Parser.dataflag[jj];
204 pos = _Parser.datapos[jj];
205 if ( (_Parser.Data.dataflags[ii] & df)
206 && !isnan(_Parser.Data.measdata[ii][pos])
207 && !isinf(_Parser.Data.measdata[ii][pos])) {
208 v = 1;
209 }
210 else {
211 df = _Parser.dataflagGPS[jj];
212 pos = _Parser.dataposGPS[jj];
213 if ( (_Parser.Data.dataflags[ii] & df)
214 && !isnan(_Parser.Data.measdata[ii][pos])
215 && !isinf(_Parser.Data.measdata[ii][pos])) {
216 v = 1;
217 }
218 }
219 if (!v) {
220 continue;
221 }
222 else
223 {
224 int isat = (_Parser.Data.satellites[ii] < 120
225 ? _Parser.Data.satellites[ii]
226 : _Parser.Data.satellites[ii] - 80);
227
228 // variables df and pos are used consequently. Perlt
229 if (df & GNSSDF_C1DATA) {
230 obs->_o.C1 = _Parser.Data.measdata[ii][pos];
231 }
232 else if (df & GNSSDF_C2DATA) {
233 obs->_o.C2 = _Parser.Data.measdata[ii][pos];
234 }
235 else if (df & GNSSDF_P1DATA) {
236 obs->_o.P1 = _Parser.Data.measdata[ii][pos];
237 }
238 else if (df & GNSSDF_P2DATA) {
239 obs->_o.P2 = _Parser.Data.measdata[ii][pos];
240 }
241 else if (df & (GNSSDF_L1CDATA|GNSSDF_L1PDATA)) {
242 obs->_o.L1 = _Parser.Data.measdata[ii][pos];
243 obs->_o.SNR1 = _Parser.Data.snrL1[ii];
244 obs->_o.lock_timei_L1 = _Parser.lastlockl1[isat];
245 }
246 else if (df & (GNSSDF_L2CDATA|GNSSDF_L2PDATA)) {
247 obs->_o.L2 = _Parser.Data.measdata[ii][pos];
248 obs->_o.SNR2 = _Parser.Data.snrL2[ii];
249 obs->_o.lock_timei_L2 = _Parser.lastlockl2[isat];
250 }
251 else if (df & (GNSSDF_S1CDATA|GNSSDF_S1PDATA)) {
252 obs->_o.S1 = _Parser.Data.measdata[ii][pos];
253 }
254 else if (df & (GNSSDF_S2CDATA|GNSSDF_S2PDATA)) {
255 obs->_o.S2 = _Parser.Data.measdata[ii][pos];
256 }
257 }
258 }
259 }
260 }
261
262 // GPS Ephemeris
263 // -------------
264 else if (rr == 1019) {
265 decoded = true;
266 gpsephemeris* ep = new gpsephemeris(_Parser.ephemerisGPS);
267 emit newGPSEph(ep);
268 }
269
270 // GLONASS Ephemeris
271 // -----------------
272 else if (rr == 1020) {
273 decoded = true;
274 glonassephemeris* ep = new glonassephemeris(_Parser.ephemerisGLONASS);
275 emit newGlonassEph(ep);
276 }
277 }
278 }
279 }
280 if (_mode == unknown && decoded) {
281 _mode = observations;
282 }
283 }
284
285 if (decoded) {
286 return success;
287 }
288 else {
289 return failure;
290 }
291}
Note: See TracBrowser for help on using the repository browser.