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

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