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

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