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

Last change on this file since 5875 was 5875, checked in by mervart, 10 years ago
File size: 24.3 KB
RevLine 
[280]1// Part of BNC, a utility for retrieving decoding and
[464]2// converting GNSS data streams from NTRIP broadcasters.
[280]3//
[464]4// Copyright (C) 2007
[280]5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
[464]7// Czech Technical University Prague, Department of Geodesy
[280]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.
[82]24
25/* -------------------------------------------------------------------------
[93]26 * BKG NTRIP Client
[82]27 * -------------------------------------------------------------------------
28 *
[5072]29 * Class: t_bncCore
[82]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
[1029]41#include <iostream>
[150]42#include <QMessageBox>
[519]43#include <cmath>
[82]44
[5070]45#include "bnccore.h"
[151]46#include "bncutils.h"
[647]47#include "bncrinex.h"
[1535]48#include "bncsettings.h"
[2011]49#include "bncversion.h"
[5738]50#include "ephemeris.h"
[5375]51#include "rinex/rnxobsfile.h"
52#include "rinex/rnxnavfile.h"
[82]53
[2899]54#ifdef USE_COMBINATION
55#include "combination/bnccomb.h"
56#endif
57
[82]58using namespace std;
59
[5084]60// Singleton
61////////////////////////////////////////////////////////////////////////////
[5861]62t_bncCore* t_bncCore::instance() {
[5084]63 static t_bncCore _bncCore;
[5861]64 return &_bncCore;
[5084]65}
66
[82]67// Constructor
68////////////////////////////////////////////////////////////////////////////
[5084]69t_bncCore::t_bncCore() {
70 _GUIenabled = true;
[150]71 _logFileFlag = 0;
72 _logFile = 0;
73 _logStream = 0;
[2519]74 _rawFile = 0;
[5729]75 _caster = 0;
[2922]76#ifdef USE_COMBINATION
77 _bncComb = 0;
78#endif
[152]79
[516]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 }
[2770]88 for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
89 _galileoEph[ii-PRN_GALILEO_START] = 0;
90 }
[516]91
[533]92 // Eph file(s)
93 // -----------
[534]94 _rinexVers = 0;
[533]95 _ephFileGPS = 0;
96 _ephStreamGPS = 0;
97 _ephFileGlonass = 0;
98 _ephStreamGlonass = 0;
[2770]99 _ephFileGalileo = 0;
100 _ephStreamGalileo = 0;
[559]101
[591]102 _port = 0;
[589]103 _server = 0;
104 _sockets = 0;
105
[937]106 _portCorr = 0;
107 _serverCorr = 0;
108 _socketsCorr = 0;
109
[2011]110 _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
[559]111#ifdef WIN32
112 _userName = QString("${USERNAME}");
113#else
114 _userName = QString("${USER}");
115#endif
116 expandEnvVar(_userName);
117 _userName = _userName.leftJustified(20, ' ', true);
[973]118
[5120]119 _corrs = new QMultiMap<bncTime, QString>;
[975]120
[5846]121 _dateAndTimeGPS = 0;
[2673]122
123 for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
124 _GLOFreq[ii] = 0;
125 }
[3027]126
[4346]127 _mainWindow = 0;
[82]128}
129
130// Destructor
131////////////////////////////////////////////////////////////////////////////
[5072]132t_bncCore::~t_bncCore() {
[109]133 delete _logStream;
134 delete _logFile;
[533]135 delete _ephStreamGPS;
136 delete _ephFileGPS;
[589]137 delete _server;
138 delete _sockets;
[937]139 delete _serverCorr;
140 delete _socketsCorr;
[534]141 if (_rinexVers == 2) {
[533]142 delete _ephStreamGlonass;
143 delete _ephFileGlonass;
144 }
[516]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 }
[2770]151 for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
152 delete _galileoEph[ii-PRN_GALILEO_START];
153 }
[975]154
155 delete _corrs;
[1156]156
[5846]157 delete _dateAndTimeGPS;
[2385]158
[2519]159 delete _rawFile;
[2865]160
[2899]161#ifdef USE_COMBINATION
[2865]162 delete _bncComb;
[2899]163#endif
[82]164}
165
166// Write a Program Message
167////////////////////////////////////////////////////////////////////////////
[5072]168void t_bncCore::slotMessage(QByteArray msg, bool showOnScreen) {
[150]169
[1218]170 QMutexLocker locker(&_mutexMessage);
[243]171
[990]172 messagePrivate(msg);
[1299]173 emit newMessage(msg, showOnScreen);
[990]174}
175
176// Write a Program Message (private, no lock)
177////////////////////////////////////////////////////////////////////////////
[5072]178void t_bncCore::messagePrivate(const QByteArray& msg) {
[990]179
[150]180 // First time resolve the log file name
181 // ------------------------------------
[1549]182 QDate currDate = currentDateAndTimeGPS().date();
183 if (_logFileFlag == 0 || _fileDate != currDate) {
[3034]184 delete _logStream; _logStream = 0;
185 delete _logFile; _logFile = 0;
[150]186 _logFileFlag = 1;
[1535]187 bncSettings settings;
[150]188 QString logFileName = settings.value("logFile").toString();
189 if ( !logFileName.isEmpty() ) {
[151]190 expandEnvVar(logFileName);
[1549]191 _logFile = new QFile(logFileName + "_" +
192 currDate.toString("yyMMdd").toAscii().data());
193 _fileDate = currDate;
[275]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 }
[150]200 _logStream = new QTextStream();
201 _logStream->setDevice(_logFile);
202 }
203 }
204
[109]205 if (_logStream) {
[3371]206 QByteArray msgLocal = msg;
207 if (msg.indexOf('\n') == 0) {
208 *_logStream << endl;
209 msgLocal = msg.mid(1);
210 }
[1154]211 *_logStream << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
[3371]212 *_logStream << msgLocal.data() << endl;
[109]213 _logStream->flush();
[3637]214 _logFile->flush();
[82]215 }
216}
[511]217
[535]218// New GPS Ephemeris
[511]219////////////////////////////////////////////////////////////////////////////
[5072]220void t_bncCore::slotNewGPSEph(gpsephemeris* gpseph) {
[516]221
222 QMutexLocker locker(&_mutex);
223
[1044]224 gpsephemeris copy_gpseph = *gpseph;
225 emit newEphGPS(copy_gpseph);
226
[534]227 printEphHeader();
228
[532]229 gpsephemeris** ee = &_gpsEph[gpseph->satellite-1];
[1218]230
[4245]231 if ( *ee != 0 &&
232 gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC == (*ee)->TOC ) {
233 checkEphemeris(*ee, gpseph);
234 }
235
[538]236 if ( *ee == 0 ||
237 gpseph->GPSweek > (*ee)->GPSweek ||
[594]238 (gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC > (*ee)->TOC) ) {
[516]239 delete *ee;
240 *ee = gpseph;
[600]241 printGPSEph(gpseph, true);
[516]242 }
243 else {
[600]244 printGPSEph(gpseph, false);
[516]245 delete gpseph;
246 }
[511]247}
248
[535]249// New Glonass Ephemeris
[511]250////////////////////////////////////////////////////////////////////////////
[5206]251void t_bncCore::slotNewGlonassEph(glonassephemeris* glonasseph, const QString& staID) {
[516]252
253 QMutexLocker locker(&_mutex);
254
[4747]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
[1164]264 glonassephemeris copy_glonasseph = *glonasseph;
265 emit newEphGlonass(copy_glonasseph);
266
[534]267 printEphHeader();
268
[532]269 glonassephemeris** ee = &_glonassEph[glonasseph->almanac_number-1];
[531]270
[3539]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
[578]282 if ( *ee == 0 ||
[3539]283 wwNew > wwOld ||
284 (wwNew == wwOld && towNew > towOld) ) {
[531]285 delete *ee;
286 *ee = glonasseph;
[5206]287 printGlonassEph(glonasseph, true, staID);
[531]288 }
289 else {
[5206]290 printGlonassEph(glonasseph, false, staID);
[531]291 delete glonasseph;
292 }
[511]293}
294
[2770]295// New Galileo Ephemeris
296////////////////////////////////////////////////////////////////////////////
[5072]297void t_bncCore::slotNewGalileoEph(galileoephemeris* galileoeph) {
[2770]298
299 QMutexLocker locker(&_mutex);
300
[2772]301 galileoephemeris copy_galileoeph = *galileoeph;
302 emit newEphGalileo(copy_galileoeph);
303
304 printEphHeader();
305
[3734]306 int galIndex = galileoeph->satellite;
307 /* GIOVE */
308 if(galIndex == 51) galIndex = 1;
309 else if(galIndex == 52) galIndex = 16;
[2785]310 if (galIndex < 0 || galIndex > PRN_GALILEO_END - PRN_GALILEO_START) {
[2773]311 emit( newMessage("Wrong Galileo Satellite Number", true) );
312 exit(1);
313 }
[2772]314
[2773]315 galileoephemeris** ee = &_galileoEph[galIndex];
316
317 if ( *ee == 0 ||
[2772]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 }
[2770]328}
329
[535]330// Print Header of the output File(s)
[516]331////////////////////////////////////////////////////////////////////////////
[5072]332void t_bncCore::printEphHeader() {
[528]333
[1535]334 bncSettings settings;
[535]335
[534]336 // Initialization
337 // --------------
338 if (_rinexVers == 0) {
[528]339
[533]340 if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
[534]341 _rinexVers = 3;
[533]342 }
343 else {
[534]344 _rinexVers = 2;
[533]345 }
[529]346
[533]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 }
[517]355 }
[533]356
[534]357 // (Re-)Open output File(s)
358 // ------------------------
[533]359 if (!_ephPath.isEmpty()) {
360
[1154]361 QDateTime datTim = currentDateAndTimeGPS();
[533]362
[583]363 QString ephFileNameGPS = _ephPath + "BRDC" +
[563]364 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'));
[533]365
[647]366 QString hlpStr = bncRinex::nextEpochStr(datTim,
367 settings.value("ephIntr").toString());
[584]368
[575]369 if (_rinexVers == 3) {
370 ephFileNameGPS += hlpStr + datTim.toString(".yyP");
371 }
372 else {
373 ephFileNameGPS += hlpStr + datTim.toString(".yyN");
374 }
[563]375
[533]376 if (_ephFileNameGPS == ephFileNameGPS) {
377 return;
378 }
379 else {
380 _ephFileNameGPS = ephFileNameGPS;
381 }
382
[575]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 }
[2770]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 }
[575]395
[533]396 delete _ephStreamGPS;
397 delete _ephFileGPS;
398
[535]399 QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
[536]400 QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
[2770]401 QFlags<QIODevice::OpenModeFlag> appendFlagGalileo;
[536]402
[535]403 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
404 QFile::exists(ephFileNameGPS) ) {
405 appendFlagGPS = QIODevice::Append;
406 }
407
[533]408 _ephFileGPS = new QFile(ephFileNameGPS);
[535]409 _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
[533]410 _ephStreamGPS = new QTextStream();
411 _ephStreamGPS->setDevice(_ephFileGPS);
412
[534]413 if (_rinexVers == 3) {
[533]414 _ephFileGlonass = _ephFileGPS;
415 _ephStreamGlonass = _ephStreamGPS;
[2770]416 _ephFileGalileo = _ephFileGPS;
417 _ephStreamGalileo = _ephStreamGPS;
[533]418 }
[534]419 else if (_rinexVers == 2) {
[583]420 QString ephFileNameGlonass = _ephPath + "BRDC" +
[563]421 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
[575]422 hlpStr + datTim.toString(".yyG");
[533]423
424 delete _ephStreamGlonass;
425 delete _ephFileGlonass;
426
[535]427 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
428 QFile::exists(ephFileNameGlonass) ) {
429 appendFlagGlonass = QIODevice::Append;
430 }
431
[533]432 _ephFileGlonass = new QFile(ephFileNameGlonass);
[535]433 _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
[533]434 _ephStreamGlonass = new QTextStream();
435 _ephStreamGlonass->setDevice(_ephFileGlonass);
436 }
437
[534]438 // Header - RINEX Version 3
439 // ------------------------
440 if (_rinexVers == 3) {
[537]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
[1154]448 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
[559]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", "");
[537]455 *_ephStreamGPS << line;
456
457 _ephStreamGPS->flush();
[535]458 }
[533]459 }
460
[536]461 // Headers - RINEX Version 2
462 // -------------------------
[534]463 else if (_rinexVers == 2) {
[536]464 if (! (appendFlagGPS & QIODevice::Append)) {
465 QString line;
[5375]466 line.sprintf("%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n",
467 t_rnxNavFile::defaultRnxNavVersion2, "", "");
[536]468 *_ephStreamGPS << line;
469
[1154]470 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
[559]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", "");
[536]477 *_ephStreamGPS << line;
[537]478
479 _ephStreamGPS->flush();
[536]480 }
481 if (! (appendFlagGlonass & QIODevice::Append)) {
482 QString line;
[5375]483 line.sprintf("%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",
484 t_rnxNavFile::defaultRnxNavVersion2, "", "");
[536]485 *_ephStreamGlonass << line;
486
[1154]487 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
[559]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", "");
[536]494 *_ephStreamGlonass << line;
[537]495
496 _ephStreamGlonass->flush();
[536]497 }
[533]498 }
499 }
[516]500}
501
[535]502// Print One GPS Ephemeris
[516]503////////////////////////////////////////////////////////////////////////////
[5072]504void t_bncCore::printGPSEph(gpsephemeris* ep, bool printFile) {
[519]505
[4020]506 t_ephGPS eph;
507 eph.set(ep);
[533]508
[5375]509 QString strV2 = eph.toString(t_rnxNavFile::defaultRnxNavVersion2);
510 QString strV3 = eph.toString(t_rnxObsHeader::defaultRnxObsVersion3);
[941]511
[4020]512 printOutput(printFile, _ephStreamGPS, strV2, strV3);
[516]513}
514
[535]515// Print One Glonass Ephemeris
[516]516////////////////////////////////////////////////////////////////////////////
[5375]517void t_bncCore::printGlonassEph(glonassephemeris* ep, bool printFile, const QString& /* staID */) {
[523]518
[4020]519 t_ephGlo eph;
[5133]520 eph.set(ep);
[523]521
[5375]522 QString strV2 = eph.toString(t_rnxNavFile::defaultRnxNavVersion2);
523 QString strV3 = eph.toString(t_rnxObsHeader::defaultRnxObsVersion3);
[525]524
[5206]525 //// beg test Dirk
[5312]526 // QString hlp = strV2;
527 // cout << hlp.replace('\n', ' ').toAscii().data() << ' ' << staID.toAscii().data() << endl;
[5206]528 //// end test Dirk
529
[4225]530 printOutput(printFile, _ephStreamGlonass, strV2, strV3);
[941]531}
532
[2770]533// Print One Galileo Ephemeris
534////////////////////////////////////////////////////////////////////////////
[5072]535void t_bncCore::printGalileoEph(galileoephemeris* ep, bool printFile) {
[2772]536
[4020]537 t_ephGal eph;
538 eph.set(ep);
[2772]539
[5375]540 QString strV2 = eph.toString(t_rnxNavFile::defaultRnxNavVersion2);
541 QString strV3 = eph.toString(t_rnxObsHeader::defaultRnxObsVersion3);
[2772]542
[4225]543 printOutput(printFile, _ephStreamGalileo, strV2, strV3);
[2770]544}
545
[941]546// Output
547////////////////////////////////////////////////////////////////////////////
[5072]548void t_bncCore::printOutput(bool printFile, QTextStream* stream,
[4020]549 const QString& strV2, const QString& strV3) {
550
[590]551 // Output into file
552 // ----------------
[943]553 if (printFile && stream) {
[941]554 if (_rinexVers == 2) {
[4020]555 *stream << strV2.toAscii();
[941]556 }
557 else {
[4020]558 *stream << strV3.toAscii();
[941]559 }
[943]560 stream->flush();
[517]561 }
[590]562
563 // Output into the socket
564 // ----------------------
565 if (_sockets) {
[642]566 QMutableListIterator<QTcpSocket*> is(*_sockets);
[590]567 while (is.hasNext()) {
568 QTcpSocket* sock = is.next();
569 if (sock->state() == QAbstractSocket::ConnectedState) {
[4020]570 if (sock->write(strV3.toAscii()) == -1) {
[642]571 delete sock;
572 is.remove();
573 }
[590]574 }
[642]575 else if (sock->state() != QAbstractSocket::ConnectingState) {
576 delete sock;
577 is.remove();
578 }
[590]579 }
580 }
[516]581}
[589]582
[591]583// Set Port Number
584////////////////////////////////////////////////////////////////////////////
[5072]585void t_bncCore::setPort(int port) {
[591]586 _port = port;
587 if (_port != 0) {
[942]588 delete _server;
[591]589 _server = new QTcpServer;
[1228]590 if ( !_server->listen(QHostAddress::Any, _port) ) {
[5072]591 slotMessage("t_bncCore: Cannot listen on ephemeris port", true);
[1228]592 }
[591]593 connect(_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
[942]594 delete _sockets;
[591]595 _sockets = new QList<QTcpSocket*>;
596 }
597}
598
[937]599// Set Port Number
600////////////////////////////////////////////////////////////////////////////
[5072]601void t_bncCore::setPortCorr(int port) {
[937]602 _portCorr = port;
603 if (_portCorr != 0) {
[942]604 delete _serverCorr;
[937]605 _serverCorr = new QTcpServer;
[1228]606 if ( !_serverCorr->listen(QHostAddress::Any, _portCorr) ) {
[5072]607 slotMessage("t_bncCore: Cannot listen on correction port", true);
[1228]608 }
[937]609 connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
[942]610 delete _socketsCorr;
[937]611 _socketsCorr = new QList<QTcpSocket*>;
612 }
613}
614
[589]615// New Connection
616////////////////////////////////////////////////////////////////////////////
[5072]617void t_bncCore::slotNewConnection() {
[589]618 _sockets->push_back( _server->nextPendingConnection() );
619}
620
[937]621// New Connection
622////////////////////////////////////////////////////////////////////////////
[5072]623void t_bncCore::slotNewConnectionCorr() {
[937]624 _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
625}
626
[621]627//
628////////////////////////////////////////////////////////////////////////////
[5072]629void t_bncCore::slotQuit() {
630 cout << "t_bncCore::slotQuit" << endl;
[5729]631 delete _caster; _caster = 0;
[5066]632 qApp->quit();
[621]633}
634
[936]635//
636////////////////////////////////////////////////////////////////////////////
[5120]637void t_bncCore::slotNewCorrLine(QString line, QString staID, bncTime coTime) {
[974]638
639 QMutexLocker locker(&_mutex);
640
[2866]641 // Combination of Corrections
642 // --------------------------
[2899]643#ifdef USE_COMBINATION
[2866]644 if (_bncComb) {
645 _bncComb->processCorrLine(staID, line);
646 }
[2899]647#endif
[2866]648
[1535]649 bncSettings settings;
[5120]650 _waitCoTime = settings.value("corrTime").toDouble();
651 if (_waitCoTime < 0.0) {
652 _waitCoTime = 0.0;
[995]653 }
654
[5123]655 // First time, set the _lastCorrDumpTime
656 // -------------------------------------
[5387]657 if (!_lastCorrDumpTime[staID].valid()) {
658 _lastCorrDumpTime[staID] = coTime - 1.0;
[974]659 }
660
[975]661 // An old correction - throw it away
662 // ---------------------------------
[5387]663 if (_waitCoTime > 0.0 && coTime <= _lastCorrDumpTime[staID]) {
[5129]664 if (!_bncComb) {
[2916]665 QString line = staID + ": Correction for one sat neglected because overaged by " +
[5120]666 QString().sprintf(" %f sec",
[5387]667 _lastCorrDumpTime[staID] - coTime + _waitCoTime);
[2916]668 messagePrivate(line.toAscii());
669 emit( newMessage(line.toAscii(), true) );
[5129]670 }
[975]671 return;
672 }
673
674 _corrs->insert(coTime, QString(line + " " + staID));
675
[976]676 // Dump Corrections
677 // ----------------
[5120]678 if (_waitCoTime == 0.0) {
[3109]679 dumpCorrs();
680 }
[5387]681 else if (coTime - _waitCoTime > _lastCorrDumpTime[staID]) {
682 dumpCorrs(_lastCorrDumpTime[staID] + 1, coTime - _waitCoTime);
683 _lastCorrDumpTime[staID] = coTime - _waitCoTime;
[976]684 }
685}
686
687// Dump Complete Correction Epochs
688////////////////////////////////////////////////////////////////////////////
[5120]689void t_bncCore::dumpCorrs(bncTime minTime, bncTime maxTime) {
[5732]690 QStringList allCorrs;
[5121]691 QMutableMapIterator<bncTime, QString> it(*_corrs);
692 while (it.hasNext()) {
693 it.next();
694 const bncTime& corrTime = it.key();
695 if (minTime <= corrTime && corrTime <= maxTime) {
696 allCorrs << it.value();
697 it.remove();
698 }
[3109]699 }
[5122]700 dumpCorrs(allCorrs);
[3109]701}
702
703// Dump all corrections
704////////////////////////////////////////////////////////////////////////////
[5072]705void t_bncCore::dumpCorrs() {
[5732]706 QStringList allCorrs;
[5120]707 QMutableMapIterator<bncTime, QString> it(*_corrs);
[3110]708 while (it.hasNext()) {
709 allCorrs << it.next().value();
710 it.remove();
711 }
712 dumpCorrs(allCorrs);
[3109]713}
714
715// Dump List of Corrections
716////////////////////////////////////////////////////////////////////////////
[5732]717void t_bncCore::dumpCorrs(const QStringList& allCorrs) {
[3109]718 emit newCorrections(allCorrs);
719 if (_socketsCorr) {
720 QListIterator<QString> it(allCorrs);
721 while (it.hasNext()) {
722 QString corrLine = it.next() + "\n";
723
724 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
725 while (is.hasNext()) {
726 QTcpSocket* sock = is.next();
727 if (sock->state() == QAbstractSocket::ConnectedState) {
728 if (sock->write(corrLine.toAscii()) == -1) {
[976]729 delete sock;
730 is.remove();
731 }
732 }
[3109]733 else if (sock->state() != QAbstractSocket::ConnectingState) {
734 delete sock;
735 is.remove();
736 }
[937]737 }
738 }
739 }
[936]740}
[1538]741
742//
743////////////////////////////////////////////////////////////////////////////
[5072]744void t_bncCore::setConfFileName(const QString& confFileName) {
[4169]745 if (confFileName.isEmpty()) {
746 _confFileName = QDir::homePath() + QDir::separator()
747 + ".config" + QDir::separator()
[5066]748 + qApp->organizationName() + QDir::separator()
749 + qApp->applicationName() + ".bnc";
[1538]750 }
[4169]751 else {
752 _confFileName = confFileName;
753 }
[1538]754}
[2385]755
756// Raw Output
757////////////////////////////////////////////////////////////////////////////
[5072]758void t_bncCore::writeRawData(const QByteArray& data, const QByteArray& staID,
[2518]759 const QByteArray& format) {
[2385]760
[2386]761 QMutexLocker locker(&_mutex);
762
[2519]763 if (!_rawFile) {
[2386]764 bncSettings settings;
[2519]765 QByteArray fileName = settings.value("rawOutFile").toByteArray();
766 if (!fileName.isEmpty()) {
[3524]767 _rawFile = new bncRawFile(fileName, staID, bncRawFile::output);
[2407]768 }
[2386]769 }
770
[2519]771 if (_rawFile) {
772 _rawFile->writeRawData(data, staID, format);
[2386]773 }
[2385]774}
[2672]775
776// Get Glonass Slot Numbers from Global Array
777////////////////////////////////////////////////////////////////////////////
[5072]778void t_bncCore::getGlonassSlotNums(int GLOFreq[]) {
[2672]779
780 QMutexLocker locker(&_mutex);
781
[2673]782 for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
783 if (_GLOFreq[ii] != 0) {
784 GLOFreq[ii] = _GLOFreq[ii];
785 }
786 }
[2672]787}
788
789// Store Glonass Slot Numbers to Global Array
790////////////////////////////////////////////////////////////////////////////
[5072]791void t_bncCore::storeGlonassSlotNums(const int GLOFreq[]) {
[2672]792
793 QMutexLocker locker(&_mutex);
794
[2673]795 for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
796 if (GLOFreq[ii] != 0) {
797 _GLOFreq[ii] = GLOFreq[ii];
798 }
799 }
[2672]800}
[2909]801
802//
803////////////////////////////////////////////////////////////////////////////
[5072]804void t_bncCore::initCombination() {
[2909]805#ifdef USE_COMBINATION
806 _bncComb = new bncComb();
[3142]807 if (_bncComb->nStreams() < 1) {
[2909]808 delete _bncComb;
809 _bncComb = 0;
810 }
811#endif
812}
[3231]813
814//
815////////////////////////////////////////////////////////////////////////////
[5072]816void t_bncCore::stopCombination() {
[3231]817#ifdef USE_COMBINATION
818 delete _bncComb;
819 _bncComb = 0;
820#endif
821}
[4167]822
[4245]823// Check Ephemeris Consistency
824////////////////////////////////////////////////////////////////////////////
[5072]825void t_bncCore::checkEphemeris(gpsephemeris* oldEph, gpsephemeris* newEph) {
[4245]826 if (oldEph->clock_bias != newEph->clock_bias ||
827 oldEph->clock_drift != newEph->clock_drift ||
828 oldEph->clock_driftrate != newEph->clock_driftrate) {
829 QString msg = currentDateAndTimeGPS().toString(Qt::ISODate) +
830 QString(" %1 EPH DIFFERS\n").arg(oldEph->satellite);
831 messagePrivate(msg.toAscii());
832 }
833}
[5577]834
[5846]835
836//
837////////////////////////////////////////////////////////////////////////////
838bool t_bncCore::dateAndTimeGPSSet() const {
839 QMutexLocker locker(&_mutexDateAndTimeGPS);
840 if (_dateAndTimeGPS) {
841 return true;
842 }
843 else {
844 return false;
845 }
846}
847
848//
849////////////////////////////////////////////////////////////////////////////
850QDateTime t_bncCore::dateAndTimeGPS() const {
851 QMutexLocker locker(&_mutexDateAndTimeGPS);
852 if (_dateAndTimeGPS) {
853 return *_dateAndTimeGPS;
854 }
855 else {
856 return QDateTime();
857 }
858}
859
860//
861////////////////////////////////////////////////////////////////////////////
862void t_bncCore::setDateAndTimeGPS(QDateTime dateTime) {
863 QMutexLocker locker(&_mutexDateAndTimeGPS);
864 delete _dateAndTimeGPS;
865 _dateAndTimeGPS = new QDateTime(dateTime);
866}
Note: See TracBrowser for help on using the repository browser.