source: ntrip/trunk/BNC/src/PPP/pppThread.cpp@ 5852

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