| 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 | *
|
|---|
| 29 | * Class: t_postProcessing
|
|---|
| 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"
|
|---|
| 43 | #include "bncapp.h"
|
|---|
| 44 | #include "bncsettings.h"
|
|---|
| 45 | #include "pppopt.h"
|
|---|
| 46 | #include "bncpppclient.h"
|
|---|
| 47 | #include "rinex/rnxobsfile.h"
|
|---|
| 48 | #include "rnxnavfile.h"
|
|---|
| 49 | #include "corrfile.h"
|
|---|
| 50 | #include "bncsettings.h"
|
|---|
| 51 | #include "bncutils.h"
|
|---|
| 52 |
|
|---|
| 53 | using namespace std;
|
|---|
| 54 |
|
|---|
| 55 | // Constructor
|
|---|
| 56 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 57 | t_postProcessing::t_postProcessing(QObject* parent) : QThread(parent) {
|
|---|
| 58 | _opt = new t_pppOpt();
|
|---|
| 59 | _rnxObsFile = 0;
|
|---|
| 60 | _rnxNavFile = 0;
|
|---|
| 61 | _corrFile = 0;
|
|---|
| 62 | _pppClient = 0;
|
|---|
| 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 | }
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | // Destructor
|
|---|
| 81 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 82 | t_postProcessing::~t_postProcessing() {
|
|---|
| 83 | delete _pppClient;
|
|---|
| 84 | delete _rnxNavFile;
|
|---|
| 85 | delete _rnxObsFile;
|
|---|
| 86 | delete _corrFile;
|
|---|
| 87 | delete _opt;
|
|---|
| 88 | delete _outStream;
|
|---|
| 89 | delete _outFile;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | // Write a Program Message
|
|---|
| 93 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 94 | void t_postProcessing::slotMessage(QByteArray msg, bool /* showOnScreen */) {
|
|---|
| 95 | if (_outStream) {
|
|---|
| 96 | *_outStream << endl << msg;
|
|---|
| 97 | _outStream->flush();
|
|---|
| 98 | }
|
|---|
| 99 | else {
|
|---|
| 100 | ((bncApp*) qApp)->slotMessage(msg, false);
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | //
|
|---|
| 105 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 106 | void t_postProcessing::run() {
|
|---|
| 107 |
|
|---|
| 108 | if (_pppClient) {
|
|---|
| 109 | return;
|
|---|
| 110 | }
|
|---|
| 111 | else {
|
|---|
| 112 | _rnxObsFile = new t_rnxObsFile(_opt->obsFileName, t_rnxObsFile::input);
|
|---|
| 113 | _rnxNavFile = new t_rnxNavFile(_opt->navFileName, t_rnxNavFile::input);
|
|---|
| 114 | _pppClient = new bncPPPclient("POST", _opt, false);
|
|---|
| 115 |
|
|---|
| 116 | if (!_opt->corrFileName.isEmpty()) {
|
|---|
| 117 | _corrFile = new t_corrFile(_opt->corrFileName);
|
|---|
| 118 | connect(_corrFile, SIGNAL(newCorrections(QList<QString>)),
|
|---|
| 119 | _pppClient, SLOT(slotNewCorrections(QList<QString>)),
|
|---|
| 120 | Qt::DirectConnection);
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | connect(_pppClient, SIGNAL(newMessage(QByteArray,bool)),
|
|---|
| 124 | this, SLOT(slotMessage(const QByteArray,bool)));
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | // Read/Process Observations
|
|---|
| 128 | // -------------------------
|
|---|
| 129 | int nEpo = 0;
|
|---|
| 130 | const t_rnxObsFile::t_rnxEpo* epo = 0;
|
|---|
| 131 | while ( (epo = _rnxObsFile->nextEpoch()) != 0 ) {
|
|---|
| 132 | ++nEpo;
|
|---|
| 133 |
|
|---|
| 134 | // Get Corrections
|
|---|
| 135 | // ---------------
|
|---|
| 136 | if (_corrFile) {
|
|---|
| 137 | _corrFile->syncRead(epo->tt);
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | // Get Ephemerides
|
|---|
| 141 | // ----------------
|
|---|
| 142 | t_eph* eph = 0;
|
|---|
| 143 | const QMap<QString, int>* corrIODs = _corrFile ? &_corrFile->corrIODs() : 0;
|
|---|
| 144 | while ( (eph = _rnxNavFile->getNextEph(epo->tt, corrIODs)) != 0 ) {
|
|---|
| 145 | if (_pppClient->putNewEph(eph) != success) {
|
|---|
| 146 | delete eph; eph = 0;
|
|---|
| 147 | }
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | for (unsigned iObs = 0; iObs < epo->rnxSat.size(); iObs++) {
|
|---|
| 151 | bool obsOK = true;
|
|---|
| 152 | const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iObs];
|
|---|
| 153 | t_obs obs;
|
|---|
| 154 | strncpy(obs.StatID, _rnxObsFile->markerName().toAscii().constData(),
|
|---|
| 155 | sizeof(obs.StatID));
|
|---|
| 156 | obs.satSys = rnxSat.satSys;
|
|---|
| 157 | obs.satNum = rnxSat.satNum;
|
|---|
| 158 | obs.GPSWeek = epo->tt.gpsw();
|
|---|
| 159 | obs.GPSWeeks = epo->tt.gpssec();
|
|---|
| 160 | //// TODO: check RINEX Version 3 types
|
|---|
| 161 | for (int iType = 0; iType < _rnxObsFile->nTypes(obs.satSys); iType++) {
|
|---|
| 162 | QByteArray type = _rnxObsFile->obsType(obs.satSys,iType).toAscii();
|
|---|
| 163 | if (type.indexOf("C1") == 0 && obs.C1 == 0.0) {
|
|---|
| 164 | obs.C1 = rnxSat.obs[iType];
|
|---|
| 165 | }
|
|---|
| 166 | else if (type.indexOf("P1") == 0 && obs.P1 == 0.0) {
|
|---|
| 167 | obs.P1 = rnxSat.obs[iType];
|
|---|
| 168 | }
|
|---|
| 169 | else if (type.indexOf("L1") == 0 && obs.L1C == 0.0) {
|
|---|
| 170 | obs.L1C = rnxSat.obs[iType];
|
|---|
| 171 | }
|
|---|
| 172 | else if (type.indexOf("C2") == 0 && obs.C2 == 0.0) {
|
|---|
| 173 | obs.C2 = rnxSat.obs[iType];
|
|---|
| 174 | }
|
|---|
| 175 | else if (type.indexOf("P2") == 0 && obs.P2 == 0.0) {
|
|---|
| 176 | obs.P2 = rnxSat.obs[iType];
|
|---|
| 177 | }
|
|---|
| 178 | else if (type.indexOf("L2") == 0 && obs.L2C == 0.0) {
|
|---|
| 179 | obs.L2C = rnxSat.obs[iType];
|
|---|
| 180 | }
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | // Get Glonass Channel Number
|
|---|
| 184 | // -------------------------
|
|---|
| 185 | if (obs.satSys == 'R') {
|
|---|
| 186 | QString prn = QString("%1%2").arg(obs.satSys)
|
|---|
| 187 | .arg(obs.satNum, 2, 10, QChar('0'));
|
|---|
| 188 | const bncEphUser::t_ephPair* ephPair = _pppClient->ephPair(prn);
|
|---|
| 189 | if (ephPair && ephPair->last) {
|
|---|
| 190 | obs.slotNum = ((t_ephGlo*) ephPair->last)->slotNum();
|
|---|
| 191 | }
|
|---|
| 192 | else {
|
|---|
| 193 | obsOK = false;
|
|---|
| 194 | }
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | // Put the new Observation to the Client
|
|---|
| 198 | // -------------------------------------
|
|---|
| 199 | if (obsOK) {
|
|---|
| 200 | _pppClient->putNewObs(obs);
|
|---|
| 201 | }
|
|---|
| 202 | }
|
|---|
| 203 | if (nEpo % 10 == 0) {
|
|---|
| 204 | emit progress(nEpo);
|
|---|
| 205 | }
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 | bncApp* app = (bncApp*) qApp;
|
|---|
| 209 | if ( app->mode() != bncApp::interactive) {
|
|---|
| 210 | app->exit(0);
|
|---|
| 211 | }
|
|---|
| 212 | else {
|
|---|
| 213 | emit finished();
|
|---|
| 214 | deleteLater();
|
|---|
| 215 | }
|
|---|
| 216 | }
|
|---|