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

Last change on this file since 6086 was 6086, checked in by mervart, 10 years ago
File size: 9.2 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 "pppOptions.h"
47#include "bncutils.h"
48#include "bncconst.h"
49#include "bncmodel.h"
50
51using namespace BNC_PPP;
52using namespace std;
53
54// Global variable holding thread-specific pointers
55//////////////////////////////////////////////////////////////////////////////
56t_pppClient* PPP_CLIENT = 0;
57
58// Static function returning thread-specific pointer
59//////////////////////////////////////////////////////////////////////////////
60t_pppClient* t_pppClient::instance() {
61 return PPP_CLIENT;
62}
63
64// Constructor
65////////////////////////////////////////////////////////////////////////////
66t_pppClient::t_pppClient(const t_pppOptions* opt) : bncEphUser(false) {
67
68 _opt = new t_pppOptions(*opt);
69 _model = new bncModel(this);
70 _epoData = new t_epoData();
71 _staID = QByteArray(_opt->_roverName.c_str());
72 PPP_CLIENT = this;
73}
74
75// Destructor
76////////////////////////////////////////////////////////////////////////////
77t_pppClient::~t_pppClient() {
78 delete _model;
79 delete _epoData;
80 delete _opt;
81}
82
83//
84////////////////////////////////////////////////////////////////////////////
85void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
86 QMutexLocker locker(&_mutex);
87
88 // Convert and store observations
89 // ------------------------------
90 _epoData->clear();
91 for (unsigned ii = 0; ii < satObs.size(); ii++) {
92 const t_satObs* obs = satObs[ii];
93 t_satData* satData = new t_satData();
94
95 if (_epoData->tt.undef()) {
96 _epoData->tt = obs->_time;
97 }
98
99 satData->tt = obs->_time;
100 satData->prn = QString(obs->_prn.toString().c_str());
101 satData->slipFlag = false;
102 satData->P1 = 0.0;
103 satData->P2 = 0.0;
104 satData->P5 = 0.0;
105 satData->L1 = 0.0;
106 satData->L2 = 0.0;
107 satData->L5 = 0.0;
108 for (unsigned ifrq = 0; ifrq < obs->_obs.size(); ifrq++) {
109 t_frqObs* frqObs = obs->_obs[ifrq];
110 if (frqObs->_rnxType2ch[0] == '1') {
111 if (frqObs->_codeValid) satData->P1 = frqObs->_code;
112 if (frqObs->_phaseValid) satData->L1 = frqObs->_phase;
113 if (frqObs->_slip) satData->slipFlag = true;
114 }
115 else if (frqObs->_rnxType2ch[0] == '2') {
116 if (frqObs->_codeValid) satData->P2 = frqObs->_code;
117 if (frqObs->_phaseValid) satData->L2 = frqObs->_phase;
118 if (frqObs->_slip) satData->slipFlag = true;
119 }
120 else if (frqObs->_rnxType2ch[0] == '5') {
121 if (frqObs->_codeValid) satData->P5 = frqObs->_code;
122 if (frqObs->_phaseValid) satData->L5 = frqObs->_phase;
123 if (frqObs->_slip) satData->slipFlag = true;
124 }
125 }
126 putNewObs(satData);
127 }
128
129 // Data Pre-Processing
130 // -------------------
131 QMutableMapIterator<QString, t_satData*> it(_epoData->satData);
132 while (it.hasNext()) {
133 it.next();
134 QString prn = it.key();
135 t_satData* satData = it.value();
136
137 if (cmpToT(satData) != success) {
138 delete satData;
139 it.remove();
140 continue;
141 }
142 }
143
144 // Filter Solution
145 // ---------------
146 if (_model->update(_epoData) == success) {
147 output->_error = false;
148 output->_epoTime = _model->time();
149 output->_xyzRover[0] = _model->x();
150 output->_xyzRover[1] = _model->y();
151 output->_xyzRover[2] = _model->z();
152 output->_numSat = 0;
153 output->_pDop = 0.0;
154 }
155 else {
156 output->_error = true;
157 }
158
159 output->_log = LOG.str();
160}
161
162//
163////////////////////////////////////////////////////////////////////////////
164void t_pppClient::putNewObs(t_satData* satData) {
165
166 // Set Observations GPS and Glonass
167 // --------------------------------
168 if (satData->system() == 'G' || satData->system() == 'R') {
169 if (satData->P1 != 0.0 && satData->P2 != 0.0 &&
170 satData->L1 != 0.0 && satData->L2 != 0.0 ) {
171
172 int channel = 0;
173 if (satData->system() == 'R') {
174// cerr << "not yet implemented" << endl;
175// exit(0);
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
218//
219////////////////////////////////////////////////////////////////////////////
220void t_pppClient::putOrbCorrections(const std::vector<t_orbCorr*>& corr) {
221 QMutexLocker locker(&_mutex);
222}
223
224//
225////////////////////////////////////////////////////////////////////////////
226void t_pppClient::putClkCorrections(const std::vector<t_clkCorr*>& corr) {
227 QMutexLocker locker(&_mutex);
228}
229
230//
231//////////////////////////////////////////////////////////////////////////////
232void t_pppClient::putBiases(const std::vector<t_satBias*>& /* satBias */) {
233}
234
235//
236//////////////////////////////////////////////////////////////////////////////
237void t_pppClient::putEphemeris(const t_eph* eph) {
238 const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
239 const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
240 const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
241 if (ephGPS) {
242 putNewEph(new t_ephGPS(*ephGPS));
243 }
244 else if (ephGlo) {
245 putNewEph(new t_ephGlo(*ephGlo));
246 }
247 else if (ephGal) {
248 putNewEph(new t_ephGal(*ephGal));
249 }
250}
251
252// Satellite Position
253////////////////////////////////////////////////////////////////////////////
254t_irc t_pppClient::getSatPos(const bncTime& tt, const QString& prn,
255 ColumnVector& xc, ColumnVector& vv) {
256 if (_eph.contains(prn)) {
257 t_eph* eLast = _eph.value(prn)->last;
258 t_eph* ePrev = _eph.value(prn)->prev;
259 if (eLast && eLast->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
260 return success;
261 }
262 else if (ePrev && ePrev->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
263 return success;
264 }
265 }
266 return failure;
267}
268
269// Correct Time of Transmission
270////////////////////////////////////////////////////////////////////////////
271t_irc t_pppClient::cmpToT(t_satData* satData) {
272
273 double prange = satData->P3;
274 if (prange == 0.0) {
275 return failure;
276 }
277
278 double clkSat = 0.0;
279 for (int ii = 1; ii <= 10; ii++) {
280
281 bncTime ToT = satData->tt - prange / t_CST::c - clkSat;
282
283 ColumnVector xc(4);
284 ColumnVector vv(3);
285 if (getSatPos(ToT, satData->prn, xc, vv) != success) {
286 return failure;
287 }
288
289 double clkSatOld = clkSat;
290 clkSat = xc(4);
291
292 if ( fabs(clkSat-clkSatOld) * t_CST::c < 1.e-4 ) {
293 satData->xx = xc.Rows(1,3);
294 satData->vv = vv;
295 satData->clk = clkSat * t_CST::c;
296 return success;
297 }
298 }
299
300 return failure;
301}
302
Note: See TracBrowser for help on using the repository browser.