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