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