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