[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 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3626] | 57 | t_postProcessing::t_postProcessing(QObject* parent) : QThread(parent) {
|
---|
[3646] | 58 | _opt = new t_pppOpt();
|
---|
| 59 | _rnxObsFile = 0;
|
---|
| 60 | _rnxNavFile = 0;
|
---|
[3688] | 61 | _corrFile = 0;
|
---|
[3646] | 62 | _pppClient = 0;
|
---|
[5238] | 63 | _isToBeDeleted = false;
|
---|
[3695] | 64 |
|
---|
| 65 | bncSettings settings;
|
---|
| 66 |
|
---|
| 67 | QString outFileName = settings.value("postOutFile").toString();
|
---|
| 68 | if (outFileName.isEmpty()) {
|
---|
| 69 | _outFile = 0;
|
---|
| 70 | _outStream = 0;
|
---|
| 71 | }
|
---|
| 72 | else {
|
---|
| 73 | expandEnvVar(outFileName);
|
---|
| 74 | _outFile = new QFile(outFileName);
|
---|
| 75 | _outFile->open(QIODevice::WriteOnly | QIODevice::Text);
|
---|
| 76 | _outStream = new QTextStream();
|
---|
| 77 | _outStream->setDevice(_outFile);
|
---|
| 78 | }
|
---|
[3625] | 79 | }
|
---|
| 80 |
|
---|
[3626] | 81 | // Destructor
|
---|
| 82 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 83 | t_postProcessing::~t_postProcessing() {
|
---|
[5238] | 84 | qDebug() << "~t_postProcessing";
|
---|
[3646] | 85 | delete _pppClient;
|
---|
| 86 | delete _rnxNavFile;
|
---|
| 87 | delete _rnxObsFile;
|
---|
[3688] | 88 | delete _corrFile;
|
---|
[3642] | 89 | delete _opt;
|
---|
[3695] | 90 | delete _outStream;
|
---|
| 91 | delete _outFile;
|
---|
[3626] | 92 | }
|
---|
| 93 |
|
---|
[3644] | 94 | // Write a Program Message
|
---|
| 95 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 96 | void t_postProcessing::slotMessage(QByteArray msg, bool /* showOnScreen */) {
|
---|
[3695] | 97 | if (_outStream) {
|
---|
[3696] | 98 | *_outStream << endl << msg;
|
---|
[3695] | 99 | _outStream->flush();
|
---|
| 100 | }
|
---|
| 101 | else {
|
---|
[5068] | 102 | BNC_CORE->slotMessage(msg, false);
|
---|
[3695] | 103 | }
|
---|
[3644] | 104 | }
|
---|
| 105 |
|
---|
[4261] | 106 | // Set Observations from RINEX File
|
---|
| 107 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 108 | void t_postProcessing::setObsFromRnx(const t_rnxObsFile* rnxObsFile,
|
---|
| 109 | const t_rnxObsFile::t_rnxEpo* epo,
|
---|
| 110 | const t_rnxObsFile::t_rnxSat& rnxSat,
|
---|
| 111 | t_obs& obs) {
|
---|
| 112 |
|
---|
| 113 | strncpy(obs.StatID, rnxObsFile->markerName().toAscii().constData(),
|
---|
| 114 | sizeof(obs.StatID));
|
---|
[4389] | 115 |
|
---|
[4261] | 116 | obs.satSys = rnxSat.satSys;
|
---|
| 117 | obs.satNum = rnxSat.satNum;
|
---|
| 118 | obs.GPSWeek = epo->tt.gpsw();
|
---|
| 119 | obs.GPSWeeks = epo->tt.gpssec();
|
---|
[4389] | 120 |
|
---|
[4261] | 121 | for (int iType = 0; iType < rnxObsFile->nTypes(obs.satSys); iType++) {
|
---|
[4391] | 122 | QString type = rnxObsFile->obsType(obs.satSys,iType).toAscii();
|
---|
[4403] | 123 | obs.setMeasdata(type, rnxObsFile->version(), rnxSat.obs[iType]);
|
---|
[4561] | 124 | if (type.indexOf("L1") == 0) {
|
---|
[4609] | 125 | obs.snrL1 = rnxSat.snr[iType];
|
---|
[4619] | 126 | obs.slipL1 = (rnxSat.lli[iType] & 1);
|
---|
[4561] | 127 | }
|
---|
| 128 | else if (type.indexOf("L2") == 0) {
|
---|
[4609] | 129 | obs.snrL2 = rnxSat.snr[iType];
|
---|
[4619] | 130 | obs.slipL2 = (rnxSat.lli[iType] & 1);
|
---|
[4561] | 131 | }
|
---|
| 132 | else if (type.indexOf("L5") == 0) {
|
---|
[4609] | 133 | obs.snrL5 = rnxSat.snr[iType];
|
---|
[4619] | 134 | obs.slipL5 = (rnxSat.lli[iType] & 1);
|
---|
[4561] | 135 | }
|
---|
[4261] | 136 | }
|
---|
| 137 | }
|
---|
| 138 |
|
---|
[5238] | 139 | //
|
---|
| 140 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 141 | void t_postProcessing::terminate() {
|
---|
| 142 | _isToBeDeleted = true;
|
---|
| 143 | if (!isRunning()) {
|
---|
| 144 | delete this;
|
---|
| 145 | }
|
---|
| 146 | }
|
---|
| 147 |
|
---|
[3626] | 148 | //
|
---|
| 149 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 150 | void t_postProcessing::run() {
|
---|
[3615] | 151 |
|
---|
[3644] | 152 | if (_pppClient) {
|
---|
| 153 | return;
|
---|
| 154 | }
|
---|
| 155 | else {
|
---|
[4363] | 156 | try {
|
---|
| 157 | _rnxObsFile = new t_rnxObsFile(_opt->obsFileName, t_rnxObsFile::input);
|
---|
| 158 | }
|
---|
| 159 | catch (...) {
|
---|
[4364] | 160 | delete _rnxObsFile; _rnxObsFile = 0;
|
---|
[4363] | 161 | emit finished();
|
---|
| 162 | deleteLater();
|
---|
| 163 | return;
|
---|
| 164 | }
|
---|
[3999] | 165 | _rnxNavFile = new t_rnxNavFile(_opt->navFileName, t_rnxNavFile::input);
|
---|
[3646] | 166 | _pppClient = new bncPPPclient("POST", _opt, false);
|
---|
[3644] | 167 |
|
---|
[3688] | 168 | if (!_opt->corrFileName.isEmpty()) {
|
---|
| 169 | _corrFile = new t_corrFile(_opt->corrFileName);
|
---|
| 170 | connect(_corrFile, SIGNAL(newCorrections(QList<QString>)),
|
---|
[3752] | 171 | _pppClient, SLOT(slotNewCorrections(QList<QString>)),
|
---|
| 172 | Qt::DirectConnection);
|
---|
[3688] | 173 | }
|
---|
[3644] | 174 |
|
---|
| 175 | connect(_pppClient, SIGNAL(newMessage(QByteArray,bool)),
|
---|
| 176 | this, SLOT(slotMessage(const QByteArray,bool)));
|
---|
[5215] | 177 | qRegisterMetaType<bncTime>("bncTime");
|
---|
[5214] | 178 | connect(_pppClient, SIGNAL(newPosition(bncTime, double, double, double)),
|
---|
| 179 | this, SIGNAL(newPosition(bncTime, double, double, double)));
|
---|
[3643] | 180 | }
|
---|
| 181 |
|
---|
[3685] | 182 | // Read/Process Observations
|
---|
| 183 | // -------------------------
|
---|
| 184 | int nEpo = 0;
|
---|
[3717] | 185 | const t_rnxObsFile::t_rnxEpo* epo = 0;
|
---|
[3683] | 186 | while ( (epo = _rnxObsFile->nextEpoch()) != 0 ) {
|
---|
[3685] | 187 | ++nEpo;
|
---|
[3689] | 188 |
|
---|
[3748] | 189 | // Get Corrections
|
---|
| 190 | // ---------------
|
---|
[3689] | 191 | if (_corrFile) {
|
---|
| 192 | _corrFile->syncRead(epo->tt);
|
---|
| 193 | }
|
---|
| 194 |
|
---|
[3748] | 195 | // Get Ephemerides
|
---|
| 196 | // ----------------
|
---|
| 197 | t_eph* eph = 0;
|
---|
[3757] | 198 | const QMap<QString, int>* corrIODs = _corrFile ? &_corrFile->corrIODs() : 0;
|
---|
| 199 | while ( (eph = _rnxNavFile->getNextEph(epo->tt, corrIODs)) != 0 ) {
|
---|
[3748] | 200 | if (_pppClient->putNewEph(eph) != success) {
|
---|
| 201 | delete eph; eph = 0;
|
---|
| 202 | }
|
---|
| 203 | }
|
---|
| 204 |
|
---|
[3717] | 205 | for (unsigned iObs = 0; iObs < epo->rnxSat.size(); iObs++) {
|
---|
[5238] | 206 | if (_isToBeDeleted) {
|
---|
| 207 | QThread::exit(0);
|
---|
| 208 | this->deleteLater();
|
---|
| 209 | return;
|
---|
| 210 | }
|
---|
[4261] | 211 |
|
---|
[3717] | 212 | const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iObs];
|
---|
[4261] | 213 |
|
---|
[3680] | 214 | t_obs obs;
|
---|
[4261] | 215 | t_postProcessing::setObsFromRnx(_rnxObsFile, epo, rnxSat, obs);
|
---|
[3762] | 216 |
|
---|
| 217 | // Get Glonass Channel Number
|
---|
| 218 | // -------------------------
|
---|
[4261] | 219 | bool obsOK = true;
|
---|
[3762] | 220 | if (obs.satSys == 'R') {
|
---|
| 221 | QString prn = QString("%1%2").arg(obs.satSys)
|
---|
| 222 | .arg(obs.satNum, 2, 10, QChar('0'));
|
---|
| 223 | const bncEphUser::t_ephPair* ephPair = _pppClient->ephPair(prn);
|
---|
| 224 | if (ephPair && ephPair->last) {
|
---|
| 225 | obs.slotNum = ((t_ephGlo*) ephPair->last)->slotNum();
|
---|
| 226 | }
|
---|
[3763] | 227 | else {
|
---|
| 228 | obsOK = false;
|
---|
| 229 | }
|
---|
[3762] | 230 | }
|
---|
| 231 |
|
---|
| 232 | // Put the new Observation to the Client
|
---|
| 233 | // -------------------------------------
|
---|
[3763] | 234 | if (obsOK) {
|
---|
| 235 | _pppClient->putNewObs(obs);
|
---|
| 236 | }
|
---|
[3680] | 237 | }
|
---|
[3685] | 238 | if (nEpo % 10 == 0) {
|
---|
| 239 | emit progress(nEpo);
|
---|
| 240 | }
|
---|
[3674] | 241 | }
|
---|
| 242 |
|
---|
[5072] | 243 | if (BNC_CORE->mode() != t_bncCore::interactive) {
|
---|
[5066] | 244 | qApp->exit(0);
|
---|
[3973] | 245 | }
|
---|
| 246 | else {
|
---|
| 247 | emit finished();
|
---|
| 248 | deleteLater();
|
---|
| 249 | }
|
---|
[3615] | 250 | }
|
---|