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

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

* empty log message *

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