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

Last change on this file since 11179 was 11179, checked in by stuerze, 7 days ago

structuered logging is added and bug is fixed in SP3 file writing

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