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

Last change on this file since 5941 was 5941, checked in by mervart, 10 years ago
File size: 12.7 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 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 emit newMessage(QByteArray(output._log.c_str()), true);
233 }
234}
235
236//
237////////////////////////////////////////////////////////////////////////////
238void t_pppRun::slotNewCorrections(QStringList corrList) {
239 QMutexLocker locker(&_mutex);
240
241 // Check the Mountpoint (source of corrections)
242 // --------------------------------------------
243 if (_opt->_realTime) {
244 if (_opt->_corrMount.empty()) {
245 return;
246 }
247 QMutableListIterator<QString> itm(corrList);
248 while (itm.hasNext()) {
249 QStringList hlp = itm.next().split(" ");
250 if (hlp.size() > 0) {
251 QString mountpoint = hlp[hlp.size()-1];
252 if (mountpoint != QString(_opt->_corrMount.c_str())) {
253 itm.remove();
254 }
255 }
256 }
257 }
258
259 if (corrList.size() == 0) {
260 return;
261 }
262
263 vector<t_orbCorr*> orbCorr;
264 vector<t_clkCorr*> clkCorr;
265 vector<t_satBias*> satBias;
266
267 QListIterator<QString> it(corrList);
268 while (it.hasNext()) {
269 QString line = it.next();
270
271 QTextStream in(&line);
272 int messageType;
273 int updateInterval;
274 int GPSweek;
275 double GPSweeks;
276 QString prn;
277 in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
278
279 if ( t_corr::relevantMessageType(messageType) ) {
280 t_corr corr;
281 corr.readLine(line);
282 if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
283 messageType == COTYPE_GPSORBIT || messageType == COTYPE_GLONASSORBIT ) {
284 t_orbCorr* cc = new t_orbCorr();
285 cc->_prn.set(corr.prn.toAscii().data());
286 cc->_iod = corr.iod;
287 cc->_time = corr.tRao;
288 cc->_system = 'R';
289 cc->_xr[0] = corr.rao[0];
290 cc->_xr[1] = corr.rao[1];
291 cc->_xr[2] = corr.rao[2];
292 cc->_dotXr[0] = corr.dotRao[0];
293 cc->_dotXr[0] = corr.dotRao[1];
294 cc->_dotXr[0] = corr.dotRao[2];
295 orbCorr.push_back(cc);
296
297 _lastOrbCorrIOD[cc->_prn.toInt()] = cc->_iod;
298 }
299 else if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
300 messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK ) {
301 t_clkCorr* cc = new t_clkCorr();
302 cc->_prn.set(corr.prn.toAscii().data());
303 cc->_iod = corr.iod;
304 cc->_time = corr.tClk;
305 cc->_dClk = corr.dClk;
306 cc->_dotDClk = corr.dotDClk;
307 cc->_dotDotDClk = corr.dotDotDClk;
308 cc->_clkPartial = 0.0;
309 if (messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK) {
310 int lastIOD = _lastOrbCorrIOD[cc->_prn.toInt()];
311 if (lastIOD != -1) {
312 cc->_iod = lastIOD;
313 }
314 else {
315 delete cc;
316 cc = 0;
317 }
318 }
319 if (cc) {
320 clkCorr.push_back(cc);
321 if (_lastClkCorrTime.undef() || cc->_time > _lastClkCorrTime) {
322 _lastClkCorrTime = cc->_time;
323 }
324 }
325 }
326 }
327 else if ( messageType == BTYPE_GPS || messageType == BTYPE_GLONASS ) {
328 t_bias bias;
329 bias.readLine(line);
330 }
331 }
332
333 _pppClient->putOrbCorrections(orbCorr);
334 _pppClient->putClkCorrections(clkCorr);
335 _pppClient->putBiases(satBias);
336
337 for (unsigned ii = 0; ii < orbCorr.size(); ii++) {
338 delete orbCorr[ii];
339 }
340 for (unsigned ii = 0; ii < clkCorr.size(); ii++) {
341 delete clkCorr[ii];
342 }
343 for (unsigned ii = 0; ii < satBias.size(); ii++) {
344 delete satBias[ii];
345 }
346}
347
348
349//
350////////////////////////////////////////////////////////////////////////////
351void t_pppRun::processFiles() {
352
353 try {
354 _rnxObsFile = new t_rnxObsFile(QString(_opt->_rinexObs.c_str()), t_rnxObsFile::input);
355 }
356 catch (...) {
357 delete _rnxObsFile; _rnxObsFile = 0;
358 emit finishedRnxPPP();
359 return;
360 }
361
362 _rnxNavFile = new t_rnxNavFile(QString(_opt->_rinexNav.c_str()), t_rnxNavFile::input);
363
364 if (!_opt->_corrFile.empty()) {
365 _corrFile = new t_corrFile(QString(_opt->_corrFile.c_str()));
366 connect(_corrFile, SIGNAL(newCorrections(QStringList)),
367 this, SLOT(slotNewCorrections(QStringList)));
368 }
369
370 // Read/Process Observations
371 // -------------------------
372 int nEpo = 0;
373 const t_rnxObsFile::t_rnxEpo* epo = 0;
374 while ( (epo = _rnxObsFile->nextEpoch()) != 0 ) {
375 ++nEpo;
376
377 if (_maxSpeed != 0) {
378 QMutexLocker locker(&_mutex);
379 if (_speed < _maxSpeed) {
380 double sleepTime = 0.02 * _maxSpeed / _speed;
381 t_pppThread::msleep(sleepTime*1.e3);
382 }
383 }
384
385 // Get Corrections
386 // ---------------
387 if (_corrFile) {
388 _corrFile->syncRead(epo->tt);
389 }
390
391 // Get Ephemerides
392 // ----------------
393 t_eph* eph = 0;
394 const QMap<QString, int>* corrIODs = _corrFile ? &_corrFile->corrIODs() : 0;
395 while ( (eph = _rnxNavFile->getNextEph(epo->tt, corrIODs)) != 0 ) {
396 _pppClient->putEphemeris(eph);
397 delete eph; eph = 0;
398 }
399
400 // Create list of observations and start epoch processing
401 // ------------------------------------------------------
402 QList<t_obs> obsList;
403 for (unsigned iObs = 0; iObs < epo->rnxSat.size(); iObs++) {
404 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iObs];
405
406 t_obs obs;
407 t_rnxObsFile::setObsFromRnx(_rnxObsFile, epo, rnxSat, obs);
408 obsList << obs;
409 }
410 slotNewObs(QByteArray(_opt->_roverName.c_str()), obsList);
411
412
413 if (nEpo % 10 == 0) {
414 emit progressRnxPPP(nEpo);
415 }
416 }
417
418 emit finishedRnxPPP();
419
420 if (BNC_CORE->mode() != t_bncCore::interactive) {
421 qApp->exit(0);
422 }
423}
424
425//
426////////////////////////////////////////////////////////////////////////////
427void t_pppRun::slotSetSpeed(int speed) {
428 QMutexLocker locker(&_mutex);
429 _speed = speed;
430}
Note: See TracBrowser for help on using the repository browser.