source: ntrip/branches/BNC_2.11.0/src/bnccore.cpp@ 10514

Last change on this file since 10514 was 7574, checked in by stuerze, 9 years ago

minor changes to prevent a crash

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