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

Last change on this file since 11041 was 11041, checked in by stuerze, 10 days ago

updates regarding RTCM-SSR

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