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

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