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