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

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

* empty log message *

File size: 6.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 "bncconst.h"
47#include "bncapp.h"
48
49using namespace std;
50
51#ifndef isinf
52# define isinf(x) 0
53#endif
54
55//
56////////////////////////////////////////////////////////////////////////////
57ephSender::ephSender() {
58 connect(this, SIGNAL(newGPSEph(gpsephemeris*)),
59 (bncApp*) qApp, SLOT(slotNewGPSEph(gpsephemeris*)));
60 connect(this, SIGNAL(newGlonassEph(glonassephemeris*)),
61 (bncApp*) qApp, SLOT(slotNewGlonassEph(glonassephemeris*)));
62}
63
64// Error Handling
65////////////////////////////////////////////////////////////////////////////
66void RTCM3Error(const char*, ...) {
67}
68
69// Constructor
70////////////////////////////////////////////////////////////////////////////
71RTCM3Decoder::RTCM3Decoder() : GPSDecoder() {
72
73 const int LEAPSECONDS = 14; /* only needed for approx. time */
74
75 time_t tim;
76 tim = time(0) - ((10*365+2+5)*24*60*60 + LEAPSECONDS);
77
78 memset(&_Parser, 0, sizeof(_Parser));
79 _Parser.GPSWeek = tim/(7*24*60*60);
80 _Parser.GPSTOW = tim%(7*24*60*60);
81}
82
83// Destructor
84////////////////////////////////////////////////////////////////////////////
85RTCM3Decoder::~RTCM3Decoder() {
86 QListIterator<p_obs> it(_obsList);
87 while (it.hasNext()) {
88 delete it.next();
89 }
90 _obsList.clear();
91}
92
93//
94////////////////////////////////////////////////////////////////////////////
95void RTCM3Decoder::Decode(char* buffer, int bufLen) {
96
97 for (int ii = 0; ii < bufLen; ii++) {
98
99 _Parser.Message[_Parser.MessageSize++] = buffer[ii];
100 if (_Parser.MessageSize >= _Parser.NeedBytes) {
101
102 while(int rr = RTCM3Parser(&_Parser)) {
103
104 // GNSS Observations
105 // -----------------
106 if (rr == 1 || rr == 2) {
107
108 if (!_Parser.init) {
109 HandleHeader(&_Parser);
110 _Parser.init = 1;
111 }
112
113 if (rr == 2) {
114 std::cerr << "No valid RINEX! All values are modulo 299792.458!\n";
115 }
116
117 for (int ii = 0; ii < _Parser.Data.numsats; ii++) {
118 Observation* obs = new Observation();
119 if (_Parser.Data.satellites[ii] <= PRN_GPS_END) {
120 obs->satSys = 'G';
121 obs->satNum = _Parser.Data.satellites[ii];
122 }
123 else if (_Parser.Data.satellites[ii] <= PRN_GLONASS_END) {
124 obs->satSys = 'R';
125 obs->satNum = _Parser.Data.satellites[ii] - PRN_GLONASS_START + 1;
126 }
127 else {
128 obs->satSys = 'S';
129 obs->satNum = _Parser.Data.satellites[ii] - PRN_WAAS_START + 20;
130 }
131 obs->GPSWeek = _Parser.Data.week;
132 obs->GPSWeeks = _Parser.Data.timeofweek / 1000.0;
133
134 for (int jj = 0; jj < _Parser.numdatatypesGPS; jj++) {
135 int v = 0;
136 int df = _Parser.dataflag[jj];
137 int pos = _Parser.datapos[jj];
138 if ( (_Parser.Data.dataflags[ii] & df)
139 && !isnan(_Parser.Data.measdata[ii][pos])
140 && !isinf(_Parser.Data.measdata[ii][pos])) {
141 v = 1;
142 }
143 else {
144 df = _Parser.dataflagGPS[jj];
145 pos = _Parser.dataposGPS[jj];
146 if ( (_Parser.Data.dataflags[ii] & df)
147 && !isnan(_Parser.Data.measdata[ii][pos])
148 && !isinf(_Parser.Data.measdata[ii][pos])) {
149 v = 1;
150 }
151 }
152 if(!v)
153 { continue; }
154 else
155 {
156 if (_Parser.dataflag[jj] & GNSSDF_C1DATA) {
157 obs->C1 = _Parser.Data.measdata[ii][_Parser.datapos[jj]];
158 }
159 else if (_Parser.dataflag[jj] & GNSSDF_C2DATA) {
160 obs->C2 = _Parser.Data.measdata[ii][_Parser.datapos[jj]];
161 }
162 else if (_Parser.dataflag[jj] & GNSSDF_P1DATA) {
163 obs->P1 = _Parser.Data.measdata[ii][_Parser.datapos[jj]];
164 }
165 else if (_Parser.dataflag[jj] & GNSSDF_P2DATA) {
166 obs->P2 = _Parser.Data.measdata[ii][_Parser.datapos[jj]];
167 }
168 else if (df & (GNSSDF_L1CDATA|GNSSDF_L1PDATA)) {
169 obs->L1 = _Parser.Data.measdata[ii][pos];
170 obs->SNR1 = _Parser.Data.snrL1[ii];
171 }
172 else if (df & (GNSSDF_L2CDATA|GNSSDF_L2PDATA)) {
173 obs->L2 = _Parser.Data.measdata[ii][pos];
174 obs->SNR2 = _Parser.Data.snrL2[ii];
175 }
176 else if (df & (GNSSDF_S1CDATA|GNSSDF_S1PDATA)) {
177 obs->S1 = _Parser.Data.measdata[ii][pos];
178 }
179 else if (df & (GNSSDF_S2CDATA|GNSSDF_S2PDATA)) {
180 obs->S2 = _Parser.Data.measdata[ii][pos];
181 }
182 }
183 }
184 _obsList.push_back(obs);
185 }
186 }
187
188 // GPS Ephemeris
189 // -------------
190 else if (rr == 1019) {
191 gpsephemeris* ep = new gpsephemeris(_Parser.ephemerisGPS);
192 emit _ephSender.newGPSEph(ep);
193 }
194
195 // GLONASS Ephemeris
196 // -----------------
197 else if (rr == 1020) {
198 glonassephemeris* ep = new glonassephemeris(_Parser.ephemerisGLONASS);
199 emit _ephSender.newGlonassEph(ep);
200 }
201 }
202 }
203 }
204}
Note: See TracBrowser for help on using the repository browser.