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

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

* empty log message *

File size: 7.1 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 t_obsInternal* obs = &(pp->_o);
83
84 t_time tt(obs->GPSWeek, obs->GPSWeeks);
85
86 if (!_epoData) {
87 _epoData = new t_epoData();
88 _epoData->tt = tt;
89 }
90 else if (tt != _epoData->tt) {
91 processEpoch();
92 delete _epoData;
93 _epoData = new t_epoData();
94 _epoData->tt = tt;
95 }
96
97 t_satData* satData = new t_satData();
98
99 satData->C1 = obs->C1;
100 satData->C2 = obs->C2;
101 satData->P1 = obs->P1;
102 satData->P2 = obs->P2;
103 satData->L1 = obs->L1;
104 satData->L2 = obs->L2;
105
106 QString prn =
107 QString("%1%2").arg(obs->satSys).arg(obs->satNum, 2, 10, QChar('0'));
108
109 _epoData->satData[prn] = satData;
110}
111
112//
113////////////////////////////////////////////////////////////////////////////
114void bncPPPclient::slotNewEphGPS(gpsephemeris gpseph) {
115 QMutexLocker locker(&_mutex);
116
117 QString prn = QString("G%1").arg(gpseph.satellite, 2, 10, QChar('0'));
118
119 if (_eph.contains(prn)) {
120 t_ephGPS* ee = static_cast<t_ephGPS*>(_eph.value(prn));
121 if ( (ee->GPSweek() < gpseph.GPSweek) ||
122 (ee->GPSweek() == gpseph.GPSweek &&
123 ee->TOC() < gpseph.TOC) ) {
124 ee->set(&gpseph);
125 }
126 }
127 else {
128 t_ephGPS* ee = new t_ephGPS();
129 ee->set(&gpseph);
130 _eph[prn] = ee;
131 }
132}
133
134//
135////////////////////////////////////////////////////////////////////////////
136void bncPPPclient::slotNewCorrections(QList<QString> corrList) {
137 QMutexLocker locker(&_mutex);
138 QListIterator<QString> it(corrList);
139 while (it.hasNext()) {
140 QTextStream in(it.next().toAscii());
141 int messageType;
142 int updateInterval;
143 int GPSweek;
144 double GPSweeks;
145 QString prn;
146 in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
147 if ( messageType == COTYPE_GPSCOMBINED ||
148 messageType == COTYPE_GLONASSCOMBINED ) {
149 t_corr* cc = 0;
150 if (_corr.contains(prn)) {
151 cc = _corr.value(prn);
152 }
153 else {
154 cc = new t_corr();
155 _corr[prn] = cc;
156 }
157 cc->tt.set(GPSweek, GPSweeks);
158 cc->rao.ReSize(3);
159 in >> cc->iod >> cc->dClk >> cc->rao[0] >> cc->rao[1] >> cc->rao[2];
160 cc->dClk /= t_CST::c;
161 }
162 }
163}
164
165// Satellite Position
166////////////////////////////////////////////////////////////////////////////
167t_irc bncPPPclient::getSatPos(const t_time& tt, const QString& prn,
168 ColumnVector& xc, ColumnVector& vv, bool& corr) {
169
170 const double MAXAGE = 120.0;
171
172 corr = false;
173
174 if (_eph.contains(prn)) {
175 t_eph* ee = _eph.value(prn);
176 ee->position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data());
177
178 if (_corr.contains(prn)) {
179 t_corr* cc = _corr.value(prn);
180 if (ee->IOD() == cc->iod && (tt - cc->tt) < MAXAGE) {
181 corr = true;
182 applyCorr(cc, xc, vv);
183 }
184 }
185
186 return success;
187 }
188
189 return failure;
190}
191
192//
193////////////////////////////////////////////////////////////////////////////
194void bncPPPclient::applyCorr(const t_corr* cc, ColumnVector& xc,
195 ColumnVector& vv) {
196 ColumnVector dx(3);
197 RSW_to_XYZ(xc.Rows(1,3), vv, cc->rao, dx);
198
199 xc[0] += dx[0];
200 xc[1] += dx[1];
201 xc[2] += dx[2];
202 xc[3] += cc->dClk;
203}
204
205// Correct Time of Transmission
206////////////////////////////////////////////////////////////////////////////
207t_irc bncPPPclient::cmpToT(const QString& prn, t_satData* satData) {
208
209 double prange = satData->C1;
210 if (prange == 0.0) {
211 prange = satData->P1;
212 }
213 if (prange == 0.0) {
214 return failure;
215 }
216
217 double clkSat = 0.0;
218 for (int ii = 1; ii <= 10; ii++) {
219
220 t_time ToT = _epoData->tt - prange / t_CST::c - clkSat;
221
222 ColumnVector xc(4);
223 ColumnVector vv(3);
224 bool corr = false;
225 if (getSatPos(ToT, prn, xc, vv, corr) != success) {
226 return failure;
227 }
228
229 double clkSatOld = clkSat;
230 clkSat = xc(4);
231
232 if ( fabs(clkSat-clkSatOld) * t_CST::c < 1.e-4 ) {
233 satData->xx = xc.Rows(1,3);
234 satData->vv = vv;
235 satData->clk = clkSat * t_CST::c;
236 satData->clkCorr = corr;
237 return success;
238 }
239 }
240
241 return failure;
242}
243
244//
245////////////////////////////////////////////////////////////////////////////
246void bncPPPclient::processEpoch() {
247
248 cout.setf(ios::fixed);
249
250 QMutableMapIterator<QString, t_satData*> it(_epoData->satData);
251
252 while (it.hasNext()) {
253 it.next();
254 QString prn = it.key();
255 t_satData* satData = it.value();
256
257 if (cmpToT(prn, satData) != success) {
258 delete satData;
259 it.remove();
260 continue;
261 }
262
263 cout << _epoData->tt.timestr(1) << " " << prn.toAscii().data() << " "
264 << setw(14) << setprecision(3) << satData->xx(1) << " "
265 << setw(14) << setprecision(3) << satData->xx(2) << " "
266 << setw(14) << setprecision(3) << satData->xx(3) << " "
267 << setw(12) << setprecision(3) << satData->clk;
268
269 if (satData->clkCorr) {
270 cout << endl;
271 }
272 else {
273 cout << " !\n";
274 }
275 }
276
277 cout << endl;
278 cout.flush();
279}
280
Note: See TracBrowser for help on using the repository browser.