| 1 | // Part of BNC, a utility for retrieving decoding and
|
|---|
| 2 | // converting GNSS data streams from NTRIP broadcasters.
|
|---|
| 3 | //
|
|---|
| 4 | // Copyright (C) 2007
|
|---|
| 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
|---|
| 6 | // http://www.bkg.bund.de
|
|---|
| 7 | // Czech Technical University Prague, Department of Geodesy
|
|---|
| 8 | // http://www.fsv.cvut.cz
|
|---|
| 9 | //
|
|---|
| 10 | // Email: euref-ip@bkg.bund.de
|
|---|
| 11 | //
|
|---|
| 12 | // This program is free software; you can redistribute it and/or
|
|---|
| 13 | // modify it under the terms of the GNU General Public License
|
|---|
| 14 | // as published by the Free Software Foundation, version 2.
|
|---|
| 15 | //
|
|---|
| 16 | // This program is distributed in the hope that it will be useful,
|
|---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 19 | // GNU General Public License for more details.
|
|---|
| 20 | //
|
|---|
| 21 | // You should have received a copy of the GNU General Public License
|
|---|
| 22 | // along with this program; if not, write to the Free Software
|
|---|
| 23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|---|
| 24 |
|
|---|
| 25 | /* -------------------------------------------------------------------------
|
|---|
| 26 | * BKG NTRIP Client
|
|---|
| 27 | * -------------------------------------------------------------------------
|
|---|
| 28 | *
|
|---|
| 29 | * Class: t_bncCore
|
|---|
| 30 | *
|
|---|
| 31 | * Purpose: This class implements the main application
|
|---|
| 32 | *
|
|---|
| 33 | * Author: L. Mervart
|
|---|
| 34 | *
|
|---|
| 35 | * Created: 29-Aug-2006
|
|---|
| 36 | *
|
|---|
| 37 | * Changes:
|
|---|
| 38 | *
|
|---|
| 39 | * -----------------------------------------------------------------------*/
|
|---|
| 40 |
|
|---|
| 41 | #include <iostream>
|
|---|
| 42 | #include <QMessageBox>
|
|---|
| 43 | #include <cmath>
|
|---|
| 44 |
|
|---|
| 45 | #include "bnccore.h"
|
|---|
| 46 | #include "bncutils.h"
|
|---|
| 47 | #include "bncrinex.h"
|
|---|
| 48 | #include "bncsettings.h"
|
|---|
| 49 | #include "bncversion.h"
|
|---|
| 50 | #include "ephemeris.h"
|
|---|
| 51 | #include "rinex/rnxobsfile.h"
|
|---|
| 52 | #include "rinex/rnxnavfile.h"
|
|---|
| 53 | #include "pppMain.h"
|
|---|
| 54 |
|
|---|
| 55 | #ifdef USE_COMBINATION
|
|---|
| 56 | # include "combination/bnccomb.h"
|
|---|
| 57 | #endif
|
|---|
| 58 |
|
|---|
| 59 | using namespace std;
|
|---|
| 60 |
|
|---|
| 61 | // Singleton
|
|---|
| 62 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 63 | t_bncCore* t_bncCore::instance() {
|
|---|
| 64 | static t_bncCore _bncCore;
|
|---|
| 65 | return &_bncCore;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | // Constructor
|
|---|
| 69 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 70 | t_bncCore::t_bncCore() {
|
|---|
| 71 | _GUIenabled = true;
|
|---|
| 72 | _logFileFlag = 0;
|
|---|
| 73 | _logFile = 0;
|
|---|
| 74 | _logStream = 0;
|
|---|
| 75 | _rawFile = 0;
|
|---|
| 76 | _caster = 0;
|
|---|
| 77 | #ifdef USE_COMBINATION
|
|---|
| 78 | _bncComb = 0;
|
|---|
| 79 | #endif
|
|---|
| 80 |
|
|---|
| 81 | // Lists of Ephemeris
|
|---|
| 82 | // ------------------
|
|---|
| 83 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
|---|
| 84 | _gpsEph[ii-PRN_GPS_START] = 0;
|
|---|
| 85 | }
|
|---|
| 86 | for (int ii = PRN_QZSS_START; ii <= PRN_QZSS_END; ii++) {
|
|---|
| 87 | _qzssEph[ii-PRN_QZSS_START] = 0;
|
|---|
| 88 | }
|
|---|
| 89 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
|---|
| 90 | _glonassEph[ii-PRN_GLONASS_START] = 0;
|
|---|
| 91 | }
|
|---|
| 92 | for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
|
|---|
| 93 | _galileoEph[ii-PRN_GALILEO_START] = 0;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | // Eph file(s)
|
|---|
| 97 | // -----------
|
|---|
| 98 | _rinexVers = 0;
|
|---|
| 99 | _ephFileGPS = 0;
|
|---|
| 100 | _ephStreamGPS = 0;
|
|---|
| 101 | _ephFileGlonass = 0;
|
|---|
| 102 | _ephStreamGlonass = 0;
|
|---|
| 103 | _ephFileGalileo = 0;
|
|---|
| 104 | _ephStreamGalileo = 0;
|
|---|
| 105 |
|
|---|
| 106 | _port = 0;
|
|---|
| 107 | _server = 0;
|
|---|
| 108 | _sockets = 0;
|
|---|
| 109 |
|
|---|
| 110 | _portCorr = 0;
|
|---|
| 111 | _serverCorr = 0;
|
|---|
| 112 | _socketsCorr = 0;
|
|---|
| 113 |
|
|---|
| 114 | _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
|
|---|
| 115 | #ifdef WIN32
|
|---|
| 116 | _userName = QString("${USERNAME}");
|
|---|
| 117 | #else
|
|---|
| 118 | _userName = QString("${USER}");
|
|---|
| 119 | #endif
|
|---|
| 120 | expandEnvVar(_userName);
|
|---|
| 121 |
|
|---|
| 122 | _userName = _userName.leftJustified(20, ' ', true);
|
|---|
| 123 | _dateAndTimeGPS = 0;
|
|---|
| 124 | _mainWindow = 0;
|
|---|
| 125 |
|
|---|
| 126 | _pppMain = new BNC_PPP::t_pppMain();
|
|---|
| 127 | qRegisterMetaType< QVector<double> >("QVector<double>");
|
|---|
| 128 | qRegisterMetaType<bncTime>("bncTime");
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | // Destructor
|
|---|
| 132 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 133 | t_bncCore::~t_bncCore() {
|
|---|
| 134 | delete _logStream;
|
|---|
| 135 | delete _logFile;
|
|---|
| 136 | delete _ephStreamGPS;
|
|---|
| 137 | delete _ephFileGPS;
|
|---|
| 138 | delete _server;
|
|---|
| 139 | delete _sockets;
|
|---|
| 140 | delete _serverCorr;
|
|---|
| 141 | delete _socketsCorr;
|
|---|
| 142 | if (_rinexVers == 2) {
|
|---|
| 143 | delete _ephStreamGlonass;
|
|---|
| 144 | delete _ephFileGlonass;
|
|---|
| 145 | }
|
|---|
| 146 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
|---|
| 147 | delete _gpsEph[ii-PRN_GPS_START];
|
|---|
| 148 | }
|
|---|
| 149 | for (int ii = PRN_QZSS_START; ii <= PRN_QZSS_END; ii++) {
|
|---|
| 150 | delete _qzssEph[ii-PRN_QZSS_START];
|
|---|
| 151 | }
|
|---|
| 152 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
|---|
| 153 | delete _glonassEph[ii-PRN_GLONASS_START];
|
|---|
| 154 | }
|
|---|
| 155 | for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
|
|---|
| 156 | delete _galileoEph[ii-PRN_GALILEO_START];
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | delete _dateAndTimeGPS;
|
|---|
| 160 | delete _rawFile;
|
|---|
| 161 |
|
|---|
| 162 | #ifdef USE_COMBINATION
|
|---|
| 163 | delete _bncComb;
|
|---|
| 164 | #endif
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | // Write a Program Message
|
|---|
| 168 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 169 | void t_bncCore::slotMessage(QByteArray msg, bool showOnScreen) {
|
|---|
| 170 |
|
|---|
| 171 | QMutexLocker locker(&_mutexMessage);
|
|---|
| 172 |
|
|---|
| 173 | messagePrivate(msg);
|
|---|
| 174 | emit newMessage(msg, showOnScreen);
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | // Write a Program Message (private, no lock)
|
|---|
| 178 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 179 | void t_bncCore::messagePrivate(const QByteArray& msg) {
|
|---|
| 180 |
|
|---|
| 181 | // First time resolve the log file name
|
|---|
| 182 | // ------------------------------------
|
|---|
| 183 | QDate currDate = currentDateAndTimeGPS().date();
|
|---|
| 184 | if (_logFileFlag == 0 || _fileDate != currDate) {
|
|---|
| 185 | delete _logStream; _logStream = 0;
|
|---|
| 186 | delete _logFile; _logFile = 0;
|
|---|
| 187 | _logFileFlag = 1;
|
|---|
| 188 | bncSettings settings;
|
|---|
| 189 | QString logFileName = settings.value("logFile").toString();
|
|---|
| 190 | if ( !logFileName.isEmpty() ) {
|
|---|
| 191 | expandEnvVar(logFileName);
|
|---|
| 192 | _logFile = new QFile(logFileName + "_" +
|
|---|
| 193 | currDate.toString("yyMMdd").toAscii().data());
|
|---|
| 194 | _fileDate = currDate;
|
|---|
| 195 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
|---|
| 196 | _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
|---|
| 197 | }
|
|---|
| 198 | else {
|
|---|
| 199 | _logFile->open(QIODevice::WriteOnly);
|
|---|
| 200 | }
|
|---|
| 201 | _logStream = new QTextStream();
|
|---|
| 202 | _logStream->setDevice(_logFile);
|
|---|
| 203 | }
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | if (_logStream) {
|
|---|
| 207 | QByteArray msgLocal = msg;
|
|---|
| 208 | if (msg.indexOf('\n') == 0) {
|
|---|
| 209 | *_logStream << endl;
|
|---|
| 210 | msgLocal = msg.mid(1);
|
|---|
| 211 | }
|
|---|
| 212 | *_logStream << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
|
|---|
| 213 | *_logStream << msgLocal.data() << endl;
|
|---|
| 214 | _logStream->flush();
|
|---|
| 215 | _logFile->flush();
|
|---|
| 216 | }
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | // New GPS Ephemeris
|
|---|
| 220 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 221 | void t_bncCore::slotNewGPSEph(gpsephemeris* gpseph) {
|
|---|
| 222 |
|
|---|
| 223 | QMutexLocker locker(&_mutex);
|
|---|
| 224 |
|
|---|
| 225 | gpsephemeris copy_gpseph = *gpseph;
|
|---|
| 226 | emit newEphGPS(copy_gpseph);
|
|---|
| 227 |
|
|---|
| 228 | printEphHeader();
|
|---|
| 229 |
|
|---|
| 230 | gpsephemeris** ee = &_gpsEph[gpseph->satellite-1];
|
|---|
| 231 | if (PRN_GPS_START <= gpseph->satellite && gpseph->satellite <= PRN_GPS_END) {
|
|---|
| 232 | ee = &_gpsEph[gpseph->satellite - PRN_GPS_START];
|
|---|
| 233 | }
|
|---|
| 234 | else if (PRN_QZSS_START <= gpseph->satellite && gpseph->satellite <= PRN_QZSS_END) {
|
|---|
| 235 | ee = &_qzssEph[gpseph->satellite - PRN_QZSS_START];
|
|---|
| 236 | }
|
|---|
| 237 |
|
|---|
| 238 | if ( *ee != 0 && gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC == (*ee)->TOC ) {
|
|---|
| 239 | checkEphemeris(*ee, gpseph);
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | if ( *ee == 0 ||
|
|---|
| 243 | gpseph->GPSweek > (*ee)->GPSweek ||
|
|---|
| 244 | (gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC > (*ee)->TOC) ) {
|
|---|
| 245 | delete *ee;
|
|---|
| 246 | *ee = gpseph;
|
|---|
| 247 | printGPSEph(gpseph, true);
|
|---|
| 248 | }
|
|---|
| 249 | else {
|
|---|
| 250 | printGPSEph(gpseph, false);
|
|---|
| 251 | delete gpseph;
|
|---|
| 252 | }
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | // New Glonass Ephemeris
|
|---|
| 256 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 257 | void t_bncCore::slotNewGlonassEph(glonassephemeris* glonasseph, const QString& staID) {
|
|---|
| 258 |
|
|---|
| 259 | QMutexLocker locker(&_mutex);
|
|---|
| 260 |
|
|---|
| 261 | // Check wrong Ephemerides
|
|---|
| 262 | // -----------------------
|
|---|
| 263 | if (glonasseph->x_pos == 0.0 &&
|
|---|
| 264 | glonasseph->y_pos == 0.0 &&
|
|---|
| 265 | glonasseph->z_pos == 0.0) {
|
|---|
| 266 | delete glonasseph;
|
|---|
| 267 | return;
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | glonassephemeris copy_glonasseph = *glonasseph;
|
|---|
| 271 | emit newEphGlonass(copy_glonasseph);
|
|---|
| 272 |
|
|---|
| 273 | printEphHeader();
|
|---|
| 274 |
|
|---|
| 275 | glonassephemeris** ee = &_glonassEph[glonasseph->almanac_number-1];
|
|---|
| 276 |
|
|---|
| 277 | int wwOld, towOld, wwNew, towNew;
|
|---|
| 278 | if (*ee != 0) {
|
|---|
| 279 | wwOld = (*ee)->GPSWeek;
|
|---|
| 280 | towOld = (*ee)->GPSTOW;
|
|---|
| 281 | updatetime(&wwOld, &towOld, (*ee)->tb*1000, 0); // Moscow -> GPS
|
|---|
| 282 |
|
|---|
| 283 | wwNew = glonasseph->GPSWeek;
|
|---|
| 284 | towNew = glonasseph->GPSTOW;
|
|---|
| 285 | updatetime(&wwNew, &towNew, glonasseph->tb*1000, 0); // Moscow -> GPS
|
|---|
| 286 | }
|
|---|
| 287 |
|
|---|
| 288 | if ( *ee == 0 ||
|
|---|
| 289 | wwNew > wwOld ||
|
|---|
| 290 | (wwNew == wwOld && towNew > towOld) ) {
|
|---|
| 291 | delete *ee;
|
|---|
| 292 | *ee = glonasseph;
|
|---|
| 293 | printGlonassEph(glonasseph, true, staID);
|
|---|
| 294 | }
|
|---|
| 295 | else {
|
|---|
| 296 | printGlonassEph(glonasseph, false, staID);
|
|---|
| 297 | delete glonasseph;
|
|---|
| 298 | }
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | // New Galileo Ephemeris
|
|---|
| 302 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 303 | void t_bncCore::slotNewGalileoEph(galileoephemeris* galileoeph) {
|
|---|
| 304 |
|
|---|
| 305 | QMutexLocker locker(&_mutex);
|
|---|
| 306 |
|
|---|
| 307 | galileoephemeris copy_galileoeph = *galileoeph;
|
|---|
| 308 | emit newEphGalileo(copy_galileoeph);
|
|---|
| 309 |
|
|---|
| 310 | printEphHeader();
|
|---|
| 311 |
|
|---|
| 312 | int galIndex = galileoeph->satellite;
|
|---|
| 313 | /* GIOVE */
|
|---|
| 314 | if(galIndex == 51) galIndex = 1;
|
|---|
| 315 | else if(galIndex == 52) galIndex = 16;
|
|---|
| 316 | if (galIndex < 0 || galIndex > PRN_GALILEO_END - PRN_GALILEO_START) {
|
|---|
| 317 | emit( newMessage("Wrong Galileo Satellite Number", true) );
|
|---|
| 318 | exit(1);
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | galileoephemeris** ee = &_galileoEph[galIndex];
|
|---|
| 322 |
|
|---|
| 323 | if ( *ee == 0 ||
|
|---|
| 324 | galileoeph->Week > (*ee)->Week ||
|
|---|
| 325 | (galileoeph->Week == (*ee)->Week && galileoeph->TOC > (*ee)->TOC) ) {
|
|---|
| 326 | delete *ee;
|
|---|
| 327 | *ee = galileoeph;
|
|---|
| 328 | printGalileoEph(galileoeph, true);
|
|---|
| 329 | }
|
|---|
| 330 | else {
|
|---|
| 331 | printGalileoEph(galileoeph, false);
|
|---|
| 332 | delete galileoeph;
|
|---|
| 333 | }
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|
| 336 | // Print Header of the output File(s)
|
|---|
| 337 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 338 | void t_bncCore::printEphHeader() {
|
|---|
| 339 |
|
|---|
| 340 | bncSettings settings;
|
|---|
| 341 |
|
|---|
| 342 | // Initialization
|
|---|
| 343 | // --------------
|
|---|
| 344 | if (_rinexVers == 0) {
|
|---|
| 345 |
|
|---|
| 346 | if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
|
|---|
| 347 | _rinexVers = 3;
|
|---|
| 348 | }
|
|---|
| 349 | else {
|
|---|
| 350 | _rinexVers = 2;
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | _ephPath = settings.value("ephPath").toString();
|
|---|
| 354 |
|
|---|
| 355 | if ( !_ephPath.isEmpty() ) {
|
|---|
| 356 | if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
|
|---|
| 357 | _ephPath += QDir::separator();
|
|---|
| 358 | }
|
|---|
| 359 | expandEnvVar(_ephPath);
|
|---|
| 360 | }
|
|---|
| 361 | }
|
|---|
| 362 |
|
|---|
| 363 | // (Re-)Open output File(s)
|
|---|
| 364 | // ------------------------
|
|---|
| 365 | if (!_ephPath.isEmpty()) {
|
|---|
| 366 |
|
|---|
| 367 | QDateTime datTim = currentDateAndTimeGPS();
|
|---|
| 368 |
|
|---|
| 369 | QString ephFileNameGPS = _ephPath + "BRDC" +
|
|---|
| 370 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'));
|
|---|
| 371 |
|
|---|
| 372 | QString hlpStr = bncRinex::nextEpochStr(datTim,
|
|---|
| 373 | settings.value("ephIntr").toString());
|
|---|
| 374 |
|
|---|
| 375 | if (_rinexVers == 3) {
|
|---|
| 376 | ephFileNameGPS += hlpStr + datTim.toString(".yyP");
|
|---|
| 377 | }
|
|---|
| 378 | else {
|
|---|
| 379 | ephFileNameGPS += hlpStr + datTim.toString(".yyN");
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 | if (_ephFileNameGPS == ephFileNameGPS) {
|
|---|
| 383 | return;
|
|---|
| 384 | }
|
|---|
| 385 | else {
|
|---|
| 386 | _ephFileNameGPS = ephFileNameGPS;
|
|---|
| 387 | }
|
|---|
| 388 |
|
|---|
| 389 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
|---|
| 390 | delete _gpsEph[ii-PRN_GPS_START];
|
|---|
| 391 | _gpsEph[ii-PRN_GPS_START] = 0;
|
|---|
| 392 | }
|
|---|
| 393 | for (int ii = PRN_QZSS_START; ii <= PRN_QZSS_END; ii++) {
|
|---|
| 394 | delete _qzssEph[ii-PRN_QZSS_START];
|
|---|
| 395 | _qzssEph[ii-PRN_QZSS_START] = 0;
|
|---|
| 396 | }
|
|---|
| 397 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
|---|
| 398 | delete _glonassEph[ii-PRN_GLONASS_START];
|
|---|
| 399 | _glonassEph[ii-PRN_GLONASS_START] = 0;
|
|---|
| 400 | }
|
|---|
| 401 | for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
|
|---|
| 402 | delete _galileoEph[ii-PRN_GALILEO_START];
|
|---|
| 403 | _galileoEph[ii-PRN_GALILEO_START] = 0;
|
|---|
| 404 | }
|
|---|
| 405 |
|
|---|
| 406 | delete _ephStreamGPS;
|
|---|
| 407 | delete _ephFileGPS;
|
|---|
| 408 |
|
|---|
| 409 | QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
|
|---|
| 410 | QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
|
|---|
| 411 | QFlags<QIODevice::OpenModeFlag> appendFlagGalileo;
|
|---|
| 412 |
|
|---|
| 413 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
|---|
| 414 | QFile::exists(ephFileNameGPS) ) {
|
|---|
| 415 | appendFlagGPS = QIODevice::Append;
|
|---|
| 416 | }
|
|---|
| 417 |
|
|---|
| 418 | _ephFileGPS = new QFile(ephFileNameGPS);
|
|---|
| 419 | _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
|
|---|
| 420 | _ephStreamGPS = new QTextStream();
|
|---|
| 421 | _ephStreamGPS->setDevice(_ephFileGPS);
|
|---|
| 422 |
|
|---|
| 423 | if (_rinexVers == 3) {
|
|---|
| 424 | _ephFileGlonass = _ephFileGPS;
|
|---|
| 425 | _ephStreamGlonass = _ephStreamGPS;
|
|---|
| 426 | _ephFileGalileo = _ephFileGPS;
|
|---|
| 427 | _ephStreamGalileo = _ephStreamGPS;
|
|---|
| 428 | }
|
|---|
| 429 | else if (_rinexVers == 2) {
|
|---|
| 430 | QString ephFileNameGlonass = _ephPath + "BRDC" +
|
|---|
| 431 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
|---|
| 432 | hlpStr + datTim.toString(".yyG");
|
|---|
| 433 |
|
|---|
| 434 | delete _ephStreamGlonass;
|
|---|
| 435 | delete _ephFileGlonass;
|
|---|
| 436 |
|
|---|
| 437 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
|---|
| 438 | QFile::exists(ephFileNameGlonass) ) {
|
|---|
| 439 | appendFlagGlonass = QIODevice::Append;
|
|---|
| 440 | }
|
|---|
| 441 |
|
|---|
| 442 | _ephFileGlonass = new QFile(ephFileNameGlonass);
|
|---|
| 443 | _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
|
|---|
| 444 | _ephStreamGlonass = new QTextStream();
|
|---|
| 445 | _ephStreamGlonass->setDevice(_ephFileGlonass);
|
|---|
| 446 | }
|
|---|
| 447 |
|
|---|
| 448 | // Header - RINEX Version 3
|
|---|
| 449 | // ------------------------
|
|---|
| 450 | if (_rinexVers == 3) {
|
|---|
| 451 | if ( ! (appendFlagGPS & QIODevice::Append)) {
|
|---|
| 452 | QString line;
|
|---|
| 453 | line.sprintf(
|
|---|
| 454 | "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
|
|---|
| 455 | 3.0, "", "");
|
|---|
| 456 | *_ephStreamGPS << line;
|
|---|
| 457 |
|
|---|
| 458 | QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
|
|---|
| 459 | *_ephStreamGPS << _pgmName.toAscii().data()
|
|---|
| 460 | << _userName.toAscii().data()
|
|---|
| 461 | << hlp.toAscii().data()
|
|---|
| 462 | << "PGM / RUN BY / DATE" << endl;
|
|---|
| 463 |
|
|---|
| 464 | line.sprintf("%60sEND OF HEADER\n", "");
|
|---|
| 465 | *_ephStreamGPS << line;
|
|---|
| 466 |
|
|---|
| 467 | _ephStreamGPS->flush();
|
|---|
| 468 | }
|
|---|
| 469 | }
|
|---|
| 470 |
|
|---|
| 471 | // Headers - RINEX Version 2
|
|---|
| 472 | // -------------------------
|
|---|
| 473 | else if (_rinexVers == 2) {
|
|---|
| 474 | if (! (appendFlagGPS & QIODevice::Append)) {
|
|---|
| 475 | QString line;
|
|---|
| 476 | line.sprintf("%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n",
|
|---|
| 477 | t_rnxNavFile::defaultRnxNavVersion2, "", "");
|
|---|
| 478 | *_ephStreamGPS << line;
|
|---|
| 479 |
|
|---|
| 480 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
|---|
| 481 | *_ephStreamGPS << _pgmName.toAscii().data()
|
|---|
| 482 | << _userName.toAscii().data()
|
|---|
| 483 | << hlp.toAscii().data()
|
|---|
| 484 | << "PGM / RUN BY / DATE" << endl;
|
|---|
| 485 |
|
|---|
| 486 | line.sprintf("%60sEND OF HEADER\n", "");
|
|---|
| 487 | *_ephStreamGPS << line;
|
|---|
| 488 |
|
|---|
| 489 | _ephStreamGPS->flush();
|
|---|
| 490 | }
|
|---|
| 491 | if (! (appendFlagGlonass & QIODevice::Append)) {
|
|---|
| 492 | QString line;
|
|---|
| 493 | line.sprintf("%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",
|
|---|
| 494 | t_rnxNavFile::defaultRnxNavVersion2, "", "");
|
|---|
| 495 | *_ephStreamGlonass << line;
|
|---|
| 496 |
|
|---|
| 497 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
|---|
| 498 | *_ephStreamGlonass << _pgmName.toAscii().data()
|
|---|
| 499 | << _userName.toAscii().data()
|
|---|
| 500 | << hlp.toAscii().data()
|
|---|
| 501 | << "PGM / RUN BY / DATE" << endl;
|
|---|
| 502 |
|
|---|
| 503 | line.sprintf("%60sEND OF HEADER\n", "");
|
|---|
| 504 | *_ephStreamGlonass << line;
|
|---|
| 505 |
|
|---|
| 506 | _ephStreamGlonass->flush();
|
|---|
| 507 | }
|
|---|
| 508 | }
|
|---|
| 509 | }
|
|---|
| 510 | }
|
|---|
| 511 |
|
|---|
| 512 | // Print One GPS Ephemeris
|
|---|
| 513 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 514 | void t_bncCore::printGPSEph(gpsephemeris* ep, bool printFile) {
|
|---|
| 515 |
|
|---|
| 516 | t_ephGPS eph;
|
|---|
| 517 | eph.set(ep);
|
|---|
| 518 |
|
|---|
| 519 | QString strV2 = eph.toString(t_rnxNavFile::defaultRnxNavVersion2);
|
|---|
| 520 | QString strV3 = eph.toString(t_rnxObsHeader::defaultRnxObsVersion3);
|
|---|
| 521 |
|
|---|
| 522 | printOutput(printFile, _ephStreamGPS, strV2, strV3);
|
|---|
| 523 | }
|
|---|
| 524 |
|
|---|
| 525 | // Print One Glonass Ephemeris
|
|---|
| 526 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 527 | void t_bncCore::printGlonassEph(glonassephemeris* ep, bool printFile, const QString& /* staID */) {
|
|---|
| 528 |
|
|---|
| 529 | t_ephGlo eph;
|
|---|
| 530 | eph.set(ep);
|
|---|
| 531 |
|
|---|
| 532 | QString strV2 = eph.toString(t_rnxNavFile::defaultRnxNavVersion2);
|
|---|
| 533 | QString strV3 = eph.toString(t_rnxObsHeader::defaultRnxObsVersion3);
|
|---|
| 534 |
|
|---|
| 535 | //// beg test Dirk
|
|---|
| 536 | // QString hlp = strV2;
|
|---|
| 537 | // cout << hlp.replace('\n', ' ').toAscii().data() << ' ' << staID.toAscii().data() << endl;
|
|---|
| 538 | //// end test Dirk
|
|---|
| 539 |
|
|---|
| 540 | printOutput(printFile, _ephStreamGlonass, strV2, strV3);
|
|---|
| 541 | }
|
|---|
| 542 |
|
|---|
| 543 | // Print One Galileo Ephemeris
|
|---|
| 544 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 545 | void t_bncCore::printGalileoEph(galileoephemeris* ep, bool printFile) {
|
|---|
| 546 |
|
|---|
| 547 | t_ephGal eph;
|
|---|
| 548 | eph.set(ep);
|
|---|
| 549 |
|
|---|
| 550 | QString strV2 = eph.toString(t_rnxNavFile::defaultRnxNavVersion2);
|
|---|
| 551 | QString strV3 = eph.toString(t_rnxObsHeader::defaultRnxObsVersion3);
|
|---|
| 552 |
|
|---|
| 553 | printOutput(printFile, _ephStreamGalileo, strV2, strV3);
|
|---|
| 554 | }
|
|---|
| 555 |
|
|---|
| 556 | // Output
|
|---|
| 557 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 558 | void t_bncCore::printOutput(bool printFile, QTextStream* stream,
|
|---|
| 559 | const QString& strV2, const QString& strV3) {
|
|---|
| 560 |
|
|---|
| 561 | // Output into file
|
|---|
| 562 | // ----------------
|
|---|
| 563 | if (printFile && stream) {
|
|---|
| 564 | if (_rinexVers == 2) {
|
|---|
| 565 | *stream << strV2.toAscii();
|
|---|
| 566 | }
|
|---|
| 567 | else {
|
|---|
| 568 | *stream << strV3.toAscii();
|
|---|
| 569 | }
|
|---|
| 570 | stream->flush();
|
|---|
| 571 | }
|
|---|
| 572 |
|
|---|
| 573 | // Output into the socket
|
|---|
| 574 | // ----------------------
|
|---|
| 575 | if (_sockets) {
|
|---|
| 576 | QMutableListIterator<QTcpSocket*> is(*_sockets);
|
|---|
| 577 | while (is.hasNext()) {
|
|---|
| 578 | QTcpSocket* sock = is.next();
|
|---|
| 579 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
|---|
| 580 | if (sock->write(strV3.toAscii()) == -1) {
|
|---|
| 581 | delete sock;
|
|---|
| 582 | is.remove();
|
|---|
| 583 | }
|
|---|
| 584 | }
|
|---|
| 585 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
|---|
| 586 | delete sock;
|
|---|
| 587 | is.remove();
|
|---|
| 588 | }
|
|---|
| 589 | }
|
|---|
| 590 | }
|
|---|
| 591 | }
|
|---|
| 592 |
|
|---|
| 593 | // Set Port Number
|
|---|
| 594 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 595 | void t_bncCore::setPort(int port) {
|
|---|
| 596 | _port = port;
|
|---|
| 597 | if (_port != 0) {
|
|---|
| 598 | delete _server;
|
|---|
| 599 | _server = new QTcpServer;
|
|---|
| 600 | if ( !_server->listen(QHostAddress::Any, _port) ) {
|
|---|
| 601 | slotMessage("t_bncCore: Cannot listen on ephemeris port", true);
|
|---|
| 602 | }
|
|---|
| 603 | connect(_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
|
|---|
| 604 | delete _sockets;
|
|---|
| 605 | _sockets = new QList<QTcpSocket*>;
|
|---|
| 606 | }
|
|---|
| 607 | }
|
|---|
| 608 |
|
|---|
| 609 | // Set Port Number
|
|---|
| 610 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 611 | void t_bncCore::setPortCorr(int port) {
|
|---|
| 612 | _portCorr = port;
|
|---|
| 613 | if (_portCorr != 0) {
|
|---|
| 614 | delete _serverCorr;
|
|---|
| 615 | _serverCorr = new QTcpServer;
|
|---|
| 616 | if ( !_serverCorr->listen(QHostAddress::Any, _portCorr) ) {
|
|---|
| 617 | slotMessage("t_bncCore: Cannot listen on correction port", true);
|
|---|
| 618 | }
|
|---|
| 619 | connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
|
|---|
| 620 | delete _socketsCorr;
|
|---|
| 621 | _socketsCorr = new QList<QTcpSocket*>;
|
|---|
| 622 | }
|
|---|
| 623 | }
|
|---|
| 624 |
|
|---|
| 625 | // New Connection
|
|---|
| 626 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 627 | void t_bncCore::slotNewConnection() {
|
|---|
| 628 | _sockets->push_back( _server->nextPendingConnection() );
|
|---|
| 629 | }
|
|---|
| 630 |
|
|---|
| 631 | // New Connection
|
|---|
| 632 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 633 | void t_bncCore::slotNewConnectionCorr() {
|
|---|
| 634 | _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
|
|---|
| 635 | }
|
|---|
| 636 |
|
|---|
| 637 | //
|
|---|
| 638 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 639 | void t_bncCore::slotQuit() {
|
|---|
| 640 | delete _caster; _caster = 0;
|
|---|
| 641 | qApp->quit();
|
|---|
| 642 | }
|
|---|
| 643 |
|
|---|
| 644 | //
|
|---|
| 645 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 646 | void t_bncCore::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
|
|---|
| 647 | QMutexLocker locker(&_mutex);
|
|---|
| 648 | emit newOrbCorrections(orbCorrections);
|
|---|
| 649 | if (_socketsCorr) {
|
|---|
| 650 | QListIterator<t_orbCorr> it(orbCorrections);
|
|---|
| 651 | while (it.hasNext()) {
|
|---|
| 652 | const t_orbCorr& corr = it.next();
|
|---|
| 653 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
|---|
| 654 | while (is.hasNext()) {
|
|---|
| 655 | QTcpSocket* sock = is.next();
|
|---|
| 656 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
|---|
| 657 | if (sock->write(corr.toLine().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 | }
|
|---|
| 668 | }
|
|---|
| 669 | }
|
|---|
| 670 |
|
|---|
| 671 | //
|
|---|
| 672 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 673 | void t_bncCore::slotNewClkCorrections(QList<t_clkCorr> clkCorrections) {
|
|---|
| 674 | QMutexLocker locker(&_mutex);
|
|---|
| 675 | emit newClkCorrections(clkCorrections);
|
|---|
| 676 | if (_socketsCorr) {
|
|---|
| 677 | QListIterator<t_clkCorr> it(clkCorrections);
|
|---|
| 678 | while (it.hasNext()) {
|
|---|
| 679 | const t_clkCorr& corr = it.next();
|
|---|
| 680 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
|---|
| 681 | while (is.hasNext()) {
|
|---|
| 682 | QTcpSocket* sock = is.next();
|
|---|
| 683 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
|---|
| 684 | if (sock->write(corr.toLine().c_str()) == -1) {
|
|---|
| 685 | delete sock;
|
|---|
| 686 | is.remove();
|
|---|
| 687 | }
|
|---|
| 688 | }
|
|---|
| 689 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
|---|
| 690 | delete sock;
|
|---|
| 691 | is.remove();
|
|---|
| 692 | }
|
|---|
| 693 | }
|
|---|
| 694 | }
|
|---|
| 695 | }
|
|---|
| 696 | }
|
|---|
| 697 |
|
|---|
| 698 | //
|
|---|
| 699 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 700 | void t_bncCore::setConfFileName(const QString& confFileName) {
|
|---|
| 701 | if (confFileName.isEmpty()) {
|
|---|
| 702 | _confFileName = QDir::homePath() + QDir::separator()
|
|---|
| 703 | + ".config" + QDir::separator()
|
|---|
| 704 | + qApp->organizationName() + QDir::separator()
|
|---|
| 705 | + qApp->applicationName() + ".bnc";
|
|---|
| 706 | }
|
|---|
| 707 | else {
|
|---|
| 708 | _confFileName = confFileName;
|
|---|
| 709 | }
|
|---|
| 710 | }
|
|---|
| 711 |
|
|---|
| 712 | // Raw Output
|
|---|
| 713 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 714 | void t_bncCore::writeRawData(const QByteArray& data, const QByteArray& staID,
|
|---|
| 715 | const QByteArray& format) {
|
|---|
| 716 |
|
|---|
| 717 | QMutexLocker locker(&_mutex);
|
|---|
| 718 |
|
|---|
| 719 | if (!_rawFile) {
|
|---|
| 720 | bncSettings settings;
|
|---|
| 721 | QByteArray fileName = settings.value("rawOutFile").toByteArray();
|
|---|
| 722 | if (!fileName.isEmpty()) {
|
|---|
| 723 | _rawFile = new bncRawFile(fileName, staID, bncRawFile::output);
|
|---|
| 724 | }
|
|---|
| 725 | }
|
|---|
| 726 |
|
|---|
| 727 | if (_rawFile) {
|
|---|
| 728 | _rawFile->writeRawData(data, staID, format);
|
|---|
| 729 | }
|
|---|
| 730 | }
|
|---|
| 731 |
|
|---|
| 732 | //
|
|---|
| 733 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 734 | void t_bncCore::initCombination() {
|
|---|
| 735 | #ifdef USE_COMBINATION
|
|---|
| 736 | _bncComb = new bncComb();
|
|---|
| 737 | if (_bncComb->nStreams() < 1) {
|
|---|
| 738 | delete _bncComb;
|
|---|
| 739 | _bncComb = 0;
|
|---|
| 740 | }
|
|---|
| 741 | #endif
|
|---|
| 742 | }
|
|---|
| 743 |
|
|---|
| 744 | //
|
|---|
| 745 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 746 | void t_bncCore::stopCombination() {
|
|---|
| 747 | #ifdef USE_COMBINATION
|
|---|
| 748 | delete _bncComb;
|
|---|
| 749 | _bncComb = 0;
|
|---|
| 750 | #endif
|
|---|
| 751 | }
|
|---|
| 752 |
|
|---|
| 753 | // Check Ephemeris Consistency
|
|---|
| 754 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 755 | void t_bncCore::checkEphemeris(gpsephemeris* oldEph, gpsephemeris* newEph) {
|
|---|
| 756 | if (oldEph->clock_bias != newEph->clock_bias ||
|
|---|
| 757 | oldEph->clock_drift != newEph->clock_drift ||
|
|---|
| 758 | oldEph->clock_driftrate != newEph->clock_driftrate) {
|
|---|
| 759 | QString msg = currentDateAndTimeGPS().toString(Qt::ISODate) +
|
|---|
| 760 | QString(" %1 EPH DIFFERS\n").arg(oldEph->satellite);
|
|---|
| 761 | messagePrivate(msg.toAscii());
|
|---|
| 762 | }
|
|---|
| 763 | }
|
|---|
| 764 |
|
|---|
| 765 |
|
|---|
| 766 | //
|
|---|
| 767 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 768 | bool t_bncCore::dateAndTimeGPSSet() const {
|
|---|
| 769 | QMutexLocker locker(&_mutexDateAndTimeGPS);
|
|---|
| 770 | if (_dateAndTimeGPS) {
|
|---|
| 771 | return true;
|
|---|
| 772 | }
|
|---|
| 773 | else {
|
|---|
| 774 | return false;
|
|---|
| 775 | }
|
|---|
| 776 | }
|
|---|
| 777 |
|
|---|
| 778 | //
|
|---|
| 779 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 780 | QDateTime t_bncCore::dateAndTimeGPS() const {
|
|---|
| 781 | QMutexLocker locker(&_mutexDateAndTimeGPS);
|
|---|
| 782 | if (_dateAndTimeGPS) {
|
|---|
| 783 | return *_dateAndTimeGPS;
|
|---|
| 784 | }
|
|---|
| 785 | else {
|
|---|
| 786 | return QDateTime();
|
|---|
| 787 | }
|
|---|
| 788 | }
|
|---|
| 789 |
|
|---|
| 790 | //
|
|---|
| 791 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 792 | void t_bncCore::setDateAndTimeGPS(QDateTime dateTime) {
|
|---|
| 793 | QMutexLocker locker(&_mutexDateAndTimeGPS);
|
|---|
| 794 | delete _dateAndTimeGPS;
|
|---|
| 795 | _dateAndTimeGPS = new QDateTime(dateTime);
|
|---|
| 796 | }
|
|---|
| 797 |
|
|---|
| 798 | //
|
|---|
| 799 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 800 | void t_bncCore::startPPP() {
|
|---|
| 801 | _pppMain->start();
|
|---|
| 802 | }
|
|---|
| 803 |
|
|---|
| 804 | //
|
|---|
| 805 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 806 | void t_bncCore::stopPPP() {
|
|---|
| 807 | _pppMain->stop();
|
|---|
| 808 | emit stopRinexPPP();
|
|---|
| 809 | }
|
|---|