source: ntrip/trunk/BNC/src/bnccore.cpp@ 5164

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