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

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