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

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