1 | // Part of BNC, a utility for retrieving decoding and
|
---|
2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
3 | //
|
---|
4 | // Copyright (C) 2007
|
---|
5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
6 | // http://www.bkg.bund.de
|
---|
7 | // Czech Technical University Prague, Department of Geodesy
|
---|
8 | // http://www.fsv.cvut.cz
|
---|
9 | //
|
---|
10 | // Email: euref-ip@bkg.bund.de
|
---|
11 | //
|
---|
12 | // This program is free software; you can redistribute it and/or
|
---|
13 | // modify it under the terms of the GNU General Public License
|
---|
14 | // as published by the Free Software Foundation, version 2.
|
---|
15 | //
|
---|
16 | // This program is distributed in the hope that it will be useful,
|
---|
17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | // GNU General Public License for more details.
|
---|
20 | //
|
---|
21 | // You should have received a copy of the GNU General Public License
|
---|
22 | // along with this program; if not, write to the Free Software
|
---|
23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
24 |
|
---|
25 | /* -------------------------------------------------------------------------
|
---|
26 | * BKG NTRIP Client
|
---|
27 | * -------------------------------------------------------------------------
|
---|
28 | *
|
---|
29 | * Class: t_bncCore
|
---|
30 | *
|
---|
31 | * Purpose: This class implements the main application
|
---|
32 | *
|
---|
33 | * Author: L. Mervart
|
---|
34 | *
|
---|
35 | * Created: 29-Aug-2006
|
---|
36 | *
|
---|
37 | * Changes:
|
---|
38 | *
|
---|
39 | * -----------------------------------------------------------------------*/
|
---|
40 |
|
---|
41 | #include <iostream>
|
---|
42 | #include <QMessageBox>
|
---|
43 | #include <cmath>
|
---|
44 |
|
---|
45 | #include "bnccore.h"
|
---|
46 | #include "bncutils.h"
|
---|
47 | #include "bncrinex.h"
|
---|
48 | #include "bncsettings.h"
|
---|
49 | #include "bncversion.h"
|
---|
50 | #include "ephemeris.h"
|
---|
51 | #include "rinex/rnxobsfile.h"
|
---|
52 | #include "rinex/rnxnavfile.h"
|
---|
53 | #include "PPP/pppMain.h"
|
---|
54 |
|
---|
55 | #ifdef USE_COMBINATION
|
---|
56 | #include "combination/bnccomb.h"
|
---|
57 | #endif
|
---|
58 |
|
---|
59 | using namespace std;
|
---|
60 |
|
---|
61 | // Singleton
|
---|
62 | ////////////////////////////////////////////////////////////////////////////
|
---|
63 | t_bncCore* t_bncCore::instance() {
|
---|
64 | static t_bncCore _bncCore;
|
---|
65 | return &_bncCore;
|
---|
66 | }
|
---|
67 |
|
---|
68 | // Constructor
|
---|
69 | ////////////////////////////////////////////////////////////////////////////
|
---|
70 | t_bncCore::t_bncCore() {
|
---|
71 | _GUIenabled = true;
|
---|
72 | _logFileFlag = 0;
|
---|
73 | _logFile = 0;
|
---|
74 | _logStream = 0;
|
---|
75 | _rawFile = 0;
|
---|
76 | _caster = 0;
|
---|
77 | #ifdef USE_COMBINATION
|
---|
78 | _bncComb = 0;
|
---|
79 | #endif
|
---|
80 |
|
---|
81 | // Lists of Ephemeris
|
---|
82 | // ------------------
|
---|
83 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
---|
84 | _gpsEph[ii-PRN_GPS_START] = 0;
|
---|
85 | }
|
---|
86 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
---|
87 | _glonassEph[ii-PRN_GLONASS_START] = 0;
|
---|
88 | }
|
---|
89 | for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
|
---|
90 | _galileoEph[ii-PRN_GALILEO_START] = 0;
|
---|
91 | }
|
---|
92 |
|
---|
93 | // Eph file(s)
|
---|
94 | // -----------
|
---|
95 | _rinexVers = 0;
|
---|
96 | _ephFileGPS = 0;
|
---|
97 | _ephStreamGPS = 0;
|
---|
98 | _ephFileGlonass = 0;
|
---|
99 | _ephStreamGlonass = 0;
|
---|
100 | _ephFileGalileo = 0;
|
---|
101 | _ephStreamGalileo = 0;
|
---|
102 |
|
---|
103 | _port = 0;
|
---|
104 | _server = 0;
|
---|
105 | _sockets = 0;
|
---|
106 |
|
---|
107 | _portCorr = 0;
|
---|
108 | _serverCorr = 0;
|
---|
109 | _socketsCorr = 0;
|
---|
110 |
|
---|
111 | _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
|
---|
112 | #ifdef WIN32
|
---|
113 | _userName = QString("${USERNAME}");
|
---|
114 | #else
|
---|
115 | _userName = QString("${USER}");
|
---|
116 | #endif
|
---|
117 | expandEnvVar(_userName);
|
---|
118 | _userName = _userName.leftJustified(20, ' ', true);
|
---|
119 |
|
---|
120 | _corrs = new QMultiMap<bncTime, QString>;
|
---|
121 |
|
---|
122 | _dateAndTimeGPS = 0;
|
---|
123 |
|
---|
124 | for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
|
---|
125 | _GLOFreq[ii] = 0;
|
---|
126 | }
|
---|
127 |
|
---|
128 | _mainWindow = 0;
|
---|
129 |
|
---|
130 | _pppMain = new BNC_PPP::t_pppMain();
|
---|
131 | qRegisterMetaType< QVector<double> >("QVector<double>");
|
---|
132 | }
|
---|
133 |
|
---|
134 | // Destructor
|
---|
135 | ////////////////////////////////////////////////////////////////////////////
|
---|
136 | t_bncCore::~t_bncCore() {
|
---|
137 | delete _logStream;
|
---|
138 | delete _logFile;
|
---|
139 | delete _ephStreamGPS;
|
---|
140 | delete _ephFileGPS;
|
---|
141 | delete _server;
|
---|
142 | delete _sockets;
|
---|
143 | delete _serverCorr;
|
---|
144 | delete _socketsCorr;
|
---|
145 | if (_rinexVers == 2) {
|
---|
146 | delete _ephStreamGlonass;
|
---|
147 | delete _ephFileGlonass;
|
---|
148 | }
|
---|
149 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
---|
150 | delete _gpsEph[ii-PRN_GPS_START];
|
---|
151 | }
|
---|
152 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
---|
153 | delete _glonassEph[ii-PRN_GLONASS_START];
|
---|
154 | }
|
---|
155 | for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
|
---|
156 | delete _galileoEph[ii-PRN_GALILEO_START];
|
---|
157 | }
|
---|
158 |
|
---|
159 | delete _corrs;
|
---|
160 |
|
---|
161 | delete _dateAndTimeGPS;
|
---|
162 |
|
---|
163 | delete _rawFile;
|
---|
164 |
|
---|
165 | #ifdef USE_COMBINATION
|
---|
166 | delete _bncComb;
|
---|
167 | #endif
|
---|
168 | }
|
---|
169 |
|
---|
170 | // Write a Program Message
|
---|
171 | ////////////////////////////////////////////////////////////////////////////
|
---|
172 | void t_bncCore::slotMessage(QByteArray msg, bool showOnScreen) {
|
---|
173 |
|
---|
174 | QMutexLocker locker(&_mutexMessage);
|
---|
175 |
|
---|
176 | messagePrivate(msg);
|
---|
177 | emit newMessage(msg, showOnScreen);
|
---|
178 | }
|
---|
179 |
|
---|
180 | // Write a Program Message (private, no lock)
|
---|
181 | ////////////////////////////////////////////////////////////////////////////
|
---|
182 | void t_bncCore::messagePrivate(const QByteArray& msg) {
|
---|
183 |
|
---|
184 | // First time resolve the log file name
|
---|
185 | // ------------------------------------
|
---|
186 | QDate currDate = currentDateAndTimeGPS().date();
|
---|
187 | if (_logFileFlag == 0 || _fileDate != currDate) {
|
---|
188 | delete _logStream; _logStream = 0;
|
---|
189 | delete _logFile; _logFile = 0;
|
---|
190 | _logFileFlag = 1;
|
---|
191 | bncSettings settings;
|
---|
192 | QString logFileName = settings.value("logFile").toString();
|
---|
193 | if ( !logFileName.isEmpty() ) {
|
---|
194 | expandEnvVar(logFileName);
|
---|
195 | _logFile = new QFile(logFileName + "_" +
|
---|
196 | currDate.toString("yyMMdd").toAscii().data());
|
---|
197 | _fileDate = currDate;
|
---|
198 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
199 | _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
---|
200 | }
|
---|
201 | else {
|
---|
202 | _logFile->open(QIODevice::WriteOnly);
|
---|
203 | }
|
---|
204 | _logStream = new QTextStream();
|
---|
205 | _logStream->setDevice(_logFile);
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | if (_logStream) {
|
---|
210 | QByteArray msgLocal = msg;
|
---|
211 | if (msg.indexOf('\n') == 0) {
|
---|
212 | *_logStream << endl;
|
---|
213 | msgLocal = msg.mid(1);
|
---|
214 | }
|
---|
215 | *_logStream << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
|
---|
216 | *_logStream << msgLocal.data() << endl;
|
---|
217 | _logStream->flush();
|
---|
218 | _logFile->flush();
|
---|
219 | }
|
---|
220 | }
|
---|
221 |
|
---|
222 | // New GPS Ephemeris
|
---|
223 | ////////////////////////////////////////////////////////////////////////////
|
---|
224 | void t_bncCore::slotNewGPSEph(gpsephemeris* gpseph) {
|
---|
225 |
|
---|
226 | QMutexLocker locker(&_mutex);
|
---|
227 |
|
---|
228 | gpsephemeris copy_gpseph = *gpseph;
|
---|
229 | emit newEphGPS(copy_gpseph);
|
---|
230 |
|
---|
231 | printEphHeader();
|
---|
232 |
|
---|
233 | gpsephemeris** ee = &_gpsEph[gpseph->satellite-1];
|
---|
234 |
|
---|
235 | if ( *ee != 0 &&
|
---|
236 | gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC == (*ee)->TOC ) {
|
---|
237 | checkEphemeris(*ee, gpseph);
|
---|
238 | }
|
---|
239 |
|
---|
240 | if ( *ee == 0 ||
|
---|
241 | gpseph->GPSweek > (*ee)->GPSweek ||
|
---|
242 | (gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC > (*ee)->TOC) ) {
|
---|
243 | delete *ee;
|
---|
244 | *ee = gpseph;
|
---|
245 | printGPSEph(gpseph, true);
|
---|
246 | }
|
---|
247 | else {
|
---|
248 | printGPSEph(gpseph, false);
|
---|
249 | delete gpseph;
|
---|
250 | }
|
---|
251 | }
|
---|
252 |
|
---|
253 | // New Glonass Ephemeris
|
---|
254 | ////////////////////////////////////////////////////////////////////////////
|
---|
255 | void t_bncCore::slotNewGlonassEph(glonassephemeris* glonasseph, const QString& staID) {
|
---|
256 |
|
---|
257 | QMutexLocker locker(&_mutex);
|
---|
258 |
|
---|
259 | // Check wrong Ephemerides
|
---|
260 | // -----------------------
|
---|
261 | if (glonasseph->x_pos == 0.0 &&
|
---|
262 | glonasseph->y_pos == 0.0 &&
|
---|
263 | glonasseph->z_pos == 0.0) {
|
---|
264 | delete glonasseph;
|
---|
265 | return;
|
---|
266 | }
|
---|
267 |
|
---|
268 | glonassephemeris copy_glonasseph = *glonasseph;
|
---|
269 | emit newEphGlonass(copy_glonasseph);
|
---|
270 |
|
---|
271 | printEphHeader();
|
---|
272 |
|
---|
273 | glonassephemeris** ee = &_glonassEph[glonasseph->almanac_number-1];
|
---|
274 |
|
---|
275 | int wwOld, towOld, wwNew, towNew;
|
---|
276 | if (*ee != 0) {
|
---|
277 | wwOld = (*ee)->GPSWeek;
|
---|
278 | towOld = (*ee)->GPSTOW;
|
---|
279 | updatetime(&wwOld, &towOld, (*ee)->tb*1000, 0); // Moscow -> GPS
|
---|
280 |
|
---|
281 | wwNew = glonasseph->GPSWeek;
|
---|
282 | towNew = glonasseph->GPSTOW;
|
---|
283 | updatetime(&wwNew, &towNew, glonasseph->tb*1000, 0); // Moscow -> GPS
|
---|
284 | }
|
---|
285 |
|
---|
286 | if ( *ee == 0 ||
|
---|
287 | wwNew > wwOld ||
|
---|
288 | (wwNew == wwOld && towNew > towOld) ) {
|
---|
289 | delete *ee;
|
---|
290 | *ee = glonasseph;
|
---|
291 | printGlonassEph(glonasseph, true, staID);
|
---|
292 | }
|
---|
293 | else {
|
---|
294 | printGlonassEph(glonasseph, false, staID);
|
---|
295 | delete glonasseph;
|
---|
296 | }
|
---|
297 | }
|
---|
298 |
|
---|
299 | // New Galileo Ephemeris
|
---|
300 | ////////////////////////////////////////////////////////////////////////////
|
---|
301 | void t_bncCore::slotNewGalileoEph(galileoephemeris* galileoeph) {
|
---|
302 |
|
---|
303 | QMutexLocker locker(&_mutex);
|
---|
304 |
|
---|
305 | galileoephemeris copy_galileoeph = *galileoeph;
|
---|
306 | emit newEphGalileo(copy_galileoeph);
|
---|
307 |
|
---|
308 | printEphHeader();
|
---|
309 |
|
---|
310 | int galIndex = galileoeph->satellite;
|
---|
311 | /* GIOVE */
|
---|
312 | if(galIndex == 51) galIndex = 1;
|
---|
313 | else if(galIndex == 52) galIndex = 16;
|
---|
314 | if (galIndex < 0 || galIndex > PRN_GALILEO_END - PRN_GALILEO_START) {
|
---|
315 | emit( newMessage("Wrong Galileo Satellite Number", true) );
|
---|
316 | exit(1);
|
---|
317 | }
|
---|
318 |
|
---|
319 | galileoephemeris** ee = &_galileoEph[galIndex];
|
---|
320 |
|
---|
321 | if ( *ee == 0 ||
|
---|
322 | galileoeph->Week > (*ee)->Week ||
|
---|
323 | (galileoeph->Week == (*ee)->Week && galileoeph->TOC > (*ee)->TOC) ) {
|
---|
324 | delete *ee;
|
---|
325 | *ee = galileoeph;
|
---|
326 | printGalileoEph(galileoeph, true);
|
---|
327 | }
|
---|
328 | else {
|
---|
329 | printGalileoEph(galileoeph, false);
|
---|
330 | delete galileoeph;
|
---|
331 | }
|
---|
332 | }
|
---|
333 |
|
---|
334 | // Print Header of the output File(s)
|
---|
335 | ////////////////////////////////////////////////////////////////////////////
|
---|
336 | void t_bncCore::printEphHeader() {
|
---|
337 |
|
---|
338 | bncSettings settings;
|
---|
339 |
|
---|
340 | // Initialization
|
---|
341 | // --------------
|
---|
342 | if (_rinexVers == 0) {
|
---|
343 |
|
---|
344 | if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
|
---|
345 | _rinexVers = 3;
|
---|
346 | }
|
---|
347 | else {
|
---|
348 | _rinexVers = 2;
|
---|
349 | }
|
---|
350 |
|
---|
351 | _ephPath = settings.value("ephPath").toString();
|
---|
352 |
|
---|
353 | if ( !_ephPath.isEmpty() ) {
|
---|
354 | if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
|
---|
355 | _ephPath += QDir::separator();
|
---|
356 | }
|
---|
357 | expandEnvVar(_ephPath);
|
---|
358 | }
|
---|
359 | }
|
---|
360 |
|
---|
361 | // (Re-)Open output File(s)
|
---|
362 | // ------------------------
|
---|
363 | if (!_ephPath.isEmpty()) {
|
---|
364 |
|
---|
365 | QDateTime datTim = currentDateAndTimeGPS();
|
---|
366 |
|
---|
367 | QString ephFileNameGPS = _ephPath + "BRDC" +
|
---|
368 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'));
|
---|
369 |
|
---|
370 | QString hlpStr = bncRinex::nextEpochStr(datTim,
|
---|
371 | settings.value("ephIntr").toString());
|
---|
372 |
|
---|
373 | if (_rinexVers == 3) {
|
---|
374 | ephFileNameGPS += hlpStr + datTim.toString(".yyP");
|
---|
375 | }
|
---|
376 | else {
|
---|
377 | ephFileNameGPS += hlpStr + datTim.toString(".yyN");
|
---|
378 | }
|
---|
379 |
|
---|
380 | if (_ephFileNameGPS == ephFileNameGPS) {
|
---|
381 | return;
|
---|
382 | }
|
---|
383 | else {
|
---|
384 | _ephFileNameGPS = ephFileNameGPS;
|
---|
385 | }
|
---|
386 |
|
---|
387 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
---|
388 | delete _gpsEph[ii-PRN_GPS_START];
|
---|
389 | _gpsEph[ii-PRN_GPS_START] = 0;
|
---|
390 | }
|
---|
391 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
---|
392 | delete _glonassEph[ii-PRN_GLONASS_START];
|
---|
393 | _glonassEph[ii-PRN_GLONASS_START] = 0;
|
---|
394 | }
|
---|
395 | for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
|
---|
396 | delete _galileoEph[ii-PRN_GALILEO_START];
|
---|
397 | _galileoEph[ii-PRN_GALILEO_START] = 0;
|
---|
398 | }
|
---|
399 |
|
---|
400 | delete _ephStreamGPS;
|
---|
401 | delete _ephFileGPS;
|
---|
402 |
|
---|
403 | QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
|
---|
404 | QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
|
---|
405 | QFlags<QIODevice::OpenModeFlag> appendFlagGalileo;
|
---|
406 |
|
---|
407 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
---|
408 | QFile::exists(ephFileNameGPS) ) {
|
---|
409 | appendFlagGPS = QIODevice::Append;
|
---|
410 | }
|
---|
411 |
|
---|
412 | _ephFileGPS = new QFile(ephFileNameGPS);
|
---|
413 | _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
|
---|
414 | _ephStreamGPS = new QTextStream();
|
---|
415 | _ephStreamGPS->setDevice(_ephFileGPS);
|
---|
416 |
|
---|
417 | if (_rinexVers == 3) {
|
---|
418 | _ephFileGlonass = _ephFileGPS;
|
---|
419 | _ephStreamGlonass = _ephStreamGPS;
|
---|
420 | _ephFileGalileo = _ephFileGPS;
|
---|
421 | _ephStreamGalileo = _ephStreamGPS;
|
---|
422 | }
|
---|
423 | else if (_rinexVers == 2) {
|
---|
424 | QString ephFileNameGlonass = _ephPath + "BRDC" +
|
---|
425 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
426 | hlpStr + datTim.toString(".yyG");
|
---|
427 |
|
---|
428 | delete _ephStreamGlonass;
|
---|
429 | delete _ephFileGlonass;
|
---|
430 |
|
---|
431 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
---|
432 | QFile::exists(ephFileNameGlonass) ) {
|
---|
433 | appendFlagGlonass = QIODevice::Append;
|
---|
434 | }
|
---|
435 |
|
---|
436 | _ephFileGlonass = new QFile(ephFileNameGlonass);
|
---|
437 | _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
|
---|
438 | _ephStreamGlonass = new QTextStream();
|
---|
439 | _ephStreamGlonass->setDevice(_ephFileGlonass);
|
---|
440 | }
|
---|
441 |
|
---|
442 | // Header - RINEX Version 3
|
---|
443 | // ------------------------
|
---|
444 | if (_rinexVers == 3) {
|
---|
445 | if ( ! (appendFlagGPS & QIODevice::Append)) {
|
---|
446 | QString line;
|
---|
447 | line.sprintf(
|
---|
448 | "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
|
---|
449 | 3.0, "", "");
|
---|
450 | *_ephStreamGPS << line;
|
---|
451 |
|
---|
452 | QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
|
---|
453 | *_ephStreamGPS << _pgmName.toAscii().data()
|
---|
454 | << _userName.toAscii().data()
|
---|
455 | << hlp.toAscii().data()
|
---|
456 | << "PGM / RUN BY / DATE" << endl;
|
---|
457 |
|
---|
458 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
459 | *_ephStreamGPS << line;
|
---|
460 |
|
---|
461 | _ephStreamGPS->flush();
|
---|
462 | }
|
---|
463 | }
|
---|
464 |
|
---|
465 | // Headers - RINEX Version 2
|
---|
466 | // -------------------------
|
---|
467 | else if (_rinexVers == 2) {
|
---|
468 | if (! (appendFlagGPS & QIODevice::Append)) {
|
---|
469 | QString line;
|
---|
470 | line.sprintf("%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n",
|
---|
471 | t_rnxNavFile::defaultRnxNavVersion2, "", "");
|
---|
472 | *_ephStreamGPS << line;
|
---|
473 |
|
---|
474 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
475 | *_ephStreamGPS << _pgmName.toAscii().data()
|
---|
476 | << _userName.toAscii().data()
|
---|
477 | << hlp.toAscii().data()
|
---|
478 | << "PGM / RUN BY / DATE" << endl;
|
---|
479 |
|
---|
480 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
481 | *_ephStreamGPS << line;
|
---|
482 |
|
---|
483 | _ephStreamGPS->flush();
|
---|
484 | }
|
---|
485 | if (! (appendFlagGlonass & QIODevice::Append)) {
|
---|
486 | QString line;
|
---|
487 | line.sprintf("%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",
|
---|
488 | t_rnxNavFile::defaultRnxNavVersion2, "", "");
|
---|
489 | *_ephStreamGlonass << line;
|
---|
490 |
|
---|
491 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
492 | *_ephStreamGlonass << _pgmName.toAscii().data()
|
---|
493 | << _userName.toAscii().data()
|
---|
494 | << hlp.toAscii().data()
|
---|
495 | << "PGM / RUN BY / DATE" << endl;
|
---|
496 |
|
---|
497 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
498 | *_ephStreamGlonass << line;
|
---|
499 |
|
---|
500 | _ephStreamGlonass->flush();
|
---|
501 | }
|
---|
502 | }
|
---|
503 | }
|
---|
504 | }
|
---|
505 |
|
---|
506 | // Print One GPS Ephemeris
|
---|
507 | ////////////////////////////////////////////////////////////////////////////
|
---|
508 | void t_bncCore::printGPSEph(gpsephemeris* ep, bool printFile) {
|
---|
509 |
|
---|
510 | t_ephGPS eph;
|
---|
511 | eph.set(ep);
|
---|
512 |
|
---|
513 | QString strV2 = eph.toString(t_rnxNavFile::defaultRnxNavVersion2);
|
---|
514 | QString strV3 = eph.toString(t_rnxObsHeader::defaultRnxObsVersion3);
|
---|
515 |
|
---|
516 | printOutput(printFile, _ephStreamGPS, strV2, strV3);
|
---|
517 | }
|
---|
518 |
|
---|
519 | // Print One Glonass Ephemeris
|
---|
520 | ////////////////////////////////////////////////////////////////////////////
|
---|
521 | void t_bncCore::printGlonassEph(glonassephemeris* ep, bool printFile, const QString& /* staID */) {
|
---|
522 |
|
---|
523 | t_ephGlo eph;
|
---|
524 | eph.set(ep);
|
---|
525 |
|
---|
526 | QString strV2 = eph.toString(t_rnxNavFile::defaultRnxNavVersion2);
|
---|
527 | QString strV3 = eph.toString(t_rnxObsHeader::defaultRnxObsVersion3);
|
---|
528 |
|
---|
529 | //// beg test Dirk
|
---|
530 | // QString hlp = strV2;
|
---|
531 | // cout << hlp.replace('\n', ' ').toAscii().data() << ' ' << staID.toAscii().data() << endl;
|
---|
532 | //// end test Dirk
|
---|
533 |
|
---|
534 | printOutput(printFile, _ephStreamGlonass, strV2, strV3);
|
---|
535 | }
|
---|
536 |
|
---|
537 | // Print One Galileo Ephemeris
|
---|
538 | ////////////////////////////////////////////////////////////////////////////
|
---|
539 | void t_bncCore::printGalileoEph(galileoephemeris* ep, bool printFile) {
|
---|
540 |
|
---|
541 | t_ephGal eph;
|
---|
542 | eph.set(ep);
|
---|
543 |
|
---|
544 | QString strV2 = eph.toString(t_rnxNavFile::defaultRnxNavVersion2);
|
---|
545 | QString strV3 = eph.toString(t_rnxObsHeader::defaultRnxObsVersion3);
|
---|
546 |
|
---|
547 | printOutput(printFile, _ephStreamGalileo, strV2, strV3);
|
---|
548 | }
|
---|
549 |
|
---|
550 | // Output
|
---|
551 | ////////////////////////////////////////////////////////////////////////////
|
---|
552 | void t_bncCore::printOutput(bool printFile, QTextStream* stream,
|
---|
553 | const QString& strV2, const QString& strV3) {
|
---|
554 |
|
---|
555 | // Output into file
|
---|
556 | // ----------------
|
---|
557 | if (printFile && stream) {
|
---|
558 | if (_rinexVers == 2) {
|
---|
559 | *stream << strV2.toAscii();
|
---|
560 | }
|
---|
561 | else {
|
---|
562 | *stream << strV3.toAscii();
|
---|
563 | }
|
---|
564 | stream->flush();
|
---|
565 | }
|
---|
566 |
|
---|
567 | // Output into the socket
|
---|
568 | // ----------------------
|
---|
569 | if (_sockets) {
|
---|
570 | QMutableListIterator<QTcpSocket*> is(*_sockets);
|
---|
571 | while (is.hasNext()) {
|
---|
572 | QTcpSocket* sock = is.next();
|
---|
573 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
574 | if (sock->write(strV3.toAscii()) == -1) {
|
---|
575 | delete sock;
|
---|
576 | is.remove();
|
---|
577 | }
|
---|
578 | }
|
---|
579 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
580 | delete sock;
|
---|
581 | is.remove();
|
---|
582 | }
|
---|
583 | }
|
---|
584 | }
|
---|
585 | }
|
---|
586 |
|
---|
587 | // Set Port Number
|
---|
588 | ////////////////////////////////////////////////////////////////////////////
|
---|
589 | void t_bncCore::setPort(int port) {
|
---|
590 | _port = port;
|
---|
591 | if (_port != 0) {
|
---|
592 | delete _server;
|
---|
593 | _server = new QTcpServer;
|
---|
594 | if ( !_server->listen(QHostAddress::Any, _port) ) {
|
---|
595 | slotMessage("t_bncCore: Cannot listen on ephemeris port", true);
|
---|
596 | }
|
---|
597 | connect(_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
|
---|
598 | delete _sockets;
|
---|
599 | _sockets = new QList<QTcpSocket*>;
|
---|
600 | }
|
---|
601 | }
|
---|
602 |
|
---|
603 | // Set Port Number
|
---|
604 | ////////////////////////////////////////////////////////////////////////////
|
---|
605 | void t_bncCore::setPortCorr(int port) {
|
---|
606 | _portCorr = port;
|
---|
607 | if (_portCorr != 0) {
|
---|
608 | delete _serverCorr;
|
---|
609 | _serverCorr = new QTcpServer;
|
---|
610 | if ( !_serverCorr->listen(QHostAddress::Any, _portCorr) ) {
|
---|
611 | slotMessage("t_bncCore: Cannot listen on correction port", true);
|
---|
612 | }
|
---|
613 | connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
|
---|
614 | delete _socketsCorr;
|
---|
615 | _socketsCorr = new QList<QTcpSocket*>;
|
---|
616 | }
|
---|
617 | }
|
---|
618 |
|
---|
619 | // New Connection
|
---|
620 | ////////////////////////////////////////////////////////////////////////////
|
---|
621 | void t_bncCore::slotNewConnection() {
|
---|
622 | _sockets->push_back( _server->nextPendingConnection() );
|
---|
623 | }
|
---|
624 |
|
---|
625 | // New Connection
|
---|
626 | ////////////////////////////////////////////////////////////////////////////
|
---|
627 | void t_bncCore::slotNewConnectionCorr() {
|
---|
628 | _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
|
---|
629 | }
|
---|
630 |
|
---|
631 | //
|
---|
632 | ////////////////////////////////////////////////////////////////////////////
|
---|
633 | void t_bncCore::slotQuit() {
|
---|
634 | cout << "t_bncCore::slotQuit" << endl;
|
---|
635 | delete _caster; _caster = 0;
|
---|
636 | qApp->quit();
|
---|
637 | }
|
---|
638 |
|
---|
639 | //
|
---|
640 | ////////////////////////////////////////////////////////////////////////////
|
---|
641 | void t_bncCore::slotNewCorrLine(QString line, QString staID, bncTime coTime) {
|
---|
642 |
|
---|
643 | QMutexLocker locker(&_mutex);
|
---|
644 |
|
---|
645 | // Combination of Corrections
|
---|
646 | // --------------------------
|
---|
647 | #ifdef USE_COMBINATION
|
---|
648 | if (_bncComb) {
|
---|
649 | _bncComb->processCorrLine(staID, line);
|
---|
650 | }
|
---|
651 | #endif
|
---|
652 |
|
---|
653 | bncSettings settings;
|
---|
654 | _waitCoTime = settings.value("corrTime").toDouble();
|
---|
655 | if (_waitCoTime < 0.0) {
|
---|
656 | _waitCoTime = 0.0;
|
---|
657 | }
|
---|
658 |
|
---|
659 | // First time, set the _lastCorrDumpTime
|
---|
660 | // -------------------------------------
|
---|
661 | if (!_lastCorrDumpTime[staID].valid()) {
|
---|
662 | _lastCorrDumpTime[staID] = coTime - 1.0;
|
---|
663 | }
|
---|
664 |
|
---|
665 | // An old correction - throw it away
|
---|
666 | // ---------------------------------
|
---|
667 | if (_waitCoTime > 0.0 && coTime <= _lastCorrDumpTime[staID]) {
|
---|
668 | if (!_bncComb) {
|
---|
669 | QString line = staID + ": Correction for one sat neglected because overaged by " +
|
---|
670 | QString().sprintf(" %f sec",
|
---|
671 | _lastCorrDumpTime[staID] - coTime + _waitCoTime);
|
---|
672 | messagePrivate(line.toAscii());
|
---|
673 | emit( newMessage(line.toAscii(), true) );
|
---|
674 | }
|
---|
675 | return;
|
---|
676 | }
|
---|
677 |
|
---|
678 | _corrs->insert(coTime, QString(line + " " + staID));
|
---|
679 |
|
---|
680 | // Dump Corrections
|
---|
681 | // ----------------
|
---|
682 | if (_waitCoTime == 0.0) {
|
---|
683 | dumpCorrs();
|
---|
684 | }
|
---|
685 | else if (coTime - _waitCoTime > _lastCorrDumpTime[staID]) {
|
---|
686 | dumpCorrs(_lastCorrDumpTime[staID] + 1, coTime - _waitCoTime);
|
---|
687 | _lastCorrDumpTime[staID] = coTime - _waitCoTime;
|
---|
688 | }
|
---|
689 | }
|
---|
690 |
|
---|
691 | // Dump Complete Correction Epochs
|
---|
692 | ////////////////////////////////////////////////////////////////////////////
|
---|
693 | void t_bncCore::dumpCorrs(bncTime minTime, bncTime maxTime) {
|
---|
694 | QStringList allCorrs;
|
---|
695 | QMutableMapIterator<bncTime, QString> it(*_corrs);
|
---|
696 | while (it.hasNext()) {
|
---|
697 | it.next();
|
---|
698 | const bncTime& corrTime = it.key();
|
---|
699 | if (minTime <= corrTime && corrTime <= maxTime) {
|
---|
700 | allCorrs << it.value();
|
---|
701 | it.remove();
|
---|
702 | }
|
---|
703 | }
|
---|
704 | dumpCorrs(allCorrs);
|
---|
705 | }
|
---|
706 |
|
---|
707 | // Dump all corrections
|
---|
708 | ////////////////////////////////////////////////////////////////////////////
|
---|
709 | void t_bncCore::dumpCorrs() {
|
---|
710 | QStringList allCorrs;
|
---|
711 | QMutableMapIterator<bncTime, QString> it(*_corrs);
|
---|
712 | while (it.hasNext()) {
|
---|
713 | allCorrs << it.next().value();
|
---|
714 | it.remove();
|
---|
715 | }
|
---|
716 | dumpCorrs(allCorrs);
|
---|
717 | }
|
---|
718 |
|
---|
719 | // Dump List of Corrections
|
---|
720 | ////////////////////////////////////////////////////////////////////////////
|
---|
721 | void t_bncCore::dumpCorrs(const QStringList& allCorrs) {
|
---|
722 | emit newCorrections(allCorrs);
|
---|
723 | if (_socketsCorr) {
|
---|
724 | QListIterator<QString> it(allCorrs);
|
---|
725 | while (it.hasNext()) {
|
---|
726 | QString corrLine = it.next() + "\n";
|
---|
727 |
|
---|
728 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
729 | while (is.hasNext()) {
|
---|
730 | QTcpSocket* sock = is.next();
|
---|
731 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
732 | if (sock->write(corrLine.toAscii()) == -1) {
|
---|
733 | delete sock;
|
---|
734 | is.remove();
|
---|
735 | }
|
---|
736 | }
|
---|
737 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
738 | delete sock;
|
---|
739 | is.remove();
|
---|
740 | }
|
---|
741 | }
|
---|
742 | }
|
---|
743 | }
|
---|
744 | }
|
---|
745 |
|
---|
746 | //
|
---|
747 | ////////////////////////////////////////////////////////////////////////////
|
---|
748 | void t_bncCore::setConfFileName(const QString& confFileName) {
|
---|
749 | if (confFileName.isEmpty()) {
|
---|
750 | _confFileName = QDir::homePath() + QDir::separator()
|
---|
751 | + ".config" + QDir::separator()
|
---|
752 | + qApp->organizationName() + QDir::separator()
|
---|
753 | + qApp->applicationName() + ".bnc";
|
---|
754 | }
|
---|
755 | else {
|
---|
756 | _confFileName = confFileName;
|
---|
757 | }
|
---|
758 | }
|
---|
759 |
|
---|
760 | // Raw Output
|
---|
761 | ////////////////////////////////////////////////////////////////////////////
|
---|
762 | void t_bncCore::writeRawData(const QByteArray& data, const QByteArray& staID,
|
---|
763 | const QByteArray& format) {
|
---|
764 |
|
---|
765 | QMutexLocker locker(&_mutex);
|
---|
766 |
|
---|
767 | if (!_rawFile) {
|
---|
768 | bncSettings settings;
|
---|
769 | QByteArray fileName = settings.value("rawOutFile").toByteArray();
|
---|
770 | if (!fileName.isEmpty()) {
|
---|
771 | _rawFile = new bncRawFile(fileName, staID, bncRawFile::output);
|
---|
772 | }
|
---|
773 | }
|
---|
774 |
|
---|
775 | if (_rawFile) {
|
---|
776 | _rawFile->writeRawData(data, staID, format);
|
---|
777 | }
|
---|
778 | }
|
---|
779 |
|
---|
780 | // Get Glonass Slot Numbers from Global Array
|
---|
781 | ////////////////////////////////////////////////////////////////////////////
|
---|
782 | void t_bncCore::getGlonassSlotNums(int GLOFreq[]) {
|
---|
783 |
|
---|
784 | QMutexLocker locker(&_mutex);
|
---|
785 |
|
---|
786 | for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
|
---|
787 | if (_GLOFreq[ii] != 0) {
|
---|
788 | GLOFreq[ii] = _GLOFreq[ii];
|
---|
789 | }
|
---|
790 | }
|
---|
791 | }
|
---|
792 |
|
---|
793 | // Store Glonass Slot Numbers to Global Array
|
---|
794 | ////////////////////////////////////////////////////////////////////////////
|
---|
795 | void t_bncCore::storeGlonassSlotNums(const int GLOFreq[]) {
|
---|
796 |
|
---|
797 | QMutexLocker locker(&_mutex);
|
---|
798 |
|
---|
799 | for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
|
---|
800 | if (GLOFreq[ii] != 0) {
|
---|
801 | _GLOFreq[ii] = GLOFreq[ii];
|
---|
802 | }
|
---|
803 | }
|
---|
804 | }
|
---|
805 |
|
---|
806 | //
|
---|
807 | ////////////////////////////////////////////////////////////////////////////
|
---|
808 | void t_bncCore::initCombination() {
|
---|
809 | #ifdef USE_COMBINATION
|
---|
810 | _bncComb = new bncComb();
|
---|
811 | if (_bncComb->nStreams() < 1) {
|
---|
812 | delete _bncComb;
|
---|
813 | _bncComb = 0;
|
---|
814 | }
|
---|
815 | #endif
|
---|
816 | }
|
---|
817 |
|
---|
818 | //
|
---|
819 | ////////////////////////////////////////////////////////////////////////////
|
---|
820 | void t_bncCore::stopCombination() {
|
---|
821 | #ifdef USE_COMBINATION
|
---|
822 | delete _bncComb;
|
---|
823 | _bncComb = 0;
|
---|
824 | #endif
|
---|
825 | }
|
---|
826 |
|
---|
827 | // Check Ephemeris Consistency
|
---|
828 | ////////////////////////////////////////////////////////////////////////////
|
---|
829 | void t_bncCore::checkEphemeris(gpsephemeris* oldEph, gpsephemeris* newEph) {
|
---|
830 | if (oldEph->clock_bias != newEph->clock_bias ||
|
---|
831 | oldEph->clock_drift != newEph->clock_drift ||
|
---|
832 | oldEph->clock_driftrate != newEph->clock_driftrate) {
|
---|
833 | QString msg = currentDateAndTimeGPS().toString(Qt::ISODate) +
|
---|
834 | QString(" %1 EPH DIFFERS\n").arg(oldEph->satellite);
|
---|
835 | messagePrivate(msg.toAscii());
|
---|
836 | }
|
---|
837 | }
|
---|
838 |
|
---|
839 |
|
---|
840 | //
|
---|
841 | ////////////////////////////////////////////////////////////////////////////
|
---|
842 | bool t_bncCore::dateAndTimeGPSSet() const {
|
---|
843 | QMutexLocker locker(&_mutexDateAndTimeGPS);
|
---|
844 | if (_dateAndTimeGPS) {
|
---|
845 | return true;
|
---|
846 | }
|
---|
847 | else {
|
---|
848 | return false;
|
---|
849 | }
|
---|
850 | }
|
---|
851 |
|
---|
852 | //
|
---|
853 | ////////////////////////////////////////////////////////////////////////////
|
---|
854 | QDateTime t_bncCore::dateAndTimeGPS() const {
|
---|
855 | QMutexLocker locker(&_mutexDateAndTimeGPS);
|
---|
856 | if (_dateAndTimeGPS) {
|
---|
857 | return *_dateAndTimeGPS;
|
---|
858 | }
|
---|
859 | else {
|
---|
860 | return QDateTime();
|
---|
861 | }
|
---|
862 | }
|
---|
863 |
|
---|
864 | //
|
---|
865 | ////////////////////////////////////////////////////////////////////////////
|
---|
866 | void t_bncCore::setDateAndTimeGPS(QDateTime dateTime) {
|
---|
867 | QMutexLocker locker(&_mutexDateAndTimeGPS);
|
---|
868 | delete _dateAndTimeGPS;
|
---|
869 | _dateAndTimeGPS = new QDateTime(dateTime);
|
---|
870 | }
|
---|
871 |
|
---|
872 | //
|
---|
873 | ////////////////////////////////////////////////////////////////////////////
|
---|
874 | void t_bncCore::startPPP(bool ownThread) {
|
---|
875 | _pppMain->start(ownThread);
|
---|
876 | }
|
---|
877 |
|
---|
878 | //
|
---|
879 | ////////////////////////////////////////////////////////////////////////////
|
---|
880 | void t_bncCore::stopPPP() {
|
---|
881 | _pppMain->stop();
|
---|
882 | }
|
---|