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

Last change on this file since 990 was 970, checked in by mervart, 16 years ago

* empty log message *

File size: 7.2 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
[689]67// Ensure, that the Decoder uses the "old" convention for the data structure for Rinex2. Perlt
68 _Parser.rinex3 = 0;
69
[296]70 time_t tim;
71 tim = time(0) - ((10*365+2+5)*24*60*60 + LEAPSECONDS);
[505]72
73 memset(&_Parser, 0, sizeof(_Parser));
[296]74 _Parser.GPSWeek = tim/(7*24*60*60);
75 _Parser.GPSTOW = tim%(7*24*60*60);
[880]76
[939]77 connect(this, SIGNAL(newGPSEph(gpsephemeris*)),
78 (bncApp*) qApp, SLOT(slotNewGPSEph(gpsephemeris*)));
79 connect(this, SIGNAL(newGlonassEph(glonassephemeris*)),
80 (bncApp*) qApp, SLOT(slotNewGlonassEph(glonassephemeris*)));
81
[880]82 // Sub-Decoder for Clock and Orbit Corrections
83 // -------------------------------------------
[970]84 _coDecoder = new RTCM3coDecoder(staID);
[296]85}
86
87// Destructor
88////////////////////////////////////////////////////////////////////////////
89RTCM3Decoder::~RTCM3Decoder() {
[880]90 delete _coDecoder;
[296]91}
92
93//
94////////////////////////////////////////////////////////////////////////////
[649]95t_irc RTCM3Decoder::Decode(char* buffer, int bufLen) {
[508]96
[913]97 bool decoded = false;
98
[880]99 // Try to decode Clock and Orbit Corrections
100 // -----------------------------------------
[913]101 if ( _coDecoder->Decode(buffer, bufLen) == success ) {
102 decoded = true;
103 }
[880]104
105 // Remaining part decodes the Observations
106 // ---------------------------------------
[296]107 for (int ii = 0; ii < bufLen; ii++) {
[505]108
[296]109 _Parser.Message[_Parser.MessageSize++] = buffer[ii];
110 if (_Parser.MessageSize >= _Parser.NeedBytes) {
111
112 while(int rr = RTCM3Parser(&_Parser)) {
113
[511]114 // GNSS Observations
115 // -----------------
116 if (rr == 1 || rr == 2) {
[658]117 decoded = true;
[296]118
[511]119 if (!_Parser.init) {
120 HandleHeader(&_Parser);
121 _Parser.init = 1;
122 }
123
124 if (rr == 2) {
125 std::cerr << "No valid RINEX! All values are modulo 299792.458!\n";
126 }
127
128 for (int ii = 0; ii < _Parser.Data.numsats; ii++) {
[622]129 p_obs obs = new t_obs();
[627]130 _obsList.push_back(obs);
[554]131 if (_Parser.Data.satellites[ii] <= PRN_GPS_END) {
[622]132 obs->_o.satSys = 'G';
133 obs->_o.satNum = _Parser.Data.satellites[ii];
[511]134 }
[554]135 else if (_Parser.Data.satellites[ii] <= PRN_GLONASS_END) {
[622]136 obs->_o.satSys = 'R';
137 obs->_o.satNum = _Parser.Data.satellites[ii] - PRN_GLONASS_START + 1;
[511]138 }
[554]139 else {
[622]140 obs->_o.satSys = 'S';
141 obs->_o.satNum = _Parser.Data.satellites[ii] - PRN_WAAS_START + 20;
[554]142 }
[622]143 obs->_o.GPSWeek = _Parser.Data.week;
144 obs->_o.GPSWeeks = _Parser.Data.timeofweek / 1000.0;
[511]145
146 for (int jj = 0; jj < _Parser.numdatatypesGPS; jj++) {
147 int v = 0;
[689]148// sepearated declaration and initalization of df and pos. Perlt
149 int df;
150 int pos;
151 df = _Parser.dataflag[jj];
152 pos = _Parser.datapos[jj];
[366]153 if ( (_Parser.Data.dataflags[ii] & df)
154 && !isnan(_Parser.Data.measdata[ii][pos])
155 && !isinf(_Parser.Data.measdata[ii][pos])) {
[511]156 v = 1;
[366]157 }
[511]158 else {
159 df = _Parser.dataflagGPS[jj];
160 pos = _Parser.dataposGPS[jj];
161 if ( (_Parser.Data.dataflags[ii] & df)
162 && !isnan(_Parser.Data.measdata[ii][pos])
163 && !isinf(_Parser.Data.measdata[ii][pos])) {
164 v = 1;
165 }
166 }
[627]167 if (!v) {
168 continue;
[511]169 }
[627]170 else
171 {
[689]172// variables df and pos are used consequently. Perlt
173 if (df & GNSSDF_C1DATA) {
174 obs->_o.C1 = _Parser.Data.measdata[ii][pos];
[627]175 }
[689]176 else if (df & GNSSDF_C2DATA) {
177 obs->_o.C2 = _Parser.Data.measdata[ii][pos];
[627]178 }
[689]179 else if (df & GNSSDF_P1DATA) {
180 obs->_o.P1 = _Parser.Data.measdata[ii][pos];
[627]181 }
[689]182 else if (df & GNSSDF_P2DATA) {
183 obs->_o.P2 = _Parser.Data.measdata[ii][pos];
[627]184 }
185 else if (df & (GNSSDF_L1CDATA|GNSSDF_L1PDATA)) {
186 obs->_o.L1 = _Parser.Data.measdata[ii][pos];
187 obs->_o.SNR1 = _Parser.Data.snrL1[ii];
188 }
189 else if (df & (GNSSDF_L2CDATA|GNSSDF_L2PDATA)) {
190 obs->_o.L2 = _Parser.Data.measdata[ii][pos];
191 obs->_o.SNR2 = _Parser.Data.snrL2[ii];
192 }
193 else if (df & (GNSSDF_S1CDATA|GNSSDF_S1PDATA)) {
194 obs->_o.S1 = _Parser.Data.measdata[ii][pos];
195 }
196 else if (df & (GNSSDF_S2CDATA|GNSSDF_S2PDATA)) {
197 obs->_o.S2 = _Parser.Data.measdata[ii][pos];
198 }
[511]199 }
[366]200 }
[296]201 }
202 }
[511]203
204 // GPS Ephemeris
205 // -------------
206 else if (rr == 1019) {
[658]207 decoded = true;
[511]208 gpsephemeris* ep = new gpsephemeris(_Parser.ephemerisGPS);
[939]209 emit newGPSEph(ep);
[511]210 }
211
212 // GLONASS Ephemeris
213 // -----------------
214 else if (rr == 1020) {
[658]215 decoded = true;
[511]216 glonassephemeris* ep = new glonassephemeris(_Parser.ephemerisGLONASS);
[939]217 emit newGlonassEph(ep);
[511]218 }
[296]219 }
220 }
221 }
[658]222 if (!decoded) {
223 return failure;
224 }
225 else {
[649]226 return success;
[658]227 }
[296]228}
Note: See TracBrowser for help on using the repository browser.