source: ntrip/trunk/BNC/src/pppRun.cpp@ 11015

Last change on this file since 11015 was 11009, checked in by stuerze, 4 days ago

updates regarding RTCM-SSR: metadata usage in PPP, if available

File size: 24.0 KB
RevLine 
[5860]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 *
[5883]30 * Class: t_pppRun
[5860]31 *
32 * Purpose: Single Real-Time PPP Client
33 *
34 * Author: L. Mervart
35 *
36 * Created: 29-Jul-2014
37 *
[7278]38 * Changes:
[5860]39 *
40 * -----------------------------------------------------------------------*/
41
42
43#include <iostream>
44#include <iomanip>
[5980]45#include <sstream>
[5860]46#include <string.h>
47#include <map>
48
[5883]49#include "pppRun.h"
[5891]50#include "pppThread.h"
[5860]51#include "bnccore.h"
52#include "bncephuser.h"
[5953]53#include "bncsettings.h"
[5984]54#include "bncoutf.h"
[6653]55#include "bncsinextro.h"
[5883]56#include "rinex/rnxobsfile.h"
57#include "rinex/rnxnavfile.h"
58#include "rinex/corrfile.h"
[7299]59#include "combination/bnccomb.h"
[5860]60
61using namespace BNC_PPP;
62using namespace std;
63
64// Constructor
65////////////////////////////////////////////////////////////////////////////
[5883]66t_pppRun::t_pppRun(const t_pppOptions* opt) {
67
[5860]68 _opt = opt;
[5883]69
[7278]70 connect(this, SIGNAL(newMessage(QByteArray,bool)),
[5860]71 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
[5883]72
[5991]73 connect(this, SIGNAL(newPosition(QByteArray, bncTime, QVector<double>)),
[5954]74 BNC_CORE, SIGNAL(newPosition(QByteArray, bncTime, QVector<double>)));
[5949]75
[5991]76 connect(this, SIGNAL(newNMEAstr(QByteArray, QByteArray)),
77 BNC_CORE, SIGNAL(newNMEAstr(QByteArray, QByteArray)));
78
[5883]79 _pppClient = new t_pppClient(_opt);
80
[5984]81 bncSettings settings;
82
[5860]83 if (_opt->_realTime) {
[5945]84 Qt::ConnectionType conType = Qt::AutoConnection;
85 if (BNC_CORE->mode() == t_bncCore::batchPostProcessing) {
86 conType = Qt::BlockingQueuedConnection;
87 }
88
[6137]89 connect(BNC_CORE->caster(), SIGNAL(newObs(QByteArray, QList<t_satObs>)),
90 this, SLOT(slotNewObs(QByteArray, QList<t_satObs>)),conType);
[5860]91
[6433]92 connect(BNC_CORE, SIGNAL(newGPSEph(t_ephGPS)),
93 this, SLOT(slotNewGPSEph(t_ephGPS)),conType);
[7278]94
[6433]95 connect(BNC_CORE, SIGNAL(newGlonassEph(t_ephGlo)),
96 this, SLOT(slotNewGlonassEph(t_ephGlo)),conType);
[7278]97
[6433]98 connect(BNC_CORE, SIGNAL(newGalileoEph(t_ephGal)),
99 this, SLOT(slotNewGalileoEph(t_ephGal)),conType);
[5860]100
[6966]101 connect(BNC_CORE, SIGNAL(newBDSEph(t_ephBDS)),
102 this, SLOT(slotNewBDSEph(t_ephBDS)),conType);
103
[7231]104 connect(BNC_CORE, SIGNAL(newTec(t_vTec)),
105 this, SLOT(slotNewTec(t_vTec)),conType);
106
[11009]107 connect(BNC_CORE, SIGNAL(newMetaData(t_metaData)),
108 this, SLOT(slotNewMetaData(t_metaData)),conType);
109
[6141]110 connect(BNC_CORE, SIGNAL(newOrbCorrections(QList<t_orbCorr>)),
111 this, SLOT(slotNewOrbCorrections(QList<t_orbCorr>)),conType);
112
113 connect(BNC_CORE, SIGNAL(newClkCorrections(QList<t_clkCorr>)),
114 this, SLOT(slotNewClkCorrections(QList<t_clkCorr>)),conType);
[6478]115
116 connect(BNC_CORE, SIGNAL(newCodeBiases(QList<t_satCodeBias>)),
117 this, SLOT(slotNewCodeBiases(QList<t_satCodeBias>)),conType);
[7288]118
119 connect(BNC_CORE, SIGNAL(newPhaseBiases(QList<t_satPhaseBias>)),
120 this, SLOT(slotNewPhaseBiases(QList<t_satPhaseBias>)),conType);
[7299]121
122 connect(BNC_CMB, SIGNAL(newOrbCorrections(QList<t_orbCorr>)),
123 this, SLOT(slotNewOrbCorrections(QList<t_orbCorr>)),conType);
124
125 connect(BNC_CMB, SIGNAL(newClkCorrections(QList<t_clkCorr>)),
126 this, SLOT(slotNewClkCorrections(QList<t_clkCorr>)),conType);
[8320]127
[9709]128 connect(BNC_CMB, SIGNAL(newCodeBiases(QList<t_satCodeBias>)),
129 this, SLOT(slotNewCodeBiases(QList<t_satCodeBias>)),conType);
130
[7972]131 connect(BNC_CORE, SIGNAL(providerIDChanged(QString)),
132 this, SLOT(slotProviderIDChanged(QString)));
[5860]133 }
134 else {
[5889]135 _rnxObsFile = 0;
136 _rnxNavFile = 0;
137 _corrFile = 0;
[10791]138 _biasFile = 0;
[9599]139 _ionoFile = 0;
[5953]140 _speed = settings.value("PPP/mapSpeedSlider").toInt();
[5941]141 connect(this, SIGNAL(progressRnxPPP(int)), BNC_CORE, SIGNAL(progressRnxPPP(int)));
142 connect(this, SIGNAL(finishedRnxPPP()), BNC_CORE, SIGNAL(finishedRnxPPP()));
[7278]143 connect(BNC_CORE, SIGNAL(mapSpeedSliderChanged(int)),
[5950]144 this, SLOT(slotSetSpeed(int)));
[5973]145 connect(BNC_CORE, SIGNAL(stopRinexPPP()), this, SLOT(slotSetStopFlag()));
[5860]146 }
[7278]147
[5973]148 _stopFlag = false;
[5984]149
[8794]150 QString roverName(_opt->_roverName.c_str());
[7506]151 QString country;
152 QString monNum = "0";
153 QString recNum = "0";
[8794]154 if (roverName.length() >= 9) {
155 monNum = QChar(roverName[4]);
156 recNum = QChar(roverName[5]);
157 }
[7506]158 QString intr = "1 day";
159 int sampl = 0;
[8320]160 QString distStr;
161 int num = 0;
162 int statIDlength = roverName.size() -1;
163 QString ID4 = roverName.left(4);
[9615]164 QString ID9 = roverName.left(9);
[8320]165 ID4 = ID4.toUpper();
[9615]166 ID4 = ID9.toUpper();
[7506]167 QListIterator<QString> it(settings.value("mountPoints").toStringList());
168 while (it.hasNext()) {
[8320]169 QString mp = it.next();
170 if (mp.indexOf(roverName.left(statIDlength)) != -1) {
171 ++num;
172 }
173 QStringList hlp = mp.split(" ");
[7506]174 if (hlp.size() < 7)
175 continue;
176 if (hlp.join(" ").indexOf(roverName, 0) != -1) {
177 country = hlp[2];
178 }
179 }
[5988]180
[8320]181 if (num > 1) {
182 distStr = "." + roverName.right(1);
183 }
184
[9615]185 if (ID9.size() < 9) {
186 ID9 = ID4
187 + QString("%1").arg(monNum, 1, 10)
188 + QString("%1").arg(recNum, 1, 10)
189 + country;
190 }
[7506]191 QString logFileSkl = settings.value("PPP/logPath").toString();
[7520]192 int l = logFileSkl.length();
[5988]193 if (logFileSkl.isEmpty()) {
194 _logFile = 0;
[5987]195 }
196 else {
[7520]197 if (l && logFileSkl[l-1] != QDir::separator() ) {
198 logFileSkl += QDir::separator();
199 }
[9783]200
201 logFileSkl = logFileSkl + ID9 + "${V3PROD}" + distStr + ".ppp";
202
[7506]203 _logFile = new bncoutf(logFileSkl, intr, sampl);
[5987]204 }
[5988]205
[7506]206 QString nmeaFileSkl = settings.value("PPP/nmeaPath").toString();
[7520]207 l = nmeaFileSkl.length();
[5988]208 if (nmeaFileSkl.isEmpty()) {
209 _nmeaFile = 0;
210 }
211 else {
[7520]212 if (l > 0 && nmeaFileSkl[l-1] != QDir::separator() ) {
213 nmeaFileSkl += QDir::separator();
214 }
[9783]215 nmeaFileSkl = nmeaFileSkl + ID9 + "${V3PROD}" + distStr + ".nmea";
216
[7506]217 _nmeaFile = new bncoutf(nmeaFileSkl, intr, sampl);
[5988]218 }
[7506]219 QString snxtroFileSkl = settings.value("PPP/snxtroPath").toString();
[7520]220 l = snxtroFileSkl.length();
[6608]221 if (snxtroFileSkl.isEmpty()) {
222 _snxtroFile = 0;
223 }
224 else {
[7520]225 if (l > 0 && snxtroFileSkl[l-1] != QDir::separator() ) {
226 snxtroFileSkl += QDir::separator();
227 }
[9942]228 snxtroFileSkl = snxtroFileSkl + ID9 + '_' + "${V3PROD}" + distStr + ".TRO";
[8403]229 sampl = settings.value("PPP/snxtroSampl").toString().split("sec").first().toInt();
[7506]230 intr = settings.value("PPP/snxtroIntr").toString();
231 _snxtroFile = new bncSinexTro(_opt, snxtroFileSkl, intr, sampl);
[6608]232 }
[5860]233}
234
235// Destructor
236////////////////////////////////////////////////////////////////////////////
[5883]237t_pppRun::~t_pppRun() {
[5984]238 delete _logFile;
[5988]239 delete _nmeaFile;
[6608]240 delete _snxtroFile;
[7655]241 while (!_epoData.empty()) {
[7926]242 delete _epoData.front();
[7655]243 _epoData.pop_front();
244 }
[5860]245}
246
[7278]247//
[5860]248////////////////////////////////////////////////////////////////////////////
[6433]249void t_pppRun::slotNewGPSEph(t_ephGPS eph) {
[5860]250 QMutexLocker locker(&_mutex);
251 _pppClient->putEphemeris(&eph);
252}
253
[7278]254//
[5860]255////////////////////////////////////////////////////////////////////////////
[6433]256void t_pppRun::slotNewGlonassEph(t_ephGlo eph) {
[5860]257 QMutexLocker locker(&_mutex);
258 _pppClient->putEphemeris(&eph);
259}
[7278]260
261//
[5860]262////////////////////////////////////////////////////////////////////////////
[6433]263void t_pppRun::slotNewGalileoEph(t_ephGal eph) {
[5860]264 QMutexLocker locker(&_mutex);
265 _pppClient->putEphemeris(&eph);
266}
267
268//
269////////////////////////////////////////////////////////////////////////////
[6966]270void t_pppRun::slotNewBDSEph(t_ephBDS eph) {
271 QMutexLocker locker(&_mutex);
272 _pppClient->putEphemeris(&eph);
273}
274
275//
276////////////////////////////////////////////////////////////////////////////
[6137]277void t_pppRun::slotNewObs(QByteArray staID, QList<t_satObs> obsList) {
[5860]278 QMutexLocker locker(&_mutex);
279
[10791]280 //// beg test
281 // if (obsList.size() > 0) {
282 // const double sampling = 5.0;
283 // const bncTime& tt = obsList[0]._time;
284 // double mod = remainder(tt.gpssec(), sampling);
285 // if (fabs(mod) > 0.05) {
286 // return;
287 // }
288 // }
289 //// end test
290
[5860]291 if (string(staID.data()) != _opt->_roverName) {
292 return;
293 }
[10590]294/*
[10185]295 int currentWeek = 0;
296 double currentSec = 0.0;
297 currentGPSWeeks(currentWeek, currentSec);
298 bncTime currentTime(currentWeek, currentSec);
[10590]299*/
[7278]300 // Loop over all observations (possible different epochs)
[5860]301 // -----------------------------------------------------
[6137]302 QListIterator<t_satObs> it(obsList);
[5860]303 while (it.hasNext()) {
[6137]304 const t_satObs& oldObs = it.next();
305 t_satObs* newObs = new t_satObs(oldObs);
[5860]306
[10590]307 /* Check regarding current time
[10185]308 // ----------------------------
[10217]309 if (OPT->_realTime && BNC_CORE->mode() != t_bncCore::batchPostProcessing ) {
[10192]310 if ((newObs->_time >= currentTime) || // future time stamp
311 (currentTime - newObs->_time) > 60.0) { // very old data sets
312 delete newObs;
313 continue;
314 }
[10185]315 }
[10590]316 */
[5860]317 // Find the corresponding data epoch or create a new one
318 // -----------------------------------------------------
319 t_epoData* epoch = 0;
320 deque<t_epoData*>::const_iterator it;
321 for (it = _epoData.begin(); it != _epoData.end(); it++) {
322 if (newObs->_time == (*it)->_time) {
323 epoch = *it;
324 break;
325 }
326 }
327 if (epoch == 0) {
328 if (_epoData.empty() || newObs->_time > _epoData.back()->_time) {
329 epoch = new t_epoData;
330 epoch->_time = newObs->_time;
331 _epoData.push_back(epoch);
332 }
333 }
334
[6137]335 // Put data into the epoch
336 // -----------------------
[5860]337 if (epoch != 0) {
338 epoch->_satObs.push_back(newObs);
339 }
[6137]340 else {
341 delete newObs;
342 }
[5860]343 }
344
[7943]345 // Make sure the buffer does not grow beyond any limit
346 // ---------------------------------------------------
[10590]347 const unsigned MAX_EPODATA_SIZE = 120;
[7943]348 if (_epoData.size() > MAX_EPODATA_SIZE) {
349 delete _epoData.front();
350 _epoData.pop_front();
351 }
352
[5860]353 // Process the oldest epochs
354 // ------------------------
[7943]355 while (_epoData.size()) {
[5860]356
357 const vector<t_satObs*>& satObs = _epoData.front()->_satObs;
358
[7943]359 // No corrections yet, skip the epoch
360 // ----------------------------------
361 if (_opt->_corrWaitTime && !_lastClkCorrTime.valid()) {
362 return;
[5873]363 }
364
[7943]365 // Process the front epoch
366 // -----------------------
367 if (_opt->_corrWaitTime == 0 ||
[9622]368 (_epoData.front()->_time - _lastClkCorrTime) < _opt->_corrWaitTime) {
[7278]369
[10185]370 if (_opt->_corrWaitTime != 0 &&
371 (fabs(_epoData.front()->_time - _lastClkCorrTime) > 60.0)) {
[9547]372 delete _epoData.front();
373 _epoData.pop_front();
[9550]374 continue;
[9547]375 }
376
[7943]377 t_output output;
378 _pppClient->processEpoch(satObs, &output);
[5980]379
[7943]380 if (!output._error) {
381 QVector<double> xx(6);
382 xx.data()[0] = output._xyzRover[0];
383 xx.data()[1] = output._xyzRover[1];
384 xx.data()[2] = output._xyzRover[2];
385 xx.data()[3] = output._neu[0];
386 xx.data()[4] = output._neu[1];
387 xx.data()[5] = output._neu[2];
388 emit newPosition(staID, output._epoTime, xx);
389 }
[5984]390
[7943]391 delete _epoData.front();
392 _epoData.pop_front();
393
394 ostringstream log;
[9543]395 if (output._error) {
[7943]396 log << output._log;
[5989]397 }
[7943]398 else {
399 log.setf(ios::fixed);
400 log << string(output._epoTime) << ' ' << staID.data()
401 << " X = " << setprecision(4) << output._xyzRover[0]
402 << " Y = " << setprecision(4) << output._xyzRover[1]
403 << " Z = " << setprecision(4) << output._xyzRover[2]
404 << " NEU: " << showpos << setw(8) << setprecision(4) << output._neu[0]
405 << " " << showpos << setw(8) << setprecision(4) << output._neu[1]
406 << " " << showpos << setw(8) << setprecision(4) << output._neu[2]
407 << " TRP: " << showpos << setw(8) << setprecision(4) << output._trp0
408 << " " << showpos << setw(8) << setprecision(4) << output._trp;
[10805]409 if (output._fixRatio > 0.0) {
410 log << " fix " << int(100*output._fixRatio) << " %";
411 }
412 else {
413 log << " flt ";
414 }
415
[7815]416 }
[7943]417
418 if (_logFile && output._epoTime.valid()) {
419 _logFile->write(output._epoTime.gpsw(), output._epoTime.gpssec(),
420 QString(output._log.c_str()));
421 }
422
423 if (!output._error) {
424 QString rmcStr = nmeaString('R', output);
425 QString ggaStr = nmeaString('G', output);
426 if (_nmeaFile) {
427 _nmeaFile->write(output._epoTime.gpsw(), output._epoTime.gpssec(), rmcStr);
428 _nmeaFile->write(output._epoTime.gpsw(), output._epoTime.gpssec(), ggaStr);
429 }
[8204]430 emit newNMEAstr(staID, rmcStr.toLatin1());
431 emit newNMEAstr(staID, ggaStr.toLatin1());
[7943]432 if (_snxtroFile && output._epoTime.valid()) {
433 _snxtroFile->write(staID, int(output._epoTime.gpsw()), output._epoTime.gpssec(),
434 output._trp0 + output._trp, output._trpStdev);
435 }
436 }
437 emit newMessage(QByteArray(log.str().c_str()), true);
[5989]438 }
[7943]439 else {
440 return;
441 }
[5860]442 }
443}
[7231]444
445//
446////////////////////////////////////////////////////////////////////////////
447void t_pppRun::slotNewTec(t_vTec vTec) {
448 if (vTec._layers.size() == 0) {
449 return;
450 }
451
452 if (_opt->_realTime) {
[9599]453 if (_opt->_ionoMount.empty() && _opt->_corrMount.empty()) {
[7231]454 return;
455 }
[10791]456 if (!_opt->_ionoMount.empty()) {
457 if (_opt->_ionoMount != vTec._staID) {
458 return;
459 }
[9599]460 }
[10791]461 else if (!_opt->_corrMount.empty()) {
462 if (_opt->_corrMount != vTec._staID) {
463 return;
464 }
[9599]465 }
[7231]466 }
467 _pppClient->putTec(&vTec);
468}
469
[7278]470//
[5860]471////////////////////////////////////////////////////////////////////////////
[11009]472void t_pppRun::slotNewMetaData(t_metaData metaData) {
473 if (metaData._entries.size() == 0) {
474 return;
475 }
476
477 if (_opt->_realTime) {
478 if (_opt->_corrMount.empty() || _opt->_corrMount != metaData._staID) {
479 return;
480 }
481 }
482 _pppClient->putMetaData(&metaData);
483}
484
485//
486////////////////////////////////////////////////////////////////////////////
[6141]487void t_pppRun::slotNewOrbCorrections(QList<t_orbCorr> orbCorr) {
488 if (orbCorr.size() == 0) {
489 return;
490 }
[5860]491
[5937]492 if (_opt->_realTime) {
[6141]493 if (_opt->_corrMount.empty() || _opt->_corrMount != orbCorr[0]._staID) {
[5937]494 return;
495 }
[5860]496 }
[6141]497 vector<t_orbCorr*> corrections;
498 for (int ii = 0; ii < orbCorr.size(); ii++) {
499 corrections.push_back(new t_orbCorr(orbCorr[ii]));
500 }
[5860]501
[7278]502 _pppClient->putOrbCorrections(corrections);
503
504 for (unsigned ii = 0; ii < corrections.size(); ii++) {
505 delete corrections[ii];
506 }
[6141]507}
508
[7278]509//
[6141]510////////////////////////////////////////////////////////////////////////////
511void t_pppRun::slotNewClkCorrections(QList<t_clkCorr> clkCorr) {
512 if (clkCorr.size() == 0) {
[5860]513 return;
514 }
515
[7301]516 if (_opt->_realTime) {
[6141]517 if (_opt->_corrMount.empty() || _opt->_corrMount != clkCorr[0]._staID) {
518 return;
[5860]519 }
520 }
[6141]521 vector<t_clkCorr*> corrections;
522 for (int ii = 0; ii < clkCorr.size(); ii++) {
523 corrections.push_back(new t_clkCorr(clkCorr[ii]));
[6991]524 _lastClkCorrTime = clkCorr[ii]._time;
[6141]525 }
[7278]526 _pppClient->putClkCorrections(corrections);
527
528 for (unsigned ii = 0; ii < corrections.size(); ii++) {
529 delete corrections[ii];
530 }
[5860]531}
[5883]532
[7278]533//
[5883]534////////////////////////////////////////////////////////////////////////////
[6478]535void t_pppRun::slotNewCodeBiases(QList<t_satCodeBias> codeBiases) {
536 if (codeBiases.size() == 0) {
537 return;
538 }
539
540 if (_opt->_realTime) {
[10791]541 if (_opt->_corrMount.empty() && _opt->_biasMount.empty()) {
[6478]542 return;
543 }
[10791]544 if (!_opt->_biasMount.empty()) {
545 if (_opt->_biasMount != codeBiases[0]._staID) {
546 return;
547 }
548 }
549 else if (!_opt->_corrMount.empty()) {
550 if (_opt->_corrMount != codeBiases[0]._staID) {
551 return;
552 }
553 }
[6478]554 }
555 vector<t_satCodeBias*> biases;
556 for (int ii = 0; ii < codeBiases.size(); ii++) {
557 biases.push_back(new t_satCodeBias(codeBiases[ii]));
558 }
559
[7278]560 _pppClient->putCodeBiases(biases);
561
562 for (unsigned ii = 0; ii < biases.size(); ii++) {
563 delete biases[ii];
564 }
[6478]565}
566
[7278]567//
[6478]568////////////////////////////////////////////////////////////////////////////
[7288]569void t_pppRun::slotNewPhaseBiases(QList<t_satPhaseBias> phaseBiases) {
570 if (phaseBiases.size() == 0) {
571 return;
572 }
573
574 if (_opt->_realTime) {
[10791]575 if (_opt->_corrMount.empty() && _opt->_biasMount.empty()) {
[7288]576 return;
577 }
[10791]578 if (!_opt->_biasMount.empty()) {
579 if (_opt->_biasMount != phaseBiases[0]._staID) {
580 return;
581 }
582 }
583 else if (!_opt->_corrMount.empty()) {
584 if (_opt->_corrMount != phaseBiases[0]._staID) {
585 return;
586 }
587 }
[7288]588 }
589 vector<t_satPhaseBias*> biases;
590 for (int ii = 0; ii < phaseBiases.size(); ii++) {
591 biases.push_back(new t_satPhaseBias(phaseBiases[ii]));
592 }
593
594 _pppClient->putPhaseBiases(biases);
595
596 for (unsigned ii = 0; ii < biases.size(); ii++) {
597 delete biases[ii];
598 }
599}
600
601//
602////////////////////////////////////////////////////////////////////////////
[5883]603void t_pppRun::processFiles() {
604
605 try {
[5889]606 _rnxObsFile = new t_rnxObsFile(QString(_opt->_rinexObs.c_str()), t_rnxObsFile::input);
[5883]607 }
608 catch (...) {
609 delete _rnxObsFile; _rnxObsFile = 0;
[5940]610 emit finishedRnxPPP();
[5883]611 return;
612 }
613
[9609]614 try {
615 _rnxNavFile = new t_rnxNavFile(QString(_opt->_rinexNav.c_str()), t_rnxNavFile::input);
616 }
617 catch (...) {
618 delete _rnxNavFile; _rnxNavFile = 0;
619 emit finishedRnxPPP();
620 return;
621 }
[5883]622
[5889]623 if (!_opt->_corrFile.empty()) {
624 _corrFile = new t_corrFile(QString(_opt->_corrFile.c_str()));
[10791]625 connect(_corrFile, SIGNAL(newOrbCorrections(QList<t_orbCorr>)), this, SLOT(slotNewOrbCorrections(QList<t_orbCorr>)));
626 connect(_corrFile, SIGNAL(newClkCorrections(QList<t_clkCorr>)), this, SLOT(slotNewClkCorrections(QList<t_clkCorr>)));
[11009]627 connect(_corrFile, SIGNAL(newMetaData(t_metaData)), this, SLOT(slotNewMetaData(t_metaData)));
[10791]628 if (_opt->_biasFile.empty()) {
629 connect(_corrFile, SIGNAL(newCodeBiases(QList<t_satCodeBias>)), this, SLOT(slotNewCodeBiases(QList<t_satCodeBias>)));
630 connect(_corrFile, SIGNAL(newPhaseBiases(QList<t_satPhaseBias>)), this, SLOT(slotNewPhaseBiases(QList<t_satPhaseBias>)));
631 }
[9609]632 if (_opt->_ionoFile.empty()) {
633 connect(_corrFile, SIGNAL(newTec(t_vTec)), this, SLOT(slotNewTec(t_vTec)));
634 }
[5883]635 }
636
[10791]637 if (!_opt->_biasFile.empty()) {
638 _biasFile = new t_corrFile(QString(_opt->_biasFile.c_str()));
639 connect(_biasFile, SIGNAL(newCodeBiases(QList<t_satCodeBias>)), this, SLOT(slotNewCodeBiases(QList<t_satCodeBias>)));
640 connect(_biasFile, SIGNAL(newPhaseBiases(QList<t_satPhaseBias>)), this, SLOT(slotNewPhaseBiases(QList<t_satPhaseBias>)));
641 }
642
[9599]643 if (!_opt->_ionoFile.empty()) {
644 _ionoFile = new t_corrFile(QString(_opt->_corrFile.c_str()));
[9609]645 connect(_ionoFile, SIGNAL(newTec(t_vTec)), this, SLOT(slotNewTec(t_vTec)));
[9599]646 }
647
[5883]648 // Read/Process Observations
649 // -------------------------
650 int nEpo = 0;
651 const t_rnxObsFile::t_rnxEpo* epo = 0;
[5973]652 while ( !_stopFlag && (epo = _rnxObsFile->nextEpoch()) != 0 ) {
[5883]653 ++nEpo;
654
[5951]655 if (_speed < 100) {
656 double sleepTime = 2.0 / _speed;
[6537]657 t_pppThread::msleep(int(sleepTime*1.e3));
[5883]658 }
659
660 // Get Corrections
661 // ---------------
[10791]662 for (t_corrFile* file : {_corrFile, _biasFile, _ionoFile}) {
663 if (file) {
664 try {
665 file->syncRead(epo->tt);
666 }
667 catch (const char* msg) {
668 emit newMessage(QByteArray(msg), true);
669 break;
670 }
671 catch (const string& msg) {
672 emit newMessage(QByteArray(msg.c_str()), true);
673 break;
674 }
675 catch (...) {
676 emit newMessage("unknown exceptions in file " + file->name().toLatin1(), true);
677 break;
678 }
[6510]679 }
[5883]680 }
681
682 // Get Ephemerides
683 // ----------------
684 t_eph* eph = 0;
[7169]685 const QMap<QString, unsigned int>* corrIODs = _corrFile ? &_corrFile->corrIODs() : 0;
[5883]686 while ( (eph = _rnxNavFile->getNextEph(epo->tt, corrIODs)) != 0 ) {
[5889]687 _pppClient->putEphemeris(eph);
688 delete eph; eph = 0;
[5883]689 }
690
[5890]691 // Create list of observations and start epoch processing
692 // ------------------------------------------------------
[6137]693 QList<t_satObs> obsList;
[5883]694 for (unsigned iObs = 0; iObs < epo->rnxSat.size(); iObs++) {
695 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iObs];
[7278]696
[6137]697 t_satObs obs;
[5883]698 t_rnxObsFile::setObsFromRnx(_rnxObsFile, epo, rnxSat, obs);
[5890]699 obsList << obs;
700 }
701 slotNewObs(QByteArray(_opt->_roverName.c_str()), obsList);
[5883]702
[5890]703
[5883]704 if (nEpo % 10 == 0) {
[5940]705 emit progressRnxPPP(nEpo);
[5883]706 }
[7278]707
[5950]708 QCoreApplication::processEvents();
[5883]709 }
710
[5940]711 emit finishedRnxPPP();
[5927]712
[5883]713 if (BNC_CORE->mode() != t_bncCore::interactive) {
[9854]714 qApp->exit(6);
[5883]715 }
[5944]716 else {
717 BNC_CORE->stopPPP();
718 }
[5883]719}
720
[7278]721//
[5883]722////////////////////////////////////////////////////////////////////////////
723void t_pppRun::slotSetSpeed(int speed) {
724 QMutexLocker locker(&_mutex);
725 _speed = speed;
726}
[5973]727
[7278]728//
[5973]729////////////////////////////////////////////////////////////////////////////
730void t_pppRun::slotSetStopFlag() {
731 QMutexLocker locker(&_mutex);
732 _stopFlag = true;
733}
[5989]734
[7278]735//
[5989]736////////////////////////////////////////////////////////////////////////////
[5990]737QString t_pppRun::nmeaString(char strType, const t_output& output) {
[5989]738
[7278]739 double ell[3];
[5989]740 xyz2ell(output._xyzRover, ell);
741 double phiDeg = ell[0] * 180 / M_PI;
742 double lamDeg = ell[1] * 180 / M_PI;
743
[7926]744 unsigned year, month, day;
745 output._epoTime.civil_date(year, month, day);
746 double gps_utc = gnumleap(year, month, day);
747
[5989]748 char phiCh = 'N';
749 if (phiDeg < 0) {
750 phiDeg = -phiDeg;
751 phiCh = 'S';
[7278]752 }
[5989]753 char lamCh = 'E';
754 if (lamDeg < 0) {
755 lamDeg = -lamDeg;
756 lamCh = 'W';
[7278]757 }
[5989]758
[5990]759 ostringstream out;
760 out.setf(ios::fixed);
[5989]761
[5990]762 if (strType == 'R') {
[8824]763 string datestr = (output._epoTime - gps_utc).datestr(0); // yyyymmdd
[7278]764 out << "GPRMC,"
[7926]765 << (output._epoTime - gps_utc).timestr(3,0) << ",A,"
[7278]766 << setw(2) << setfill('0') << int(phiDeg)
[8824]767 << setw(7) << setprecision(4) << setfill('0') << fmod(60*phiDeg,60) << ',' << phiCh << ','
[7278]768 << setw(3) << setfill('0') << int(lamDeg)
[8824]769 << setw(7) << setprecision(4) << setfill('0') << fmod(60*lamDeg,60) << ',' << lamCh << ",,,"
770 << datestr[6] << datestr[7] << datestr[4] << datestr[5] << datestr[2] << datestr[3] << ",,";
[5990]771 }
772 else if (strType == 'G') {
[7278]773 out << "GPGGA,"
[7926]774 << (output._epoTime - gps_utc).timestr(2,0) << ','
[7278]775 << setw(2) << setfill('0') << int(phiDeg)
776 << setw(10) << setprecision(7) << setfill('0')
[5990]777 << fmod(60*phiDeg,60) << ',' << phiCh << ','
[7278]778 << setw(3) << setfill('0') << int(lamDeg)
779 << setw(10) << setprecision(7) << setfill('0')
780 << fmod(60*lamDeg,60) << ',' << lamCh
[5990]781 << ",1," << setw(2) << setfill('0') << output._numSat << ','
[7926]782 << setw(3) << setprecision(1) << output._hDop << ','
[5990]783 << setprecision(3) << ell[2] << ",M,0.0,M,,";
784 }
785 else {
786 return "";
787 }
[5989]788
[5990]789 QString nmStr(out.str().c_str());
[5989]790 unsigned char XOR = 0;
791 for (int ii = 0; ii < nmStr.length(); ii++) {
[8204]792 XOR ^= (unsigned char) nmStr[ii].toLatin1();
[5989]793 }
794
[8692]795 return '$' + nmStr + QString("*%1").arg(XOR, 2, 16, QLatin1Char('0')) + "\n";
[5989]796}
[7972]797
798//
799////////////////////////////////////////////////////////////////////////////
800void t_pppRun::slotProviderIDChanged(QString mountPoint) {
801 QMutexLocker locker(&_mutex);
802
803 if (mountPoint.toStdString() !=_opt->_corrMount) {
804 return;
805 }
806
[10763]807 QString msg = "pppRun " + QString(_opt->_roverName.c_str()) + ": SSR Provider or Service changed: " + mountPoint;
[8204]808 emit newMessage(msg.toLatin1(), true);
[7972]809
810 _pppClient->reset();
811
812 while (!_epoData.empty()) {
813 delete _epoData.front();
814 _epoData.pop_front();
815 }
816}
Note: See TracBrowser for help on using the repository browser.