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: bncPPPclient
|
---|
30 | *
|
---|
31 | * Purpose: Precise Point Positioning
|
---|
32 | *
|
---|
33 | * Author: L. Mervart
|
---|
34 | *
|
---|
35 | * Created: 21-Nov-2009
|
---|
36 | *
|
---|
37 | * Changes:
|
---|
38 | *
|
---|
39 | * -----------------------------------------------------------------------*/
|
---|
40 |
|
---|
41 | #include "bncpppclient.h"
|
---|
42 | #include "bncapp.h"
|
---|
43 | #include "bncutils.h"
|
---|
44 | #include "bncconst.h"
|
---|
45 | #include "bncmodel.h"
|
---|
46 |
|
---|
47 | extern "C" {
|
---|
48 | #include "clock_orbit_rtcm.h"
|
---|
49 | }
|
---|
50 |
|
---|
51 | using namespace std;
|
---|
52 |
|
---|
53 | // Constructor
|
---|
54 | ////////////////////////////////////////////////////////////////////////////
|
---|
55 | bncPPPclient::bncPPPclient(QByteArray staID) {
|
---|
56 |
|
---|
57 | connect(((bncApp*)qApp), SIGNAL(newEphGPS(gpsephemeris)),
|
---|
58 | this, SLOT(slotNewEphGPS(gpsephemeris)));
|
---|
59 | connect(((bncApp*)qApp), SIGNAL(newCorrections(QList<QString>)),
|
---|
60 | this, SLOT(slotNewCorrections(QList<QString>)));
|
---|
61 |
|
---|
62 | _staID = staID;
|
---|
63 | _epoData = 0;
|
---|
64 | _model = new bncModel(staID);
|
---|
65 | }
|
---|
66 |
|
---|
67 | // Destructor
|
---|
68 | ////////////////////////////////////////////////////////////////////////////
|
---|
69 | bncPPPclient::~bncPPPclient() {
|
---|
70 | delete _model;
|
---|
71 | delete _epoData;
|
---|
72 | QMapIterator<QString, t_eph*> it(_eph);
|
---|
73 | while (it.hasNext()) {
|
---|
74 | it.next();
|
---|
75 | delete it.value();
|
---|
76 | }
|
---|
77 | QMapIterator<QString, t_corr*> ic(_corr);
|
---|
78 | while (ic.hasNext()) {
|
---|
79 | ic.next();
|
---|
80 | delete ic.value();
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | //
|
---|
85 | ////////////////////////////////////////////////////////////////////////////
|
---|
86 | void bncPPPclient::putNewObs(p_obs pp) {
|
---|
87 | QMutexLocker locker(&_mutex);
|
---|
88 |
|
---|
89 | static const double c1 = t_CST::freq1 * t_CST::freq1 /
|
---|
90 | (t_CST::freq1 * t_CST::freq1 - t_CST::freq2 * t_CST::freq2);
|
---|
91 |
|
---|
92 | static const double c2 = - t_CST::freq2 * t_CST::freq2 /
|
---|
93 | (t_CST::freq1 * t_CST::freq1 - t_CST::freq2 * t_CST::freq2);
|
---|
94 |
|
---|
95 | t_obsInternal* obs = &(pp->_o);
|
---|
96 |
|
---|
97 | t_satData* satData = new t_satData();
|
---|
98 |
|
---|
99 | // Set Code Observations
|
---|
100 | // ---------------------
|
---|
101 | if (obs->P1) {
|
---|
102 | satData->P1 = obs->P1;
|
---|
103 | satData->codeTypeF1 = t_satData::P_CODE;
|
---|
104 | }
|
---|
105 | else if (obs->C1) {
|
---|
106 | satData->P1 = obs->C1;
|
---|
107 | satData->codeTypeF1 = t_satData::C_CODE;
|
---|
108 | }
|
---|
109 | else {
|
---|
110 | delete satData;
|
---|
111 | return;
|
---|
112 | }
|
---|
113 |
|
---|
114 | if (obs->P2) {
|
---|
115 | satData->P2 = obs->P2;
|
---|
116 | satData->codeTypeF2 = t_satData::P_CODE;
|
---|
117 | }
|
---|
118 | else if (obs->C2) {
|
---|
119 | satData->P2 = obs->C2;
|
---|
120 | satData->codeTypeF2 = t_satData::C_CODE;
|
---|
121 | }
|
---|
122 | else {
|
---|
123 | delete satData;
|
---|
124 | return;
|
---|
125 | }
|
---|
126 |
|
---|
127 | satData->P3 = c1 * satData->P1 + c2 * satData->P2;
|
---|
128 |
|
---|
129 | // Set Phase Observations
|
---|
130 | // ----------------------
|
---|
131 | if (obs->L1 && obs->L2) {
|
---|
132 | satData->L1 = obs->L1 * t_CST::lambda1;
|
---|
133 | satData->L2 = obs->L2 * t_CST::lambda2;
|
---|
134 | }
|
---|
135 | else {
|
---|
136 | delete satData;
|
---|
137 | return;
|
---|
138 | }
|
---|
139 | satData->L3 = c1 * satData->L1 + c2 * satData->L2;
|
---|
140 |
|
---|
141 | // Add new Satellite to the epoch
|
---|
142 | // ------------------------------
|
---|
143 | t_time tt(obs->GPSWeek, obs->GPSWeeks);
|
---|
144 |
|
---|
145 | if (!_epoData) {
|
---|
146 | _epoData = new t_epoData();
|
---|
147 | _epoData->tt = tt;
|
---|
148 | }
|
---|
149 | else if (tt != _epoData->tt) {
|
---|
150 | processEpoch();
|
---|
151 | delete _epoData;
|
---|
152 | _epoData = new t_epoData();
|
---|
153 | _epoData->tt = tt;
|
---|
154 | }
|
---|
155 |
|
---|
156 | QString prn =
|
---|
157 | QString("%1%2").arg(obs->satSys).arg(obs->satNum, 2, 10, QChar('0'));
|
---|
158 |
|
---|
159 | _epoData->satData[prn] = satData;
|
---|
160 | }
|
---|
161 |
|
---|
162 | //
|
---|
163 | ////////////////////////////////////////////////////////////////////////////
|
---|
164 | void bncPPPclient::slotNewEphGPS(gpsephemeris gpseph) {
|
---|
165 | QMutexLocker locker(&_mutex);
|
---|
166 |
|
---|
167 | QString prn = QString("G%1").arg(gpseph.satellite, 2, 10, QChar('0'));
|
---|
168 |
|
---|
169 | if (_eph.contains(prn)) {
|
---|
170 | t_ephGPS* ee = static_cast<t_ephGPS*>(_eph.value(prn));
|
---|
171 | if ( (ee->GPSweek() < gpseph.GPSweek) ||
|
---|
172 | (ee->GPSweek() == gpseph.GPSweek &&
|
---|
173 | ee->TOC() < gpseph.TOC) ) {
|
---|
174 | ee->set(&gpseph);
|
---|
175 | }
|
---|
176 | }
|
---|
177 | else {
|
---|
178 | t_ephGPS* ee = new t_ephGPS();
|
---|
179 | ee->set(&gpseph);
|
---|
180 | _eph[prn] = ee;
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | //
|
---|
185 | ////////////////////////////////////////////////////////////////////////////
|
---|
186 | void bncPPPclient::slotNewCorrections(QList<QString> corrList) {
|
---|
187 | QMutexLocker locker(&_mutex);
|
---|
188 |
|
---|
189 | if (corrList.size() == 0) {
|
---|
190 | return;
|
---|
191 | }
|
---|
192 |
|
---|
193 | // Remove All Corrections
|
---|
194 | // ----------------------
|
---|
195 | QMapIterator<QString, t_corr*> ic(_corr);
|
---|
196 | while (ic.hasNext()) {
|
---|
197 | ic.next();
|
---|
198 | delete ic.value();
|
---|
199 | }
|
---|
200 | _corr.clear();
|
---|
201 |
|
---|
202 | QListIterator<QString> it(corrList);
|
---|
203 | while (it.hasNext()) {
|
---|
204 | QTextStream in(it.next().toAscii());
|
---|
205 | int messageType;
|
---|
206 | int updateInterval;
|
---|
207 | int GPSweek;
|
---|
208 | double GPSweeks;
|
---|
209 | QString prn;
|
---|
210 | in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
|
---|
211 | if ( messageType == COTYPE_GPSCOMBINED ||
|
---|
212 | messageType == COTYPE_GLONASSCOMBINED ) {
|
---|
213 | t_corr* cc = 0;
|
---|
214 | if (_corr.contains(prn)) {
|
---|
215 | cc = _corr.value(prn);
|
---|
216 | }
|
---|
217 | else {
|
---|
218 | cc = new t_corr();
|
---|
219 | _corr[prn] = cc;
|
---|
220 | }
|
---|
221 | cc->tt.set(GPSweek, GPSweeks);
|
---|
222 | cc->rao.ReSize(3);
|
---|
223 | in >> cc->iod >> cc->dClk >> cc->rao[0] >> cc->rao[1] >> cc->rao[2];
|
---|
224 | cc->dClk /= t_CST::c;
|
---|
225 | }
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 | // Satellite Position
|
---|
230 | ////////////////////////////////////////////////////////////////////////////
|
---|
231 | t_irc bncPPPclient::getSatPos(const t_time& tt, const QString& prn,
|
---|
232 | ColumnVector& xc, ColumnVector& vv, bool& corr) {
|
---|
233 |
|
---|
234 | const bool CORR_REQUIRED = true;
|
---|
235 | const double MAXAGE = 120.0;
|
---|
236 |
|
---|
237 | corr = false;
|
---|
238 |
|
---|
239 | if (_eph.contains(prn)) {
|
---|
240 | t_eph* ee = _eph.value(prn);
|
---|
241 | ee->position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data());
|
---|
242 |
|
---|
243 | if (CORR_REQUIRED) {
|
---|
244 | if (_corr.contains(prn)) {
|
---|
245 | t_corr* cc = _corr.value(prn);
|
---|
246 | if (ee->IOD() == cc->iod && (tt - cc->tt) < MAXAGE) {
|
---|
247 | corr = true;
|
---|
248 | applyCorr(cc, xc, vv);
|
---|
249 | return success;
|
---|
250 | }
|
---|
251 | }
|
---|
252 | return failure;
|
---|
253 | }
|
---|
254 |
|
---|
255 | return success;
|
---|
256 | }
|
---|
257 |
|
---|
258 | return failure;
|
---|
259 | }
|
---|
260 |
|
---|
261 | //
|
---|
262 | ////////////////////////////////////////////////////////////////////////////
|
---|
263 | void bncPPPclient::applyCorr(const t_corr* cc, ColumnVector& xc,
|
---|
264 | ColumnVector& vv) {
|
---|
265 | ColumnVector dx(3);
|
---|
266 | RSW_to_XYZ(xc.Rows(1,3), vv, cc->rao, dx);
|
---|
267 |
|
---|
268 | xc[0] -= dx[0];
|
---|
269 | xc[1] -= dx[1];
|
---|
270 | xc[2] -= dx[2];
|
---|
271 | xc[3] -= cc->dClk;
|
---|
272 |
|
---|
273 | // Relativistic Correction
|
---|
274 | // -----------------------
|
---|
275 | xc[3] -= 2.0 * DotProduct(xc.Rows(1,3),vv) / t_CST::c / t_CST::c ;
|
---|
276 | }
|
---|
277 |
|
---|
278 | // Correct Time of Transmission
|
---|
279 | ////////////////////////////////////////////////////////////////////////////
|
---|
280 | t_irc bncPPPclient::cmpToT(const QString& prn, t_satData* satData) {
|
---|
281 |
|
---|
282 | double prange = satData->P3;
|
---|
283 | if (prange == 0.0) {
|
---|
284 | return failure;
|
---|
285 | }
|
---|
286 |
|
---|
287 | double clkSat = 0.0;
|
---|
288 | for (int ii = 1; ii <= 10; ii++) {
|
---|
289 |
|
---|
290 | t_time ToT = _epoData->tt - prange / t_CST::c - clkSat;
|
---|
291 |
|
---|
292 | ColumnVector xc(4);
|
---|
293 | ColumnVector vv(3);
|
---|
294 | bool corr = false;
|
---|
295 | if (getSatPos(ToT, prn, xc, vv, corr) != success) {
|
---|
296 | return failure;
|
---|
297 | }
|
---|
298 |
|
---|
299 | double clkSatOld = clkSat;
|
---|
300 | clkSat = xc(4);
|
---|
301 |
|
---|
302 | if ( fabs(clkSat-clkSatOld) * t_CST::c < 1.e-4 ) {
|
---|
303 | satData->xx = xc.Rows(1,3);
|
---|
304 | satData->vv = vv;
|
---|
305 | satData->clk = clkSat * t_CST::c;
|
---|
306 | satData->clkCorr = corr;
|
---|
307 | return success;
|
---|
308 | }
|
---|
309 | }
|
---|
310 |
|
---|
311 | return failure;
|
---|
312 | }
|
---|
313 |
|
---|
314 | //
|
---|
315 | ////////////////////////////////////////////////////////////////////////////
|
---|
316 | void bncPPPclient::processEpoch() {
|
---|
317 |
|
---|
318 | // Data Pre-Processing
|
---|
319 | // -------------------
|
---|
320 | QMutableMapIterator<QString, t_satData*> im(_epoData->satData);
|
---|
321 | while (im.hasNext()) {
|
---|
322 | im.next();
|
---|
323 | QString prn = im.key();
|
---|
324 | t_satData* satData = im.value();
|
---|
325 |
|
---|
326 | if (cmpToT(prn, satData) != success) {
|
---|
327 | delete satData;
|
---|
328 | im.remove();
|
---|
329 | continue;
|
---|
330 | }
|
---|
331 | }
|
---|
332 |
|
---|
333 | // Filter Solution
|
---|
334 | // ---------------
|
---|
335 | if (_model->update(_epoData) != success) {
|
---|
336 | return;
|
---|
337 | }
|
---|
338 | }
|
---|
339 |
|
---|