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