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