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

Last change on this file since 5973 was 5973, checked in by mervart, 11 years ago
File size: 13.5 KB
RevLine 
[5860]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 *
[5883]30 * Class: t_pppRun
[5860]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
[5883]48#include "pppRun.h"
[5891]49#include "pppThread.h"
[5860]50#include "bnccore.h"
51#include "bncephuser.h"
[5953]52#include "bncsettings.h"
[5883]53#include "rinex/rnxobsfile.h"
54#include "rinex/rnxnavfile.h"
55#include "rinex/corrfile.h"
[5860]56
57using namespace BNC_PPP;
58using namespace std;
59
60// Constructor
61////////////////////////////////////////////////////////////////////////////
[5883]62t_pppRun::t_pppRun(const t_pppOptions* opt) {
63
[5973]64 cout << "t_pppRun" << endl;
65
[5860]66 _opt = opt;
[5883]67
[5860]68 connect(this, SIGNAL(newMessage(QByteArray,bool)),
69 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
[5883]70
[5954]71 connect(this, SIGNAL(newPosition(QByteArray, bncTime, QVector<double>)),
72 BNC_CORE, SIGNAL(newPosition(QByteArray, bncTime, QVector<double>)));
[5949]73
[5883]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
[5860]81 if (_opt->_realTime) {
[5945]82 Qt::ConnectionType conType = Qt::AutoConnection;
83 if (BNC_CORE->mode() == t_bncCore::batchPostProcessing) {
84 conType = Qt::BlockingQueuedConnection;
85 }
86
[5860]87 connect(BNC_CORE->caster(), SIGNAL(newObs(QByteArray, QList<t_obs>)),
[5945]88 this, SLOT(slotNewObs(QByteArray, QList<t_obs>)),conType);
[5860]89
90 connect(BNC_CORE, SIGNAL(newEphGPS(gpsephemeris)),
[5945]91 this, SLOT(slotNewEphGPS(gpsephemeris)),conType);
[5860]92
93 connect(BNC_CORE, SIGNAL(newEphGlonass(glonassephemeris)),
[5945]94 this, SLOT(slotNewEphGlonass(glonassephemeris)),conType);
[5860]95
96 connect(BNC_CORE, SIGNAL(newEphGalileo(galileoephemeris)),
[5945]97 this, SLOT(slotNewEphGalileo(galileoephemeris)),conType);
[5860]98
99 connect(BNC_CORE, SIGNAL(newCorrections(QStringList)),
[5945]100 this, SLOT(slotNewCorrections(QStringList)),conType);
[5860]101 }
102 else {
[5953]103 bncSettings settings;
[5889]104 _rnxObsFile = 0;
105 _rnxNavFile = 0;
106 _corrFile = 0;
[5953]107 _speed = settings.value("PPP/mapSpeedSlider").toInt();
[5941]108 connect(this, SIGNAL(progressRnxPPP(int)), BNC_CORE, SIGNAL(progressRnxPPP(int)));
109 connect(this, SIGNAL(finishedRnxPPP()), BNC_CORE, SIGNAL(finishedRnxPPP()));
[5950]110 connect(BNC_CORE, SIGNAL(mapSpeedSliderChanged(int)),
111 this, SLOT(slotSetSpeed(int)));
[5973]112 connect(BNC_CORE, SIGNAL(stopRinexPPP()), this, SLOT(slotSetStopFlag()));
[5860]113 }
[5973]114
115 _stopFlag = false;
[5860]116}
117
118// Destructor
119////////////////////////////////////////////////////////////////////////////
[5883]120t_pppRun::~t_pppRun() {
[5973]121 cout << "~t_pppRun" << endl;
[5860]122}
123
124//
125////////////////////////////////////////////////////////////////////////////
[5883]126void t_pppRun::slotNewEphGPS(gpsephemeris gpseph) {
[5860]127 QMutexLocker locker(&_mutex);
128 t_ephGPS eph;
129 eph.set(&gpseph);
130 _pppClient->putEphemeris(&eph);
131}
132
133//
134////////////////////////////////////////////////////////////////////////////
[5883]135void t_pppRun::slotNewEphGlonass(glonassephemeris gloeph) {
[5860]136 QMutexLocker locker(&_mutex);
137 t_ephGlo eph;
138 eph.set(&gloeph);
139 _pppClient->putEphemeris(&eph);
140}
141
142//
143////////////////////////////////////////////////////////////////////////////
[5883]144void t_pppRun::slotNewEphGalileo(galileoephemeris galeph) {
[5860]145 QMutexLocker locker(&_mutex);
146 t_ephGal eph;
147 eph.set(&galeph);
148 _pppClient->putEphemeris(&eph);
149}
150
151//
152////////////////////////////////////////////////////////////////////////////
[5883]153void t_pppRun::slotNewObs(QByteArray staID, QList<t_obs> obsList) {
[5860]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++) {
[5936]194 string hlp = oldObs.rnxStr(iEntry).toAscii().data();
[5933]195 if (hlp.length() >= 2 && oldObs._measdata[iEntry] != 0.0) {
[5860]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 // ------------------------
[5923]225 while (_epoData.size() &&
226 (!_opt->_realTime || _epoData.front()->_time < _lastClkCorrTime + 10.0)) {
[5860]227
228 const vector<t_satObs*>& satObs = _epoData.front()->_satObs;
229
230 t_output output;
231 _pppClient->processEpoch(satObs, &output);
232
[5953]233 if (!output._error) {
[5879]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];
[5954]241 emit newPosition(staID, output._epoTime, xx);
[5873]242 }
243
[5860]244 delete _epoData.front(); _epoData.pop_front();
245
[5948]246 emit newMessage(QByteArray(output._log.c_str()), true);
[5860]247 }
248}
249
250//
251////////////////////////////////////////////////////////////////////////////
[5883]252void t_pppRun::slotNewCorrections(QStringList corrList) {
[5860]253 QMutexLocker locker(&_mutex);
254
255 // Check the Mountpoint (source of corrections)
256 // --------------------------------------------
[5937]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 }
[5860]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}
[5883]361
362
363//
364////////////////////////////////////////////////////////////////////////////
365void t_pppRun::processFiles() {
366
367 try {
[5889]368 _rnxObsFile = new t_rnxObsFile(QString(_opt->_rinexObs.c_str()), t_rnxObsFile::input);
[5883]369 }
370 catch (...) {
371 delete _rnxObsFile; _rnxObsFile = 0;
[5940]372 emit finishedRnxPPP();
[5883]373 return;
374 }
375
[5889]376 _rnxNavFile = new t_rnxNavFile(QString(_opt->_rinexNav.c_str()), t_rnxNavFile::input);
[5883]377
[5889]378 if (!_opt->_corrFile.empty()) {
379 _corrFile = new t_corrFile(QString(_opt->_corrFile.c_str()));
[5883]380 connect(_corrFile, SIGNAL(newCorrections(QStringList)),
[5889]381 this, SLOT(slotNewCorrections(QStringList)));
[5883]382 }
383
384 // Read/Process Observations
385 // -------------------------
386 int nEpo = 0;
387 const t_rnxObsFile::t_rnxEpo* epo = 0;
[5973]388 while ( !_stopFlag && (epo = _rnxObsFile->nextEpoch()) != 0 ) {
[5883]389 ++nEpo;
390
[5951]391 if (_speed < 100) {
392 double sleepTime = 2.0 / _speed;
393 t_pppThread::msleep(sleepTime*1.e3);
[5883]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 ) {
[5889]407 _pppClient->putEphemeris(eph);
408 delete eph; eph = 0;
[5883]409 }
410
[5890]411 // Create list of observations and start epoch processing
412 // ------------------------------------------------------
413 QList<t_obs> obsList;
[5883]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);
[5890]419 obsList << obs;
420 }
421 slotNewObs(QByteArray(_opt->_roverName.c_str()), obsList);
[5883]422
[5890]423
[5883]424 if (nEpo % 10 == 0) {
[5940]425 emit progressRnxPPP(nEpo);
[5883]426 }
[5950]427
428 QCoreApplication::processEvents();
[5883]429 }
430
[5940]431 emit finishedRnxPPP();
[5927]432
[5883]433 if (BNC_CORE->mode() != t_bncCore::interactive) {
434 qApp->exit(0);
435 }
[5944]436 else {
437 BNC_CORE->stopPPP();
438 }
[5883]439}
440
441//
442////////////////////////////////////////////////////////////////////////////
443void t_pppRun::slotSetSpeed(int speed) {
444 QMutexLocker locker(&_mutex);
445 _speed = speed;
446}
[5973]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.