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

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