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

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