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

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