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

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