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

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