| 1 | // Part of BNC, a utility for retrieving decoding and
|
|---|
| 2 | // converting GNSS data streams from NTRIP broadcasters.
|
|---|
| 3 | //
|
|---|
| 4 | // Copyright (C) 2007
|
|---|
| 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
|---|
| 6 | // http://bkg.bund.de
|
|---|
| 7 | // Czech Technical University Prague, Department of Geodesy
|
|---|
| 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.
|
|---|
| 24 |
|
|---|
| 25 | /* -------------------------------------------------------------------------
|
|---|
| 26 | * BKG NTRIP Client
|
|---|
| 27 | * -------------------------------------------------------------------------
|
|---|
| 28 | *
|
|---|
| 29 | * Class: t_bncCore
|
|---|
| 30 | *
|
|---|
| 31 | * Purpose: This class implements the main application
|
|---|
| 32 | *
|
|---|
| 33 | * Author: L. Mervart
|
|---|
| 34 | *
|
|---|
| 35 | * Created: 29-Aug-2006
|
|---|
| 36 | *
|
|---|
| 37 | * Changes:
|
|---|
| 38 | *
|
|---|
| 39 | * -----------------------------------------------------------------------*/
|
|---|
| 40 |
|
|---|
| 41 | #include <iostream>
|
|---|
| 42 | #include <sstream>
|
|---|
| 43 | #include <QMessageBox>
|
|---|
| 44 | #include <cmath>
|
|---|
| 45 | #ifndef Q_OS_WIN
|
|---|
| 46 | #include <sys/stat.h>
|
|---|
| 47 | #endif
|
|---|
| 48 |
|
|---|
| 49 | #include "bnccore.h"
|
|---|
| 50 | #include "ssrQc.h"
|
|---|
| 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"
|
|---|
| 58 | #include "pppMain.h"
|
|---|
| 59 | #include "combination/bnccomb.h"
|
|---|
| 60 |
|
|---|
| 61 | using namespace std;
|
|---|
| 62 |
|
|---|
| 63 | // Singleton
|
|---|
| 64 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 65 | t_bncCore* t_bncCore::instance() {
|
|---|
| 66 | static t_bncCore _bncCore;
|
|---|
| 67 | return &_bncCore;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | // Constructor
|
|---|
| 71 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 72 | t_bncCore::t_bncCore() : _ephUser(false) {
|
|---|
| 73 | _logFileFlag = 0;
|
|---|
| 74 | _logFile = 0;
|
|---|
| 75 | _logStream = 0;
|
|---|
| 76 | _logFileStructured = 0;
|
|---|
| 77 | _logStructuredInit = false;
|
|---|
| 78 | _logFormatStructured = t_logRecord::json;
|
|---|
| 79 | _logLevelStructured = t_logRecord::debug;
|
|---|
| 80 | _rawFile = 0;
|
|---|
| 81 | _caster = 0;
|
|---|
| 82 |
|
|---|
| 83 | // Eph file(s)
|
|---|
| 84 | // -----------
|
|---|
| 85 | _rinexVers = 0;
|
|---|
| 86 | _ephFilePerStation = false;
|
|---|
| 87 |
|
|---|
| 88 | _portEph = 0;
|
|---|
| 89 | _serverEph = 0;
|
|---|
| 90 | _socketsEph = 0;
|
|---|
| 91 |
|
|---|
| 92 | _portCorr = 0;
|
|---|
| 93 | _serverCorr = 0;
|
|---|
| 94 | _socketsCorr = 0;
|
|---|
| 95 |
|
|---|
| 96 | _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
|
|---|
| 97 | #ifdef WIN32
|
|---|
| 98 | _userName = QString("${USERNAME}");
|
|---|
| 99 | #else
|
|---|
| 100 | _userName = QString("${USER}");
|
|---|
| 101 | #endif
|
|---|
| 102 | expandEnvVar(_userName);
|
|---|
| 103 |
|
|---|
| 104 | _userName = _userName.leftJustified(20, ' ', true);
|
|---|
| 105 | _dateAndTimeGPS = 0;
|
|---|
| 106 | _mainWindow = 0;
|
|---|
| 107 |
|
|---|
| 108 | _pppMain = new BNC_PPP::t_pppMain();
|
|---|
| 109 | _ssrQc = 0;
|
|---|
| 110 | qRegisterMetaType< QVector<double> > ("QVector<double>");
|
|---|
| 111 | qRegisterMetaType<bncTime> ("bncTime");
|
|---|
| 112 | qRegisterMetaType<t_logRecord> ("t_logRecord");
|
|---|
| 113 | qRegisterMetaType<t_ephGPS> ("t_ephGPS");
|
|---|
| 114 | qRegisterMetaType<t_ephGlo> ("t_ephGlo");
|
|---|
| 115 | qRegisterMetaType<t_ephGal> ("t_ephGal");
|
|---|
| 116 | qRegisterMetaType<t_ephSBAS> ("t_ephSBAS");
|
|---|
| 117 | qRegisterMetaType<t_ephBDS> ("t_ephBDS");
|
|---|
| 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");
|
|---|
| 123 | qRegisterMetaType<t_metaData> ("t_metaData");
|
|---|
| 124 | qRegisterMetaType<QList<t_satAntenna> > ("QList<t_satAntenna>");
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | // Destructor
|
|---|
| 128 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 129 | t_bncCore::~t_bncCore() {
|
|---|
| 130 | delete _logStream; _logStream = 0;
|
|---|
| 131 | delete _logFile; _logFile = 0;
|
|---|
| 132 | delete _logFileStructured; _logFileStructured = 0;
|
|---|
| 133 | qDeleteAll(_ephFiles);
|
|---|
| 134 | delete _serverEph;
|
|---|
| 135 | delete _socketsEph;
|
|---|
| 136 | delete _serverCorr;
|
|---|
| 137 | delete _socketsCorr;
|
|---|
| 138 | delete _dateAndTimeGPS;
|
|---|
| 139 | if (_rawFile) {
|
|---|
| 140 | delete _rawFile;
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | bncComb::destruct();
|
|---|
| 144 | delete _ssrQc;
|
|---|
| 145 |
|
|---|
| 146 | delete _pppMain;
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | // Write a Program Message
|
|---|
| 150 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 151 | void t_bncCore::slotMessage(QByteArray msg, bool showOnScreen) {
|
|---|
| 152 | if (msg.isEmpty()) {
|
|---|
| 153 | return;
|
|---|
| 154 | }
|
|---|
| 155 | slotLogRecord(t_logRecord::fromMessage(msg), showOnScreen);
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | // Write a Program Message of a component with an explicit level
|
|---|
| 159 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 160 | void 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 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 170 | void 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 |
|
|---|
| 177 | // Write a Program Message with structured fields (structured logfile);
|
|---|
| 178 | // the classic logfile and the screen get the text rec._msg
|
|---|
| 179 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 180 | void t_bncCore::slotLogRecord(t_logRecord rec, bool showOnScreen) {
|
|---|
| 181 | if (rec._msg.isEmpty()) {
|
|---|
| 182 | return;
|
|---|
| 183 | }
|
|---|
| 184 | QMutexLocker locker(&_mutexMessage);
|
|---|
| 185 |
|
|---|
| 186 | messagePrivate(rec);
|
|---|
| 187 | emit newMessage(rec._msg, showOnScreen);
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | // Write a Program Message (private, no lock)
|
|---|
| 191 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 192 | void t_bncCore::messagePrivate(const t_logRecord& rec) {
|
|---|
| 193 |
|
|---|
| 194 | // First time resolve the log file names
|
|---|
| 195 | // -------------------------------------
|
|---|
| 196 | QDateTime currDateTime = currentDateAndTimeGPS();
|
|---|
| 197 | QDate currDate = currDateTime.date();
|
|---|
| 198 | if (_logFileFlag == 0 || _fileDate != currDate) {
|
|---|
| 199 | delete _logStream; _logStream = 0;
|
|---|
| 200 | delete _logFile; _logFile = 0;
|
|---|
| 201 | _logFileFlag = 1;
|
|---|
| 202 | _fileDate = currDate;
|
|---|
| 203 | bncSettings settings;
|
|---|
| 204 | bool append = (Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked);
|
|---|
| 205 | QString logFileName = settings.value("logFile").toString();
|
|---|
| 206 | if ( !logFileName.isEmpty() ) {
|
|---|
| 207 | expandEnvVar(logFileName);
|
|---|
| 208 | _logFile = new QFile(logFileName + "_" +
|
|---|
| 209 | currDate.toString("yyMMdd").toLatin1().data());
|
|---|
| 210 | if (append) {
|
|---|
| 211 | _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
|---|
| 212 | }
|
|---|
| 213 | else {
|
|---|
| 214 | _logFile->open(QIODevice::WriteOnly);
|
|---|
| 215 | }
|
|---|
| 216 | _logStream = new QTextStream();
|
|---|
| 217 | _logStream->setDevice(_logFile);
|
|---|
| 218 | }
|
|---|
| 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);
|
|---|
| 229 | _logFormatStructured = t_logRecord::formatFromString(
|
|---|
| 230 | settings.value("logFormatStructured").toString());
|
|---|
| 231 | _logLevelStructured = t_logRecord::levelFromString(
|
|---|
| 232 | settings.value("logLevelStructured").toString());
|
|---|
| 233 | openLogFileStructured();
|
|---|
| 234 | }
|
|---|
| 235 | }
|
|---|
| 236 | else if (!_logFileStructuredName.isEmpty() && _logStructuredCheck.hasExpired(1000)) {
|
|---|
| 237 | openLogFileStructured(); // reopens only if the file was moved or removed
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | if (_logStream) {
|
|---|
| 241 | QByteArray msgLocal = rec._msg;
|
|---|
| 242 | if (rec._msg.indexOf('\n') == 0) {
|
|---|
| 243 | *_logStream << "\r\n";
|
|---|
| 244 | msgLocal = rec._msg.mid(1);
|
|---|
| 245 | }
|
|---|
| 246 | *_logStream << currDateTime.toString("yy-MM-dd hh:mm:ss ").toLatin1().data();
|
|---|
| 247 | *_logStream << msgLocal.data() << "\r\n";
|
|---|
| 248 | _logStream->flush();
|
|---|
| 249 | _logFile->flush();
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | if (_logFileStructured && rec._level >= _logLevelStructured) {
|
|---|
| 253 | _logFileStructured->write(rec.encode(_logFormatStructured, currDateTime) + "\n");
|
|---|
| 254 | _logFileStructured->flush();
|
|---|
| 255 | }
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 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 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 262 | void 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 |
|
|---|
| 285 | //
|
|---|
| 286 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 287 | t_irc t_bncCore::checkPrintEph(t_eph* eph) {
|
|---|
| 288 | QMutexLocker locker(&_mutex);
|
|---|
| 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 | }
|
|---|
| 311 | t_irc ircPut = _ephUser.putNewEph(eph, true);
|
|---|
| 312 | #ifdef BNC_DEBUG_BCE
|
|---|
| 313 | if (eph->checkState() == t_eph::unhealthy) {
|
|---|
| 314 | messagePrivate(t_logRecord::debugMessage("bce", QString("%1: UNHEALTHY %2:%3")
|
|---|
| 315 | .arg(eph->receptStaID())
|
|---|
| 316 | .arg(eph->typeStr(eph->type(), eph->prn(), 99.0))
|
|---|
| 317 | .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1()));
|
|---|
| 318 | }
|
|---|
| 319 | if (eph->checkState() == t_eph::bad) {
|
|---|
| 320 | messagePrivate(t_logRecord::debugMessage("bce", QString("%1: WRONG %2:%3")
|
|---|
| 321 | .arg(eph->receptStaID())
|
|---|
| 322 | .arg(eph->typeStr(eph->type(), eph->prn(), 99.0))
|
|---|
| 323 | .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1()));
|
|---|
| 324 | }
|
|---|
| 325 | if (eph->checkState() == t_eph::outdated) {
|
|---|
| 326 | messagePrivate(t_logRecord::debugMessage("bce", QString("%1: OUTDATED %2:%3")
|
|---|
| 327 | .arg(eph->receptStaID())
|
|---|
| 328 | .arg(eph->typeStr(eph->type(), eph->prn(), 99.0))
|
|---|
| 329 | .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1()));
|
|---|
| 330 | }
|
|---|
| 331 | #endif
|
|---|
| 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);
|
|---|
| 342 | return success;
|
|---|
| 343 | }
|
|---|
| 344 |
|
|---|
| 345 | // New GPS Ephemeris
|
|---|
| 346 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 347 | void t_bncCore::slotNewGPSEph(t_ephGPS eph) {
|
|---|
| 348 | if (checkPrintEph(&eph) == success) {
|
|---|
| 349 | emit newGPSEph(eph);
|
|---|
| 350 | }
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | // New Glonass Ephemeris
|
|---|
| 354 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 355 | void t_bncCore::slotNewGlonassEph(t_ephGlo eph) {
|
|---|
| 356 | if (checkPrintEph(&eph) == success) {
|
|---|
| 357 | emit newGlonassEph(eph);
|
|---|
| 358 | }
|
|---|
| 359 | }
|
|---|
| 360 |
|
|---|
| 361 | // New Galileo Ephemeris
|
|---|
| 362 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 363 | void t_bncCore::slotNewGalileoEph(t_ephGal eph) {
|
|---|
| 364 | if (checkPrintEph(&eph) == success) {
|
|---|
| 365 | emit newGalileoEph(eph);
|
|---|
| 366 | }
|
|---|
| 367 | }
|
|---|
| 368 |
|
|---|
| 369 | // New SBAS Ephemeris
|
|---|
| 370 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 371 | void t_bncCore::slotNewSBASEph(t_ephSBAS eph) {
|
|---|
| 372 | if (checkPrintEph(&eph) == success) {
|
|---|
| 373 | emit newSBASEph(eph);
|
|---|
| 374 | }
|
|---|
| 375 | }
|
|---|
| 376 |
|
|---|
| 377 | // New BDS Ephemeris
|
|---|
| 378 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 379 | void t_bncCore::slotNewBDSEph(t_ephBDS eph) {
|
|---|
| 380 | if (checkPrintEph(&eph) == success) {
|
|---|
| 381 | emit newBDSEph(eph);
|
|---|
| 382 | }
|
|---|
| 383 | }
|
|---|
| 384 |
|
|---|
| 385 | // Close RINEX Navigation File(s)
|
|---|
| 386 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 387 | void 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 | }
|
|---|
| 393 |
|
|---|
| 394 | // Destructor
|
|---|
| 395 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 396 | t_bncCore::t_ephFile::~t_ephFile() {
|
|---|
| 397 | close();
|
|---|
| 398 | delete _ephUser;
|
|---|
| 399 | }
|
|---|
| 400 |
|
|---|
| 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 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 404 | QString 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;
|
|---|
| 408 | }
|
|---|
| 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 | }
|
|---|
| 417 |
|
|---|
| 418 | // Print Header of the output File(s), returns the file of the stream
|
|---|
| 419 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 420 | t_bncCore::t_ephFile* t_bncCore::printEphHeader(QString receptStaID) {
|
|---|
| 421 |
|
|---|
| 422 | bncSettings settings;
|
|---|
| 423 |
|
|---|
| 424 | // Initialization
|
|---|
| 425 | // --------------
|
|---|
| 426 | if (_rinexVers == 0) {
|
|---|
| 427 |
|
|---|
| 428 | _rinexVers = settings.value("ephVersion").toInt();
|
|---|
| 429 |
|
|---|
| 430 | _ephFilePerStation = Qt::CheckState(settings.value("ephFilePerStation").toInt()) == Qt::Checked;
|
|---|
| 431 |
|
|---|
| 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 | }
|
|---|
| 440 | }
|
|---|
| 441 |
|
|---|
| 442 | if (_ephPath.isEmpty()) {
|
|---|
| 443 | return 0;
|
|---|
| 444 | }
|
|---|
| 445 |
|
|---|
| 446 | QString key = _ephFilePerStation ? receptStaID : QString();
|
|---|
| 447 |
|
|---|
| 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 | }
|
|---|
| 467 |
|
|---|
| 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;
|
|---|
| 478 | }
|
|---|
| 479 | }
|
|---|
| 480 | }
|
|---|
| 481 |
|
|---|
| 482 | t_ephFile*& ephFile = _ephFiles[key];
|
|---|
| 483 | if (!ephFile) {
|
|---|
| 484 | ephFile = new t_ephFile;
|
|---|
| 485 | if (_ephFilePerStation) {
|
|---|
| 486 | ephFile->_ephUser = new bncEphUser(false);
|
|---|
| 487 | }
|
|---|
| 488 | }
|
|---|
| 489 |
|
|---|
| 490 | // (Re-)Open output File(s)
|
|---|
| 491 | // ------------------------
|
|---|
| 492 | QDateTime datTim = currentDateAndTimeGPS();
|
|---|
| 493 |
|
|---|
| 494 | QString hlpStr = bncRinex::nextEpochStr(datTim,
|
|---|
| 495 | settings.value("ephIntr").toString(), _rinexVers);
|
|---|
| 496 |
|
|---|
| 497 | QString ephFileNameGPS = _ephPath + base;
|
|---|
| 498 |
|
|---|
| 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 | }
|
|---|
| 511 |
|
|---|
| 512 | if (ephFile->_name == ephFileNameGPS) {
|
|---|
| 513 | return ephFile;
|
|---|
| 514 | }
|
|---|
| 515 | ephFile->_name = ephFileNameGPS;
|
|---|
| 516 | ephFile->close();
|
|---|
| 517 |
|
|---|
| 518 | QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
|
|---|
| 519 | QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
|
|---|
| 520 |
|
|---|
| 521 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
|---|
| 522 | QFile::exists(ephFileNameGPS) ) {
|
|---|
| 523 | appendFlagGPS = QIODevice::Append;
|
|---|
| 524 | }
|
|---|
| 525 |
|
|---|
| 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;
|
|---|
| 531 |
|
|---|
| 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");
|
|---|
| 536 |
|
|---|
| 537 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
|---|
| 538 | QFile::exists(ephFileNameGlonass) ) {
|
|---|
| 539 | appendFlagGlonass = QIODevice::Append;
|
|---|
| 540 | }
|
|---|
| 541 |
|
|---|
| 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;
|
|---|
| 548 |
|
|---|
| 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();
|
|---|
| 561 |
|
|---|
| 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";
|
|---|
| 567 |
|
|---|
| 568 | QStringListIterator it(comments);
|
|---|
| 569 | while (it.hasNext()) {
|
|---|
| 570 | *streamGPS << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
|
|---|
| 571 | }
|
|---|
| 572 |
|
|---|
| 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 | }
|
|---|
| 578 |
|
|---|
| 579 | line = QString().asprintf("%60sEND OF HEADER\n", "");
|
|---|
| 580 | *streamGPS << line;
|
|---|
| 581 |
|
|---|
| 582 | streamGPS->flush();
|
|---|
| 583 | }
|
|---|
| 584 | }
|
|---|
| 585 |
|
|---|
| 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();
|
|---|
| 594 |
|
|---|
| 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";
|
|---|
| 604 | }
|
|---|
| 605 |
|
|---|
| 606 | line = QString().asprintf("%60sEND OF HEADER\n", "");
|
|---|
| 607 | *streamGPS << line;
|
|---|
| 608 |
|
|---|
| 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();
|
|---|
| 616 |
|
|---|
| 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";
|
|---|
| 622 |
|
|---|
| 623 | QStringListIterator it(comments);
|
|---|
| 624 | while (it.hasNext()) {
|
|---|
| 625 | *streamGlonass << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
|
|---|
| 626 | }
|
|---|
| 627 |
|
|---|
| 628 | line = QString().asprintf("%60sEND OF HEADER\n", "");
|
|---|
| 629 | *streamGlonass << line;
|
|---|
| 630 |
|
|---|
| 631 | streamGlonass->flush();
|
|---|
| 632 | }
|
|---|
| 633 | }
|
|---|
| 634 |
|
|---|
| 635 | return ephFile;
|
|---|
| 636 | }
|
|---|
| 637 |
|
|---|
| 638 | // Print One Ephemeris
|
|---|
| 639 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 640 | void t_bncCore::printEph(t_ephFile* ephFile, const t_eph& eph, bool printFile) {
|
|---|
| 641 |
|
|---|
| 642 | QString strV2 = eph.toString(defaultRnxNavVersion2);
|
|---|
| 643 | QString strV3 = eph.toString(defaultRnxNavVersion3);
|
|---|
| 644 | QString strV4 = eph.toString(defaultRnxNavVersion4);
|
|---|
| 645 |
|
|---|
| 646 | QTextStream* streamN = ephFile ? ephFile->_streamN : 0;
|
|---|
| 647 | QTextStream* streamG = ephFile ? ephFile->_streamG : 0;
|
|---|
| 648 |
|
|---|
| 649 | if (_rinexVers == 2 && eph.system() == t_eph::GLONASS) {
|
|---|
| 650 | printOutputEph(printFile, streamG, strV2, strV3, strV4);
|
|---|
| 651 | }
|
|---|
| 652 | else if (_rinexVers == 2 && eph.system() == t_eph::GPS) {
|
|---|
| 653 | printOutputEph(printFile, streamN, strV2, strV3, strV4);
|
|---|
| 654 | }
|
|---|
| 655 | else if (_rinexVers >= 3) {
|
|---|
| 656 | printOutputEph(printFile, streamN, strV2, strV3, strV4);
|
|---|
| 657 | }
|
|---|
| 658 | }
|
|---|
| 659 |
|
|---|
| 660 | // Output
|
|---|
| 661 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 662 | void t_bncCore::printOutputEph(bool printFile, QTextStream* stream,
|
|---|
| 663 | const QString& strV2, const QString& strV3,
|
|---|
| 664 | const QString& strV4) {
|
|---|
| 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 | }
|
|---|
| 675 |
|
|---|
| 676 | // Output into file
|
|---|
| 677 | // ----------------
|
|---|
| 678 | if (printFile && stream) {
|
|---|
| 679 | *stream << strVx.toLatin1();
|
|---|
| 680 | stream->flush();
|
|---|
| 681 | }
|
|---|
| 682 |
|
|---|
| 683 | // Output into the socket
|
|---|
| 684 | // ----------------------
|
|---|
| 685 | if (_socketsEph) {
|
|---|
| 686 | QMutableListIterator<QTcpSocket*> is(*_socketsEph);
|
|---|
| 687 | while (is.hasNext()) {
|
|---|
| 688 | QTcpSocket* sock = is.next();
|
|---|
| 689 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
|---|
| 690 | if (sock->write(strVx.toLatin1()) == -1) {
|
|---|
| 691 | delete sock;
|
|---|
| 692 | is.remove();
|
|---|
| 693 | }
|
|---|
| 694 | }
|
|---|
| 695 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
|---|
| 696 | delete sock;
|
|---|
| 697 | is.remove();
|
|---|
| 698 | }
|
|---|
| 699 | }
|
|---|
| 700 | }
|
|---|
| 701 | }
|
|---|
| 702 |
|
|---|
| 703 | // Set Port Number
|
|---|
| 704 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 705 | void t_bncCore::setPortEph(int port) {
|
|---|
| 706 | _portEph = port;
|
|---|
| 707 | if (_portEph != 0) {
|
|---|
| 708 | delete _serverEph;
|
|---|
| 709 | _serverEph = new QTcpServer;
|
|---|
| 710 | _serverEph->setProxy(QNetworkProxy::NoProxy);
|
|---|
| 711 | if ( !_serverEph->listen(QHostAddress::LocalHost, _portEph) ) {
|
|---|
| 712 | QString message = "t_bncCore: Cannot listen on ephemeris port "
|
|---|
| 713 | + QByteArray::number(_portEph) + ": "
|
|---|
| 714 | + _serverEph->errorString();
|
|---|
| 715 | slotLogRecord(t_logRecord::message(t_logRecord::error, message.toLatin1(), "bnc"), true);
|
|---|
| 716 | }
|
|---|
| 717 | connect(_serverEph, SIGNAL(newConnection()), this, SLOT(slotNewConnectionEph()));
|
|---|
| 718 | delete _socketsEph;
|
|---|
| 719 | _socketsEph = new QList<QTcpSocket*>;
|
|---|
| 720 | }
|
|---|
| 721 | }
|
|---|
| 722 |
|
|---|
| 723 | // Set Port Number
|
|---|
| 724 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 725 | void t_bncCore::setPortCorr(int port) {
|
|---|
| 726 | _portCorr = port;
|
|---|
| 727 | if (_portCorr != 0) {
|
|---|
| 728 | delete _serverCorr;
|
|---|
| 729 | _serverCorr = new QTcpServer;
|
|---|
| 730 | _serverCorr->setProxy(QNetworkProxy::NoProxy);
|
|---|
| 731 | if ( !_serverCorr->listen(QHostAddress::LocalHost, _portCorr) ) {
|
|---|
| 732 | QString message = "t_bncCore: Cannot listen on correction port "
|
|---|
| 733 | + QByteArray::number(_portCorr) + ": "
|
|---|
| 734 | + _serverCorr->errorString();
|
|---|
| 735 | slotLogRecord(t_logRecord::message(t_logRecord::error, message.toLatin1(), "bnc"), true);
|
|---|
| 736 | }
|
|---|
| 737 | connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
|
|---|
| 738 | delete _socketsCorr;
|
|---|
| 739 | _socketsCorr = new QList<QTcpSocket*>;
|
|---|
| 740 | }
|
|---|
| 741 | }
|
|---|
| 742 |
|
|---|
| 743 | // New Connection
|
|---|
| 744 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 745 | void t_bncCore::slotNewConnectionEph() {
|
|---|
| 746 | _socketsEph->push_back( _serverEph->nextPendingConnection() );
|
|---|
| 747 | }
|
|---|
| 748 |
|
|---|
| 749 | // New Connection
|
|---|
| 750 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 751 | void t_bncCore::slotNewConnectionCorr() {
|
|---|
| 752 | _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
|
|---|
| 753 | }
|
|---|
| 754 |
|
|---|
| 755 | //
|
|---|
| 756 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 757 | void t_bncCore::slotQuit() {
|
|---|
| 758 | delete _caster; _caster = 0;
|
|---|
| 759 | qApp->quit();
|
|---|
| 760 | }
|
|---|
| 761 |
|
|---|
| 762 | //
|
|---|
| 763 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 764 | void t_bncCore::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
|
|---|
| 765 | QMutexLocker locker(&_mutex);
|
|---|
| 766 | emit newOrbCorrections(orbCorrections);
|
|---|
| 767 | if (_socketsCorr) {
|
|---|
| 768 | ostringstream out;
|
|---|
| 769 | t_orbCorr::writeEpoch(&out, orbCorrections);
|
|---|
| 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) {
|
|---|
| 775 | delete sock;
|
|---|
| 776 | is.remove();
|
|---|
| 777 | }
|
|---|
| 778 | }
|
|---|
| 779 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
|---|
| 780 | delete sock;
|
|---|
| 781 | is.remove();
|
|---|
| 782 | }
|
|---|
| 783 | }
|
|---|
| 784 | }
|
|---|
| 785 | }
|
|---|
| 786 |
|
|---|
| 787 | //
|
|---|
| 788 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 789 | void t_bncCore::slotNewClkCorrections(QList<t_clkCorr> clkCorrections) {
|
|---|
| 790 | QMutexLocker locker(&_mutex);
|
|---|
| 791 | emit newClkCorrections(clkCorrections);
|
|---|
| 792 | if (_socketsCorr) {
|
|---|
| 793 | ostringstream out;
|
|---|
| 794 | t_clkCorr::writeEpoch(&out, clkCorrections);
|
|---|
| 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) {
|
|---|
| 800 | delete sock;
|
|---|
| 801 | is.remove();
|
|---|
| 802 | }
|
|---|
| 803 | }
|
|---|
| 804 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
|---|
| 805 | delete sock;
|
|---|
| 806 | is.remove();
|
|---|
| 807 | }
|
|---|
| 808 | }
|
|---|
| 809 | }
|
|---|
| 810 | }
|
|---|
| 811 |
|
|---|
| 812 | //
|
|---|
| 813 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 814 | void t_bncCore::slotNewCodeBiases(QList<t_satCodeBias> codeBiases) {
|
|---|
| 815 | QMutexLocker locker(&_mutex);
|
|---|
| 816 | emit newCodeBiases(codeBiases);
|
|---|
| 817 | if (_socketsCorr) {
|
|---|
| 818 | ostringstream out;
|
|---|
| 819 | t_satCodeBias::writeEpoch(&out, codeBiases);
|
|---|
| 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 | }
|
|---|
| 835 | }
|
|---|
| 836 |
|
|---|
| 837 | //
|
|---|
| 838 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 839 | void t_bncCore::slotNewPhaseBiases(QList<t_satPhaseBias> phaseBiases) {
|
|---|
| 840 | QMutexLocker locker(&_mutex);
|
|---|
| 841 | emit newPhaseBiases(phaseBiases);
|
|---|
| 842 | if (_socketsCorr) {
|
|---|
| 843 | ostringstream out;
|
|---|
| 844 | t_satPhaseBias::writeEpoch(&out, phaseBiases);
|
|---|
| 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 | }
|
|---|
| 860 | }
|
|---|
| 861 |
|
|---|
| 862 | //
|
|---|
| 863 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 864 | void t_bncCore::slotNewTec(t_vTec vTec) {
|
|---|
| 865 | QMutexLocker locker(&_mutex);
|
|---|
| 866 | emit newTec(vTec);
|
|---|
| 867 | if (_socketsCorr) {
|
|---|
| 868 | ostringstream out;
|
|---|
| 869 | t_vTec::write(&out, vTec);
|
|---|
| 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 | }
|
|---|
| 885 | }
|
|---|
| 886 |
|
|---|
| 887 | //
|
|---|
| 888 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 889 | void 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 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 914 | void 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 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 939 | void t_bncCore::setConfFileName(const QString& confFileName) {
|
|---|
| 940 | if (confFileName.isEmpty()) {
|
|---|
| 941 | _confFileName = QDir::homePath() + QDir::separator()
|
|---|
| 942 | + ".config" + QDir::separator()
|
|---|
| 943 | + qApp->organizationName() + QDir::separator()
|
|---|
| 944 | + qApp->applicationName() + ".bnc";
|
|---|
| 945 | }
|
|---|
| 946 | else {
|
|---|
| 947 | _confFileName = confFileName;
|
|---|
| 948 | }
|
|---|
| 949 | }
|
|---|
| 950 |
|
|---|
| 951 | // Raw Output
|
|---|
| 952 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 953 | void t_bncCore::writeRawData(const QByteArray& data, const QByteArray& staID,
|
|---|
| 954 | const QByteArray& format) {
|
|---|
| 955 |
|
|---|
| 956 | QMutexLocker locker(&_mutex);
|
|---|
| 957 |
|
|---|
| 958 | if (!_rawFile) {
|
|---|
| 959 | bncSettings settings;
|
|---|
| 960 | QByteArray fileName = settings.value("rawOutFile").toByteArray();
|
|---|
| 961 | if (!fileName.isEmpty()) {
|
|---|
| 962 | _rawFile = new bncRawFile(fileName, staID, bncRawFile::output);
|
|---|
| 963 | }
|
|---|
| 964 | }
|
|---|
| 965 |
|
|---|
| 966 | if (_rawFile) {
|
|---|
| 967 | _rawFile->writeRawData(data, staID, format);
|
|---|
| 968 | }
|
|---|
| 969 | }
|
|---|
| 970 |
|
|---|
| 971 | //
|
|---|
| 972 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 973 | void t_bncCore::initCombination() {
|
|---|
| 974 | bncComb::getInstance();
|
|---|
| 975 | if (BNC_CMB->nStreams() < 1) {
|
|---|
| 976 | bncComb::destruct();
|
|---|
| 977 | }
|
|---|
| 978 | }
|
|---|
| 979 |
|
|---|
| 980 | //
|
|---|
| 981 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 982 | void t_bncCore::stopCombination() {
|
|---|
| 983 | bncComb::destruct();
|
|---|
| 984 | }
|
|---|
| 985 |
|
|---|
| 986 | // SSR QC of the decoded correction streams (optional)
|
|---|
| 987 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 988 | void t_bncCore::initSsrQc() {
|
|---|
| 989 | delete _ssrQc; _ssrQc = 0;
|
|---|
| 990 | bncSettings settings;
|
|---|
| 991 | QString dirName = settings.value("ssrQcPath").toString();
|
|---|
| 992 | if (dirName.isEmpty()) {
|
|---|
| 993 | return;
|
|---|
| 994 | }
|
|---|
| 995 | expandEnvVar(dirName);
|
|---|
| 996 | QStringList streams = settings.value("ssrQcStreams").toString().split(QRegularExpression("[ ,;]+"), Qt::SkipEmptyParts);
|
|---|
| 997 | if (streams.isEmpty()) {
|
|---|
| 998 | streams << "ALL";
|
|---|
| 999 | }
|
|---|
| 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 | }
|
|---|
| 1008 | _ssrQc = new t_ssrQc(dirName, interval, streams, settings.value("ssrQcRef").toString().trimmed());
|
|---|
| 1009 | }
|
|---|
| 1010 |
|
|---|
| 1011 | // Writes the final SSR QC report
|
|---|
| 1012 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 1013 | void t_bncCore::stopSsrQc() {
|
|---|
| 1014 | delete _ssrQc; _ssrQc = 0;
|
|---|
| 1015 | }
|
|---|
| 1016 |
|
|---|
| 1017 | //
|
|---|
| 1018 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 1019 | bool 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 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 1031 | QDateTime 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 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 1043 | void t_bncCore::setDateAndTimeGPS(QDateTime dateTime) {
|
|---|
| 1044 | QMutexLocker locker(&_mutexDateAndTimeGPS);
|
|---|
| 1045 | delete _dateAndTimeGPS;
|
|---|
| 1046 | _dateAndTimeGPS = new QDateTime(dateTime);
|
|---|
| 1047 | }
|
|---|
| 1048 |
|
|---|
| 1049 | //
|
|---|
| 1050 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 1051 | void t_bncCore::startPPP() {
|
|---|
| 1052 | _pppMain->start();
|
|---|
| 1053 | }
|
|---|
| 1054 |
|
|---|
| 1055 | //
|
|---|
| 1056 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 1057 | void t_bncCore::stopPPP() {
|
|---|
| 1058 | _pppMain->stop();
|
|---|
| 1059 | emit stopRinexPPP();
|
|---|
| 1060 | }
|
|---|
| 1061 |
|
|---|