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

Last change on this file since 1024 was 1022, checked in by mervart, 18 years ago

* empty log message *

File size: 8.1 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 // GNSS Observations
128 // -----------------
129 if (rr == 1 || rr == 2) {
130 decoded = true;
131
132 if (!_Parser.init) {
133 HandleHeader(&_Parser);
134 _Parser.init = 1;
135 }
136
137 if (rr == 2) {
138 std::cerr << "No valid RINEX! All values are modulo 299792.458!\n";
139 }
140
141 for (int ii = 0; ii < _Parser.Data.numsats; ii++) {
142 p_obs obs = new t_obs();
143 _obsList.push_back(obs);
144 if (_Parser.Data.satellites[ii] <= PRN_GPS_END) {
145 obs->_o.satSys = 'G';
146 obs->_o.satNum = _Parser.Data.satellites[ii];
147 }
148 else if (_Parser.Data.satellites[ii] <= PRN_GLONASS_END) {
149 obs->_o.satSys = 'R';
150 obs->_o.satNum = _Parser.Data.satellites[ii] - PRN_GLONASS_START + 1;
151 }
152 else {
153 obs->_o.satSys = 'S';
154 obs->_o.satNum = _Parser.Data.satellites[ii] - PRN_WAAS_START + 20;
155 }
156 obs->_o.GPSWeek = _Parser.Data.week;
157 obs->_o.GPSWeeks = _Parser.Data.timeofweek / 1000.0;
158
159 for (int jj = 0; jj < _Parser.numdatatypesGPS; jj++) {
160 int v = 0;
161 // sepearated declaration and initalization of df and pos. Perlt
162 int df;
163 int pos;
164 df = _Parser.dataflag[jj];
165 pos = _Parser.datapos[jj];
166 if ( (_Parser.Data.dataflags[ii] & df)
167 && !isnan(_Parser.Data.measdata[ii][pos])
168 && !isinf(_Parser.Data.measdata[ii][pos])) {
169 v = 1;
170 }
171 else {
172 df = _Parser.dataflagGPS[jj];
173 pos = _Parser.dataposGPS[jj];
174 if ( (_Parser.Data.dataflags[ii] & df)
175 && !isnan(_Parser.Data.measdata[ii][pos])
176 && !isinf(_Parser.Data.measdata[ii][pos])) {
177 v = 1;
178 }
179 }
180 if (!v) {
181 continue;
182 }
183 else
184 {
185 // variables df and pos are used consequently. Perlt
186 if (df & GNSSDF_C1DATA) {
187 obs->_o.C1 = _Parser.Data.measdata[ii][pos];
188 }
189 else if (df & GNSSDF_C2DATA) {
190 obs->_o.C2 = _Parser.Data.measdata[ii][pos];
191 }
192 else if (df & GNSSDF_P1DATA) {
193 obs->_o.P1 = _Parser.Data.measdata[ii][pos];
194 }
195 else if (df & GNSSDF_P2DATA) {
196 obs->_o.P2 = _Parser.Data.measdata[ii][pos];
197 }
198 else if (df & (GNSSDF_L1CDATA|GNSSDF_L1PDATA)) {
199 obs->_o.L1 = _Parser.Data.measdata[ii][pos];
200 obs->_o.SNR1 = _Parser.Data.snrL1[ii];
201 }
202 else if (df & (GNSSDF_L2CDATA|GNSSDF_L2PDATA)) {
203 obs->_o.L2 = _Parser.Data.measdata[ii][pos];
204 obs->_o.SNR2 = _Parser.Data.snrL2[ii];
205 }
206 else if (df & (GNSSDF_S1CDATA|GNSSDF_S1PDATA)) {
207 obs->_o.S1 = _Parser.Data.measdata[ii][pos];
208 }
209 else if (df & (GNSSDF_S2CDATA|GNSSDF_S2PDATA)) {
210 obs->_o.S2 = _Parser.Data.measdata[ii][pos];
211 }
212 }
213 }
214 }
215 }
216
217 // GPS Ephemeris
218 // -------------
219 else if (rr == 1019) {
220 decoded = true;
221 gpsephemeris* ep = new gpsephemeris(_Parser.ephemerisGPS);
222 emit newGPSEph(ep);
223 }
224
225 // GLONASS Ephemeris
226 // -----------------
227 else if (rr == 1020) {
228 decoded = true;
229 glonassephemeris* ep = new glonassephemeris(_Parser.ephemerisGLONASS);
230 emit newGlonassEph(ep);
231 }
232 }
233 }
234 }
235 if (_mode == unknown && decoded) {
236 _mode = observations;
237 emit(newMessage( (_staID + " : mode set to observations").toAscii() ));
238 }
239 }
240
241 if (decoded) {
242 return success;
243 }
244 else {
245 return failure;
246 }
247}
Note: See TracBrowser for help on using the repository browser.