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