[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>
|
---|
[642] | 44 | #include <unistd.h>
|
---|
[82] | 45 |
|
---|
| 46 | #include "bncapp.h"
|
---|
[151] | 47 | #include "bncutils.h"
|
---|
[647] | 48 | #include "bncrinex.h"
|
---|
[1535] | 49 | #include "bncsettings.h"
|
---|
[2011] | 50 | #include "bncversion.h"
|
---|
[82] | 51 |
|
---|
| 52 | using namespace std;
|
---|
| 53 |
|
---|
| 54 | // Constructor
|
---|
| 55 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1291] | 56 | bncApp::bncApp(int& argc, char* argv[], bool GUIenabled) :
|
---|
[82] | 57 | QApplication(argc, argv, GUIenabled) {
|
---|
[109] | 58 |
|
---|
[150] | 59 | _logFileFlag = 0;
|
---|
| 60 | _logFile = 0;
|
---|
| 61 | _logStream = 0;
|
---|
[621] | 62 | _caster = 0;
|
---|
[152] | 63 |
|
---|
[516] | 64 | // Lists of Ephemeris
|
---|
| 65 | // ------------------
|
---|
| 66 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
---|
| 67 | _gpsEph[ii-PRN_GPS_START] = 0;
|
---|
| 68 | }
|
---|
| 69 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
---|
| 70 | _glonassEph[ii-PRN_GLONASS_START] = 0;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[533] | 73 | // Eph file(s)
|
---|
| 74 | // -----------
|
---|
[534] | 75 | _rinexVers = 0;
|
---|
[533] | 76 | _ephFileGPS = 0;
|
---|
| 77 | _ephStreamGPS = 0;
|
---|
| 78 | _ephFileGlonass = 0;
|
---|
| 79 | _ephStreamGlonass = 0;
|
---|
[559] | 80 |
|
---|
[591] | 81 | _port = 0;
|
---|
[589] | 82 | _server = 0;
|
---|
| 83 | _sockets = 0;
|
---|
| 84 |
|
---|
[937] | 85 | _portCorr = 0;
|
---|
| 86 | _serverCorr = 0;
|
---|
| 87 | _socketsCorr = 0;
|
---|
| 88 |
|
---|
[2011] | 89 | _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
|
---|
[559] | 90 | #ifdef WIN32
|
---|
| 91 | _userName = QString("${USERNAME}");
|
---|
| 92 | #else
|
---|
| 93 | _userName = QString("${USER}");
|
---|
| 94 | #endif
|
---|
| 95 | expandEnvVar(_userName);
|
---|
| 96 | _userName = _userName.leftJustified(20, ' ', true);
|
---|
[973] | 97 |
|
---|
| 98 | _lastDumpCoSec = 0;
|
---|
[975] | 99 |
|
---|
| 100 | _corrs = new QMultiMap<long, QString>;
|
---|
[1155] | 101 |
|
---|
| 102 | _currentDateAndTimeGPS = 0;
|
---|
[82] | 103 | }
|
---|
| 104 |
|
---|
| 105 | // Destructor
|
---|
| 106 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 107 | bncApp::~bncApp() {
|
---|
[109] | 108 | delete _logStream;
|
---|
| 109 | delete _logFile;
|
---|
[533] | 110 | delete _ephStreamGPS;
|
---|
| 111 | delete _ephFileGPS;
|
---|
[589] | 112 | delete _server;
|
---|
| 113 | delete _sockets;
|
---|
[937] | 114 | delete _serverCorr;
|
---|
| 115 | delete _socketsCorr;
|
---|
[534] | 116 | if (_rinexVers == 2) {
|
---|
[533] | 117 | delete _ephStreamGlonass;
|
---|
| 118 | delete _ephFileGlonass;
|
---|
| 119 | }
|
---|
[516] | 120 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
---|
| 121 | delete _gpsEph[ii-PRN_GPS_START];
|
---|
| 122 | }
|
---|
| 123 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
---|
| 124 | delete _glonassEph[ii-PRN_GLONASS_START];
|
---|
| 125 | }
|
---|
[975] | 126 |
|
---|
| 127 | delete _corrs;
|
---|
[1156] | 128 |
|
---|
| 129 | delete _currentDateAndTimeGPS;
|
---|
[82] | 130 | }
|
---|
| 131 |
|
---|
| 132 | // Write a Program Message
|
---|
| 133 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1383] | 134 | void bncApp::slotMessage(QByteArray msg, bool showOnScreen) {
|
---|
[150] | 135 |
|
---|
[1218] | 136 | QMutexLocker locker(&_mutexMessage);
|
---|
[243] | 137 |
|
---|
[990] | 138 | messagePrivate(msg);
|
---|
[1299] | 139 | emit newMessage(msg, showOnScreen);
|
---|
[990] | 140 | }
|
---|
| 141 |
|
---|
| 142 | // Write a Program Message (private, no lock)
|
---|
| 143 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 144 | void bncApp::messagePrivate(const QByteArray& msg) {
|
---|
| 145 |
|
---|
[150] | 146 | // First time resolve the log file name
|
---|
| 147 | // ------------------------------------
|
---|
[1549] | 148 | QDate currDate = currentDateAndTimeGPS().date();
|
---|
| 149 | if (_logFileFlag == 0 || _fileDate != currDate) {
|
---|
| 150 | delete _logFile;
|
---|
[150] | 151 | _logFileFlag = 1;
|
---|
[1535] | 152 | bncSettings settings;
|
---|
[150] | 153 | QString logFileName = settings.value("logFile").toString();
|
---|
| 154 | if ( !logFileName.isEmpty() ) {
|
---|
[151] | 155 | expandEnvVar(logFileName);
|
---|
[1549] | 156 | _logFile = new QFile(logFileName + "_" +
|
---|
| 157 | currDate.toString("yyMMdd").toAscii().data());
|
---|
| 158 | _fileDate = currDate;
|
---|
[275] | 159 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
| 160 | _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
---|
| 161 | }
|
---|
| 162 | else {
|
---|
| 163 | _logFile->open(QIODevice::WriteOnly);
|
---|
| 164 | }
|
---|
[150] | 165 | _logStream = new QTextStream();
|
---|
| 166 | _logStream->setDevice(_logFile);
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 |
|
---|
[109] | 170 | if (_logStream) {
|
---|
[1154] | 171 | *_logStream << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
|
---|
[109] | 172 | *_logStream << msg.data() << endl;
|
---|
| 173 | _logStream->flush();
|
---|
[82] | 174 | }
|
---|
| 175 | }
|
---|
[511] | 176 |
|
---|
[535] | 177 | // New GPS Ephemeris
|
---|
[511] | 178 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 179 | void bncApp::slotNewGPSEph(gpsephemeris* gpseph) {
|
---|
[516] | 180 |
|
---|
| 181 | QMutexLocker locker(&_mutex);
|
---|
| 182 |
|
---|
[1044] | 183 | gpsephemeris copy_gpseph = *gpseph;
|
---|
| 184 | emit newEphGPS(copy_gpseph);
|
---|
| 185 |
|
---|
[534] | 186 | printEphHeader();
|
---|
| 187 |
|
---|
[532] | 188 | gpsephemeris** ee = &_gpsEph[gpseph->satellite-1];
|
---|
[1218] | 189 |
|
---|
[538] | 190 | if ( *ee == 0 ||
|
---|
| 191 | gpseph->GPSweek > (*ee)->GPSweek ||
|
---|
[594] | 192 | (gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC > (*ee)->TOC) ) {
|
---|
[516] | 193 | delete *ee;
|
---|
| 194 | *ee = gpseph;
|
---|
[600] | 195 | printGPSEph(gpseph, true);
|
---|
[516] | 196 | }
|
---|
| 197 | else {
|
---|
[600] | 198 | printGPSEph(gpseph, false);
|
---|
[516] | 199 | delete gpseph;
|
---|
| 200 | }
|
---|
[511] | 201 | }
|
---|
| 202 |
|
---|
[535] | 203 | // New Glonass Ephemeris
|
---|
[511] | 204 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 205 | void bncApp::slotNewGlonassEph(glonassephemeris* glonasseph) {
|
---|
[516] | 206 |
|
---|
| 207 | QMutexLocker locker(&_mutex);
|
---|
| 208 |
|
---|
[1164] | 209 | glonassephemeris copy_glonasseph = *glonasseph;
|
---|
| 210 | emit newEphGlonass(copy_glonasseph);
|
---|
| 211 |
|
---|
[534] | 212 | printEphHeader();
|
---|
| 213 |
|
---|
[532] | 214 | glonassephemeris** ee = &_glonassEph[glonasseph->almanac_number-1];
|
---|
[531] | 215 |
|
---|
[578] | 216 | int wwOld, towOld, wwNew, towNew;
|
---|
[577] | 217 | if (*ee != 0) {
|
---|
[578] | 218 | wwOld = (*ee)->GPSWeek;
|
---|
| 219 | towOld = (*ee)->GPSTOW;
|
---|
[2257] | 220 | updatetime(&wwOld, &towOld, (*ee)->tb*1000, 0); // Moscow -> GPS
|
---|
[577] | 221 |
|
---|
[578] | 222 | wwNew = glonasseph->GPSWeek;
|
---|
| 223 | towNew = glonasseph->GPSTOW;
|
---|
[2257] | 224 | updatetime(&wwNew, &towNew, glonasseph->tb*1000, 0); // Moscow -> GPS
|
---|
[577] | 225 | }
|
---|
| 226 |
|
---|
[578] | 227 | if ( *ee == 0 ||
|
---|
| 228 | wwNew > wwOld ||
|
---|
| 229 | (wwNew == wwOld && towNew > towOld) ) {
|
---|
[531] | 230 | delete *ee;
|
---|
| 231 | *ee = glonasseph;
|
---|
[600] | 232 | printGlonassEph(glonasseph, true);
|
---|
[531] | 233 | }
|
---|
| 234 | else {
|
---|
[600] | 235 | printGlonassEph(glonasseph, false);
|
---|
[531] | 236 | delete glonasseph;
|
---|
| 237 | }
|
---|
[511] | 238 | }
|
---|
| 239 |
|
---|
[535] | 240 | // Print Header of the output File(s)
|
---|
[516] | 241 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 242 | void bncApp::printEphHeader() {
|
---|
[528] | 243 |
|
---|
[1535] | 244 | bncSettings settings;
|
---|
[535] | 245 |
|
---|
[534] | 246 | // Initialization
|
---|
| 247 | // --------------
|
---|
| 248 | if (_rinexVers == 0) {
|
---|
[528] | 249 |
|
---|
[533] | 250 | if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
|
---|
[534] | 251 | _rinexVers = 3;
|
---|
[533] | 252 | }
|
---|
| 253 | else {
|
---|
[534] | 254 | _rinexVers = 2;
|
---|
[533] | 255 | }
|
---|
[529] | 256 |
|
---|
[533] | 257 | _ephPath = settings.value("ephPath").toString();
|
---|
| 258 |
|
---|
| 259 | if ( !_ephPath.isEmpty() ) {
|
---|
| 260 | if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
|
---|
| 261 | _ephPath += QDir::separator();
|
---|
| 262 | }
|
---|
| 263 | expandEnvVar(_ephPath);
|
---|
| 264 | }
|
---|
[517] | 265 | }
|
---|
[533] | 266 |
|
---|
[534] | 267 | // (Re-)Open output File(s)
|
---|
| 268 | // ------------------------
|
---|
[533] | 269 | if (!_ephPath.isEmpty()) {
|
---|
| 270 |
|
---|
[1154] | 271 | QDateTime datTim = currentDateAndTimeGPS();
|
---|
[533] | 272 |
|
---|
[583] | 273 | QString ephFileNameGPS = _ephPath + "BRDC" +
|
---|
[563] | 274 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'));
|
---|
[533] | 275 |
|
---|
[647] | 276 | QString hlpStr = bncRinex::nextEpochStr(datTim,
|
---|
| 277 | settings.value("ephIntr").toString());
|
---|
[584] | 278 |
|
---|
[575] | 279 | if (_rinexVers == 3) {
|
---|
| 280 | ephFileNameGPS += hlpStr + datTim.toString(".yyP");
|
---|
| 281 | }
|
---|
| 282 | else {
|
---|
| 283 | ephFileNameGPS += hlpStr + datTim.toString(".yyN");
|
---|
| 284 | }
|
---|
[563] | 285 |
|
---|
[533] | 286 | if (_ephFileNameGPS == ephFileNameGPS) {
|
---|
| 287 | return;
|
---|
| 288 | }
|
---|
| 289 | else {
|
---|
| 290 | _ephFileNameGPS = ephFileNameGPS;
|
---|
| 291 | }
|
---|
| 292 |
|
---|
[575] | 293 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
---|
| 294 | delete _gpsEph[ii-PRN_GPS_START];
|
---|
| 295 | _gpsEph[ii-PRN_GPS_START] = 0;
|
---|
| 296 | }
|
---|
| 297 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
---|
| 298 | delete _glonassEph[ii-PRN_GLONASS_START];
|
---|
| 299 | _glonassEph[ii-PRN_GLONASS_START] = 0;
|
---|
| 300 | }
|
---|
| 301 |
|
---|
[533] | 302 | delete _ephStreamGPS;
|
---|
| 303 | delete _ephFileGPS;
|
---|
| 304 |
|
---|
[535] | 305 | QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
|
---|
[536] | 306 | QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
|
---|
| 307 |
|
---|
[535] | 308 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
---|
| 309 | QFile::exists(ephFileNameGPS) ) {
|
---|
| 310 | appendFlagGPS = QIODevice::Append;
|
---|
| 311 | }
|
---|
| 312 |
|
---|
[533] | 313 | _ephFileGPS = new QFile(ephFileNameGPS);
|
---|
[535] | 314 | _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
|
---|
[533] | 315 | _ephStreamGPS = new QTextStream();
|
---|
| 316 | _ephStreamGPS->setDevice(_ephFileGPS);
|
---|
| 317 |
|
---|
[534] | 318 | if (_rinexVers == 3) {
|
---|
[533] | 319 | _ephFileGlonass = _ephFileGPS;
|
---|
| 320 | _ephStreamGlonass = _ephStreamGPS;
|
---|
| 321 | }
|
---|
[534] | 322 | else if (_rinexVers == 2) {
|
---|
[583] | 323 | QString ephFileNameGlonass = _ephPath + "BRDC" +
|
---|
[563] | 324 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
[575] | 325 | hlpStr + datTim.toString(".yyG");
|
---|
[533] | 326 |
|
---|
| 327 | delete _ephStreamGlonass;
|
---|
| 328 | delete _ephFileGlonass;
|
---|
| 329 |
|
---|
[535] | 330 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
---|
| 331 | QFile::exists(ephFileNameGlonass) ) {
|
---|
| 332 | appendFlagGlonass = QIODevice::Append;
|
---|
| 333 | }
|
---|
| 334 |
|
---|
[533] | 335 | _ephFileGlonass = new QFile(ephFileNameGlonass);
|
---|
[535] | 336 | _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
|
---|
[533] | 337 | _ephStreamGlonass = new QTextStream();
|
---|
| 338 | _ephStreamGlonass->setDevice(_ephFileGlonass);
|
---|
| 339 | }
|
---|
| 340 |
|
---|
[534] | 341 | // Header - RINEX Version 3
|
---|
| 342 | // ------------------------
|
---|
| 343 | if (_rinexVers == 3) {
|
---|
[537] | 344 | if ( ! (appendFlagGPS & QIODevice::Append)) {
|
---|
| 345 | QString line;
|
---|
| 346 | line.sprintf(
|
---|
| 347 | "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
|
---|
| 348 | 3.0, "", "");
|
---|
| 349 | *_ephStreamGPS << line;
|
---|
| 350 |
|
---|
[1154] | 351 | QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
|
---|
[559] | 352 | *_ephStreamGPS << _pgmName.toAscii().data()
|
---|
| 353 | << _userName.toAscii().data()
|
---|
| 354 | << hlp.toAscii().data()
|
---|
| 355 | << "PGM / RUN BY / DATE" << endl;
|
---|
| 356 |
|
---|
| 357 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
[537] | 358 | *_ephStreamGPS << line;
|
---|
| 359 |
|
---|
| 360 | _ephStreamGPS->flush();
|
---|
[535] | 361 | }
|
---|
[533] | 362 | }
|
---|
| 363 |
|
---|
[536] | 364 | // Headers - RINEX Version 2
|
---|
| 365 | // -------------------------
|
---|
[534] | 366 | else if (_rinexVers == 2) {
|
---|
[536] | 367 | if (! (appendFlagGPS & QIODevice::Append)) {
|
---|
| 368 | QString line;
|
---|
| 369 | line.sprintf(
|
---|
[565] | 370 | "%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n", 2.11, "", "");
|
---|
[536] | 371 | *_ephStreamGPS << line;
|
---|
| 372 |
|
---|
[1154] | 373 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
[559] | 374 | *_ephStreamGPS << _pgmName.toAscii().data()
|
---|
| 375 | << _userName.toAscii().data()
|
---|
| 376 | << hlp.toAscii().data()
|
---|
| 377 | << "PGM / RUN BY / DATE" << endl;
|
---|
| 378 |
|
---|
| 379 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
[536] | 380 | *_ephStreamGPS << line;
|
---|
[537] | 381 |
|
---|
| 382 | _ephStreamGPS->flush();
|
---|
[536] | 383 | }
|
---|
| 384 | if (! (appendFlagGlonass & QIODevice::Append)) {
|
---|
| 385 | QString line;
|
---|
| 386 | line.sprintf(
|
---|
[582] | 387 | "%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",2.11,"","");
|
---|
[536] | 388 | *_ephStreamGlonass << line;
|
---|
| 389 |
|
---|
[1154] | 390 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
[559] | 391 | *_ephStreamGlonass << _pgmName.toAscii().data()
|
---|
| 392 | << _userName.toAscii().data()
|
---|
| 393 | << hlp.toAscii().data()
|
---|
| 394 | << "PGM / RUN BY / DATE" << endl;
|
---|
| 395 |
|
---|
| 396 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
[536] | 397 | *_ephStreamGlonass << line;
|
---|
[537] | 398 |
|
---|
| 399 | _ephStreamGlonass->flush();
|
---|
[536] | 400 | }
|
---|
[533] | 401 | }
|
---|
| 402 | }
|
---|
[516] | 403 | }
|
---|
| 404 |
|
---|
[535] | 405 | // Print One GPS Ephemeris
|
---|
[516] | 406 | ////////////////////////////////////////////////////////////////////////////
|
---|
[600] | 407 | void bncApp::printGPSEph(gpsephemeris* ep, bool printFile) {
|
---|
[519] | 408 |
|
---|
[941] | 409 | QString lineV2;
|
---|
| 410 | QString lineV3;
|
---|
[533] | 411 |
|
---|
[590] | 412 | struct converttimeinfo cti;
|
---|
| 413 | converttime(&cti, ep->GPSweek, ep->TOC);
|
---|
[941] | 414 |
|
---|
| 415 | lineV3.sprintf("G%02d %04d %02d %02d %02d %02d %02d %18.11e %18.11e %18.11e\n",
|
---|
[589] | 416 | ep->satellite, cti.year, cti.month, cti.day, cti.hour,
|
---|
| 417 | cti.minute, cti.second, ep->clock_bias, ep->clock_drift,
|
---|
| 418 | ep->clock_driftrate);
|
---|
[941] | 419 |
|
---|
| 420 | lineV2.sprintf("%02d %02d %02d %02d %02d %02d%5.1f %18.11e %18.11e %18.11e\n",
|
---|
[590] | 421 | ep->satellite, cti.year%100, cti.month, cti.day, cti.hour,
|
---|
| 422 | cti.minute, (double) cti.second, ep->clock_bias,
|
---|
| 423 | ep->clock_drift, ep->clock_driftrate);
|
---|
[520] | 424 |
|
---|
[941] | 425 | QString line;
|
---|
| 426 | QByteArray allLines;
|
---|
| 427 |
|
---|
[1316] | 428 | QByteArray fmt;
|
---|
[1321] | 429 | QByteArray fmt2;
|
---|
[1316] | 430 | if (_rinexVers == 2) {
|
---|
[1321] | 431 | fmt = " %18.11e %18.11e %18.11e %18.11e\n";
|
---|
| 432 | fmt2 = " %18.11e %18.11e\n";
|
---|
[1316] | 433 | }
|
---|
| 434 | else {
|
---|
[1321] | 435 | fmt = " %18.11e %18.11e %18.11e %18.11e\n";
|
---|
| 436 | fmt2 = " %18.11e %18.11e\n";
|
---|
[1316] | 437 | }
|
---|
| 438 |
|
---|
| 439 | line.sprintf(fmt.data(), (double)ep->IODE, ep->Crs, ep->Delta_n, ep->M0);
|
---|
[590] | 440 | allLines += line;
|
---|
| 441 |
|
---|
[1316] | 442 | line.sprintf(fmt.data(), ep->Cuc, ep->e, ep->Cus, ep->sqrt_A);
|
---|
[590] | 443 | allLines += line;
|
---|
[520] | 444 |
|
---|
[1316] | 445 | line.sprintf(fmt.data(), (double) ep->TOE, ep->Cic, ep->OMEGA0, ep->Cis);
|
---|
[590] | 446 | allLines += line;
|
---|
| 447 |
|
---|
[1316] | 448 | line.sprintf(fmt.data(), ep->i0, ep->Crc, ep->omega, ep->OMEGADOT);
|
---|
[590] | 449 | allLines += line;
|
---|
[520] | 450 |
|
---|
[590] | 451 | double dd = 0;
|
---|
| 452 | unsigned long ii = ep->flags;
|
---|
| 453 | if(ii & GPSEPHF_L2CACODE)
|
---|
| 454 | dd += 2.0;
|
---|
| 455 | if(ii & GPSEPHF_L2PCODE)
|
---|
| 456 | dd += 1.0;
|
---|
[1316] | 457 | line.sprintf(fmt.data(), ep->IDOT, dd, (double) ep->GPSweek,
|
---|
| 458 | ii & GPSEPHF_L2PCODEDATA ? 1.0 : 0.0);
|
---|
[590] | 459 | allLines += line;
|
---|
[520] | 460 |
|
---|
[590] | 461 | if(ep->URAindex <= 6) /* URA index */
|
---|
| 462 | dd = ceil(10.0*pow(2.0, 1.0+((double)ep->URAindex)/2.0))/10.0;
|
---|
| 463 | else
|
---|
| 464 | dd = ceil(10.0*pow(2.0, ((double)ep->URAindex)/2.0))/10.0;
|
---|
[1316] | 465 | line.sprintf(fmt.data(), dd, ((double) ep->SVhealth), ep->TGD,
|
---|
| 466 | ((double) ep->IODC));
|
---|
[590] | 467 | allLines += line;
|
---|
[519] | 468 |
|
---|
[1321] | 469 | line.sprintf(fmt2.data(), ((double)ep->TOW), 0.0);
|
---|
[590] | 470 | allLines += line;
|
---|
[519] | 471 |
|
---|
[943] | 472 | printOutput(printFile, _ephStreamGPS, lineV2, lineV3, allLines);
|
---|
[516] | 473 | }
|
---|
| 474 |
|
---|
[535] | 475 | // Print One Glonass Ephemeris
|
---|
[516] | 476 | ////////////////////////////////////////////////////////////////////////////
|
---|
[600] | 477 | void bncApp::printGlonassEph(glonassephemeris* ep, bool printFile) {
|
---|
[523] | 478 |
|
---|
[590] | 479 | int ww = ep->GPSWeek;
|
---|
| 480 | int tow = ep->GPSTOW;
|
---|
| 481 | struct converttimeinfo cti;
|
---|
[523] | 482 |
|
---|
[2257] | 483 | updatetime(&ww, &tow, ep->tb*1000, 1); // Moscow -> UTC
|
---|
[590] | 484 | converttime(&cti, ww, tow);
|
---|
[525] | 485 |
|
---|
[885] | 486 | int tk = ep->tk-3*60*60;
|
---|
| 487 | if (tk < 0) {
|
---|
| 488 | tk += 86400;
|
---|
[590] | 489 | }
|
---|
[525] | 490 |
|
---|
[941] | 491 | QString lineV2;
|
---|
| 492 | QString lineV3;
|
---|
| 493 |
|
---|
| 494 | lineV3.sprintf("R%02d %04d %02d %02d %02d %02d %02d %18.11e %18.11e %18.11e\n",
|
---|
[590] | 495 | ep->almanac_number, cti.year, cti.month, cti.day, cti.hour,
|
---|
[885] | 496 | cti.minute, cti.second, -ep->tau, ep->gamma, (double) tk);
|
---|
[941] | 497 |
|
---|
| 498 | lineV2.sprintf("%02d %02d %02d %02d %02d %02d%5.1f %18.11e %18.11e %18.11e\n",
|
---|
[590] | 499 | ep->almanac_number, cti.year%100, cti.month, cti.day,
|
---|
| 500 | cti.hour, cti.minute, (double) cti.second, -ep->tau,
|
---|
[885] | 501 | ep->gamma, (double) tk);
|
---|
[590] | 502 |
|
---|
[941] | 503 | QString line;
|
---|
| 504 | QByteArray allLines;
|
---|
| 505 |
|
---|
[1316] | 506 | QByteArray fmt;
|
---|
| 507 | if (_rinexVers == 2) {
|
---|
| 508 | fmt = " %18.11e %18.11e %18.11e %18.11e\n";
|
---|
| 509 | }
|
---|
| 510 | else {
|
---|
| 511 | fmt = " %18.11e %18.11e %18.11e %18.11e\n";
|
---|
| 512 | }
|
---|
| 513 |
|
---|
| 514 | line.sprintf(fmt.data(), ep->x_pos, ep->x_velocity, ep->x_acceleration,
|
---|
[590] | 515 | (ep->flags & GLOEPHF_UNHEALTHY) ? 1.0 : 0.0);
|
---|
| 516 | allLines += line;
|
---|
| 517 |
|
---|
[1316] | 518 | line.sprintf(fmt.data(), ep->y_pos, ep->y_velocity, ep->y_acceleration,
|
---|
[590] | 519 | (double) ep->frequency_number);
|
---|
| 520 | allLines += line;
|
---|
| 521 |
|
---|
[1316] | 522 | line.sprintf(fmt.data(), ep->z_pos, ep->z_velocity, ep->z_acceleration,
|
---|
| 523 | (double) ep->E);
|
---|
[590] | 524 | allLines += line;
|
---|
[525] | 525 |
|
---|
[943] | 526 | printOutput(printFile, _ephStreamGlonass, lineV2, lineV3, allLines);
|
---|
[941] | 527 | }
|
---|
| 528 |
|
---|
| 529 | // Output
|
---|
| 530 | ////////////////////////////////////////////////////////////////////////////
|
---|
[943] | 531 | void bncApp::printOutput(bool printFile, QTextStream* stream,
|
---|
| 532 | const QString& lineV2,
|
---|
[941] | 533 | const QString& lineV3,
|
---|
| 534 | const QByteArray& allLines) {
|
---|
[590] | 535 | // Output into file
|
---|
| 536 | // ----------------
|
---|
[943] | 537 | if (printFile && stream) {
|
---|
[941] | 538 | if (_rinexVers == 2) {
|
---|
[943] | 539 | *stream << lineV2.toAscii();
|
---|
[941] | 540 | }
|
---|
| 541 | else {
|
---|
[943] | 542 | *stream << lineV3.toAscii();
|
---|
[941] | 543 | }
|
---|
[943] | 544 | *stream << allLines;
|
---|
| 545 | stream->flush();
|
---|
[517] | 546 | }
|
---|
[590] | 547 |
|
---|
| 548 | // Output into the socket
|
---|
| 549 | // ----------------------
|
---|
| 550 | if (_sockets) {
|
---|
[642] | 551 | QMutableListIterator<QTcpSocket*> is(*_sockets);
|
---|
[590] | 552 | while (is.hasNext()) {
|
---|
| 553 | QTcpSocket* sock = is.next();
|
---|
| 554 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
[941] | 555 | if (sock->write(lineV3.toAscii()) == -1 ||
|
---|
| 556 | sock->write(allLines) == -1) {
|
---|
[642] | 557 | delete sock;
|
---|
| 558 | is.remove();
|
---|
| 559 | }
|
---|
[590] | 560 | }
|
---|
[642] | 561 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
| 562 | delete sock;
|
---|
| 563 | is.remove();
|
---|
| 564 | }
|
---|
[590] | 565 | }
|
---|
| 566 | }
|
---|
[516] | 567 | }
|
---|
[589] | 568 |
|
---|
[591] | 569 | // Set Port Number
|
---|
| 570 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 571 | void bncApp::setPort(int port) {
|
---|
| 572 | _port = port;
|
---|
| 573 | if (_port != 0) {
|
---|
[942] | 574 | delete _server;
|
---|
[591] | 575 | _server = new QTcpServer;
|
---|
[1228] | 576 | if ( !_server->listen(QHostAddress::Any, _port) ) {
|
---|
[1451] | 577 | slotMessage("bncApp: Cannot listen on ephemeris port", true);
|
---|
[1228] | 578 | }
|
---|
[591] | 579 | connect(_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
|
---|
[942] | 580 | delete _sockets;
|
---|
[591] | 581 | _sockets = new QList<QTcpSocket*>;
|
---|
| 582 | }
|
---|
| 583 | }
|
---|
| 584 |
|
---|
[937] | 585 | // Set Port Number
|
---|
| 586 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 587 | void bncApp::setPortCorr(int port) {
|
---|
| 588 | _portCorr = port;
|
---|
| 589 | if (_portCorr != 0) {
|
---|
[942] | 590 | delete _serverCorr;
|
---|
[937] | 591 | _serverCorr = new QTcpServer;
|
---|
[1228] | 592 | if ( !_serverCorr->listen(QHostAddress::Any, _portCorr) ) {
|
---|
[1451] | 593 | slotMessage("bncApp: Cannot listen on correction port", true);
|
---|
[1228] | 594 | }
|
---|
[937] | 595 | connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
|
---|
[942] | 596 | delete _socketsCorr;
|
---|
[937] | 597 | _socketsCorr = new QList<QTcpSocket*>;
|
---|
| 598 | }
|
---|
| 599 | }
|
---|
| 600 |
|
---|
[589] | 601 | // New Connection
|
---|
| 602 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 603 | void bncApp::slotNewConnection() {
|
---|
| 604 | _sockets->push_back( _server->nextPendingConnection() );
|
---|
| 605 | }
|
---|
| 606 |
|
---|
[937] | 607 | // New Connection
|
---|
| 608 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 609 | void bncApp::slotNewConnectionCorr() {
|
---|
| 610 | _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
|
---|
| 611 | }
|
---|
| 612 |
|
---|
[621] | 613 | //
|
---|
| 614 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 615 | void bncApp::slotQuit() {
|
---|
[1029] | 616 | cout << "bncApp::slotQuit" << endl;
|
---|
[621] | 617 | delete _caster;
|
---|
| 618 | quit();
|
---|
| 619 | }
|
---|
| 620 |
|
---|
[936] | 621 | //
|
---|
| 622 | ////////////////////////////////////////////////////////////////////////////
|
---|
[974] | 623 | void bncApp::slotNewCorrLine(QString line, QString staID, long coTime) {
|
---|
| 624 |
|
---|
| 625 | QMutexLocker locker(&_mutex);
|
---|
| 626 |
|
---|
[1535] | 627 | bncSettings settings;
|
---|
[995] | 628 | _waitCoTime = settings.value("corrTime").toInt();
|
---|
| 629 | if (_waitCoTime < 1) {
|
---|
| 630 | _waitCoTime = 1;
|
---|
| 631 | }
|
---|
| 632 |
|
---|
[974] | 633 | // First time, set the _lastDumpSec immediately
|
---|
| 634 | // --------------------------------------------
|
---|
| 635 | if (_lastDumpCoSec == 0) {
|
---|
| 636 | _lastDumpCoSec = coTime - 1;
|
---|
| 637 | }
|
---|
| 638 |
|
---|
[975] | 639 | // An old correction - throw it away
|
---|
| 640 | // ---------------------------------
|
---|
| 641 | if (coTime <= _lastDumpCoSec) {
|
---|
[1236] | 642 | QString line = staID + ": Correction for one sat neglected because overaged by " +
|
---|
[1035] | 643 | QString().sprintf(" %ld sec",
|
---|
[990] | 644 | _lastDumpCoSec - coTime + _waitCoTime);
|
---|
[991] | 645 | messagePrivate(line.toAscii());
|
---|
[1299] | 646 | emit( newMessage(line.toAscii(), true) );
|
---|
[975] | 647 | return;
|
---|
| 648 | }
|
---|
| 649 |
|
---|
| 650 | _corrs->insert(coTime, QString(line + " " + staID));
|
---|
| 651 |
|
---|
[976] | 652 | // Dump Corrections
|
---|
| 653 | // ----------------
|
---|
| 654 | if (coTime - _waitCoTime > _lastDumpCoSec) {
|
---|
| 655 | dumpCorrs(_lastDumpCoSec + 1, coTime - _waitCoTime);
|
---|
| 656 | _lastDumpCoSec = coTime - _waitCoTime;
|
---|
| 657 | }
|
---|
| 658 | }
|
---|
| 659 |
|
---|
| 660 | // Dump Complete Correction Epochs
|
---|
| 661 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 662 | void bncApp::dumpCorrs(long minTime, long maxTime) {
|
---|
| 663 |
|
---|
| 664 | for (long sec = minTime; sec <= maxTime; sec++) {
|
---|
| 665 | QList<QString> allCorrs = _corrs->values(sec);
|
---|
[2001] | 666 | emit newCorrections(allCorrs);
|
---|
[2105] | 667 | if (_socketsCorr) {
|
---|
| 668 | QListIterator<QString> it(allCorrs);
|
---|
| 669 | while (it.hasNext()) {
|
---|
| 670 | QString corrLine = it.next() + "\n";
|
---|
| 671 |
|
---|
| 672 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
| 673 | while (is.hasNext()) {
|
---|
| 674 | QTcpSocket* sock = is.next();
|
---|
| 675 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
| 676 | if (sock->write(corrLine.toAscii()) == -1) {
|
---|
| 677 | delete sock;
|
---|
| 678 | is.remove();
|
---|
| 679 | }
|
---|
| 680 | }
|
---|
| 681 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
[976] | 682 | delete sock;
|
---|
| 683 | is.remove();
|
---|
| 684 | }
|
---|
| 685 | }
|
---|
[937] | 686 | }
|
---|
| 687 | }
|
---|
[976] | 688 | _corrs->remove(sec);
|
---|
[937] | 689 | }
|
---|
[936] | 690 | }
|
---|
[1538] | 691 |
|
---|
| 692 | //
|
---|
| 693 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 694 | void bncApp::setConfFileName(const QString& confFileName) {
|
---|
| 695 | if (confFileName.isEmpty()) {
|
---|
[1539] | 696 | _confFileName = QDir::homePath() + QDir::separator()
|
---|
| 697 | + ".config" + QDir::separator()
|
---|
| 698 | + organizationName() + QDir::separator()
|
---|
| 699 | + applicationName() + ".ini";
|
---|
[1538] | 700 | }
|
---|
| 701 | else {
|
---|
| 702 | _confFileName = confFileName;
|
---|
| 703 | }
|
---|
| 704 | }
|
---|