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

Last change on this file since 5834 was 5834, checked in by mervart, 10 years ago
File size: 8.4 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 _pppClient = new t_pppClient(_opt);
108 }
109 else {
110 throw t_except("t_pppRun: post-processing not yet implemented");
111 }
112}
113
114// Destructor
115////////////////////////////////////////////////////////////////////////////
116t_pppRun::~t_pppRun() {
117}
118
119//
120////////////////////////////////////////////////////////////////////////////
121void t_pppRun::slotNewEphGPS(gpsephemeris gpseph) {
122 QMutexLocker locker(&_mutex);
123 t_ephGPS eph;
124 eph.set(&gpseph);
125 _pppClient->putEphemeris(&eph);
126}
127
128//
129////////////////////////////////////////////////////////////////////////////
130void t_pppRun::slotNewEphGlonass(glonassephemeris gloeph) {
131 QMutexLocker locker(&_mutex);
132 t_ephGlo eph;
133 eph.set(&gloeph);
134 _pppClient->putEphemeris(&eph);
135}
136
137//
138////////////////////////////////////////////////////////////////////////////
139void t_pppRun::slotNewEphGalileo(galileoephemeris galeph) {
140 QMutexLocker locker(&_mutex);
141 t_ephGal eph;
142 eph.set(&galeph);
143 _pppClient->putEphemeris(&eph);
144}
145
146//
147////////////////////////////////////////////////////////////////////////////
148void t_pppRun::slotNewObs(QByteArray staID, QList<t_obs> obsList) {
149 QMutexLocker locker(&_mutex);
150
151 if (string(staID.data()) != _opt->_roverName) {
152 return;
153 }
154
155 // Loop over all obsevations (possible different epochs)
156 // -----------------------------------------------------
157 QListIterator<t_obs> it(obsList);
158 while (it.hasNext()) {
159 const t_obs& oldObs = it.next();
160 t_satObs* newObs = new t_satObs;
161
162 newObs->_prn.set(oldObs.satSys, oldObs.satNum);
163 newObs->_time.set(oldObs.GPSWeek, oldObs.GPSWeeks);
164
165 // Find the corresponding data epoch or create a new one
166 // -----------------------------------------------------
167 t_epoData* epoch = 0;
168 deque<t_epoData*>::const_iterator it;
169 for (it = _epoData.begin(); it != _epoData.end(); it++) {
170 if (newObs->_time == (*it)->_time) {
171 epoch = *it;
172 break;
173 }
174 }
175 if (epoch == 0) {
176 if (_epoData.empty() || newObs->_time > _epoData.back()->_time) {
177 epoch = new t_epoData;
178 epoch->_time = newObs->_time;
179 _epoData.push_back(epoch);
180 }
181 }
182
183 // Fill the new observation and add it to the corresponding epoch
184 // --------------------------------------------------------------
185 if (epoch != 0) {
186 epoch->_satObs.push_back(newObs);
187 map<string, t_frqObs*> frqObsMap;
188 for (unsigned iEntry = 0; iEntry < GNSSENTRY_NUMBER; iEntry++) {
189 string hlp(oldObs.rnxStr(iEntry).toAscii().data());
190 if (hlp.length() == 3) {
191 char obsType = hlp[0];
192 string rnxType2ch = hlp.substr(1);
193 if (obsType == 'C' || obsType == 'L') {
194 t_frqObs* frqObs = 0;
195 if (frqObsMap.find(rnxType2ch) == frqObsMap.end()) {
196 frqObs = new t_frqObs();
197 frqObsMap[rnxType2ch] = frqObs;
198 frqObs->_rnxType2ch = rnxType2ch;
199 newObs->_obs.push_back(frqObs);
200 }
201 else {
202 frqObs = frqObsMap[rnxType2ch];
203 }
204 if (obsType == 'C') {
205 frqObs->_code = oldObs._measdata[iEntry];
206 frqObs->_codeValid = true;
207 }
208 else if (obsType == 'L') {
209 frqObs->_phase = oldObs._measdata[iEntry];
210 frqObs->_phaseValid = true;
211 }
212 }
213 }
214 }
215 }
216 }
217
218 // Process the oldest epoch
219 // ------------------------
220 if (_epoData.size() > 1) {
221
222 const vector<t_satObs*>& satObs = _epoData.front()->_satObs;
223
224 t_output output;
225 _pppClient->processEpoch(satObs, &output);
226
227 delete _epoData.front(); _epoData.pop_front();
228
229 emit newMessage(QByteArray(output._log.c_str()), true);
230 }
231}
232
233//
234////////////////////////////////////////////////////////////////////////////
235void t_pppRun::slotNewCorrections(QStringList corrList) {
236 QMutexLocker locker(&_mutex);
237
238 if (_opt->_corrMount.empty()) {
239 return;
240 }
241
242 // Check the Mountpoint (source of corrections)
243 // --------------------------------------------
244 QMutableListIterator<QString> itm(corrList);
245 while (itm.hasNext()) {
246 QStringList hlp = itm.next().split(" ");
247 if (hlp.size() > 0) {
248 QString mountpoint = hlp[hlp.size()-1];
249 if (mountpoint != QString(_opt->_corrMount.c_str())) {
250 itm.remove();
251 }
252 }
253 }
254
255 if (corrList.size() == 0) {
256 return;
257 }
258
259 QListIterator<QString> it(corrList);
260 while (it.hasNext()) {
261 QString line = it.next();
262
263 QTextStream in(&line);
264 int messageType;
265 int updateInterval;
266 int GPSweek;
267 double GPSweeks;
268 QString prn;
269 in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
270
271 if ( t_corr::relevantMessageType(messageType) ) {
272 t_corr corr;
273 corr.readLine(line);
274 }
275 else if ( messageType == BTYPE_GPS || messageType == BTYPE_GLONASS ) {
276 t_bias bias;
277 bias.readLine(line);
278 }
279 }
280
281 // _pppClient->putOrbCorrections(const std::vector<t_orbCorr*>& corr);
282 // _pppClient->putClkCorrections(const std::vector<t_clkCorr*>& corr);
283 // _pppClient->putBiases(const std::vector<t_satBiases*>& biases);
284}
Note: See TracBrowser for help on using the repository browser.