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_pppRun
|
---|
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 <sstream>
|
---|
46 | #include <string.h>
|
---|
47 | #include <map>
|
---|
48 |
|
---|
49 | #include "pppRun.h"
|
---|
50 | #include "pppThread.h"
|
---|
51 | #include "bnccore.h"
|
---|
52 | #include "bncephuser.h"
|
---|
53 | #include "bncsettings.h"
|
---|
54 | #include "bncoutf.h"
|
---|
55 | #include "rinex/rnxobsfile.h"
|
---|
56 | #include "rinex/rnxnavfile.h"
|
---|
57 | #include "rinex/corrfile.h"
|
---|
58 |
|
---|
59 | using namespace BNC_PPP;
|
---|
60 | using namespace std;
|
---|
61 |
|
---|
62 | // Constructor
|
---|
63 | ////////////////////////////////////////////////////////////////////////////
|
---|
64 | t_pppRun::t_pppRun(const t_pppOptions* opt) {
|
---|
65 |
|
---|
66 | _opt = opt;
|
---|
67 |
|
---|
68 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
69 | BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
|
---|
70 |
|
---|
71 | connect(this, SIGNAL(newPosition(QByteArray, bncTime, QVector<double>)),
|
---|
72 | BNC_CORE, SIGNAL(newPosition(QByteArray, bncTime, QVector<double>)));
|
---|
73 |
|
---|
74 | connect(this, SIGNAL(newNMEAstr(QByteArray, QByteArray)),
|
---|
75 | BNC_CORE, SIGNAL(newNMEAstr(QByteArray, QByteArray)));
|
---|
76 |
|
---|
77 | for (unsigned iPrn = 0; iPrn <= t_prn::MAXPRN; iPrn++) {
|
---|
78 | _lastOrbCorrIOD[iPrn] = -1;
|
---|
79 | _lastClkCorrValue[iPrn] = 0.0;
|
---|
80 | }
|
---|
81 |
|
---|
82 | _pppClient = new t_pppClient(_opt);
|
---|
83 |
|
---|
84 | bncSettings settings;
|
---|
85 |
|
---|
86 | if (_opt->_realTime) {
|
---|
87 | Qt::ConnectionType conType = Qt::AutoConnection;
|
---|
88 | if (BNC_CORE->mode() == t_bncCore::batchPostProcessing) {
|
---|
89 | conType = Qt::BlockingQueuedConnection;
|
---|
90 | }
|
---|
91 |
|
---|
92 | connect(BNC_CORE->caster(), SIGNAL(newObs(QByteArray, QList<t_satObs>)),
|
---|
93 | this, SLOT(slotNewObs(QByteArray, QList<t_satObs>)),conType);
|
---|
94 |
|
---|
95 | connect(BNC_CORE, SIGNAL(newEphGPS(gpsephemeris)),
|
---|
96 | this, SLOT(slotNewEphGPS(gpsephemeris)),conType);
|
---|
97 |
|
---|
98 | connect(BNC_CORE, SIGNAL(newEphGlonass(glonassephemeris)),
|
---|
99 | this, SLOT(slotNewEphGlonass(glonassephemeris)),conType);
|
---|
100 |
|
---|
101 | connect(BNC_CORE, SIGNAL(newEphGalileo(galileoephemeris)),
|
---|
102 | this, SLOT(slotNewEphGalileo(galileoephemeris)),conType);
|
---|
103 |
|
---|
104 | connect(BNC_CORE, SIGNAL(newCorrections(QStringList)),
|
---|
105 | this, SLOT(slotNewCorrections(QStringList)),conType);
|
---|
106 | }
|
---|
107 | else {
|
---|
108 | _rnxObsFile = 0;
|
---|
109 | _rnxNavFile = 0;
|
---|
110 | _corrFile = 0;
|
---|
111 | _speed = settings.value("PPP/mapSpeedSlider").toInt();
|
---|
112 | connect(this, SIGNAL(progressRnxPPP(int)), BNC_CORE, SIGNAL(progressRnxPPP(int)));
|
---|
113 | connect(this, SIGNAL(finishedRnxPPP()), BNC_CORE, SIGNAL(finishedRnxPPP()));
|
---|
114 | connect(BNC_CORE, SIGNAL(mapSpeedSliderChanged(int)),
|
---|
115 | this, SLOT(slotSetSpeed(int)));
|
---|
116 | connect(BNC_CORE, SIGNAL(stopRinexPPP()), this, SLOT(slotSetStopFlag()));
|
---|
117 | }
|
---|
118 |
|
---|
119 | _stopFlag = false;
|
---|
120 |
|
---|
121 | QString roverName(_opt->_roverName.c_str());
|
---|
122 |
|
---|
123 | QString logFileSkl = settings.value("PPP/logFile").toString();
|
---|
124 | if (logFileSkl.isEmpty()) {
|
---|
125 | _logFile = 0;
|
---|
126 | }
|
---|
127 | else {
|
---|
128 | if (logFileSkl.indexOf("${STATION}") == -1) {
|
---|
129 | logFileSkl = roverName + "_" + logFileSkl;
|
---|
130 | }
|
---|
131 | else {
|
---|
132 | logFileSkl.replace("${STATION}", roverName);
|
---|
133 | }
|
---|
134 | _logFile = new bncoutf(logFileSkl, "1 day", 0);
|
---|
135 | }
|
---|
136 |
|
---|
137 | QString nmeaFileSkl = settings.value("PPP/nmeaFile").toString();
|
---|
138 | if (nmeaFileSkl.isEmpty()) {
|
---|
139 | _nmeaFile = 0;
|
---|
140 | }
|
---|
141 | else {
|
---|
142 | if (nmeaFileSkl.indexOf("${STATION}") == -1) {
|
---|
143 | nmeaFileSkl = roverName + "_" + nmeaFileSkl;
|
---|
144 | }
|
---|
145 | else {
|
---|
146 | nmeaFileSkl.replace("${STATION}", roverName);
|
---|
147 | }
|
---|
148 | _nmeaFile = new bncoutf(nmeaFileSkl, "1 day", 0);
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | // Destructor
|
---|
153 | ////////////////////////////////////////////////////////////////////////////
|
---|
154 | t_pppRun::~t_pppRun() {
|
---|
155 | delete _logFile;
|
---|
156 | delete _nmeaFile;
|
---|
157 | }
|
---|
158 |
|
---|
159 | //
|
---|
160 | ////////////////////////////////////////////////////////////////////////////
|
---|
161 | void t_pppRun::slotNewEphGPS(gpsephemeris gpseph) {
|
---|
162 | QMutexLocker locker(&_mutex);
|
---|
163 | t_ephGPS eph;
|
---|
164 | eph.set(&gpseph);
|
---|
165 | _pppClient->putEphemeris(&eph);
|
---|
166 | }
|
---|
167 |
|
---|
168 | //
|
---|
169 | ////////////////////////////////////////////////////////////////////////////
|
---|
170 | void t_pppRun::slotNewEphGlonass(glonassephemeris gloeph) {
|
---|
171 | QMutexLocker locker(&_mutex);
|
---|
172 | t_ephGlo eph;
|
---|
173 | eph.set(&gloeph);
|
---|
174 | _pppClient->putEphemeris(&eph);
|
---|
175 | }
|
---|
176 |
|
---|
177 | //
|
---|
178 | ////////////////////////////////////////////////////////////////////////////
|
---|
179 | void t_pppRun::slotNewEphGalileo(galileoephemeris galeph) {
|
---|
180 | QMutexLocker locker(&_mutex);
|
---|
181 | t_ephGal eph;
|
---|
182 | eph.set(&galeph);
|
---|
183 | _pppClient->putEphemeris(&eph);
|
---|
184 | }
|
---|
185 |
|
---|
186 | //
|
---|
187 | ////////////////////////////////////////////////////////////////////////////
|
---|
188 | void t_pppRun::slotNewObs(QByteArray staID, QList<t_satObs> obsList) {
|
---|
189 | QMutexLocker locker(&_mutex);
|
---|
190 |
|
---|
191 | if (string(staID.data()) != _opt->_roverName) {
|
---|
192 | return;
|
---|
193 | }
|
---|
194 |
|
---|
195 | // Loop over all obsevations (possible different epochs)
|
---|
196 | // -----------------------------------------------------
|
---|
197 | QListIterator<t_satObs> it(obsList);
|
---|
198 | while (it.hasNext()) {
|
---|
199 | const t_satObs& oldObs = it.next();
|
---|
200 | t_satObs* newObs = new t_satObs(oldObs);
|
---|
201 |
|
---|
202 | // Find the corresponding data epoch or create a new one
|
---|
203 | // -----------------------------------------------------
|
---|
204 | t_epoData* epoch = 0;
|
---|
205 | deque<t_epoData*>::const_iterator it;
|
---|
206 | for (it = _epoData.begin(); it != _epoData.end(); it++) {
|
---|
207 | if (newObs->_time == (*it)->_time) {
|
---|
208 | epoch = *it;
|
---|
209 | break;
|
---|
210 | }
|
---|
211 | }
|
---|
212 | if (epoch == 0) {
|
---|
213 | if (_epoData.empty() || newObs->_time > _epoData.back()->_time) {
|
---|
214 | epoch = new t_epoData;
|
---|
215 | epoch->_time = newObs->_time;
|
---|
216 | _epoData.push_back(epoch);
|
---|
217 | }
|
---|
218 | }
|
---|
219 |
|
---|
220 | // Put data into the epoch
|
---|
221 | // -----------------------
|
---|
222 | if (epoch != 0) {
|
---|
223 | epoch->_satObs.push_back(newObs);
|
---|
224 | }
|
---|
225 | else {
|
---|
226 | delete newObs;
|
---|
227 | }
|
---|
228 | }
|
---|
229 |
|
---|
230 | // Process the oldest epochs
|
---|
231 | // ------------------------
|
---|
232 | while (_epoData.size() && !waitForCorr(_epoData.front()->_time)) {
|
---|
233 |
|
---|
234 | const vector<t_satObs*>& satObs = _epoData.front()->_satObs;
|
---|
235 |
|
---|
236 | t_output output;
|
---|
237 | _pppClient->processEpoch(satObs, &output);
|
---|
238 |
|
---|
239 | if (!output._error) {
|
---|
240 | QVector<double> xx(6);
|
---|
241 | xx.data()[0] = output._xyzRover[0];
|
---|
242 | xx.data()[1] = output._xyzRover[1];
|
---|
243 | xx.data()[2] = output._xyzRover[2];
|
---|
244 | xx.data()[3] = output._neu[0];
|
---|
245 | xx.data()[4] = output._neu[1];
|
---|
246 | xx.data()[5] = output._neu[2];
|
---|
247 | emit newPosition(staID, output._epoTime, xx);
|
---|
248 | }
|
---|
249 |
|
---|
250 | delete _epoData.front(); _epoData.pop_front();
|
---|
251 |
|
---|
252 | ostringstream log;
|
---|
253 | if (output._error) {
|
---|
254 | log << output._log;
|
---|
255 | }
|
---|
256 | else {
|
---|
257 | log.setf(ios::fixed);
|
---|
258 | log << string(output._epoTime) << ' ' << staID.data()
|
---|
259 | << " X = " << setprecision(4) << output._xyzRover[0]
|
---|
260 | << " Y = " << setprecision(4) << output._xyzRover[1]
|
---|
261 | << " Z = " << setprecision(4) << output._xyzRover[2]
|
---|
262 | << " NEU: " << setprecision(4) << output._neu[0]
|
---|
263 | << " " << setprecision(4) << output._neu[1]
|
---|
264 | << " " << setprecision(4) << output._neu[2];
|
---|
265 | }
|
---|
266 |
|
---|
267 | if (_logFile && output._epoTime.valid()) {
|
---|
268 | _logFile->write(output._epoTime.gpsw(), output._epoTime.gpssec(),
|
---|
269 | QString(output._log.c_str()));
|
---|
270 | }
|
---|
271 |
|
---|
272 | if (!output._error) {
|
---|
273 | QString rmcStr = nmeaString('R', output);
|
---|
274 | QString ggaStr = nmeaString('G', output);
|
---|
275 | if (_nmeaFile) {
|
---|
276 | _nmeaFile->write(output._epoTime.gpsw(), output._epoTime.gpssec(), rmcStr);
|
---|
277 | _nmeaFile->write(output._epoTime.gpsw(), output._epoTime.gpssec(), ggaStr);
|
---|
278 | }
|
---|
279 | emit newNMEAstr(staID, rmcStr.toAscii());
|
---|
280 | emit newNMEAstr(staID, ggaStr.toAscii());
|
---|
281 | }
|
---|
282 |
|
---|
283 | emit newMessage(QByteArray(log.str().c_str()), true);
|
---|
284 | }
|
---|
285 | }
|
---|
286 |
|
---|
287 | //
|
---|
288 | ////////////////////////////////////////////////////////////////////////////
|
---|
289 | void t_pppRun::slotNewCorrections(QStringList corrList) {
|
---|
290 | QMutexLocker locker(&_mutex);
|
---|
291 |
|
---|
292 | // Check the Mountpoint (source of corrections)
|
---|
293 | // --------------------------------------------
|
---|
294 | if (_opt->_realTime) {
|
---|
295 | if (_opt->_corrMount.empty()) {
|
---|
296 | return;
|
---|
297 | }
|
---|
298 | QMutableListIterator<QString> itm(corrList);
|
---|
299 | while (itm.hasNext()) {
|
---|
300 | QStringList hlp = itm.next().split(" ");
|
---|
301 | if (hlp.size() > 0) {
|
---|
302 | QString mountpoint = hlp[hlp.size()-1];
|
---|
303 | if (mountpoint != QString(_opt->_corrMount.c_str())) {
|
---|
304 | itm.remove();
|
---|
305 | }
|
---|
306 | }
|
---|
307 | }
|
---|
308 | }
|
---|
309 |
|
---|
310 | if (corrList.size() == 0) {
|
---|
311 | return;
|
---|
312 | }
|
---|
313 |
|
---|
314 | vector<t_orbCorr*> orbCorr;
|
---|
315 | vector<t_clkCorr*> clkCorr;
|
---|
316 | vector<t_satBias*> satBias;
|
---|
317 |
|
---|
318 | QListIterator<QString> it(corrList);
|
---|
319 | while (it.hasNext()) {
|
---|
320 | QString line = it.next();
|
---|
321 |
|
---|
322 | QTextStream in(&line);
|
---|
323 | int messageType;
|
---|
324 | int updateInterval;
|
---|
325 | int GPSweek;
|
---|
326 | double GPSweeks;
|
---|
327 | QString prn;
|
---|
328 | in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
|
---|
329 |
|
---|
330 | if ( t_corr::relevantMessageType(messageType) ) {
|
---|
331 | t_corr corr;
|
---|
332 | corr.readLine(line);
|
---|
333 | if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
|
---|
334 | messageType == COTYPE_GPSORBIT || messageType == COTYPE_GLONASSORBIT ) {
|
---|
335 | t_orbCorr* cc = new t_orbCorr();
|
---|
336 | cc->_prn.set(corr.prn.toAscii().data());
|
---|
337 | cc->_iod = corr.iod;
|
---|
338 | cc->_time = corr.tRao;
|
---|
339 | cc->_system = 'R';
|
---|
340 | cc->_xr[0] = corr.rao[0];
|
---|
341 | cc->_xr[1] = corr.rao[1];
|
---|
342 | cc->_xr[2] = corr.rao[2];
|
---|
343 | cc->_dotXr[0] = corr.dotRao[0];
|
---|
344 | cc->_dotXr[0] = corr.dotRao[1];
|
---|
345 | cc->_dotXr[0] = corr.dotRao[2];
|
---|
346 | orbCorr.push_back(cc);
|
---|
347 |
|
---|
348 | _lastOrbCorrIOD[cc->_prn.toInt()] = cc->_iod;
|
---|
349 | }
|
---|
350 | else if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
|
---|
351 | messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK ) {
|
---|
352 | t_clkCorr* cc = new t_clkCorr();
|
---|
353 | cc->_prn.set(corr.prn.toAscii().data());
|
---|
354 | cc->_iod = corr.iod;
|
---|
355 | cc->_time = corr.tClk;
|
---|
356 | cc->_dClk = corr.dClk;
|
---|
357 | cc->_dotDClk = corr.dotDClk;
|
---|
358 | cc->_dotDotDClk = corr.dotDotDClk;
|
---|
359 | cc->_clkPartial = 0.0;
|
---|
360 | if (messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK) {
|
---|
361 | int lastIOD = _lastOrbCorrIOD[cc->_prn.toInt()];
|
---|
362 | if (lastIOD != -1) {
|
---|
363 | cc->_iod = lastIOD;
|
---|
364 | }
|
---|
365 | else {
|
---|
366 | delete cc;
|
---|
367 | cc = 0;
|
---|
368 | }
|
---|
369 | }
|
---|
370 | if (cc) {
|
---|
371 | clkCorr.push_back(cc);
|
---|
372 | _lastClkCorrValue[cc->_prn.toInt()] = cc->_dClk;
|
---|
373 | if (_lastClkCorrTime.undef() || cc->_time > _lastClkCorrTime) {
|
---|
374 | _lastClkCorrTime = cc->_time;
|
---|
375 | }
|
---|
376 | }
|
---|
377 | }
|
---|
378 | }
|
---|
379 | else if ( messageType == BTYPE_GPS || messageType == BTYPE_GLONASS ) {
|
---|
380 | }
|
---|
381 | }
|
---|
382 |
|
---|
383 | _pppClient->putOrbCorrections(orbCorr);
|
---|
384 | _pppClient->putClkCorrections(clkCorr);
|
---|
385 | _pppClient->putBiases(satBias);
|
---|
386 |
|
---|
387 | for (unsigned ii = 0; ii < orbCorr.size(); ii++) {
|
---|
388 | delete orbCorr[ii];
|
---|
389 | }
|
---|
390 | for (unsigned ii = 0; ii < clkCorr.size(); ii++) {
|
---|
391 | delete clkCorr[ii];
|
---|
392 | }
|
---|
393 | for (unsigned ii = 0; ii < satBias.size(); ii++) {
|
---|
394 | delete satBias[ii];
|
---|
395 | }
|
---|
396 | }
|
---|
397 |
|
---|
398 |
|
---|
399 | //
|
---|
400 | ////////////////////////////////////////////////////////////////////////////
|
---|
401 | void t_pppRun::processFiles() {
|
---|
402 |
|
---|
403 | try {
|
---|
404 | _rnxObsFile = new t_rnxObsFile(QString(_opt->_rinexObs.c_str()), t_rnxObsFile::input);
|
---|
405 | }
|
---|
406 | catch (...) {
|
---|
407 | delete _rnxObsFile; _rnxObsFile = 0;
|
---|
408 | emit finishedRnxPPP();
|
---|
409 | return;
|
---|
410 | }
|
---|
411 |
|
---|
412 | _rnxNavFile = new t_rnxNavFile(QString(_opt->_rinexNav.c_str()), t_rnxNavFile::input);
|
---|
413 |
|
---|
414 | if (!_opt->_corrFile.empty()) {
|
---|
415 | _corrFile = new t_corrFile(QString(_opt->_corrFile.c_str()));
|
---|
416 | connect(_corrFile, SIGNAL(newCorrections(QStringList)),
|
---|
417 | this, SLOT(slotNewCorrections(QStringList)));
|
---|
418 | }
|
---|
419 |
|
---|
420 | // Read/Process Observations
|
---|
421 | // -------------------------
|
---|
422 | int nEpo = 0;
|
---|
423 | const t_rnxObsFile::t_rnxEpo* epo = 0;
|
---|
424 | while ( !_stopFlag && (epo = _rnxObsFile->nextEpoch()) != 0 ) {
|
---|
425 | ++nEpo;
|
---|
426 |
|
---|
427 | if (_speed < 100) {
|
---|
428 | double sleepTime = 2.0 / _speed;
|
---|
429 | t_pppThread::msleep(sleepTime*1.e3);
|
---|
430 | }
|
---|
431 |
|
---|
432 | // Get Corrections
|
---|
433 | // ---------------
|
---|
434 | if (_corrFile) {
|
---|
435 | _corrFile->syncRead(epo->tt);
|
---|
436 | }
|
---|
437 |
|
---|
438 | // Get Ephemerides
|
---|
439 | // ----------------
|
---|
440 | t_eph* eph = 0;
|
---|
441 | const QMap<QString, int>* corrIODs = _corrFile ? &_corrFile->corrIODs() : 0;
|
---|
442 | while ( (eph = _rnxNavFile->getNextEph(epo->tt, corrIODs)) != 0 ) {
|
---|
443 | _pppClient->putEphemeris(eph);
|
---|
444 | delete eph; eph = 0;
|
---|
445 | }
|
---|
446 |
|
---|
447 | // Create list of observations and start epoch processing
|
---|
448 | // ------------------------------------------------------
|
---|
449 | QList<t_satObs> obsList;
|
---|
450 | for (unsigned iObs = 0; iObs < epo->rnxSat.size(); iObs++) {
|
---|
451 | const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iObs];
|
---|
452 |
|
---|
453 | t_satObs obs;
|
---|
454 | t_rnxObsFile::setObsFromRnx(_rnxObsFile, epo, rnxSat, obs);
|
---|
455 | obsList << obs;
|
---|
456 | }
|
---|
457 | slotNewObs(QByteArray(_opt->_roverName.c_str()), obsList);
|
---|
458 |
|
---|
459 |
|
---|
460 | if (nEpo % 10 == 0) {
|
---|
461 | emit progressRnxPPP(nEpo);
|
---|
462 | }
|
---|
463 |
|
---|
464 | QCoreApplication::processEvents();
|
---|
465 | }
|
---|
466 |
|
---|
467 | emit finishedRnxPPP();
|
---|
468 |
|
---|
469 | if (BNC_CORE->mode() != t_bncCore::interactive) {
|
---|
470 | qApp->exit(0);
|
---|
471 | }
|
---|
472 | else {
|
---|
473 | BNC_CORE->stopPPP();
|
---|
474 | }
|
---|
475 | }
|
---|
476 |
|
---|
477 | //
|
---|
478 | ////////////////////////////////////////////////////////////////////////////
|
---|
479 | void t_pppRun::slotSetSpeed(int speed) {
|
---|
480 | QMutexLocker locker(&_mutex);
|
---|
481 | _speed = speed;
|
---|
482 | }
|
---|
483 |
|
---|
484 | //
|
---|
485 | ////////////////////////////////////////////////////////////////////////////
|
---|
486 | void t_pppRun::slotSetStopFlag() {
|
---|
487 | QMutexLocker locker(&_mutex);
|
---|
488 | _stopFlag = true;
|
---|
489 | }
|
---|
490 |
|
---|
491 | //
|
---|
492 | ////////////////////////////////////////////////////////////////////////////
|
---|
493 | QString t_pppRun::nmeaString(char strType, const t_output& output) {
|
---|
494 |
|
---|
495 | double ell[3];
|
---|
496 | xyz2ell(output._xyzRover, ell);
|
---|
497 | double phiDeg = ell[0] * 180 / M_PI;
|
---|
498 | double lamDeg = ell[1] * 180 / M_PI;
|
---|
499 |
|
---|
500 | char phiCh = 'N';
|
---|
501 | if (phiDeg < 0) {
|
---|
502 | phiDeg = -phiDeg;
|
---|
503 | phiCh = 'S';
|
---|
504 | }
|
---|
505 | char lamCh = 'E';
|
---|
506 | if (lamDeg < 0) {
|
---|
507 | lamDeg = -lamDeg;
|
---|
508 | lamCh = 'W';
|
---|
509 | }
|
---|
510 |
|
---|
511 | ostringstream out;
|
---|
512 | out.setf(ios::fixed);
|
---|
513 |
|
---|
514 | if (strType == 'R') {
|
---|
515 | string datestr = output._epoTime.datestr(0); // yyyymmdd
|
---|
516 | out << "GPRMC,"
|
---|
517 | << output._epoTime.timestr(0,0) << ",A,"
|
---|
518 | << setw(2) << setfill('0') << int(phiDeg)
|
---|
519 | << setw(6) << setprecision(3) << setfill('0')
|
---|
520 | << fmod(60*phiDeg,60) << ',' << phiCh << ','
|
---|
521 | << setw(3) << setfill('0') << int(lamDeg)
|
---|
522 | << setw(6) << setprecision(3) << setfill('0')
|
---|
523 | << fmod(60*lamDeg,60) << ',' << lamCh << ",,,"
|
---|
524 | << datestr[6] << datestr[7] << datestr[4] << datestr[5]
|
---|
525 | << datestr[2] << datestr[3] << ",,";
|
---|
526 | }
|
---|
527 | else if (strType == 'G') {
|
---|
528 | out << "GPGGA,"
|
---|
529 | << output._epoTime.timestr(0,0) << ','
|
---|
530 | << setw(2) << setfill('0') << int(phiDeg)
|
---|
531 | << setw(10) << setprecision(7) << setfill('0')
|
---|
532 | << fmod(60*phiDeg,60) << ',' << phiCh << ','
|
---|
533 | << setw(3) << setfill('0') << int(lamDeg)
|
---|
534 | << setw(10) << setprecision(7) << setfill('0')
|
---|
535 | << fmod(60*lamDeg,60) << ',' << lamCh
|
---|
536 | << ",1," << setw(2) << setfill('0') << output._numSat << ','
|
---|
537 | << setw(3) << setprecision(1) << output._pDop << ','
|
---|
538 | << setprecision(3) << ell[2] << ",M,0.0,M,,";
|
---|
539 | }
|
---|
540 | else {
|
---|
541 | return "";
|
---|
542 | }
|
---|
543 |
|
---|
544 | QString nmStr(out.str().c_str());
|
---|
545 | unsigned char XOR = 0;
|
---|
546 | for (int ii = 0; ii < nmStr.length(); ii++) {
|
---|
547 | XOR ^= (unsigned char) nmStr[ii].toAscii();
|
---|
548 | }
|
---|
549 |
|
---|
550 | return '$' + nmStr + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
|
---|
551 | }
|
---|
552 |
|
---|
553 | //
|
---|
554 | ////////////////////////////////////////////////////////////////////////////
|
---|
555 | bool t_pppRun::waitForCorr(const bncTime& epoTime) const {
|
---|
556 |
|
---|
557 | if (!_opt->_realTime || _opt->_corrMount.empty()) {
|
---|
558 | return false;
|
---|
559 | }
|
---|
560 | else if (!_lastClkCorrTime.valid()) {
|
---|
561 | return true;
|
---|
562 | }
|
---|
563 | else {
|
---|
564 | double dt = epoTime - _lastClkCorrTime;
|
---|
565 | if (dt > 1.0 && dt < _opt->_corrWaitTime) {
|
---|
566 | return true;
|
---|
567 | }
|
---|
568 | else {
|
---|
569 | return false;
|
---|
570 | }
|
---|
571 | }
|
---|
572 | return false;
|
---|
573 | }
|
---|