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

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