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

Last change on this file since 4747 was 4747, checked in by mervart, 10 years ago
File size: 23.0 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 // 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
261 glonassephemeris copy_glonasseph = *glonasseph;
262 emit newEphGlonass(copy_glonasseph);
263
264 printEphHeader();
265
266 glonassephemeris** ee = &_glonassEph[glonasseph->almanac_number-1];
267
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
279 if ( *ee == 0 ||
280 wwNew > wwOld ||
281 (wwNew == wwOld && towNew > towOld) ) {
282 delete *ee;
283 *ee = glonasseph;
284 printGlonassEph(glonasseph, true);
285 }
286 else {
287 printGlonassEph(glonasseph, false);
288 delete glonasseph;
289 }
290}
291
292// New Galileo Ephemeris
293////////////////////////////////////////////////////////////////////////////
294void bncApp::slotNewGalileoEph(galileoephemeris* galileoeph) {
295
296 QMutexLocker locker(&_mutex);
297
298 galileoephemeris copy_galileoeph = *galileoeph;
299 emit newEphGalileo(copy_galileoeph);
300
301 printEphHeader();
302
303 int galIndex = galileoeph->satellite;
304 /* GIOVE */
305 if(galIndex == 51) galIndex = 1;
306 else if(galIndex == 52) galIndex = 16;
307 if (galIndex < 0 || galIndex > PRN_GALILEO_END - PRN_GALILEO_START) {
308 emit( newMessage("Wrong Galileo Satellite Number", true) );
309 exit(1);
310 }
311
312 galileoephemeris** ee = &_galileoEph[galIndex];
313
314 if ( *ee == 0 ||
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 }
325}
326
327// Print Header of the output File(s)
328////////////////////////////////////////////////////////////////////////////
329void bncApp::printEphHeader() {
330
331 bncSettings settings;
332
333 // Initialization
334 // --------------
335 if (_rinexVers == 0) {
336
337 if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
338 _rinexVers = 3;
339 }
340 else {
341 _rinexVers = 2;
342 }
343
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 }
352 }
353
354 // (Re-)Open output File(s)
355 // ------------------------
356 if (!_ephPath.isEmpty()) {
357
358 QDateTime datTim = currentDateAndTimeGPS();
359
360 QString ephFileNameGPS = _ephPath + "BRDC" +
361 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'));
362
363 QString hlpStr = bncRinex::nextEpochStr(datTim,
364 settings.value("ephIntr").toString());
365
366 if (_rinexVers == 3) {
367 ephFileNameGPS += hlpStr + datTim.toString(".yyP");
368 }
369 else {
370 ephFileNameGPS += hlpStr + datTim.toString(".yyN");
371 }
372
373 if (_ephFileNameGPS == ephFileNameGPS) {
374 return;
375 }
376 else {
377 _ephFileNameGPS = ephFileNameGPS;
378 }
379
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 }
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 }
392
393 delete _ephStreamGPS;
394 delete _ephFileGPS;
395
396 QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
397 QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
398 QFlags<QIODevice::OpenModeFlag> appendFlagGalileo;
399
400 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
401 QFile::exists(ephFileNameGPS) ) {
402 appendFlagGPS = QIODevice::Append;
403 }
404
405 _ephFileGPS = new QFile(ephFileNameGPS);
406 _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
407 _ephStreamGPS = new QTextStream();
408 _ephStreamGPS->setDevice(_ephFileGPS);
409
410 if (_rinexVers == 3) {
411 _ephFileGlonass = _ephFileGPS;
412 _ephStreamGlonass = _ephStreamGPS;
413 _ephFileGalileo = _ephFileGPS;
414 _ephStreamGalileo = _ephStreamGPS;
415 }
416 else if (_rinexVers == 2) {
417 QString ephFileNameGlonass = _ephPath + "BRDC" +
418 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
419 hlpStr + datTim.toString(".yyG");
420
421 delete _ephStreamGlonass;
422 delete _ephFileGlonass;
423
424 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
425 QFile::exists(ephFileNameGlonass) ) {
426 appendFlagGlonass = QIODevice::Append;
427 }
428
429 _ephFileGlonass = new QFile(ephFileNameGlonass);
430 _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
431 _ephStreamGlonass = new QTextStream();
432 _ephStreamGlonass->setDevice(_ephFileGlonass);
433 }
434
435 // Header - RINEX Version 3
436 // ------------------------
437 if (_rinexVers == 3) {
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
445 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
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", "");
452 *_ephStreamGPS << line;
453
454 _ephStreamGPS->flush();
455 }
456 }
457
458 // Headers - RINEX Version 2
459 // -------------------------
460 else if (_rinexVers == 2) {
461 if (! (appendFlagGPS & QIODevice::Append)) {
462 QString line;
463 line.sprintf(
464 "%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n", 2.10, "", "");
465 *_ephStreamGPS << line;
466
467 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
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", "");
474 *_ephStreamGPS << line;
475
476 _ephStreamGPS->flush();
477 }
478 if (! (appendFlagGlonass & QIODevice::Append)) {
479 QString line;
480 line.sprintf(
481 "%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",2.10,"","");
482 *_ephStreamGlonass << line;
483
484 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
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", "");
491 *_ephStreamGlonass << line;
492
493 _ephStreamGlonass->flush();
494 }
495 }
496 }
497}
498
499// Print One GPS Ephemeris
500////////////////////////////////////////////////////////////////////////////
501void bncApp::printGPSEph(gpsephemeris* ep, bool printFile) {
502
503 t_ephGPS eph;
504 eph.set(ep);
505
506 QString strV2 = eph.toString(2.11);
507 QString strV3 = eph.toString(3.01);
508
509 printOutput(printFile, _ephStreamGPS, strV2, strV3);
510}
511
512// Print One Glonass Ephemeris
513////////////////////////////////////////////////////////////////////////////
514void bncApp::printGlonassEph(glonassephemeris* ep, bool printFile) {
515
516 t_ephGlo eph;
517 eph.set(ep);
518
519 QString strV2 = eph.toString(2.11);
520 QString strV3 = eph.toString(3.01);
521
522 printOutput(printFile, _ephStreamGlonass, strV2, strV3);
523}
524
525// Print One Galileo Ephemeris
526////////////////////////////////////////////////////////////////////////////
527void bncApp::printGalileoEph(galileoephemeris* ep, bool printFile) {
528
529 t_ephGal eph;
530 eph.set(ep);
531
532 QString strV2 = eph.toString(2.11);
533 QString strV3 = eph.toString(3.01);
534
535 printOutput(printFile, _ephStreamGalileo, strV2, strV3);
536}
537
538// Output
539////////////////////////////////////////////////////////////////////////////
540void bncApp::printOutput(bool printFile, QTextStream* stream,
541 const QString& strV2, const QString& strV3) {
542
543 // Output into file
544 // ----------------
545 if (printFile && stream) {
546 if (_rinexVers == 2) {
547 *stream << strV2.toAscii();
548 }
549 else {
550 *stream << strV3.toAscii();
551 }
552 stream->flush();
553 }
554
555 // Output into the socket
556 // ----------------------
557 if (_sockets) {
558 QMutableListIterator<QTcpSocket*> is(*_sockets);
559 while (is.hasNext()) {
560 QTcpSocket* sock = is.next();
561 if (sock->state() == QAbstractSocket::ConnectedState) {
562 if (sock->write(strV3.toAscii()) == -1) {
563 delete sock;
564 is.remove();
565 }
566 }
567 else if (sock->state() != QAbstractSocket::ConnectingState) {
568 delete sock;
569 is.remove();
570 }
571 }
572 }
573}
574
575// Set Port Number
576////////////////////////////////////////////////////////////////////////////
577void bncApp::setPort(int port) {
578 _port = port;
579 if (_port != 0) {
580 delete _server;
581 _server = new QTcpServer;
582 if ( !_server->listen(QHostAddress::Any, _port) ) {
583 slotMessage("bncApp: Cannot listen on ephemeris port", true);
584 }
585 connect(_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
586 delete _sockets;
587 _sockets = new QList<QTcpSocket*>;
588 }
589}
590
591// Set Port Number
592////////////////////////////////////////////////////////////////////////////
593void bncApp::setPortCorr(int port) {
594 _portCorr = port;
595 if (_portCorr != 0) {
596 delete _serverCorr;
597 _serverCorr = new QTcpServer;
598 if ( !_serverCorr->listen(QHostAddress::Any, _portCorr) ) {
599 slotMessage("bncApp: Cannot listen on correction port", true);
600 }
601 connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
602 delete _socketsCorr;
603 _socketsCorr = new QList<QTcpSocket*>;
604 }
605}
606
607// New Connection
608////////////////////////////////////////////////////////////////////////////
609void bncApp::slotNewConnection() {
610 _sockets->push_back( _server->nextPendingConnection() );
611}
612
613// New Connection
614////////////////////////////////////////////////////////////////////////////
615void bncApp::slotNewConnectionCorr() {
616 _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
617}
618
619//
620////////////////////////////////////////////////////////////////////////////
621void bncApp::slotQuit() {
622 cout << "bncApp::slotQuit" << endl;
623 delete _caster;
624 quit();
625}
626
627//
628////////////////////////////////////////////////////////////////////////////
629void bncApp::slotNewCorrLine(QString line, QString staID, long coTime) {
630
631 QMutexLocker locker(&_mutex);
632
633 // Combination of Corrections
634 // --------------------------
635#ifdef USE_COMBINATION
636 if (_bncComb) {
637 _bncComb->processCorrLine(staID, line);
638 }
639#endif
640
641 bncSettings settings;
642 _waitCoTime = settings.value("corrTime").toInt();
643 if (_waitCoTime < 0) {
644 _waitCoTime = 0;
645 }
646
647 // First time, set the _lastDumpSec immediately
648 // --------------------------------------------
649 if (_lastDumpCoSec == 0) {
650 _lastDumpCoSec = coTime - 1;
651 }
652
653 // An old correction - throw it away
654 // ---------------------------------
655 if (_waitCoTime > 0 && coTime <= _lastDumpCoSec) {
656 if (!_bncComb) {
657 QString line = staID + ": Correction for one sat neglected because overaged by " +
658 QString().sprintf(" %ld sec",
659 _lastDumpCoSec - coTime + _waitCoTime);
660 messagePrivate(line.toAscii());
661 emit( newMessage(line.toAscii(), true) );
662 }
663 return;
664 }
665
666 _corrs->insert(coTime, QString(line + " " + staID));
667
668 // Dump Corrections
669 // ----------------
670 if (_waitCoTime == 0) {
671 dumpCorrs();
672 }
673 else if (coTime - _waitCoTime > _lastDumpCoSec) {
674 dumpCorrs(_lastDumpCoSec + 1, coTime - _waitCoTime);
675 _lastDumpCoSec = coTime - _waitCoTime;
676 }
677}
678
679// Dump Complete Correction Epochs
680////////////////////////////////////////////////////////////////////////////
681void bncApp::dumpCorrs(long minTime, long maxTime) {
682 for (long sec = minTime; sec <= maxTime; sec++) {
683 QList<QString> allCorrs = _corrs->values(sec);
684 dumpCorrs(allCorrs);
685 _corrs->remove(sec);
686 }
687}
688
689// Dump all corrections
690////////////////////////////////////////////////////////////////////////////
691void bncApp::dumpCorrs() {
692 QList<QString> allCorrs;
693 QMutableMapIterator<long, QString> it(*_corrs);
694 while (it.hasNext()) {
695 allCorrs << it.next().value();
696 it.remove();
697 }
698 dumpCorrs(allCorrs);
699}
700
701// Dump List of Corrections
702////////////////////////////////////////////////////////////////////////////
703void bncApp::dumpCorrs(const QList<QString>& allCorrs) {
704 emit newCorrections(allCorrs);
705 if (_socketsCorr) {
706 QListIterator<QString> it(allCorrs);
707 while (it.hasNext()) {
708 QString corrLine = it.next() + "\n";
709
710 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
711 while (is.hasNext()) {
712 QTcpSocket* sock = is.next();
713 if (sock->state() == QAbstractSocket::ConnectedState) {
714 if (sock->write(corrLine.toAscii()) == -1) {
715 delete sock;
716 is.remove();
717 }
718 }
719 else if (sock->state() != QAbstractSocket::ConnectingState) {
720 delete sock;
721 is.remove();
722 }
723 }
724 }
725 }
726}
727
728//
729////////////////////////////////////////////////////////////////////////////
730void bncApp::setConfFileName(const QString& confFileName) {
731 if (confFileName.isEmpty()) {
732 _confFileName = QDir::homePath() + QDir::separator()
733 + ".config" + QDir::separator()
734 + organizationName() + QDir::separator()
735 + applicationName() + ".bnc";
736 }
737 else {
738 _confFileName = confFileName;
739 }
740}
741
742// Raw Output
743////////////////////////////////////////////////////////////////////////////
744void bncApp::writeRawData(const QByteArray& data, const QByteArray& staID,
745 const QByteArray& format) {
746
747 QMutexLocker locker(&_mutex);
748
749 if (!_rawFile) {
750 bncSettings settings;
751 QByteArray fileName = settings.value("rawOutFile").toByteArray();
752 if (!fileName.isEmpty()) {
753 _rawFile = new bncRawFile(fileName, staID, bncRawFile::output);
754 }
755 }
756
757 if (_rawFile) {
758 _rawFile->writeRawData(data, staID, format);
759 }
760}
761
762// Get Glonass Slot Numbers from Global Array
763////////////////////////////////////////////////////////////////////////////
764void bncApp::getGlonassSlotNums(int GLOFreq[]) {
765
766 QMutexLocker locker(&_mutex);
767
768 for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
769 if (_GLOFreq[ii] != 0) {
770 GLOFreq[ii] = _GLOFreq[ii];
771 }
772 }
773}
774
775// Store Glonass Slot Numbers to Global Array
776////////////////////////////////////////////////////////////////////////////
777void bncApp::storeGlonassSlotNums(const int GLOFreq[]) {
778
779 QMutexLocker locker(&_mutex);
780
781 for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
782 if (GLOFreq[ii] != 0) {
783 _GLOFreq[ii] = GLOFreq[ii];
784 }
785 }
786}
787
788//
789////////////////////////////////////////////////////////////////////////////
790void bncApp::initCombination() {
791#ifdef USE_COMBINATION
792 _bncComb = new bncComb();
793 if (_bncComb->nStreams() < 1) {
794 delete _bncComb;
795 _bncComb = 0;
796 }
797#endif
798}
799
800//
801////////////////////////////////////////////////////////////////////////////
802void bncApp::stopCombination() {
803#ifdef USE_COMBINATION
804 delete _bncComb;
805 _bncComb = 0;
806#endif
807}
808
809// Handling Events (virtual)
810////////////////////////////////////////////////////////////////////////////
811bool bncApp::event(QEvent* ev) {
812
813 if (ev->type() == QEvent::FileOpen) { // currently happens on Mac only
814 QString fileName = static_cast<QFileOpenEvent*>(ev)->file();
815 setConfFileName(fileName);
816 return true;
817 }
818
819 return QApplication::event(ev);
820}
821
822// Check Ephemeris Consistency
823////////////////////////////////////////////////////////////////////////////
824void bncApp::checkEphemeris(gpsephemeris* oldEph, gpsephemeris* newEph) {
825 if (oldEph->clock_bias != newEph->clock_bias ||
826 oldEph->clock_drift != newEph->clock_drift ||
827 oldEph->clock_driftrate != newEph->clock_driftrate) {
828 QString msg = currentDateAndTimeGPS().toString(Qt::ISODate) +
829 QString(" %1 EPH DIFFERS\n").arg(oldEph->satellite);
830 messagePrivate(msg.toAscii());
831 }
832}
Note: See TracBrowser for help on using the repository browser.