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

Last change on this file since 11179 was 11179, checked in by stuerze, 4 weeks ago

structuered logging is added and bug is fixed in SP3 file writing

File size: 30.7 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)
[11021]6// http://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 *
[7291]37 * Changes:
[82]38 *
39 * -----------------------------------------------------------------------*/
40
[1029]41#include <iostream>
[6461]42#include <sstream>
[150]43#include <QMessageBox>
[519]44#include <cmath>
[82]45
[7291]46#include "bnccore.h"
[11066]47#include "ssrQc.h"
[7291]48#include "bncutils.h"
49#include "bncrinex.h"
50#include "bncsettings.h"
51#include "bncversion.h"
52#include "ephemeris.h"
53#include "rinex/rnxobsfile.h"
54#include "rinex/rnxnavfile.h"
[6051]55#include "pppMain.h"
[7298]56#include "combination/bnccomb.h"
[82]57
58using namespace std;
59
[7291]60// Singleton
[5084]61////////////////////////////////////////////////////////////////////////////
[5861]62t_bncCore* t_bncCore::instance() {
[5084]63 static t_bncCore _bncCore;
[5861]64 return &_bncCore;
[5084]65}
66
[82]67// Constructor
68////////////////////////////////////////////////////////////////////////////
[6441]69t_bncCore::t_bncCore() : _ephUser(false) {
[150]70 _logFileFlag = 0;
71 _logFile = 0;
72 _logStream = 0;
[11179]73 _logFileStructured = 0;
74 _logFormatStructured = t_logRecord::json;
[2519]75 _rawFile = 0;
[5729]76 _caster = 0;
[152]77
[533]78 // Eph file(s)
79 // -----------
[11136]80 _rinexVers = 0;
81 _ephFilePerStation = false;
[559]82
[6451]83 _portEph = 0;
84 _serverEph = 0;
85 _socketsEph = 0;
[589]86
[937]87 _portCorr = 0;
88 _serverCorr = 0;
89 _socketsCorr = 0;
90
[2011]91 _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
[559]92#ifdef WIN32
93 _userName = QString("${USERNAME}");
94#else
95 _userName = QString("${USER}");
96#endif
97 expandEnvVar(_userName);
[973]98
[6151]99 _userName = _userName.leftJustified(20, ' ', true);
[5846]100 _dateAndTimeGPS = 0;
[6151]101 _mainWindow = 0;
[2673]102
[5899]103 _pppMain = new BNC_PPP::t_pppMain();
[11066]104 _ssrQc = 0;
[6486]105 qRegisterMetaType< QVector<double> > ("QVector<double>");
106 qRegisterMetaType<bncTime> ("bncTime");
[11179]107 qRegisterMetaType<t_logRecord> ("t_logRecord");
[6486]108 qRegisterMetaType<t_ephGPS> ("t_ephGPS");
109 qRegisterMetaType<t_ephGlo> ("t_ephGlo");
110 qRegisterMetaType<t_ephGal> ("t_ephGal");
111 qRegisterMetaType<t_ephSBAS> ("t_ephSBAS");
[6598]112 qRegisterMetaType<t_ephBDS> ("t_ephBDS");
[6486]113 qRegisterMetaType<QList<t_orbCorr> > ("QList<t_orbCorr>");
114 qRegisterMetaType<QList<t_clkCorr> > ("QList<t_clkCorr>");
115 qRegisterMetaType<QList<t_satCodeBias> > ("QList<t_satCodeBias>");
116 qRegisterMetaType<QList<t_satPhaseBias> > ("QList<t_satPhaseBias>");
117 qRegisterMetaType<t_vTec> ("t_vTec");
[11008]118 qRegisterMetaType<t_metaData> ("t_metaData");
[11039]119 qRegisterMetaType<QList<t_satAntenna> > ("QList<t_satAntenna>");
[82]120}
121
122// Destructor
123////////////////////////////////////////////////////////////////////////////
[5072]124t_bncCore::~t_bncCore() {
[10221]125 delete _logStream; _logStream = 0;
126 delete _logFile; _logFile = 0;
[11179]127 delete _logFileStructured; _logFileStructured = 0;
[11136]128 qDeleteAll(_ephFiles);
[6451]129 delete _serverEph;
130 delete _socketsEph;
[937]131 delete _serverCorr;
132 delete _socketsCorr;
[5846]133 delete _dateAndTimeGPS;
[9822]134 if (_rawFile) {
135 delete _rawFile;
136 }
137
[10040]138 bncComb::destruct();
[11066]139 delete _ssrQc;
[10040]140
[7856]141 delete _pppMain;
[82]142}
143
144// Write a Program Message
145////////////////////////////////////////////////////////////////////////////
[5072]146void t_bncCore::slotMessage(QByteArray msg, bool showOnScreen) {
[10027]147 if (msg.isEmpty()) {
148 return;
149 }
[11179]150 slotLogRecord(t_logRecord::fromMessage(msg), showOnScreen);
151}
152
153// Write a Program Message with structured fields (structured logfile);
154// the classic logfile and the screen get the text rec._msg
155////////////////////////////////////////////////////////////////////////////
156void t_bncCore::slotLogRecord(t_logRecord rec, bool showOnScreen) {
157 if (rec._msg.isEmpty()) {
158 return;
159 }
[1218]160 QMutexLocker locker(&_mutexMessage);
[243]161
[11179]162 messagePrivate(rec);
163 emit newMessage(rec._msg, showOnScreen);
[990]164}
165
166// Write a Program Message (private, no lock)
167////////////////////////////////////////////////////////////////////////////
[11179]168void t_bncCore::messagePrivate(const t_logRecord& rec) {
[990]169
[11179]170 // First time resolve the log file names
171 // -------------------------------------
172 QDateTime currDateTime = currentDateAndTimeGPS();
173 QDate currDate = currDateTime.date();
[1549]174 if (_logFileFlag == 0 || _fileDate != currDate) {
[3034]175 delete _logStream; _logStream = 0;
176 delete _logFile; _logFile = 0;
[11179]177 delete _logFileStructured; _logFileStructured = 0;
[150]178 _logFileFlag = 1;
[11179]179 _fileDate = currDate;
[1535]180 bncSettings settings;
[11179]181 bool append = (Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked);
[150]182 QString logFileName = settings.value("logFile").toString();
183 if ( !logFileName.isEmpty() ) {
[151]184 expandEnvVar(logFileName);
[7291]185 _logFile = new QFile(logFileName + "_" +
[8127]186 currDate.toString("yyMMdd").toLatin1().data());
[11179]187 if (append) {
[275]188 _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
189 }
190 else {
191 _logFile->open(QIODevice::WriteOnly);
192 }
[150]193 _logStream = new QTextStream();
194 _logStream->setDevice(_logFile);
195 }
[11179]196 QString structName = settings.value("logFileStructured").toString();
197 if ( !structName.isEmpty() ) {
198 expandEnvVar(structName);
199 _logFormatStructured = t_logRecord::formatFromString(
200 settings.value("logFormatStructured").toString());
201 _logFileStructured = new QFile(structName + "_" + currDate.toString("yyMMdd"));
202 if (!_logFileStructured->open(append ? (QIODevice::WriteOnly | QIODevice::Append)
203 : QIODevice::WriteOnly)) {
204 delete _logFileStructured; _logFileStructured = 0;
205 }
206 }
[150]207 }
208
[109]209 if (_logStream) {
[11179]210 QByteArray msgLocal = rec._msg;
211 if (rec._msg.indexOf('\n') == 0) {
[9819]212 *_logStream << "\r\n";
[11179]213 msgLocal = rec._msg.mid(1);
[3371]214 }
[11179]215 *_logStream << currDateTime.toString("yy-MM-dd hh:mm:ss ").toLatin1().data();
[9819]216 *_logStream << msgLocal.data() << "\r\n";
[109]217 _logStream->flush();
[3637]218 _logFile->flush();
[82]219 }
[11179]220
221 if (_logFileStructured) {
222 _logFileStructured->write(rec.encode(_logFormatStructured, currDateTime) + "\n");
223 _logFileStructured->flush();
224 }
[82]225}
[511]226
[7291]227//
[511]228////////////////////////////////////////////////////////////////////////////
[6520]229t_irc t_bncCore::checkPrintEph(t_eph* eph) {
[516]230 QMutexLocker locker(&_mutex);
[6520]231 t_irc ircPut = _ephUser.putNewEph(eph, true);
[10549]232#ifdef BNC_DEBUG_BCE
[9767]233 if (eph->checkState() == t_eph::unhealthy) {
[11179]234 messagePrivate(t_logRecord::fromMessage(QString("%1: UNHEALTHY %2:%3")
[9217]235 .arg(eph->receptStaID())
[10587]236 .arg(eph->typeStr(eph->type(), eph->prn(), 99.0))
[11179]237 .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1()));
[6519]238 }
[9768]239 if (eph->checkState() == t_eph::bad) {
[11179]240 messagePrivate(t_logRecord::fromMessage(QString("%1: WRONG %2:%3")
[9217]241 .arg(eph->receptStaID())
[10587]242 .arg(eph->typeStr(eph->type(), eph->prn(), 99.0))
[11179]243 .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1()));
[7208]244 }
[9772]245 if (eph->checkState() == t_eph::outdated) {
[11179]246 messagePrivate(t_logRecord::fromMessage(QString("%1: OUTDATED %2:%3")
[9217]247 .arg(eph->receptStaID())
[10587]248 .arg(eph->typeStr(eph->type(), eph->prn(), 99.0))
[11179]249 .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1()));
[8215]250 }
[9379]251#endif
[11136]252 t_ephFile* ephFile = printEphHeader(eph->receptStaID());
253 bool printFile = (ircPut == success);
254 if (ephFile && ephFile->_ephUser) {
255 // file per stream: new ephemerides of this stream, independent of other streams;
256 // the check state of the emitted ephemeris stays that of the common check
257 t_eph::e_checkState checkState = eph->checkState();
258 printFile = (ephFile->_ephUser->putNewEph(eph, true) == success);
259 eph->setCheckState(checkState);
260 }
261 printEph(ephFile, *eph, printFile);
[6520]262 return success;
[511]263}
[6520]264
[7291]265// New GPS Ephemeris
[6520]266////////////////////////////////////////////////////////////////////////////
267void t_bncCore::slotNewGPSEph(t_ephGPS eph) {
268 if (checkPrintEph(&eph) == success) {
269 emit newGPSEph(eph);
270 }
271}
[7291]272
[535]273// New Glonass Ephemeris
[511]274////////////////////////////////////////////////////////////////////////////
[6432]275void t_bncCore::slotNewGlonassEph(t_ephGlo eph) {
[6520]276 if (checkPrintEph(&eph) == success) {
277 emit newGlonassEph(eph);
[6519]278 }
[511]279}
280
[2770]281// New Galileo Ephemeris
282////////////////////////////////////////////////////////////////////////////
[6432]283void t_bncCore::slotNewGalileoEph(t_ephGal eph) {
[6520]284 if (checkPrintEph(&eph) == success) {
285 emit newGalileoEph(eph);
[6519]286 }
[6432]287}
[2772]288
[6432]289// New SBAS Ephemeris
290////////////////////////////////////////////////////////////////////////////
291void t_bncCore::slotNewSBASEph(t_ephSBAS eph) {
[6520]292 if (checkPrintEph(&eph) == success) {
293 emit newSBASEph(eph);
[6519]294 }
[2770]295}
296
[6598]297// New BDS Ephemeris
[6595]298////////////////////////////////////////////////////////////////////////////
[6598]299void t_bncCore::slotNewBDSEph(t_ephBDS eph) {
[6595]300 if (checkPrintEph(&eph) == success) {
[6598]301 emit newBDSEph(eph);
[6595]302 }
303}
[6432]304
[11136]305// Close RINEX Navigation File(s)
[516]306////////////////////////////////////////////////////////////////////////////
[11136]307void t_bncCore::t_ephFile::close() {
308 delete _streamN; _streamN = 0;
309 delete _fileN; _fileN = 0;
310 delete _streamG; _streamG = 0;
311 delete _fileG; _fileG = 0;
312}
[528]313
[11136]314// Destructor
315////////////////////////////////////////////////////////////////////////////
316t_bncCore::t_ephFile::~t_ephFile() {
317 close();
318 delete _ephUser;
319}
[535]320
[11136]321// Station part of a RINEX navigation file name: "BRDC" (+ "00WRD" in RINEX 3/4)
322// for the single file, otherwise derived from the stream like the observation files
323////////////////////////////////////////////////////////////////////////////
324QString t_bncCore::ephFileNameBase(const QString& staID, const QString& country) const {
325 QString ID = staID.isEmpty() ? QString("BRDC") : staID.left(4).toUpper();
326 if (_rinexVers <= 2) {
327 return ID;
[7999]328 }
[11136]329 if (staID.size() >= 9 &&
330 isdigit((unsigned char) staID[4].toLatin1()) &&
331 isdigit((unsigned char) staID[5].toLatin1())) {
332 return staID.left(9).toUpper(); // e.g. BCEP00BKG0 -> BCEP00BKG
333 }
334 return ID + "00" + ((!staID.isEmpty() && country.size() >= 3) ? country.left(3).toUpper()
335 : QString("WRD")); // WORLD
336}
[7999]337
[11136]338// Print Header of the output File(s), returns the file of the stream
339////////////////////////////////////////////////////////////////////////////
340t_bncCore::t_ephFile* t_bncCore::printEphHeader(QString receptStaID) {
341
342 bncSettings settings;
343
[534]344 // Initialization
345 // --------------
346 if (_rinexVers == 0) {
[528]347
[9760]348 _rinexVers = settings.value("ephVersion").toInt();
[529]349
[11136]350 _ephFilePerStation = Qt::CheckState(settings.value("ephFilePerStation").toInt()) == Qt::Checked;
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
[11136]362 if (_ephPath.isEmpty()) {
363 return 0;
364 }
[533]365
[11136]366 QString key = _ephFilePerStation ? receptStaID : QString();
[533]367
[11136]368 // Source comments and station part of the file name
369 // --------------------------------------------------
370 QStringList comments;
371 QMap<QString, QString> nameBase; // staID -> station part of its file name
372 QListIterator<QString> it(settings.value("mountPoints").toStringList());
373 while (it.hasNext()) {
374 QStringList hlp = it.next().split(" ");
375 if (hlp.size() < 7)
376 continue;
377 QUrl url(hlp[0]);
378 QString decoder = hlp[1];
379 QString staID = url.path().mid(1);
380 if (key.isEmpty() || staID == key) {
381 comments.append("Source: " + decoder +
382 " " + QUrl::toAce(url.host()) +
383 "/" + url.path().mid(1).toLatin1());
384 }
385 nameBase[staID] = ephFileNameBase(staID, hlp[2]);
386 }
[533]387
[11136]388 QString base = (!key.isEmpty() && nameBase.contains(key)) ? nameBase[key]
389 : ephFileNameBase(key, QString());
390 QString distStr;
391 if (!key.isEmpty()) {
392 QMapIterator<QString, QString> im(nameBase);
393 while (im.hasNext()) {
394 im.next();
395 if (im.key() != key && im.value() == base) { // name conflict with another stream
396 distStr = "_" + key;
397 break;
[10091]398 }
[575]399 }
[11136]400 }
[563]401
[11136]402 t_ephFile*& ephFile = _ephFiles[key];
403 if (!ephFile) {
404 ephFile = new t_ephFile;
405 if (_ephFilePerStation) {
406 ephFile->_ephUser = new bncEphUser(false);
[533]407 }
[11136]408 }
[533]409
[11136]410 // (Re-)Open output File(s)
411 // ------------------------
412 QDateTime datTim = currentDateAndTimeGPS();
[533]413
[11136]414 QString hlpStr = bncRinex::nextEpochStr(datTim,
415 settings.value("ephIntr").toString(), _rinexVers);
[536]416
[11136]417 QString ephFileNameGPS = _ephPath + base;
[535]418
[11136]419 if (_rinexVers > 2) {
420 ephFileNameGPS += "_S_" + // stream
421 QString("%1").arg(datTim.date().year()) +
422 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
423 hlpStr + // HM_period
424 "_MN" + // mixed BRDC
425 distStr + ".rnx";
426 }
427 else { // RNX v2.11
428 ephFileNameGPS += QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
429 hlpStr + distStr + datTim.toString(".yyN");
430 }
[533]431
[11136]432 if (ephFile->_name == ephFileNameGPS) {
433 return ephFile;
434 }
435 ephFile->_name = ephFileNameGPS;
436 ephFile->close();
[533]437
[11136]438 QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
439 QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
[533]440
[11136]441 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
442 QFile::exists(ephFileNameGPS) ) {
443 appendFlagGPS = QIODevice::Append;
444 }
[535]445
[11136]446 ephFile->_fileN = new QFile(ephFileNameGPS);
447 ephFile->_fileN->open(QIODevice::WriteOnly | appendFlagGPS);
448 ephFile->_streamN = new QTextStream();
449 ephFile->_streamN->setDevice(ephFile->_fileN);
450 QTextStream* streamGPS = ephFile->_streamN;
[533]451
[11136]452 if (_rinexVers == 2) {
453 QString ephFileNameGlonass = _ephPath + base +
454 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
455 hlpStr + distStr + datTim.toString(".yyG");
[7291]456
[11136]457 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
458 QFile::exists(ephFileNameGlonass) ) {
459 appendFlagGlonass = QIODevice::Append;
460 }
[559]461
[11136]462 ephFile->_fileG = new QFile(ephFileNameGlonass);
463 ephFile->_fileG->open(QIODevice::WriteOnly | appendFlagGlonass);
464 ephFile->_streamG = new QTextStream();
465 ephFile->_streamG->setDevice(ephFile->_fileG);
466 }
467 QTextStream* streamGlonass = ephFile->_streamG;
[7999]468
[11136]469 // Header - RINEX Version 3
470 // ------------------------
471 if (_rinexVers > 2) {
472 if ( ! (appendFlagGPS & QIODevice::Append)) {
473 double rinexVersion = defaultRnxNavVersion4;
474 if (_rinexVers < 4.0) {
475 rinexVersion = defaultRnxNavVersion3;
476 }
477 QString line = QString().asprintf("%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
478 rinexVersion, "", "");
479 *streamGPS << line;
480 line.clear();
[9765]481
[11136]482 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
483 *streamGPS << _pgmName.toLatin1().data()
484 << _userName.toLatin1().data()
485 << hlp.toLatin1().data()
486 << "PGM / RUN BY / DATE\n";
[7291]487
[11136]488 QStringListIterator it(comments);
489 while (it.hasNext()) {
490 *streamGPS << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
[535]491 }
[533]492
[11136]493 if (_rinexVers == 4) {
494 int leapSecs = gnumleap(datTim.date().year(), datTim.date().month(), datTim.date().day());
495 *streamGPS << QString("%1").arg(leapSecs, 6, 10, QLatin1Char(' ')).left(60).leftJustified(60)
496 << "LEAP SECONDS\n";
497 }
[7291]498
[11136]499 line = QString().asprintf("%60sEND OF HEADER\n", "");
500 *streamGPS << line;
[559]501
[11136]502 streamGPS->flush();
503 }
504 }
[7999]505
[11136]506 // Headers - RINEX Version 2
507 // -------------------------
508 else {
509 if (! (appendFlagGPS & QIODevice::Append)) {
510 QString line = QString().asprintf("%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n",
511 defaultRnxNavVersion2, "", "");
512 *streamGPS << line;
513 line.clear();
[537]514
[11136]515 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
516 *streamGPS << _pgmName.toLatin1().data()
517 << _userName.toLatin1().data()
518 << hlp.toLatin1().data()
519 << "PGM / RUN BY / DATE\n";
520
521 QStringListIterator it(comments);
522 while (it.hasNext()) {
523 *streamGPS << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
[536]524 }
[7291]525
[11136]526 line = QString().asprintf("%60sEND OF HEADER\n", "");
527 *streamGPS << line;
[559]528
[11136]529 streamGPS->flush();
530 }
531 if (! (appendFlagGlonass & QIODevice::Append)) {
532 QString line = QString().asprintf("%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",
533 defaultRnxNavVersion2, "", "");
534 *streamGlonass << line;
535 line.clear();
[7999]536
[11136]537 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
538 *streamGlonass << _pgmName.toLatin1().data()
539 << _userName.toLatin1().data()
540 << hlp.toLatin1().data()
541 << "PGM / RUN BY / DATE\n";
[537]542
[11136]543 QStringListIterator it(comments);
544 while (it.hasNext()) {
545 *streamGlonass << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
[536]546 }
[11136]547
548 line = QString().asprintf("%60sEND OF HEADER\n", "");
549 *streamGlonass << line;
550
551 streamGlonass->flush();
[533]552 }
553 }
[11136]554
555 return ephFile;
[516]556}
557
[6432]558// Print One Ephemeris
[516]559////////////////////////////////////////////////////////////////////////////
[11136]560void t_bncCore::printEph(t_ephFile* ephFile, const t_eph& eph, bool printFile) {
[519]561
[8127]562 QString strV2 = eph.toString(defaultRnxNavVersion2);
[9483]563 QString strV3 = eph.toString(defaultRnxNavVersion3);
[9760]564 QString strV4 = eph.toString(defaultRnxNavVersion4);
[941]565
[11136]566 QTextStream* streamN = ephFile ? ephFile->_streamN : 0;
567 QTextStream* streamG = ephFile ? ephFile->_streamG : 0;
568
[10587]569 if (_rinexVers == 2 && eph.system() == t_eph::GLONASS) {
[11136]570 printOutputEph(printFile, streamG, strV2, strV3, strV4);
[7026]571 }
[10587]572 else if (_rinexVers == 2 && eph.system() == t_eph::GPS) {
[11136]573 printOutputEph(printFile, streamN, strV2, strV3, strV4);
[7026]574 }
[9765]575 else if (_rinexVers >= 3) {
[11136]576 printOutputEph(printFile, streamN, strV2, strV3, strV4);
[7026]577 }
[941]578}
579
580// Output
581////////////////////////////////////////////////////////////////////////////
[6451]582void t_bncCore::printOutputEph(bool printFile, QTextStream* stream,
[9760]583 const QString& strV2, const QString& strV3,
584 const QString& strV4) {
[9770]585 QString strVx;
586 if (_rinexVers == 2) {
587 strVx = strV2;
588 }
589 else if (_rinexVers == 3) {
590 strVx = strV3;
591 }
592 else if (_rinexVers == 4) {
593 strVx = strV4;
594 }
[4020]595
[590]596 // Output into file
597 // ----------------
[943]598 if (printFile && stream) {
[9770]599 *stream << strVx.toLatin1();
[943]600 stream->flush();
[517]601 }
[590]602
603 // Output into the socket
604 // ----------------------
[6451]605 if (_socketsEph) {
606 QMutableListIterator<QTcpSocket*> is(*_socketsEph);
[590]607 while (is.hasNext()) {
608 QTcpSocket* sock = is.next();
609 if (sock->state() == QAbstractSocket::ConnectedState) {
[9770]610 if (sock->write(strVx.toLatin1()) == -1) {
[642]611 delete sock;
612 is.remove();
613 }
[590]614 }
[642]615 else if (sock->state() != QAbstractSocket::ConnectingState) {
616 delete sock;
617 is.remove();
618 }
[590]619 }
620 }
[516]621}
[589]622
[591]623// Set Port Number
624////////////////////////////////////////////////////////////////////////////
[6451]625void t_bncCore::setPortEph(int port) {
626 _portEph = port;
627 if (_portEph != 0) {
628 delete _serverEph;
629 _serverEph = new QTcpServer;
[8921]630 _serverEph->setProxy(QNetworkProxy::NoProxy);
[10696]631 if ( !_serverEph->listen(QHostAddress::LocalHost, _portEph) ) {
[8918]632 QString message = "t_bncCore: Cannot listen on ephemeris port "
[8921]633 + QByteArray::number(_portEph) + ": "
634 + _serverEph->errorString();
[8918]635 slotMessage(message.toLatin1(), true);
[1228]636 }
[6451]637 connect(_serverEph, SIGNAL(newConnection()), this, SLOT(slotNewConnectionEph()));
638 delete _socketsEph;
639 _socketsEph = new QList<QTcpSocket*>;
[591]640 }
641}
642
[937]643// Set Port Number
644////////////////////////////////////////////////////////////////////////////
[5072]645void t_bncCore::setPortCorr(int port) {
[937]646 _portCorr = port;
647 if (_portCorr != 0) {
[942]648 delete _serverCorr;
[937]649 _serverCorr = new QTcpServer;
[8921]650 _serverCorr->setProxy(QNetworkProxy::NoProxy);
[10696]651 if ( !_serverCorr->listen(QHostAddress::LocalHost, _portCorr) ) {
[8918]652 QString message = "t_bncCore: Cannot listen on correction port "
[8921]653 + QByteArray::number(_portCorr) + ": "
654 + _serverCorr->errorString();
[8918]655 slotMessage(message.toLatin1(), true);
[1228]656 }
[937]657 connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
[942]658 delete _socketsCorr;
[937]659 _socketsCorr = new QList<QTcpSocket*>;
660 }
661}
662
[589]663// New Connection
664////////////////////////////////////////////////////////////////////////////
[6451]665void t_bncCore::slotNewConnectionEph() {
666 _socketsEph->push_back( _serverEph->nextPendingConnection() );
[589]667}
668
[937]669// New Connection
670////////////////////////////////////////////////////////////////////////////
[5072]671void t_bncCore::slotNewConnectionCorr() {
[937]672 _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
673}
674
[7291]675//
[621]676////////////////////////////////////////////////////////////////////////////
[5072]677void t_bncCore::slotQuit() {
[5729]678 delete _caster; _caster = 0;
[5066]679 qApp->quit();
[621]680}
681
[7291]682//
[936]683////////////////////////////////////////////////////////////////////////////
[6141]684void t_bncCore::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
[6151]685 QMutexLocker locker(&_mutex);
[6141]686 emit newOrbCorrections(orbCorrections);
[6151]687 if (_socketsCorr) {
[6455]688 ostringstream out;
[7291]689 t_orbCorr::writeEpoch(&out, orbCorrections);
[6455]690 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
691 while (is.hasNext()) {
692 QTcpSocket* sock = is.next();
693 if (sock->state() == QAbstractSocket::ConnectedState) {
694 if (sock->write(out.str().c_str()) == -1) {
[6151]695 delete sock;
696 is.remove();
697 }
698 }
[6455]699 else if (sock->state() != QAbstractSocket::ConnectingState) {
700 delete sock;
701 is.remove();
702 }
[6151]703 }
704 }
[6141]705}
[974]706
[7291]707//
[6141]708////////////////////////////////////////////////////////////////////////////
709void t_bncCore::slotNewClkCorrections(QList<t_clkCorr> clkCorrections) {
[974]710 QMutexLocker locker(&_mutex);
[6151]711 emit newClkCorrections(clkCorrections);
[3109]712 if (_socketsCorr) {
[6455]713 ostringstream out;
[7291]714 t_clkCorr::writeEpoch(&out, clkCorrections);
[6455]715 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
716 while (is.hasNext()) {
717 QTcpSocket* sock = is.next();
718 if (sock->state() == QAbstractSocket::ConnectedState) {
719 if (sock->write(out.str().c_str()) == -1) {
[3109]720 delete sock;
721 is.remove();
722 }
[937]723 }
[6455]724 else if (sock->state() != QAbstractSocket::ConnectingState) {
725 delete sock;
726 is.remove();
727 }
[937]728 }
729 }
[936]730}
[1538]731
[7291]732//
[1538]733////////////////////////////////////////////////////////////////////////////
[6480]734void t_bncCore::slotNewCodeBiases(QList<t_satCodeBias> codeBiases) {
[6485]735 QMutexLocker locker(&_mutex);
736 emit newCodeBiases(codeBiases);
737 if (_socketsCorr) {
738 ostringstream out;
[7291]739 t_satCodeBias::writeEpoch(&out, codeBiases);
[6485]740 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
741 while (is.hasNext()) {
742 QTcpSocket* sock = is.next();
743 if (sock->state() == QAbstractSocket::ConnectedState) {
744 if (sock->write(out.str().c_str()) == -1) {
745 delete sock;
746 is.remove();
747 }
748 }
749 else if (sock->state() != QAbstractSocket::ConnectingState) {
750 delete sock;
751 is.remove();
752 }
753 }
754 }
[6480]755}
756
[7291]757//
[6480]758////////////////////////////////////////////////////////////////////////////
[6484]759void t_bncCore::slotNewPhaseBiases(QList<t_satPhaseBias> phaseBiases) {
[6485]760 QMutexLocker locker(&_mutex);
761 emit newPhaseBiases(phaseBiases);
762 if (_socketsCorr) {
763 ostringstream out;
[7291]764 t_satPhaseBias::writeEpoch(&out, phaseBiases);
[6485]765 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
766 while (is.hasNext()) {
767 QTcpSocket* sock = is.next();
768 if (sock->state() == QAbstractSocket::ConnectedState) {
769 if (sock->write(out.str().c_str()) == -1) {
770 delete sock;
771 is.remove();
772 }
773 }
774 else if (sock->state() != QAbstractSocket::ConnectingState) {
775 delete sock;
776 is.remove();
777 }
778 }
779 }
[6484]780}
781
[7291]782//
[6484]783////////////////////////////////////////////////////////////////////////////
784void t_bncCore::slotNewTec(t_vTec vTec) {
[6485]785 QMutexLocker locker(&_mutex);
786 emit newTec(vTec);
787 if (_socketsCorr) {
788 ostringstream out;
[7291]789 t_vTec::write(&out, vTec);
[6485]790 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
791 while (is.hasNext()) {
792 QTcpSocket* sock = is.next();
793 if (sock->state() == QAbstractSocket::ConnectedState) {
794 if (sock->write(out.str().c_str()) == -1) {
795 delete sock;
796 is.remove();
797 }
798 }
799 else if (sock->state() != QAbstractSocket::ConnectingState) {
800 delete sock;
801 is.remove();
802 }
803 }
804 }
[6484]805}
806
[7291]807//
[6484]808////////////////////////////////////////////////////////////////////////////
[11008]809void t_bncCore::slotNewMetaData(t_metaData metaData) {
810 QMutexLocker locker(&_mutex);
811 emit newMetaData(metaData);
812 if (_socketsCorr) {
813 ostringstream out;
814 t_metaData::write(&out, metaData);
815 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
816 while (is.hasNext()) {
817 QTcpSocket* sock = is.next();
818 if (sock->state() == QAbstractSocket::ConnectedState) {
819 if (sock->write(out.str().c_str()) == -1) {
820 delete sock;
821 is.remove();
822 }
823 }
824 else if (sock->state() != QAbstractSocket::ConnectingState) {
825 delete sock;
826 is.remove();
827 }
828 }
829 }
830}
831
832//
833////////////////////////////////////////////////////////////////////////////
[11039]834void t_bncCore::slotNewSatAntennas(QList<t_satAntenna> satAntennas) {
835 QMutexLocker locker(&_mutex);
836 emit newSatAntennas(satAntennas);
837 if (_socketsCorr) {
838 ostringstream out;
839 t_satAntenna::writeEpoch(&out, satAntennas);
840 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
841 while (is.hasNext()) {
842 QTcpSocket* sock = is.next();
843 if (sock->state() == QAbstractSocket::ConnectedState) {
844 if (sock->write(out.str().c_str()) == -1) {
845 delete sock;
846 is.remove();
847 }
848 }
849 else if (sock->state() != QAbstractSocket::ConnectingState) {
850 delete sock;
851 is.remove();
852 }
853 }
854 }
855}
856
857//
858////////////////////////////////////////////////////////////////////////////
[5072]859void t_bncCore::setConfFileName(const QString& confFileName) {
[4169]860 if (confFileName.isEmpty()) {
[7291]861 _confFileName = QDir::homePath() + QDir::separator()
[4169]862 + ".config" + QDir::separator()
[5066]863 + qApp->organizationName() + QDir::separator()
864 + qApp->applicationName() + ".bnc";
[1538]865 }
[4169]866 else {
867 _confFileName = confFileName;
868 }
[1538]869}
[2385]870
871// Raw Output
872////////////////////////////////////////////////////////////////////////////
[5072]873void t_bncCore::writeRawData(const QByteArray& data, const QByteArray& staID,
[2518]874 const QByteArray& format) {
[2385]875
[2386]876 QMutexLocker locker(&_mutex);
877
[2519]878 if (!_rawFile) {
[2386]879 bncSettings settings;
[2519]880 QByteArray fileName = settings.value("rawOutFile").toByteArray();
881 if (!fileName.isEmpty()) {
[3524]882 _rawFile = new bncRawFile(fileName, staID, bncRawFile::output);
[2407]883 }
[2386]884 }
885
[2519]886 if (_rawFile) {
887 _rawFile->writeRawData(data, staID, format);
[2386]888 }
[2385]889}
[2672]890
[7291]891//
[2909]892////////////////////////////////////////////////////////////////////////////
[10040]893void t_bncCore::initCombination() {
894 bncComb::getInstance();
895 if (BNC_CMB->nStreams() < 1) {
896 bncComb::destruct();
[2909]897 }
898}
[3231]899
[7291]900//
[3231]901////////////////////////////////////////////////////////////////////////////
[5072]902void t_bncCore::stopCombination() {
[10040]903 bncComb::destruct();
[3231]904}
[4167]905
[11066]906// SSR QC of the decoded correction streams (optional)
907////////////////////////////////////////////////////////////////////////////
908void t_bncCore::initSsrQc() {
909 delete _ssrQc; _ssrQc = 0;
910 bncSettings settings;
[11075]911 QString dirName = settings.value("ssrQcPath").toString();
912 if (dirName.isEmpty()) {
[11066]913 return;
914 }
[11075]915 expandEnvVar(dirName);
916 QStringList streams = settings.value("ssrQcStreams").toString().split(QRegularExpression("[ ,;]+"), Qt::SkipEmptyParts);
917 if (streams.isEmpty()) {
918 streams << "ALL";
919 }
[11066]920 QStringList hlp = settings.value("ssrQcIntr").toString().split(' ', Qt::SkipEmptyParts);
921 double interval = 3600.0;
922 if (hlp.size() == 2) {
923 double fac = (hlp[1] == "min") ? 60.0 : (hlp[1] == "hour") ? 3600.0 : (hlp[1] == "day") ? 86400.0 : 0.0;
924 if (hlp[0].toDouble() * fac > 0.0) {
925 interval = hlp[0].toDouble() * fac;
926 }
927 }
[11075]928 _ssrQc = new t_ssrQc(dirName, interval, streams, settings.value("ssrQcRef").toString().trimmed());
[11066]929}
930
931// Writes the final SSR QC report
932////////////////////////////////////////////////////////////////////////////
933void t_bncCore::stopSsrQc() {
934 delete _ssrQc; _ssrQc = 0;
935}
936
[5846]937//
938////////////////////////////////////////////////////////////////////////////
939bool t_bncCore::dateAndTimeGPSSet() const {
940 QMutexLocker locker(&_mutexDateAndTimeGPS);
941 if (_dateAndTimeGPS) {
942 return true;
943 }
944 else {
945 return false;
946 }
947}
948
949//
950////////////////////////////////////////////////////////////////////////////
951QDateTime t_bncCore::dateAndTimeGPS() const {
952 QMutexLocker locker(&_mutexDateAndTimeGPS);
953 if (_dateAndTimeGPS) {
954 return *_dateAndTimeGPS;
955 }
956 else {
957 return QDateTime();
958 }
959}
960
961//
962////////////////////////////////////////////////////////////////////////////
963void t_bncCore::setDateAndTimeGPS(QDateTime dateTime) {
964 QMutexLocker locker(&_mutexDateAndTimeGPS);
965 delete _dateAndTimeGPS;
966 _dateAndTimeGPS = new QDateTime(dateTime);
967}
[5900]968
969//
970////////////////////////////////////////////////////////////////////////////
[5946]971void t_bncCore::startPPP() {
972 _pppMain->start();
[5900]973}
974
975//
976////////////////////////////////////////////////////////////////////////////
977void t_bncCore::stopPPP() {
[5903]978 _pppMain->stop();
[5972]979 emit stopRinexPPP();
[5900]980}
[6383]981
Note: See TracBrowser for help on using the repository browser.