| 1 | // Part of BNC, a utility for retrieving decoding and
|
|---|
| 2 | // converting GNSS data streams from NTRIP broadcasters.
|
|---|
| 3 | //
|
|---|
| 4 | // Copyright (C) 2007
|
|---|
| 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
|---|
| 6 | // http://www.bkg.bund.de
|
|---|
| 7 | // Czech Technical University Prague, Department of Geodesy
|
|---|
| 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.
|
|---|
| 24 |
|
|---|
| 25 | /* -------------------------------------------------------------------------
|
|---|
| 26 | * BKG NTRIP Client
|
|---|
| 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 |
|
|---|
| 41 | #include <iostream>
|
|---|
| 42 | #include <QSettings>
|
|---|
| 43 | #include <QMessageBox>
|
|---|
| 44 | #include <cmath>
|
|---|
| 45 | #include <unistd.h>
|
|---|
| 46 |
|
|---|
| 47 | #include "bncapp.h"
|
|---|
| 48 | #include "bncutils.h"
|
|---|
| 49 | #include "bncrinex.h"
|
|---|
| 50 |
|
|---|
| 51 | using namespace std;
|
|---|
| 52 |
|
|---|
| 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 |
|
|---|
| 67 | // Constructor
|
|---|
| 68 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 69 | bncApp::bncApp(int argc, char* argv[], bool GUIenabled) :
|
|---|
| 70 | QApplication(argc, argv, GUIenabled) {
|
|---|
| 71 |
|
|---|
| 72 | _bncVersion = "BNC 1.6";
|
|---|
| 73 |
|
|---|
| 74 | _logFileFlag = 0;
|
|---|
| 75 | _logFile = 0;
|
|---|
| 76 | _logStream = 0;
|
|---|
| 77 | _caster = 0;
|
|---|
| 78 |
|
|---|
| 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 |
|
|---|
| 88 | // Eph file(s)
|
|---|
| 89 | // -----------
|
|---|
| 90 | _rinexVers = 0;
|
|---|
| 91 | _ephFileGPS = 0;
|
|---|
| 92 | _ephStreamGPS = 0;
|
|---|
| 93 | _ephFileGlonass = 0;
|
|---|
| 94 | _ephStreamGlonass = 0;
|
|---|
| 95 |
|
|---|
| 96 | _port = 0;
|
|---|
| 97 | _server = 0;
|
|---|
| 98 | _sockets = 0;
|
|---|
| 99 |
|
|---|
| 100 | _portCorr = 0;
|
|---|
| 101 | _serverCorr = 0;
|
|---|
| 102 | _socketsCorr = 0;
|
|---|
| 103 |
|
|---|
| 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);
|
|---|
| 112 |
|
|---|
| 113 | _lastDumpCoSec = 0;
|
|---|
| 114 |
|
|---|
| 115 | _corrs = new QMultiMap<long, QString>;
|
|---|
| 116 |
|
|---|
| 117 | _currentDateAndTimeGPS = 0;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | // Destructor
|
|---|
| 121 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 122 | bncApp::~bncApp() {
|
|---|
| 123 | delete _logStream;
|
|---|
| 124 | delete _logFile;
|
|---|
| 125 | delete _ephStreamGPS;
|
|---|
| 126 | delete _ephFileGPS;
|
|---|
| 127 | delete _server;
|
|---|
| 128 | delete _sockets;
|
|---|
| 129 | delete _serverCorr;
|
|---|
| 130 | delete _socketsCorr;
|
|---|
| 131 | if (_rinexVers == 2) {
|
|---|
| 132 | delete _ephStreamGlonass;
|
|---|
| 133 | delete _ephFileGlonass;
|
|---|
| 134 | }
|
|---|
| 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 | }
|
|---|
| 141 |
|
|---|
| 142 | delete _corrs;
|
|---|
| 143 |
|
|---|
| 144 | delete _currentDateAndTimeGPS;
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | // Write a Program Message
|
|---|
| 148 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 149 | void bncApp::slotMessage(const QByteArray msg) {
|
|---|
| 150 |
|
|---|
| 151 | QMutexLocker locker(&_mutexMessage);
|
|---|
| 152 |
|
|---|
| 153 | messagePrivate(msg);
|
|---|
| 154 | emit newMessage(msg);
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | // Write a Program Message (private, no lock)
|
|---|
| 158 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 159 | void bncApp::messagePrivate(const QByteArray& msg) {
|
|---|
| 160 |
|
|---|
| 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() ) {
|
|---|
| 168 | expandEnvVar(logFileName);
|
|---|
| 169 | _logFile = new QFile(logFileName);
|
|---|
| 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 | }
|
|---|
| 176 | _logStream = new QTextStream();
|
|---|
| 177 | _logStream->setDevice(_logFile);
|
|---|
| 178 | }
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | if (_logStream) {
|
|---|
| 182 | *_logStream << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
|
|---|
| 183 | *_logStream << msg.data() << endl;
|
|---|
| 184 | _logStream->flush();
|
|---|
| 185 | }
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | // New GPS Ephemeris
|
|---|
| 189 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 190 | void bncApp::slotNewGPSEph(gpsephemeris* gpseph) {
|
|---|
| 191 |
|
|---|
| 192 | QMutexLocker locker(&_mutex);
|
|---|
| 193 |
|
|---|
| 194 | gpsephemeris copy_gpseph = *gpseph;
|
|---|
| 195 | emit newEphGPS(copy_gpseph);
|
|---|
| 196 |
|
|---|
| 197 | printEphHeader();
|
|---|
| 198 |
|
|---|
| 199 | gpsephemeris** ee = &_gpsEph[gpseph->satellite-1];
|
|---|
| 200 |
|
|---|
| 201 | if ( *ee == 0 ||
|
|---|
| 202 | gpseph->GPSweek > (*ee)->GPSweek ||
|
|---|
| 203 | (gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC > (*ee)->TOC) ) {
|
|---|
| 204 | delete *ee;
|
|---|
| 205 | *ee = gpseph;
|
|---|
| 206 | printGPSEph(gpseph, true);
|
|---|
| 207 | }
|
|---|
| 208 | else {
|
|---|
| 209 | printGPSEph(gpseph, false);
|
|---|
| 210 | delete gpseph;
|
|---|
| 211 | }
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | // New Glonass Ephemeris
|
|---|
| 215 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 216 | void bncApp::slotNewGlonassEph(glonassephemeris* glonasseph) {
|
|---|
| 217 |
|
|---|
| 218 | QMutexLocker locker(&_mutex);
|
|---|
| 219 |
|
|---|
| 220 | glonassephemeris copy_glonasseph = *glonasseph;
|
|---|
| 221 | emit newEphGlonass(copy_glonasseph);
|
|---|
| 222 |
|
|---|
| 223 | printEphHeader();
|
|---|
| 224 |
|
|---|
| 225 | glonassephemeris** ee = &_glonassEph[glonasseph->almanac_number-1];
|
|---|
| 226 |
|
|---|
| 227 | int wwOld, towOld, wwNew, towNew;
|
|---|
| 228 | if (*ee != 0) {
|
|---|
| 229 | wwOld = (*ee)->GPSWeek;
|
|---|
| 230 | towOld = (*ee)->GPSTOW;
|
|---|
| 231 | updatetime(&wwOld, &towOld, (*ee)->tb*1000, 0);
|
|---|
| 232 |
|
|---|
| 233 | wwNew = glonasseph->GPSWeek;
|
|---|
| 234 | towNew = glonasseph->GPSTOW;
|
|---|
| 235 | updatetime(&wwNew, &towNew, glonasseph->tb*1000, 0);
|
|---|
| 236 | }
|
|---|
| 237 |
|
|---|
| 238 | if ( *ee == 0 ||
|
|---|
| 239 | wwNew > wwOld ||
|
|---|
| 240 | (wwNew == wwOld && towNew > towOld) ) {
|
|---|
| 241 | delete *ee;
|
|---|
| 242 | *ee = glonasseph;
|
|---|
| 243 | printGlonassEph(glonasseph, true);
|
|---|
| 244 | }
|
|---|
| 245 | else {
|
|---|
| 246 | printGlonassEph(glonasseph, false);
|
|---|
| 247 | delete glonasseph;
|
|---|
| 248 | }
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | // Print Header of the output File(s)
|
|---|
| 252 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 253 | void bncApp::printEphHeader() {
|
|---|
| 254 |
|
|---|
| 255 | QSettings settings;
|
|---|
| 256 |
|
|---|
| 257 | // Initialization
|
|---|
| 258 | // --------------
|
|---|
| 259 | if (_rinexVers == 0) {
|
|---|
| 260 |
|
|---|
| 261 | if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
|
|---|
| 262 | _rinexVers = 3;
|
|---|
| 263 | }
|
|---|
| 264 | else {
|
|---|
| 265 | _rinexVers = 2;
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 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 | }
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | // (Re-)Open output File(s)
|
|---|
| 279 | // ------------------------
|
|---|
| 280 | if (!_ephPath.isEmpty()) {
|
|---|
| 281 |
|
|---|
| 282 | QDateTime datTim = currentDateAndTimeGPS();
|
|---|
| 283 |
|
|---|
| 284 | QString ephFileNameGPS = _ephPath + "BRDC" +
|
|---|
| 285 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'));
|
|---|
| 286 |
|
|---|
| 287 | QString hlpStr = bncRinex::nextEpochStr(datTim,
|
|---|
| 288 | settings.value("ephIntr").toString());
|
|---|
| 289 |
|
|---|
| 290 | if (_rinexVers == 3) {
|
|---|
| 291 | ephFileNameGPS += hlpStr + datTim.toString(".yyP");
|
|---|
| 292 | }
|
|---|
| 293 | else {
|
|---|
| 294 | ephFileNameGPS += hlpStr + datTim.toString(".yyN");
|
|---|
| 295 | }
|
|---|
| 296 |
|
|---|
| 297 | if (_ephFileNameGPS == ephFileNameGPS) {
|
|---|
| 298 | return;
|
|---|
| 299 | }
|
|---|
| 300 | else {
|
|---|
| 301 | _ephFileNameGPS = ephFileNameGPS;
|
|---|
| 302 | }
|
|---|
| 303 |
|
|---|
| 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 |
|
|---|
| 313 | delete _ephStreamGPS;
|
|---|
| 314 | delete _ephFileGPS;
|
|---|
| 315 |
|
|---|
| 316 | QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
|
|---|
| 317 | QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
|
|---|
| 318 |
|
|---|
| 319 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
|---|
| 320 | QFile::exists(ephFileNameGPS) ) {
|
|---|
| 321 | appendFlagGPS = QIODevice::Append;
|
|---|
| 322 | }
|
|---|
| 323 |
|
|---|
| 324 | _ephFileGPS = new QFile(ephFileNameGPS);
|
|---|
| 325 | _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
|
|---|
| 326 | _ephStreamGPS = new QTextStream();
|
|---|
| 327 | _ephStreamGPS->setDevice(_ephFileGPS);
|
|---|
| 328 |
|
|---|
| 329 | if (_rinexVers == 3) {
|
|---|
| 330 | _ephFileGlonass = _ephFileGPS;
|
|---|
| 331 | _ephStreamGlonass = _ephStreamGPS;
|
|---|
| 332 | }
|
|---|
| 333 | else if (_rinexVers == 2) {
|
|---|
| 334 | QString ephFileNameGlonass = _ephPath + "BRDC" +
|
|---|
| 335 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
|---|
| 336 | hlpStr + datTim.toString(".yyG");
|
|---|
| 337 |
|
|---|
| 338 | delete _ephStreamGlonass;
|
|---|
| 339 | delete _ephFileGlonass;
|
|---|
| 340 |
|
|---|
| 341 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
|---|
| 342 | QFile::exists(ephFileNameGlonass) ) {
|
|---|
| 343 | appendFlagGlonass = QIODevice::Append;
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 | _ephFileGlonass = new QFile(ephFileNameGlonass);
|
|---|
| 347 | _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
|
|---|
| 348 | _ephStreamGlonass = new QTextStream();
|
|---|
| 349 | _ephStreamGlonass->setDevice(_ephFileGlonass);
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | // Header - RINEX Version 3
|
|---|
| 353 | // ------------------------
|
|---|
| 354 | if (_rinexVers == 3) {
|
|---|
| 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 |
|
|---|
| 362 | QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
|
|---|
| 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", "");
|
|---|
| 369 | *_ephStreamGPS << line;
|
|---|
| 370 |
|
|---|
| 371 | _ephStreamGPS->flush();
|
|---|
| 372 | }
|
|---|
| 373 | }
|
|---|
| 374 |
|
|---|
| 375 | // Headers - RINEX Version 2
|
|---|
| 376 | // -------------------------
|
|---|
| 377 | else if (_rinexVers == 2) {
|
|---|
| 378 | if (! (appendFlagGPS & QIODevice::Append)) {
|
|---|
| 379 | QString line;
|
|---|
| 380 | line.sprintf(
|
|---|
| 381 | "%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n", 2.11, "", "");
|
|---|
| 382 | *_ephStreamGPS << line;
|
|---|
| 383 |
|
|---|
| 384 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
|---|
| 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", "");
|
|---|
| 391 | *_ephStreamGPS << line;
|
|---|
| 392 |
|
|---|
| 393 | _ephStreamGPS->flush();
|
|---|
| 394 | }
|
|---|
| 395 | if (! (appendFlagGlonass & QIODevice::Append)) {
|
|---|
| 396 | QString line;
|
|---|
| 397 | line.sprintf(
|
|---|
| 398 | "%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",2.11,"","");
|
|---|
| 399 | *_ephStreamGlonass << line;
|
|---|
| 400 |
|
|---|
| 401 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
|---|
| 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", "");
|
|---|
| 408 | *_ephStreamGlonass << line;
|
|---|
| 409 |
|
|---|
| 410 | _ephStreamGlonass->flush();
|
|---|
| 411 | }
|
|---|
| 412 | }
|
|---|
| 413 | }
|
|---|
| 414 | }
|
|---|
| 415 |
|
|---|
| 416 | // Print One GPS Ephemeris
|
|---|
| 417 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 418 | void bncApp::printGPSEph(gpsephemeris* ep, bool printFile) {
|
|---|
| 419 |
|
|---|
| 420 | QString lineV2;
|
|---|
| 421 | QString lineV3;
|
|---|
| 422 |
|
|---|
| 423 | struct converttimeinfo cti;
|
|---|
| 424 | converttime(&cti, ep->GPSweek, ep->TOC);
|
|---|
| 425 |
|
|---|
| 426 | lineV3.sprintf("G%02d %04d %02d %02d %02d %02d %02d %18.11e %18.11e %18.11e\n",
|
|---|
| 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);
|
|---|
| 430 |
|
|---|
| 431 | lineV2.sprintf("%02d %02d %02d %02d %02d %02d%5.1f %18.11e %18.11e %18.11e\n",
|
|---|
| 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);
|
|---|
| 435 |
|
|---|
| 436 | QString line;
|
|---|
| 437 | QByteArray allLines;
|
|---|
| 438 |
|
|---|
| 439 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", (double)ep->IODE,
|
|---|
| 440 | ep->Crs, ep->Delta_n, ep->M0);
|
|---|
| 441 | allLines += line;
|
|---|
| 442 |
|
|---|
| 443 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->Cuc,
|
|---|
| 444 | ep->e, ep->Cus, ep->sqrt_A);
|
|---|
| 445 | allLines += line;
|
|---|
| 446 |
|
|---|
| 447 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n",
|
|---|
| 448 | (double) ep->TOE, ep->Cic, ep->OMEGA0, ep->Cis);
|
|---|
| 449 | allLines += line;
|
|---|
| 450 |
|
|---|
| 451 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->i0,
|
|---|
| 452 | ep->Crc, ep->omega, ep->OMEGADOT);
|
|---|
| 453 | allLines += line;
|
|---|
| 454 |
|
|---|
| 455 | double dd = 0;
|
|---|
| 456 | unsigned long ii = ep->flags;
|
|---|
| 457 | if(ii & GPSEPHF_L2CACODE)
|
|---|
| 458 | dd += 2.0;
|
|---|
| 459 | if(ii & GPSEPHF_L2PCODE)
|
|---|
| 460 | dd += 1.0;
|
|---|
| 461 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->IDOT, dd,
|
|---|
| 462 | (double) ep->GPSweek, ii & GPSEPHF_L2PCODEDATA ? 1.0 : 0.0);
|
|---|
| 463 | allLines += line;
|
|---|
| 464 |
|
|---|
| 465 | if(ep->URAindex <= 6) /* URA index */
|
|---|
| 466 | dd = ceil(10.0*pow(2.0, 1.0+((double)ep->URAindex)/2.0))/10.0;
|
|---|
| 467 | else
|
|---|
| 468 | dd = ceil(10.0*pow(2.0, ((double)ep->URAindex)/2.0))/10.0;
|
|---|
| 469 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", dd,
|
|---|
| 470 | ((double) ep->SVhealth), ep->TGD, ((double) ep->IODC));
|
|---|
| 471 | allLines += line;
|
|---|
| 472 |
|
|---|
| 473 | line.sprintf(" %18.11e %18.11e\n", ((double)ep->TOW), 0.0);
|
|---|
| 474 | allLines += line;
|
|---|
| 475 |
|
|---|
| 476 | printOutput(printFile, _ephStreamGPS, lineV2, lineV3, allLines);
|
|---|
| 477 | }
|
|---|
| 478 |
|
|---|
| 479 | // Print One Glonass Ephemeris
|
|---|
| 480 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 481 | void bncApp::printGlonassEph(glonassephemeris* ep, bool printFile) {
|
|---|
| 482 |
|
|---|
| 483 | int ww = ep->GPSWeek;
|
|---|
| 484 | int tow = ep->GPSTOW;
|
|---|
| 485 | struct converttimeinfo cti;
|
|---|
| 486 |
|
|---|
| 487 | updatetime(&ww, &tow, ep->tb*1000, 0);
|
|---|
| 488 | converttime(&cti, ww, tow);
|
|---|
| 489 |
|
|---|
| 490 | int tk = ep->tk-3*60*60;
|
|---|
| 491 | if (tk < 0) {
|
|---|
| 492 | tk += 86400;
|
|---|
| 493 | }
|
|---|
| 494 |
|
|---|
| 495 | QString lineV2;
|
|---|
| 496 | QString lineV3;
|
|---|
| 497 |
|
|---|
| 498 | lineV3.sprintf("R%02d %04d %02d %02d %02d %02d %02d %18.11e %18.11e %18.11e\n",
|
|---|
| 499 | ep->almanac_number, cti.year, cti.month, cti.day, cti.hour,
|
|---|
| 500 | cti.minute, cti.second, -ep->tau, ep->gamma, (double) tk);
|
|---|
| 501 |
|
|---|
| 502 | lineV2.sprintf("%02d %02d %02d %02d %02d %02d%5.1f %18.11e %18.11e %18.11e\n",
|
|---|
| 503 | ep->almanac_number, cti.year%100, cti.month, cti.day,
|
|---|
| 504 | cti.hour, cti.minute, (double) cti.second, -ep->tau,
|
|---|
| 505 | ep->gamma, (double) tk);
|
|---|
| 506 |
|
|---|
| 507 | QString line;
|
|---|
| 508 | QByteArray allLines;
|
|---|
| 509 |
|
|---|
| 510 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->x_pos,
|
|---|
| 511 | ep->x_velocity, ep->x_acceleration,
|
|---|
| 512 | (ep->flags & GLOEPHF_UNHEALTHY) ? 1.0 : 0.0);
|
|---|
| 513 | allLines += line;
|
|---|
| 514 |
|
|---|
| 515 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->y_pos,
|
|---|
| 516 | ep->y_velocity, ep->y_acceleration,
|
|---|
| 517 | (double) ep->frequency_number);
|
|---|
| 518 | allLines += line;
|
|---|
| 519 |
|
|---|
| 520 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->z_pos,
|
|---|
| 521 | ep->z_velocity, ep->z_acceleration, (double) ep->E);
|
|---|
| 522 | allLines += line;
|
|---|
| 523 |
|
|---|
| 524 | printOutput(printFile, _ephStreamGlonass, lineV2, lineV3, allLines);
|
|---|
| 525 | }
|
|---|
| 526 |
|
|---|
| 527 | // Output
|
|---|
| 528 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 529 | void bncApp::printOutput(bool printFile, QTextStream* stream,
|
|---|
| 530 | const QString& lineV2,
|
|---|
| 531 | const QString& lineV3,
|
|---|
| 532 | const QByteArray& allLines) {
|
|---|
| 533 | // Output into file
|
|---|
| 534 | // ----------------
|
|---|
| 535 | if (printFile && stream) {
|
|---|
| 536 | if (_rinexVers == 2) {
|
|---|
| 537 | *stream << lineV2.toAscii();
|
|---|
| 538 | }
|
|---|
| 539 | else {
|
|---|
| 540 | *stream << lineV3.toAscii();
|
|---|
| 541 | }
|
|---|
| 542 | *stream << allLines;
|
|---|
| 543 | stream->flush();
|
|---|
| 544 | }
|
|---|
| 545 |
|
|---|
| 546 | // Output into the socket
|
|---|
| 547 | // ----------------------
|
|---|
| 548 | if (_sockets) {
|
|---|
| 549 | QMutableListIterator<QTcpSocket*> is(*_sockets);
|
|---|
| 550 | while (is.hasNext()) {
|
|---|
| 551 | QTcpSocket* sock = is.next();
|
|---|
| 552 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
|---|
| 553 | if (sock->write(lineV3.toAscii()) == -1 ||
|
|---|
| 554 | sock->write(allLines) == -1) {
|
|---|
| 555 | delete sock;
|
|---|
| 556 | is.remove();
|
|---|
| 557 | }
|
|---|
| 558 | }
|
|---|
| 559 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
|---|
| 560 | delete sock;
|
|---|
| 561 | is.remove();
|
|---|
| 562 | }
|
|---|
| 563 | }
|
|---|
| 564 | }
|
|---|
| 565 | }
|
|---|
| 566 |
|
|---|
| 567 | // Set Port Number
|
|---|
| 568 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 569 | void bncApp::setPort(int port) {
|
|---|
| 570 | _port = port;
|
|---|
| 571 | if (_port != 0) {
|
|---|
| 572 | delete _server;
|
|---|
| 573 | _server = new QTcpServer;
|
|---|
| 574 | if ( !_server->listen(QHostAddress::Any, _port) ) {
|
|---|
| 575 | slotMessage("bncApp: cannot listen on ephemeris port");
|
|---|
| 576 | }
|
|---|
| 577 | connect(_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
|
|---|
| 578 | delete _sockets;
|
|---|
| 579 | _sockets = new QList<QTcpSocket*>;
|
|---|
| 580 | }
|
|---|
| 581 | }
|
|---|
| 582 |
|
|---|
| 583 | // Set Port Number
|
|---|
| 584 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 585 | void bncApp::setPortCorr(int port) {
|
|---|
| 586 | _portCorr = port;
|
|---|
| 587 | if (_portCorr != 0) {
|
|---|
| 588 | delete _serverCorr;
|
|---|
| 589 | _serverCorr = new QTcpServer;
|
|---|
| 590 | if ( !_serverCorr->listen(QHostAddress::Any, _portCorr) ) {
|
|---|
| 591 | slotMessage("bncApp: cannot listen on correction port");
|
|---|
| 592 | }
|
|---|
| 593 | connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
|
|---|
| 594 | delete _socketsCorr;
|
|---|
| 595 | _socketsCorr = new QList<QTcpSocket*>;
|
|---|
| 596 | }
|
|---|
| 597 | }
|
|---|
| 598 |
|
|---|
| 599 | // New Connection
|
|---|
| 600 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 601 | void bncApp::slotNewConnection() {
|
|---|
| 602 | _sockets->push_back( _server->nextPendingConnection() );
|
|---|
| 603 | }
|
|---|
| 604 |
|
|---|
| 605 | // New Connection
|
|---|
| 606 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 607 | void bncApp::slotNewConnectionCorr() {
|
|---|
| 608 | _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
|
|---|
| 609 | }
|
|---|
| 610 |
|
|---|
| 611 | //
|
|---|
| 612 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 613 | void bncApp::slotQuit() {
|
|---|
| 614 | cout << "bncApp::slotQuit" << endl;
|
|---|
| 615 | delete _caster;
|
|---|
| 616 | quit();
|
|---|
| 617 | }
|
|---|
| 618 |
|
|---|
| 619 | //
|
|---|
| 620 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 621 | void bncApp::slotNewCorrLine(QString line, QString staID, long coTime) {
|
|---|
| 622 |
|
|---|
| 623 | QMutexLocker locker(&_mutex);
|
|---|
| 624 |
|
|---|
| 625 | if (!_socketsCorr) {
|
|---|
| 626 | return;
|
|---|
| 627 | }
|
|---|
| 628 |
|
|---|
| 629 | QSettings settings;
|
|---|
| 630 | _waitCoTime = settings.value("corrTime").toInt();
|
|---|
| 631 | if (_waitCoTime < 1) {
|
|---|
| 632 | _waitCoTime = 1;
|
|---|
| 633 | }
|
|---|
| 634 |
|
|---|
| 635 | // First time, set the _lastDumpSec immediately
|
|---|
| 636 | // --------------------------------------------
|
|---|
| 637 | if (_lastDumpCoSec == 0) {
|
|---|
| 638 | _lastDumpCoSec = coTime - 1;
|
|---|
| 639 | }
|
|---|
| 640 |
|
|---|
| 641 | // An old correction - throw it away
|
|---|
| 642 | // ---------------------------------
|
|---|
| 643 | if (coTime <= _lastDumpCoSec) {
|
|---|
| 644 | QString line = staID + ": Correction for one sat neglected because overaged by " +
|
|---|
| 645 | QString().sprintf(" %ld sec",
|
|---|
| 646 | _lastDumpCoSec - coTime + _waitCoTime);
|
|---|
| 647 | messagePrivate(line.toAscii());
|
|---|
| 648 | emit( newMessage(line.toAscii()) );
|
|---|
| 649 | return;
|
|---|
| 650 | }
|
|---|
| 651 |
|
|---|
| 652 | _corrs->insert(coTime, QString(line + " " + staID));
|
|---|
| 653 |
|
|---|
| 654 | // Dump Corrections
|
|---|
| 655 | // ----------------
|
|---|
| 656 | if (coTime - _waitCoTime > _lastDumpCoSec) {
|
|---|
| 657 | dumpCorrs(_lastDumpCoSec + 1, coTime - _waitCoTime);
|
|---|
| 658 | _lastDumpCoSec = coTime - _waitCoTime;
|
|---|
| 659 | }
|
|---|
| 660 | }
|
|---|
| 661 |
|
|---|
| 662 | // Dump Complete Correction Epochs
|
|---|
| 663 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 664 | void bncApp::dumpCorrs(long minTime, long maxTime) {
|
|---|
| 665 |
|
|---|
| 666 | for (long sec = minTime; sec <= maxTime; sec++) {
|
|---|
| 667 | QList<QString> allCorrs = _corrs->values(sec);
|
|---|
| 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) {
|
|---|
| 682 | delete sock;
|
|---|
| 683 | is.remove();
|
|---|
| 684 | }
|
|---|
| 685 | }
|
|---|
| 686 | }
|
|---|
| 687 | _corrs->remove(sec);
|
|---|
| 688 | }
|
|---|
| 689 | }
|
|---|