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

Last change on this file since 1032 was 1030, checked in by weber, 18 years ago

* empty log message *

File size: 8.3 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 _staID = staID;
68
69 // Ensure, that the Decoder uses the "old" convention for the data structure for Rinex2. Perlt
70 _Parser.rinex3 = 0;
71
72 time_t tim;
73 tim = time(0) - ((10*365+2+5)*24*60*60 + LEAPSECONDS);
74
75 memset(&_Parser, 0, sizeof(_Parser));
76 _Parser.GPSWeek = tim/(7*24*60*60);
77 _Parser.GPSTOW = tim%(7*24*60*60);
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) {
102
103 bool decoded = false;
104
105 // Try to decode Clock and Orbit Corrections
106 // -----------------------------------------
107 if (_mode == unknown || _mode == corrections) {
108 if ( _coDecoder->Decode(buffer, bufLen) == success ) {
109 decoded = true;
110 if (_mode == unknown) {
111 _mode = corrections;
112 emit(newMessage( (_staID + " : mode set to corrections").toAscii() ));
113 }
114 }
115 }
116
117 // Remaining part decodes the Observations
118 // ---------------------------------------
119 if (_mode == unknown || _mode == observations) {
120 for (int ii = 0; ii < bufLen; ii++) {
121
122 _Parser.Message[_Parser.MessageSize++] = buffer[ii];
123 if (_Parser.MessageSize >= _Parser.NeedBytes) {
124
125 while(int rr = RTCM3Parser(&_Parser)) {
126
127 // RTCM message types
128 // ------------------
129 for (int kk = 0; kk < _Parser.typeSize; kk++) {
130 _typeList.push_back(_Parser.typeList[kk]);
131 }
132 _Parser.typeSize = 0;
133
134 // GNSS Observations
135 // -----------------
136 if (rr == 1 || rr == 2) {
137 decoded = true;
138
139 if (!_Parser.init) {
140 HandleHeader(&_Parser);
141 _Parser.init = 1;
142 }
143
144 if (rr == 2) {
145 std::cerr << "No valid RINEX! All values are modulo 299792.458!\n";
146 }
147
148 for (int ii = 0; ii < _Parser.Data.numsats; ii++) {
149 p_obs obs = new t_obs();
150 _obsList.push_back(obs);
151 if (_Parser.Data.satellites[ii] <= PRN_GPS_END) {
152 obs->_o.satSys = 'G';
153 obs->_o.satNum = _Parser.Data.satellites[ii];
154 }
155 else if (_Parser.Data.satellites[ii] <= PRN_GLONASS_END) {
156 obs->_o.satSys = 'R';
157 obs->_o.satNum = _Parser.Data.satellites[ii] - PRN_GLONASS_START + 1;
158 }
159 else {
160 obs->_o.satSys = 'S';
161 obs->_o.satNum = _Parser.Data.satellites[ii] - PRN_WAAS_START + 20;
162 }
163 obs->_o.GPSWeek = _Parser.Data.week;
164 obs->_o.GPSWeeks = _Parser.Data.timeofweek / 1000.0;
165
166 for (int jj = 0; jj < _Parser.numdatatypesGPS; jj++) {
167 int v = 0;
168 // sepearated declaration and initalization of df and pos. Perlt
169 int df;
170 int pos;
171 df = _Parser.dataflag[jj];
172 pos = _Parser.datapos[jj];
173 if ( (_Parser.Data.dataflags[ii] & df)
174 && !isnan(_Parser.Data.measdata[ii][pos])
175 && !isinf(_Parser.Data.measdata[ii][pos])) {
176 v = 1;
177 }
178 else {
179 df = _Parser.dataflagGPS[jj];
180 pos = _Parser.dataposGPS[jj];
181 if ( (_Parser.Data.dataflags[ii] & df)
182 && !isnan(_Parser.Data.measdata[ii][pos])
183 && !isinf(_Parser.Data.measdata[ii][pos])) {
184 v = 1;
185 }
186 }
187 if (!v) {
188 continue;
189 }
190 else
191 {
192 // variables df and pos are used consequently. Perlt
193 if (df & GNSSDF_C1DATA) {
194 obs->_o.C1 = _Parser.Data.measdata[ii][pos];
195 }
196 else if (df & GNSSDF_C2DATA) {
197 obs->_o.C2 = _Parser.Data.measdata[ii][pos];
198 }
199 else if (df & GNSSDF_P1DATA) {
200 obs->_o.P1 = _Parser.Data.measdata[ii][pos];
201 }
202 else if (df & GNSSDF_P2DATA) {
203 obs->_o.P2 = _Parser.Data.measdata[ii][pos];
204 }
205 else if (df & (GNSSDF_L1CDATA|GNSSDF_L1PDATA)) {
206 obs->_o.L1 = _Parser.Data.measdata[ii][pos];
207 obs->_o.SNR1 = _Parser.Data.snrL1[ii];
208 }
209 else if (df & (GNSSDF_L2CDATA|GNSSDF_L2PDATA)) {
210 obs->_o.L2 = _Parser.Data.measdata[ii][pos];
211 obs->_o.SNR2 = _Parser.Data.snrL2[ii];
212 }
213 else if (df & (GNSSDF_S1CDATA|GNSSDF_S1PDATA)) {
214 obs->_o.S1 = _Parser.Data.measdata[ii][pos];
215 }
216 else if (df & (GNSSDF_S2CDATA|GNSSDF_S2PDATA)) {
217 obs->_o.S2 = _Parser.Data.measdata[ii][pos];
218 }
219 }
220 }
221 }
222 }
223
224 // GPS Ephemeris
225 // -------------
226 else if (rr == 1019) {
227 decoded = true;
228 gpsephemeris* ep = new gpsephemeris(_Parser.ephemerisGPS);
229 emit newGPSEph(ep);
230 }
231
232 // GLONASS Ephemeris
233 // -----------------
234 else if (rr == 1020) {
235 decoded = true;
236 glonassephemeris* ep = new glonassephemeris(_Parser.ephemerisGLONASS);
237 emit newGlonassEph(ep);
238 }
239 }
240 }
241 }
242 if (_mode == unknown && decoded) {
243 _mode = observations;
244 emit(newMessage( (_staID + " : mode set to observations").toAscii() ));
245 }
246 }
247
248 if (decoded) {
249 return success;
250 }
251 else {
252 return failure;
253 }
254}
Note: See TracBrowser for help on using the repository browser.