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

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