[280] | 1 | // Part of BNC, a utility for retrieving decoding and
|
---|
[464] | 2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
[280] | 3 | //
|
---|
[464] | 4 | // Copyright (C) 2007
|
---|
[280] | 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
| 6 | // http://www.bkg.bund.de
|
---|
[464] | 7 | // Czech Technical University Prague, Department of Geodesy
|
---|
[280] | 8 | // http://www.fsv.cvut.cz
|
---|
| 9 | //
|
---|
| 10 | // Email: euref-ip@bkg.bund.de
|
---|
| 11 | //
|
---|
| 12 | // This program is free software; you can redistribute it and/or
|
---|
| 13 | // modify it under the terms of the GNU General Public License
|
---|
| 14 | // as published by the Free Software Foundation, version 2.
|
---|
| 15 | //
|
---|
| 16 | // This program is distributed in the hope that it will be useful,
|
---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | // GNU General Public License for more details.
|
---|
| 20 | //
|
---|
| 21 | // You should have received a copy of the GNU General Public License
|
---|
| 22 | // along with this program; if not, write to the Free Software
|
---|
| 23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
[82] | 24 |
|
---|
| 25 | /* -------------------------------------------------------------------------
|
---|
[93] | 26 | * BKG NTRIP Client
|
---|
[82] | 27 | * -------------------------------------------------------------------------
|
---|
| 28 | *
|
---|
[5072] | 29 | * Class: t_bncCore
|
---|
[82] | 30 | *
|
---|
| 31 | * Purpose: This class implements the main application
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 29-Aug-2006
|
---|
| 36 | *
|
---|
[7291] | 37 | * Changes:
|
---|
[82] | 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
[1029] | 41 | #include <iostream>
|
---|
[6461] | 42 | #include <sstream>
|
---|
[150] | 43 | #include <QMessageBox>
|
---|
[519] | 44 | #include <cmath>
|
---|
[82] | 45 |
|
---|
[7291] | 46 | #include "bnccore.h"
|
---|
| 47 | #include "bncutils.h"
|
---|
| 48 | #include "bncrinex.h"
|
---|
| 49 | #include "bncsettings.h"
|
---|
| 50 | #include "bncversion.h"
|
---|
| 51 | #include "ephemeris.h"
|
---|
| 52 | #include "rinex/rnxobsfile.h"
|
---|
| 53 | #include "rinex/rnxnavfile.h"
|
---|
[6051] | 54 | #include "pppMain.h"
|
---|
[7298] | 55 | #include "combination/bnccomb.h"
|
---|
[82] | 56 |
|
---|
| 57 | using namespace std;
|
---|
| 58 |
|
---|
[7291] | 59 | // Singleton
|
---|
[5084] | 60 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5861] | 61 | t_bncCore* t_bncCore::instance() {
|
---|
[5084] | 62 | static t_bncCore _bncCore;
|
---|
[5861] | 63 | return &_bncCore;
|
---|
[5084] | 64 | }
|
---|
| 65 |
|
---|
[82] | 66 | // Constructor
|
---|
| 67 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6441] | 68 | t_bncCore::t_bncCore() : _ephUser(false) {
|
---|
[150] | 69 | _logFileFlag = 0;
|
---|
| 70 | _logFile = 0;
|
---|
| 71 | _logStream = 0;
|
---|
[2519] | 72 | _rawFile = 0;
|
---|
[5729] | 73 | _caster = 0;
|
---|
[152] | 74 |
|
---|
[533] | 75 | // Eph file(s)
|
---|
| 76 | // -----------
|
---|
[534] | 77 | _rinexVers = 0;
|
---|
[533] | 78 | _ephFileGPS = 0;
|
---|
| 79 | _ephStreamGPS = 0;
|
---|
| 80 | _ephFileGlonass = 0;
|
---|
| 81 | _ephStreamGlonass = 0;
|
---|
[2770] | 82 | _ephFileGalileo = 0;
|
---|
| 83 | _ephStreamGalileo = 0;
|
---|
[6384] | 84 | _ephFileSBAS = 0;
|
---|
| 85 | _ephStreamSBAS = 0;
|
---|
[559] | 86 |
|
---|
[6451] | 87 | _portEph = 0;
|
---|
| 88 | _serverEph = 0;
|
---|
| 89 | _socketsEph = 0;
|
---|
[589] | 90 |
|
---|
[937] | 91 | _portCorr = 0;
|
---|
| 92 | _serverCorr = 0;
|
---|
| 93 | _socketsCorr = 0;
|
---|
| 94 |
|
---|
[2011] | 95 | _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
|
---|
[559] | 96 | #ifdef WIN32
|
---|
| 97 | _userName = QString("${USERNAME}");
|
---|
| 98 | #else
|
---|
| 99 | _userName = QString("${USER}");
|
---|
| 100 | #endif
|
---|
| 101 | expandEnvVar(_userName);
|
---|
[973] | 102 |
|
---|
[6151] | 103 | _userName = _userName.leftJustified(20, ' ', true);
|
---|
[5846] | 104 | _dateAndTimeGPS = 0;
|
---|
[6151] | 105 | _mainWindow = 0;
|
---|
[2673] | 106 |
|
---|
[5899] | 107 | _pppMain = new BNC_PPP::t_pppMain();
|
---|
[6486] | 108 | qRegisterMetaType< QVector<double> > ("QVector<double>");
|
---|
| 109 | qRegisterMetaType<bncTime> ("bncTime");
|
---|
| 110 | qRegisterMetaType<t_ephGPS> ("t_ephGPS");
|
---|
| 111 | qRegisterMetaType<t_ephGlo> ("t_ephGlo");
|
---|
| 112 | qRegisterMetaType<t_ephGal> ("t_ephGal");
|
---|
| 113 | qRegisterMetaType<t_ephSBAS> ("t_ephSBAS");
|
---|
[6598] | 114 | qRegisterMetaType<t_ephBDS> ("t_ephBDS");
|
---|
[6486] | 115 | qRegisterMetaType<QList<t_orbCorr> > ("QList<t_orbCorr>");
|
---|
| 116 | qRegisterMetaType<QList<t_clkCorr> > ("QList<t_clkCorr>");
|
---|
| 117 | qRegisterMetaType<QList<t_satCodeBias> > ("QList<t_satCodeBias>");
|
---|
| 118 | qRegisterMetaType<QList<t_satPhaseBias> > ("QList<t_satPhaseBias>");
|
---|
| 119 | qRegisterMetaType<t_vTec> ("t_vTec");
|
---|
[82] | 120 | }
|
---|
| 121 |
|
---|
| 122 | // Destructor
|
---|
| 123 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 124 | t_bncCore::~t_bncCore() {
|
---|
[109] | 125 | delete _logStream;
|
---|
| 126 | delete _logFile;
|
---|
[533] | 127 | delete _ephStreamGPS;
|
---|
| 128 | delete _ephFileGPS;
|
---|
[6451] | 129 | delete _serverEph;
|
---|
| 130 | delete _socketsEph;
|
---|
[937] | 131 | delete _serverCorr;
|
---|
| 132 | delete _socketsCorr;
|
---|
[534] | 133 | if (_rinexVers == 2) {
|
---|
[533] | 134 | delete _ephStreamGlonass;
|
---|
| 135 | delete _ephFileGlonass;
|
---|
| 136 | }
|
---|
[975] | 137 |
|
---|
[5846] | 138 | delete _dateAndTimeGPS;
|
---|
[9822] | 139 | if (_rawFile) {
|
---|
| 140 | delete _rawFile;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
[10040] | 143 | bncComb::destruct();
|
---|
| 144 |
|
---|
[7856] | 145 | delete _pppMain;
|
---|
[82] | 146 | }
|
---|
| 147 |
|
---|
| 148 | // Write a Program Message
|
---|
| 149 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 150 | void t_bncCore::slotMessage(QByteArray msg, bool showOnScreen) {
|
---|
[10027] | 151 | if (msg.isEmpty()) {
|
---|
| 152 | return;
|
---|
| 153 | }
|
---|
[1218] | 154 | QMutexLocker locker(&_mutexMessage);
|
---|
[243] | 155 |
|
---|
[990] | 156 | messagePrivate(msg);
|
---|
[1299] | 157 | emit newMessage(msg, showOnScreen);
|
---|
[990] | 158 | }
|
---|
| 159 |
|
---|
| 160 | // Write a Program Message (private, no lock)
|
---|
| 161 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 162 | void t_bncCore::messagePrivate(const QByteArray& msg) {
|
---|
[990] | 163 |
|
---|
[150] | 164 | // First time resolve the log file name
|
---|
| 165 | // ------------------------------------
|
---|
[1549] | 166 | QDate currDate = currentDateAndTimeGPS().date();
|
---|
| 167 | if (_logFileFlag == 0 || _fileDate != currDate) {
|
---|
[3034] | 168 | delete _logStream; _logStream = 0;
|
---|
| 169 | delete _logFile; _logFile = 0;
|
---|
[150] | 170 | _logFileFlag = 1;
|
---|
[1535] | 171 | bncSettings settings;
|
---|
[150] | 172 | QString logFileName = settings.value("logFile").toString();
|
---|
| 173 | if ( !logFileName.isEmpty() ) {
|
---|
[151] | 174 | expandEnvVar(logFileName);
|
---|
[7291] | 175 | _logFile = new QFile(logFileName + "_" +
|
---|
[8127] | 176 | currDate.toString("yyMMdd").toLatin1().data());
|
---|
[1549] | 177 | _fileDate = currDate;
|
---|
[275] | 178 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
| 179 | _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
---|
| 180 | }
|
---|
| 181 | else {
|
---|
| 182 | _logFile->open(QIODevice::WriteOnly);
|
---|
| 183 | }
|
---|
[150] | 184 | _logStream = new QTextStream();
|
---|
| 185 | _logStream->setDevice(_logFile);
|
---|
| 186 | }
|
---|
| 187 | }
|
---|
| 188 |
|
---|
[109] | 189 | if (_logStream) {
|
---|
[3371] | 190 | QByteArray msgLocal = msg;
|
---|
| 191 | if (msg.indexOf('\n') == 0) {
|
---|
[9819] | 192 | *_logStream << "\r\n";
|
---|
[3371] | 193 | msgLocal = msg.mid(1);
|
---|
| 194 | }
|
---|
[8127] | 195 | *_logStream << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toLatin1().data();
|
---|
[9819] | 196 | *_logStream << msgLocal.data() << "\r\n";
|
---|
[109] | 197 | _logStream->flush();
|
---|
[3637] | 198 | _logFile->flush();
|
---|
[82] | 199 | }
|
---|
| 200 | }
|
---|
[511] | 201 |
|
---|
[7291] | 202 | //
|
---|
[511] | 203 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6520] | 204 | t_irc t_bncCore::checkPrintEph(t_eph* eph) {
|
---|
[516] | 205 | QMutexLocker locker(&_mutex);
|
---|
[6520] | 206 | t_irc ircPut = _ephUser.putNewEph(eph, true);
|
---|
[9772] | 207 | #ifdef BNC_DEBUG_BCEP
|
---|
[9767] | 208 | if (eph->checkState() == t_eph::unhealthy) {
|
---|
| 209 | messagePrivate(QString("%1: UNHEALTHY %2:%3")
|
---|
[9217] | 210 | .arg(eph->receptStaID())
|
---|
[9765] | 211 | .arg(eph->navTypeString(eph->navType(), eph->prn(), 99.0))
|
---|
| 212 | .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1());
|
---|
[6519] | 213 | }
|
---|
[9768] | 214 | if (eph->checkState() == t_eph::bad) {
|
---|
[9767] | 215 | messagePrivate(QString("%1: WRONG %2:%3")
|
---|
[9217] | 216 | .arg(eph->receptStaID())
|
---|
[9765] | 217 | .arg(eph->navTypeString(eph->navType(), eph->prn(), 99.0))
|
---|
| 218 | .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1());
|
---|
[7208] | 219 | }
|
---|
[9772] | 220 | if (eph->checkState() == t_eph::outdated) {
|
---|
[9767] | 221 | messagePrivate(QString("%1: OUTDATED %2:%3")
|
---|
[9217] | 222 | .arg(eph->receptStaID())
|
---|
[9765] | 223 | .arg(eph->navTypeString(eph->navType(), eph->prn(), 99.0))
|
---|
| 224 | .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1());
|
---|
[8215] | 225 | }
|
---|
[9379] | 226 | #endif
|
---|
[534] | 227 | printEphHeader();
|
---|
[6520] | 228 | printEph(*eph, (ircPut == success));
|
---|
| 229 | return success;
|
---|
[511] | 230 | }
|
---|
[6520] | 231 |
|
---|
[7291] | 232 | // New GPS Ephemeris
|
---|
[6520] | 233 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 234 | void t_bncCore::slotNewGPSEph(t_ephGPS eph) {
|
---|
| 235 | if (checkPrintEph(&eph) == success) {
|
---|
| 236 | emit newGPSEph(eph);
|
---|
| 237 | }
|
---|
| 238 | }
|
---|
[7291] | 239 |
|
---|
[535] | 240 | // New Glonass Ephemeris
|
---|
[511] | 241 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6432] | 242 | void t_bncCore::slotNewGlonassEph(t_ephGlo eph) {
|
---|
[6520] | 243 | if (checkPrintEph(&eph) == success) {
|
---|
| 244 | emit newGlonassEph(eph);
|
---|
[6519] | 245 | }
|
---|
[511] | 246 | }
|
---|
| 247 |
|
---|
[2770] | 248 | // New Galileo Ephemeris
|
---|
| 249 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6432] | 250 | void t_bncCore::slotNewGalileoEph(t_ephGal eph) {
|
---|
[6520] | 251 | if (checkPrintEph(&eph) == success) {
|
---|
| 252 | emit newGalileoEph(eph);
|
---|
[6519] | 253 | }
|
---|
[6432] | 254 | }
|
---|
[2772] | 255 |
|
---|
[6432] | 256 | // New SBAS Ephemeris
|
---|
| 257 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 258 | void t_bncCore::slotNewSBASEph(t_ephSBAS eph) {
|
---|
[6520] | 259 | if (checkPrintEph(&eph) == success) {
|
---|
| 260 | emit newSBASEph(eph);
|
---|
[6519] | 261 | }
|
---|
[2770] | 262 | }
|
---|
| 263 |
|
---|
[6598] | 264 | // New BDS Ephemeris
|
---|
[6595] | 265 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6598] | 266 | void t_bncCore::slotNewBDSEph(t_ephBDS eph) {
|
---|
[6595] | 267 | if (checkPrintEph(&eph) == success) {
|
---|
[6598] | 268 | emit newBDSEph(eph);
|
---|
[6595] | 269 | }
|
---|
| 270 | }
|
---|
[6432] | 271 |
|
---|
[535] | 272 | // Print Header of the output File(s)
|
---|
[516] | 273 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 274 | void t_bncCore::printEphHeader() {
|
---|
[528] | 275 |
|
---|
[1535] | 276 | bncSettings settings;
|
---|
[7999] | 277 | QStringList comments;
|
---|
[535] | 278 |
|
---|
[7999] | 279 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
| 280 | while (it.hasNext()) {
|
---|
| 281 | QStringList hlp = it.next().split(" ");
|
---|
| 282 | if (hlp.size() < 7)
|
---|
| 283 | continue;
|
---|
| 284 | QUrl url(hlp[0]);
|
---|
| 285 | QString decoder = hlp[1];
|
---|
| 286 | comments.append("Source: " + decoder +
|
---|
[8203] | 287 | " " + QUrl::toAce(url.host()) +
|
---|
[8127] | 288 | "/" + url.path().mid(1).toLatin1());
|
---|
[7999] | 289 | }
|
---|
| 290 |
|
---|
[534] | 291 | // Initialization
|
---|
| 292 | // --------------
|
---|
| 293 | if (_rinexVers == 0) {
|
---|
[528] | 294 |
|
---|
[9760] | 295 | _rinexVers = settings.value("ephVersion").toInt();
|
---|
[529] | 296 |
|
---|
[533] | 297 | _ephPath = settings.value("ephPath").toString();
|
---|
| 298 |
|
---|
| 299 | if ( !_ephPath.isEmpty() ) {
|
---|
| 300 | if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
|
---|
| 301 | _ephPath += QDir::separator();
|
---|
| 302 | }
|
---|
| 303 | expandEnvVar(_ephPath);
|
---|
| 304 | }
|
---|
[517] | 305 | }
|
---|
[533] | 306 |
|
---|
[534] | 307 | // (Re-)Open output File(s)
|
---|
| 308 | // ------------------------
|
---|
[533] | 309 | if (!_ephPath.isEmpty()) {
|
---|
| 310 |
|
---|
[1154] | 311 | QDateTime datTim = currentDateAndTimeGPS();
|
---|
[533] | 312 |
|
---|
[7179] | 313 | QString ephFileNameGPS = _ephPath + "BRDC";
|
---|
[533] | 314 |
|
---|
[7291] | 315 | QString hlpStr = bncRinex::nextEpochStr(datTim,
|
---|
[9760] | 316 | settings.value("ephIntr").toString(), _rinexVers);
|
---|
[584] | 317 |
|
---|
[9760] | 318 | if (_rinexVers > 2) {
|
---|
[8354] | 319 | QString country = "WRD"; // WORLD
|
---|
| 320 | QString monNum = "0";
|
---|
| 321 | QString recNum = "0";
|
---|
| 322 | ephFileNameGPS += QString("%1").arg(monNum, 1, 10) +
|
---|
| 323 | QString("%1").arg(recNum, 1, 10) +
|
---|
| 324 | country +
|
---|
| 325 | "_S_" + // stream
|
---|
| 326 | QString("%1").arg(datTim.date().year()) +
|
---|
| 327 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
| 328 | hlpStr + // HM_period
|
---|
| 329 | "_MN.rnx"; // mixed BRDC
|
---|
[575] | 330 | }
|
---|
[7179] | 331 | else { // RNX v2.11
|
---|
| 332 | ephFileNameGPS += QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
| 333 | hlpStr + datTim.toString(".yyN");
|
---|
[575] | 334 | }
|
---|
[563] | 335 |
|
---|
[533] | 336 | if (_ephFileNameGPS == ephFileNameGPS) {
|
---|
| 337 | return;
|
---|
| 338 | }
|
---|
| 339 | else {
|
---|
| 340 | _ephFileNameGPS = ephFileNameGPS;
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | delete _ephStreamGPS;
|
---|
| 344 | delete _ephFileGPS;
|
---|
| 345 |
|
---|
[535] | 346 | QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
|
---|
[536] | 347 | QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
|
---|
| 348 |
|
---|
[535] | 349 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
---|
| 350 | QFile::exists(ephFileNameGPS) ) {
|
---|
| 351 | appendFlagGPS = QIODevice::Append;
|
---|
| 352 | }
|
---|
| 353 |
|
---|
[533] | 354 | _ephFileGPS = new QFile(ephFileNameGPS);
|
---|
[535] | 355 | _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
|
---|
[533] | 356 | _ephStreamGPS = new QTextStream();
|
---|
| 357 | _ephStreamGPS->setDevice(_ephFileGPS);
|
---|
| 358 |
|
---|
[9760] | 359 | if (_rinexVers > 2) {
|
---|
[533] | 360 | _ephFileGlonass = _ephFileGPS;
|
---|
| 361 | _ephStreamGlonass = _ephStreamGPS;
|
---|
[2770] | 362 | _ephFileGalileo = _ephFileGPS;
|
---|
| 363 | _ephStreamGalileo = _ephStreamGPS;
|
---|
[6384] | 364 | _ephFileSBAS = _ephFileGPS;
|
---|
| 365 | _ephStreamSBAS = _ephStreamGPS;
|
---|
[533] | 366 | }
|
---|
[9760] | 367 | else {
|
---|
[583] | 368 | QString ephFileNameGlonass = _ephPath + "BRDC" +
|
---|
[563] | 369 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
[575] | 370 | hlpStr + datTim.toString(".yyG");
|
---|
[533] | 371 |
|
---|
| 372 | delete _ephStreamGlonass;
|
---|
| 373 | delete _ephFileGlonass;
|
---|
| 374 |
|
---|
[535] | 375 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
---|
| 376 | QFile::exists(ephFileNameGlonass) ) {
|
---|
| 377 | appendFlagGlonass = QIODevice::Append;
|
---|
| 378 | }
|
---|
| 379 |
|
---|
[533] | 380 | _ephFileGlonass = new QFile(ephFileNameGlonass);
|
---|
[535] | 381 | _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
|
---|
[533] | 382 | _ephStreamGlonass = new QTextStream();
|
---|
| 383 | _ephStreamGlonass->setDevice(_ephFileGlonass);
|
---|
| 384 | }
|
---|
| 385 |
|
---|
[534] | 386 | // Header - RINEX Version 3
|
---|
| 387 | // ------------------------
|
---|
[9760] | 388 | if (_rinexVers > 2) {
|
---|
[537] | 389 | if ( ! (appendFlagGPS & QIODevice::Append)) {
|
---|
[9765] | 390 | double rinexVersion = defaultRnxNavVersion4;
|
---|
| 391 | if (_rinexVers < 4.0) {
|
---|
| 392 | rinexVersion = defaultRnxNavVersion3;
|
---|
| 393 | }
|
---|
[9675] | 394 | QString line = QString().asprintf("%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
|
---|
[9765] | 395 | rinexVersion, "", "");
|
---|
[537] | 396 | *_ephStreamGPS << line;
|
---|
[9675] | 397 | line.clear();
|
---|
[7291] | 398 |
|
---|
[1154] | 399 | QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
|
---|
[8127] | 400 | *_ephStreamGPS << _pgmName.toLatin1().data()
|
---|
| 401 | << _userName.toLatin1().data()
|
---|
| 402 | << hlp.toLatin1().data()
|
---|
[9675] | 403 | << "PGM / RUN BY / DATE\n";
|
---|
[559] | 404 |
|
---|
[7999] | 405 | QStringListIterator it(comments);
|
---|
| 406 | while (it.hasNext()) {
|
---|
| 407 | *_ephStreamGPS << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
|
---|
| 408 | }
|
---|
| 409 |
|
---|
[9765] | 410 | if (_rinexVers == 4) {
|
---|
| 411 | int leapSecs = gnumleap(datTim.date().year(), datTim.date().month(), datTim.date().day());
|
---|
| 412 | *_ephStreamGPS << QString("%1").arg(leapSecs, 6, 10, QLatin1Char(' ')).left(60).leftJustified(60)
|
---|
| 413 | << "LEAP SECONDS\n";
|
---|
| 414 | }
|
---|
| 415 |
|
---|
[9675] | 416 | line = QString().asprintf("%60sEND OF HEADER\n", "");
|
---|
[537] | 417 | *_ephStreamGPS << line;
|
---|
[7291] | 418 |
|
---|
[537] | 419 | _ephStreamGPS->flush();
|
---|
[535] | 420 | }
|
---|
[533] | 421 | }
|
---|
| 422 |
|
---|
[536] | 423 | // Headers - RINEX Version 2
|
---|
| 424 | // -------------------------
|
---|
[9760] | 425 | else {
|
---|
[536] | 426 | if (! (appendFlagGPS & QIODevice::Append)) {
|
---|
[9675] | 427 | QString line = QString().asprintf("%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n",
|
---|
[8127] | 428 | defaultRnxNavVersion2, "", "");
|
---|
[536] | 429 | *_ephStreamGPS << line;
|
---|
[9675] | 430 | line.clear();
|
---|
[7291] | 431 |
|
---|
[1154] | 432 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
[8127] | 433 | *_ephStreamGPS << _pgmName.toLatin1().data()
|
---|
| 434 | << _userName.toLatin1().data()
|
---|
| 435 | << hlp.toLatin1().data()
|
---|
[9675] | 436 | << "PGM / RUN BY / DATE\n";
|
---|
[559] | 437 |
|
---|
[7999] | 438 | QStringListIterator it(comments);
|
---|
| 439 | while (it.hasNext()) {
|
---|
| 440 | *_ephStreamGPS << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
|
---|
| 441 | }
|
---|
| 442 |
|
---|
[9675] | 443 | line = QString().asprintf("%60sEND OF HEADER\n", "");
|
---|
[536] | 444 | *_ephStreamGPS << line;
|
---|
[537] | 445 |
|
---|
| 446 | _ephStreamGPS->flush();
|
---|
[536] | 447 | }
|
---|
| 448 | if (! (appendFlagGlonass & QIODevice::Append)) {
|
---|
[9675] | 449 | QString line = QString().asprintf("%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",
|
---|
[8127] | 450 | defaultRnxNavVersion2, "", "");
|
---|
[536] | 451 | *_ephStreamGlonass << line;
|
---|
[9675] | 452 | line.clear();
|
---|
[7291] | 453 |
|
---|
[1154] | 454 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
[8127] | 455 | *_ephStreamGlonass << _pgmName.toLatin1().data()
|
---|
| 456 | << _userName.toLatin1().data()
|
---|
| 457 | << hlp.toLatin1().data()
|
---|
[9675] | 458 | << "PGM / RUN BY / DATE\n";
|
---|
[559] | 459 |
|
---|
[7999] | 460 | QStringListIterator it(comments);
|
---|
| 461 | while (it.hasNext()) {
|
---|
| 462 | *_ephStreamGlonass << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
|
---|
| 463 | }
|
---|
| 464 |
|
---|
[9675] | 465 | line = QString().asprintf("%60sEND OF HEADER\n", "");
|
---|
[536] | 466 | *_ephStreamGlonass << line;
|
---|
[537] | 467 |
|
---|
| 468 | _ephStreamGlonass->flush();
|
---|
[536] | 469 | }
|
---|
[533] | 470 | }
|
---|
| 471 | }
|
---|
[516] | 472 | }
|
---|
| 473 |
|
---|
[6432] | 474 | // Print One Ephemeris
|
---|
[516] | 475 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6432] | 476 | void t_bncCore::printEph(const t_eph& eph, bool printFile) {
|
---|
[519] | 477 |
|
---|
[8127] | 478 | QString strV2 = eph.toString(defaultRnxNavVersion2);
|
---|
[9483] | 479 | QString strV3 = eph.toString(defaultRnxNavVersion3);
|
---|
[9760] | 480 | QString strV4 = eph.toString(defaultRnxNavVersion4);
|
---|
[941] | 481 |
|
---|
[7026] | 482 | if (_rinexVers == 2 && eph.type() == t_eph::GLONASS) {
|
---|
[9760] | 483 | printOutputEph(printFile, _ephStreamGlonass, strV2, strV3, strV4);
|
---|
[7026] | 484 | }
|
---|
| 485 | else if(_rinexVers == 2 && eph.type() == t_eph::GPS) {
|
---|
[9760] | 486 | printOutputEph(printFile, _ephStreamGPS, strV2, strV3, strV4);
|
---|
[7026] | 487 | }
|
---|
[9765] | 488 | else if (_rinexVers >= 3) {
|
---|
[9760] | 489 | printOutputEph(printFile, _ephStreamGPS, strV2, strV3, strV4);
|
---|
[7026] | 490 | }
|
---|
[941] | 491 | }
|
---|
| 492 |
|
---|
| 493 | // Output
|
---|
| 494 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6451] | 495 | void t_bncCore::printOutputEph(bool printFile, QTextStream* stream,
|
---|
[9760] | 496 | const QString& strV2, const QString& strV3,
|
---|
| 497 | const QString& strV4) {
|
---|
[9770] | 498 | QString strVx;
|
---|
| 499 | if (_rinexVers == 2) {
|
---|
| 500 | strVx = strV2;
|
---|
| 501 | }
|
---|
| 502 | else if (_rinexVers == 3) {
|
---|
| 503 | strVx = strV3;
|
---|
| 504 | }
|
---|
| 505 | else if (_rinexVers == 4) {
|
---|
| 506 | strVx = strV4;
|
---|
| 507 | }
|
---|
[4020] | 508 |
|
---|
[590] | 509 | // Output into file
|
---|
| 510 | // ----------------
|
---|
[943] | 511 | if (printFile && stream) {
|
---|
[9770] | 512 | *stream << strVx.toLatin1();
|
---|
[943] | 513 | stream->flush();
|
---|
[517] | 514 | }
|
---|
[590] | 515 |
|
---|
| 516 | // Output into the socket
|
---|
| 517 | // ----------------------
|
---|
[6451] | 518 | if (_socketsEph) {
|
---|
| 519 | QMutableListIterator<QTcpSocket*> is(*_socketsEph);
|
---|
[590] | 520 | while (is.hasNext()) {
|
---|
| 521 | QTcpSocket* sock = is.next();
|
---|
| 522 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
[9770] | 523 | if (sock->write(strVx.toLatin1()) == -1) {
|
---|
[642] | 524 | delete sock;
|
---|
| 525 | is.remove();
|
---|
| 526 | }
|
---|
[590] | 527 | }
|
---|
[642] | 528 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 529 | delete sock;
|
---|
| 530 | is.remove();
|
---|
| 531 | }
|
---|
[590] | 532 | }
|
---|
| 533 | }
|
---|
[516] | 534 | }
|
---|
[589] | 535 |
|
---|
[591] | 536 | // Set Port Number
|
---|
| 537 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6451] | 538 | void t_bncCore::setPortEph(int port) {
|
---|
| 539 | _portEph = port;
|
---|
| 540 | if (_portEph != 0) {
|
---|
| 541 | delete _serverEph;
|
---|
| 542 | _serverEph = new QTcpServer;
|
---|
[8921] | 543 | _serverEph->setProxy(QNetworkProxy::NoProxy);
|
---|
[6451] | 544 | if ( !_serverEph->listen(QHostAddress::Any, _portEph) ) {
|
---|
[8918] | 545 | QString message = "t_bncCore: Cannot listen on ephemeris port "
|
---|
[8921] | 546 | + QByteArray::number(_portEph) + ": "
|
---|
| 547 | + _serverEph->errorString();
|
---|
[8918] | 548 | slotMessage(message.toLatin1(), true);
|
---|
[1228] | 549 | }
|
---|
[6451] | 550 | connect(_serverEph, SIGNAL(newConnection()), this, SLOT(slotNewConnectionEph()));
|
---|
| 551 | delete _socketsEph;
|
---|
| 552 | _socketsEph = new QList<QTcpSocket*>;
|
---|
[591] | 553 | }
|
---|
| 554 | }
|
---|
| 555 |
|
---|
[937] | 556 | // Set Port Number
|
---|
| 557 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 558 | void t_bncCore::setPortCorr(int port) {
|
---|
[937] | 559 | _portCorr = port;
|
---|
| 560 | if (_portCorr != 0) {
|
---|
[942] | 561 | delete _serverCorr;
|
---|
[937] | 562 | _serverCorr = new QTcpServer;
|
---|
[8921] | 563 | _serverCorr->setProxy(QNetworkProxy::NoProxy);
|
---|
[1228] | 564 | if ( !_serverCorr->listen(QHostAddress::Any, _portCorr) ) {
|
---|
[8918] | 565 | QString message = "t_bncCore: Cannot listen on correction port "
|
---|
[8921] | 566 | + QByteArray::number(_portCorr) + ": "
|
---|
| 567 | + _serverCorr->errorString();
|
---|
[8918] | 568 | slotMessage(message.toLatin1(), true);
|
---|
[1228] | 569 | }
|
---|
[937] | 570 | connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
|
---|
[942] | 571 | delete _socketsCorr;
|
---|
[937] | 572 | _socketsCorr = new QList<QTcpSocket*>;
|
---|
| 573 | }
|
---|
| 574 | }
|
---|
| 575 |
|
---|
[589] | 576 | // New Connection
|
---|
| 577 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6451] | 578 | void t_bncCore::slotNewConnectionEph() {
|
---|
| 579 | _socketsEph->push_back( _serverEph->nextPendingConnection() );
|
---|
[589] | 580 | }
|
---|
| 581 |
|
---|
[937] | 582 | // New Connection
|
---|
| 583 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 584 | void t_bncCore::slotNewConnectionCorr() {
|
---|
[937] | 585 | _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
|
---|
| 586 | }
|
---|
| 587 |
|
---|
[7291] | 588 | //
|
---|
[621] | 589 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 590 | void t_bncCore::slotQuit() {
|
---|
[5729] | 591 | delete _caster; _caster = 0;
|
---|
[5066] | 592 | qApp->quit();
|
---|
[621] | 593 | }
|
---|
| 594 |
|
---|
[7291] | 595 | //
|
---|
[936] | 596 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6141] | 597 | void t_bncCore::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
|
---|
[6151] | 598 | QMutexLocker locker(&_mutex);
|
---|
[6141] | 599 | emit newOrbCorrections(orbCorrections);
|
---|
[6151] | 600 | if (_socketsCorr) {
|
---|
[6455] | 601 | ostringstream out;
|
---|
[7291] | 602 | t_orbCorr::writeEpoch(&out, orbCorrections);
|
---|
[6455] | 603 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
| 604 | while (is.hasNext()) {
|
---|
| 605 | QTcpSocket* sock = is.next();
|
---|
| 606 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
| 607 | if (sock->write(out.str().c_str()) == -1) {
|
---|
[6151] | 608 | delete sock;
|
---|
| 609 | is.remove();
|
---|
| 610 | }
|
---|
| 611 | }
|
---|
[6455] | 612 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 613 | delete sock;
|
---|
| 614 | is.remove();
|
---|
| 615 | }
|
---|
[6151] | 616 | }
|
---|
| 617 | }
|
---|
[6141] | 618 | }
|
---|
[974] | 619 |
|
---|
[7291] | 620 | //
|
---|
[6141] | 621 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 622 | void t_bncCore::slotNewClkCorrections(QList<t_clkCorr> clkCorrections) {
|
---|
[974] | 623 | QMutexLocker locker(&_mutex);
|
---|
[6151] | 624 | emit newClkCorrections(clkCorrections);
|
---|
[3109] | 625 | if (_socketsCorr) {
|
---|
[6455] | 626 | ostringstream out;
|
---|
[7291] | 627 | t_clkCorr::writeEpoch(&out, clkCorrections);
|
---|
[6455] | 628 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
| 629 | while (is.hasNext()) {
|
---|
| 630 | QTcpSocket* sock = is.next();
|
---|
| 631 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
| 632 | if (sock->write(out.str().c_str()) == -1) {
|
---|
[3109] | 633 | delete sock;
|
---|
| 634 | is.remove();
|
---|
| 635 | }
|
---|
[937] | 636 | }
|
---|
[6455] | 637 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 638 | delete sock;
|
---|
| 639 | is.remove();
|
---|
| 640 | }
|
---|
[937] | 641 | }
|
---|
| 642 | }
|
---|
[936] | 643 | }
|
---|
[1538] | 644 |
|
---|
[7291] | 645 | //
|
---|
[1538] | 646 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6480] | 647 | void t_bncCore::slotNewCodeBiases(QList<t_satCodeBias> codeBiases) {
|
---|
[6485] | 648 | QMutexLocker locker(&_mutex);
|
---|
| 649 | emit newCodeBiases(codeBiases);
|
---|
| 650 | if (_socketsCorr) {
|
---|
| 651 | ostringstream out;
|
---|
[7291] | 652 | t_satCodeBias::writeEpoch(&out, codeBiases);
|
---|
[6485] | 653 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
| 654 | while (is.hasNext()) {
|
---|
| 655 | QTcpSocket* sock = is.next();
|
---|
| 656 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
| 657 | if (sock->write(out.str().c_str()) == -1) {
|
---|
| 658 | delete sock;
|
---|
| 659 | is.remove();
|
---|
| 660 | }
|
---|
| 661 | }
|
---|
| 662 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 663 | delete sock;
|
---|
| 664 | is.remove();
|
---|
| 665 | }
|
---|
| 666 | }
|
---|
| 667 | }
|
---|
[6480] | 668 | }
|
---|
| 669 |
|
---|
[7291] | 670 | //
|
---|
[6480] | 671 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6484] | 672 | void t_bncCore::slotNewPhaseBiases(QList<t_satPhaseBias> phaseBiases) {
|
---|
[6485] | 673 | QMutexLocker locker(&_mutex);
|
---|
| 674 | emit newPhaseBiases(phaseBiases);
|
---|
| 675 | if (_socketsCorr) {
|
---|
| 676 | ostringstream out;
|
---|
[7291] | 677 | t_satPhaseBias::writeEpoch(&out, phaseBiases);
|
---|
[6485] | 678 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
| 679 | while (is.hasNext()) {
|
---|
| 680 | QTcpSocket* sock = is.next();
|
---|
| 681 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
| 682 | if (sock->write(out.str().c_str()) == -1) {
|
---|
| 683 | delete sock;
|
---|
| 684 | is.remove();
|
---|
| 685 | }
|
---|
| 686 | }
|
---|
| 687 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 688 | delete sock;
|
---|
| 689 | is.remove();
|
---|
| 690 | }
|
---|
| 691 | }
|
---|
| 692 | }
|
---|
[6484] | 693 | }
|
---|
| 694 |
|
---|
[7291] | 695 | //
|
---|
[6484] | 696 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 697 | void t_bncCore::slotNewTec(t_vTec vTec) {
|
---|
[6485] | 698 | QMutexLocker locker(&_mutex);
|
---|
| 699 | emit newTec(vTec);
|
---|
| 700 | if (_socketsCorr) {
|
---|
| 701 | ostringstream out;
|
---|
[7291] | 702 | t_vTec::write(&out, vTec);
|
---|
[6485] | 703 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
| 704 | while (is.hasNext()) {
|
---|
| 705 | QTcpSocket* sock = is.next();
|
---|
| 706 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
| 707 | if (sock->write(out.str().c_str()) == -1) {
|
---|
| 708 | delete sock;
|
---|
| 709 | is.remove();
|
---|
| 710 | }
|
---|
| 711 | }
|
---|
| 712 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 713 | delete sock;
|
---|
| 714 | is.remove();
|
---|
| 715 | }
|
---|
| 716 | }
|
---|
| 717 | }
|
---|
[6484] | 718 | }
|
---|
| 719 |
|
---|
[7291] | 720 | //
|
---|
[6484] | 721 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 722 | void t_bncCore::setConfFileName(const QString& confFileName) {
|
---|
[4169] | 723 | if (confFileName.isEmpty()) {
|
---|
[7291] | 724 | _confFileName = QDir::homePath() + QDir::separator()
|
---|
[4169] | 725 | + ".config" + QDir::separator()
|
---|
[5066] | 726 | + qApp->organizationName() + QDir::separator()
|
---|
| 727 | + qApp->applicationName() + ".bnc";
|
---|
[1538] | 728 | }
|
---|
[4169] | 729 | else {
|
---|
| 730 | _confFileName = confFileName;
|
---|
| 731 | }
|
---|
[1538] | 732 | }
|
---|
[2385] | 733 |
|
---|
| 734 | // Raw Output
|
---|
| 735 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 736 | void t_bncCore::writeRawData(const QByteArray& data, const QByteArray& staID,
|
---|
[2518] | 737 | const QByteArray& format) {
|
---|
[2385] | 738 |
|
---|
[2386] | 739 | QMutexLocker locker(&_mutex);
|
---|
| 740 |
|
---|
[2519] | 741 | if (!_rawFile) {
|
---|
[2386] | 742 | bncSettings settings;
|
---|
[2519] | 743 | QByteArray fileName = settings.value("rawOutFile").toByteArray();
|
---|
| 744 | if (!fileName.isEmpty()) {
|
---|
[3524] | 745 | _rawFile = new bncRawFile(fileName, staID, bncRawFile::output);
|
---|
[2407] | 746 | }
|
---|
[2386] | 747 | }
|
---|
| 748 |
|
---|
[2519] | 749 | if (_rawFile) {
|
---|
| 750 | _rawFile->writeRawData(data, staID, format);
|
---|
[2386] | 751 | }
|
---|
[2385] | 752 | }
|
---|
[2672] | 753 |
|
---|
[7291] | 754 | //
|
---|
[2909] | 755 | ////////////////////////////////////////////////////////////////////////////
|
---|
[10040] | 756 | void t_bncCore::initCombination() {
|
---|
| 757 | bncComb::getInstance();
|
---|
| 758 | if (BNC_CMB->nStreams() < 1) {
|
---|
| 759 | bncComb::destruct();
|
---|
[2909] | 760 | }
|
---|
| 761 | }
|
---|
[3231] | 762 |
|
---|
[7291] | 763 | //
|
---|
[3231] | 764 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 765 | void t_bncCore::stopCombination() {
|
---|
[10040] | 766 | bncComb::destruct();
|
---|
[3231] | 767 | }
|
---|
[4167] | 768 |
|
---|
[5846] | 769 | //
|
---|
| 770 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 771 | bool t_bncCore::dateAndTimeGPSSet() const {
|
---|
| 772 | QMutexLocker locker(&_mutexDateAndTimeGPS);
|
---|
| 773 | if (_dateAndTimeGPS) {
|
---|
| 774 | return true;
|
---|
| 775 | }
|
---|
| 776 | else {
|
---|
| 777 | return false;
|
---|
| 778 | }
|
---|
| 779 | }
|
---|
| 780 |
|
---|
| 781 | //
|
---|
| 782 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 783 | QDateTime t_bncCore::dateAndTimeGPS() const {
|
---|
| 784 | QMutexLocker locker(&_mutexDateAndTimeGPS);
|
---|
| 785 | if (_dateAndTimeGPS) {
|
---|
| 786 | return *_dateAndTimeGPS;
|
---|
| 787 | }
|
---|
| 788 | else {
|
---|
| 789 | return QDateTime();
|
---|
| 790 | }
|
---|
| 791 | }
|
---|
| 792 |
|
---|
| 793 | //
|
---|
| 794 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 795 | void t_bncCore::setDateAndTimeGPS(QDateTime dateTime) {
|
---|
| 796 | QMutexLocker locker(&_mutexDateAndTimeGPS);
|
---|
| 797 | delete _dateAndTimeGPS;
|
---|
| 798 | _dateAndTimeGPS = new QDateTime(dateTime);
|
---|
| 799 | }
|
---|
[5900] | 800 |
|
---|
| 801 | //
|
---|
| 802 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5946] | 803 | void t_bncCore::startPPP() {
|
---|
| 804 | _pppMain->start();
|
---|
[5900] | 805 | }
|
---|
| 806 |
|
---|
| 807 | //
|
---|
| 808 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 809 | void t_bncCore::stopPPP() {
|
---|
[5903] | 810 | _pppMain->stop();
|
---|
[5972] | 811 | emit stopRinexPPP();
|
---|
[5900] | 812 | }
|
---|
[6383] | 813 |
|
---|