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

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