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

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

* empty log message *

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