| 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_pgmCore
|
|---|
| 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 "RTCM3/ephemeris.h"
|
|---|
| 51 |
|
|---|
| 52 | #ifdef USE_COMBINATION
|
|---|
| 53 | #include "combination/bnccomb.h"
|
|---|
| 54 | #endif
|
|---|
| 55 |
|
|---|
| 56 | using namespace std;
|
|---|
| 57 |
|
|---|
| 58 | // Constructor
|
|---|
| 59 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 60 | t_pgmCore::t_pgmCore(int& argc, char* argv[], bool GUIenabled) {
|
|---|
| 61 | _GUIenabled = GUIenabled;
|
|---|
| 62 | _logFileFlag = 0;
|
|---|
| 63 | _logFile = 0;
|
|---|
| 64 | _logStream = 0;
|
|---|
| 65 | _caster = 0;
|
|---|
| 66 | _rawFile = 0;
|
|---|
| 67 | #ifdef USE_COMBINATION
|
|---|
| 68 | _bncComb = 0;
|
|---|
| 69 | #endif
|
|---|
| 70 |
|
|---|
| 71 | // Lists of Ephemeris
|
|---|
| 72 | // ------------------
|
|---|
| 73 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
|---|
| 74 | _gpsEph[ii-PRN_GPS_START] = 0;
|
|---|
| 75 | }
|
|---|
| 76 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
|---|
| 77 | _glonassEph[ii-PRN_GLONASS_START] = 0;
|
|---|
| 78 | }
|
|---|
| 79 | for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
|
|---|
| 80 | _galileoEph[ii-PRN_GALILEO_START] = 0;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | // Eph file(s)
|
|---|
| 84 | // -----------
|
|---|
| 85 | _rinexVers = 0;
|
|---|
| 86 | _ephFileGPS = 0;
|
|---|
| 87 | _ephStreamGPS = 0;
|
|---|
| 88 | _ephFileGlonass = 0;
|
|---|
| 89 | _ephStreamGlonass = 0;
|
|---|
| 90 | _ephFileGalileo = 0;
|
|---|
| 91 | _ephStreamGalileo = 0;
|
|---|
| 92 |
|
|---|
| 93 | _port = 0;
|
|---|
| 94 | _server = 0;
|
|---|
| 95 | _sockets = 0;
|
|---|
| 96 |
|
|---|
| 97 | _portCorr = 0;
|
|---|
| 98 | _serverCorr = 0;
|
|---|
| 99 | _socketsCorr = 0;
|
|---|
| 100 |
|
|---|
| 101 | _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
|
|---|
| 102 | #ifdef WIN32
|
|---|
| 103 | _userName = QString("${USERNAME}");
|
|---|
| 104 | #else
|
|---|
| 105 | _userName = QString("${USER}");
|
|---|
| 106 | #endif
|
|---|
| 107 | expandEnvVar(_userName);
|
|---|
| 108 | _userName = _userName.leftJustified(20, ' ', true);
|
|---|
| 109 |
|
|---|
| 110 | _lastDumpCoSec = 0;
|
|---|
| 111 |
|
|---|
| 112 | _corrs = new QMultiMap<long, QString>;
|
|---|
| 113 |
|
|---|
| 114 | _currentDateAndTimeGPS = 0;
|
|---|
| 115 |
|
|---|
| 116 | for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
|
|---|
| 117 | _GLOFreq[ii] = 0;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | _bncPPPclient = 0;
|
|---|
| 121 |
|
|---|
| 122 | _mainWindow = 0;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | // Destructor
|
|---|
| 126 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 127 | t_pgmCore::~t_pgmCore() {
|
|---|
| 128 | delete _logStream;
|
|---|
| 129 | delete _logFile;
|
|---|
| 130 | delete _ephStreamGPS;
|
|---|
| 131 | delete _ephFileGPS;
|
|---|
| 132 | delete _server;
|
|---|
| 133 | delete _sockets;
|
|---|
| 134 | delete _serverCorr;
|
|---|
| 135 | delete _socketsCorr;
|
|---|
| 136 | if (_rinexVers == 2) {
|
|---|
| 137 | delete _ephStreamGlonass;
|
|---|
| 138 | delete _ephFileGlonass;
|
|---|
| 139 | }
|
|---|
| 140 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
|---|
| 141 | delete _gpsEph[ii-PRN_GPS_START];
|
|---|
| 142 | }
|
|---|
| 143 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
|---|
| 144 | delete _glonassEph[ii-PRN_GLONASS_START];
|
|---|
| 145 | }
|
|---|
| 146 | for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
|
|---|
| 147 | delete _galileoEph[ii-PRN_GALILEO_START];
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | delete _corrs;
|
|---|
| 151 |
|
|---|
| 152 | delete _currentDateAndTimeGPS;
|
|---|
| 153 |
|
|---|
| 154 | delete _rawFile;
|
|---|
| 155 |
|
|---|
| 156 | #ifdef USE_COMBINATION
|
|---|
| 157 | delete _bncComb;
|
|---|
| 158 | #endif
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | // Write a Program Message
|
|---|
| 162 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 163 | void t_pgmCore::slotMessage(QByteArray msg, bool showOnScreen) {
|
|---|
| 164 |
|
|---|
| 165 | QMutexLocker locker(&_mutexMessage);
|
|---|
| 166 |
|
|---|
| 167 | messagePrivate(msg);
|
|---|
| 168 | emit newMessage(msg, showOnScreen);
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | // Write a Program Message (private, no lock)
|
|---|
| 172 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 173 | void t_pgmCore::messagePrivate(const QByteArray& msg) {
|
|---|
| 174 |
|
|---|
| 175 | // First time resolve the log file name
|
|---|
| 176 | // ------------------------------------
|
|---|
| 177 | QDate currDate = currentDateAndTimeGPS().date();
|
|---|
| 178 | if (_logFileFlag == 0 || _fileDate != currDate) {
|
|---|
| 179 | delete _logStream; _logStream = 0;
|
|---|
| 180 | delete _logFile; _logFile = 0;
|
|---|
| 181 | _logFileFlag = 1;
|
|---|
| 182 | bncSettings settings;
|
|---|
| 183 | QString logFileName = settings.value("logFile").toString();
|
|---|
| 184 | if ( !logFileName.isEmpty() ) {
|
|---|
| 185 | expandEnvVar(logFileName);
|
|---|
| 186 | _logFile = new QFile(logFileName + "_" +
|
|---|
| 187 | currDate.toString("yyMMdd").toAscii().data());
|
|---|
| 188 | _fileDate = currDate;
|
|---|
| 189 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
|---|
| 190 | _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
|---|
| 191 | }
|
|---|
| 192 | else {
|
|---|
| 193 | _logFile->open(QIODevice::WriteOnly);
|
|---|
| 194 | }
|
|---|
| 195 | _logStream = new QTextStream();
|
|---|
| 196 | _logStream->setDevice(_logFile);
|
|---|
| 197 | }
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | if (_logStream) {
|
|---|
| 201 | QByteArray msgLocal = msg;
|
|---|
| 202 | if (msg.indexOf('\n') == 0) {
|
|---|
| 203 | *_logStream << endl;
|
|---|
| 204 | msgLocal = msg.mid(1);
|
|---|
| 205 | }
|
|---|
| 206 | *_logStream << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
|
|---|
| 207 | *_logStream << msgLocal.data() << endl;
|
|---|
| 208 | _logStream->flush();
|
|---|
| 209 | _logFile->flush();
|
|---|
| 210 | }
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | // New GPS Ephemeris
|
|---|
| 214 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 215 | void t_pgmCore::slotNewGPSEph(gpsephemeris* gpseph) {
|
|---|
| 216 |
|
|---|
| 217 | QMutexLocker locker(&_mutex);
|
|---|
| 218 |
|
|---|
| 219 | gpsephemeris copy_gpseph = *gpseph;
|
|---|
| 220 | emit newEphGPS(copy_gpseph);
|
|---|
| 221 |
|
|---|
| 222 | printEphHeader();
|
|---|
| 223 |
|
|---|
| 224 | gpsephemeris** ee = &_gpsEph[gpseph->satellite-1];
|
|---|
| 225 |
|
|---|
| 226 | if ( *ee != 0 &&
|
|---|
| 227 | gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC == (*ee)->TOC ) {
|
|---|
| 228 | checkEphemeris(*ee, gpseph);
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | if ( *ee == 0 ||
|
|---|
| 232 | gpseph->GPSweek > (*ee)->GPSweek ||
|
|---|
| 233 | (gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC > (*ee)->TOC) ) {
|
|---|
| 234 | delete *ee;
|
|---|
| 235 | *ee = gpseph;
|
|---|
| 236 | printGPSEph(gpseph, true);
|
|---|
| 237 | }
|
|---|
| 238 | else {
|
|---|
| 239 | printGPSEph(gpseph, false);
|
|---|
| 240 | delete gpseph;
|
|---|
| 241 | }
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | // New Glonass Ephemeris
|
|---|
| 245 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 246 | void t_pgmCore::slotNewGlonassEph(glonassephemeris* glonasseph) {
|
|---|
| 247 |
|
|---|
| 248 | QMutexLocker locker(&_mutex);
|
|---|
| 249 |
|
|---|
| 250 | // Check wrong Ephemerides
|
|---|
| 251 | // -----------------------
|
|---|
| 252 | if (glonasseph->x_pos == 0.0 &&
|
|---|
| 253 | glonasseph->y_pos == 0.0 &&
|
|---|
| 254 | glonasseph->z_pos == 0.0) {
|
|---|
| 255 | delete glonasseph;
|
|---|
| 256 | return;
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 | glonassephemeris copy_glonasseph = *glonasseph;
|
|---|
| 260 | emit newEphGlonass(copy_glonasseph);
|
|---|
| 261 |
|
|---|
| 262 | printEphHeader();
|
|---|
| 263 |
|
|---|
| 264 | glonassephemeris** ee = &_glonassEph[glonasseph->almanac_number-1];
|
|---|
| 265 |
|
|---|
| 266 | int wwOld, towOld, wwNew, towNew;
|
|---|
| 267 | if (*ee != 0) {
|
|---|
| 268 | wwOld = (*ee)->GPSWeek;
|
|---|
| 269 | towOld = (*ee)->GPSTOW;
|
|---|
| 270 | updatetime(&wwOld, &towOld, (*ee)->tb*1000, 0); // Moscow -> GPS
|
|---|
| 271 |
|
|---|
| 272 | wwNew = glonasseph->GPSWeek;
|
|---|
| 273 | towNew = glonasseph->GPSTOW;
|
|---|
| 274 | updatetime(&wwNew, &towNew, glonasseph->tb*1000, 0); // Moscow -> GPS
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | if ( *ee == 0 ||
|
|---|
| 278 | wwNew > wwOld ||
|
|---|
| 279 | (wwNew == wwOld && towNew > towOld) ) {
|
|---|
| 280 | delete *ee;
|
|---|
| 281 | *ee = glonasseph;
|
|---|
| 282 | printGlonassEph(glonasseph, true);
|
|---|
| 283 | }
|
|---|
| 284 | else {
|
|---|
| 285 | printGlonassEph(glonasseph, false);
|
|---|
| 286 | delete glonasseph;
|
|---|
| 287 | }
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | // New Galileo Ephemeris
|
|---|
| 291 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 292 | void t_pgmCore::slotNewGalileoEph(galileoephemeris* galileoeph) {
|
|---|
| 293 |
|
|---|
| 294 | QMutexLocker locker(&_mutex);
|
|---|
| 295 |
|
|---|
| 296 | galileoephemeris copy_galileoeph = *galileoeph;
|
|---|
| 297 | emit newEphGalileo(copy_galileoeph);
|
|---|
| 298 |
|
|---|
| 299 | printEphHeader();
|
|---|
| 300 |
|
|---|
| 301 | int galIndex = galileoeph->satellite;
|
|---|
| 302 | /* GIOVE */
|
|---|
| 303 | if(galIndex == 51) galIndex = 1;
|
|---|
| 304 | else if(galIndex == 52) galIndex = 16;
|
|---|
| 305 | if (galIndex < 0 || galIndex > PRN_GALILEO_END - PRN_GALILEO_START) {
|
|---|
| 306 | emit( newMessage("Wrong Galileo Satellite Number", true) );
|
|---|
| 307 | exit(1);
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | galileoephemeris** ee = &_galileoEph[galIndex];
|
|---|
| 311 |
|
|---|
| 312 | if ( *ee == 0 ||
|
|---|
| 313 | galileoeph->Week > (*ee)->Week ||
|
|---|
| 314 | (galileoeph->Week == (*ee)->Week && galileoeph->TOC > (*ee)->TOC) ) {
|
|---|
| 315 | delete *ee;
|
|---|
| 316 | *ee = galileoeph;
|
|---|
| 317 | printGalileoEph(galileoeph, true);
|
|---|
| 318 | }
|
|---|
| 319 | else {
|
|---|
| 320 | printGalileoEph(galileoeph, false);
|
|---|
| 321 | delete galileoeph;
|
|---|
| 322 | }
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 | // Print Header of the output File(s)
|
|---|
| 326 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 327 | void t_pgmCore::printEphHeader() {
|
|---|
| 328 |
|
|---|
| 329 | bncSettings settings;
|
|---|
| 330 |
|
|---|
| 331 | // Initialization
|
|---|
| 332 | // --------------
|
|---|
| 333 | if (_rinexVers == 0) {
|
|---|
| 334 |
|
|---|
| 335 | if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
|
|---|
| 336 | _rinexVers = 3;
|
|---|
| 337 | }
|
|---|
| 338 | else {
|
|---|
| 339 | _rinexVers = 2;
|
|---|
| 340 | }
|
|---|
| 341 |
|
|---|
| 342 | _ephPath = settings.value("ephPath").toString();
|
|---|
| 343 |
|
|---|
| 344 | if ( !_ephPath.isEmpty() ) {
|
|---|
| 345 | if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
|
|---|
| 346 | _ephPath += QDir::separator();
|
|---|
| 347 | }
|
|---|
| 348 | expandEnvVar(_ephPath);
|
|---|
| 349 | }
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | // (Re-)Open output File(s)
|
|---|
| 353 | // ------------------------
|
|---|
| 354 | if (!_ephPath.isEmpty()) {
|
|---|
| 355 |
|
|---|
| 356 | QDateTime datTim = currentDateAndTimeGPS();
|
|---|
| 357 |
|
|---|
| 358 | QString ephFileNameGPS = _ephPath + "BRDC" +
|
|---|
| 359 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'));
|
|---|
| 360 |
|
|---|
| 361 | QString hlpStr = bncRinex::nextEpochStr(datTim,
|
|---|
| 362 | settings.value("ephIntr").toString());
|
|---|
| 363 |
|
|---|
| 364 | if (_rinexVers == 3) {
|
|---|
| 365 | ephFileNameGPS += hlpStr + datTim.toString(".yyP");
|
|---|
| 366 | }
|
|---|
| 367 | else {
|
|---|
| 368 | ephFileNameGPS += hlpStr + datTim.toString(".yyN");
|
|---|
| 369 | }
|
|---|
| 370 |
|
|---|
| 371 | if (_ephFileNameGPS == ephFileNameGPS) {
|
|---|
| 372 | return;
|
|---|
| 373 | }
|
|---|
| 374 | else {
|
|---|
| 375 | _ephFileNameGPS = ephFileNameGPS;
|
|---|
| 376 | }
|
|---|
| 377 |
|
|---|
| 378 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
|---|
| 379 | delete _gpsEph[ii-PRN_GPS_START];
|
|---|
| 380 | _gpsEph[ii-PRN_GPS_START] = 0;
|
|---|
| 381 | }
|
|---|
| 382 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
|---|
| 383 | delete _glonassEph[ii-PRN_GLONASS_START];
|
|---|
| 384 | _glonassEph[ii-PRN_GLONASS_START] = 0;
|
|---|
| 385 | }
|
|---|
| 386 | for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
|
|---|
| 387 | delete _galileoEph[ii-PRN_GALILEO_START];
|
|---|
| 388 | _galileoEph[ii-PRN_GALILEO_START] = 0;
|
|---|
| 389 | }
|
|---|
| 390 |
|
|---|
| 391 | delete _ephStreamGPS;
|
|---|
| 392 | delete _ephFileGPS;
|
|---|
| 393 |
|
|---|
| 394 | QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
|
|---|
| 395 | QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
|
|---|
| 396 | QFlags<QIODevice::OpenModeFlag> appendFlagGalileo;
|
|---|
| 397 |
|
|---|
| 398 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
|---|
| 399 | QFile::exists(ephFileNameGPS) ) {
|
|---|
| 400 | appendFlagGPS = QIODevice::Append;
|
|---|
| 401 | }
|
|---|
| 402 |
|
|---|
| 403 | _ephFileGPS = new QFile(ephFileNameGPS);
|
|---|
| 404 | _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
|
|---|
| 405 | _ephStreamGPS = new QTextStream();
|
|---|
| 406 | _ephStreamGPS->setDevice(_ephFileGPS);
|
|---|
| 407 |
|
|---|
| 408 | if (_rinexVers == 3) {
|
|---|
| 409 | _ephFileGlonass = _ephFileGPS;
|
|---|
| 410 | _ephStreamGlonass = _ephStreamGPS;
|
|---|
| 411 | _ephFileGalileo = _ephFileGPS;
|
|---|
| 412 | _ephStreamGalileo = _ephStreamGPS;
|
|---|
| 413 | }
|
|---|
| 414 | else if (_rinexVers == 2) {
|
|---|
| 415 | QString ephFileNameGlonass = _ephPath + "BRDC" +
|
|---|
| 416 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
|---|
| 417 | hlpStr + datTim.toString(".yyG");
|
|---|
| 418 |
|
|---|
| 419 | delete _ephStreamGlonass;
|
|---|
| 420 | delete _ephFileGlonass;
|
|---|
| 421 |
|
|---|
| 422 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
|---|
| 423 | QFile::exists(ephFileNameGlonass) ) {
|
|---|
| 424 | appendFlagGlonass = QIODevice::Append;
|
|---|
| 425 | }
|
|---|
| 426 |
|
|---|
| 427 | _ephFileGlonass = new QFile(ephFileNameGlonass);
|
|---|
| 428 | _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
|
|---|
| 429 | _ephStreamGlonass = new QTextStream();
|
|---|
| 430 | _ephStreamGlonass->setDevice(_ephFileGlonass);
|
|---|
| 431 | }
|
|---|
| 432 |
|
|---|
| 433 | // Header - RINEX Version 3
|
|---|
| 434 | // ------------------------
|
|---|
| 435 | if (_rinexVers == 3) {
|
|---|
| 436 | if ( ! (appendFlagGPS & QIODevice::Append)) {
|
|---|
| 437 | QString line;
|
|---|
| 438 | line.sprintf(
|
|---|
| 439 | "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
|
|---|
| 440 | 3.0, "", "");
|
|---|
| 441 | *_ephStreamGPS << line;
|
|---|
| 442 |
|
|---|
| 443 | QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
|
|---|
| 444 | *_ephStreamGPS << _pgmName.toAscii().data()
|
|---|
| 445 | << _userName.toAscii().data()
|
|---|
| 446 | << hlp.toAscii().data()
|
|---|
| 447 | << "PGM / RUN BY / DATE" << endl;
|
|---|
| 448 |
|
|---|
| 449 | line.sprintf("%60sEND OF HEADER\n", "");
|
|---|
| 450 | *_ephStreamGPS << line;
|
|---|
| 451 |
|
|---|
| 452 | _ephStreamGPS->flush();
|
|---|
| 453 | }
|
|---|
| 454 | }
|
|---|
| 455 |
|
|---|
| 456 | // Headers - RINEX Version 2
|
|---|
| 457 | // -------------------------
|
|---|
| 458 | else if (_rinexVers == 2) {
|
|---|
| 459 | if (! (appendFlagGPS & QIODevice::Append)) {
|
|---|
| 460 | QString line;
|
|---|
| 461 | line.sprintf(
|
|---|
| 462 | "%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n", 2.10, "", "");
|
|---|
| 463 | *_ephStreamGPS << line;
|
|---|
| 464 |
|
|---|
| 465 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
|---|
| 466 | *_ephStreamGPS << _pgmName.toAscii().data()
|
|---|
| 467 | << _userName.toAscii().data()
|
|---|
| 468 | << hlp.toAscii().data()
|
|---|
| 469 | << "PGM / RUN BY / DATE" << endl;
|
|---|
| 470 |
|
|---|
| 471 | line.sprintf("%60sEND OF HEADER\n", "");
|
|---|
| 472 | *_ephStreamGPS << line;
|
|---|
| 473 |
|
|---|
| 474 | _ephStreamGPS->flush();
|
|---|
| 475 | }
|
|---|
| 476 | if (! (appendFlagGlonass & QIODevice::Append)) {
|
|---|
| 477 | QString line;
|
|---|
| 478 | line.sprintf(
|
|---|
| 479 | "%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",2.10,"","");
|
|---|
| 480 | *_ephStreamGlonass << line;
|
|---|
| 481 |
|
|---|
| 482 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
|---|
| 483 | *_ephStreamGlonass << _pgmName.toAscii().data()
|
|---|
| 484 | << _userName.toAscii().data()
|
|---|
| 485 | << hlp.toAscii().data()
|
|---|
| 486 | << "PGM / RUN BY / DATE" << endl;
|
|---|
| 487 |
|
|---|
| 488 | line.sprintf("%60sEND OF HEADER\n", "");
|
|---|
| 489 | *_ephStreamGlonass << line;
|
|---|
| 490 |
|
|---|
| 491 | _ephStreamGlonass->flush();
|
|---|
| 492 | }
|
|---|
| 493 | }
|
|---|
| 494 | }
|
|---|
| 495 | }
|
|---|
| 496 |
|
|---|
| 497 | // Print One GPS Ephemeris
|
|---|
| 498 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 499 | void t_pgmCore::printGPSEph(gpsephemeris* ep, bool printFile) {
|
|---|
| 500 |
|
|---|
| 501 | t_ephGPS eph;
|
|---|
| 502 | eph.set(ep);
|
|---|
| 503 |
|
|---|
| 504 | QString strV2 = eph.toString(2.11);
|
|---|
| 505 | QString strV3 = eph.toString(3.01);
|
|---|
| 506 |
|
|---|
| 507 | printOutput(printFile, _ephStreamGPS, strV2, strV3);
|
|---|
| 508 | }
|
|---|
| 509 |
|
|---|
| 510 | // Print One Glonass Ephemeris
|
|---|
| 511 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 512 | void t_pgmCore::printGlonassEph(glonassephemeris* ep, bool printFile) {
|
|---|
| 513 |
|
|---|
| 514 | t_ephGlo eph;
|
|---|
| 515 | bool timeChanged;
|
|---|
| 516 | eph.set(ep, timeChanged);
|
|---|
| 517 |
|
|---|
| 518 | QString strV2 = eph.toString(2.11);
|
|---|
| 519 | QString strV3 = eph.toString(3.01);
|
|---|
| 520 |
|
|---|
| 521 | printOutput(printFile, _ephStreamGlonass, strV2, strV3);
|
|---|
| 522 | }
|
|---|
| 523 |
|
|---|
| 524 | // Print One Galileo Ephemeris
|
|---|
| 525 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 526 | void t_pgmCore::printGalileoEph(galileoephemeris* ep, bool printFile) {
|
|---|
| 527 |
|
|---|
| 528 | t_ephGal eph;
|
|---|
| 529 | eph.set(ep);
|
|---|
| 530 |
|
|---|
| 531 | QString strV2 = eph.toString(2.11);
|
|---|
| 532 | QString strV3 = eph.toString(3.01);
|
|---|
| 533 |
|
|---|
| 534 | printOutput(printFile, _ephStreamGalileo, strV2, strV3);
|
|---|
| 535 | }
|
|---|
| 536 |
|
|---|
| 537 | // Output
|
|---|
| 538 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 539 | void t_pgmCore::printOutput(bool printFile, QTextStream* stream,
|
|---|
| 540 | const QString& strV2, const QString& strV3) {
|
|---|
| 541 |
|
|---|
| 542 | // Output into file
|
|---|
| 543 | // ----------------
|
|---|
| 544 | if (printFile && stream) {
|
|---|
| 545 | if (_rinexVers == 2) {
|
|---|
| 546 | *stream << strV2.toAscii();
|
|---|
| 547 | }
|
|---|
| 548 | else {
|
|---|
| 549 | *stream << strV3.toAscii();
|
|---|
| 550 | }
|
|---|
| 551 | stream->flush();
|
|---|
| 552 | }
|
|---|
| 553 |
|
|---|
| 554 | // Output into the socket
|
|---|
| 555 | // ----------------------
|
|---|
| 556 | if (_sockets) {
|
|---|
| 557 | QMutableListIterator<QTcpSocket*> is(*_sockets);
|
|---|
| 558 | while (is.hasNext()) {
|
|---|
| 559 | QTcpSocket* sock = is.next();
|
|---|
| 560 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
|---|
| 561 | if (sock->write(strV3.toAscii()) == -1) {
|
|---|
| 562 | delete sock;
|
|---|
| 563 | is.remove();
|
|---|
| 564 | }
|
|---|
| 565 | }
|
|---|
| 566 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
|---|
| 567 | delete sock;
|
|---|
| 568 | is.remove();
|
|---|
| 569 | }
|
|---|
| 570 | }
|
|---|
| 571 | }
|
|---|
| 572 | }
|
|---|
| 573 |
|
|---|
| 574 | // Set Port Number
|
|---|
| 575 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 576 | void t_pgmCore::setPort(int port) {
|
|---|
| 577 | _port = port;
|
|---|
| 578 | if (_port != 0) {
|
|---|
| 579 | delete _server;
|
|---|
| 580 | _server = new QTcpServer;
|
|---|
| 581 | if ( !_server->listen(QHostAddress::Any, _port) ) {
|
|---|
| 582 | slotMessage("t_pgmCore: Cannot listen on ephemeris port", true);
|
|---|
| 583 | }
|
|---|
| 584 | connect(_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
|
|---|
| 585 | delete _sockets;
|
|---|
| 586 | _sockets = new QList<QTcpSocket*>;
|
|---|
| 587 | }
|
|---|
| 588 | }
|
|---|
| 589 |
|
|---|
| 590 | // Set Port Number
|
|---|
| 591 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 592 | void t_pgmCore::setPortCorr(int port) {
|
|---|
| 593 | _portCorr = port;
|
|---|
| 594 | if (_portCorr != 0) {
|
|---|
| 595 | delete _serverCorr;
|
|---|
| 596 | _serverCorr = new QTcpServer;
|
|---|
| 597 | if ( !_serverCorr->listen(QHostAddress::Any, _portCorr) ) {
|
|---|
| 598 | slotMessage("t_pgmCore: Cannot listen on correction port", true);
|
|---|
| 599 | }
|
|---|
| 600 | connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
|
|---|
| 601 | delete _socketsCorr;
|
|---|
| 602 | _socketsCorr = new QList<QTcpSocket*>;
|
|---|
| 603 | }
|
|---|
| 604 | }
|
|---|
| 605 |
|
|---|
| 606 | // New Connection
|
|---|
| 607 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 608 | void t_pgmCore::slotNewConnection() {
|
|---|
| 609 | _sockets->push_back( _server->nextPendingConnection() );
|
|---|
| 610 | }
|
|---|
| 611 |
|
|---|
| 612 | // New Connection
|
|---|
| 613 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 614 | void t_pgmCore::slotNewConnectionCorr() {
|
|---|
| 615 | _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
|
|---|
| 616 | }
|
|---|
| 617 |
|
|---|
| 618 | //
|
|---|
| 619 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 620 | void t_pgmCore::slotQuit() {
|
|---|
| 621 | cout << "t_pgmCore::slotQuit" << endl;
|
|---|
| 622 | delete _caster;
|
|---|
| 623 | qApp->quit();
|
|---|
| 624 | }
|
|---|
| 625 |
|
|---|
| 626 | //
|
|---|
| 627 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 628 | void t_pgmCore::slotNewCorrLine(QString line, QString staID, long coTime) {
|
|---|
| 629 |
|
|---|
| 630 | QMutexLocker locker(&_mutex);
|
|---|
| 631 |
|
|---|
| 632 | // Combination of Corrections
|
|---|
| 633 | // --------------------------
|
|---|
| 634 | #ifdef USE_COMBINATION
|
|---|
| 635 | if (_bncComb) {
|
|---|
| 636 | _bncComb->processCorrLine(staID, line);
|
|---|
| 637 | }
|
|---|
| 638 | #endif
|
|---|
| 639 |
|
|---|
| 640 | bncSettings settings;
|
|---|
| 641 | _waitCoTime = settings.value("corrTime").toInt();
|
|---|
| 642 | if (_waitCoTime < 0) {
|
|---|
| 643 | _waitCoTime = 0;
|
|---|
| 644 | }
|
|---|
| 645 |
|
|---|
| 646 | // First time, set the _lastDumpSec immediately
|
|---|
| 647 | // --------------------------------------------
|
|---|
| 648 | if (_lastDumpCoSec == 0) {
|
|---|
| 649 | _lastDumpCoSec = coTime - 1;
|
|---|
| 650 | }
|
|---|
| 651 |
|
|---|
| 652 | // An old correction - throw it away
|
|---|
| 653 | // ---------------------------------
|
|---|
| 654 | if (_waitCoTime > 0 && coTime <= _lastDumpCoSec) {
|
|---|
| 655 | if (!_bncComb) {
|
|---|
| 656 | QString line = staID + ": Correction for one sat neglected because overaged by " +
|
|---|
| 657 | QString().sprintf(" %ld sec",
|
|---|
| 658 | _lastDumpCoSec - coTime + _waitCoTime);
|
|---|
| 659 | messagePrivate(line.toAscii());
|
|---|
| 660 | emit( newMessage(line.toAscii(), true) );
|
|---|
| 661 | }
|
|---|
| 662 | return;
|
|---|
| 663 | }
|
|---|
| 664 |
|
|---|
| 665 | _corrs->insert(coTime, QString(line + " " + staID));
|
|---|
| 666 |
|
|---|
| 667 | // Dump Corrections
|
|---|
| 668 | // ----------------
|
|---|
| 669 | if (_waitCoTime == 0) {
|
|---|
| 670 | dumpCorrs();
|
|---|
| 671 | }
|
|---|
| 672 | else if (coTime - _waitCoTime > _lastDumpCoSec) {
|
|---|
| 673 | dumpCorrs(_lastDumpCoSec + 1, coTime - _waitCoTime);
|
|---|
| 674 | _lastDumpCoSec = coTime - _waitCoTime;
|
|---|
| 675 | }
|
|---|
| 676 | }
|
|---|
| 677 |
|
|---|
| 678 | // Dump Complete Correction Epochs
|
|---|
| 679 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 680 | void t_pgmCore::dumpCorrs(long minTime, long maxTime) {
|
|---|
| 681 | for (long sec = minTime; sec <= maxTime; sec++) {
|
|---|
| 682 | QList<QString> allCorrs = _corrs->values(sec);
|
|---|
| 683 | dumpCorrs(allCorrs);
|
|---|
| 684 | _corrs->remove(sec);
|
|---|
| 685 | }
|
|---|
| 686 | }
|
|---|
| 687 |
|
|---|
| 688 | // Dump all corrections
|
|---|
| 689 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 690 | void t_pgmCore::dumpCorrs() {
|
|---|
| 691 | QList<QString> allCorrs;
|
|---|
| 692 | QMutableMapIterator<long, QString> it(*_corrs);
|
|---|
| 693 | while (it.hasNext()) {
|
|---|
| 694 | allCorrs << it.next().value();
|
|---|
| 695 | it.remove();
|
|---|
| 696 | }
|
|---|
| 697 | dumpCorrs(allCorrs);
|
|---|
| 698 | }
|
|---|
| 699 |
|
|---|
| 700 | // Dump List of Corrections
|
|---|
| 701 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 702 | void t_pgmCore::dumpCorrs(const QList<QString>& allCorrs) {
|
|---|
| 703 | emit newCorrections(allCorrs);
|
|---|
| 704 | if (_socketsCorr) {
|
|---|
| 705 | QListIterator<QString> it(allCorrs);
|
|---|
| 706 | while (it.hasNext()) {
|
|---|
| 707 | QString corrLine = it.next() + "\n";
|
|---|
| 708 |
|
|---|
| 709 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
|---|
| 710 | while (is.hasNext()) {
|
|---|
| 711 | QTcpSocket* sock = is.next();
|
|---|
| 712 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
|---|
| 713 | if (sock->write(corrLine.toAscii()) == -1) {
|
|---|
| 714 | delete sock;
|
|---|
| 715 | is.remove();
|
|---|
| 716 | }
|
|---|
| 717 | }
|
|---|
| 718 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
|---|
| 719 | delete sock;
|
|---|
| 720 | is.remove();
|
|---|
| 721 | }
|
|---|
| 722 | }
|
|---|
| 723 | }
|
|---|
| 724 | }
|
|---|
| 725 | }
|
|---|
| 726 |
|
|---|
| 727 | //
|
|---|
| 728 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 729 | void t_pgmCore::setConfFileName(const QString& confFileName) {
|
|---|
| 730 | if (confFileName.isEmpty()) {
|
|---|
| 731 | _confFileName = QDir::homePath() + QDir::separator()
|
|---|
| 732 | + ".config" + QDir::separator()
|
|---|
| 733 | + qApp->organizationName() + QDir::separator()
|
|---|
| 734 | + qApp->applicationName() + ".bnc";
|
|---|
| 735 | }
|
|---|
| 736 | else {
|
|---|
| 737 | _confFileName = confFileName;
|
|---|
| 738 | }
|
|---|
| 739 | }
|
|---|
| 740 |
|
|---|
| 741 | // Raw Output
|
|---|
| 742 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 743 | void t_pgmCore::writeRawData(const QByteArray& data, const QByteArray& staID,
|
|---|
| 744 | const QByteArray& format) {
|
|---|
| 745 |
|
|---|
| 746 | QMutexLocker locker(&_mutex);
|
|---|
| 747 |
|
|---|
| 748 | if (!_rawFile) {
|
|---|
| 749 | bncSettings settings;
|
|---|
| 750 | QByteArray fileName = settings.value("rawOutFile").toByteArray();
|
|---|
| 751 | if (!fileName.isEmpty()) {
|
|---|
| 752 | _rawFile = new bncRawFile(fileName, staID, bncRawFile::output);
|
|---|
| 753 | }
|
|---|
| 754 | }
|
|---|
| 755 |
|
|---|
| 756 | if (_rawFile) {
|
|---|
| 757 | _rawFile->writeRawData(data, staID, format);
|
|---|
| 758 | }
|
|---|
| 759 | }
|
|---|
| 760 |
|
|---|
| 761 | // Get Glonass Slot Numbers from Global Array
|
|---|
| 762 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 763 | void t_pgmCore::getGlonassSlotNums(int GLOFreq[]) {
|
|---|
| 764 |
|
|---|
| 765 | QMutexLocker locker(&_mutex);
|
|---|
| 766 |
|
|---|
| 767 | for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
|
|---|
| 768 | if (_GLOFreq[ii] != 0) {
|
|---|
| 769 | GLOFreq[ii] = _GLOFreq[ii];
|
|---|
| 770 | }
|
|---|
| 771 | }
|
|---|
| 772 | }
|
|---|
| 773 |
|
|---|
| 774 | // Store Glonass Slot Numbers to Global Array
|
|---|
| 775 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 776 | void t_pgmCore::storeGlonassSlotNums(const int GLOFreq[]) {
|
|---|
| 777 |
|
|---|
| 778 | QMutexLocker locker(&_mutex);
|
|---|
| 779 |
|
|---|
| 780 | for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
|
|---|
| 781 | if (GLOFreq[ii] != 0) {
|
|---|
| 782 | _GLOFreq[ii] = GLOFreq[ii];
|
|---|
| 783 | }
|
|---|
| 784 | }
|
|---|
| 785 | }
|
|---|
| 786 |
|
|---|
| 787 | //
|
|---|
| 788 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 789 | void t_pgmCore::initCombination() {
|
|---|
| 790 | #ifdef USE_COMBINATION
|
|---|
| 791 | _bncComb = new bncComb();
|
|---|
| 792 | if (_bncComb->nStreams() < 1) {
|
|---|
| 793 | delete _bncComb;
|
|---|
| 794 | _bncComb = 0;
|
|---|
| 795 | }
|
|---|
| 796 | #endif
|
|---|
| 797 | }
|
|---|
| 798 |
|
|---|
| 799 | //
|
|---|
| 800 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 801 | void t_pgmCore::stopCombination() {
|
|---|
| 802 | #ifdef USE_COMBINATION
|
|---|
| 803 | delete _bncComb;
|
|---|
| 804 | _bncComb = 0;
|
|---|
| 805 | #endif
|
|---|
| 806 | }
|
|---|
| 807 |
|
|---|
| 808 | // Check Ephemeris Consistency
|
|---|
| 809 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 810 | void t_pgmCore::checkEphemeris(gpsephemeris* oldEph, gpsephemeris* newEph) {
|
|---|
| 811 | if (oldEph->clock_bias != newEph->clock_bias ||
|
|---|
| 812 | oldEph->clock_drift != newEph->clock_drift ||
|
|---|
| 813 | oldEph->clock_driftrate != newEph->clock_driftrate) {
|
|---|
| 814 | QString msg = currentDateAndTimeGPS().toString(Qt::ISODate) +
|
|---|
| 815 | QString(" %1 EPH DIFFERS\n").arg(oldEph->satellite);
|
|---|
| 816 | messagePrivate(msg.toAscii());
|
|---|
| 817 | }
|
|---|
| 818 | }
|
|---|