source: ntrip/trunk/BNC/src/PPP/pppRunRealTime.cpp@ 5879

Last change on this file since 5879 was 5879, checked in by mervart, 10 years ago
File size: 10.2 KB
Line 
1
2// Part of BNC, a utility for retrieving decoding and
3// converting GNSS data streams from NTRIP broadcasters.
4//
5// Copyright (C) 2007
6// German Federal Agency for Cartography and Geodesy (BKG)
7// http://www.bkg.bund.de
8// Czech Technical University Prague, Department of Geodesy
9// http://www.fsv.cvut.cz
10//
11// Email: euref-ip@bkg.bund.de
12//
13// This program is free software; you can redistribute it and/or
14// modify it under the terms of the GNU General Public License
15// as published by the Free Software Foundation, version 2.
16//
17// This program is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU General Public License for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with this program; if not, write to the Free Software
24// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26/* -------------------------------------------------------------------------
27 * BKG NTRIP Client
28 * -------------------------------------------------------------------------
29 *
30 * Class: t_pppRunRealTime
31 *
32 * Purpose: Single Real-Time PPP Client
33 *
34 * Author: L. Mervart
35 *
36 * Created: 29-Jul-2014
37 *
38 * Changes:
39 *
40 * -----------------------------------------------------------------------*/
41
42
43#include <iostream>
44#include <iomanip>
45#include <string.h>
46#include <map>
47
48#include "pppRunRealTime.h"
49#include "bnccore.h"
50#include "bncephuser.h"
51
52using namespace BNC_PPP;
53using namespace std;
54
55// Constructor
56////////////////////////////////////////////////////////////////////////////
57t_pppRunRealTime::t_pppRunRealTime(const t_pppOptions* opt) {
58 _opt = opt;
59 connect(this, SIGNAL(newMessage(QByteArray,bool)),
60 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
61 if (_opt->_realTime) {
62 connect(BNC_CORE->caster(), SIGNAL(newObs(QByteArray, QList<t_obs>)),
63 this, SLOT(slotNewObs(QByteArray, QList<t_obs>)));
64
65 connect(BNC_CORE, SIGNAL(newEphGPS(gpsephemeris)),
66 this, SLOT(slotNewEphGPS(gpsephemeris)));
67
68 connect(BNC_CORE, SIGNAL(newEphGlonass(glonassephemeris)),
69 this, SLOT(slotNewEphGlonass(glonassephemeris)));
70
71 connect(BNC_CORE, SIGNAL(newEphGalileo(galileoephemeris)),
72 this, SLOT(slotNewEphGalileo(galileoephemeris)));
73
74 connect(BNC_CORE, SIGNAL(newCorrections(QStringList)),
75 this, SLOT(slotNewCorrections(QStringList)));
76
77 connect(this, SIGNAL(newPosition(bncTime, QVector<double>)),
78 BNC_CORE, SIGNAL(newPosition(bncTime, QVector<double>)));
79
80 for (unsigned iPrn = 0; iPrn <= t_prn::MAXPRN; iPrn++) {
81 _lastOrbCorrIOD[iPrn] = -1;
82 _lastClkCorrValue[iPrn] = 0.0;
83 }
84
85 _pppClient = new t_pppClient(_opt);
86 }
87 else {
88 throw t_except("t_pppRunRealTime: post-processing not yet implemented");
89 }
90}
91
92// Destructor
93////////////////////////////////////////////////////////////////////////////
94t_pppRunRealTime::~t_pppRunRealTime() {
95}
96
97//
98////////////////////////////////////////////////////////////////////////////
99void t_pppRunRealTime::slotNewEphGPS(gpsephemeris gpseph) {
100 QMutexLocker locker(&_mutex);
101 t_ephGPS eph;
102 eph.set(&gpseph);
103 _pppClient->putEphemeris(&eph);
104}
105
106//
107////////////////////////////////////////////////////////////////////////////
108void t_pppRunRealTime::slotNewEphGlonass(glonassephemeris gloeph) {
109 QMutexLocker locker(&_mutex);
110 t_ephGlo eph;
111 eph.set(&gloeph);
112 _pppClient->putEphemeris(&eph);
113}
114
115//
116////////////////////////////////////////////////////////////////////////////
117void t_pppRunRealTime::slotNewEphGalileo(galileoephemeris galeph) {
118 QMutexLocker locker(&_mutex);
119 t_ephGal eph;
120 eph.set(&galeph);
121 _pppClient->putEphemeris(&eph);
122}
123
124//
125////////////////////////////////////////////////////////////////////////////
126void t_pppRunRealTime::slotNewObs(QByteArray staID, QList<t_obs> obsList) {
127 QMutexLocker locker(&_mutex);
128
129 if (string(staID.data()) != _opt->_roverName) {
130 return;
131 }
132
133 // Loop over all obsevations (possible different epochs)
134 // -----------------------------------------------------
135 QListIterator<t_obs> it(obsList);
136 while (it.hasNext()) {
137 const t_obs& oldObs = it.next();
138 t_satObs* newObs = new t_satObs;
139
140 newObs->_prn.set(oldObs.satSys, oldObs.satNum);
141 newObs->_time.set(oldObs.GPSWeek, oldObs.GPSWeeks);
142
143 // Find the corresponding data epoch or create a new one
144 // -----------------------------------------------------
145 t_epoData* epoch = 0;
146 deque<t_epoData*>::const_iterator it;
147 for (it = _epoData.begin(); it != _epoData.end(); it++) {
148 if (newObs->_time == (*it)->_time) {
149 epoch = *it;
150 break;
151 }
152 }
153 if (epoch == 0) {
154 if (_epoData.empty() || newObs->_time > _epoData.back()->_time) {
155 epoch = new t_epoData;
156 epoch->_time = newObs->_time;
157 _epoData.push_back(epoch);
158 }
159 }
160
161 // Fill the new observation and add it to the corresponding epoch
162 // --------------------------------------------------------------
163 if (epoch != 0) {
164 epoch->_satObs.push_back(newObs);
165 map<string, t_frqObs*> frqObsMap;
166 for (unsigned iEntry = 0; iEntry < GNSSENTRY_NUMBER; iEntry++) {
167 string hlp(oldObs.rnxStr(iEntry).toAscii().data());
168 if (hlp.length() == 3) {
169 char obsType = hlp[0];
170 string rnxType2ch = hlp.substr(1);
171 if (obsType == 'C' || obsType == 'L') {
172 t_frqObs* frqObs = 0;
173 if (frqObsMap.find(rnxType2ch) == frqObsMap.end()) {
174 frqObs = new t_frqObs();
175 frqObsMap[rnxType2ch] = frqObs;
176 frqObs->_rnxType2ch = rnxType2ch;
177 newObs->_obs.push_back(frqObs);
178 }
179 else {
180 frqObs = frqObsMap[rnxType2ch];
181 }
182 if (obsType == 'C') {
183 frqObs->_code = oldObs._measdata[iEntry];
184 frqObs->_codeValid = true;
185 }
186 else if (obsType == 'L') {
187 frqObs->_phase = oldObs._measdata[iEntry];
188 frqObs->_phaseValid = true;
189 }
190 }
191 }
192 }
193 }
194 }
195
196 // Process the oldest epochs
197 // ------------------------
198 while (_epoData.size() && _epoData.front()->_time < _lastClkCorrTime + 10.0) {
199
200 const vector<t_satObs*>& satObs = _epoData.front()->_satObs;
201
202 t_output output;
203 _pppClient->processEpoch(satObs, &output);
204
205 if (!output._error && _opt->xyzAprRoverSet()) {
206 QVector<double> xx(6);
207 xx.data()[0] = output._xyzRover[0];
208 xx.data()[1] = output._xyzRover[1];
209 xx.data()[2] = output._xyzRover[2];
210 xx.data()[3] = output._neu[0];
211 xx.data()[4] = output._neu[1];
212 xx.data()[5] = output._neu[2];
213 emit newPosition(output._epoTime, xx);
214 }
215
216 delete _epoData.front(); _epoData.pop_front();
217
218 emit newMessage(QByteArray(output._log.c_str()), true);
219 }
220}
221
222//
223////////////////////////////////////////////////////////////////////////////
224void t_pppRunRealTime::slotNewCorrections(QStringList corrList) {
225 QMutexLocker locker(&_mutex);
226
227 if (_opt->_corrMount.empty()) {
228 return;
229 }
230
231 // Check the Mountpoint (source of corrections)
232 // --------------------------------------------
233 QMutableListIterator<QString> itm(corrList);
234 while (itm.hasNext()) {
235 QStringList hlp = itm.next().split(" ");
236 if (hlp.size() > 0) {
237 QString mountpoint = hlp[hlp.size()-1];
238 if (mountpoint != QString(_opt->_corrMount.c_str())) {
239 itm.remove();
240 }
241 }
242 }
243
244 if (corrList.size() == 0) {
245 return;
246 }
247
248 vector<t_orbCorr*> orbCorr;
249 vector<t_clkCorr*> clkCorr;
250 vector<t_satBias*> satBias;
251
252 QListIterator<QString> it(corrList);
253 while (it.hasNext()) {
254 QString line = it.next();
255
256 QTextStream in(&line);
257 int messageType;
258 int updateInterval;
259 int GPSweek;
260 double GPSweeks;
261 QString prn;
262 in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
263
264 if ( t_corr::relevantMessageType(messageType) ) {
265 t_corr corr;
266 corr.readLine(line);
267 if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
268 messageType == COTYPE_GPSORBIT || messageType == COTYPE_GLONASSORBIT ) {
269 t_orbCorr* cc = new t_orbCorr();
270 cc->_prn.set(corr.prn.toAscii().data());
271 cc->_iod = corr.iod;
272 cc->_time = corr.tRao;
273 cc->_system = 'R';
274 cc->_xr[0] = corr.rao[0];
275 cc->_xr[1] = corr.rao[1];
276 cc->_xr[2] = corr.rao[2];
277 cc->_dotXr[0] = corr.dotRao[0];
278 cc->_dotXr[0] = corr.dotRao[1];
279 cc->_dotXr[0] = corr.dotRao[2];
280 orbCorr.push_back(cc);
281
282 _lastOrbCorrIOD[cc->_prn.toInt()] = cc->_iod;
283 }
284 else if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
285 messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK ) {
286 t_clkCorr* cc = new t_clkCorr();
287 cc->_prn.set(corr.prn.toAscii().data());
288 cc->_iod = corr.iod;
289 cc->_time = corr.tClk;
290 cc->_dClk = corr.dClk;
291 cc->_dotDClk = corr.dotDClk;
292 cc->_dotDotDClk = corr.dotDotDClk;
293 cc->_clkPartial = 0.0;
294 if (messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK) {
295 int lastIOD = _lastOrbCorrIOD[cc->_prn.toInt()];
296 if (lastIOD != -1) {
297 cc->_iod = lastIOD;
298 }
299 else {
300 delete cc;
301 cc = 0;
302 }
303 }
304 if (cc) {
305 clkCorr.push_back(cc);
306 if (_lastClkCorrTime.undef() || cc->_time > _lastClkCorrTime) {
307 _lastClkCorrTime = cc->_time;
308 }
309 }
310 }
311 }
312 else if ( messageType == BTYPE_GPS || messageType == BTYPE_GLONASS ) {
313 t_bias bias;
314 bias.readLine(line);
315 }
316 }
317
318 _pppClient->putOrbCorrections(orbCorr);
319 _pppClient->putClkCorrections(clkCorr);
320 _pppClient->putBiases(satBias);
321
322 for (unsigned ii = 0; ii < orbCorr.size(); ii++) {
323 delete orbCorr[ii];
324 }
325 for (unsigned ii = 0; ii < clkCorr.size(); ii++) {
326 delete clkCorr[ii];
327 }
328 for (unsigned ii = 0; ii < satBias.size(); ii++) {
329 delete satBias[ii];
330 }
331}
Note: See TracBrowser for help on using the repository browser.