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