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

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