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

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