[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) {
|
---|
[9591] | 188 | *_logStream << endl;
|
---|
[3371] | 189 | msgLocal = msg.mid(1);
|
---|
| 190 | }
|
---|
[8127] | 191 | *_logStream << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toLatin1().data();
|
---|
[9591] | 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);
|
---|
[9379] | 203 | #ifdef BNC_DEBUG_BCEP
|
---|
[7208] | 204 | if (eph->checkState() == t_eph::bad) {
|
---|
[9219] | 205 | messagePrivate(QString("%1: WRONG EPHEMERIS: %2")
|
---|
[9217] | 206 | .arg(eph->receptStaID())
|
---|
[9213] | 207 | .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 3.0)).toLatin1());
|
---|
[6520] | 208 | return failure;
|
---|
[6519] | 209 | }
|
---|
[7208] | 210 | else if (eph->checkState() == t_eph::outdated) {
|
---|
[9219] | 211 | messagePrivate(QString("%1: OUTDATED EPHEMERIS: %2")
|
---|
[9217] | 212 | .arg(eph->receptStaID())
|
---|
[9212] | 213 | .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 3.0)).toLatin1());
|
---|
[7208] | 214 | return failure;
|
---|
| 215 | }
|
---|
[8215] | 216 | else if (eph->checkState() == t_eph::unhealthy) {
|
---|
[9217] | 217 | messagePrivate(QString("%1: UNHEALTHY EPHEMERIS: %2")
|
---|
| 218 | .arg(eph->receptStaID())
|
---|
[9212] | 219 | .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 3.0)).toLatin1());
|
---|
[8215] | 220 | }
|
---|
[9379] | 221 | #endif
|
---|
[534] | 222 | printEphHeader();
|
---|
[6520] | 223 | printEph(*eph, (ircPut == success));
|
---|
| 224 | return success;
|
---|
[511] | 225 | }
|
---|
[6520] | 226 |
|
---|
[7291] | 227 | // New GPS Ephemeris
|
---|
[6520] | 228 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 229 | void t_bncCore::slotNewGPSEph(t_ephGPS eph) {
|
---|
| 230 | if (checkPrintEph(&eph) == success) {
|
---|
| 231 | emit newGPSEph(eph);
|
---|
| 232 | }
|
---|
| 233 | }
|
---|
[7291] | 234 |
|
---|
[535] | 235 | // New Glonass Ephemeris
|
---|
[511] | 236 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6432] | 237 | void t_bncCore::slotNewGlonassEph(t_ephGlo eph) {
|
---|
[6520] | 238 | if (checkPrintEph(&eph) == success) {
|
---|
| 239 | emit newGlonassEph(eph);
|
---|
[6519] | 240 | }
|
---|
[511] | 241 | }
|
---|
| 242 |
|
---|
[2770] | 243 | // New Galileo Ephemeris
|
---|
| 244 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6432] | 245 | void t_bncCore::slotNewGalileoEph(t_ephGal eph) {
|
---|
[6520] | 246 | if (checkPrintEph(&eph) == success) {
|
---|
| 247 | emit newGalileoEph(eph);
|
---|
[6519] | 248 | }
|
---|
[6432] | 249 | }
|
---|
[2772] | 250 |
|
---|
[6432] | 251 | // New SBAS Ephemeris
|
---|
| 252 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 253 | void t_bncCore::slotNewSBASEph(t_ephSBAS eph) {
|
---|
[6520] | 254 | if (checkPrintEph(&eph) == success) {
|
---|
| 255 | emit newSBASEph(eph);
|
---|
[6519] | 256 | }
|
---|
[2770] | 257 | }
|
---|
| 258 |
|
---|
[6598] | 259 | // New BDS Ephemeris
|
---|
[6595] | 260 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6598] | 261 | void t_bncCore::slotNewBDSEph(t_ephBDS eph) {
|
---|
[6595] | 262 | if (checkPrintEph(&eph) == success) {
|
---|
[6598] | 263 | emit newBDSEph(eph);
|
---|
[6595] | 264 | }
|
---|
| 265 | }
|
---|
[6432] | 266 |
|
---|
[535] | 267 | // Print Header of the output File(s)
|
---|
[516] | 268 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 269 | void t_bncCore::printEphHeader() {
|
---|
[528] | 270 |
|
---|
[1535] | 271 | bncSettings settings;
|
---|
[7999] | 272 | QStringList comments;
|
---|
[535] | 273 |
|
---|
[7999] | 274 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
| 275 | while (it.hasNext()) {
|
---|
| 276 | QStringList hlp = it.next().split(" ");
|
---|
| 277 | if (hlp.size() < 7)
|
---|
| 278 | continue;
|
---|
| 279 | QUrl url(hlp[0]);
|
---|
| 280 | QString decoder = hlp[1];
|
---|
| 281 | comments.append("Source: " + decoder +
|
---|
[8203] | 282 | " " + QUrl::toAce(url.host()) +
|
---|
[8127] | 283 | "/" + url.path().mid(1).toLatin1());
|
---|
[7999] | 284 | }
|
---|
| 285 |
|
---|
[534] | 286 | // Initialization
|
---|
| 287 | // --------------
|
---|
| 288 | if (_rinexVers == 0) {
|
---|
[528] | 289 |
|
---|
[9760] | 290 | _rinexVers = settings.value("ephVersion").toInt();
|
---|
[529] | 291 |
|
---|
[533] | 292 | _ephPath = settings.value("ephPath").toString();
|
---|
| 293 |
|
---|
| 294 | if ( !_ephPath.isEmpty() ) {
|
---|
| 295 | if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
|
---|
| 296 | _ephPath += QDir::separator();
|
---|
| 297 | }
|
---|
| 298 | expandEnvVar(_ephPath);
|
---|
| 299 | }
|
---|
[517] | 300 | }
|
---|
[533] | 301 |
|
---|
[534] | 302 | // (Re-)Open output File(s)
|
---|
| 303 | // ------------------------
|
---|
[533] | 304 | if (!_ephPath.isEmpty()) {
|
---|
| 305 |
|
---|
[1154] | 306 | QDateTime datTim = currentDateAndTimeGPS();
|
---|
[533] | 307 |
|
---|
[7179] | 308 | QString ephFileNameGPS = _ephPath + "BRDC";
|
---|
[533] | 309 |
|
---|
[7291] | 310 | QString hlpStr = bncRinex::nextEpochStr(datTim,
|
---|
[9760] | 311 | settings.value("ephIntr").toString(), _rinexVers);
|
---|
[584] | 312 |
|
---|
[9760] | 313 | if (_rinexVers > 2) {
|
---|
[8354] | 314 | QString country = "WRD"; // WORLD
|
---|
| 315 | QString monNum = "0";
|
---|
| 316 | QString recNum = "0";
|
---|
| 317 | ephFileNameGPS += QString("%1").arg(monNum, 1, 10) +
|
---|
| 318 | QString("%1").arg(recNum, 1, 10) +
|
---|
| 319 | country +
|
---|
| 320 | "_S_" + // stream
|
---|
| 321 | QString("%1").arg(datTim.date().year()) +
|
---|
| 322 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
| 323 | hlpStr + // HM_period
|
---|
| 324 | "_MN.rnx"; // mixed BRDC
|
---|
[575] | 325 | }
|
---|
[7179] | 326 | else { // RNX v2.11
|
---|
| 327 | ephFileNameGPS += QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
| 328 | hlpStr + datTim.toString(".yyN");
|
---|
[575] | 329 | }
|
---|
[563] | 330 |
|
---|
[533] | 331 | if (_ephFileNameGPS == ephFileNameGPS) {
|
---|
| 332 | return;
|
---|
| 333 | }
|
---|
| 334 | else {
|
---|
| 335 | _ephFileNameGPS = ephFileNameGPS;
|
---|
| 336 | }
|
---|
| 337 |
|
---|
| 338 | delete _ephStreamGPS;
|
---|
| 339 | delete _ephFileGPS;
|
---|
| 340 |
|
---|
[535] | 341 | QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
|
---|
[536] | 342 | QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
|
---|
| 343 |
|
---|
[535] | 344 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
---|
| 345 | QFile::exists(ephFileNameGPS) ) {
|
---|
| 346 | appendFlagGPS = QIODevice::Append;
|
---|
| 347 | }
|
---|
| 348 |
|
---|
[533] | 349 | _ephFileGPS = new QFile(ephFileNameGPS);
|
---|
[535] | 350 | _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
|
---|
[533] | 351 | _ephStreamGPS = new QTextStream();
|
---|
| 352 | _ephStreamGPS->setDevice(_ephFileGPS);
|
---|
| 353 |
|
---|
[9760] | 354 | if (_rinexVers > 2) {
|
---|
[533] | 355 | _ephFileGlonass = _ephFileGPS;
|
---|
| 356 | _ephStreamGlonass = _ephStreamGPS;
|
---|
[2770] | 357 | _ephFileGalileo = _ephFileGPS;
|
---|
| 358 | _ephStreamGalileo = _ephStreamGPS;
|
---|
[6384] | 359 | _ephFileSBAS = _ephFileGPS;
|
---|
| 360 | _ephStreamSBAS = _ephStreamGPS;
|
---|
[533] | 361 | }
|
---|
[9760] | 362 | else {
|
---|
[583] | 363 | QString ephFileNameGlonass = _ephPath + "BRDC" +
|
---|
[563] | 364 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
[575] | 365 | hlpStr + datTim.toString(".yyG");
|
---|
[533] | 366 |
|
---|
| 367 | delete _ephStreamGlonass;
|
---|
| 368 | delete _ephFileGlonass;
|
---|
| 369 |
|
---|
[535] | 370 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
---|
| 371 | QFile::exists(ephFileNameGlonass) ) {
|
---|
| 372 | appendFlagGlonass = QIODevice::Append;
|
---|
| 373 | }
|
---|
| 374 |
|
---|
[533] | 375 | _ephFileGlonass = new QFile(ephFileNameGlonass);
|
---|
[535] | 376 | _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
|
---|
[533] | 377 | _ephStreamGlonass = new QTextStream();
|
---|
| 378 | _ephStreamGlonass->setDevice(_ephFileGlonass);
|
---|
| 379 | }
|
---|
| 380 |
|
---|
[534] | 381 | // Header - RINEX Version 3
|
---|
| 382 | // ------------------------
|
---|
[9760] | 383 | if (_rinexVers > 2) {
|
---|
[537] | 384 | if ( ! (appendFlagGPS & QIODevice::Append)) {
|
---|
[9675] | 385 | QString line = QString().asprintf("%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
|
---|
[8127] | 386 | defaultRnxNavVersion3, "", "");
|
---|
[537] | 387 | *_ephStreamGPS << line;
|
---|
[9675] | 388 | line.clear();
|
---|
[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()
|
---|
[9675] | 394 | << "PGM / RUN BY / DATE\n";
|
---|
[559] | 395 |
|
---|
[7999] | 396 | QStringListIterator it(comments);
|
---|
| 397 | while (it.hasNext()) {
|
---|
| 398 | *_ephStreamGPS << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
|
---|
| 399 | }
|
---|
| 400 |
|
---|
[9675] | 401 | line = QString().asprintf("%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 | // -------------------------
|
---|
[9760] | 410 | else {
|
---|
[536] | 411 | if (! (appendFlagGPS & QIODevice::Append)) {
|
---|
[9675] | 412 | QString line = QString().asprintf("%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n",
|
---|
[8127] | 413 | defaultRnxNavVersion2, "", "");
|
---|
[536] | 414 | *_ephStreamGPS << line;
|
---|
[9675] | 415 | line.clear();
|
---|
[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()
|
---|
[9675] | 421 | << "PGM / RUN BY / DATE\n";
|
---|
[559] | 422 |
|
---|
[7999] | 423 | QStringListIterator it(comments);
|
---|
| 424 | while (it.hasNext()) {
|
---|
| 425 | *_ephStreamGPS << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
|
---|
| 426 | }
|
---|
| 427 |
|
---|
[9675] | 428 | line = QString().asprintf("%60sEND OF HEADER\n", "");
|
---|
[536] | 429 | *_ephStreamGPS << line;
|
---|
[537] | 430 |
|
---|
| 431 | _ephStreamGPS->flush();
|
---|
[536] | 432 | }
|
---|
| 433 | if (! (appendFlagGlonass & QIODevice::Append)) {
|
---|
[9675] | 434 | QString line = QString().asprintf("%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",
|
---|
[8127] | 435 | defaultRnxNavVersion2, "", "");
|
---|
[536] | 436 | *_ephStreamGlonass << line;
|
---|
[9675] | 437 | line.clear();
|
---|
[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()
|
---|
[9675] | 443 | << "PGM / RUN BY / DATE\n";
|
---|
[559] | 444 |
|
---|
[7999] | 445 | QStringListIterator it(comments);
|
---|
| 446 | while (it.hasNext()) {
|
---|
| 447 | *_ephStreamGlonass << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
|
---|
| 448 | }
|
---|
| 449 |
|
---|
[9675] | 450 | line = QString().asprintf("%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);
|
---|
[9483] | 464 | QString strV3 = eph.toString(defaultRnxNavVersion3);
|
---|
[9760] | 465 | QString strV4 = eph.toString(defaultRnxNavVersion4);
|
---|
[941] | 466 |
|
---|
[7026] | 467 | if (_rinexVers == 2 && eph.type() == t_eph::GLONASS) {
|
---|
[9760] | 468 | printOutputEph(printFile, _ephStreamGlonass, strV2, strV3, strV4);
|
---|
[7026] | 469 | }
|
---|
| 470 | else if(_rinexVers == 2 && eph.type() == t_eph::GPS) {
|
---|
[9760] | 471 | printOutputEph(printFile, _ephStreamGPS, strV2, strV3, strV4);
|
---|
[7026] | 472 | }
|
---|
| 473 | else if (_rinexVers == 3) {
|
---|
[9760] | 474 | printOutputEph(printFile, _ephStreamGPS, strV2, strV3, strV4);
|
---|
[7026] | 475 | }
|
---|
[941] | 476 | }
|
---|
| 477 |
|
---|
| 478 | // Output
|
---|
| 479 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6451] | 480 | void t_bncCore::printOutputEph(bool printFile, QTextStream* stream,
|
---|
[9760] | 481 | const QString& strV2, const QString& strV3,
|
---|
| 482 | const QString& strV4) {
|
---|
[4020] | 483 |
|
---|
[590] | 484 | // Output into file
|
---|
| 485 | // ----------------
|
---|
[943] | 486 | if (printFile && stream) {
|
---|
[9760] | 487 | if (_rinexVers == 2) {
|
---|
[8127] | 488 | *stream << strV2.toLatin1();
|
---|
[941] | 489 | }
|
---|
[9760] | 490 | else if (_rinexVers == 3) {
|
---|
[8127] | 491 | *stream << strV3.toLatin1();
|
---|
[941] | 492 | }
|
---|
[9760] | 493 | else if (_rinexVers == 4) {
|
---|
| 494 | *stream << strV4.toLatin1();
|
---|
| 495 | }
|
---|
[943] | 496 | stream->flush();
|
---|
[517] | 497 | }
|
---|
[590] | 498 |
|
---|
| 499 | // Output into the socket
|
---|
| 500 | // ----------------------
|
---|
[6451] | 501 | if (_socketsEph) {
|
---|
| 502 | QMutableListIterator<QTcpSocket*> is(*_socketsEph);
|
---|
[590] | 503 | while (is.hasNext()) {
|
---|
| 504 | QTcpSocket* sock = is.next();
|
---|
| 505 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
[8127] | 506 | if (sock->write(strV3.toLatin1()) == -1) {
|
---|
[642] | 507 | delete sock;
|
---|
| 508 | is.remove();
|
---|
| 509 | }
|
---|
[590] | 510 | }
|
---|
[642] | 511 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 512 | delete sock;
|
---|
| 513 | is.remove();
|
---|
| 514 | }
|
---|
[590] | 515 | }
|
---|
| 516 | }
|
---|
[516] | 517 | }
|
---|
[589] | 518 |
|
---|
[591] | 519 | // Set Port Number
|
---|
| 520 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6451] | 521 | void t_bncCore::setPortEph(int port) {
|
---|
| 522 | _portEph = port;
|
---|
| 523 | if (_portEph != 0) {
|
---|
| 524 | delete _serverEph;
|
---|
| 525 | _serverEph = new QTcpServer;
|
---|
[8921] | 526 | _serverEph->setProxy(QNetworkProxy::NoProxy);
|
---|
[6451] | 527 | if ( !_serverEph->listen(QHostAddress::Any, _portEph) ) {
|
---|
[8918] | 528 | QString message = "t_bncCore: Cannot listen on ephemeris port "
|
---|
[8921] | 529 | + QByteArray::number(_portEph) + ": "
|
---|
| 530 | + _serverEph->errorString();
|
---|
[8918] | 531 | slotMessage(message.toLatin1(), true);
|
---|
[1228] | 532 | }
|
---|
[6451] | 533 | connect(_serverEph, SIGNAL(newConnection()), this, SLOT(slotNewConnectionEph()));
|
---|
| 534 | delete _socketsEph;
|
---|
| 535 | _socketsEph = new QList<QTcpSocket*>;
|
---|
[591] | 536 | }
|
---|
| 537 | }
|
---|
| 538 |
|
---|
[937] | 539 | // Set Port Number
|
---|
| 540 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 541 | void t_bncCore::setPortCorr(int port) {
|
---|
[937] | 542 | _portCorr = port;
|
---|
| 543 | if (_portCorr != 0) {
|
---|
[942] | 544 | delete _serverCorr;
|
---|
[937] | 545 | _serverCorr = new QTcpServer;
|
---|
[8921] | 546 | _serverCorr->setProxy(QNetworkProxy::NoProxy);
|
---|
[1228] | 547 | if ( !_serverCorr->listen(QHostAddress::Any, _portCorr) ) {
|
---|
[8918] | 548 | QString message = "t_bncCore: Cannot listen on correction port "
|
---|
[8921] | 549 | + QByteArray::number(_portCorr) + ": "
|
---|
| 550 | + _serverCorr->errorString();
|
---|
[8918] | 551 | slotMessage(message.toLatin1(), true);
|
---|
[1228] | 552 | }
|
---|
[937] | 553 | connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
|
---|
[942] | 554 | delete _socketsCorr;
|
---|
[937] | 555 | _socketsCorr = new QList<QTcpSocket*>;
|
---|
| 556 | }
|
---|
| 557 | }
|
---|
| 558 |
|
---|
[589] | 559 | // New Connection
|
---|
| 560 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6451] | 561 | void t_bncCore::slotNewConnectionEph() {
|
---|
| 562 | _socketsEph->push_back( _serverEph->nextPendingConnection() );
|
---|
[589] | 563 | }
|
---|
| 564 |
|
---|
[937] | 565 | // New Connection
|
---|
| 566 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 567 | void t_bncCore::slotNewConnectionCorr() {
|
---|
[937] | 568 | _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
|
---|
| 569 | }
|
---|
| 570 |
|
---|
[7291] | 571 | //
|
---|
[621] | 572 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 573 | void t_bncCore::slotQuit() {
|
---|
[5729] | 574 | delete _caster; _caster = 0;
|
---|
[5066] | 575 | qApp->quit();
|
---|
[621] | 576 | }
|
---|
| 577 |
|
---|
[7291] | 578 | //
|
---|
[936] | 579 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6141] | 580 | void t_bncCore::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
|
---|
[6151] | 581 | QMutexLocker locker(&_mutex);
|
---|
[6141] | 582 | emit newOrbCorrections(orbCorrections);
|
---|
[6151] | 583 | if (_socketsCorr) {
|
---|
[6455] | 584 | ostringstream out;
|
---|
[7291] | 585 | t_orbCorr::writeEpoch(&out, orbCorrections);
|
---|
[6455] | 586 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
| 587 | while (is.hasNext()) {
|
---|
| 588 | QTcpSocket* sock = is.next();
|
---|
| 589 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
| 590 | if (sock->write(out.str().c_str()) == -1) {
|
---|
[6151] | 591 | delete sock;
|
---|
| 592 | is.remove();
|
---|
| 593 | }
|
---|
| 594 | }
|
---|
[6455] | 595 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 596 | delete sock;
|
---|
| 597 | is.remove();
|
---|
| 598 | }
|
---|
[6151] | 599 | }
|
---|
| 600 | }
|
---|
[6141] | 601 | }
|
---|
[974] | 602 |
|
---|
[7291] | 603 | //
|
---|
[6141] | 604 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 605 | void t_bncCore::slotNewClkCorrections(QList<t_clkCorr> clkCorrections) {
|
---|
[974] | 606 | QMutexLocker locker(&_mutex);
|
---|
[6151] | 607 | emit newClkCorrections(clkCorrections);
|
---|
[3109] | 608 | if (_socketsCorr) {
|
---|
[6455] | 609 | ostringstream out;
|
---|
[7291] | 610 | t_clkCorr::writeEpoch(&out, clkCorrections);
|
---|
[6455] | 611 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
| 612 | while (is.hasNext()) {
|
---|
| 613 | QTcpSocket* sock = is.next();
|
---|
| 614 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
| 615 | if (sock->write(out.str().c_str()) == -1) {
|
---|
[3109] | 616 | delete sock;
|
---|
| 617 | is.remove();
|
---|
| 618 | }
|
---|
[937] | 619 | }
|
---|
[6455] | 620 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 621 | delete sock;
|
---|
| 622 | is.remove();
|
---|
| 623 | }
|
---|
[937] | 624 | }
|
---|
| 625 | }
|
---|
[936] | 626 | }
|
---|
[1538] | 627 |
|
---|
[7291] | 628 | //
|
---|
[1538] | 629 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6480] | 630 | void t_bncCore::slotNewCodeBiases(QList<t_satCodeBias> codeBiases) {
|
---|
[6485] | 631 | QMutexLocker locker(&_mutex);
|
---|
| 632 | emit newCodeBiases(codeBiases);
|
---|
| 633 | if (_socketsCorr) {
|
---|
| 634 | ostringstream out;
|
---|
[7291] | 635 | t_satCodeBias::writeEpoch(&out, codeBiases);
|
---|
[6485] | 636 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
| 637 | while (is.hasNext()) {
|
---|
| 638 | QTcpSocket* sock = is.next();
|
---|
| 639 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
| 640 | if (sock->write(out.str().c_str()) == -1) {
|
---|
| 641 | delete sock;
|
---|
| 642 | is.remove();
|
---|
| 643 | }
|
---|
| 644 | }
|
---|
| 645 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 646 | delete sock;
|
---|
| 647 | is.remove();
|
---|
| 648 | }
|
---|
| 649 | }
|
---|
| 650 | }
|
---|
[6480] | 651 | }
|
---|
| 652 |
|
---|
[7291] | 653 | //
|
---|
[6480] | 654 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6484] | 655 | void t_bncCore::slotNewPhaseBiases(QList<t_satPhaseBias> phaseBiases) {
|
---|
[6485] | 656 | QMutexLocker locker(&_mutex);
|
---|
| 657 | emit newPhaseBiases(phaseBiases);
|
---|
| 658 | if (_socketsCorr) {
|
---|
| 659 | ostringstream out;
|
---|
[7291] | 660 | t_satPhaseBias::writeEpoch(&out, phaseBiases);
|
---|
[6485] | 661 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
| 662 | while (is.hasNext()) {
|
---|
| 663 | QTcpSocket* sock = is.next();
|
---|
| 664 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
| 665 | if (sock->write(out.str().c_str()) == -1) {
|
---|
| 666 | delete sock;
|
---|
| 667 | is.remove();
|
---|
| 668 | }
|
---|
| 669 | }
|
---|
| 670 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 671 | delete sock;
|
---|
| 672 | is.remove();
|
---|
| 673 | }
|
---|
| 674 | }
|
---|
| 675 | }
|
---|
[6484] | 676 | }
|
---|
| 677 |
|
---|
[7291] | 678 | //
|
---|
[6484] | 679 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 680 | void t_bncCore::slotNewTec(t_vTec vTec) {
|
---|
[6485] | 681 | QMutexLocker locker(&_mutex);
|
---|
| 682 | emit newTec(vTec);
|
---|
| 683 | if (_socketsCorr) {
|
---|
| 684 | ostringstream out;
|
---|
[7291] | 685 | t_vTec::write(&out, vTec);
|
---|
[6485] | 686 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
| 687 | while (is.hasNext()) {
|
---|
| 688 | QTcpSocket* sock = is.next();
|
---|
| 689 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
| 690 | if (sock->write(out.str().c_str()) == -1) {
|
---|
| 691 | delete sock;
|
---|
| 692 | is.remove();
|
---|
| 693 | }
|
---|
| 694 | }
|
---|
| 695 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 696 | delete sock;
|
---|
| 697 | is.remove();
|
---|
| 698 | }
|
---|
| 699 | }
|
---|
| 700 | }
|
---|
[6484] | 701 | }
|
---|
| 702 |
|
---|
[7291] | 703 | //
|
---|
[6484] | 704 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 705 | void t_bncCore::setConfFileName(const QString& confFileName) {
|
---|
[4169] | 706 | if (confFileName.isEmpty()) {
|
---|
[7291] | 707 | _confFileName = QDir::homePath() + QDir::separator()
|
---|
[4169] | 708 | + ".config" + QDir::separator()
|
---|
[5066] | 709 | + qApp->organizationName() + QDir::separator()
|
---|
| 710 | + qApp->applicationName() + ".bnc";
|
---|
[1538] | 711 | }
|
---|
[4169] | 712 | else {
|
---|
| 713 | _confFileName = confFileName;
|
---|
| 714 | }
|
---|
[1538] | 715 | }
|
---|
[2385] | 716 |
|
---|
| 717 | // Raw Output
|
---|
| 718 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 719 | void t_bncCore::writeRawData(const QByteArray& data, const QByteArray& staID,
|
---|
[2518] | 720 | const QByteArray& format) {
|
---|
[2385] | 721 |
|
---|
[2386] | 722 | QMutexLocker locker(&_mutex);
|
---|
| 723 |
|
---|
[2519] | 724 | if (!_rawFile) {
|
---|
[2386] | 725 | bncSettings settings;
|
---|
[2519] | 726 | QByteArray fileName = settings.value("rawOutFile").toByteArray();
|
---|
| 727 | if (!fileName.isEmpty()) {
|
---|
[3524] | 728 | _rawFile = new bncRawFile(fileName, staID, bncRawFile::output);
|
---|
[2407] | 729 | }
|
---|
[2386] | 730 | }
|
---|
| 731 |
|
---|
[2519] | 732 | if (_rawFile) {
|
---|
| 733 | _rawFile->writeRawData(data, staID, format);
|
---|
[2386] | 734 | }
|
---|
[2385] | 735 | }
|
---|
[2672] | 736 |
|
---|
[7291] | 737 | //
|
---|
[2909] | 738 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 739 | void t_bncCore::initCombination() {
|
---|
[2909] | 740 | _bncComb = new bncComb();
|
---|
[3142] | 741 | if (_bncComb->nStreams() < 1) {
|
---|
[2909] | 742 | delete _bncComb;
|
---|
| 743 | _bncComb = 0;
|
---|
| 744 | }
|
---|
| 745 | }
|
---|
[3231] | 746 |
|
---|
[7291] | 747 | //
|
---|
[3231] | 748 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5072] | 749 | void t_bncCore::stopCombination() {
|
---|
[3231] | 750 | delete _bncComb;
|
---|
| 751 | _bncComb = 0;
|
---|
| 752 | }
|
---|
[4167] | 753 |
|
---|
[5846] | 754 | //
|
---|
| 755 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 756 | bool t_bncCore::dateAndTimeGPSSet() const {
|
---|
| 757 | QMutexLocker locker(&_mutexDateAndTimeGPS);
|
---|
| 758 | if (_dateAndTimeGPS) {
|
---|
| 759 | return true;
|
---|
| 760 | }
|
---|
| 761 | else {
|
---|
| 762 | return false;
|
---|
| 763 | }
|
---|
| 764 | }
|
---|
| 765 |
|
---|
| 766 | //
|
---|
| 767 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 768 | QDateTime t_bncCore::dateAndTimeGPS() const {
|
---|
| 769 | QMutexLocker locker(&_mutexDateAndTimeGPS);
|
---|
| 770 | if (_dateAndTimeGPS) {
|
---|
| 771 | return *_dateAndTimeGPS;
|
---|
| 772 | }
|
---|
| 773 | else {
|
---|
| 774 | return QDateTime();
|
---|
| 775 | }
|
---|
| 776 | }
|
---|
| 777 |
|
---|
| 778 | //
|
---|
| 779 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 780 | void t_bncCore::setDateAndTimeGPS(QDateTime dateTime) {
|
---|
| 781 | QMutexLocker locker(&_mutexDateAndTimeGPS);
|
---|
| 782 | delete _dateAndTimeGPS;
|
---|
| 783 | _dateAndTimeGPS = new QDateTime(dateTime);
|
---|
| 784 | }
|
---|
[5900] | 785 |
|
---|
| 786 | //
|
---|
| 787 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5946] | 788 | void t_bncCore::startPPP() {
|
---|
| 789 | _pppMain->start();
|
---|
[5900] | 790 | }
|
---|
| 791 |
|
---|
| 792 | //
|
---|
| 793 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 794 | void t_bncCore::stopPPP() {
|
---|
[5903] | 795 | _pppMain->stop();
|
---|
[5972] | 796 | emit stopRinexPPP();
|
---|
[5900] | 797 | }
|
---|
[6383] | 798 |
|
---|