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

Last change on this file since 4561 was 4561, checked in by mervart, 12 years ago
File size: 6.6 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 "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
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
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////////////////////////////////////////////////////////////////////////////
82t_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////////////////////////////////////////////////////////////////////////////
94void 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// 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));
113
114 obs.satSys = rnxSat.satSys;
115 obs.satNum = rnxSat.satNum;
116 obs.GPSWeek = epo->tt.gpsw();
117 obs.GPSWeeks = epo->tt.gpssec();
118
119 for (int iType = 0; iType < rnxObsFile->nTypes(obs.satSys); iType++) {
120 QString type = rnxObsFile->obsType(obs.satSys,iType).toAscii();
121 obs.setMeasdata(type, rnxObsFile->version(), rnxSat.obs[iType]);
122 if (type.indexOf("L1") == 0) {
123 obs.snrL1 = rnxSat.snr[iType];
124 }
125 else if (type.indexOf("L2") == 0) {
126 obs.snrL2 = rnxSat.snr[iType];
127 }
128 else if (type.indexOf("L5") == 0) {
129 obs.snrL5 = rnxSat.snr[iType];
130 }
131 // TOOD: handle slip flags
132 }
133}
134
135//
136////////////////////////////////////////////////////////////////////////////
137void t_postProcessing::run() {
138
139 if (_pppClient) {
140 return;
141 }
142 else {
143 try {
144 _rnxObsFile = new t_rnxObsFile(_opt->obsFileName, t_rnxObsFile::input);
145 }
146 catch (...) {
147 delete _rnxObsFile; _rnxObsFile = 0;
148 emit finished();
149 deleteLater();
150 return;
151 }
152 _rnxNavFile = new t_rnxNavFile(_opt->navFileName, t_rnxNavFile::input);
153 _pppClient = new bncPPPclient("POST", _opt, false);
154
155 if (!_opt->corrFileName.isEmpty()) {
156 _corrFile = new t_corrFile(_opt->corrFileName);
157 connect(_corrFile, SIGNAL(newCorrections(QList<QString>)),
158 _pppClient, SLOT(slotNewCorrections(QList<QString>)),
159 Qt::DirectConnection);
160 }
161
162 connect(_pppClient, SIGNAL(newMessage(QByteArray,bool)),
163 this, SLOT(slotMessage(const QByteArray,bool)));
164 }
165
166 // Read/Process Observations
167 // -------------------------
168 int nEpo = 0;
169 const t_rnxObsFile::t_rnxEpo* epo = 0;
170 while ( (epo = _rnxObsFile->nextEpoch()) != 0 ) {
171 ++nEpo;
172
173 // Get Corrections
174 // ---------------
175 if (_corrFile) {
176 _corrFile->syncRead(epo->tt);
177 }
178
179 // Get Ephemerides
180 // ----------------
181 t_eph* eph = 0;
182 const QMap<QString, int>* corrIODs = _corrFile ? &_corrFile->corrIODs() : 0;
183 while ( (eph = _rnxNavFile->getNextEph(epo->tt, corrIODs)) != 0 ) {
184 if (_pppClient->putNewEph(eph) != success) {
185 delete eph; eph = 0;
186 }
187 }
188
189 for (unsigned iObs = 0; iObs < epo->rnxSat.size(); iObs++) {
190
191 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iObs];
192
193 t_obs obs;
194 t_postProcessing::setObsFromRnx(_rnxObsFile, epo, rnxSat, obs);
195
196 // Get Glonass Channel Number
197 // -------------------------
198 bool obsOK = true;
199 if (obs.satSys == 'R') {
200 QString prn = QString("%1%2").arg(obs.satSys)
201 .arg(obs.satNum, 2, 10, QChar('0'));
202 const bncEphUser::t_ephPair* ephPair = _pppClient->ephPair(prn);
203 if (ephPair && ephPair->last) {
204 obs.slotNum = ((t_ephGlo*) ephPair->last)->slotNum();
205 }
206 else {
207 obsOK = false;
208 }
209 }
210
211 // Put the new Observation to the Client
212 // -------------------------------------
213 if (obsOK) {
214 _pppClient->putNewObs(obs);
215 }
216 }
217 if (nEpo % 10 == 0) {
218 emit progress(nEpo);
219 }
220 }
221
222 bncApp* app = (bncApp*) qApp;
223 if ( app->mode() != bncApp::interactive) {
224 app->exit(0);
225 }
226 else {
227 emit finished();
228 deleteLater();
229 }
230}
Note: See TracBrowser for help on using the repository browser.