source: ntrip/trunk/BNC/src/PPP/pppRun.cpp@ 5988

Last change on this file since 5988 was 5988, checked in by mervart, 10 years ago
File size: 14.9 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 "rinex/rnxobsfile.h"
56#include "rinex/rnxnavfile.h"
57#include "rinex/corrfile.h"
58
59using namespace BNC_PPP;
60using namespace std;
61
62// Constructor
63////////////////////////////////////////////////////////////////////////////
64t_pppRun::t_pppRun(const t_pppOptions* opt) {
65
66 _opt = opt;
67
68 connect(this, SIGNAL(newMessage(QByteArray,bool)),
69 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
70
71 connect(this, SIGNAL(newPosition(QByteArray, bncTime, QVector<double>)),
72 BNC_CORE, SIGNAL(newPosition(QByteArray, bncTime, QVector<double>)));
73
74 for (unsigned iPrn = 0; iPrn <= t_prn::MAXPRN; iPrn++) {
75 _lastOrbCorrIOD[iPrn] = -1;
76 _lastClkCorrValue[iPrn] = 0.0;
77 }
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_obs>)),
90 this, SLOT(slotNewObs(QByteArray, QList<t_obs>)),conType);
91
92 connect(BNC_CORE, SIGNAL(newEphGPS(gpsephemeris)),
93 this, SLOT(slotNewEphGPS(gpsephemeris)),conType);
94
95 connect(BNC_CORE, SIGNAL(newEphGlonass(glonassephemeris)),
96 this, SLOT(slotNewEphGlonass(glonassephemeris)),conType);
97
98 connect(BNC_CORE, SIGNAL(newEphGalileo(galileoephemeris)),
99 this, SLOT(slotNewEphGalileo(galileoephemeris)),conType);
100
101 connect(BNC_CORE, SIGNAL(newCorrections(QStringList)),
102 this, SLOT(slotNewCorrections(QStringList)),conType);
103 }
104 else {
105 _rnxObsFile = 0;
106 _rnxNavFile = 0;
107 _corrFile = 0;
108 _speed = settings.value("PPP/mapSpeedSlider").toInt();
109 connect(this, SIGNAL(progressRnxPPP(int)), BNC_CORE, SIGNAL(progressRnxPPP(int)));
110 connect(this, SIGNAL(finishedRnxPPP()), BNC_CORE, SIGNAL(finishedRnxPPP()));
111 connect(BNC_CORE, SIGNAL(mapSpeedSliderChanged(int)),
112 this, SLOT(slotSetSpeed(int)));
113 connect(BNC_CORE, SIGNAL(stopRinexPPP()), this, SLOT(slotSetStopFlag()));
114 }
115
116 _stopFlag = false;
117
118 QString roverName(_opt->_roverName.c_str());
119
120 QString logFileSkl = settings.value("PPP/logFile").toString();
121 if (logFileSkl.isEmpty()) {
122 _logFile = 0;
123 }
124 else {
125 if (logFileSkl.indexOf("${STATION}") == -1) {
126 logFileSkl = roverName + "_" + logFileSkl;
127 }
128 else {
129 logFileSkl.replace("${STATION}", roverName);
130 }
131 _logFile = new bncoutf(logFileSkl, "1 day", 0);
132 }
133
134 QString nmeaFileSkl = settings.value("PPP/nmeaFile").toString();
135 if (nmeaFileSkl.isEmpty()) {
136 _nmeaFile = 0;
137 }
138 else {
139 if (nmeaFileSkl.indexOf("${STATION}") == -1) {
140 nmeaFileSkl = roverName + "_" + nmeaFileSkl;
141 }
142 else {
143 nmeaFileSkl.replace("${STATION}", roverName);
144 }
145 _nmeaFile = new bncoutf(nmeaFileSkl, "1 day", 0);
146 }
147}
148
149// Destructor
150////////////////////////////////////////////////////////////////////////////
151t_pppRun::~t_pppRun() {
152 delete _logFile;
153 delete _nmeaFile;
154}
155
156//
157////////////////////////////////////////////////////////////////////////////
158void t_pppRun::slotNewEphGPS(gpsephemeris gpseph) {
159 QMutexLocker locker(&_mutex);
160 t_ephGPS eph;
161 eph.set(&gpseph);
162 _pppClient->putEphemeris(&eph);
163}
164
165//
166////////////////////////////////////////////////////////////////////////////
167void t_pppRun::slotNewEphGlonass(glonassephemeris gloeph) {
168 QMutexLocker locker(&_mutex);
169 t_ephGlo eph;
170 eph.set(&gloeph);
171 _pppClient->putEphemeris(&eph);
172}
173
174//
175////////////////////////////////////////////////////////////////////////////
176void t_pppRun::slotNewEphGalileo(galileoephemeris galeph) {
177 QMutexLocker locker(&_mutex);
178 t_ephGal eph;
179 eph.set(&galeph);
180 _pppClient->putEphemeris(&eph);
181}
182
183//
184////////////////////////////////////////////////////////////////////////////
185void t_pppRun::slotNewObs(QByteArray staID, QList<t_obs> obsList) {
186 QMutexLocker locker(&_mutex);
187
188 if (string(staID.data()) != _opt->_roverName) {
189 return;
190 }
191
192 // Loop over all obsevations (possible different epochs)
193 // -----------------------------------------------------
194 QListIterator<t_obs> it(obsList);
195 while (it.hasNext()) {
196 const t_obs& oldObs = it.next();
197 t_satObs* newObs = new t_satObs;
198
199 newObs->_prn.set(oldObs.satSys, oldObs.satNum);
200 newObs->_time.set(oldObs.GPSWeek, oldObs.GPSWeeks);
201
202 // Find the corresponding data epoch or create a new one
203 // -----------------------------------------------------
204 t_epoData* epoch = 0;
205 deque<t_epoData*>::const_iterator it;
206 for (it = _epoData.begin(); it != _epoData.end(); it++) {
207 if (newObs->_time == (*it)->_time) {
208 epoch = *it;
209 break;
210 }
211 }
212 if (epoch == 0) {
213 if (_epoData.empty() || newObs->_time > _epoData.back()->_time) {
214 epoch = new t_epoData;
215 epoch->_time = newObs->_time;
216 _epoData.push_back(epoch);
217 }
218 }
219
220 // Fill the new observation and add it to the corresponding epoch
221 // --------------------------------------------------------------
222 if (epoch != 0) {
223 epoch->_satObs.push_back(newObs);
224 map<string, t_frqObs*> frqObsMap;
225 for (unsigned iEntry = 0; iEntry < GNSSENTRY_NUMBER; iEntry++) {
226 string hlp = oldObs.rnxStr(iEntry).toAscii().data();
227 if (hlp.length() >= 2 && oldObs._measdata[iEntry] != 0.0) {
228 char obsType = hlp[0];
229 string rnxType2ch = hlp.substr(1);
230 if (obsType == 'C' || obsType == 'L') {
231 t_frqObs* frqObs = 0;
232 if (frqObsMap.find(rnxType2ch) == frqObsMap.end()) {
233 frqObs = new t_frqObs();
234 frqObsMap[rnxType2ch] = frqObs;
235 frqObs->_rnxType2ch = rnxType2ch;
236 newObs->_obs.push_back(frqObs);
237 }
238 else {
239 frqObs = frqObsMap[rnxType2ch];
240 }
241 if (obsType == 'C') {
242 frqObs->_code = oldObs._measdata[iEntry];
243 frqObs->_codeValid = true;
244 }
245 else if (obsType == 'L') {
246 frqObs->_phase = oldObs._measdata[iEntry];
247 frqObs->_phaseValid = true;
248 }
249 }
250 }
251 }
252 }
253 }
254
255 // Process the oldest epochs
256 // ------------------------
257 while (_epoData.size() &&
258 (!_opt->_realTime || _epoData.front()->_time < _lastClkCorrTime + 10.0)) {
259
260 const vector<t_satObs*>& satObs = _epoData.front()->_satObs;
261
262 t_output output;
263 _pppClient->processEpoch(satObs, &output);
264
265 if (!output._error) {
266 QVector<double> xx(6);
267 xx.data()[0] = output._xyzRover[0];
268 xx.data()[1] = output._xyzRover[1];
269 xx.data()[2] = output._xyzRover[2];
270 xx.data()[3] = output._neu[0];
271 xx.data()[4] = output._neu[1];
272 xx.data()[5] = output._neu[2];
273 emit newPosition(staID, output._epoTime, xx);
274 }
275
276 delete _epoData.front(); _epoData.pop_front();
277
278 ostringstream log;
279 if (output._error) {
280 log << output._log;
281 }
282 else {
283 log.setf(ios::fixed);
284 log << string(output._epoTime) << ' ' << staID.data()
285 << " X = " << setprecision(4) << output._xyzRover[0]
286 << " Y = " << setprecision(4) << output._xyzRover[1]
287 << " Z = " << setprecision(4) << output._xyzRover[2]
288 << " NEU: " << setprecision(4) << output._neu[0]
289 << " " << setprecision(4) << output._neu[1]
290 << " " << setprecision(4) << output._neu[2];
291 }
292
293 if (_logFile && output._epoTime.valid()) {
294 _logFile->write(output._epoTime.gpsw(), output._epoTime.gpssec(),
295 QString(output._log.c_str()));
296 }
297
298 emit newMessage(QByteArray(log.str().c_str()), true);
299 }
300}
301
302//
303////////////////////////////////////////////////////////////////////////////
304void t_pppRun::slotNewCorrections(QStringList corrList) {
305 QMutexLocker locker(&_mutex);
306
307 // Check the Mountpoint (source of corrections)
308 // --------------------------------------------
309 if (_opt->_realTime) {
310 if (_opt->_corrMount.empty()) {
311 return;
312 }
313 QMutableListIterator<QString> itm(corrList);
314 while (itm.hasNext()) {
315 QStringList hlp = itm.next().split(" ");
316 if (hlp.size() > 0) {
317 QString mountpoint = hlp[hlp.size()-1];
318 if (mountpoint != QString(_opt->_corrMount.c_str())) {
319 itm.remove();
320 }
321 }
322 }
323 }
324
325 if (corrList.size() == 0) {
326 return;
327 }
328
329 vector<t_orbCorr*> orbCorr;
330 vector<t_clkCorr*> clkCorr;
331 vector<t_satBias*> satBias;
332
333 QListIterator<QString> it(corrList);
334 while (it.hasNext()) {
335 QString line = it.next();
336
337 QTextStream in(&line);
338 int messageType;
339 int updateInterval;
340 int GPSweek;
341 double GPSweeks;
342 QString prn;
343 in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
344
345 if ( t_corr::relevantMessageType(messageType) ) {
346 t_corr corr;
347 corr.readLine(line);
348 if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
349 messageType == COTYPE_GPSORBIT || messageType == COTYPE_GLONASSORBIT ) {
350 t_orbCorr* cc = new t_orbCorr();
351 cc->_prn.set(corr.prn.toAscii().data());
352 cc->_iod = corr.iod;
353 cc->_time = corr.tRao;
354 cc->_system = 'R';
355 cc->_xr[0] = corr.rao[0];
356 cc->_xr[1] = corr.rao[1];
357 cc->_xr[2] = corr.rao[2];
358 cc->_dotXr[0] = corr.dotRao[0];
359 cc->_dotXr[0] = corr.dotRao[1];
360 cc->_dotXr[0] = corr.dotRao[2];
361 orbCorr.push_back(cc);
362
363 _lastOrbCorrIOD[cc->_prn.toInt()] = cc->_iod;
364 }
365 else if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
366 messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK ) {
367 t_clkCorr* cc = new t_clkCorr();
368 cc->_prn.set(corr.prn.toAscii().data());
369 cc->_iod = corr.iod;
370 cc->_time = corr.tClk;
371 cc->_dClk = corr.dClk;
372 cc->_dotDClk = corr.dotDClk;
373 cc->_dotDotDClk = corr.dotDotDClk;
374 cc->_clkPartial = 0.0;
375 if (messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK) {
376 int lastIOD = _lastOrbCorrIOD[cc->_prn.toInt()];
377 if (lastIOD != -1) {
378 cc->_iod = lastIOD;
379 }
380 else {
381 delete cc;
382 cc = 0;
383 }
384 }
385 if (cc) {
386 clkCorr.push_back(cc);
387 if (_lastClkCorrTime.undef() || cc->_time > _lastClkCorrTime) {
388 _lastClkCorrTime = cc->_time;
389 }
390 }
391 }
392 }
393 else if ( messageType == BTYPE_GPS || messageType == BTYPE_GLONASS ) {
394 t_bias bias;
395 bias.readLine(line);
396 }
397 }
398
399 _pppClient->putOrbCorrections(orbCorr);
400 _pppClient->putClkCorrections(clkCorr);
401 _pppClient->putBiases(satBias);
402
403 for (unsigned ii = 0; ii < orbCorr.size(); ii++) {
404 delete orbCorr[ii];
405 }
406 for (unsigned ii = 0; ii < clkCorr.size(); ii++) {
407 delete clkCorr[ii];
408 }
409 for (unsigned ii = 0; ii < satBias.size(); ii++) {
410 delete satBias[ii];
411 }
412}
413
414
415//
416////////////////////////////////////////////////////////////////////////////
417void t_pppRun::processFiles() {
418
419 try {
420 _rnxObsFile = new t_rnxObsFile(QString(_opt->_rinexObs.c_str()), t_rnxObsFile::input);
421 }
422 catch (...) {
423 delete _rnxObsFile; _rnxObsFile = 0;
424 emit finishedRnxPPP();
425 return;
426 }
427
428 _rnxNavFile = new t_rnxNavFile(QString(_opt->_rinexNav.c_str()), t_rnxNavFile::input);
429
430 if (!_opt->_corrFile.empty()) {
431 _corrFile = new t_corrFile(QString(_opt->_corrFile.c_str()));
432 connect(_corrFile, SIGNAL(newCorrections(QStringList)),
433 this, SLOT(slotNewCorrections(QStringList)));
434 }
435
436 // Read/Process Observations
437 // -------------------------
438 int nEpo = 0;
439 const t_rnxObsFile::t_rnxEpo* epo = 0;
440 while ( !_stopFlag && (epo = _rnxObsFile->nextEpoch()) != 0 ) {
441 ++nEpo;
442
443 if (_speed < 100) {
444 double sleepTime = 2.0 / _speed;
445 t_pppThread::msleep(sleepTime*1.e3);
446 }
447
448 // Get Corrections
449 // ---------------
450 if (_corrFile) {
451 _corrFile->syncRead(epo->tt);
452 }
453
454 // Get Ephemerides
455 // ----------------
456 t_eph* eph = 0;
457 const QMap<QString, int>* corrIODs = _corrFile ? &_corrFile->corrIODs() : 0;
458 while ( (eph = _rnxNavFile->getNextEph(epo->tt, corrIODs)) != 0 ) {
459 _pppClient->putEphemeris(eph);
460 delete eph; eph = 0;
461 }
462
463 // Create list of observations and start epoch processing
464 // ------------------------------------------------------
465 QList<t_obs> obsList;
466 for (unsigned iObs = 0; iObs < epo->rnxSat.size(); iObs++) {
467 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iObs];
468
469 t_obs obs;
470 t_rnxObsFile::setObsFromRnx(_rnxObsFile, epo, rnxSat, obs);
471 obsList << obs;
472 }
473 slotNewObs(QByteArray(_opt->_roverName.c_str()), obsList);
474
475
476 if (nEpo % 10 == 0) {
477 emit progressRnxPPP(nEpo);
478 }
479
480 QCoreApplication::processEvents();
481 }
482
483 emit finishedRnxPPP();
484
485 if (BNC_CORE->mode() != t_bncCore::interactive) {
486 qApp->exit(0);
487 }
488 else {
489 BNC_CORE->stopPPP();
490 }
491}
492
493//
494////////////////////////////////////////////////////////////////////////////
495void t_pppRun::slotSetSpeed(int speed) {
496 QMutexLocker locker(&_mutex);
497 _speed = speed;
498}
499
500//
501////////////////////////////////////////////////////////////////////////////
502void t_pppRun::slotSetStopFlag() {
503 QMutexLocker locker(&_mutex);
504 _stopFlag = true;
505}
Note: See TracBrowser for help on using the repository browser.