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

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