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