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

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

* empty log message *

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