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