1 |
|
---|
2 | // Part of BNC, a utility for retrieving decoding and
|
---|
3 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
4 | //
|
---|
5 | // Copyright (C) 2007
|
---|
6 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
7 | // http://www.bkg.bund.de
|
---|
8 | // Czech Technical University Prague, Department of Geodesy
|
---|
9 | // http://www.fsv.cvut.cz
|
---|
10 | //
|
---|
11 | // Email: euref-ip@bkg.bund.de
|
---|
12 | //
|
---|
13 | // This program is free software; you can redistribute it and/or
|
---|
14 | // modify it under the terms of the GNU General Public License
|
---|
15 | // as published by the Free Software Foundation, version 2.
|
---|
16 | //
|
---|
17 | // This program is distributed in the hope that it will be useful,
|
---|
18 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
20 | // GNU General Public License for more details.
|
---|
21 | //
|
---|
22 | // You should have received a copy of the GNU General Public License
|
---|
23 | // along with this program; if not, write to the Free Software
|
---|
24 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
25 |
|
---|
26 | /* -------------------------------------------------------------------------
|
---|
27 | * BKG NTRIP Client
|
---|
28 | * -------------------------------------------------------------------------
|
---|
29 | *
|
---|
30 | * Class: t_pppRun
|
---|
31 | *
|
---|
32 | * Purpose: Single Real-Time PPP Client
|
---|
33 | *
|
---|
34 | * Author: L. Mervart
|
---|
35 | *
|
---|
36 | * Created: 29-Jul-2014
|
---|
37 | *
|
---|
38 | * Changes:
|
---|
39 | *
|
---|
40 | * -----------------------------------------------------------------------*/
|
---|
41 |
|
---|
42 |
|
---|
43 | #include <iostream>
|
---|
44 | #include <iomanip>
|
---|
45 | #include <string.h>
|
---|
46 | #include <map>
|
---|
47 |
|
---|
48 | #include "pppRun.h"
|
---|
49 | #include "pppThread.h"
|
---|
50 | #include "bnccore.h"
|
---|
51 | #include "bncephuser.h"
|
---|
52 | #include "rinex/rnxobsfile.h"
|
---|
53 | #include "rinex/rnxnavfile.h"
|
---|
54 | #include "rinex/corrfile.h"
|
---|
55 |
|
---|
56 | using namespace BNC_PPP;
|
---|
57 | using namespace std;
|
---|
58 |
|
---|
59 | // Constructor
|
---|
60 | ////////////////////////////////////////////////////////////////////////////
|
---|
61 | t_pppRun::t_pppRun(const t_pppOptions* opt) {
|
---|
62 |
|
---|
63 | cout << "t_pppRun" << endl;
|
---|
64 |
|
---|
65 | _opt = opt;
|
---|
66 |
|
---|
67 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
68 | BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
|
---|
69 |
|
---|
70 | for (unsigned iPrn = 0; iPrn <= t_prn::MAXPRN; iPrn++) {
|
---|
71 | _lastOrbCorrIOD[iPrn] = -1;
|
---|
72 | _lastClkCorrValue[iPrn] = 0.0;
|
---|
73 | }
|
---|
74 |
|
---|
75 | _pppClient = new t_pppClient(_opt);
|
---|
76 |
|
---|
77 | if (_opt->_realTime) {
|
---|
78 | connect(this, SIGNAL(newPosition(bncTime, QVector<double>)),
|
---|
79 | BNC_CORE, SIGNAL(newPosition(bncTime, QVector<double>)));
|
---|
80 |
|
---|
81 | Qt::ConnectionType conType = Qt::AutoConnection;
|
---|
82 | if (BNC_CORE->mode() == t_bncCore::batchPostProcessing) {
|
---|
83 | conType = Qt::BlockingQueuedConnection;
|
---|
84 | }
|
---|
85 |
|
---|
86 | connect(BNC_CORE->caster(), SIGNAL(newObs(QByteArray, QList<t_obs>)),
|
---|
87 | this, SLOT(slotNewObs(QByteArray, QList<t_obs>)),conType);
|
---|
88 |
|
---|
89 | connect(BNC_CORE, SIGNAL(newEphGPS(gpsephemeris)),
|
---|
90 | this, SLOT(slotNewEphGPS(gpsephemeris)),conType);
|
---|
91 |
|
---|
92 | connect(BNC_CORE, SIGNAL(newEphGlonass(glonassephemeris)),
|
---|
93 | this, SLOT(slotNewEphGlonass(glonassephemeris)),conType);
|
---|
94 |
|
---|
95 | connect(BNC_CORE, SIGNAL(newEphGalileo(galileoephemeris)),
|
---|
96 | this, SLOT(slotNewEphGalileo(galileoephemeris)),conType);
|
---|
97 |
|
---|
98 | connect(BNC_CORE, SIGNAL(newCorrections(QStringList)),
|
---|
99 | this, SLOT(slotNewCorrections(QStringList)),conType);
|
---|
100 | }
|
---|
101 | else {
|
---|
102 | _rnxObsFile = 0;
|
---|
103 | _rnxNavFile = 0;
|
---|
104 | _corrFile = 0;
|
---|
105 | _maxSpeed = 0;
|
---|
106 | _speed = 0;
|
---|
107 | connect(this, SIGNAL(progressRnxPPP(int)), BNC_CORE, SIGNAL(progressRnxPPP(int)));
|
---|
108 | connect(this, SIGNAL(finishedRnxPPP()), BNC_CORE, SIGNAL(finishedRnxPPP()));
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | // Destructor
|
---|
113 | ////////////////////////////////////////////////////////////////////////////
|
---|
114 | t_pppRun::~t_pppRun() {
|
---|
115 | cout << "~t_pppRun" << endl;
|
---|
116 | }
|
---|
117 |
|
---|
118 | //
|
---|
119 | ////////////////////////////////////////////////////////////////////////////
|
---|
120 | void t_pppRun::slotNewEphGPS(gpsephemeris gpseph) {
|
---|
121 | QMutexLocker locker(&_mutex);
|
---|
122 | t_ephGPS eph;
|
---|
123 | eph.set(&gpseph);
|
---|
124 | _pppClient->putEphemeris(&eph);
|
---|
125 | }
|
---|
126 |
|
---|
127 | //
|
---|
128 | ////////////////////////////////////////////////////////////////////////////
|
---|
129 | void t_pppRun::slotNewEphGlonass(glonassephemeris gloeph) {
|
---|
130 | QMutexLocker locker(&_mutex);
|
---|
131 | t_ephGlo eph;
|
---|
132 | eph.set(&gloeph);
|
---|
133 | _pppClient->putEphemeris(&eph);
|
---|
134 | }
|
---|
135 |
|
---|
136 | //
|
---|
137 | ////////////////////////////////////////////////////////////////////////////
|
---|
138 | void t_pppRun::slotNewEphGalileo(galileoephemeris galeph) {
|
---|
139 | QMutexLocker locker(&_mutex);
|
---|
140 | t_ephGal eph;
|
---|
141 | eph.set(&galeph);
|
---|
142 | _pppClient->putEphemeris(&eph);
|
---|
143 | }
|
---|
144 |
|
---|
145 | //
|
---|
146 | ////////////////////////////////////////////////////////////////////////////
|
---|
147 | void t_pppRun::slotNewObs(QByteArray staID, QList<t_obs> obsList) {
|
---|
148 | QMutexLocker locker(&_mutex);
|
---|
149 |
|
---|
150 | if (string(staID.data()) != _opt->_roverName) {
|
---|
151 | return;
|
---|
152 | }
|
---|
153 |
|
---|
154 | // Loop over all obsevations (possible different epochs)
|
---|
155 | // -----------------------------------------------------
|
---|
156 | QListIterator<t_obs> it(obsList);
|
---|
157 | while (it.hasNext()) {
|
---|
158 | const t_obs& oldObs = it.next();
|
---|
159 | t_satObs* newObs = new t_satObs;
|
---|
160 |
|
---|
161 | newObs->_prn.set(oldObs.satSys, oldObs.satNum);
|
---|
162 | newObs->_time.set(oldObs.GPSWeek, oldObs.GPSWeeks);
|
---|
163 |
|
---|
164 | // Find the corresponding data epoch or create a new one
|
---|
165 | // -----------------------------------------------------
|
---|
166 | t_epoData* epoch = 0;
|
---|
167 | deque<t_epoData*>::const_iterator it;
|
---|
168 | for (it = _epoData.begin(); it != _epoData.end(); it++) {
|
---|
169 | if (newObs->_time == (*it)->_time) {
|
---|
170 | epoch = *it;
|
---|
171 | break;
|
---|
172 | }
|
---|
173 | }
|
---|
174 | if (epoch == 0) {
|
---|
175 | if (_epoData.empty() || newObs->_time > _epoData.back()->_time) {
|
---|
176 | epoch = new t_epoData;
|
---|
177 | epoch->_time = newObs->_time;
|
---|
178 | _epoData.push_back(epoch);
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|
182 | // Fill the new observation and add it to the corresponding epoch
|
---|
183 | // --------------------------------------------------------------
|
---|
184 | if (epoch != 0) {
|
---|
185 | epoch->_satObs.push_back(newObs);
|
---|
186 | map<string, t_frqObs*> frqObsMap;
|
---|
187 | for (unsigned iEntry = 0; iEntry < GNSSENTRY_NUMBER; iEntry++) {
|
---|
188 | string hlp = oldObs.rnxStr(iEntry).toAscii().data();
|
---|
189 | if (hlp.length() >= 2 && oldObs._measdata[iEntry] != 0.0) {
|
---|
190 | char obsType = hlp[0];
|
---|
191 | string rnxType2ch = hlp.substr(1);
|
---|
192 | if (obsType == 'C' || obsType == 'L') {
|
---|
193 | t_frqObs* frqObs = 0;
|
---|
194 | if (frqObsMap.find(rnxType2ch) == frqObsMap.end()) {
|
---|
195 | frqObs = new t_frqObs();
|
---|
196 | frqObsMap[rnxType2ch] = frqObs;
|
---|
197 | frqObs->_rnxType2ch = rnxType2ch;
|
---|
198 | newObs->_obs.push_back(frqObs);
|
---|
199 | }
|
---|
200 | else {
|
---|
201 | frqObs = frqObsMap[rnxType2ch];
|
---|
202 | }
|
---|
203 | if (obsType == 'C') {
|
---|
204 | frqObs->_code = oldObs._measdata[iEntry];
|
---|
205 | frqObs->_codeValid = true;
|
---|
206 | }
|
---|
207 | else if (obsType == 'L') {
|
---|
208 | frqObs->_phase = oldObs._measdata[iEntry];
|
---|
209 | frqObs->_phaseValid = true;
|
---|
210 | }
|
---|
211 | }
|
---|
212 | }
|
---|
213 | }
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | // Process the oldest epochs
|
---|
218 | // ------------------------
|
---|
219 | while (_epoData.size() &&
|
---|
220 | (!_opt->_realTime || _epoData.front()->_time < _lastClkCorrTime + 10.0)) {
|
---|
221 |
|
---|
222 | const vector<t_satObs*>& satObs = _epoData.front()->_satObs;
|
---|
223 |
|
---|
224 | t_output output;
|
---|
225 | _pppClient->processEpoch(satObs, &output);
|
---|
226 |
|
---|
227 | if (!output._error && _opt->xyzAprRoverSet()) {
|
---|
228 | QVector<double> xx(6);
|
---|
229 | xx.data()[0] = output._xyzRover[0];
|
---|
230 | xx.data()[1] = output._xyzRover[1];
|
---|
231 | xx.data()[2] = output._xyzRover[2];
|
---|
232 | xx.data()[3] = output._neu[0];
|
---|
233 | xx.data()[4] = output._neu[1];
|
---|
234 | xx.data()[5] = output._neu[2];
|
---|
235 | emit newPosition(output._epoTime, xx);
|
---|
236 | }
|
---|
237 |
|
---|
238 | delete _epoData.front(); _epoData.pop_front();
|
---|
239 |
|
---|
240 | bool showOnScreen = _opt->_realTime;
|
---|
241 | emit newMessage(QByteArray(output._log.c_str()), showOnScreen);
|
---|
242 | }
|
---|
243 | }
|
---|
244 |
|
---|
245 | //
|
---|
246 | ////////////////////////////////////////////////////////////////////////////
|
---|
247 | void t_pppRun::slotNewCorrections(QStringList corrList) {
|
---|
248 | QMutexLocker locker(&_mutex);
|
---|
249 |
|
---|
250 | // Check the Mountpoint (source of corrections)
|
---|
251 | // --------------------------------------------
|
---|
252 | if (_opt->_realTime) {
|
---|
253 | if (_opt->_corrMount.empty()) {
|
---|
254 | return;
|
---|
255 | }
|
---|
256 | QMutableListIterator<QString> itm(corrList);
|
---|
257 | while (itm.hasNext()) {
|
---|
258 | QStringList hlp = itm.next().split(" ");
|
---|
259 | if (hlp.size() > 0) {
|
---|
260 | QString mountpoint = hlp[hlp.size()-1];
|
---|
261 | if (mountpoint != QString(_opt->_corrMount.c_str())) {
|
---|
262 | itm.remove();
|
---|
263 | }
|
---|
264 | }
|
---|
265 | }
|
---|
266 | }
|
---|
267 |
|
---|
268 | if (corrList.size() == 0) {
|
---|
269 | return;
|
---|
270 | }
|
---|
271 |
|
---|
272 | vector<t_orbCorr*> orbCorr;
|
---|
273 | vector<t_clkCorr*> clkCorr;
|
---|
274 | vector<t_satBias*> satBias;
|
---|
275 |
|
---|
276 | QListIterator<QString> it(corrList);
|
---|
277 | while (it.hasNext()) {
|
---|
278 | QString line = it.next();
|
---|
279 |
|
---|
280 | QTextStream in(&line);
|
---|
281 | int messageType;
|
---|
282 | int updateInterval;
|
---|
283 | int GPSweek;
|
---|
284 | double GPSweeks;
|
---|
285 | QString prn;
|
---|
286 | in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
|
---|
287 |
|
---|
288 | if ( t_corr::relevantMessageType(messageType) ) {
|
---|
289 | t_corr corr;
|
---|
290 | corr.readLine(line);
|
---|
291 | if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
|
---|
292 | messageType == COTYPE_GPSORBIT || messageType == COTYPE_GLONASSORBIT ) {
|
---|
293 | t_orbCorr* cc = new t_orbCorr();
|
---|
294 | cc->_prn.set(corr.prn.toAscii().data());
|
---|
295 | cc->_iod = corr.iod;
|
---|
296 | cc->_time = corr.tRao;
|
---|
297 | cc->_system = 'R';
|
---|
298 | cc->_xr[0] = corr.rao[0];
|
---|
299 | cc->_xr[1] = corr.rao[1];
|
---|
300 | cc->_xr[2] = corr.rao[2];
|
---|
301 | cc->_dotXr[0] = corr.dotRao[0];
|
---|
302 | cc->_dotXr[0] = corr.dotRao[1];
|
---|
303 | cc->_dotXr[0] = corr.dotRao[2];
|
---|
304 | orbCorr.push_back(cc);
|
---|
305 |
|
---|
306 | _lastOrbCorrIOD[cc->_prn.toInt()] = cc->_iod;
|
---|
307 | }
|
---|
308 | else if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
|
---|
309 | messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK ) {
|
---|
310 | t_clkCorr* cc = new t_clkCorr();
|
---|
311 | cc->_prn.set(corr.prn.toAscii().data());
|
---|
312 | cc->_iod = corr.iod;
|
---|
313 | cc->_time = corr.tClk;
|
---|
314 | cc->_dClk = corr.dClk;
|
---|
315 | cc->_dotDClk = corr.dotDClk;
|
---|
316 | cc->_dotDotDClk = corr.dotDotDClk;
|
---|
317 | cc->_clkPartial = 0.0;
|
---|
318 | if (messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK) {
|
---|
319 | int lastIOD = _lastOrbCorrIOD[cc->_prn.toInt()];
|
---|
320 | if (lastIOD != -1) {
|
---|
321 | cc->_iod = lastIOD;
|
---|
322 | }
|
---|
323 | else {
|
---|
324 | delete cc;
|
---|
325 | cc = 0;
|
---|
326 | }
|
---|
327 | }
|
---|
328 | if (cc) {
|
---|
329 | clkCorr.push_back(cc);
|
---|
330 | if (_lastClkCorrTime.undef() || cc->_time > _lastClkCorrTime) {
|
---|
331 | _lastClkCorrTime = cc->_time;
|
---|
332 | }
|
---|
333 | }
|
---|
334 | }
|
---|
335 | }
|
---|
336 | else if ( messageType == BTYPE_GPS || messageType == BTYPE_GLONASS ) {
|
---|
337 | t_bias bias;
|
---|
338 | bias.readLine(line);
|
---|
339 | }
|
---|
340 | }
|
---|
341 |
|
---|
342 | _pppClient->putOrbCorrections(orbCorr);
|
---|
343 | _pppClient->putClkCorrections(clkCorr);
|
---|
344 | _pppClient->putBiases(satBias);
|
---|
345 |
|
---|
346 | for (unsigned ii = 0; ii < orbCorr.size(); ii++) {
|
---|
347 | delete orbCorr[ii];
|
---|
348 | }
|
---|
349 | for (unsigned ii = 0; ii < clkCorr.size(); ii++) {
|
---|
350 | delete clkCorr[ii];
|
---|
351 | }
|
---|
352 | for (unsigned ii = 0; ii < satBias.size(); ii++) {
|
---|
353 | delete satBias[ii];
|
---|
354 | }
|
---|
355 | }
|
---|
356 |
|
---|
357 |
|
---|
358 | //
|
---|
359 | ////////////////////////////////////////////////////////////////////////////
|
---|
360 | void t_pppRun::processFiles() {
|
---|
361 |
|
---|
362 | try {
|
---|
363 | _rnxObsFile = new t_rnxObsFile(QString(_opt->_rinexObs.c_str()), t_rnxObsFile::input);
|
---|
364 | }
|
---|
365 | catch (...) {
|
---|
366 | delete _rnxObsFile; _rnxObsFile = 0;
|
---|
367 | emit finishedRnxPPP();
|
---|
368 | return;
|
---|
369 | }
|
---|
370 |
|
---|
371 | _rnxNavFile = new t_rnxNavFile(QString(_opt->_rinexNav.c_str()), t_rnxNavFile::input);
|
---|
372 |
|
---|
373 | if (!_opt->_corrFile.empty()) {
|
---|
374 | _corrFile = new t_corrFile(QString(_opt->_corrFile.c_str()));
|
---|
375 | connect(_corrFile, SIGNAL(newCorrections(QStringList)),
|
---|
376 | this, SLOT(slotNewCorrections(QStringList)));
|
---|
377 | }
|
---|
378 |
|
---|
379 | // Read/Process Observations
|
---|
380 | // -------------------------
|
---|
381 | int nEpo = 0;
|
---|
382 | const t_rnxObsFile::t_rnxEpo* epo = 0;
|
---|
383 | while ( (epo = _rnxObsFile->nextEpoch()) != 0 ) {
|
---|
384 | ++nEpo;
|
---|
385 |
|
---|
386 | if (_maxSpeed != 0) {
|
---|
387 | QMutexLocker locker(&_mutex);
|
---|
388 | if (_speed < _maxSpeed) {
|
---|
389 | double sleepTime = 0.02 * _maxSpeed / _speed;
|
---|
390 | t_pppThread::msleep(sleepTime*1.e3);
|
---|
391 | }
|
---|
392 | }
|
---|
393 |
|
---|
394 | // Get Corrections
|
---|
395 | // ---------------
|
---|
396 | if (_corrFile) {
|
---|
397 | _corrFile->syncRead(epo->tt);
|
---|
398 | }
|
---|
399 |
|
---|
400 | // Get Ephemerides
|
---|
401 | // ----------------
|
---|
402 | t_eph* eph = 0;
|
---|
403 | const QMap<QString, int>* corrIODs = _corrFile ? &_corrFile->corrIODs() : 0;
|
---|
404 | while ( (eph = _rnxNavFile->getNextEph(epo->tt, corrIODs)) != 0 ) {
|
---|
405 | _pppClient->putEphemeris(eph);
|
---|
406 | delete eph; eph = 0;
|
---|
407 | }
|
---|
408 |
|
---|
409 | // Create list of observations and start epoch processing
|
---|
410 | // ------------------------------------------------------
|
---|
411 | QList<t_obs> obsList;
|
---|
412 | for (unsigned iObs = 0; iObs < epo->rnxSat.size(); iObs++) {
|
---|
413 | const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iObs];
|
---|
414 |
|
---|
415 | t_obs obs;
|
---|
416 | t_rnxObsFile::setObsFromRnx(_rnxObsFile, epo, rnxSat, obs);
|
---|
417 | obsList << obs;
|
---|
418 | }
|
---|
419 | slotNewObs(QByteArray(_opt->_roverName.c_str()), obsList);
|
---|
420 |
|
---|
421 |
|
---|
422 | if (nEpo % 10 == 0) {
|
---|
423 | emit progressRnxPPP(nEpo);
|
---|
424 | }
|
---|
425 | }
|
---|
426 |
|
---|
427 | emit finishedRnxPPP();
|
---|
428 |
|
---|
429 | if (BNC_CORE->mode() != t_bncCore::interactive) {
|
---|
430 | qApp->exit(0);
|
---|
431 | }
|
---|
432 | else {
|
---|
433 | BNC_CORE->stopPPP();
|
---|
434 | }
|
---|
435 | }
|
---|
436 |
|
---|
437 | //
|
---|
438 | ////////////////////////////////////////////////////////////////////////////
|
---|
439 | void t_pppRun::slotSetSpeed(int speed) {
|
---|
440 | QMutexLocker locker(&_mutex);
|
---|
441 | _speed = speed;
|
---|
442 | }
|
---|