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

Last change on this file since 11215 was 11215, checked in by stuerze, 2 weeks ago

Upload Ephemeris: majority vote included

File size: 34.2 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);
[11215]289
290 // Satellite outside the range supported by BNC (e.g. G39, test signal of
291 // NTS-3, not IS-GPS compliant): the ephemeris is neither written to RINEX
292 // nor passed on (upload, PPP, combination, SSR QC); each data set is
293 // logged once as RINEX record instead
294 if (eph->prn().toInt() == 0) {
295 QString key = QString("%1 %2 %3 %4").arg(eph->prn().toInternalString().c_str())
296 .arg(eph->TOC().datestr().c_str()).arg(eph->TOC().timestr(0).c_str()).arg(eph->IOD());
297 if (!_ephOutOfRange.contains(key)) {
298 _ephOutOfRange.insert(key);
299 double version = (_rinexVers == 2) ? defaultRnxNavVersion2 :
300 (_rinexVers == 4) ? defaultRnxNavVersion4 : defaultRnxNavVersion3;
301 messagePrivate(t_logRecord::message(t_logRecord::warning,
302 QString("%1: ephemeris of satellite %2 outside the range supported by BNC - not used, RINEX %3 record:")
303 .arg(eph->receptStaID()).arg(eph->prn().toString().c_str()).arg(version, 0, 'f', 2).toLatin1(), "bce"));
304 QStringList lines = eph->toString(version).split('\n', Qt::SkipEmptyParts);
305 for (int ii = 0; ii < lines.size(); ii++) {
306 messagePrivate(t_logRecord::message(t_logRecord::warning, lines[ii].toLatin1(), "bce"));
307 }
308 }
309 return failure;
310 }
[6520]311 t_irc ircPut = _ephUser.putNewEph(eph, true);
[10549]312#ifdef BNC_DEBUG_BCE
[9767]313 if (eph->checkState() == t_eph::unhealthy) {
[11185]314 messagePrivate(t_logRecord::debugMessage("bce", QString("%1: UNHEALTHY %2:%3")
[9217]315 .arg(eph->receptStaID())
[10587]316 .arg(eph->typeStr(eph->type(), eph->prn(), 99.0))
[11179]317 .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1()));
[6519]318 }
[9768]319 if (eph->checkState() == t_eph::bad) {
[11185]320 messagePrivate(t_logRecord::debugMessage("bce", QString("%1: WRONG %2:%3")
[9217]321 .arg(eph->receptStaID())
[10587]322 .arg(eph->typeStr(eph->type(), eph->prn(), 99.0))
[11179]323 .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1()));
[7208]324 }
[9772]325 if (eph->checkState() == t_eph::outdated) {
[11185]326 messagePrivate(t_logRecord::debugMessage("bce", QString("%1: OUTDATED %2:%3")
[9217]327 .arg(eph->receptStaID())
[10587]328 .arg(eph->typeStr(eph->type(), eph->prn(), 99.0))
[11179]329 .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1()));
[8215]330 }
[9379]331#endif
[11136]332 t_ephFile* ephFile = printEphHeader(eph->receptStaID());
333 bool printFile = (ircPut == success);
334 if (ephFile && ephFile->_ephUser) {
335 // file per stream: new ephemerides of this stream, independent of other streams;
336 // the check state of the emitted ephemeris stays that of the common check
337 t_eph::e_checkState checkState = eph->checkState();
338 printFile = (ephFile->_ephUser->putNewEph(eph, true) == success);
339 eph->setCheckState(checkState);
340 }
341 printEph(ephFile, *eph, printFile);
[6520]342 return success;
[511]343}
[6520]344
[7291]345// New GPS Ephemeris
[6520]346////////////////////////////////////////////////////////////////////////////
347void t_bncCore::slotNewGPSEph(t_ephGPS eph) {
348 if (checkPrintEph(&eph) == success) {
349 emit newGPSEph(eph);
350 }
351}
[7291]352
[535]353// New Glonass Ephemeris
[511]354////////////////////////////////////////////////////////////////////////////
[6432]355void t_bncCore::slotNewGlonassEph(t_ephGlo eph) {
[6520]356 if (checkPrintEph(&eph) == success) {
357 emit newGlonassEph(eph);
[6519]358 }
[511]359}
360
[2770]361// New Galileo Ephemeris
362////////////////////////////////////////////////////////////////////////////
[6432]363void t_bncCore::slotNewGalileoEph(t_ephGal eph) {
[6520]364 if (checkPrintEph(&eph) == success) {
365 emit newGalileoEph(eph);
[6519]366 }
[6432]367}
[2772]368
[6432]369// New SBAS Ephemeris
370////////////////////////////////////////////////////////////////////////////
371void t_bncCore::slotNewSBASEph(t_ephSBAS eph) {
[6520]372 if (checkPrintEph(&eph) == success) {
373 emit newSBASEph(eph);
[6519]374 }
[2770]375}
376
[6598]377// New BDS Ephemeris
[6595]378////////////////////////////////////////////////////////////////////////////
[6598]379void t_bncCore::slotNewBDSEph(t_ephBDS eph) {
[6595]380 if (checkPrintEph(&eph) == success) {
[6598]381 emit newBDSEph(eph);
[6595]382 }
383}
[6432]384
[11136]385// Close RINEX Navigation File(s)
[516]386////////////////////////////////////////////////////////////////////////////
[11136]387void t_bncCore::t_ephFile::close() {
388 delete _streamN; _streamN = 0;
389 delete _fileN; _fileN = 0;
390 delete _streamG; _streamG = 0;
391 delete _fileG; _fileG = 0;
392}
[528]393
[11136]394// Destructor
395////////////////////////////////////////////////////////////////////////////
396t_bncCore::t_ephFile::~t_ephFile() {
397 close();
398 delete _ephUser;
399}
[535]400
[11136]401// Station part of a RINEX navigation file name: "BRDC" (+ "00WRD" in RINEX 3/4)
402// for the single file, otherwise derived from the stream like the observation files
403////////////////////////////////////////////////////////////////////////////
404QString t_bncCore::ephFileNameBase(const QString& staID, const QString& country) const {
405 QString ID = staID.isEmpty() ? QString("BRDC") : staID.left(4).toUpper();
406 if (_rinexVers <= 2) {
407 return ID;
[7999]408 }
[11136]409 if (staID.size() >= 9 &&
410 isdigit((unsigned char) staID[4].toLatin1()) &&
411 isdigit((unsigned char) staID[5].toLatin1())) {
412 return staID.left(9).toUpper(); // e.g. BCEP00BKG0 -> BCEP00BKG
413 }
414 return ID + "00" + ((!staID.isEmpty() && country.size() >= 3) ? country.left(3).toUpper()
415 : QString("WRD")); // WORLD
416}
[7999]417
[11136]418// Print Header of the output File(s), returns the file of the stream
419////////////////////////////////////////////////////////////////////////////
420t_bncCore::t_ephFile* t_bncCore::printEphHeader(QString receptStaID) {
421
422 bncSettings settings;
423
[534]424 // Initialization
425 // --------------
426 if (_rinexVers == 0) {
[528]427
[9760]428 _rinexVers = settings.value("ephVersion").toInt();
[529]429
[11136]430 _ephFilePerStation = Qt::CheckState(settings.value("ephFilePerStation").toInt()) == Qt::Checked;
431
[533]432 _ephPath = settings.value("ephPath").toString();
433
434 if ( !_ephPath.isEmpty() ) {
435 if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
436 _ephPath += QDir::separator();
437 }
438 expandEnvVar(_ephPath);
439 }
[517]440 }
[533]441
[11136]442 if (_ephPath.isEmpty()) {
443 return 0;
444 }
[533]445
[11136]446 QString key = _ephFilePerStation ? receptStaID : QString();
[533]447
[11136]448 // Source comments and station part of the file name
449 // --------------------------------------------------
450 QStringList comments;
451 QMap<QString, QString> nameBase; // staID -> station part of its file name
452 QListIterator<QString> it(settings.value("mountPoints").toStringList());
453 while (it.hasNext()) {
454 QStringList hlp = it.next().split(" ");
455 if (hlp.size() < 7)
456 continue;
457 QUrl url(hlp[0]);
458 QString decoder = hlp[1];
459 QString staID = url.path().mid(1);
460 if (key.isEmpty() || staID == key) {
461 comments.append("Source: " + decoder +
462 " " + QUrl::toAce(url.host()) +
463 "/" + url.path().mid(1).toLatin1());
464 }
465 nameBase[staID] = ephFileNameBase(staID, hlp[2]);
466 }
[533]467
[11136]468 QString base = (!key.isEmpty() && nameBase.contains(key)) ? nameBase[key]
469 : ephFileNameBase(key, QString());
470 QString distStr;
471 if (!key.isEmpty()) {
472 QMapIterator<QString, QString> im(nameBase);
473 while (im.hasNext()) {
474 im.next();
475 if (im.key() != key && im.value() == base) { // name conflict with another stream
476 distStr = "_" + key;
477 break;
[10091]478 }
[575]479 }
[11136]480 }
[563]481
[11136]482 t_ephFile*& ephFile = _ephFiles[key];
483 if (!ephFile) {
484 ephFile = new t_ephFile;
485 if (_ephFilePerStation) {
486 ephFile->_ephUser = new bncEphUser(false);
[533]487 }
[11136]488 }
[533]489
[11136]490 // (Re-)Open output File(s)
491 // ------------------------
492 QDateTime datTim = currentDateAndTimeGPS();
[533]493
[11136]494 QString hlpStr = bncRinex::nextEpochStr(datTim,
495 settings.value("ephIntr").toString(), _rinexVers);
[536]496
[11136]497 QString ephFileNameGPS = _ephPath + base;
[535]498
[11136]499 if (_rinexVers > 2) {
500 ephFileNameGPS += "_S_" + // stream
501 QString("%1").arg(datTim.date().year()) +
502 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
503 hlpStr + // HM_period
504 "_MN" + // mixed BRDC
505 distStr + ".rnx";
506 }
507 else { // RNX v2.11
508 ephFileNameGPS += QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
509 hlpStr + distStr + datTim.toString(".yyN");
510 }
[533]511
[11136]512 if (ephFile->_name == ephFileNameGPS) {
513 return ephFile;
514 }
515 ephFile->_name = ephFileNameGPS;
516 ephFile->close();
[533]517
[11136]518 QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
519 QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
[533]520
[11136]521 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
522 QFile::exists(ephFileNameGPS) ) {
523 appendFlagGPS = QIODevice::Append;
524 }
[535]525
[11136]526 ephFile->_fileN = new QFile(ephFileNameGPS);
527 ephFile->_fileN->open(QIODevice::WriteOnly | appendFlagGPS);
528 ephFile->_streamN = new QTextStream();
529 ephFile->_streamN->setDevice(ephFile->_fileN);
530 QTextStream* streamGPS = ephFile->_streamN;
[533]531
[11136]532 if (_rinexVers == 2) {
533 QString ephFileNameGlonass = _ephPath + base +
534 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
535 hlpStr + distStr + datTim.toString(".yyG");
[7291]536
[11136]537 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
538 QFile::exists(ephFileNameGlonass) ) {
539 appendFlagGlonass = QIODevice::Append;
540 }
[559]541
[11136]542 ephFile->_fileG = new QFile(ephFileNameGlonass);
543 ephFile->_fileG->open(QIODevice::WriteOnly | appendFlagGlonass);
544 ephFile->_streamG = new QTextStream();
545 ephFile->_streamG->setDevice(ephFile->_fileG);
546 }
547 QTextStream* streamGlonass = ephFile->_streamG;
[7999]548
[11136]549 // Header - RINEX Version 3
550 // ------------------------
551 if (_rinexVers > 2) {
552 if ( ! (appendFlagGPS & QIODevice::Append)) {
553 double rinexVersion = defaultRnxNavVersion4;
554 if (_rinexVers < 4.0) {
555 rinexVersion = defaultRnxNavVersion3;
556 }
557 QString line = QString().asprintf("%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
558 rinexVersion, "", "");
559 *streamGPS << line;
560 line.clear();
[9765]561
[11136]562 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
563 *streamGPS << _pgmName.toLatin1().data()
564 << _userName.toLatin1().data()
565 << hlp.toLatin1().data()
566 << "PGM / RUN BY / DATE\n";
[7291]567
[11136]568 QStringListIterator it(comments);
569 while (it.hasNext()) {
570 *streamGPS << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
[535]571 }
[533]572
[11136]573 if (_rinexVers == 4) {
574 int leapSecs = gnumleap(datTim.date().year(), datTim.date().month(), datTim.date().day());
575 *streamGPS << QString("%1").arg(leapSecs, 6, 10, QLatin1Char(' ')).left(60).leftJustified(60)
576 << "LEAP SECONDS\n";
577 }
[7291]578
[11136]579 line = QString().asprintf("%60sEND OF HEADER\n", "");
580 *streamGPS << line;
[559]581
[11136]582 streamGPS->flush();
583 }
584 }
[7999]585
[11136]586 // Headers - RINEX Version 2
587 // -------------------------
588 else {
589 if (! (appendFlagGPS & QIODevice::Append)) {
590 QString line = QString().asprintf("%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n",
591 defaultRnxNavVersion2, "", "");
592 *streamGPS << line;
593 line.clear();
[537]594
[11136]595 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
596 *streamGPS << _pgmName.toLatin1().data()
597 << _userName.toLatin1().data()
598 << hlp.toLatin1().data()
599 << "PGM / RUN BY / DATE\n";
600
601 QStringListIterator it(comments);
602 while (it.hasNext()) {
603 *streamGPS << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
[536]604 }
[7291]605
[11136]606 line = QString().asprintf("%60sEND OF HEADER\n", "");
607 *streamGPS << line;
[559]608
[11136]609 streamGPS->flush();
610 }
611 if (! (appendFlagGlonass & QIODevice::Append)) {
612 QString line = QString().asprintf("%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",
613 defaultRnxNavVersion2, "", "");
614 *streamGlonass << line;
615 line.clear();
[7999]616
[11136]617 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
618 *streamGlonass << _pgmName.toLatin1().data()
619 << _userName.toLatin1().data()
620 << hlp.toLatin1().data()
621 << "PGM / RUN BY / DATE\n";
[537]622
[11136]623 QStringListIterator it(comments);
624 while (it.hasNext()) {
625 *streamGlonass << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
[536]626 }
[11136]627
628 line = QString().asprintf("%60sEND OF HEADER\n", "");
629 *streamGlonass << line;
630
631 streamGlonass->flush();
[533]632 }
633 }
[11136]634
635 return ephFile;
[516]636}
637
[6432]638// Print One Ephemeris
[516]639////////////////////////////////////////////////////////////////////////////
[11136]640void t_bncCore::printEph(t_ephFile* ephFile, const t_eph& eph, bool printFile) {
[519]641
[8127]642 QString strV2 = eph.toString(defaultRnxNavVersion2);
[9483]643 QString strV3 = eph.toString(defaultRnxNavVersion3);
[9760]644 QString strV4 = eph.toString(defaultRnxNavVersion4);
[941]645
[11136]646 QTextStream* streamN = ephFile ? ephFile->_streamN : 0;
647 QTextStream* streamG = ephFile ? ephFile->_streamG : 0;
648
[10587]649 if (_rinexVers == 2 && eph.system() == t_eph::GLONASS) {
[11136]650 printOutputEph(printFile, streamG, strV2, strV3, strV4);
[7026]651 }
[10587]652 else if (_rinexVers == 2 && eph.system() == t_eph::GPS) {
[11136]653 printOutputEph(printFile, streamN, strV2, strV3, strV4);
[7026]654 }
[9765]655 else if (_rinexVers >= 3) {
[11136]656 printOutputEph(printFile, streamN, strV2, strV3, strV4);
[7026]657 }
[941]658}
659
660// Output
661////////////////////////////////////////////////////////////////////////////
[6451]662void t_bncCore::printOutputEph(bool printFile, QTextStream* stream,
[9760]663 const QString& strV2, const QString& strV3,
664 const QString& strV4) {
[9770]665 QString strVx;
666 if (_rinexVers == 2) {
667 strVx = strV2;
668 }
669 else if (_rinexVers == 3) {
670 strVx = strV3;
671 }
672 else if (_rinexVers == 4) {
673 strVx = strV4;
674 }
[4020]675
[590]676 // Output into file
677 // ----------------
[943]678 if (printFile && stream) {
[9770]679 *stream << strVx.toLatin1();
[943]680 stream->flush();
[517]681 }
[590]682
683 // Output into the socket
684 // ----------------------
[6451]685 if (_socketsEph) {
686 QMutableListIterator<QTcpSocket*> is(*_socketsEph);
[590]687 while (is.hasNext()) {
688 QTcpSocket* sock = is.next();
689 if (sock->state() == QAbstractSocket::ConnectedState) {
[9770]690 if (sock->write(strVx.toLatin1()) == -1) {
[642]691 delete sock;
692 is.remove();
693 }
[590]694 }
[642]695 else if (sock->state() != QAbstractSocket::ConnectingState) {
696 delete sock;
697 is.remove();
698 }
[590]699 }
700 }
[516]701}
[589]702
[591]703// Set Port Number
704////////////////////////////////////////////////////////////////////////////
[6451]705void t_bncCore::setPortEph(int port) {
706 _portEph = port;
707 if (_portEph != 0) {
708 delete _serverEph;
709 _serverEph = new QTcpServer;
[8921]710 _serverEph->setProxy(QNetworkProxy::NoProxy);
[10696]711 if ( !_serverEph->listen(QHostAddress::LocalHost, _portEph) ) {
[8918]712 QString message = "t_bncCore: Cannot listen on ephemeris port "
[8921]713 + QByteArray::number(_portEph) + ": "
714 + _serverEph->errorString();
[11185]715 slotLogRecord(t_logRecord::message(t_logRecord::error, message.toLatin1(), "bnc"), true);
[1228]716 }
[6451]717 connect(_serverEph, SIGNAL(newConnection()), this, SLOT(slotNewConnectionEph()));
718 delete _socketsEph;
719 _socketsEph = new QList<QTcpSocket*>;
[591]720 }
721}
722
[937]723// Set Port Number
724////////////////////////////////////////////////////////////////////////////
[5072]725void t_bncCore::setPortCorr(int port) {
[937]726 _portCorr = port;
727 if (_portCorr != 0) {
[942]728 delete _serverCorr;
[937]729 _serverCorr = new QTcpServer;
[8921]730 _serverCorr->setProxy(QNetworkProxy::NoProxy);
[10696]731 if ( !_serverCorr->listen(QHostAddress::LocalHost, _portCorr) ) {
[8918]732 QString message = "t_bncCore: Cannot listen on correction port "
[8921]733 + QByteArray::number(_portCorr) + ": "
734 + _serverCorr->errorString();
[11185]735 slotLogRecord(t_logRecord::message(t_logRecord::error, message.toLatin1(), "bnc"), true);
[1228]736 }
[937]737 connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
[942]738 delete _socketsCorr;
[937]739 _socketsCorr = new QList<QTcpSocket*>;
740 }
741}
742
[589]743// New Connection
744////////////////////////////////////////////////////////////////////////////
[6451]745void t_bncCore::slotNewConnectionEph() {
746 _socketsEph->push_back( _serverEph->nextPendingConnection() );
[589]747}
748
[937]749// New Connection
750////////////////////////////////////////////////////////////////////////////
[5072]751void t_bncCore::slotNewConnectionCorr() {
[937]752 _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
753}
754
[7291]755//
[621]756////////////////////////////////////////////////////////////////////////////
[5072]757void t_bncCore::slotQuit() {
[5729]758 delete _caster; _caster = 0;
[5066]759 qApp->quit();
[621]760}
761
[7291]762//
[936]763////////////////////////////////////////////////////////////////////////////
[6141]764void t_bncCore::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
[6151]765 QMutexLocker locker(&_mutex);
[6141]766 emit newOrbCorrections(orbCorrections);
[6151]767 if (_socketsCorr) {
[6455]768 ostringstream out;
[7291]769 t_orbCorr::writeEpoch(&out, orbCorrections);
[6455]770 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
771 while (is.hasNext()) {
772 QTcpSocket* sock = is.next();
773 if (sock->state() == QAbstractSocket::ConnectedState) {
774 if (sock->write(out.str().c_str()) == -1) {
[6151]775 delete sock;
776 is.remove();
777 }
778 }
[6455]779 else if (sock->state() != QAbstractSocket::ConnectingState) {
780 delete sock;
781 is.remove();
782 }
[6151]783 }
784 }
[6141]785}
[974]786
[7291]787//
[6141]788////////////////////////////////////////////////////////////////////////////
789void t_bncCore::slotNewClkCorrections(QList<t_clkCorr> clkCorrections) {
[974]790 QMutexLocker locker(&_mutex);
[6151]791 emit newClkCorrections(clkCorrections);
[3109]792 if (_socketsCorr) {
[6455]793 ostringstream out;
[7291]794 t_clkCorr::writeEpoch(&out, clkCorrections);
[6455]795 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
796 while (is.hasNext()) {
797 QTcpSocket* sock = is.next();
798 if (sock->state() == QAbstractSocket::ConnectedState) {
799 if (sock->write(out.str().c_str()) == -1) {
[3109]800 delete sock;
801 is.remove();
802 }
[937]803 }
[6455]804 else if (sock->state() != QAbstractSocket::ConnectingState) {
805 delete sock;
806 is.remove();
807 }
[937]808 }
809 }
[936]810}
[1538]811
[7291]812//
[1538]813////////////////////////////////////////////////////////////////////////////
[6480]814void t_bncCore::slotNewCodeBiases(QList<t_satCodeBias> codeBiases) {
[6485]815 QMutexLocker locker(&_mutex);
816 emit newCodeBiases(codeBiases);
817 if (_socketsCorr) {
818 ostringstream out;
[7291]819 t_satCodeBias::writeEpoch(&out, codeBiases);
[6485]820 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
821 while (is.hasNext()) {
822 QTcpSocket* sock = is.next();
823 if (sock->state() == QAbstractSocket::ConnectedState) {
824 if (sock->write(out.str().c_str()) == -1) {
825 delete sock;
826 is.remove();
827 }
828 }
829 else if (sock->state() != QAbstractSocket::ConnectingState) {
830 delete sock;
831 is.remove();
832 }
833 }
834 }
[6480]835}
836
[7291]837//
[6480]838////////////////////////////////////////////////////////////////////////////
[6484]839void t_bncCore::slotNewPhaseBiases(QList<t_satPhaseBias> phaseBiases) {
[6485]840 QMutexLocker locker(&_mutex);
841 emit newPhaseBiases(phaseBiases);
842 if (_socketsCorr) {
843 ostringstream out;
[7291]844 t_satPhaseBias::writeEpoch(&out, phaseBiases);
[6485]845 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
846 while (is.hasNext()) {
847 QTcpSocket* sock = is.next();
848 if (sock->state() == QAbstractSocket::ConnectedState) {
849 if (sock->write(out.str().c_str()) == -1) {
850 delete sock;
851 is.remove();
852 }
853 }
854 else if (sock->state() != QAbstractSocket::ConnectingState) {
855 delete sock;
856 is.remove();
857 }
858 }
859 }
[6484]860}
861
[7291]862//
[6484]863////////////////////////////////////////////////////////////////////////////
864void t_bncCore::slotNewTec(t_vTec vTec) {
[6485]865 QMutexLocker locker(&_mutex);
866 emit newTec(vTec);
867 if (_socketsCorr) {
868 ostringstream out;
[7291]869 t_vTec::write(&out, vTec);
[6485]870 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
871 while (is.hasNext()) {
872 QTcpSocket* sock = is.next();
873 if (sock->state() == QAbstractSocket::ConnectedState) {
874 if (sock->write(out.str().c_str()) == -1) {
875 delete sock;
876 is.remove();
877 }
878 }
879 else if (sock->state() != QAbstractSocket::ConnectingState) {
880 delete sock;
881 is.remove();
882 }
883 }
884 }
[6484]885}
886
[7291]887//
[6484]888////////////////////////////////////////////////////////////////////////////
[11008]889void t_bncCore::slotNewMetaData(t_metaData metaData) {
890 QMutexLocker locker(&_mutex);
891 emit newMetaData(metaData);
892 if (_socketsCorr) {
893 ostringstream out;
894 t_metaData::write(&out, metaData);
895 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
896 while (is.hasNext()) {
897 QTcpSocket* sock = is.next();
898 if (sock->state() == QAbstractSocket::ConnectedState) {
899 if (sock->write(out.str().c_str()) == -1) {
900 delete sock;
901 is.remove();
902 }
903 }
904 else if (sock->state() != QAbstractSocket::ConnectingState) {
905 delete sock;
906 is.remove();
907 }
908 }
909 }
910}
911
912//
913////////////////////////////////////////////////////////////////////////////
[11039]914void t_bncCore::slotNewSatAntennas(QList<t_satAntenna> satAntennas) {
915 QMutexLocker locker(&_mutex);
916 emit newSatAntennas(satAntennas);
917 if (_socketsCorr) {
918 ostringstream out;
919 t_satAntenna::writeEpoch(&out, satAntennas);
920 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
921 while (is.hasNext()) {
922 QTcpSocket* sock = is.next();
923 if (sock->state() == QAbstractSocket::ConnectedState) {
924 if (sock->write(out.str().c_str()) == -1) {
925 delete sock;
926 is.remove();
927 }
928 }
929 else if (sock->state() != QAbstractSocket::ConnectingState) {
930 delete sock;
931 is.remove();
932 }
933 }
934 }
935}
936
937//
938////////////////////////////////////////////////////////////////////////////
[5072]939void t_bncCore::setConfFileName(const QString& confFileName) {
[4169]940 if (confFileName.isEmpty()) {
[7291]941 _confFileName = QDir::homePath() + QDir::separator()
[4169]942 + ".config" + QDir::separator()
[5066]943 + qApp->organizationName() + QDir::separator()
944 + qApp->applicationName() + ".bnc";
[1538]945 }
[4169]946 else {
947 _confFileName = confFileName;
948 }
[1538]949}
[2385]950
951// Raw Output
952////////////////////////////////////////////////////////////////////////////
[5072]953void t_bncCore::writeRawData(const QByteArray& data, const QByteArray& staID,
[2518]954 const QByteArray& format) {
[2385]955
[2386]956 QMutexLocker locker(&_mutex);
957
[2519]958 if (!_rawFile) {
[2386]959 bncSettings settings;
[2519]960 QByteArray fileName = settings.value("rawOutFile").toByteArray();
961 if (!fileName.isEmpty()) {
[3524]962 _rawFile = new bncRawFile(fileName, staID, bncRawFile::output);
[2407]963 }
[2386]964 }
965
[2519]966 if (_rawFile) {
967 _rawFile->writeRawData(data, staID, format);
[2386]968 }
[2385]969}
[2672]970
[7291]971//
[2909]972////////////////////////////////////////////////////////////////////////////
[10040]973void t_bncCore::initCombination() {
974 bncComb::getInstance();
975 if (BNC_CMB->nStreams() < 1) {
976 bncComb::destruct();
[2909]977 }
978}
[3231]979
[7291]980//
[3231]981////////////////////////////////////////////////////////////////////////////
[5072]982void t_bncCore::stopCombination() {
[10040]983 bncComb::destruct();
[3231]984}
[4167]985
[11066]986// SSR QC of the decoded correction streams (optional)
987////////////////////////////////////////////////////////////////////////////
988void t_bncCore::initSsrQc() {
989 delete _ssrQc; _ssrQc = 0;
990 bncSettings settings;
[11075]991 QString dirName = settings.value("ssrQcPath").toString();
992 if (dirName.isEmpty()) {
[11066]993 return;
994 }
[11075]995 expandEnvVar(dirName);
996 QStringList streams = settings.value("ssrQcStreams").toString().split(QRegularExpression("[ ,;]+"), Qt::SkipEmptyParts);
997 if (streams.isEmpty()) {
998 streams << "ALL";
999 }
[11066]1000 QStringList hlp = settings.value("ssrQcIntr").toString().split(' ', Qt::SkipEmptyParts);
1001 double interval = 3600.0;
1002 if (hlp.size() == 2) {
1003 double fac = (hlp[1] == "min") ? 60.0 : (hlp[1] == "hour") ? 3600.0 : (hlp[1] == "day") ? 86400.0 : 0.0;
1004 if (hlp[0].toDouble() * fac > 0.0) {
1005 interval = hlp[0].toDouble() * fac;
1006 }
1007 }
[11075]1008 _ssrQc = new t_ssrQc(dirName, interval, streams, settings.value("ssrQcRef").toString().trimmed());
[11066]1009}
1010
1011// Writes the final SSR QC report
1012////////////////////////////////////////////////////////////////////////////
1013void t_bncCore::stopSsrQc() {
1014 delete _ssrQc; _ssrQc = 0;
1015}
1016
[5846]1017//
1018////////////////////////////////////////////////////////////////////////////
1019bool t_bncCore::dateAndTimeGPSSet() const {
1020 QMutexLocker locker(&_mutexDateAndTimeGPS);
1021 if (_dateAndTimeGPS) {
1022 return true;
1023 }
1024 else {
1025 return false;
1026 }
1027}
1028
1029//
1030////////////////////////////////////////////////////////////////////////////
1031QDateTime t_bncCore::dateAndTimeGPS() const {
1032 QMutexLocker locker(&_mutexDateAndTimeGPS);
1033 if (_dateAndTimeGPS) {
1034 return *_dateAndTimeGPS;
1035 }
1036 else {
1037 return QDateTime();
1038 }
1039}
1040
1041//
1042////////////////////////////////////////////////////////////////////////////
1043void t_bncCore::setDateAndTimeGPS(QDateTime dateTime) {
1044 QMutexLocker locker(&_mutexDateAndTimeGPS);
1045 delete _dateAndTimeGPS;
1046 _dateAndTimeGPS = new QDateTime(dateTime);
1047}
[5900]1048
1049//
1050////////////////////////////////////////////////////////////////////////////
[5946]1051void t_bncCore::startPPP() {
1052 _pppMain->start();
[5900]1053}
1054
1055//
1056////////////////////////////////////////////////////////////////////////////
1057void t_bncCore::stopPPP() {
[5903]1058 _pppMain->stop();
[5972]1059 emit stopRinexPPP();
[5900]1060}
[6383]1061
Note: See TracBrowser for help on using the repository browser.