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
RevLine 
[4757]1
[5719]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 *
[5813]30 * Class: t_pppThread, t_pppRun
[5719]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
[4757]43#include <iostream>
[4775]44#include <iomanip>
[4757]45#include <string.h>
[5782]46#include <map>
[4757]47
[5813]48#include "pppThread.h"
[5068]49#include "bnccore.h"
[5834]50#include "bncephuser.h"
[4757]51
[5814]52using namespace BNC_PPP;
[4757]53using namespace std;
54
55// Constructor
56////////////////////////////////////////////////////////////////////////////
[5813]57t_pppThread::t_pppThread(const t_pppOptions* opt) : QThread(0) {
[5774]58 _opt = opt;
59 _pppRun = 0;
[5775]60 connect(this, SIGNAL(finished()), this, SLOT(deleteLater()));
61
[5767]62 connect(this, SIGNAL(newMessage(QByteArray,bool)),
63 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
[4763]64}
65
66// Destructor
67////////////////////////////////////////////////////////////////////////////
[5813]68t_pppThread::~t_pppThread() {
[5731]69 delete _pppRun;
[4763]70}
71
72// Run (virtual)
73////////////////////////////////////////////////////////////////////////////
[5813]74void t_pppThread::run() {
[5742]75 try {
76 _pppRun = new t_pppRun(_opt);
[5775]77 QThread::exec();
[5742]78 }
[5825]79 catch (t_except exc) {
[5768]80 _pppRun = 0;
[5766]81 emit newMessage(QByteArray(exc.what().c_str()), true);
[5742]82 }
[5731]83}
84
85// Constructor
86////////////////////////////////////////////////////////////////////////////
[5810]87t_pppRun::t_pppRun(const t_pppOptions* opt) {
[5731]88 _opt = opt;
[5767]89 connect(this, SIGNAL(newMessage(QByteArray,bool)),
90 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
[5742]91 if (_opt->_realTime) {
[5729]92 connect(BNC_CORE->caster(), SIGNAL(newObs(QByteArray, QList<t_obs>)),
93 this, SLOT(slotNewObs(QByteArray, QList<t_obs>)));
[4757]94
[5722]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)));
[4757]103
[5732]104 connect(BNC_CORE, SIGNAL(newCorrections(QStringList)),
105 this, SLOT(slotNewCorrections(QStringList)));
[5742]106
[5840]107 for (unsigned iPrn = 0; iPrn <= t_prn::MAXPRN; iPrn++) {
108 _lastOrbCorrIOD[iPrn] = -1;
109 _lastClkCorrValue[iPrn] = 0.0;
110 }
111
[5761]112 _pppClient = new t_pppClient(_opt);
[5722]113 }
[5742]114 else {
[5825]115 throw t_except("t_pppRun: post-processing not yet implemented");
[5742]116 }
[5731]117}
[5729]118
[5731]119// Destructor
120////////////////////////////////////////////////////////////////////////////
121t_pppRun::~t_pppRun() {
[4757]122}
123
124//
125////////////////////////////////////////////////////////////////////////////
[5731]126void t_pppRun::slotNewEphGPS(gpsephemeris gpseph) {
[4757]127 QMutexLocker locker(&_mutex);
[5742]128 t_ephGPS eph;
129 eph.set(&gpseph);
[5772]130 _pppClient->putEphemeris(&eph);
[4757]131}
132
133//
134////////////////////////////////////////////////////////////////////////////
[5731]135void t_pppRun::slotNewEphGlonass(glonassephemeris gloeph) {
[4757]136 QMutexLocker locker(&_mutex);
[5769]137 t_ephGlo eph;
138 eph.set(&gloeph);
[5772]139 _pppClient->putEphemeris(&eph);
[4757]140}
141
142//
143////////////////////////////////////////////////////////////////////////////
[5769]144void t_pppRun::slotNewEphGalileo(galileoephemeris galeph) {
[5681]145 QMutexLocker locker(&_mutex);
[5769]146 t_ephGal eph;
147 eph.set(&galeph);
[5772]148 _pppClient->putEphemeris(&eph);
[4757]149}
150
151//
152////////////////////////////////////////////////////////////////////////////
[5731]153void t_pppRun::slotNewObs(QByteArray staID, QList<t_obs> obsList) {
[4757]154 QMutexLocker locker(&_mutex);
[5766]155
[5777]156 if (string(staID.data()) != _opt->_roverName) {
157 return;
158 }
159
[5791]160 // Loop over all obsevations (possible different epochs)
161 // -----------------------------------------------------
[5778]162 QListIterator<t_obs> it(obsList);
163 while (it.hasNext()) {
[5780]164 const t_obs& oldObs = it.next();
[5819]165 t_satObs* newObs = new t_satObs;
[5781]166
167 newObs->_prn.set(oldObs.satSys, oldObs.satNum);
168 newObs->_time.set(oldObs.GPSWeek, oldObs.GPSWeeks);
[5780]169
[5791]170 // Find the corresponding data epoch or create a new one
171 // -----------------------------------------------------
[5833]172 t_epoData* epoch = 0;
173 deque<t_epoData*>::const_iterator it;
174 for (it = _epoData.begin(); it != _epoData.end(); it++) {
[5791]175 if (newObs->_time == (*it)->_time) {
[5833]176 epoch = *it;
[5791]177 break;
178 }
179 }
[5833]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);
[5791]185 }
186 }
[5790]187
[5791]188 // Fill the new observation and add it to the corresponding epoch
189 // --------------------------------------------------------------
[5833]190 if (epoch != 0) {
191 epoch->_satObs.push_back(newObs);
[5832]192 map<string, t_frqObs*> frqObsMap;
[5791]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') {
[5832]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);
[5791]205 }
206 else {
[5832]207 frqObs = frqObsMap[rnxType2ch];
[5791]208 }
209 if (obsType == 'C') {
[5832]210 frqObs->_code = oldObs._measdata[iEntry];
211 frqObs->_codeValid = true;
[5791]212 }
213 else if (obsType == 'L') {
[5832]214 frqObs->_phase = oldObs._measdata[iEntry];
215 frqObs->_phaseValid = true;
[5791]216 }
[5783]217 }
218 }
[5782]219 }
220 }
[5778]221 }
[5772]222
[5791]223 // Process the oldest epoch
224 // ------------------------
[5850]225 while (_epoData.size() && _epoData.front()->_time < _lastClkCorrTime) {
[5772]226
[5833]227 const vector<t_satObs*>& satObs = _epoData.front()->_satObs;
[5791]228
229 t_output output;
[5823]230 _pppClient->processEpoch(satObs, &output);
[5791]231
[5833]232 delete _epoData.front(); _epoData.pop_front();
[5848]233
234 //// beg test
235 cout << output._log << endl; cout.flush();
236 //// end test
[5791]237
238 emit newMessage(QByteArray(output._log.c_str()), true);
[5779]239 }
[5589]240}
[5525]241
[5833]242//
243////////////////////////////////////////////////////////////////////////////
244void t_pppRun::slotNewCorrections(QStringList corrList) {
245 QMutexLocker locker(&_mutex);
246
[5834]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
[5835]268 vector<t_orbCorr*> orbCorr;
269 vector<t_clkCorr*> clkCorr;
270 vector<t_satBias*> satBias;
271
[5834]272 QListIterator<QString> it(corrList);
[5833]273 while (it.hasNext()) {
[5834]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);
[5836]287 if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
288 messageType == COTYPE_GPSORBIT || messageType == COTYPE_GLONASSORBIT ) {
[5838]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];
[5840]300 orbCorr.push_back(cc);
301
302 _lastOrbCorrIOD[cc->_prn.toInt()] = cc->_iod;
[5836]303 }
304 else if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
305 messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK ) {
[5838]306 t_clkCorr* cc = new t_clkCorr();
307 cc->_prn.set(corr.prn.toAscii().data());
308 cc->_iod = corr.iod;
[5848]309 cc->_time = corr.tClk;
[5838]310 cc->_dClk = corr.dClk;
311 cc->_dotDClk = corr.dotDClk;
312 cc->_dotDotDClk = corr.dotDotDClk;
313 cc->_clkPartial = 0.0;
[5840]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);
[5850]326 if (_lastClkCorrTime.undef() || cc->_time > _lastClkCorrTime) {
327 _lastClkCorrTime = cc->_time;
328 }
[5840]329 }
[5836]330 }
[5834]331 }
332 else if ( messageType == BTYPE_GPS || messageType == BTYPE_GLONASS ) {
333 t_bias bias;
334 bias.readLine(line);
335 }
[5833]336 }
337
[5835]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 }
[5833]351}
Note: See TracBrowser for help on using the repository browser.