source: ntrip/trunk/BNC/src/rinex/bncpostprocess.cpp@ 5214

Last change on this file since 5214 was 5214, checked in by mervart, 11 years ago
File size: 6.8 KB
RevLine 
[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
53using namespace std;
54
[3626]55// Constructor
[3615]56////////////////////////////////////////////////////////////////////////////
[3626]57t_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////////////////////////////////////////////////////////////////////////////
82t_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////////////////////////////////////////////////////////////////////////////
94void t_postProcessing::slotMessage(QByteArray msg, bool /* showOnScreen */) {
[3695]95 if (_outStream) {
[3696]96 *_outStream << endl << msg;
[3695]97 _outStream->flush();
98 }
99 else {
[5068]100 BNC_CORE->slotMessage(msg, false);
[3695]101 }
[3644]102}
103
[4261]104// Set Observations from RINEX File
105////////////////////////////////////////////////////////////////////////////
106void 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));
[4389]113
[4261]114 obs.satSys = rnxSat.satSys;
115 obs.satNum = rnxSat.satNum;
116 obs.GPSWeek = epo->tt.gpsw();
117 obs.GPSWeeks = epo->tt.gpssec();
[4389]118
[4261]119 for (int iType = 0; iType < rnxObsFile->nTypes(obs.satSys); iType++) {
[4391]120 QString type = rnxObsFile->obsType(obs.satSys,iType).toAscii();
[4403]121 obs.setMeasdata(type, rnxObsFile->version(), rnxSat.obs[iType]);
[4561]122 if (type.indexOf("L1") == 0) {
[4609]123 obs.snrL1 = rnxSat.snr[iType];
[4619]124 obs.slipL1 = (rnxSat.lli[iType] & 1);
[4561]125 }
126 else if (type.indexOf("L2") == 0) {
[4609]127 obs.snrL2 = rnxSat.snr[iType];
[4619]128 obs.slipL2 = (rnxSat.lli[iType] & 1);
[4561]129 }
130 else if (type.indexOf("L5") == 0) {
[4609]131 obs.snrL5 = rnxSat.snr[iType];
[4619]132 obs.slipL5 = (rnxSat.lli[iType] & 1);
[4561]133 }
[4261]134 }
135}
136
[3626]137//
138////////////////////////////////////////////////////////////////////////////
139void t_postProcessing::run() {
[3615]140
[3644]141 if (_pppClient) {
142 return;
143 }
144 else {
[4363]145 try {
146 _rnxObsFile = new t_rnxObsFile(_opt->obsFileName, t_rnxObsFile::input);
147 }
148 catch (...) {
[4364]149 delete _rnxObsFile; _rnxObsFile = 0;
[4363]150 emit finished();
151 deleteLater();
152 return;
153 }
[3999]154 _rnxNavFile = new t_rnxNavFile(_opt->navFileName, t_rnxNavFile::input);
[3646]155 _pppClient = new bncPPPclient("POST", _opt, false);
[3644]156
[3688]157 if (!_opt->corrFileName.isEmpty()) {
158 _corrFile = new t_corrFile(_opt->corrFileName);
159 connect(_corrFile, SIGNAL(newCorrections(QList<QString>)),
[3752]160 _pppClient, SLOT(slotNewCorrections(QList<QString>)),
161 Qt::DirectConnection);
[3688]162 }
[3644]163
164 connect(_pppClient, SIGNAL(newMessage(QByteArray,bool)),
165 this, SLOT(slotMessage(const QByteArray,bool)));
[5214]166 connect(_pppClient, SIGNAL(newPosition(bncTime, double, double, double)),
167 this, SIGNAL(newPosition(bncTime, double, double, double)));
[3643]168 }
169
[3685]170 // Read/Process Observations
171 // -------------------------
172 int nEpo = 0;
[3717]173 const t_rnxObsFile::t_rnxEpo* epo = 0;
[3683]174 while ( (epo = _rnxObsFile->nextEpoch()) != 0 ) {
[3685]175 ++nEpo;
[3689]176
[3748]177 // Get Corrections
178 // ---------------
[3689]179 if (_corrFile) {
180 _corrFile->syncRead(epo->tt);
181 }
182
[3748]183 // Get Ephemerides
184 // ----------------
185 t_eph* eph = 0;
[3757]186 const QMap<QString, int>* corrIODs = _corrFile ? &_corrFile->corrIODs() : 0;
187 while ( (eph = _rnxNavFile->getNextEph(epo->tt, corrIODs)) != 0 ) {
[3748]188 if (_pppClient->putNewEph(eph) != success) {
189 delete eph; eph = 0;
190 }
191 }
192
[3717]193 for (unsigned iObs = 0; iObs < epo->rnxSat.size(); iObs++) {
[4261]194
[3717]195 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iObs];
[4261]196
[3680]197 t_obs obs;
[4261]198 t_postProcessing::setObsFromRnx(_rnxObsFile, epo, rnxSat, obs);
[3762]199
200 // Get Glonass Channel Number
201 // -------------------------
[4261]202 bool obsOK = true;
[3762]203 if (obs.satSys == 'R') {
204 QString prn = QString("%1%2").arg(obs.satSys)
205 .arg(obs.satNum, 2, 10, QChar('0'));
206 const bncEphUser::t_ephPair* ephPair = _pppClient->ephPair(prn);
207 if (ephPair && ephPair->last) {
208 obs.slotNum = ((t_ephGlo*) ephPair->last)->slotNum();
209 }
[3763]210 else {
211 obsOK = false;
212 }
[3762]213 }
214
215 // Put the new Observation to the Client
216 // -------------------------------------
[3763]217 if (obsOK) {
218 _pppClient->putNewObs(obs);
219 }
[3680]220 }
[3685]221 if (nEpo % 10 == 0) {
222 emit progress(nEpo);
223 }
[3674]224 }
225
[5072]226 if (BNC_CORE->mode() != t_bncCore::interactive) {
[5066]227 qApp->exit(0);
[3973]228 }
229 else {
230 emit finished();
231 deleteLater();
232 }
[3615]233}
Note: See TracBrowser for help on using the repository browser.