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