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

Last change on this file since 10793 was 10791, checked in by mervart, 3 weeks ago

BNC Multifrequency and PPPAR Client (initial version)

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