[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 |
|
---|
[4245] | 225 | if ( *ee != 0 &&
|
---|
| 226 | gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC == (*ee)->TOC ) {
|
---|
| 227 | checkEphemeris(*ee, gpseph);
|
---|
| 228 | }
|
---|
| 229 |
|
---|
[538] | 230 | if ( *ee == 0 ||
|
---|
| 231 | gpseph->GPSweek > (*ee)->GPSweek ||
|
---|
[594] | 232 | (gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC > (*ee)->TOC) ) {
|
---|
[516] | 233 | delete *ee;
|
---|
| 234 | *ee = gpseph;
|
---|
[600] | 235 | printGPSEph(gpseph, true);
|
---|
[516] | 236 | }
|
---|
| 237 | else {
|
---|
[600] | 238 | printGPSEph(gpseph, false);
|
---|
[516] | 239 | delete gpseph;
|
---|
| 240 | }
|
---|
[511] | 241 | }
|
---|
| 242 |
|
---|
[535] | 243 | // New Glonass Ephemeris
|
---|
[511] | 244 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 245 | void bncApp::slotNewGlonassEph(glonassephemeris* glonasseph) {
|
---|
[516] | 246 |
|
---|
| 247 | QMutexLocker locker(&_mutex);
|
---|
| 248 |
|
---|
[1164] | 249 | glonassephemeris copy_glonasseph = *glonasseph;
|
---|
| 250 | emit newEphGlonass(copy_glonasseph);
|
---|
| 251 |
|
---|
[534] | 252 | printEphHeader();
|
---|
| 253 |
|
---|
[532] | 254 | glonassephemeris** ee = &_glonassEph[glonasseph->almanac_number-1];
|
---|
[531] | 255 |
|
---|
[3539] | 256 | int wwOld, towOld, wwNew, towNew;
|
---|
| 257 | if (*ee != 0) {
|
---|
| 258 | wwOld = (*ee)->GPSWeek;
|
---|
| 259 | towOld = (*ee)->GPSTOW;
|
---|
| 260 | updatetime(&wwOld, &towOld, (*ee)->tb*1000, 0); // Moscow -> GPS
|
---|
| 261 |
|
---|
| 262 | wwNew = glonasseph->GPSWeek;
|
---|
| 263 | towNew = glonasseph->GPSTOW;
|
---|
| 264 | updatetime(&wwNew, &towNew, glonasseph->tb*1000, 0); // Moscow -> GPS
|
---|
| 265 | }
|
---|
| 266 |
|
---|
[578] | 267 | if ( *ee == 0 ||
|
---|
[3539] | 268 | wwNew > wwOld ||
|
---|
| 269 | (wwNew == wwOld && towNew > towOld) ) {
|
---|
[531] | 270 | delete *ee;
|
---|
| 271 | *ee = glonasseph;
|
---|
[600] | 272 | printGlonassEph(glonasseph, true);
|
---|
[531] | 273 | }
|
---|
| 274 | else {
|
---|
[600] | 275 | printGlonassEph(glonasseph, false);
|
---|
[531] | 276 | delete glonasseph;
|
---|
| 277 | }
|
---|
[511] | 278 | }
|
---|
| 279 |
|
---|
[2770] | 280 | // New Galileo Ephemeris
|
---|
| 281 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 282 | void bncApp::slotNewGalileoEph(galileoephemeris* galileoeph) {
|
---|
| 283 |
|
---|
| 284 | QMutexLocker locker(&_mutex);
|
---|
| 285 |
|
---|
[2772] | 286 | galileoephemeris copy_galileoeph = *galileoeph;
|
---|
| 287 | emit newEphGalileo(copy_galileoeph);
|
---|
| 288 |
|
---|
| 289 | printEphHeader();
|
---|
| 290 |
|
---|
[3734] | 291 | int galIndex = galileoeph->satellite;
|
---|
| 292 | /* GIOVE */
|
---|
| 293 | if(galIndex == 51) galIndex = 1;
|
---|
| 294 | else if(galIndex == 52) galIndex = 16;
|
---|
[2785] | 295 | if (galIndex < 0 || galIndex > PRN_GALILEO_END - PRN_GALILEO_START) {
|
---|
[2773] | 296 | emit( newMessage("Wrong Galileo Satellite Number", true) );
|
---|
| 297 | exit(1);
|
---|
| 298 | }
|
---|
[2772] | 299 |
|
---|
[2773] | 300 | galileoephemeris** ee = &_galileoEph[galIndex];
|
---|
| 301 |
|
---|
| 302 | if ( *ee == 0 ||
|
---|
[2772] | 303 | galileoeph->Week > (*ee)->Week ||
|
---|
| 304 | (galileoeph->Week == (*ee)->Week && galileoeph->TOC > (*ee)->TOC) ) {
|
---|
| 305 | delete *ee;
|
---|
| 306 | *ee = galileoeph;
|
---|
| 307 | printGalileoEph(galileoeph, true);
|
---|
| 308 | }
|
---|
| 309 | else {
|
---|
| 310 | printGalileoEph(galileoeph, false);
|
---|
| 311 | delete galileoeph;
|
---|
| 312 | }
|
---|
[2770] | 313 | }
|
---|
| 314 |
|
---|
[535] | 315 | // Print Header of the output File(s)
|
---|
[516] | 316 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 317 | void bncApp::printEphHeader() {
|
---|
[528] | 318 |
|
---|
[1535] | 319 | bncSettings settings;
|
---|
[535] | 320 |
|
---|
[534] | 321 | // Initialization
|
---|
| 322 | // --------------
|
---|
| 323 | if (_rinexVers == 0) {
|
---|
[528] | 324 |
|
---|
[533] | 325 | if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
|
---|
[534] | 326 | _rinexVers = 3;
|
---|
[533] | 327 | }
|
---|
| 328 | else {
|
---|
[534] | 329 | _rinexVers = 2;
|
---|
[533] | 330 | }
|
---|
[529] | 331 |
|
---|
[533] | 332 | _ephPath = settings.value("ephPath").toString();
|
---|
| 333 |
|
---|
| 334 | if ( !_ephPath.isEmpty() ) {
|
---|
| 335 | if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
|
---|
| 336 | _ephPath += QDir::separator();
|
---|
| 337 | }
|
---|
| 338 | expandEnvVar(_ephPath);
|
---|
| 339 | }
|
---|
[517] | 340 | }
|
---|
[533] | 341 |
|
---|
[534] | 342 | // (Re-)Open output File(s)
|
---|
| 343 | // ------------------------
|
---|
[533] | 344 | if (!_ephPath.isEmpty()) {
|
---|
| 345 |
|
---|
[1154] | 346 | QDateTime datTim = currentDateAndTimeGPS();
|
---|
[533] | 347 |
|
---|
[583] | 348 | QString ephFileNameGPS = _ephPath + "BRDC" +
|
---|
[563] | 349 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'));
|
---|
[533] | 350 |
|
---|
[647] | 351 | QString hlpStr = bncRinex::nextEpochStr(datTim,
|
---|
| 352 | settings.value("ephIntr").toString());
|
---|
[584] | 353 |
|
---|
[575] | 354 | if (_rinexVers == 3) {
|
---|
| 355 | ephFileNameGPS += hlpStr + datTim.toString(".yyP");
|
---|
| 356 | }
|
---|
| 357 | else {
|
---|
| 358 | ephFileNameGPS += hlpStr + datTim.toString(".yyN");
|
---|
| 359 | }
|
---|
[563] | 360 |
|
---|
[533] | 361 | if (_ephFileNameGPS == ephFileNameGPS) {
|
---|
| 362 | return;
|
---|
| 363 | }
|
---|
| 364 | else {
|
---|
| 365 | _ephFileNameGPS = ephFileNameGPS;
|
---|
| 366 | }
|
---|
| 367 |
|
---|
[575] | 368 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
---|
| 369 | delete _gpsEph[ii-PRN_GPS_START];
|
---|
| 370 | _gpsEph[ii-PRN_GPS_START] = 0;
|
---|
| 371 | }
|
---|
| 372 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
---|
| 373 | delete _glonassEph[ii-PRN_GLONASS_START];
|
---|
| 374 | _glonassEph[ii-PRN_GLONASS_START] = 0;
|
---|
| 375 | }
|
---|
[2770] | 376 | for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
|
---|
| 377 | delete _galileoEph[ii-PRN_GALILEO_START];
|
---|
| 378 | _galileoEph[ii-PRN_GALILEO_START] = 0;
|
---|
| 379 | }
|
---|
[575] | 380 |
|
---|
[533] | 381 | delete _ephStreamGPS;
|
---|
| 382 | delete _ephFileGPS;
|
---|
| 383 |
|
---|
[535] | 384 | QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
|
---|
[536] | 385 | QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
|
---|
[2770] | 386 | QFlags<QIODevice::OpenModeFlag> appendFlagGalileo;
|
---|
[536] | 387 |
|
---|
[535] | 388 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
---|
| 389 | QFile::exists(ephFileNameGPS) ) {
|
---|
| 390 | appendFlagGPS = QIODevice::Append;
|
---|
| 391 | }
|
---|
| 392 |
|
---|
[533] | 393 | _ephFileGPS = new QFile(ephFileNameGPS);
|
---|
[535] | 394 | _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
|
---|
[533] | 395 | _ephStreamGPS = new QTextStream();
|
---|
| 396 | _ephStreamGPS->setDevice(_ephFileGPS);
|
---|
| 397 |
|
---|
[534] | 398 | if (_rinexVers == 3) {
|
---|
[533] | 399 | _ephFileGlonass = _ephFileGPS;
|
---|
| 400 | _ephStreamGlonass = _ephStreamGPS;
|
---|
[2770] | 401 | _ephFileGalileo = _ephFileGPS;
|
---|
| 402 | _ephStreamGalileo = _ephStreamGPS;
|
---|
[533] | 403 | }
|
---|
[534] | 404 | else if (_rinexVers == 2) {
|
---|
[583] | 405 | QString ephFileNameGlonass = _ephPath + "BRDC" +
|
---|
[563] | 406 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
[575] | 407 | hlpStr + datTim.toString(".yyG");
|
---|
[533] | 408 |
|
---|
| 409 | delete _ephStreamGlonass;
|
---|
| 410 | delete _ephFileGlonass;
|
---|
| 411 |
|
---|
[535] | 412 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
---|
| 413 | QFile::exists(ephFileNameGlonass) ) {
|
---|
| 414 | appendFlagGlonass = QIODevice::Append;
|
---|
| 415 | }
|
---|
| 416 |
|
---|
[533] | 417 | _ephFileGlonass = new QFile(ephFileNameGlonass);
|
---|
[535] | 418 | _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
|
---|
[533] | 419 | _ephStreamGlonass = new QTextStream();
|
---|
| 420 | _ephStreamGlonass->setDevice(_ephFileGlonass);
|
---|
| 421 | }
|
---|
| 422 |
|
---|
[534] | 423 | // Header - RINEX Version 3
|
---|
| 424 | // ------------------------
|
---|
| 425 | if (_rinexVers == 3) {
|
---|
[537] | 426 | if ( ! (appendFlagGPS & QIODevice::Append)) {
|
---|
| 427 | QString line;
|
---|
| 428 | line.sprintf(
|
---|
| 429 | "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
|
---|
| 430 | 3.0, "", "");
|
---|
| 431 | *_ephStreamGPS << line;
|
---|
| 432 |
|
---|
[1154] | 433 | QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
|
---|
[559] | 434 | *_ephStreamGPS << _pgmName.toAscii().data()
|
---|
| 435 | << _userName.toAscii().data()
|
---|
| 436 | << hlp.toAscii().data()
|
---|
| 437 | << "PGM / RUN BY / DATE" << endl;
|
---|
| 438 |
|
---|
| 439 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
[537] | 440 | *_ephStreamGPS << line;
|
---|
| 441 |
|
---|
| 442 | _ephStreamGPS->flush();
|
---|
[535] | 443 | }
|
---|
[533] | 444 | }
|
---|
| 445 |
|
---|
[536] | 446 | // Headers - RINEX Version 2
|
---|
| 447 | // -------------------------
|
---|
[534] | 448 | else if (_rinexVers == 2) {
|
---|
[536] | 449 | if (! (appendFlagGPS & QIODevice::Append)) {
|
---|
| 450 | QString line;
|
---|
| 451 | line.sprintf(
|
---|
[2405] | 452 | "%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n", 2.10, "", "");
|
---|
[536] | 453 | *_ephStreamGPS << line;
|
---|
| 454 |
|
---|
[1154] | 455 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
[559] | 456 | *_ephStreamGPS << _pgmName.toAscii().data()
|
---|
| 457 | << _userName.toAscii().data()
|
---|
| 458 | << hlp.toAscii().data()
|
---|
| 459 | << "PGM / RUN BY / DATE" << endl;
|
---|
| 460 |
|
---|
| 461 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
[536] | 462 | *_ephStreamGPS << line;
|
---|
[537] | 463 |
|
---|
| 464 | _ephStreamGPS->flush();
|
---|
[536] | 465 | }
|
---|
| 466 | if (! (appendFlagGlonass & QIODevice::Append)) {
|
---|
| 467 | QString line;
|
---|
| 468 | line.sprintf(
|
---|
[2405] | 469 | "%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",2.10,"","");
|
---|
[536] | 470 | *_ephStreamGlonass << line;
|
---|
| 471 |
|
---|
[1154] | 472 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
[559] | 473 | *_ephStreamGlonass << _pgmName.toAscii().data()
|
---|
| 474 | << _userName.toAscii().data()
|
---|
| 475 | << hlp.toAscii().data()
|
---|
| 476 | << "PGM / RUN BY / DATE" << endl;
|
---|
| 477 |
|
---|
| 478 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
[536] | 479 | *_ephStreamGlonass << line;
|
---|
[537] | 480 |
|
---|
| 481 | _ephStreamGlonass->flush();
|
---|
[536] | 482 | }
|
---|
[533] | 483 | }
|
---|
| 484 | }
|
---|
[516] | 485 | }
|
---|
| 486 |
|
---|
[535] | 487 | // Print One GPS Ephemeris
|
---|
[516] | 488 | ////////////////////////////////////////////////////////////////////////////
|
---|
[600] | 489 | void bncApp::printGPSEph(gpsephemeris* ep, bool printFile) {
|
---|
[519] | 490 |
|
---|
[4020] | 491 | t_ephGPS eph;
|
---|
| 492 | eph.set(ep);
|
---|
[533] | 493 |
|
---|
[4020] | 494 | QString strV2 = eph.toString(2.11);
|
---|
| 495 | QString strV3 = eph.toString(3.01);
|
---|
[941] | 496 |
|
---|
[4020] | 497 | printOutput(printFile, _ephStreamGPS, strV2, strV3);
|
---|
[516] | 498 | }
|
---|
| 499 |
|
---|
[535] | 500 | // Print One Glonass Ephemeris
|
---|
[516] | 501 | ////////////////////////////////////////////////////////////////////////////
|
---|
[600] | 502 | void bncApp::printGlonassEph(glonassephemeris* ep, bool printFile) {
|
---|
[523] | 503 |
|
---|
[4020] | 504 | t_ephGlo eph;
|
---|
| 505 | eph.set(ep);
|
---|
[523] | 506 |
|
---|
[4020] | 507 | QString strV2 = eph.toString(2.11);
|
---|
| 508 | QString strV3 = eph.toString(3.01);
|
---|
[525] | 509 |
|
---|
[4225] | 510 | printOutput(printFile, _ephStreamGlonass, strV2, strV3);
|
---|
[941] | 511 | }
|
---|
| 512 |
|
---|
[2770] | 513 | // Print One Galileo Ephemeris
|
---|
| 514 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 515 | void bncApp::printGalileoEph(galileoephemeris* ep, bool printFile) {
|
---|
[2772] | 516 |
|
---|
[4020] | 517 | t_ephGal eph;
|
---|
| 518 | eph.set(ep);
|
---|
[2772] | 519 |
|
---|
[4020] | 520 | QString strV2 = eph.toString(2.11);
|
---|
| 521 | QString strV3 = eph.toString(3.01);
|
---|
[2772] | 522 |
|
---|
[4225] | 523 | printOutput(printFile, _ephStreamGalileo, strV2, strV3);
|
---|
[2770] | 524 | }
|
---|
| 525 |
|
---|
[941] | 526 | // Output
|
---|
| 527 | ////////////////////////////////////////////////////////////////////////////
|
---|
[943] | 528 | void bncApp::printOutput(bool printFile, QTextStream* stream,
|
---|
[4020] | 529 | const QString& strV2, const QString& strV3) {
|
---|
| 530 |
|
---|
[590] | 531 | // Output into file
|
---|
| 532 | // ----------------
|
---|
[943] | 533 | if (printFile && stream) {
|
---|
[941] | 534 | if (_rinexVers == 2) {
|
---|
[4020] | 535 | *stream << strV2.toAscii();
|
---|
[941] | 536 | }
|
---|
| 537 | else {
|
---|
[4020] | 538 | *stream << strV3.toAscii();
|
---|
[941] | 539 | }
|
---|
[943] | 540 | stream->flush();
|
---|
[517] | 541 | }
|
---|
[590] | 542 |
|
---|
| 543 | // Output into the socket
|
---|
| 544 | // ----------------------
|
---|
| 545 | if (_sockets) {
|
---|
[642] | 546 | QMutableListIterator<QTcpSocket*> is(*_sockets);
|
---|
[590] | 547 | while (is.hasNext()) {
|
---|
| 548 | QTcpSocket* sock = is.next();
|
---|
| 549 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
[4020] | 550 | if (sock->write(strV3.toAscii()) == -1) {
|
---|
[642] | 551 | delete sock;
|
---|
| 552 | is.remove();
|
---|
| 553 | }
|
---|
[590] | 554 | }
|
---|
[642] | 555 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 556 | delete sock;
|
---|
| 557 | is.remove();
|
---|
| 558 | }
|
---|
[590] | 559 | }
|
---|
| 560 | }
|
---|
[516] | 561 | }
|
---|
[589] | 562 |
|
---|
[591] | 563 | // Set Port Number
|
---|
| 564 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 565 | void bncApp::setPort(int port) {
|
---|
| 566 | _port = port;
|
---|
| 567 | if (_port != 0) {
|
---|
[942] | 568 | delete _server;
|
---|
[591] | 569 | _server = new QTcpServer;
|
---|
[1228] | 570 | if ( !_server->listen(QHostAddress::Any, _port) ) {
|
---|
[1451] | 571 | slotMessage("bncApp: Cannot listen on ephemeris port", true);
|
---|
[1228] | 572 | }
|
---|
[591] | 573 | connect(_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
|
---|
[942] | 574 | delete _sockets;
|
---|
[591] | 575 | _sockets = new QList<QTcpSocket*>;
|
---|
| 576 | }
|
---|
| 577 | }
|
---|
| 578 |
|
---|
[937] | 579 | // Set Port Number
|
---|
| 580 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 581 | void bncApp::setPortCorr(int port) {
|
---|
| 582 | _portCorr = port;
|
---|
| 583 | if (_portCorr != 0) {
|
---|
[942] | 584 | delete _serverCorr;
|
---|
[937] | 585 | _serverCorr = new QTcpServer;
|
---|
[1228] | 586 | if ( !_serverCorr->listen(QHostAddress::Any, _portCorr) ) {
|
---|
[1451] | 587 | slotMessage("bncApp: Cannot listen on correction port", true);
|
---|
[1228] | 588 | }
|
---|
[937] | 589 | connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
|
---|
[942] | 590 | delete _socketsCorr;
|
---|
[937] | 591 | _socketsCorr = new QList<QTcpSocket*>;
|
---|
| 592 | }
|
---|
| 593 | }
|
---|
| 594 |
|
---|
[589] | 595 | // New Connection
|
---|
| 596 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 597 | void bncApp::slotNewConnection() {
|
---|
| 598 | _sockets->push_back( _server->nextPendingConnection() );
|
---|
| 599 | }
|
---|
| 600 |
|
---|
[937] | 601 | // New Connection
|
---|
| 602 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 603 | void bncApp::slotNewConnectionCorr() {
|
---|
| 604 | _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
|
---|
| 605 | }
|
---|
| 606 |
|
---|
[621] | 607 | //
|
---|
| 608 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 609 | void bncApp::slotQuit() {
|
---|
[1029] | 610 | cout << "bncApp::slotQuit" << endl;
|
---|
[621] | 611 | delete _caster;
|
---|
| 612 | quit();
|
---|
| 613 | }
|
---|
| 614 |
|
---|
[936] | 615 | //
|
---|
| 616 | ////////////////////////////////////////////////////////////////////////////
|
---|
[974] | 617 | void bncApp::slotNewCorrLine(QString line, QString staID, long coTime) {
|
---|
| 618 |
|
---|
| 619 | QMutexLocker locker(&_mutex);
|
---|
| 620 |
|
---|
[2866] | 621 | // Combination of Corrections
|
---|
| 622 | // --------------------------
|
---|
[2899] | 623 | #ifdef USE_COMBINATION
|
---|
[2866] | 624 | if (_bncComb) {
|
---|
| 625 | _bncComb->processCorrLine(staID, line);
|
---|
| 626 | }
|
---|
[2899] | 627 | #endif
|
---|
[2866] | 628 |
|
---|
[1535] | 629 | bncSettings settings;
|
---|
[3109] | 630 | _waitCoTime = settings.value("corrTime").toInt();
|
---|
| 631 | if (_waitCoTime < 0) {
|
---|
| 632 | _waitCoTime = 0;
|
---|
[995] | 633 | }
|
---|
| 634 |
|
---|
[974] | 635 | // First time, set the _lastDumpSec immediately
|
---|
| 636 | // --------------------------------------------
|
---|
| 637 | if (_lastDumpCoSec == 0) {
|
---|
| 638 | _lastDumpCoSec = coTime - 1;
|
---|
| 639 | }
|
---|
| 640 |
|
---|
[975] | 641 | // An old correction - throw it away
|
---|
| 642 | // ---------------------------------
|
---|
[3109] | 643 | if (_waitCoTime > 0 && coTime <= _lastDumpCoSec) {
|
---|
[2916] | 644 | if (!_bncComb) {
|
---|
| 645 | QString line = staID + ": Correction for one sat neglected because overaged by " +
|
---|
| 646 | QString().sprintf(" %ld sec",
|
---|
| 647 | _lastDumpCoSec - coTime + _waitCoTime);
|
---|
| 648 | messagePrivate(line.toAscii());
|
---|
| 649 | emit( newMessage(line.toAscii(), true) );
|
---|
| 650 | }
|
---|
[975] | 651 | return;
|
---|
| 652 | }
|
---|
| 653 |
|
---|
| 654 | _corrs->insert(coTime, QString(line + " " + staID));
|
---|
| 655 |
|
---|
[976] | 656 | // Dump Corrections
|
---|
| 657 | // ----------------
|
---|
[3109] | 658 | if (_waitCoTime == 0) {
|
---|
| 659 | dumpCorrs();
|
---|
| 660 | }
|
---|
| 661 | else if (coTime - _waitCoTime > _lastDumpCoSec) {
|
---|
[976] | 662 | dumpCorrs(_lastDumpCoSec + 1, coTime - _waitCoTime);
|
---|
| 663 | _lastDumpCoSec = coTime - _waitCoTime;
|
---|
| 664 | }
|
---|
| 665 | }
|
---|
| 666 |
|
---|
| 667 | // Dump Complete Correction Epochs
|
---|
| 668 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 669 | void bncApp::dumpCorrs(long minTime, long maxTime) {
|
---|
| 670 | for (long sec = minTime; sec <= maxTime; sec++) {
|
---|
| 671 | QList<QString> allCorrs = _corrs->values(sec);
|
---|
[3109] | 672 | dumpCorrs(allCorrs);
|
---|
| 673 | _corrs->remove(sec);
|
---|
| 674 | }
|
---|
| 675 | }
|
---|
| 676 |
|
---|
| 677 | // Dump all corrections
|
---|
| 678 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 679 | void bncApp::dumpCorrs() {
|
---|
[3110] | 680 | QList<QString> allCorrs;
|
---|
| 681 | QMutableMapIterator<long, QString> it(*_corrs);
|
---|
| 682 | while (it.hasNext()) {
|
---|
| 683 | allCorrs << it.next().value();
|
---|
| 684 | it.remove();
|
---|
| 685 | }
|
---|
| 686 | dumpCorrs(allCorrs);
|
---|
[3109] | 687 | }
|
---|
| 688 |
|
---|
| 689 | // Dump List of Corrections
|
---|
| 690 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 691 | void bncApp::dumpCorrs(const QList<QString>& allCorrs) {
|
---|
| 692 | emit newCorrections(allCorrs);
|
---|
| 693 | if (_socketsCorr) {
|
---|
| 694 | QListIterator<QString> it(allCorrs);
|
---|
| 695 | while (it.hasNext()) {
|
---|
| 696 | QString corrLine = it.next() + "\n";
|
---|
| 697 |
|
---|
| 698 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
| 699 | while (is.hasNext()) {
|
---|
| 700 | QTcpSocket* sock = is.next();
|
---|
| 701 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
| 702 | if (sock->write(corrLine.toAscii()) == -1) {
|
---|
[976] | 703 | delete sock;
|
---|
| 704 | is.remove();
|
---|
| 705 | }
|
---|
| 706 | }
|
---|
[3109] | 707 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 708 | delete sock;
|
---|
| 709 | is.remove();
|
---|
| 710 | }
|
---|
[937] | 711 | }
|
---|
| 712 | }
|
---|
| 713 | }
|
---|
[936] | 714 | }
|
---|
[1538] | 715 |
|
---|
| 716 | //
|
---|
| 717 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 718 | void bncApp::setConfFileName(const QString& confFileName) {
|
---|
[4169] | 719 | if (confFileName.isEmpty()) {
|
---|
| 720 | _confFileName = QDir::homePath() + QDir::separator()
|
---|
| 721 | + ".config" + QDir::separator()
|
---|
| 722 | + organizationName() + QDir::separator()
|
---|
[4171] | 723 | + applicationName() + ".bnc";
|
---|
[1538] | 724 | }
|
---|
[4169] | 725 | else {
|
---|
| 726 | _confFileName = confFileName;
|
---|
| 727 | }
|
---|
[1538] | 728 | }
|
---|
[2385] | 729 |
|
---|
| 730 | // Raw Output
|
---|
| 731 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2518] | 732 | void bncApp::writeRawData(const QByteArray& data, const QByteArray& staID,
|
---|
| 733 | const QByteArray& format) {
|
---|
[2385] | 734 |
|
---|
[2386] | 735 | QMutexLocker locker(&_mutex);
|
---|
| 736 |
|
---|
[2519] | 737 | if (!_rawFile) {
|
---|
[2386] | 738 | bncSettings settings;
|
---|
[2519] | 739 | QByteArray fileName = settings.value("rawOutFile").toByteArray();
|
---|
| 740 | if (!fileName.isEmpty()) {
|
---|
[3524] | 741 | _rawFile = new bncRawFile(fileName, staID, bncRawFile::output);
|
---|
[2407] | 742 | }
|
---|
[2386] | 743 | }
|
---|
| 744 |
|
---|
[2519] | 745 | if (_rawFile) {
|
---|
| 746 | _rawFile->writeRawData(data, staID, format);
|
---|
[2386] | 747 | }
|
---|
[2385] | 748 | }
|
---|
[2672] | 749 |
|
---|
| 750 | // Get Glonass Slot Numbers from Global Array
|
---|
| 751 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 752 | void bncApp::getGlonassSlotNums(int GLOFreq[]) {
|
---|
| 753 |
|
---|
| 754 | QMutexLocker locker(&_mutex);
|
---|
| 755 |
|
---|
[2673] | 756 | for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
|
---|
| 757 | if (_GLOFreq[ii] != 0) {
|
---|
| 758 | GLOFreq[ii] = _GLOFreq[ii];
|
---|
| 759 | }
|
---|
| 760 | }
|
---|
[2672] | 761 | }
|
---|
| 762 |
|
---|
| 763 | // Store Glonass Slot Numbers to Global Array
|
---|
| 764 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 765 | void bncApp::storeGlonassSlotNums(const int GLOFreq[]) {
|
---|
| 766 |
|
---|
| 767 | QMutexLocker locker(&_mutex);
|
---|
| 768 |
|
---|
[2673] | 769 | for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
|
---|
| 770 | if (GLOFreq[ii] != 0) {
|
---|
| 771 | _GLOFreq[ii] = GLOFreq[ii];
|
---|
| 772 | }
|
---|
| 773 | }
|
---|
[2672] | 774 | }
|
---|
[2909] | 775 |
|
---|
| 776 | //
|
---|
| 777 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 778 | void bncApp::initCombination() {
|
---|
| 779 | #ifdef USE_COMBINATION
|
---|
| 780 | _bncComb = new bncComb();
|
---|
[3142] | 781 | if (_bncComb->nStreams() < 1) {
|
---|
[2909] | 782 | delete _bncComb;
|
---|
| 783 | _bncComb = 0;
|
---|
| 784 | }
|
---|
| 785 | #endif
|
---|
| 786 | }
|
---|
[3231] | 787 |
|
---|
| 788 | //
|
---|
| 789 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 790 | void bncApp::stopCombination() {
|
---|
| 791 | #ifdef USE_COMBINATION
|
---|
| 792 | delete _bncComb;
|
---|
| 793 | _bncComb = 0;
|
---|
| 794 | #endif
|
---|
| 795 | }
|
---|
[4167] | 796 |
|
---|
| 797 | // Handling Events (virtual)
|
---|
| 798 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 799 | bool bncApp::event(QEvent* ev) {
|
---|
| 800 |
|
---|
[4169] | 801 | if (ev->type() == QEvent::FileOpen) { // currently happens on Mac only
|
---|
[4167] | 802 | QString fileName = static_cast<QFileOpenEvent*>(ev)->file();
|
---|
[4168] | 803 | setConfFileName(fileName);
|
---|
[4167] | 804 | return true;
|
---|
| 805 | }
|
---|
| 806 |
|
---|
| 807 | return QApplication::event(ev);
|
---|
| 808 | }
|
---|
[4245] | 809 |
|
---|
| 810 | // Check Ephemeris Consistency
|
---|
| 811 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 812 | void bncApp::checkEphemeris(gpsephemeris* oldEph, gpsephemeris* newEph) {
|
---|
| 813 | if (oldEph->clock_bias != newEph->clock_bias ||
|
---|
| 814 | oldEph->clock_drift != newEph->clock_drift ||
|
---|
| 815 | oldEph->clock_driftrate != newEph->clock_driftrate) {
|
---|
| 816 | QString msg = currentDateAndTimeGPS().toString(Qt::ISODate) +
|
---|
| 817 | QString(" %1 EPH DIFFERS\n").arg(oldEph->satellite);
|
---|
| 818 | messagePrivate(msg.toAscii());
|
---|
| 819 | }
|
---|
| 820 | }
|
---|