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

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