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

Last change on this file since 6184 was 6114, checked in by mervart, 10 years ago
File size: 10.2 KB
RevLine 
[6048]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 *
[6085]29 * Class: t_pppClient
[6048]30 *
[6083]31 * Purpose: Precise Point Positioning
[6048]32 *
33 * Author: L. Mervart
34 *
[6083]35 * Created: 21-Nov-2009
[6048]36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
[6083]41#include <newmatio.h>
[6048]42#include <iomanip>
[6083]43#include <sstream>
[6048]44
[6086]45#include "pppClient.h"
[6099]46#include "bncephuser.h"
[6083]47#include "bncutils.h"
[6048]48
49using namespace BNC_PPP;
50using namespace std;
51
52// Constructor
[6083]53////////////////////////////////////////////////////////////////////////////
[6099]54t_pppClient::t_pppClient(const t_pppOptions* opt) {
[6083]55
[6093]56 _opt = new t_pppOptions(*opt);
57 _filter = new t_pppFilter(this);
58 _epoData = new t_epoData();
59 _log = new ostringstream();
[6099]60 _ephUser = new bncEphUser(false);
[6048]61}
62
63// Destructor
[6083]64////////////////////////////////////////////////////////////////////////////
[6085]65t_pppClient::~t_pppClient() {
[6093]66 delete _filter;
[6083]67 delete _epoData;
[6048]68 delete _opt;
[6099]69 delete _ephUser;
[6087]70 delete _log;
[6048]71}
72
[6083]73//
74////////////////////////////////////////////////////////////////////////////
[6085]75void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
[6083]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 // ---------------
[6093]135 if (_filter->update(_epoData) == success) {
[6083]136 output->_error = false;
[6093]137 output->_epoTime = _filter->time();
138 output->_xyzRover[0] = _filter->x();
139 output->_xyzRover[1] = _filter->y();
140 output->_xyzRover[2] = _filter->z();
[6112]141 copy(&_filter->Q().data()[0], &_filter->Q().data()[6], output->_covMatrix);
[6114]142 output->_neu[0] = _filter->neu()[0];
143 output->_neu[1] = _filter->neu()[1];
144 output->_neu[2] = _filter->neu()[2];
145 output->_numSat = _filter->numSat();
146 output->_pDop = _filter->PDOP();
[6083]147 }
148 else {
149 output->_error = true;
150 }
151
[6098]152 output->_log = _log->str();
153 delete _log; _log = new ostringstream();
[6083]154}
155
156//
157////////////////////////////////////////////////////////////////////////////
[6085]158void t_pppClient::putNewObs(t_satData* satData) {
[6083]159
160 // Set Observations GPS and Glonass
161 // --------------------------------
162 if (satData->system() == 'G' || satData->system() == 'R') {
163 if (satData->P1 != 0.0 && satData->P2 != 0.0 &&
164 satData->L1 != 0.0 && satData->L2 != 0.0 ) {
165
166 int channel = 0;
167 if (satData->system() == 'R') {
[6099]168 const bncEphUser::t_ephPair* ephPair = _ephUser->ephPair(satData->prn);
169 if (ephPair) {
170 channel = ephPair->last->slotNum();
[6096]171 }
172 else {
173 delete satData;
174 return;
175 }
[6083]176 }
177
178 t_frequency::type fType1 = t_lc::toFreq(satData->system(), t_lc::l1);
179 t_frequency::type fType2 = t_lc::toFreq(satData->system(), t_lc::l2);
180 double f1 = t_CST::freq(fType1, channel);
181 double f2 = t_CST::freq(fType2, channel);
182 double a1 = f1 * f1 / (f1 * f1 - f2 * f2);
183 double a2 = - f2 * f2 / (f1 * f1 - f2 * f2);
184 satData->L1 = satData->L1 * t_CST::c / f1;
185 satData->L2 = satData->L2 * t_CST::c / f2;
186 satData->P3 = a1 * satData->P1 + a2 * satData->P2;
187 satData->L3 = a1 * satData->L1 + a2 * satData->L2;
188 satData->lambda3 = a1 * t_CST::c / f1 + a2 * t_CST::c / f2;
189 _epoData->satData[satData->prn] = satData;
190 }
191 else {
192 delete satData;
193 }
194 }
195
196 // Set Observations Galileo
197 // ------------------------
198 else if (satData->system() == 'E') {
199 if (satData->P1 != 0.0 && satData->P5 != 0.0 &&
200 satData->L1 != 0.0 && satData->L5 != 0.0 ) {
201 double f1 = t_CST::freq(t_frequency::E1, 0);
202 double f5 = t_CST::freq(t_frequency::E5, 0);
203 double a1 = f1 * f1 / (f1 * f1 - f5 * f5);
204 double a5 = - f5 * f5 / (f1 * f1 - f5 * f5);
205 satData->L1 = satData->L1 * t_CST::c / f1;
206 satData->L5 = satData->L5 * t_CST::c / f5;
207 satData->P3 = a1 * satData->P1 + a5 * satData->P5;
208 satData->L3 = a1 * satData->L1 + a5 * satData->L5;
209 satData->lambda3 = a1 * t_CST::c / f1 + a5 * t_CST::c / f5;
210 _epoData->satData[satData->prn] = satData;
211 }
212 else {
213 delete satData;
214 }
215 }
216}
217
[6048]218//
[6083]219////////////////////////////////////////////////////////////////////////////
[6085]220void t_pppClient::putOrbCorrections(const std::vector<t_orbCorr*>& corr) {
[6097]221 for (unsigned ii = 0; ii < corr.size(); ii++) {
222 QString prn = QString(corr[ii]->_prn.toString().c_str());
[6099]223 const bncEphUser::t_ephPair* ephPair = _ephUser->ephPair(prn);
224 if (ephPair) {
225 t_eph* eLast = ephPair->last;
226 t_eph* ePrev = ephPair->prev;
[6097]227 if (eLast && eLast->IOD() == corr[ii]->_iod) {
228 eLast->setOrbCorr(corr[ii]);
229 }
230 else if (ePrev && ePrev->IOD() == corr[ii]->_iod) {
231 ePrev->setOrbCorr(corr[ii]);
232 }
233 }
234 }
[6083]235}
236
237//
238////////////////////////////////////////////////////////////////////////////
[6085]239void t_pppClient::putClkCorrections(const std::vector<t_clkCorr*>& corr) {
[6097]240 for (unsigned ii = 0; ii < corr.size(); ii++) {
241 QString prn = QString(corr[ii]->_prn.toString().c_str());
[6099]242 const bncEphUser::t_ephPair* ephPair = _ephUser->ephPair(prn);
243 if (ephPair) {
244 t_eph* eLast = ephPair->last;
245 t_eph* ePrev = ephPair->prev;
[6097]246 if (eLast && eLast->IOD() == corr[ii]->_iod) {
247 eLast->setClkCorr(corr[ii]);
248 }
249 else if (ePrev && ePrev->IOD() == corr[ii]->_iod) {
250 ePrev->setClkCorr(corr[ii]);
251 }
252 }
253 }
[6083]254}
255
256//
[6048]257//////////////////////////////////////////////////////////////////////////////
[6086]258void t_pppClient::putBiases(const std::vector<t_satBias*>& /* satBias */) {
259}
260
261//
262//////////////////////////////////////////////////////////////////////////////
[6048]263void t_pppClient::putEphemeris(const t_eph* eph) {
[6069]264 const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
265 const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
266 const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
267 if (ephGPS) {
[6099]268 _ephUser->putNewEph(new t_ephGPS(*ephGPS));
[6069]269 }
270 else if (ephGlo) {
[6099]271 _ephUser->putNewEph(new t_ephGlo(*ephGlo));
[6069]272 }
273 else if (ephGal) {
[6099]274 _ephUser->putNewEph(new t_ephGal(*ephGal));
[6069]275 }
[6048]276}
277
[6083]278// Satellite Position
279////////////////////////////////////////////////////////////////////////////
[6085]280t_irc t_pppClient::getSatPos(const bncTime& tt, const QString& prn,
[6083]281 ColumnVector& xc, ColumnVector& vv) {
[6099]282
283 const bncEphUser::t_ephPair* ephPair = _ephUser->ephPair(prn);
284 if (ephPair) {
285 t_eph* eLast = ephPair->last;
286 t_eph* ePrev = ephPair->prev;
[6083]287 if (eLast && eLast->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
288 return success;
289 }
290 else if (ePrev && ePrev->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
291 return success;
292 }
293 }
294 return failure;
[6048]295}
296
[6083]297// Correct Time of Transmission
298////////////////////////////////////////////////////////////////////////////
[6085]299t_irc t_pppClient::cmpToT(t_satData* satData) {
[6048]300
[6083]301 double prange = satData->P3;
302 if (prange == 0.0) {
303 return failure;
304 }
[6048]305
[6083]306 double clkSat = 0.0;
307 for (int ii = 1; ii <= 10; ii++) {
308
309 bncTime ToT = satData->tt - prange / t_CST::c - clkSat;
310
311 ColumnVector xc(4);
312 ColumnVector vv(3);
313 if (getSatPos(ToT, satData->prn, xc, vv) != success) {
314 return failure;
315 }
316
317 double clkSatOld = clkSat;
318 clkSat = xc(4);
319
320 if ( fabs(clkSat-clkSatOld) * t_CST::c < 1.e-4 ) {
321 satData->xx = xc.Rows(1,3);
322 satData->vv = vv;
323 satData->clk = clkSat * t_CST::c;
324 return success;
325 }
326 }
327
328 return failure;
[6048]329}
330
Note: See TracBrowser for help on using the repository browser.