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

Last change on this file since 5239 was 5239, checked in by mervart, 11 years ago
File size: 7.1 KB
Line 
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 "bnccore.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
53using namespace std;
54
55// Constructor
56////////////////////////////////////////////////////////////////////////////
57t_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 _isToBeDeleted = false;
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 }
79}
80
81// Destructor
82////////////////////////////////////////////////////////////////////////////
83t_postProcessing::~t_postProcessing() {
84 delete _pppClient;
85 delete _rnxNavFile;
86 delete _rnxObsFile;
87 delete _corrFile;
88 delete _opt;
89 delete _outStream;
90 delete _outFile;
91}
92
93// Write a Program Message
94////////////////////////////////////////////////////////////////////////////
95void t_postProcessing::slotMessage(QByteArray msg, bool /* showOnScreen */) {
96 if (_outStream) {
97 *_outStream << endl << msg;
98 _outStream->flush();
99 }
100 else {
101 BNC_CORE->slotMessage(msg, false);
102 }
103}
104
105// Set Observations from RINEX File
106////////////////////////////////////////////////////////////////////////////
107void t_postProcessing::setObsFromRnx(const t_rnxObsFile* rnxObsFile,
108 const t_rnxObsFile::t_rnxEpo* epo,
109 const t_rnxObsFile::t_rnxSat& rnxSat,
110 t_obs& obs) {
111
112 strncpy(obs.StatID, rnxObsFile->markerName().toAscii().constData(),
113 sizeof(obs.StatID));
114
115 obs.satSys = rnxSat.satSys;
116 obs.satNum = rnxSat.satNum;
117 obs.GPSWeek = epo->tt.gpsw();
118 obs.GPSWeeks = epo->tt.gpssec();
119
120 for (int iType = 0; iType < rnxObsFile->nTypes(obs.satSys); iType++) {
121 QString type = rnxObsFile->obsType(obs.satSys,iType).toAscii();
122 obs.setMeasdata(type, rnxObsFile->version(), rnxSat.obs[iType]);
123 if (type.indexOf("L1") == 0) {
124 obs.snrL1 = rnxSat.snr[iType];
125 obs.slipL1 = (rnxSat.lli[iType] & 1);
126 }
127 else if (type.indexOf("L2") == 0) {
128 obs.snrL2 = rnxSat.snr[iType];
129 obs.slipL2 = (rnxSat.lli[iType] & 1);
130 }
131 else if (type.indexOf("L5") == 0) {
132 obs.snrL5 = rnxSat.snr[iType];
133 obs.slipL5 = (rnxSat.lli[iType] & 1);
134 }
135 }
136}
137
138//
139////////////////////////////////////////////////////////////////////////////
140void t_postProcessing::terminate() {
141 _isToBeDeleted = true;
142 if (!isRunning()) {
143 delete this;
144 }
145}
146
147//
148////////////////////////////////////////////////////////////////////////////
149void t_postProcessing::run() {
150
151 if (_pppClient) {
152 return;
153 }
154 else {
155 try {
156 _rnxObsFile = new t_rnxObsFile(_opt->obsFileName, t_rnxObsFile::input);
157 }
158 catch (...) {
159 delete _rnxObsFile; _rnxObsFile = 0;
160 emit finished();
161 deleteLater();
162 return;
163 }
164 _rnxNavFile = new t_rnxNavFile(_opt->navFileName, t_rnxNavFile::input);
165 _pppClient = new bncPPPclient("POST", _opt, false);
166
167 if (!_opt->corrFileName.isEmpty()) {
168 _corrFile = new t_corrFile(_opt->corrFileName);
169 connect(_corrFile, SIGNAL(newCorrections(QList<QString>)),
170 _pppClient, SLOT(slotNewCorrections(QList<QString>)),
171 Qt::DirectConnection);
172 }
173
174 connect(_pppClient, SIGNAL(newMessage(QByteArray,bool)),
175 this, SLOT(slotMessage(const QByteArray,bool)));
176 qRegisterMetaType<bncTime>("bncTime");
177 connect(_pppClient, SIGNAL(newPosition(bncTime, double, double, double)),
178 this, SIGNAL(newPosition(bncTime, double, double, double)));
179 }
180
181 // Read/Process Observations
182 // -------------------------
183 int nEpo = 0;
184 const t_rnxObsFile::t_rnxEpo* epo = 0;
185 while ( (epo = _rnxObsFile->nextEpoch()) != 0 ) {
186 ++nEpo;
187
188 // Get Corrections
189 // ---------------
190 if (_corrFile) {
191 _corrFile->syncRead(epo->tt);
192 }
193
194 // Get Ephemerides
195 // ----------------
196 t_eph* eph = 0;
197 const QMap<QString, int>* corrIODs = _corrFile ? &_corrFile->corrIODs() : 0;
198 while ( (eph = _rnxNavFile->getNextEph(epo->tt, corrIODs)) != 0 ) {
199 if (_pppClient->putNewEph(eph) != success) {
200 delete eph; eph = 0;
201 }
202 }
203
204 for (unsigned iObs = 0; iObs < epo->rnxSat.size(); iObs++) {
205 if (_isToBeDeleted) {
206 QThread::exit(0);
207 this->deleteLater();
208 return;
209 }
210
211 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iObs];
212
213 t_obs obs;
214 t_postProcessing::setObsFromRnx(_rnxObsFile, epo, rnxSat, obs);
215
216 // Get Glonass Channel Number
217 // -------------------------
218 bool obsOK = true;
219 if (obs.satSys == 'R') {
220 QString prn = QString("%1%2").arg(obs.satSys)
221 .arg(obs.satNum, 2, 10, QChar('0'));
222 const bncEphUser::t_ephPair* ephPair = _pppClient->ephPair(prn);
223 if (ephPair && ephPair->last) {
224 obs.slotNum = ((t_ephGlo*) ephPair->last)->slotNum();
225 }
226 else {
227 obsOK = false;
228 }
229 }
230
231 // Put the new Observation to the Client
232 // -------------------------------------
233 if (obsOK) {
234 _pppClient->putNewObs(obs);
235 }
236 }
237 if (nEpo % 10 == 0) {
238 emit progress(nEpo);
239 }
240 }
241
242 if (BNC_CORE->mode() != t_bncCore::interactive) {
243 qApp->exit(0);
244 }
245 else {
246 emit finished();
247 deleteLater();
248 }
249}
Note: See TracBrowser for help on using the repository browser.