source: ntrip/trunk/BNC/src/PPP_free/pppClient.cpp@ 6100

Last change on this file since 6100 was 6100, checked in by mervart, 10 years ago
File size: 10.0 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: t_pppClient
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 <newmatio.h>
42#include <iomanip>
43#include <sstream>
44
45#include "pppClient.h"
46#include "bncephuser.h"
47#include "bncutils.h"
48
49using namespace BNC_PPP;
50using namespace std;
51
52// Constructor
53////////////////////////////////////////////////////////////////////////////
54t_pppClient::t_pppClient(const t_pppOptions* opt) {
55
56 _opt = new t_pppOptions(*opt);
57 _filter = new t_pppFilter(this);
58 _epoData = new t_epoData();
59 _log = new ostringstream();
60 _ephUser = new bncEphUser(false);
61}
62
63// Destructor
64////////////////////////////////////////////////////////////////////////////
65t_pppClient::~t_pppClient() {
66 delete _filter;
67 delete _epoData;
68 delete _opt;
69 delete _ephUser;
70 delete _log;
71}
72
73//
74////////////////////////////////////////////////////////////////////////////
75void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
76
77 // Convert and store observations
78 // ------------------------------
79 _epoData->clear();
80 for (unsigned ii = 0; ii < satObs.size(); ii++) {
81 const t_satObs* obs = satObs[ii];
82 t_satData* satData = new t_satData();
83
84 if (_epoData->tt.undef()) {
85 _epoData->tt = obs->_time;
86 }
87
88 satData->tt = obs->_time;
89 satData->prn = QString(obs->_prn.toString().c_str());
90 satData->slipFlag = false;
91 satData->P1 = 0.0;
92 satData->P2 = 0.0;
93 satData->P5 = 0.0;
94 satData->L1 = 0.0;
95 satData->L2 = 0.0;
96 satData->L5 = 0.0;
97 for (unsigned ifrq = 0; ifrq < obs->_obs.size(); ifrq++) {
98 t_frqObs* frqObs = obs->_obs[ifrq];
99 if (frqObs->_rnxType2ch[0] == '1') {
100 if (frqObs->_codeValid) satData->P1 = frqObs->_code;
101 if (frqObs->_phaseValid) satData->L1 = frqObs->_phase;
102 if (frqObs->_slip) satData->slipFlag = true;
103 }
104 else if (frqObs->_rnxType2ch[0] == '2') {
105 if (frqObs->_codeValid) satData->P2 = frqObs->_code;
106 if (frqObs->_phaseValid) satData->L2 = frqObs->_phase;
107 if (frqObs->_slip) satData->slipFlag = true;
108 }
109 else if (frqObs->_rnxType2ch[0] == '5') {
110 if (frqObs->_codeValid) satData->P5 = frqObs->_code;
111 if (frqObs->_phaseValid) satData->L5 = frqObs->_phase;
112 if (frqObs->_slip) satData->slipFlag = true;
113 }
114 }
115 putNewObs(satData);
116 }
117
118 // Data Pre-Processing
119 // -------------------
120 QMutableMapIterator<QString, t_satData*> it(_epoData->satData);
121 while (it.hasNext()) {
122 it.next();
123 QString prn = it.key();
124 t_satData* satData = it.value();
125
126 if (cmpToT(satData) != success) {
127 delete satData;
128 it.remove();
129 continue;
130 }
131 }
132
133 // Filter Solution
134 // ---------------
135 if (_filter->update(_epoData) == success) {
136 output->_error = false;
137 output->_epoTime = _filter->time();
138 output->_xyzRover[0] = _filter->x();
139 output->_xyzRover[1] = _filter->y();
140 output->_xyzRover[2] = _filter->z();
141 output->_numSat = 0;
142 output->_pDop = 0.0;
143 }
144 else {
145 output->_error = true;
146 }
147
148 output->_log = _log->str();
149 delete _log; _log = new ostringstream();
150}
151
152//
153////////////////////////////////////////////////////////////////////////////
154void t_pppClient::putNewObs(t_satData* satData) {
155
156 // Set Observations GPS and Glonass
157 // --------------------------------
158 if (satData->system() == 'G' || satData->system() == 'R') {
159 if (satData->P1 != 0.0 && satData->P2 != 0.0 &&
160 satData->L1 != 0.0 && satData->L2 != 0.0 ) {
161
162 int channel = 0;
163 if (satData->system() == 'R') {
164 const bncEphUser::t_ephPair* ephPair = _ephUser->ephPair(satData->prn);
165 if (ephPair) {
166 channel = ephPair->last->slotNum();
167 }
168 else {
169 delete satData;
170 return;
171 }
172 }
173
174 t_frequency::type fType1 = t_lc::toFreq(satData->system(), t_lc::l1);
175 t_frequency::type fType2 = t_lc::toFreq(satData->system(), t_lc::l2);
176 double f1 = t_CST::freq(fType1, channel);
177 double f2 = t_CST::freq(fType2, channel);
178 double a1 = f1 * f1 / (f1 * f1 - f2 * f2);
179 double a2 = - f2 * f2 / (f1 * f1 - f2 * f2);
180 satData->L1 = satData->L1 * t_CST::c / f1;
181 satData->L2 = satData->L2 * t_CST::c / f2;
182 satData->P3 = a1 * satData->P1 + a2 * satData->P2;
183 satData->L3 = a1 * satData->L1 + a2 * satData->L2;
184 satData->lambda3 = a1 * t_CST::c / f1 + a2 * t_CST::c / f2;
185 _epoData->satData[satData->prn] = satData;
186 }
187 else {
188 delete satData;
189 }
190 }
191
192 // Set Observations Galileo
193 // ------------------------
194 else if (satData->system() == 'E') {
195 if (satData->P1 != 0.0 && satData->P5 != 0.0 &&
196 satData->L1 != 0.0 && satData->L5 != 0.0 ) {
197 double f1 = t_CST::freq(t_frequency::E1, 0);
198 double f5 = t_CST::freq(t_frequency::E5, 0);
199 double a1 = f1 * f1 / (f1 * f1 - f5 * f5);
200 double a5 = - f5 * f5 / (f1 * f1 - f5 * f5);
201 satData->L1 = satData->L1 * t_CST::c / f1;
202 satData->L5 = satData->L5 * t_CST::c / f5;
203 satData->P3 = a1 * satData->P1 + a5 * satData->P5;
204 satData->L3 = a1 * satData->L1 + a5 * satData->L5;
205 satData->lambda3 = a1 * t_CST::c / f1 + a5 * t_CST::c / f5;
206 _epoData->satData[satData->prn] = satData;
207 }
208 else {
209 delete satData;
210 }
211 }
212}
213
214//
215////////////////////////////////////////////////////////////////////////////
216void t_pppClient::putOrbCorrections(const std::vector<t_orbCorr*>& corr) {
217 for (unsigned ii = 0; ii < corr.size(); ii++) {
218 QString prn = QString(corr[ii]->_prn.toString().c_str());
219 const bncEphUser::t_ephPair* ephPair = _ephUser->ephPair(prn);
220 if (ephPair) {
221 t_eph* eLast = ephPair->last;
222 t_eph* ePrev = ephPair->prev;
223 if (eLast && eLast->IOD() == corr[ii]->_iod) {
224 eLast->setOrbCorr(corr[ii]);
225 }
226 else if (ePrev && ePrev->IOD() == corr[ii]->_iod) {
227 ePrev->setOrbCorr(corr[ii]);
228 }
229 }
230 }
231}
232
233//
234////////////////////////////////////////////////////////////////////////////
235void t_pppClient::putClkCorrections(const std::vector<t_clkCorr*>& corr) {
236 for (unsigned ii = 0; ii < corr.size(); ii++) {
237 QString prn = QString(corr[ii]->_prn.toString().c_str());
238 const bncEphUser::t_ephPair* ephPair = _ephUser->ephPair(prn);
239 if (ephPair) {
240 t_eph* eLast = ephPair->last;
241 t_eph* ePrev = ephPair->prev;
242 if (eLast && eLast->IOD() == corr[ii]->_iod) {
243 eLast->setClkCorr(corr[ii]);
244 }
245 else if (ePrev && ePrev->IOD() == corr[ii]->_iod) {
246 ePrev->setClkCorr(corr[ii]);
247 }
248 }
249 }
250}
251
252//
253//////////////////////////////////////////////////////////////////////////////
254void t_pppClient::putBiases(const std::vector<t_satBias*>& /* satBias */) {
255}
256
257//
258//////////////////////////////////////////////////////////////////////////////
259void t_pppClient::putEphemeris(const t_eph* eph) {
260 const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
261 const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
262 const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
263 if (ephGPS) {
264 _ephUser->putNewEph(new t_ephGPS(*ephGPS));
265 }
266 else if (ephGlo) {
267 _ephUser->putNewEph(new t_ephGlo(*ephGlo));
268 }
269 else if (ephGal) {
270 _ephUser->putNewEph(new t_ephGal(*ephGal));
271 }
272}
273
274// Satellite Position
275////////////////////////////////////////////////////////////////////////////
276t_irc t_pppClient::getSatPos(const bncTime& tt, const QString& prn,
277 ColumnVector& xc, ColumnVector& vv) {
278
279 const bncEphUser::t_ephPair* ephPair = _ephUser->ephPair(prn);
280 if (ephPair) {
281 t_eph* eLast = ephPair->last;
282 t_eph* ePrev = ephPair->prev;
283 if (eLast && eLast->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
284 return success;
285 }
286 else if (ePrev && ePrev->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
287 return success;
288 }
289 }
290 return failure;
291}
292
293// Correct Time of Transmission
294////////////////////////////////////////////////////////////////////////////
295t_irc t_pppClient::cmpToT(t_satData* satData) {
296
297 double prange = satData->P3;
298 if (prange == 0.0) {
299 return failure;
300 }
301
302 double clkSat = 0.0;
303 for (int ii = 1; ii <= 10; ii++) {
304
305 bncTime ToT = satData->tt - prange / t_CST::c - clkSat;
306
307 ColumnVector xc(4);
308 ColumnVector vv(3);
309 if (getSatPos(ToT, satData->prn, xc, vv) != success) {
310 return failure;
311 }
312
313 double clkSatOld = clkSat;
314 clkSat = xc(4);
315
316 if ( fabs(clkSat-clkSatOld) * t_CST::c < 1.e-4 ) {
317 satData->xx = xc.Rows(1,3);
318 satData->vv = vv;
319 satData->clk = clkSat * t_CST::c;
320 return success;
321 }
322 }
323
324 return failure;
325}
326
Note: See TracBrowser for help on using the repository browser.