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

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