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

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