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

Last change on this file since 5870 was 5870, checked in by mervart, 10 years ago
File size: 9.7 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 for (unsigned iPrn = 0; iPrn <= t_prn::MAXPRN; iPrn++) {
78 _lastOrbCorrIOD[iPrn] = -1;
79 _lastClkCorrValue[iPrn] = 0.0;
80 }
81
82 _pppClient = new t_pppClient(_opt);
83 }
84 else {
85 throw t_except("t_pppRunRealTime: post-processing not yet implemented");
86 }
87}
88
89// Destructor
90////////////////////////////////////////////////////////////////////////////
91t_pppRunRealTime::~t_pppRunRealTime() {
92}
93
94//
95////////////////////////////////////////////////////////////////////////////
96void t_pppRunRealTime::slotNewEphGPS(gpsephemeris gpseph) {
97 QMutexLocker locker(&_mutex);
98 t_ephGPS eph;
99 eph.set(&gpseph);
100 _pppClient->putEphemeris(&eph);
101}
102
103//
104////////////////////////////////////////////////////////////////////////////
105void t_pppRunRealTime::slotNewEphGlonass(glonassephemeris gloeph) {
106 QMutexLocker locker(&_mutex);
107 t_ephGlo eph;
108 eph.set(&gloeph);
109 _pppClient->putEphemeris(&eph);
110}
111
112//
113////////////////////////////////////////////////////////////////////////////
114void t_pppRunRealTime::slotNewEphGalileo(galileoephemeris galeph) {
115 QMutexLocker locker(&_mutex);
116 t_ephGal eph;
117 eph.set(&galeph);
118 _pppClient->putEphemeris(&eph);
119}
120
121//
122////////////////////////////////////////////////////////////////////////////
123void t_pppRunRealTime::slotNewObs(QByteArray staID, QList<t_obs> obsList) {
124 QMutexLocker locker(&_mutex);
125
126 if (string(staID.data()) != _opt->_roverName) {
127 return;
128 }
129
130 // Loop over all obsevations (possible different epochs)
131 // -----------------------------------------------------
132 QListIterator<t_obs> it(obsList);
133 while (it.hasNext()) {
134 const t_obs& oldObs = it.next();
135 t_satObs* newObs = new t_satObs;
136
137 newObs->_prn.set(oldObs.satSys, oldObs.satNum);
138 newObs->_time.set(oldObs.GPSWeek, oldObs.GPSWeeks);
139
140 // Find the corresponding data epoch or create a new one
141 // -----------------------------------------------------
142 t_epoData* epoch = 0;
143 deque<t_epoData*>::const_iterator it;
144 for (it = _epoData.begin(); it != _epoData.end(); it++) {
145 if (newObs->_time == (*it)->_time) {
146 epoch = *it;
147 break;
148 }
149 }
150 if (epoch == 0) {
151 if (_epoData.empty() || newObs->_time > _epoData.back()->_time) {
152 epoch = new t_epoData;
153 epoch->_time = newObs->_time;
154 _epoData.push_back(epoch);
155 }
156 }
157
158 // Fill the new observation and add it to the corresponding epoch
159 // --------------------------------------------------------------
160 if (epoch != 0) {
161 epoch->_satObs.push_back(newObs);
162 map<string, t_frqObs*> frqObsMap;
163 for (unsigned iEntry = 0; iEntry < GNSSENTRY_NUMBER; iEntry++) {
164 string hlp(oldObs.rnxStr(iEntry).toAscii().data());
165 if (hlp.length() == 3) {
166 char obsType = hlp[0];
167 string rnxType2ch = hlp.substr(1);
168 if (obsType == 'C' || obsType == 'L') {
169 t_frqObs* frqObs = 0;
170 if (frqObsMap.find(rnxType2ch) == frqObsMap.end()) {
171 frqObs = new t_frqObs();
172 frqObsMap[rnxType2ch] = frqObs;
173 frqObs->_rnxType2ch = rnxType2ch;
174 newObs->_obs.push_back(frqObs);
175 }
176 else {
177 frqObs = frqObsMap[rnxType2ch];
178 }
179 if (obsType == 'C') {
180 frqObs->_code = oldObs._measdata[iEntry];
181 frqObs->_codeValid = true;
182 }
183 else if (obsType == 'L') {
184 frqObs->_phase = oldObs._measdata[iEntry];
185 frqObs->_phaseValid = true;
186 }
187 }
188 }
189 }
190 }
191 }
192
193 // Process the oldest epochs
194 // ------------------------
195 while (_epoData.size() && _epoData.front()->_time < _lastClkCorrTime + 10.0) {
196
197 const vector<t_satObs*>& satObs = _epoData.front()->_satObs;
198
199 t_output output;
200 _pppClient->processEpoch(satObs, &output);
201
202 delete _epoData.front(); _epoData.pop_front();
203
204 emit newMessage(QByteArray(output._log.c_str()), true);
205 }
206}
207
208//
209////////////////////////////////////////////////////////////////////////////
210void t_pppRunRealTime::slotNewCorrections(QStringList corrList) {
211 QMutexLocker locker(&_mutex);
212
213 if (_opt->_corrMount.empty()) {
214 return;
215 }
216
217 // Check the Mountpoint (source of corrections)
218 // --------------------------------------------
219 QMutableListIterator<QString> itm(corrList);
220 while (itm.hasNext()) {
221 QStringList hlp = itm.next().split(" ");
222 if (hlp.size() > 0) {
223 QString mountpoint = hlp[hlp.size()-1];
224 if (mountpoint != QString(_opt->_corrMount.c_str())) {
225 itm.remove();
226 }
227 }
228 }
229
230 if (corrList.size() == 0) {
231 return;
232 }
233
234 vector<t_orbCorr*> orbCorr;
235 vector<t_clkCorr*> clkCorr;
236 vector<t_satBias*> satBias;
237
238 QListIterator<QString> it(corrList);
239 while (it.hasNext()) {
240 QString line = it.next();
241
242 QTextStream in(&line);
243 int messageType;
244 int updateInterval;
245 int GPSweek;
246 double GPSweeks;
247 QString prn;
248 in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
249
250 if ( t_corr::relevantMessageType(messageType) ) {
251 t_corr corr;
252 corr.readLine(line);
253 if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
254 messageType == COTYPE_GPSORBIT || messageType == COTYPE_GLONASSORBIT ) {
255 t_orbCorr* cc = new t_orbCorr();
256 cc->_prn.set(corr.prn.toAscii().data());
257 cc->_iod = corr.iod;
258 cc->_time = corr.tRao;
259 cc->_system = 'R';
260 cc->_xr[0] = corr.rao[0];
261 cc->_xr[1] = corr.rao[1];
262 cc->_xr[2] = corr.rao[2];
263 cc->_dotXr[0] = corr.dotRao[0];
264 cc->_dotXr[0] = corr.dotRao[1];
265 cc->_dotXr[0] = corr.dotRao[2];
266 orbCorr.push_back(cc);
267
268 _lastOrbCorrIOD[cc->_prn.toInt()] = cc->_iod;
269 }
270 else if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
271 messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK ) {
272 t_clkCorr* cc = new t_clkCorr();
273 cc->_prn.set(corr.prn.toAscii().data());
274 cc->_iod = corr.iod;
275 cc->_time = corr.tClk;
276 cc->_dClk = corr.dClk;
277 cc->_dotDClk = corr.dotDClk;
278 cc->_dotDotDClk = corr.dotDotDClk;
279 cc->_clkPartial = 0.0;
280 if (messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK) {
281 int lastIOD = _lastOrbCorrIOD[cc->_prn.toInt()];
282 if (lastIOD != -1) {
283 cc->_iod = lastIOD;
284 }
285 else {
286 delete cc;
287 cc = 0;
288 }
289 }
290 if (cc) {
291 clkCorr.push_back(cc);
292 if (_lastClkCorrTime.undef() || cc->_time > _lastClkCorrTime) {
293 _lastClkCorrTime = cc->_time;
294 }
295 }
296 }
297 }
298 else if ( messageType == BTYPE_GPS || messageType == BTYPE_GLONASS ) {
299 t_bias bias;
300 bias.readLine(line);
301 }
302 }
303
304 _pppClient->putOrbCorrections(orbCorr);
305 _pppClient->putClkCorrections(clkCorr);
306 _pppClient->putBiases(satBias);
307
308 for (unsigned ii = 0; ii < orbCorr.size(); ii++) {
309 delete orbCorr[ii];
310 }
311 for (unsigned ii = 0; ii < clkCorr.size(); ii++) {
312 delete clkCorr[ii];
313 }
314 for (unsigned ii = 0; ii < satBias.size(); ii++) {
315 delete satBias[ii];
316 }
317}
Note: See TracBrowser for help on using the repository browser.