source: ntrip/trunk/BNC/bncpppclient.cpp@ 2062

Last change on this file since 2062 was 2062, checked in by mervart, 14 years ago

* empty log message *

File size: 8.3 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: bncPPPclient
30 *
31 * Purpose: Precise Point Positioning
32 *
33 * Author: L. Mervart
34 *
35 * Created: 21-Nov-2009
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iomanip>
42#include <newmatio.h>
43#include <sstream>
44
45#include "bncpppclient.h"
46#include "bncutils.h"
47#include "bncconst.h"
48#include "bncmodel.h"
49
50extern "C" {
51#include "clock_orbit_rtcm.h"
52}
53
54using namespace std;
55
56// Constructor
57////////////////////////////////////////////////////////////////////////////
58bncPPPclient::bncPPPclient(QByteArray staID) {
59 _staID = staID;
60 _epoData = 0;
61 _model = new bncModel();
62}
63
64// Destructor
65////////////////////////////////////////////////////////////////////////////
66bncPPPclient::~bncPPPclient() {
67 delete _model;
68 delete _epoData;
69 QMapIterator<QString, t_eph*> it(_eph);
70 while (it.hasNext()) {
71 it.next();
72 delete it.value();
73 }
74 QMapIterator<QString, t_corr*> ic(_corr);
75 while (ic.hasNext()) {
76 ic.next();
77 delete ic.value();
78 }
79}
80
81//
82////////////////////////////////////////////////////////////////////////////
83void bncPPPclient::putNewObs(p_obs pp) {
84 QMutexLocker locker(&_mutex);
85
86 static const double c1 = t_CST::freq1 * t_CST::freq1 /
87 (t_CST::freq1 * t_CST::freq1 - t_CST::freq2 * t_CST::freq2);
88
89 static const double c2 = - t_CST::freq2 * t_CST::freq2 /
90 (t_CST::freq1 * t_CST::freq1 - t_CST::freq2 * t_CST::freq2);
91
92 t_obsInternal* obs = &(pp->_o);
93
94 t_satData* satData = new t_satData();
95
96 // Set Code Observations
97 // ---------------------
98 if (obs->P1) {
99 satData->P1 = obs->P1;
100 satData->codeTypeF1 = t_satData::P_CODE;
101 }
102 else if (obs->C1) {
103 satData->P1 = obs->C1;
104 satData->codeTypeF1 = t_satData::C_CODE;
105 }
106 else {
107 delete satData;
108 return;
109 }
110
111 if (obs->P2) {
112 satData->P2 = obs->P2;
113 satData->codeTypeF2 = t_satData::P_CODE;
114 }
115 else if (obs->C2) {
116 satData->P2 = obs->C2;
117 satData->codeTypeF2 = t_satData::C_CODE;
118 }
119 else {
120 delete satData;
121 return;
122 }
123
124 satData->P3 = c1 * satData->P1 + c2 * satData->P2;
125
126 // Set Phase Observations
127 // ----------------------
128 if (obs->L1 && obs->L2) {
129 satData->L1 = obs->L1 * t_CST::lambda1;
130 satData->L2 = obs->L2 * t_CST::lambda2;
131 }
132 else {
133 delete satData;
134 return;
135 }
136 satData->L3 = c1 * satData->L1 + c2 * satData->L2;
137
138 // Add new Satellite to the epoch
139 // ------------------------------
140 t_time tt(obs->GPSWeek, obs->GPSWeeks);
141
142 if (!_epoData) {
143 _epoData = new t_epoData();
144 _epoData->tt = tt;
145 }
146 else if (tt != _epoData->tt) {
147 processEpoch();
148 delete _epoData;
149 _epoData = new t_epoData();
150 _epoData->tt = tt;
151 }
152
153 QString prn =
154 QString("%1%2").arg(obs->satSys).arg(obs->satNum, 2, 10, QChar('0'));
155
156 _epoData->satData[prn] = satData;
157}
158
159//
160////////////////////////////////////////////////////////////////////////////
161void bncPPPclient::slotNewEphGPS(gpsephemeris gpseph) {
162 QMutexLocker locker(&_mutex);
163
164 QString prn = QString("G%1").arg(gpseph.satellite, 2, 10, QChar('0'));
165
166 if (_eph.contains(prn)) {
167 t_ephGPS* ee = static_cast<t_ephGPS*>(_eph.value(prn));
168 if ( (ee->GPSweek() < gpseph.GPSweek) ||
169 (ee->GPSweek() == gpseph.GPSweek &&
170 ee->TOC() < gpseph.TOC) ) {
171 ee->set(&gpseph);
172 }
173 }
174 else {
175 t_ephGPS* ee = new t_ephGPS();
176 ee->set(&gpseph);
177 _eph[prn] = ee;
178 }
179}
180
181//
182////////////////////////////////////////////////////////////////////////////
183void bncPPPclient::slotNewCorrections(QList<QString> corrList) {
184 QMutexLocker locker(&_mutex);
185 QListIterator<QString> it(corrList);
186 while (it.hasNext()) {
187 QTextStream in(it.next().toAscii());
188 int messageType;
189 int updateInterval;
190 int GPSweek;
191 double GPSweeks;
192 QString prn;
193 in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
194 if ( messageType == COTYPE_GPSCOMBINED ||
195 messageType == COTYPE_GLONASSCOMBINED ) {
196 t_corr* cc = 0;
197 if (_corr.contains(prn)) {
198 cc = _corr.value(prn);
199 }
200 else {
201 cc = new t_corr();
202 _corr[prn] = cc;
203 }
204 cc->tt.set(GPSweek, GPSweeks);
205 cc->rao.ReSize(3);
206 in >> cc->iod >> cc->dClk >> cc->rao[0] >> cc->rao[1] >> cc->rao[2];
207 cc->dClk /= t_CST::c;
208 }
209 }
210}
211
212// Satellite Position
213////////////////////////////////////////////////////////////////////////////
214t_irc bncPPPclient::getSatPos(const t_time& tt, const QString& prn,
215 ColumnVector& xc, ColumnVector& vv, bool& corr) {
216
217 const double MAXAGE = 120.0;
218
219 corr = false;
220
221 if (_eph.contains(prn)) {
222 t_eph* ee = _eph.value(prn);
223 ee->position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data());
224
225 if (_corr.contains(prn)) {
226 t_corr* cc = _corr.value(prn);
227 if (ee->IOD() == cc->iod && (tt - cc->tt) < MAXAGE) {
228 corr = true;
229 applyCorr(cc, xc, vv);
230 }
231 }
232
233 return success;
234 }
235
236 return failure;
237}
238
239//
240////////////////////////////////////////////////////////////////////////////
241void bncPPPclient::applyCorr(const t_corr* cc, ColumnVector& xc,
242 ColumnVector& vv) {
243 ColumnVector dx(3);
244 RSW_to_XYZ(xc.Rows(1,3), vv, cc->rao, dx);
245
246 xc[0] += dx[0];
247 xc[1] += dx[1];
248 xc[2] += dx[2];
249 xc[3] += cc->dClk;
250}
251
252// Correct Time of Transmission
253////////////////////////////////////////////////////////////////////////////
254t_irc bncPPPclient::cmpToT(const QString& prn, t_satData* satData) {
255
256 double prange = satData->P3;
257 if (prange == 0.0) {
258 return failure;
259 }
260
261 double clkSat = 0.0;
262 for (int ii = 1; ii <= 10; ii++) {
263
264 t_time ToT = _epoData->tt - prange / t_CST::c - clkSat;
265
266 ColumnVector xc(4);
267 ColumnVector vv(3);
268 bool corr = false;
269 if (getSatPos(ToT, prn, xc, vv, corr) != success) {
270 return failure;
271 }
272
273 double clkSatOld = clkSat;
274 clkSat = xc(4);
275
276 if ( fabs(clkSat-clkSatOld) * t_CST::c < 1.e-4 ) {
277 satData->xx = xc.Rows(1,3);
278 satData->vv = vv;
279 satData->clk = clkSat * t_CST::c;
280 satData->clkCorr = corr;
281 return success;
282 }
283 }
284
285 return failure;
286}
287
288//
289////////////////////////////////////////////////////////////////////////////
290void bncPPPclient::processEpoch() {
291
292 // Data Pre-Processing
293 // -------------------
294 QMutableMapIterator<QString, t_satData*> im(_epoData->satData);
295 while (im.hasNext()) {
296 im.next();
297 QString prn = im.key();
298 t_satData* satData = im.value();
299
300 if (cmpToT(prn, satData) != success) {
301 delete satData;
302 im.remove();
303 continue;
304 }
305 }
306
307 // Bancroft Solution
308 // -----------------
309 if (_model->cmpBancroft(_epoData) != success) {
310 return;
311 }
312
313 // Filter Solution
314 // ---------------
315 if (_model->update(_epoData) != success) {
316 return;
317 }
318
319 ostringstream str;
320 str.setf(ios::fixed);
321 str << " PPP " << _staID.data() << " "
322 << _epoData->tt.timestr(1) << " " << _epoData->size() << " "
323 << setw(14) << setprecision(3) << _model->xx()(1) << " "
324 << setw(14) << setprecision(3) << _model->xx()(2) << " "
325 << setw(14) << setprecision(3) << _model->xx()(3);
326
327 emit newMessage(QString(str.str().c_str()).toAscii(), true);
328}
329
Note: See TracBrowser for help on using the repository browser.