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

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

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

File size: 24.0 KB
Line 
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 <sstream>
46#include <string.h>
47#include <map>
48
49#include "pppRun.h"
50#include "pppThread.h"
51#include "bnccore.h"
52#include "bncephuser.h"
53#include "bncsettings.h"
54#include "bncoutf.h"
55#include "bncsinextro.h"
56#include "rinex/rnxobsfile.h"
57#include "rinex/rnxnavfile.h"
58#include "rinex/corrfile.h"
59#include "combination/bnccomb.h"
60
61using namespace BNC_PPP;
62using namespace std;
63
64// Constructor
65////////////////////////////////////////////////////////////////////////////
66t_pppRun::t_pppRun(const t_pppOptions* opt) {
67
68 _opt = opt;
69
70 connect(this, SIGNAL(newMessage(QByteArray,bool)),
71 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
72
73 connect(this, SIGNAL(newPosition(QByteArray, bncTime, QVector<double>)),
74 BNC_CORE, SIGNAL(newPosition(QByteArray, bncTime, QVector<double>)));
75
76 connect(this, SIGNAL(newNMEAstr(QByteArray, QByteArray)),
77 BNC_CORE, SIGNAL(newNMEAstr(QByteArray, QByteArray)));
78
79 _pppClient = new t_pppClient(_opt);
80
81 bncSettings settings;
82
83 if (_opt->_realTime) {
84 Qt::ConnectionType conType = Qt::AutoConnection;
85 if (BNC_CORE->mode() == t_bncCore::batchPostProcessing) {
86 conType = Qt::BlockingQueuedConnection;
87 }
88
89 connect(BNC_CORE->caster(), SIGNAL(newObs(QByteArray, QList<t_satObs>)),
90 this, SLOT(slotNewObs(QByteArray, QList<t_satObs>)),conType);
91
92 connect(BNC_CORE, SIGNAL(newGPSEph(t_ephGPS)),
93 this, SLOT(slotNewGPSEph(t_ephGPS)),conType);
94
95 connect(BNC_CORE, SIGNAL(newGlonassEph(t_ephGlo)),
96 this, SLOT(slotNewGlonassEph(t_ephGlo)),conType);
97
98 connect(BNC_CORE, SIGNAL(newGalileoEph(t_ephGal)),
99 this, SLOT(slotNewGalileoEph(t_ephGal)),conType);
100
101 connect(BNC_CORE, SIGNAL(newBDSEph(t_ephBDS)),
102 this, SLOT(slotNewBDSEph(t_ephBDS)),conType);
103
104 connect(BNC_CORE, SIGNAL(newTec(t_vTec)),
105 this, SLOT(slotNewTec(t_vTec)),conType);
106
107 connect(BNC_CORE, SIGNAL(newMetaData(t_metaData)),
108 this, SLOT(slotNewMetaData(t_metaData)),conType);
109
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);
115
116 connect(BNC_CORE, SIGNAL(newCodeBiases(QList<t_satCodeBias>)),
117 this, SLOT(slotNewCodeBiases(QList<t_satCodeBias>)),conType);
118
119 connect(BNC_CORE, SIGNAL(newPhaseBiases(QList<t_satPhaseBias>)),
120 this, SLOT(slotNewPhaseBiases(QList<t_satPhaseBias>)),conType);
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);
127
128 connect(BNC_CMB, SIGNAL(newCodeBiases(QList<t_satCodeBias>)),
129 this, SLOT(slotNewCodeBiases(QList<t_satCodeBias>)),conType);
130
131 connect(BNC_CORE, SIGNAL(providerIDChanged(QString)),
132 this, SLOT(slotProviderIDChanged(QString)));
133 }
134 else {
135 _rnxObsFile = 0;
136 _rnxNavFile = 0;
137 _corrFile = 0;
138 _biasFile = 0;
139 _ionoFile = 0;
140 _speed = settings.value("PPP/mapSpeedSlider").toInt();
141 connect(this, SIGNAL(progressRnxPPP(int)), BNC_CORE, SIGNAL(progressRnxPPP(int)));
142 connect(this, SIGNAL(finishedRnxPPP()), BNC_CORE, SIGNAL(finishedRnxPPP()));
143 connect(BNC_CORE, SIGNAL(mapSpeedSliderChanged(int)),
144 this, SLOT(slotSetSpeed(int)));
145 connect(BNC_CORE, SIGNAL(stopRinexPPP()), this, SLOT(slotSetStopFlag()));
146 }
147
148 _stopFlag = false;
149
150 QString roverName(_opt->_roverName.c_str());
151 QString country;
152 QString monNum = "0";
153 QString recNum = "0";
154 if (roverName.length() >= 9) {
155 monNum = QChar(roverName[4]);
156 recNum = QChar(roverName[5]);
157 }
158 QString intr = "1 day";
159 int sampl = 0;
160 QString distStr;
161 int num = 0;
162 int statIDlength = roverName.size() -1;
163 QString ID4 = roverName.left(4);
164 QString ID9 = roverName.left(9);
165 ID4 = ID4.toUpper();
166 ID4 = ID9.toUpper();
167 QListIterator<QString> it(settings.value("mountPoints").toStringList());
168 while (it.hasNext()) {
169 QString mp = it.next();
170 if (mp.indexOf(roverName.left(statIDlength)) != -1) {
171 ++num;
172 }
173 QStringList hlp = mp.split(" ");
174 if (hlp.size() < 7)
175 continue;
176 if (hlp.join(" ").indexOf(roverName, 0) != -1) {
177 country = hlp[2];
178 }
179 }
180
181 if (num > 1) {
182 distStr = "." + roverName.right(1);
183 }
184
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 }
191 QString logFileSkl = settings.value("PPP/logPath").toString();
192 int l = logFileSkl.length();
193 if (logFileSkl.isEmpty()) {
194 _logFile = 0;
195 }
196 else {
197 if (l && logFileSkl[l-1] != QDir::separator() ) {
198 logFileSkl += QDir::separator();
199 }
200
201 logFileSkl = logFileSkl + ID9 + "${V3PROD}" + distStr + ".ppp";
202
203 _logFile = new bncoutf(logFileSkl, intr, sampl);
204 }
205
206 QString nmeaFileSkl = settings.value("PPP/nmeaPath").toString();
207 l = nmeaFileSkl.length();
208 if (nmeaFileSkl.isEmpty()) {
209 _nmeaFile = 0;
210 }
211 else {
212 if (l > 0 && nmeaFileSkl[l-1] != QDir::separator() ) {
213 nmeaFileSkl += QDir::separator();
214 }
215 nmeaFileSkl = nmeaFileSkl + ID9 + "${V3PROD}" + distStr + ".nmea";
216
217 _nmeaFile = new bncoutf(nmeaFileSkl, intr, sampl);
218 }
219 QString snxtroFileSkl = settings.value("PPP/snxtroPath").toString();
220 l = snxtroFileSkl.length();
221 if (snxtroFileSkl.isEmpty()) {
222 _snxtroFile = 0;
223 }
224 else {
225 if (l > 0 && snxtroFileSkl[l-1] != QDir::separator() ) {
226 snxtroFileSkl += QDir::separator();
227 }
228 snxtroFileSkl = snxtroFileSkl + ID9 + '_' + "${V3PROD}" + distStr + ".TRO";
229 sampl = settings.value("PPP/snxtroSampl").toString().split("sec").first().toInt();
230 intr = settings.value("PPP/snxtroIntr").toString();
231 _snxtroFile = new bncSinexTro(_opt, snxtroFileSkl, intr, sampl);
232 }
233}
234
235// Destructor
236////////////////////////////////////////////////////////////////////////////
237t_pppRun::~t_pppRun() {
238 delete _logFile;
239 delete _nmeaFile;
240 delete _snxtroFile;
241 while (!_epoData.empty()) {
242 delete _epoData.front();
243 _epoData.pop_front();
244 }
245}
246
247//
248////////////////////////////////////////////////////////////////////////////
249void t_pppRun::slotNewGPSEph(t_ephGPS eph) {
250 QMutexLocker locker(&_mutex);
251 _pppClient->putEphemeris(&eph);
252}
253
254//
255////////////////////////////////////////////////////////////////////////////
256void t_pppRun::slotNewGlonassEph(t_ephGlo eph) {
257 QMutexLocker locker(&_mutex);
258 _pppClient->putEphemeris(&eph);
259}
260
261//
262////////////////////////////////////////////////////////////////////////////
263void t_pppRun::slotNewGalileoEph(t_ephGal eph) {
264 QMutexLocker locker(&_mutex);
265 _pppClient->putEphemeris(&eph);
266}
267
268//
269////////////////////////////////////////////////////////////////////////////
270void t_pppRun::slotNewBDSEph(t_ephBDS eph) {
271 QMutexLocker locker(&_mutex);
272 _pppClient->putEphemeris(&eph);
273}
274
275//
276////////////////////////////////////////////////////////////////////////////
277void t_pppRun::slotNewObs(QByteArray staID, QList<t_satObs> obsList) {
278 QMutexLocker locker(&_mutex);
279
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
291 if (string(staID.data()) != _opt->_roverName) {
292 return;
293 }
294/*
295 int currentWeek = 0;
296 double currentSec = 0.0;
297 currentGPSWeeks(currentWeek, currentSec);
298 bncTime currentTime(currentWeek, currentSec);
299*/
300 // Loop over all observations (possible different epochs)
301 // -----------------------------------------------------
302 QListIterator<t_satObs> it(obsList);
303 while (it.hasNext()) {
304 const t_satObs& oldObs = it.next();
305 t_satObs* newObs = new t_satObs(oldObs);
306
307 /* Check regarding current time
308 // ----------------------------
309 if (OPT->_realTime && BNC_CORE->mode() != t_bncCore::batchPostProcessing ) {
310 if ((newObs->_time >= currentTime) || // future time stamp
311 (currentTime - newObs->_time) > 60.0) { // very old data sets
312 delete newObs;
313 continue;
314 }
315 }
316 */
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
335 // Put data into the epoch
336 // -----------------------
337 if (epoch != 0) {
338 epoch->_satObs.push_back(newObs);
339 }
340 else {
341 delete newObs;
342 }
343 }
344
345 // Make sure the buffer does not grow beyond any limit
346 // ---------------------------------------------------
347 const unsigned MAX_EPODATA_SIZE = 120;
348 if (_epoData.size() > MAX_EPODATA_SIZE) {
349 delete _epoData.front();
350 _epoData.pop_front();
351 }
352
353 // Process the oldest epochs
354 // ------------------------
355 while (_epoData.size()) {
356
357 const vector<t_satObs*>& satObs = _epoData.front()->_satObs;
358
359 // No corrections yet, skip the epoch
360 // ----------------------------------
361 if (_opt->_corrWaitTime && !_lastClkCorrTime.valid()) {
362 return;
363 }
364
365 // Process the front epoch
366 // -----------------------
367 if (_opt->_corrWaitTime == 0 ||
368 (_epoData.front()->_time - _lastClkCorrTime) < _opt->_corrWaitTime) {
369
370 if (_opt->_corrWaitTime != 0 &&
371 (fabs(_epoData.front()->_time - _lastClkCorrTime) > 60.0)) {
372 delete _epoData.front();
373 _epoData.pop_front();
374 continue;
375 }
376
377 t_output output;
378 _pppClient->processEpoch(satObs, &output);
379
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 }
390
391 delete _epoData.front();
392 _epoData.pop_front();
393
394 ostringstream log;
395 if (output._error) {
396 log << output._log;
397 }
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;
409 if (output._fixRatio > 0.0) {
410 log << " fix " << int(100*output._fixRatio) << " %";
411 }
412 else {
413 log << " flt ";
414 }
415
416 }
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 }
430 emit newNMEAstr(staID, rmcStr.toLatin1());
431 emit newNMEAstr(staID, ggaStr.toLatin1());
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);
438 }
439 else {
440 return;
441 }
442 }
443}
444
445//
446////////////////////////////////////////////////////////////////////////////
447void t_pppRun::slotNewTec(t_vTec vTec) {
448 if (vTec._layers.size() == 0) {
449 return;
450 }
451
452 if (_opt->_realTime) {
453 if (_opt->_ionoMount.empty() && _opt->_corrMount.empty()) {
454 return;
455 }
456 if (!_opt->_ionoMount.empty()) {
457 if (_opt->_ionoMount != vTec._staID) {
458 return;
459 }
460 }
461 else if (!_opt->_corrMount.empty()) {
462 if (_opt->_corrMount != vTec._staID) {
463 return;
464 }
465 }
466 }
467 _pppClient->putTec(&vTec);
468}
469
470//
471////////////////////////////////////////////////////////////////////////////
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////////////////////////////////////////////////////////////////////////////
487void t_pppRun::slotNewOrbCorrections(QList<t_orbCorr> orbCorr) {
488 if (orbCorr.size() == 0) {
489 return;
490 }
491
492 if (_opt->_realTime) {
493 if (_opt->_corrMount.empty() || _opt->_corrMount != orbCorr[0]._staID) {
494 return;
495 }
496 }
497 vector<t_orbCorr*> corrections;
498 for (int ii = 0; ii < orbCorr.size(); ii++) {
499 corrections.push_back(new t_orbCorr(orbCorr[ii]));
500 }
501
502 _pppClient->putOrbCorrections(corrections);
503
504 for (unsigned ii = 0; ii < corrections.size(); ii++) {
505 delete corrections[ii];
506 }
507}
508
509//
510////////////////////////////////////////////////////////////////////////////
511void t_pppRun::slotNewClkCorrections(QList<t_clkCorr> clkCorr) {
512 if (clkCorr.size() == 0) {
513 return;
514 }
515
516 if (_opt->_realTime) {
517 if (_opt->_corrMount.empty() || _opt->_corrMount != clkCorr[0]._staID) {
518 return;
519 }
520 }
521 vector<t_clkCorr*> corrections;
522 for (int ii = 0; ii < clkCorr.size(); ii++) {
523 corrections.push_back(new t_clkCorr(clkCorr[ii]));
524 _lastClkCorrTime = clkCorr[ii]._time;
525 }
526 _pppClient->putClkCorrections(corrections);
527
528 for (unsigned ii = 0; ii < corrections.size(); ii++) {
529 delete corrections[ii];
530 }
531}
532
533//
534////////////////////////////////////////////////////////////////////////////
535void t_pppRun::slotNewCodeBiases(QList<t_satCodeBias> codeBiases) {
536 if (codeBiases.size() == 0) {
537 return;
538 }
539
540 if (_opt->_realTime) {
541 if (_opt->_corrMount.empty() && _opt->_biasMount.empty()) {
542 return;
543 }
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 }
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
560 _pppClient->putCodeBiases(biases);
561
562 for (unsigned ii = 0; ii < biases.size(); ii++) {
563 delete biases[ii];
564 }
565}
566
567//
568////////////////////////////////////////////////////////////////////////////
569void t_pppRun::slotNewPhaseBiases(QList<t_satPhaseBias> phaseBiases) {
570 if (phaseBiases.size() == 0) {
571 return;
572 }
573
574 if (_opt->_realTime) {
575 if (_opt->_corrMount.empty() && _opt->_biasMount.empty()) {
576 return;
577 }
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 }
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////////////////////////////////////////////////////////////////////////////
603void t_pppRun::processFiles() {
604
605 try {
606 _rnxObsFile = new t_rnxObsFile(QString(_opt->_rinexObs.c_str()), t_rnxObsFile::input);
607 }
608 catch (...) {
609 delete _rnxObsFile; _rnxObsFile = 0;
610 emit finishedRnxPPP();
611 return;
612 }
613
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 }
622
623 if (!_opt->_corrFile.empty()) {
624 _corrFile = new t_corrFile(QString(_opt->_corrFile.c_str()));
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>)));
627 connect(_corrFile, SIGNAL(newMetaData(t_metaData)), this, SLOT(slotNewMetaData(t_metaData)));
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 }
632 if (_opt->_ionoFile.empty()) {
633 connect(_corrFile, SIGNAL(newTec(t_vTec)), this, SLOT(slotNewTec(t_vTec)));
634 }
635 }
636
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
643 if (!_opt->_ionoFile.empty()) {
644 _ionoFile = new t_corrFile(QString(_opt->_corrFile.c_str()));
645 connect(_ionoFile, SIGNAL(newTec(t_vTec)), this, SLOT(slotNewTec(t_vTec)));
646 }
647
648 // Read/Process Observations
649 // -------------------------
650 int nEpo = 0;
651 const t_rnxObsFile::t_rnxEpo* epo = 0;
652 while ( !_stopFlag && (epo = _rnxObsFile->nextEpoch()) != 0 ) {
653 ++nEpo;
654
655 if (_speed < 100) {
656 double sleepTime = 2.0 / _speed;
657 t_pppThread::msleep(int(sleepTime*1.e3));
658 }
659
660 // Get Corrections
661 // ---------------
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 }
679 }
680 }
681
682 // Get Ephemerides
683 // ----------------
684 t_eph* eph = 0;
685 const QMap<QString, unsigned int>* corrIODs = _corrFile ? &_corrFile->corrIODs() : 0;
686 while ( (eph = _rnxNavFile->getNextEph(epo->tt, corrIODs)) != 0 ) {
687 _pppClient->putEphemeris(eph);
688 delete eph; eph = 0;
689 }
690
691 // Create list of observations and start epoch processing
692 // ------------------------------------------------------
693 QList<t_satObs> obsList;
694 for (unsigned iObs = 0; iObs < epo->rnxSat.size(); iObs++) {
695 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iObs];
696
697 t_satObs obs;
698 t_rnxObsFile::setObsFromRnx(_rnxObsFile, epo, rnxSat, obs);
699 obsList << obs;
700 }
701 slotNewObs(QByteArray(_opt->_roverName.c_str()), obsList);
702
703
704 if (nEpo % 10 == 0) {
705 emit progressRnxPPP(nEpo);
706 }
707
708 QCoreApplication::processEvents();
709 }
710
711 emit finishedRnxPPP();
712
713 if (BNC_CORE->mode() != t_bncCore::interactive) {
714 qApp->exit(6);
715 }
716 else {
717 BNC_CORE->stopPPP();
718 }
719}
720
721//
722////////////////////////////////////////////////////////////////////////////
723void t_pppRun::slotSetSpeed(int speed) {
724 QMutexLocker locker(&_mutex);
725 _speed = speed;
726}
727
728//
729////////////////////////////////////////////////////////////////////////////
730void t_pppRun::slotSetStopFlag() {
731 QMutexLocker locker(&_mutex);
732 _stopFlag = true;
733}
734
735//
736////////////////////////////////////////////////////////////////////////////
737QString t_pppRun::nmeaString(char strType, const t_output& output) {
738
739 double ell[3];
740 xyz2ell(output._xyzRover, ell);
741 double phiDeg = ell[0] * 180 / M_PI;
742 double lamDeg = ell[1] * 180 / M_PI;
743
744 unsigned year, month, day;
745 output._epoTime.civil_date(year, month, day);
746 double gps_utc = gnumleap(year, month, day);
747
748 char phiCh = 'N';
749 if (phiDeg < 0) {
750 phiDeg = -phiDeg;
751 phiCh = 'S';
752 }
753 char lamCh = 'E';
754 if (lamDeg < 0) {
755 lamDeg = -lamDeg;
756 lamCh = 'W';
757 }
758
759 ostringstream out;
760 out.setf(ios::fixed);
761
762 if (strType == 'R') {
763 string datestr = (output._epoTime - gps_utc).datestr(0); // yyyymmdd
764 out << "GPRMC,"
765 << (output._epoTime - gps_utc).timestr(3,0) << ",A,"
766 << setw(2) << setfill('0') << int(phiDeg)
767 << setw(7) << setprecision(4) << setfill('0') << fmod(60*phiDeg,60) << ',' << phiCh << ','
768 << setw(3) << setfill('0') << int(lamDeg)
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] << ",,";
771 }
772 else if (strType == 'G') {
773 out << "GPGGA,"
774 << (output._epoTime - gps_utc).timestr(2,0) << ','
775 << setw(2) << setfill('0') << int(phiDeg)
776 << setw(10) << setprecision(7) << setfill('0')
777 << fmod(60*phiDeg,60) << ',' << phiCh << ','
778 << setw(3) << setfill('0') << int(lamDeg)
779 << setw(10) << setprecision(7) << setfill('0')
780 << fmod(60*lamDeg,60) << ',' << lamCh
781 << ",1," << setw(2) << setfill('0') << output._numSat << ','
782 << setw(3) << setprecision(1) << output._hDop << ','
783 << setprecision(3) << ell[2] << ",M,0.0,M,,";
784 }
785 else {
786 return "";
787 }
788
789 QString nmStr(out.str().c_str());
790 unsigned char XOR = 0;
791 for (int ii = 0; ii < nmStr.length(); ii++) {
792 XOR ^= (unsigned char) nmStr[ii].toLatin1();
793 }
794
795 return '$' + nmStr + QString("*%1").arg(XOR, 2, 16, QLatin1Char('0')) + "\n";
796}
797
798//
799////////////////////////////////////////////////////////////////////////////
800void t_pppRun::slotProviderIDChanged(QString mountPoint) {
801 QMutexLocker locker(&_mutex);
802
803 if (mountPoint.toStdString() !=_opt->_corrMount) {
804 return;
805 }
806
807 QString msg = "pppRun " + QString(_opt->_roverName.c_str()) + ": SSR Provider or Service changed: " + mountPoint;
808 emit newMessage(msg.toLatin1(), true);
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.