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

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