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