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 |
|
---|
56 | using namespace BNC_PPP;
|
---|
57 | using namespace std;
|
---|
58 |
|
---|
59 | // Constructor
|
---|
60 | ////////////////////////////////////////////////////////////////////////////
|
---|
61 | t_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 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | // Destructor
|
---|
104 | ////////////////////////////////////////////////////////////////////////////
|
---|
105 | t_pppRun::~t_pppRun() {
|
---|
106 | }
|
---|
107 |
|
---|
108 | //
|
---|
109 | ////////////////////////////////////////////////////////////////////////////
|
---|
110 | void t_pppRun::slotNewEphGPS(gpsephemeris gpseph) {
|
---|
111 | QMutexLocker locker(&_mutex);
|
---|
112 | t_ephGPS eph;
|
---|
113 | eph.set(&gpseph);
|
---|
114 | _pppClient->putEphemeris(&eph);
|
---|
115 | }
|
---|
116 |
|
---|
117 | //
|
---|
118 | ////////////////////////////////////////////////////////////////////////////
|
---|
119 | void t_pppRun::slotNewEphGlonass(glonassephemeris gloeph) {
|
---|
120 | QMutexLocker locker(&_mutex);
|
---|
121 | t_ephGlo eph;
|
---|
122 | eph.set(&gloeph);
|
---|
123 | _pppClient->putEphemeris(&eph);
|
---|
124 | }
|
---|
125 |
|
---|
126 | //
|
---|
127 | ////////////////////////////////////////////////////////////////////////////
|
---|
128 | void t_pppRun::slotNewEphGalileo(galileoephemeris galeph) {
|
---|
129 | QMutexLocker locker(&_mutex);
|
---|
130 | t_ephGal eph;
|
---|
131 | eph.set(&galeph);
|
---|
132 | _pppClient->putEphemeris(&eph);
|
---|
133 | }
|
---|
134 |
|
---|
135 | //
|
---|
136 | ////////////////////////////////////////////////////////////////////////////
|
---|
137 | void t_pppRun::slotNewObs(QByteArray staID, QList<t_obs> obsList) {
|
---|
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 |
|
---|
180 | if (hlp.length() == 2) {
|
---|
181 | if (hlp == "C1") hlp = "C1C";
|
---|
182 | else if (hlp == "P1") hlp = "C1P";
|
---|
183 | else if (hlp == "C2") hlp = "C2C";
|
---|
184 | else if (hlp == "P2") hlp = "C2P";
|
---|
185 | else if (hlp == "L1") hlp = "L1C";
|
---|
186 | else if (hlp == "L2") hlp = "L2C";
|
---|
187 | }
|
---|
188 |
|
---|
189 | if (hlp.length() == 3) {
|
---|
190 | char obsType = hlp[0];
|
---|
191 | string rnxType2ch = hlp.substr(1);
|
---|
192 | if (obsType == 'C' || obsType == 'L') {
|
---|
193 | t_frqObs* frqObs = 0;
|
---|
194 | if (frqObsMap.find(rnxType2ch) == frqObsMap.end()) {
|
---|
195 | frqObs = new t_frqObs();
|
---|
196 | frqObsMap[rnxType2ch] = frqObs;
|
---|
197 | frqObs->_rnxType2ch = rnxType2ch;
|
---|
198 | newObs->_obs.push_back(frqObs);
|
---|
199 | }
|
---|
200 | else {
|
---|
201 | frqObs = frqObsMap[rnxType2ch];
|
---|
202 | }
|
---|
203 | if (obsType == 'C') {
|
---|
204 | frqObs->_code = oldObs._measdata[iEntry];
|
---|
205 | frqObs->_codeValid = true;
|
---|
206 | }
|
---|
207 | else if (obsType == 'L') {
|
---|
208 | frqObs->_phase = oldObs._measdata[iEntry];
|
---|
209 | frqObs->_phaseValid = true;
|
---|
210 | }
|
---|
211 | }
|
---|
212 | }
|
---|
213 | }
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | // Process the oldest epochs
|
---|
218 | // ------------------------
|
---|
219 | while (_epoData.size() &&
|
---|
220 | (!_opt->_realTime || _epoData.front()->_time < _lastClkCorrTime + 10.0)) {
|
---|
221 |
|
---|
222 | const vector<t_satObs*>& satObs = _epoData.front()->_satObs;
|
---|
223 |
|
---|
224 | t_output output;
|
---|
225 | _pppClient->processEpoch(satObs, &output);
|
---|
226 |
|
---|
227 | if (!output._error && _opt->xyzAprRoverSet()) {
|
---|
228 | QVector<double> xx(6);
|
---|
229 | xx.data()[0] = output._xyzRover[0];
|
---|
230 | xx.data()[1] = output._xyzRover[1];
|
---|
231 | xx.data()[2] = output._xyzRover[2];
|
---|
232 | xx.data()[3] = output._neu[0];
|
---|
233 | xx.data()[4] = output._neu[1];
|
---|
234 | xx.data()[5] = output._neu[2];
|
---|
235 | emit newPosition(output._epoTime, xx);
|
---|
236 | }
|
---|
237 |
|
---|
238 | delete _epoData.front(); _epoData.pop_front();
|
---|
239 |
|
---|
240 | emit newMessage(QByteArray(output._log.c_str()), true);
|
---|
241 | }
|
---|
242 | }
|
---|
243 |
|
---|
244 | //
|
---|
245 | ////////////////////////////////////////////////////////////////////////////
|
---|
246 | void t_pppRun::slotNewCorrections(QStringList corrList) {
|
---|
247 | QMutexLocker locker(&_mutex);
|
---|
248 |
|
---|
249 | if (_opt->_corrMount.empty()) {
|
---|
250 | return;
|
---|
251 | }
|
---|
252 |
|
---|
253 | // Check the Mountpoint (source of corrections)
|
---|
254 | // --------------------------------------------
|
---|
255 | QMutableListIterator<QString> itm(corrList);
|
---|
256 | while (itm.hasNext()) {
|
---|
257 | QStringList hlp = itm.next().split(" ");
|
---|
258 | if (hlp.size() > 0) {
|
---|
259 | QString mountpoint = hlp[hlp.size()-1];
|
---|
260 | if (mountpoint != QString(_opt->_corrMount.c_str())) {
|
---|
261 | itm.remove();
|
---|
262 | }
|
---|
263 | }
|
---|
264 | }
|
---|
265 |
|
---|
266 | if (corrList.size() == 0) {
|
---|
267 | return;
|
---|
268 | }
|
---|
269 |
|
---|
270 | vector<t_orbCorr*> orbCorr;
|
---|
271 | vector<t_clkCorr*> clkCorr;
|
---|
272 | vector<t_satBias*> satBias;
|
---|
273 |
|
---|
274 | QListIterator<QString> it(corrList);
|
---|
275 | while (it.hasNext()) {
|
---|
276 | QString line = it.next();
|
---|
277 |
|
---|
278 | QTextStream in(&line);
|
---|
279 | int messageType;
|
---|
280 | int updateInterval;
|
---|
281 | int GPSweek;
|
---|
282 | double GPSweeks;
|
---|
283 | QString prn;
|
---|
284 | in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
|
---|
285 |
|
---|
286 | if ( t_corr::relevantMessageType(messageType) ) {
|
---|
287 | t_corr corr;
|
---|
288 | corr.readLine(line);
|
---|
289 | if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
|
---|
290 | messageType == COTYPE_GPSORBIT || messageType == COTYPE_GLONASSORBIT ) {
|
---|
291 | t_orbCorr* cc = new t_orbCorr();
|
---|
292 | cc->_prn.set(corr.prn.toAscii().data());
|
---|
293 | cc->_iod = corr.iod;
|
---|
294 | cc->_time = corr.tRao;
|
---|
295 | cc->_system = 'R';
|
---|
296 | cc->_xr[0] = corr.rao[0];
|
---|
297 | cc->_xr[1] = corr.rao[1];
|
---|
298 | cc->_xr[2] = corr.rao[2];
|
---|
299 | cc->_dotXr[0] = corr.dotRao[0];
|
---|
300 | cc->_dotXr[0] = corr.dotRao[1];
|
---|
301 | cc->_dotXr[0] = corr.dotRao[2];
|
---|
302 | orbCorr.push_back(cc);
|
---|
303 |
|
---|
304 | _lastOrbCorrIOD[cc->_prn.toInt()] = cc->_iod;
|
---|
305 | }
|
---|
306 | else if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
|
---|
307 | messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK ) {
|
---|
308 | t_clkCorr* cc = new t_clkCorr();
|
---|
309 | cc->_prn.set(corr.prn.toAscii().data());
|
---|
310 | cc->_iod = corr.iod;
|
---|
311 | cc->_time = corr.tClk;
|
---|
312 | cc->_dClk = corr.dClk;
|
---|
313 | cc->_dotDClk = corr.dotDClk;
|
---|
314 | cc->_dotDotDClk = corr.dotDotDClk;
|
---|
315 | cc->_clkPartial = 0.0;
|
---|
316 | if (messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK) {
|
---|
317 | int lastIOD = _lastOrbCorrIOD[cc->_prn.toInt()];
|
---|
318 | if (lastIOD != -1) {
|
---|
319 | cc->_iod = lastIOD;
|
---|
320 | }
|
---|
321 | else {
|
---|
322 | delete cc;
|
---|
323 | cc = 0;
|
---|
324 | }
|
---|
325 | }
|
---|
326 | if (cc) {
|
---|
327 | clkCorr.push_back(cc);
|
---|
328 | if (_lastClkCorrTime.undef() || cc->_time > _lastClkCorrTime) {
|
---|
329 | _lastClkCorrTime = cc->_time;
|
---|
330 | }
|
---|
331 | }
|
---|
332 | }
|
---|
333 | }
|
---|
334 | else if ( messageType == BTYPE_GPS || messageType == BTYPE_GLONASS ) {
|
---|
335 | t_bias bias;
|
---|
336 | bias.readLine(line);
|
---|
337 | }
|
---|
338 | }
|
---|
339 |
|
---|
340 | _pppClient->putOrbCorrections(orbCorr);
|
---|
341 | _pppClient->putClkCorrections(clkCorr);
|
---|
342 | _pppClient->putBiases(satBias);
|
---|
343 |
|
---|
344 | for (unsigned ii = 0; ii < orbCorr.size(); ii++) {
|
---|
345 | delete orbCorr[ii];
|
---|
346 | }
|
---|
347 | for (unsigned ii = 0; ii < clkCorr.size(); ii++) {
|
---|
348 | delete clkCorr[ii];
|
---|
349 | }
|
---|
350 | for (unsigned ii = 0; ii < satBias.size(); ii++) {
|
---|
351 | delete satBias[ii];
|
---|
352 | }
|
---|
353 | }
|
---|
354 |
|
---|
355 |
|
---|
356 | //
|
---|
357 | ////////////////////////////////////////////////////////////////////////////
|
---|
358 | void t_pppRun::processFiles() {
|
---|
359 |
|
---|
360 | try {
|
---|
361 | _rnxObsFile = new t_rnxObsFile(QString(_opt->_rinexObs.c_str()), t_rnxObsFile::input);
|
---|
362 | }
|
---|
363 | catch (...) {
|
---|
364 | delete _rnxObsFile; _rnxObsFile = 0;
|
---|
365 | emit finished();
|
---|
366 | return;
|
---|
367 | }
|
---|
368 |
|
---|
369 | _rnxNavFile = new t_rnxNavFile(QString(_opt->_rinexNav.c_str()), t_rnxNavFile::input);
|
---|
370 |
|
---|
371 | if (!_opt->_corrFile.empty()) {
|
---|
372 | _corrFile = new t_corrFile(QString(_opt->_corrFile.c_str()));
|
---|
373 | connect(_corrFile, SIGNAL(newCorrections(QStringList)),
|
---|
374 | this, SLOT(slotNewCorrections(QStringList)));
|
---|
375 | }
|
---|
376 |
|
---|
377 | // Read/Process Observations
|
---|
378 | // -------------------------
|
---|
379 | int nEpo = 0;
|
---|
380 | const t_rnxObsFile::t_rnxEpo* epo = 0;
|
---|
381 | while ( (epo = _rnxObsFile->nextEpoch()) != 0 ) {
|
---|
382 | ++nEpo;
|
---|
383 |
|
---|
384 | if (_maxSpeed != 0) {
|
---|
385 | QMutexLocker locker(&_mutex);
|
---|
386 | if (_speed < _maxSpeed) {
|
---|
387 | double sleepTime = 0.02 * _maxSpeed / _speed;
|
---|
388 | t_pppThread::msleep(sleepTime*1.e3);
|
---|
389 | }
|
---|
390 | }
|
---|
391 |
|
---|
392 | // Get Corrections
|
---|
393 | // ---------------
|
---|
394 | if (_corrFile) {
|
---|
395 | _corrFile->syncRead(epo->tt);
|
---|
396 | }
|
---|
397 |
|
---|
398 | // Get Ephemerides
|
---|
399 | // ----------------
|
---|
400 | t_eph* eph = 0;
|
---|
401 | const QMap<QString, int>* corrIODs = _corrFile ? &_corrFile->corrIODs() : 0;
|
---|
402 | while ( (eph = _rnxNavFile->getNextEph(epo->tt, corrIODs)) != 0 ) {
|
---|
403 | _pppClient->putEphemeris(eph);
|
---|
404 | delete eph; eph = 0;
|
---|
405 | }
|
---|
406 |
|
---|
407 | // Create list of observations and start epoch processing
|
---|
408 | // ------------------------------------------------------
|
---|
409 | QList<t_obs> obsList;
|
---|
410 | for (unsigned iObs = 0; iObs < epo->rnxSat.size(); iObs++) {
|
---|
411 | const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iObs];
|
---|
412 |
|
---|
413 | t_obs obs;
|
---|
414 | t_rnxObsFile::setObsFromRnx(_rnxObsFile, epo, rnxSat, obs);
|
---|
415 | obsList << obs;
|
---|
416 | }
|
---|
417 | slotNewObs(QByteArray(_opt->_roverName.c_str()), obsList);
|
---|
418 |
|
---|
419 |
|
---|
420 | if (nEpo % 10 == 0) {
|
---|
421 | emit progress(nEpo);
|
---|
422 | }
|
---|
423 | }
|
---|
424 |
|
---|
425 | emit finished();
|
---|
426 |
|
---|
427 | if (BNC_CORE->mode() != t_bncCore::interactive) {
|
---|
428 | qApp->exit(0);
|
---|
429 | }
|
---|
430 | }
|
---|
431 |
|
---|
432 | //
|
---|
433 | ////////////////////////////////////////////////////////////////////////////
|
---|
434 | void t_pppRun::slotSetSpeed(int speed) {
|
---|
435 | QMutexLocker locker(&_mutex);
|
---|
436 | _speed = speed;
|
---|
437 | }
|
---|