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

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