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

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

* empty log message *

File size: 8.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 "RTCM3coDecoder.h"
47#include "bncconst.h"
48#include "bncapp.h"
49
50using namespace std;
51
52#ifndef isinf
53# define isinf(x) 0
54#endif
55
56// Error Handling
57////////////////////////////////////////////////////////////////////////////
58void RTCM3Error(const char*, ...) {
59}
60
61// Constructor
62////////////////////////////////////////////////////////////////////////////
63RTCM3Decoder::RTCM3Decoder(const QString& staID) : GPSDecoder() {
64
65 const int LEAPSECONDS = 14; /* only needed for approx. time */
66
67 QSettings settings;
68 _checkMountPoint = settings.value("messTypes").toString();
69 _staID = staID;
70
71 // Ensure, that the Decoder uses the "old" convention for the data structure for Rinex2. Perlt
72 _Parser.rinex3 = 0;
73
74 time_t tim;
75 tim = time(0) - ((10*365+2+5)*24*60*60 + LEAPSECONDS);
76
77 memset(&_Parser, 0, sizeof(_Parser));
78 _Parser.GPSWeek = tim/(7*24*60*60);
79 _Parser.GPSTOW = tim%(7*24*60*60);
80
81 connect(this, SIGNAL(newGPSEph(gpsephemeris*)),
82 (bncApp*) qApp, SLOT(slotNewGPSEph(gpsephemeris*)));
83 connect(this, SIGNAL(newGlonassEph(glonassephemeris*)),
84 (bncApp*) qApp, SLOT(slotNewGlonassEph(glonassephemeris*)));
85
86 // Sub-Decoder for Clock and Orbit Corrections
87 // -------------------------------------------
88 _coDecoder = new RTCM3coDecoder(staID);
89
90 // Mode can be either observations or corrections
91 // ----------------------------------------------
92 _mode = unknown;
93}
94
95// Destructor
96////////////////////////////////////////////////////////////////////////////
97RTCM3Decoder::~RTCM3Decoder() {
98 delete _coDecoder;
99}
100
101//
102////////////////////////////////////////////////////////////////////////////
103t_irc RTCM3Decoder::Decode(char* buffer, int bufLen) {
104
105 bool decoded = false;
106
107 // Try to decode Clock and Orbit Corrections
108 // -----------------------------------------
109 if (_mode == unknown || _mode == corrections) {
110 printf("corrections\n");
111 if ( _coDecoder->Decode(buffer, bufLen) == success ) {
112 decoded = true;
113 if (_mode == unknown) {
114 _mode = corrections;
115// emit(newMessage( (_staID + " : mode set to corrections").toAscii() ));
116 }
117 }
118 }
119
120 // Remaining part decodes the Observations
121 // ---------------------------------------
122 if (_mode == unknown || _mode == observations || _checkMountPoint == _staID || _checkMountPoint == "ALL") {
123 printf("observations\n");
124 for (int ii = 0; ii < bufLen; ii++) {
125
126 _Parser.Message[_Parser.MessageSize++] = buffer[ii];
127 if (_Parser.MessageSize >= _Parser.NeedBytes) {
128
129 // RTCM message types
130 // ------------------
131 for (int kk = 0; kk < _Parser.typeSize; kk++) {
132 _typeList.push_back(_Parser.typeList[kk]);
133 }
134 _Parser.typeSize = 0;
135
136 while(int rr = RTCM3Parser(&_Parser)) {
137
138 // GNSS Observations
139 // -----------------
140 if (rr == 1 || rr == 2) {
141 decoded = true;
142
143 if (!_Parser.init) {
144 HandleHeader(&_Parser);
145 _Parser.init = 1;
146 }
147
148 if (rr == 2) {
149// std::cerr << "No valid RINEX! All values are modulo 299792.458!\n";
150 emit(newMessage( (_staID + ": No valid RINEX! All values are modulo 299792.458!").toAscii() ));
151 }
152
153 for (int ii = 0; ii < _Parser.Data.numsats; ii++) {
154 p_obs obs = new t_obs();
155 _obsList.push_back(obs);
156 if (_Parser.Data.satellites[ii] <= PRN_GPS_END) {
157 obs->_o.satSys = 'G';
158 obs->_o.satNum = _Parser.Data.satellites[ii];
159 }
160 else if (_Parser.Data.satellites[ii] <= PRN_GLONASS_END) {
161 obs->_o.satSys = 'R';
162 obs->_o.satNum = _Parser.Data.satellites[ii] - PRN_GLONASS_START + 1;
163 }
164 else {
165 obs->_o.satSys = 'S';
166 obs->_o.satNum = _Parser.Data.satellites[ii] - PRN_WAAS_START + 20;
167 }
168 obs->_o.GPSWeek = _Parser.Data.week;
169 obs->_o.GPSWeeks = _Parser.Data.timeofweek / 1000.0;
170
171 for (int jj = 0; jj < _Parser.numdatatypesGPS; jj++) {
172 int v = 0;
173 // sepearated declaration and initalization of df and pos. Perlt
174 int df;
175 int pos;
176 df = _Parser.dataflag[jj];
177 pos = _Parser.datapos[jj];
178 if ( (_Parser.Data.dataflags[ii] & df)
179 && !isnan(_Parser.Data.measdata[ii][pos])
180 && !isinf(_Parser.Data.measdata[ii][pos])) {
181 v = 1;
182 }
183 else {
184 df = _Parser.dataflagGPS[jj];
185 pos = _Parser.dataposGPS[jj];
186 if ( (_Parser.Data.dataflags[ii] & df)
187 && !isnan(_Parser.Data.measdata[ii][pos])
188 && !isinf(_Parser.Data.measdata[ii][pos])) {
189 v = 1;
190 }
191 }
192 if (!v) {
193 continue;
194 }
195 else
196 {
197 // variables df and pos are used consequently. Perlt
198 if (df & GNSSDF_C1DATA) {
199 obs->_o.C1 = _Parser.Data.measdata[ii][pos];
200 }
201 else if (df & GNSSDF_C2DATA) {
202 obs->_o.C2 = _Parser.Data.measdata[ii][pos];
203 }
204 else if (df & GNSSDF_P1DATA) {
205 obs->_o.P1 = _Parser.Data.measdata[ii][pos];
206 }
207 else if (df & GNSSDF_P2DATA) {
208 obs->_o.P2 = _Parser.Data.measdata[ii][pos];
209 }
210 else if (df & (GNSSDF_L1CDATA|GNSSDF_L1PDATA)) {
211 obs->_o.L1 = _Parser.Data.measdata[ii][pos];
212 obs->_o.SNR1 = _Parser.Data.snrL1[ii];
213 }
214 else if (df & (GNSSDF_L2CDATA|GNSSDF_L2PDATA)) {
215 obs->_o.L2 = _Parser.Data.measdata[ii][pos];
216 obs->_o.SNR2 = _Parser.Data.snrL2[ii];
217 }
218 else if (df & (GNSSDF_S1CDATA|GNSSDF_S1PDATA)) {
219 obs->_o.S1 = _Parser.Data.measdata[ii][pos];
220 }
221 else if (df & (GNSSDF_S2CDATA|GNSSDF_S2PDATA)) {
222 obs->_o.S2 = _Parser.Data.measdata[ii][pos];
223 }
224 }
225 }
226 }
227 }
228
229 // GPS Ephemeris
230 // -------------
231 else if (rr == 1019) {
232 decoded = true;
233 gpsephemeris* ep = new gpsephemeris(_Parser.ephemerisGPS);
234 emit newGPSEph(ep);
235 }
236
237 // GLONASS Ephemeris
238 // -----------------
239 else if (rr == 1020) {
240 decoded = true;
241 glonassephemeris* ep = new glonassephemeris(_Parser.ephemerisGLONASS);
242 emit newGlonassEph(ep);
243 }
244 }
245 }
246 }
247 if (_mode == unknown && decoded) {
248 _mode = observations;
249// emit(newMessage( (_staID + " : mode set to observations").toAscii() ));
250 }
251 }
252
253 if (decoded) {
254 return success;
255 }
256 else {
257 return failure;
258 }
259}
Note: See TracBrowser for help on using the repository browser.