[3615] | 1 | // Part of BNC, a utility for retrieving decoding and
|
---|
| 2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 2007
|
---|
| 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
| 6 | // http://www.bkg.bund.de
|
---|
| 7 | // Czech Technical University Prague, Department of Geodesy
|
---|
| 8 | // http://www.fsv.cvut.cz
|
---|
| 9 | //
|
---|
| 10 | // Email: euref-ip@bkg.bund.de
|
---|
| 11 | //
|
---|
| 12 | // This program is free software; you can redistribute it and/or
|
---|
| 13 | // modify it under the terms of the GNU General Public License
|
---|
| 14 | // as published by the Free Software Foundation, version 2.
|
---|
| 15 | //
|
---|
| 16 | // This program is distributed in the hope that it will be useful,
|
---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | // GNU General Public License for more details.
|
---|
| 20 | //
|
---|
| 21 | // You should have received a copy of the GNU General Public License
|
---|
| 22 | // along with this program; if not, write to the Free Software
|
---|
| 23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
| 24 |
|
---|
| 25 | /* -------------------------------------------------------------------------
|
---|
| 26 | * BKG NTRIP Client
|
---|
| 27 | * -------------------------------------------------------------------------
|
---|
| 28 | *
|
---|
[3626] | 29 | * Class: t_postProcessing
|
---|
[3615] | 30 | *
|
---|
| 31 | * Purpose: Precise Point Positioning in Post-Processing Mode
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 22-Jan-2012
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
| 41 | #include <iostream>
|
---|
| 42 | #include "bncpostprocess.h"
|
---|
[5070] | 43 | #include "bnccore.h"
|
---|
[3625] | 44 | #include "bncsettings.h"
|
---|
[3642] | 45 | #include "pppopt.h"
|
---|
[3643] | 46 | #include "bncpppclient.h"
|
---|
[3717] | 47 | #include "rinex/rnxobsfile.h"
|
---|
[3646] | 48 | #include "rnxnavfile.h"
|
---|
[3688] | 49 | #include "corrfile.h"
|
---|
[3695] | 50 | #include "bncsettings.h"
|
---|
| 51 | #include "bncutils.h"
|
---|
[3615] | 52 |
|
---|
| 53 | using namespace std;
|
---|
| 54 |
|
---|
[3626] | 55 | // Constructor
|
---|
[3615] | 56 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5263] | 57 | t_postProcessing::t_postProcessing(QObject* parent, int maxSpeed, int speed) : QThread(parent) {
|
---|
[5262] | 58 |
|
---|
| 59 | _maxSpeed = maxSpeed;
|
---|
[5263] | 60 | _speed = speed;
|
---|
[3646] | 61 | _opt = new t_pppOpt();
|
---|
| 62 | _rnxObsFile = 0;
|
---|
| 63 | _rnxNavFile = 0;
|
---|
[3688] | 64 | _corrFile = 0;
|
---|
[3646] | 65 | _pppClient = 0;
|
---|
[5238] | 66 | _isToBeDeleted = false;
|
---|
[3695] | 67 |
|
---|
| 68 | bncSettings settings;
|
---|
| 69 |
|
---|
| 70 | QString outFileName = settings.value("postOutFile").toString();
|
---|
| 71 | if (outFileName.isEmpty()) {
|
---|
| 72 | _outFile = 0;
|
---|
| 73 | _outStream = 0;
|
---|
| 74 | }
|
---|
| 75 | else {
|
---|
| 76 | expandEnvVar(outFileName);
|
---|
| 77 | _outFile = new QFile(outFileName);
|
---|
| 78 | _outFile->open(QIODevice::WriteOnly | QIODevice::Text);
|
---|
| 79 | _outStream = new QTextStream();
|
---|
| 80 | _outStream->setDevice(_outFile);
|
---|
| 81 | }
|
---|
[3625] | 82 | }
|
---|
| 83 |
|
---|
[3626] | 84 | // Destructor
|
---|
| 85 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 86 | t_postProcessing::~t_postProcessing() {
|
---|
[3646] | 87 | delete _pppClient;
|
---|
| 88 | delete _rnxNavFile;
|
---|
| 89 | delete _rnxObsFile;
|
---|
[3688] | 90 | delete _corrFile;
|
---|
[3642] | 91 | delete _opt;
|
---|
[3695] | 92 | delete _outStream;
|
---|
| 93 | delete _outFile;
|
---|
[3626] | 94 | }
|
---|
| 95 |
|
---|
[3644] | 96 | // Write a Program Message
|
---|
| 97 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 98 | void t_postProcessing::slotMessage(QByteArray msg, bool /* showOnScreen */) {
|
---|
[3695] | 99 | if (_outStream) {
|
---|
[3696] | 100 | *_outStream << endl << msg;
|
---|
[3695] | 101 | _outStream->flush();
|
---|
| 102 | }
|
---|
| 103 | else {
|
---|
[5068] | 104 | BNC_CORE->slotMessage(msg, false);
|
---|
[3695] | 105 | }
|
---|
[3644] | 106 | }
|
---|
| 107 |
|
---|
[5238] | 108 | //
|
---|
| 109 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 110 | void t_postProcessing::terminate() {
|
---|
| 111 | _isToBeDeleted = true;
|
---|
| 112 | if (!isRunning()) {
|
---|
| 113 | delete this;
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 |
|
---|
[3626] | 117 | //
|
---|
| 118 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 119 | void t_postProcessing::run() {
|
---|
[3615] | 120 |
|
---|
[3644] | 121 | if (_pppClient) {
|
---|
| 122 | return;
|
---|
| 123 | }
|
---|
| 124 | else {
|
---|
[4363] | 125 | try {
|
---|
| 126 | _rnxObsFile = new t_rnxObsFile(_opt->obsFileName, t_rnxObsFile::input);
|
---|
| 127 | }
|
---|
| 128 | catch (...) {
|
---|
[4364] | 129 | delete _rnxObsFile; _rnxObsFile = 0;
|
---|
[4363] | 130 | emit finished();
|
---|
| 131 | return;
|
---|
| 132 | }
|
---|
[3999] | 133 | _rnxNavFile = new t_rnxNavFile(_opt->navFileName, t_rnxNavFile::input);
|
---|
[3646] | 134 | _pppClient = new bncPPPclient("POST", _opt, false);
|
---|
[3644] | 135 |
|
---|
[3688] | 136 | if (!_opt->corrFileName.isEmpty()) {
|
---|
| 137 | _corrFile = new t_corrFile(_opt->corrFileName);
|
---|
[5732] | 138 | connect(_corrFile, SIGNAL(newCorrections(QStringList)),
|
---|
| 139 | _pppClient, SLOT(slotNewCorrections(QStringList)),
|
---|
[3752] | 140 | Qt::DirectConnection);
|
---|
[3688] | 141 | }
|
---|
[3644] | 142 |
|
---|
| 143 | connect(_pppClient, SIGNAL(newMessage(QByteArray,bool)),
|
---|
| 144 | this, SLOT(slotMessage(const QByteArray,bool)));
|
---|
[5215] | 145 | qRegisterMetaType<bncTime>("bncTime");
|
---|
[5879] | 146 | connect(_pppClient, SIGNAL(newPosition(bncTime, QVector<double>)),
|
---|
| 147 | this, SIGNAL(newPosition(bncTime, QVector<double>)));
|
---|
[3643] | 148 | }
|
---|
| 149 |
|
---|
[3685] | 150 | // Read/Process Observations
|
---|
| 151 | // -------------------------
|
---|
| 152 | int nEpo = 0;
|
---|
[3717] | 153 | const t_rnxObsFile::t_rnxEpo* epo = 0;
|
---|
[3683] | 154 | while ( (epo = _rnxObsFile->nextEpoch()) != 0 ) {
|
---|
[3685] | 155 | ++nEpo;
|
---|
[3689] | 156 |
|
---|
[5268] | 157 | if (_maxSpeed != 0) {
|
---|
| 158 | QMutexLocker locker(&_mutex);
|
---|
| 159 | if (_speed < _maxSpeed) {
|
---|
| 160 | double sleepTime = 0.02 * _maxSpeed / _speed;
|
---|
| 161 | msleep(sleepTime*1.e3);
|
---|
| 162 | }
|
---|
| 163 | }
|
---|
| 164 |
|
---|
[3748] | 165 | // Get Corrections
|
---|
| 166 | // ---------------
|
---|
[3689] | 167 | if (_corrFile) {
|
---|
| 168 | _corrFile->syncRead(epo->tt);
|
---|
| 169 | }
|
---|
| 170 |
|
---|
[3748] | 171 | // Get Ephemerides
|
---|
| 172 | // ----------------
|
---|
| 173 | t_eph* eph = 0;
|
---|
[3757] | 174 | const QMap<QString, int>* corrIODs = _corrFile ? &_corrFile->corrIODs() : 0;
|
---|
| 175 | while ( (eph = _rnxNavFile->getNextEph(epo->tt, corrIODs)) != 0 ) {
|
---|
[3748] | 176 | if (_pppClient->putNewEph(eph) != success) {
|
---|
| 177 | delete eph; eph = 0;
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
| 180 |
|
---|
[3717] | 181 | for (unsigned iObs = 0; iObs < epo->rnxSat.size(); iObs++) {
|
---|
[5263] | 182 |
|
---|
[5238] | 183 | if (_isToBeDeleted) {
|
---|
| 184 | QThread::exit(0);
|
---|
| 185 | return;
|
---|
| 186 | }
|
---|
[4261] | 187 |
|
---|
[3717] | 188 | const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iObs];
|
---|
[4261] | 189 |
|
---|
[3680] | 190 | t_obs obs;
|
---|
[4261] | 191 | t_postProcessing::setObsFromRnx(_rnxObsFile, epo, rnxSat, obs);
|
---|
[3762] | 192 |
|
---|
| 193 | // Get Glonass Channel Number
|
---|
| 194 | // -------------------------
|
---|
[4261] | 195 | bool obsOK = true;
|
---|
[3762] | 196 | if (obs.satSys == 'R') {
|
---|
| 197 | QString prn = QString("%1%2").arg(obs.satSys)
|
---|
| 198 | .arg(obs.satNum, 2, 10, QChar('0'));
|
---|
| 199 | const bncEphUser::t_ephPair* ephPair = _pppClient->ephPair(prn);
|
---|
| 200 | if (ephPair && ephPair->last) {
|
---|
| 201 | obs.slotNum = ((t_ephGlo*) ephPair->last)->slotNum();
|
---|
| 202 | }
|
---|
[3763] | 203 | else {
|
---|
| 204 | obsOK = false;
|
---|
| 205 | }
|
---|
[3762] | 206 | }
|
---|
| 207 |
|
---|
| 208 | // Put the new Observation to the Client
|
---|
| 209 | // -------------------------------------
|
---|
[3763] | 210 | if (obsOK) {
|
---|
| 211 | _pppClient->putNewObs(obs);
|
---|
| 212 | }
|
---|
[3680] | 213 | }
|
---|
[3685] | 214 | if (nEpo % 10 == 0) {
|
---|
| 215 | emit progress(nEpo);
|
---|
| 216 | }
|
---|
[3674] | 217 | }
|
---|
| 218 |
|
---|
[5072] | 219 | if (BNC_CORE->mode() != t_bncCore::interactive) {
|
---|
[5066] | 220 | qApp->exit(0);
|
---|
[3973] | 221 | }
|
---|
| 222 | else {
|
---|
| 223 | emit finished();
|
---|
| 224 | deleteLater();
|
---|
| 225 | }
|
---|
[3615] | 226 | }
|
---|
[5262] | 227 |
|
---|
| 228 | //
|
---|
| 229 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 230 | void t_postProcessing::slotSetSpeed(int speed) {
|
---|
[5263] | 231 | QMutexLocker locker(&_mutex);
|
---|
| 232 | _speed = speed;
|
---|
[5262] | 233 | }
|
---|