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