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

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