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

Last change on this file since 5873 was 5873, checked in by mervart, 8 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, double, double, double)),
78 BNC_CORE, SLOT(slotNewPosition(bncTime, double, double, 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 ColumnVector dx(3);
207 dx[0] = _opt->_xyzAprRover[0] - output._xyzRover[0];
208 dx[1] = _opt->_xyzAprRover[1] - output._xyzRover[1];
209 dx[2] = _opt->_xyzAprRover[2] - output._xyzRover[2];
210 emit newPosition (output._epoTime, dx[0], dx[1], dx[2]);
211 }
212
213 delete _epoData.front(); _epoData.pop_front();
214
215 emit newMessage(QByteArray(output._log.c_str()), true);
216 }
217}
218
219//
220////////////////////////////////////////////////////////////////////////////
221void t_pppRunRealTime::slotNewCorrections(QStringList corrList) {
222 QMutexLocker locker(&_mutex);
223
224 if (_opt->_corrMount.empty()) {
225 return;
226 }
227
228 // Check the Mountpoint (source of corrections)
229 // --------------------------------------------
230 QMutableListIterator<QString> itm(corrList);
231 while (itm.hasNext()) {
232 QStringList hlp = itm.next().split(" ");
233 if (hlp.size() > 0) {
234 QString mountpoint = hlp[hlp.size()-1];
235 if (mountpoint != QString(_opt->_corrMount.c_str())) {
236 itm.remove();
237 }
238 }
239 }
240
241 if (corrList.size() == 0) {
242 return;
243 }
244
245 vector<t_orbCorr*> orbCorr;
246 vector<t_clkCorr*> clkCorr;
247 vector<t_satBias*> satBias;
248
249 QListIterator<QString> it(corrList);
250 while (it.hasNext()) {
251 QString line = it.next();
252
253 QTextStream in(&line);
254 int messageType;
255 int updateInterval;
256 int GPSweek;
257 double GPSweeks;
258 QString prn;
259 in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
260
261 if ( t_corr::relevantMessageType(messageType) ) {
262 t_corr corr;
263 corr.readLine(line);
264 if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
265 messageType == COTYPE_GPSORBIT || messageType == COTYPE_GLONASSORBIT ) {
266 t_orbCorr* cc = new t_orbCorr();
267 cc->_prn.set(corr.prn.toAscii().data());
268 cc->_iod = corr.iod;
269 cc->_time = corr.tRao;
270 cc->_system = 'R';
271 cc->_xr[0] = corr.rao[0];
272 cc->_xr[1] = corr.rao[1];
273 cc->_xr[2] = corr.rao[2];
274 cc->_dotXr[0] = corr.dotRao[0];
275 cc->_dotXr[0] = corr.dotRao[1];
276 cc->_dotXr[0] = corr.dotRao[2];
277 orbCorr.push_back(cc);
278
279 _lastOrbCorrIOD[cc->_prn.toInt()] = cc->_iod;
280 }
281 else if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
282 messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK ) {
283 t_clkCorr* cc = new t_clkCorr();
284 cc->_prn.set(corr.prn.toAscii().data());
285 cc->_iod = corr.iod;
286 cc->_time = corr.tClk;
287 cc->_dClk = corr.dClk;
288 cc->_dotDClk = corr.dotDClk;
289 cc->_dotDotDClk = corr.dotDotDClk;
290 cc->_clkPartial = 0.0;
291 if (messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK) {
292 int lastIOD = _lastOrbCorrIOD[cc->_prn.toInt()];
293 if (lastIOD != -1) {
294 cc->_iod = lastIOD;
295 }
296 else {
297 delete cc;
298 cc = 0;
299 }
300 }
301 if (cc) {
302 clkCorr.push_back(cc);
303 if (_lastClkCorrTime.undef() || cc->_time > _lastClkCorrTime) {
304 _lastClkCorrTime = cc->_time;
305 }
306 }
307 }
308 }
309 else if ( messageType == BTYPE_GPS || messageType == BTYPE_GLONASS ) {
310 t_bias bias;
311 bias.readLine(line);
312 }
313 }
314
315 _pppClient->putOrbCorrections(orbCorr);
316 _pppClient->putClkCorrections(clkCorr);
317 _pppClient->putBiases(satBias);
318
319 for (unsigned ii = 0; ii < orbCorr.size(); ii++) {
320 delete orbCorr[ii];
321 }
322 for (unsigned ii = 0; ii < clkCorr.size(); ii++) {
323 delete clkCorr[ii];
324 }
325 for (unsigned ii = 0; ii < satBias.size(); ii++) {
326 delete satBias[ii];
327 }
328}
Note: See TracBrowser for help on using the repository browser.