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

Last change on this file since 5833 was 5833, checked in by mervart, 10 years ago
File size: 7.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
51using namespace BNC_PPP;
52using namespace std;
53
54// Constructor
55////////////////////////////////////////////////////////////////////////////
56t_pppThread::t_pppThread(const t_pppOptions* opt) : QThread(0) {
57 _opt = opt;
58 _pppRun = 0;
59 connect(this, SIGNAL(finished()), this, SLOT(deleteLater()));
60
61 connect(this, SIGNAL(newMessage(QByteArray,bool)),
62 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
63}
64
65// Destructor
66////////////////////////////////////////////////////////////////////////////
67t_pppThread::~t_pppThread() {
68 delete _pppRun;
69}
70
71// Run (virtual)
72////////////////////////////////////////////////////////////////////////////
73void t_pppThread::run() {
74 try {
75 _pppRun = new t_pppRun(_opt);
76 QThread::exec();
77 }
78 catch (t_except exc) {
79 _pppRun = 0;
80 emit newMessage(QByteArray(exc.what().c_str()), true);
81 }
82}
83
84// Constructor
85////////////////////////////////////////////////////////////////////////////
86t_pppRun::t_pppRun(const t_pppOptions* opt) {
87 _opt = opt;
88 connect(this, SIGNAL(newMessage(QByteArray,bool)),
89 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
90 if (_opt->_realTime) {
91 connect(BNC_CORE->caster(), SIGNAL(newObs(QByteArray, QList<t_obs>)),
92 this, SLOT(slotNewObs(QByteArray, QList<t_obs>)));
93
94 connect(BNC_CORE, SIGNAL(newEphGPS(gpsephemeris)),
95 this, SLOT(slotNewEphGPS(gpsephemeris)));
96
97 connect(BNC_CORE, SIGNAL(newEphGlonass(glonassephemeris)),
98 this, SLOT(slotNewEphGlonass(glonassephemeris)));
99
100 connect(BNC_CORE, SIGNAL(newEphGalileo(galileoephemeris)),
101 this, SLOT(slotNewEphGalileo(galileoephemeris)));
102
103 connect(BNC_CORE, SIGNAL(newCorrections(QStringList)),
104 this, SLOT(slotNewCorrections(QStringList)));
105
106 _pppClient = new t_pppClient(_opt);
107 }
108 else {
109 throw t_except("t_pppRun: post-processing not yet implemented");
110 }
111}
112
113// Destructor
114////////////////////////////////////////////////////////////////////////////
115t_pppRun::~t_pppRun() {
116}
117
118//
119////////////////////////////////////////////////////////////////////////////
120void t_pppRun::slotNewEphGPS(gpsephemeris gpseph) {
121 QMutexLocker locker(&_mutex);
122 t_ephGPS eph;
123 eph.set(&gpseph);
124 _pppClient->putEphemeris(&eph);
125}
126
127//
128////////////////////////////////////////////////////////////////////////////
129void t_pppRun::slotNewEphGlonass(glonassephemeris gloeph) {
130 QMutexLocker locker(&_mutex);
131 t_ephGlo eph;
132 eph.set(&gloeph);
133 _pppClient->putEphemeris(&eph);
134}
135
136//
137////////////////////////////////////////////////////////////////////////////
138void t_pppRun::slotNewEphGalileo(galileoephemeris galeph) {
139 QMutexLocker locker(&_mutex);
140 t_ephGal eph;
141 eph.set(&galeph);
142 _pppClient->putEphemeris(&eph);
143}
144
145//
146////////////////////////////////////////////////////////////////////////////
147void t_pppRun::slotNewObs(QByteArray staID, QList<t_obs> obsList) {
148 QMutexLocker locker(&_mutex);
149
150 if (string(staID.data()) != _opt->_roverName) {
151 return;
152 }
153
154 // Loop over all obsevations (possible different epochs)
155 // -----------------------------------------------------
156 QListIterator<t_obs> it(obsList);
157 while (it.hasNext()) {
158 const t_obs& oldObs = it.next();
159 t_satObs* newObs = new t_satObs;
160
161 newObs->_prn.set(oldObs.satSys, oldObs.satNum);
162 newObs->_time.set(oldObs.GPSWeek, oldObs.GPSWeeks);
163
164 // Find the corresponding data epoch or create a new one
165 // -----------------------------------------------------
166 t_epoData* epoch = 0;
167 deque<t_epoData*>::const_iterator it;
168 for (it = _epoData.begin(); it != _epoData.end(); it++) {
169 if (newObs->_time == (*it)->_time) {
170 epoch = *it;
171 break;
172 }
173 }
174 if (epoch == 0) {
175 if (_epoData.empty() || newObs->_time > _epoData.back()->_time) {
176 epoch = new t_epoData;
177 epoch->_time = newObs->_time;
178 _epoData.push_back(epoch);
179 }
180 }
181
182 // Fill the new observation and add it to the corresponding epoch
183 // --------------------------------------------------------------
184 if (epoch != 0) {
185 epoch->_satObs.push_back(newObs);
186 map<string, t_frqObs*> frqObsMap;
187 for (unsigned iEntry = 0; iEntry < GNSSENTRY_NUMBER; iEntry++) {
188 string hlp(oldObs.rnxStr(iEntry).toAscii().data());
189 if (hlp.length() == 3) {
190 char obsType = hlp[0];
191 string rnxType2ch = hlp.substr(1);
192 if (obsType == 'C' || obsType == 'L') {
193 t_frqObs* frqObs = 0;
194 if (frqObsMap.find(rnxType2ch) == frqObsMap.end()) {
195 frqObs = new t_frqObs();
196 frqObsMap[rnxType2ch] = frqObs;
197 frqObs->_rnxType2ch = rnxType2ch;
198 newObs->_obs.push_back(frqObs);
199 }
200 else {
201 frqObs = frqObsMap[rnxType2ch];
202 }
203 if (obsType == 'C') {
204 frqObs->_code = oldObs._measdata[iEntry];
205 frqObs->_codeValid = true;
206 }
207 else if (obsType == 'L') {
208 frqObs->_phase = oldObs._measdata[iEntry];
209 frqObs->_phaseValid = true;
210 }
211 }
212 }
213 }
214 }
215 }
216
217 // Process the oldest epoch
218 // ------------------------
219 if (_epoData.size() > 1) {
220
221 const vector<t_satObs*>& satObs = _epoData.front()->_satObs;
222
223 t_output output;
224 _pppClient->processEpoch(satObs, &output);
225
226 delete _epoData.front(); _epoData.pop_front();
227
228 emit newMessage(QByteArray(output._log.c_str()), true);
229 }
230}
231
232//
233////////////////////////////////////////////////////////////////////////////
234void t_pppRun::slotNewCorrections(QStringList corrList) {
235 QMutexLocker locker(&_mutex);
236
237 QStringListIterator it(corrList);
238 while (it.hasNext()) {
239 it.next();
240 }
241
242 // _pppClient->putOrbCorrections(const std::vector<t_orbCorr*>& corr);
243 // _pppClient->putClkCorrections(const std::vector<t_clkCorr*>& corr);
244 // _pppClient->putBiases(const std::vector<t_satBiases*>& biases);
245}
Note: See TracBrowser for help on using the repository browser.