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