source: ntrip/trunk/BNC/src/bncapp.cpp@ 4997

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