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