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

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