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