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