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

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

* empty log message *

File size: 9.8 KB
RevLine 
[2035]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 "bncpppclient.h"
[2113]42#include "bncapp.h"
[2043]43#include "bncutils.h"
[2044]44#include "bncconst.h"
[2058]45#include "bncmodel.h"
[2035]46
47extern "C" {
48#include "clock_orbit_rtcm.h"
49}
50
51using namespace std;
52
53// Constructor
54////////////////////////////////////////////////////////////////////////////
55bncPPPclient::bncPPPclient(QByteArray staID) {
[2113]56
57 connect(((bncApp*)qApp), SIGNAL(newEphGPS(gpsephemeris)),
58 this, SLOT(slotNewEphGPS(gpsephemeris)));
59 connect(((bncApp*)qApp), SIGNAL(newCorrections(QList<QString>)),
60 this, SLOT(slotNewCorrections(QList<QString>)));
61
[2039]62 _staID = staID;
63 _epoData = 0;
[2113]64 _model = new bncModel(staID);
[2182]65 connect(_model, SIGNAL(newNMEAstr(QByteArray)),
66 this, SIGNAL(newNMEAstr(QByteArray)));
[2035]67}
68
69// Destructor
70////////////////////////////////////////////////////////////////////////////
71bncPPPclient::~bncPPPclient() {
[2058]72 delete _model;
[2039]73 delete _epoData;
[2035]74 QMapIterator<QString, t_eph*> it(_eph);
75 while (it.hasNext()) {
76 it.next();
77 delete it.value();
78 }
79 QMapIterator<QString, t_corr*> ic(_corr);
80 while (ic.hasNext()) {
81 ic.next();
82 delete ic.value();
83 }
84}
85
86//
87////////////////////////////////////////////////////////////////////////////
88void bncPPPclient::putNewObs(p_obs pp) {
[2037]89 QMutexLocker locker(&_mutex);
[2051]90
91 static const double c1 = t_CST::freq1 * t_CST::freq1 /
92 (t_CST::freq1 * t_CST::freq1 - t_CST::freq2 * t_CST::freq2);
[2037]93
[2051]94 static const double c2 = - t_CST::freq2 * t_CST::freq2 /
95 (t_CST::freq1 * t_CST::freq1 - t_CST::freq2 * t_CST::freq2);
96
[2037]97 t_obsInternal* obs = &(pp->_o);
[2051]98
99 t_satData* satData = new t_satData();
100
101 // Set Code Observations
102 // ---------------------
103 if (obs->P1) {
104 satData->P1 = obs->P1;
105 satData->codeTypeF1 = t_satData::P_CODE;
106 }
107 else if (obs->C1) {
108 satData->P1 = obs->C1;
109 satData->codeTypeF1 = t_satData::C_CODE;
110 }
111 else {
112 delete satData;
113 return;
114 }
115
116 if (obs->P2) {
117 satData->P2 = obs->P2;
118 satData->codeTypeF2 = t_satData::P_CODE;
119 }
120 else if (obs->C2) {
121 satData->P2 = obs->C2;
122 satData->codeTypeF2 = t_satData::C_CODE;
123 }
124 else {
125 delete satData;
126 return;
127 }
128
129 satData->P3 = c1 * satData->P1 + c2 * satData->P2;
130
131 // Set Phase Observations
132 // ----------------------
133 if (obs->L1 && obs->L2) {
134 satData->L1 = obs->L1 * t_CST::lambda1;
135 satData->L2 = obs->L2 * t_CST::lambda2;
136 }
137 else {
138 delete satData;
139 return;
140 }
141 satData->L3 = c1 * satData->L1 + c2 * satData->L2;
142
143 // Add new Satellite to the epoch
144 // ------------------------------
[2123]145 bncTime tt(obs->GPSWeek, obs->GPSWeeks);
[2037]146
[2039]147 if (!_epoData) {
148 _epoData = new t_epoData();
149 _epoData->tt = tt;
[2037]150 }
[2039]151 else if (tt != _epoData->tt) {
[2037]152 processEpoch();
[2039]153 delete _epoData;
154 _epoData = new t_epoData();
155 _epoData->tt = tt;
[2037]156 }
[2039]157
158 QString prn =
[2037]159 QString("%1%2").arg(obs->satSys).arg(obs->satNum, 2, 10, QChar('0'));
[2039]160
[2221]161 cout << prn.toAscii().data() << " " << obs->slot << endl;
162
[2039]163 _epoData->satData[prn] = satData;
[2035]164}
165
166//
167////////////////////////////////////////////////////////////////////////////
168void bncPPPclient::slotNewEphGPS(gpsephemeris gpseph) {
169 QMutexLocker locker(&_mutex);
170
171 QString prn = QString("G%1").arg(gpseph.satellite, 2, 10, QChar('0'));
172
173 if (_eph.contains(prn)) {
[2040]174 t_ephGPS* ee = static_cast<t_ephGPS*>(_eph.value(prn));
175 if ( (ee->GPSweek() < gpseph.GPSweek) ||
176 (ee->GPSweek() == gpseph.GPSweek &&
177 ee->TOC() < gpseph.TOC) ) {
178 ee->set(&gpseph);
179 }
[2035]180 }
181 else {
182 t_ephGPS* ee = new t_ephGPS();
183 ee->set(&gpseph);
184 _eph[prn] = ee;
185 }
186}
187
188//
189////////////////////////////////////////////////////////////////////////////
190void bncPPPclient::slotNewCorrections(QList<QString> corrList) {
191 QMutexLocker locker(&_mutex);
[2069]192
193 if (corrList.size() == 0) {
194 return;
195 }
196
197 // Remove All Corrections
198 // ----------------------
199 QMapIterator<QString, t_corr*> ic(_corr);
200 while (ic.hasNext()) {
201 ic.next();
202 delete ic.value();
203 }
204 _corr.clear();
205
[2035]206 QListIterator<QString> it(corrList);
207 while (it.hasNext()) {
208 QTextStream in(it.next().toAscii());
209 int messageType;
210 int updateInterval;
211 int GPSweek;
212 double GPSweeks;
213 QString prn;
214 in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
215 if ( messageType == COTYPE_GPSCOMBINED ||
[2207]216 messageType == COTYPE_GLONASSCOMBINED ||
217 messageType == COTYPE_GPSORBIT ||
218 messageType == COTYPE_GPSCLOCK ||
219 messageType == COTYPE_GLONASSORBIT ||
220 messageType == COTYPE_GLONASSCLOCK ) {
221
[2035]222 t_corr* cc = 0;
223 if (_corr.contains(prn)) {
224 cc = _corr.value(prn);
225 }
226 else {
227 cc = new t_corr();
228 _corr[prn] = cc;
229 }
[2207]230
[2035]231 cc->tt.set(GPSweek, GPSweeks);
[2207]232
233 if ( messageType == COTYPE_GPSCOMBINED ||
234 messageType == COTYPE_GLONASSCOMBINED ) {
235 cc->rao.ReSize(3);
236 in >> cc->iod >> cc->dClk >> cc->rao[0] >> cc->rao[1] >> cc->rao[2];
237 cc->dClk /= t_CST::c;
[2208]238 cc->raoSet = true;
239 cc->dClkSet = true;
[2207]240 }
241 else if ( messageType == COTYPE_GPSORBIT ||
242 messageType == COTYPE_GLONASSORBIT ) {
243 cc->rao.ReSize(3);
244 in >> cc->iod >> cc->rao[0] >> cc->rao[1] >> cc->rao[2];
[2208]245 cc->raoSet = true;
[2207]246 }
247 else if ( messageType == COTYPE_GPSCLOCK ||
248 messageType == COTYPE_GLONASSCLOCK ) {
249 int dummyIOD;
250 in >> dummyIOD >> cc->dClk;
251 cc->dClk /= t_CST::c;
[2208]252 cc->dClkSet = true;
[2207]253 }
[2035]254 }
255 }
[2208]256
257 QMutableMapIterator<QString, t_corr*> im(_corr);
258 while (im.hasNext()) {
259 im.next();
260 t_corr* cc = im.value();
261 if (!cc->ready()) {
262 delete cc;
263 im.remove();
264 }
265 }
[2035]266}
267
268// Satellite Position
269////////////////////////////////////////////////////////////////////////////
[2123]270t_irc bncPPPclient::getSatPos(const bncTime& tt, const QString& prn,
[2041]271 ColumnVector& xc, ColumnVector& vv, bool& corr) {
[2035]272
[2067]273 const bool CORR_REQUIRED = true;
274 const double MAXAGE = 120.0;
[2041]275
276 corr = false;
277
[2035]278 if (_eph.contains(prn)) {
[2040]279 t_eph* ee = _eph.value(prn);
280 ee->position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data());
281
[2068]282 if (CORR_REQUIRED) {
283 if (_corr.contains(prn)) {
284 t_corr* cc = _corr.value(prn);
285 if (ee->IOD() == cc->iod && (tt - cc->tt) < MAXAGE) {
286 corr = true;
287 applyCorr(cc, xc, vv);
288 return success;
289 }
[2041]290 }
[2068]291 return failure;
[2040]292 }
[2068]293
[2035]294 return success;
295 }
296
297 return failure;
298}
299
300//
301////////////////////////////////////////////////////////////////////////////
[2041]302void bncPPPclient::applyCorr(const t_corr* cc, ColumnVector& xc,
303 ColumnVector& vv) {
[2043]304 ColumnVector dx(3);
305 RSW_to_XYZ(xc.Rows(1,3), vv, cc->rao, dx);
[2041]306
[2107]307 xc[0] -= dx[0];
308 xc[1] -= dx[1];
309 xc[2] -= dx[2];
310 xc[3] -= cc->dClk;
[2068]311
312 // Relativistic Correction
313 // -----------------------
314 xc[3] -= 2.0 * DotProduct(xc.Rows(1,3),vv) / t_CST::c / t_CST::c ;
[2041]315}
316
[2049]317// Correct Time of Transmission
318////////////////////////////////////////////////////////////////////////////
319t_irc bncPPPclient::cmpToT(const QString& prn, t_satData* satData) {
320
[2051]321 double prange = satData->P3;
[2049]322 if (prange == 0.0) {
323 return failure;
324 }
325
326 double clkSat = 0.0;
327 for (int ii = 1; ii <= 10; ii++) {
328
[2123]329 bncTime ToT = _epoData->tt - prange / t_CST::c - clkSat;
[2049]330
331 ColumnVector xc(4);
332 ColumnVector vv(3);
333 bool corr = false;
334 if (getSatPos(ToT, prn, xc, vv, corr) != success) {
335 return failure;
336 }
337
338 double clkSatOld = clkSat;
[2050]339 clkSat = xc(4);
[2049]340
341 if ( fabs(clkSat-clkSatOld) * t_CST::c < 1.e-4 ) {
342 satData->xx = xc.Rows(1,3);
343 satData->vv = vv;
[2050]344 satData->clk = clkSat * t_CST::c;
[2049]345 satData->clkCorr = corr;
346 return success;
347 }
348 }
349
350 return failure;
351}
352
[2041]353//
354////////////////////////////////////////////////////////////////////////////
[2035]355void bncPPPclient::processEpoch() {
356
[2053]357 // Data Pre-Processing
358 // -------------------
359 QMutableMapIterator<QString, t_satData*> im(_epoData->satData);
360 while (im.hasNext()) {
361 im.next();
362 QString prn = im.key();
363 t_satData* satData = im.value();
[2049]364
365 if (cmpToT(prn, satData) != success) {
366 delete satData;
[2053]367 im.remove();
[2049]368 continue;
369 }
[2053]370 }
[2035]371
[2060]372 // Filter Solution
373 // ---------------
[2143]374 if (_model->update(_epoData) == success) {
[2145]375 emit newPosition(_model->time(), _model->x(), _model->y(), _model->z());
[2060]376 }
[2035]377}
[2049]378
Note: See TracBrowser for help on using the repository browser.