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

Last change on this file since 11187 was 11187, checked in by stuerze, 3 weeks ago

Structured logging improved

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