| 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(&_mutex);
|
|---|
| 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 | if ( *ee == 0 ||
|
|---|
| 201 | gpseph->GPSweek > (*ee)->GPSweek ||
|
|---|
| 202 | (gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC > (*ee)->TOC) ) {
|
|---|
| 203 | delete *ee;
|
|---|
| 204 | *ee = gpseph;
|
|---|
| 205 | printGPSEph(gpseph, true);
|
|---|
| 206 | }
|
|---|
| 207 | else {
|
|---|
| 208 | printGPSEph(gpseph, false);
|
|---|
| 209 | delete gpseph;
|
|---|
| 210 | }
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | // New Glonass Ephemeris
|
|---|
| 214 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 215 | void bncApp::slotNewGlonassEph(glonassephemeris* glonasseph) {
|
|---|
| 216 |
|
|---|
| 217 | QMutexLocker locker(&_mutex);
|
|---|
| 218 |
|
|---|
| 219 | glonassephemeris copy_glonasseph = *glonasseph;
|
|---|
| 220 | emit newEphGlonass(copy_glonasseph);
|
|---|
| 221 |
|
|---|
| 222 | printEphHeader();
|
|---|
| 223 |
|
|---|
| 224 | glonassephemeris** ee = &_glonassEph[glonasseph->almanac_number-1];
|
|---|
| 225 |
|
|---|
| 226 | int wwOld, towOld, wwNew, towNew;
|
|---|
| 227 | if (*ee != 0) {
|
|---|
| 228 | wwOld = (*ee)->GPSWeek;
|
|---|
| 229 | towOld = (*ee)->GPSTOW;
|
|---|
| 230 | updatetime(&wwOld, &towOld, (*ee)->tb*1000, 0);
|
|---|
| 231 |
|
|---|
| 232 | wwNew = glonasseph->GPSWeek;
|
|---|
| 233 | towNew = glonasseph->GPSTOW;
|
|---|
| 234 | updatetime(&wwNew, &towNew, glonasseph->tb*1000, 0);
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | if ( *ee == 0 ||
|
|---|
| 238 | wwNew > wwOld ||
|
|---|
| 239 | (wwNew == wwOld && towNew > towOld) ) {
|
|---|
| 240 | delete *ee;
|
|---|
| 241 | *ee = glonasseph;
|
|---|
| 242 | printGlonassEph(glonasseph, true);
|
|---|
| 243 | }
|
|---|
| 244 | else {
|
|---|
| 245 | printGlonassEph(glonasseph, false);
|
|---|
| 246 | delete glonasseph;
|
|---|
| 247 | }
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | // Print Header of the output File(s)
|
|---|
| 251 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 252 | void bncApp::printEphHeader() {
|
|---|
| 253 |
|
|---|
| 254 | QSettings settings;
|
|---|
| 255 |
|
|---|
| 256 | // Initialization
|
|---|
| 257 | // --------------
|
|---|
| 258 | if (_rinexVers == 0) {
|
|---|
| 259 |
|
|---|
| 260 | if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
|
|---|
| 261 | _rinexVers = 3;
|
|---|
| 262 | }
|
|---|
| 263 | else {
|
|---|
| 264 | _rinexVers = 2;
|
|---|
| 265 | }
|
|---|
| 266 |
|
|---|
| 267 | _ephPath = settings.value("ephPath").toString();
|
|---|
| 268 |
|
|---|
| 269 | if ( !_ephPath.isEmpty() ) {
|
|---|
| 270 | if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
|
|---|
| 271 | _ephPath += QDir::separator();
|
|---|
| 272 | }
|
|---|
| 273 | expandEnvVar(_ephPath);
|
|---|
| 274 | }
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | // (Re-)Open output File(s)
|
|---|
| 278 | // ------------------------
|
|---|
| 279 | if (!_ephPath.isEmpty()) {
|
|---|
| 280 |
|
|---|
| 281 | QDateTime datTim = currentDateAndTimeGPS();
|
|---|
| 282 |
|
|---|
| 283 | QString ephFileNameGPS = _ephPath + "BRDC" +
|
|---|
| 284 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'));
|
|---|
| 285 |
|
|---|
| 286 | QString hlpStr = bncRinex::nextEpochStr(datTim,
|
|---|
| 287 | settings.value("ephIntr").toString());
|
|---|
| 288 |
|
|---|
| 289 | if (_rinexVers == 3) {
|
|---|
| 290 | ephFileNameGPS += hlpStr + datTim.toString(".yyP");
|
|---|
| 291 | }
|
|---|
| 292 | else {
|
|---|
| 293 | ephFileNameGPS += hlpStr + datTim.toString(".yyN");
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | if (_ephFileNameGPS == ephFileNameGPS) {
|
|---|
| 297 | return;
|
|---|
| 298 | }
|
|---|
| 299 | else {
|
|---|
| 300 | _ephFileNameGPS = ephFileNameGPS;
|
|---|
| 301 | }
|
|---|
| 302 |
|
|---|
| 303 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
|---|
| 304 | delete _gpsEph[ii-PRN_GPS_START];
|
|---|
| 305 | _gpsEph[ii-PRN_GPS_START] = 0;
|
|---|
| 306 | }
|
|---|
| 307 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
|---|
| 308 | delete _glonassEph[ii-PRN_GLONASS_START];
|
|---|
| 309 | _glonassEph[ii-PRN_GLONASS_START] = 0;
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | delete _ephStreamGPS;
|
|---|
| 313 | delete _ephFileGPS;
|
|---|
| 314 |
|
|---|
| 315 | QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
|
|---|
| 316 | QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
|
|---|
| 317 |
|
|---|
| 318 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
|---|
| 319 | QFile::exists(ephFileNameGPS) ) {
|
|---|
| 320 | appendFlagGPS = QIODevice::Append;
|
|---|
| 321 | }
|
|---|
| 322 |
|
|---|
| 323 | _ephFileGPS = new QFile(ephFileNameGPS);
|
|---|
| 324 | _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
|
|---|
| 325 | _ephStreamGPS = new QTextStream();
|
|---|
| 326 | _ephStreamGPS->setDevice(_ephFileGPS);
|
|---|
| 327 |
|
|---|
| 328 | if (_rinexVers == 3) {
|
|---|
| 329 | _ephFileGlonass = _ephFileGPS;
|
|---|
| 330 | _ephStreamGlonass = _ephStreamGPS;
|
|---|
| 331 | }
|
|---|
| 332 | else if (_rinexVers == 2) {
|
|---|
| 333 | QString ephFileNameGlonass = _ephPath + "BRDC" +
|
|---|
| 334 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
|---|
| 335 | hlpStr + datTim.toString(".yyG");
|
|---|
| 336 |
|
|---|
| 337 | delete _ephStreamGlonass;
|
|---|
| 338 | delete _ephFileGlonass;
|
|---|
| 339 |
|
|---|
| 340 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
|---|
| 341 | QFile::exists(ephFileNameGlonass) ) {
|
|---|
| 342 | appendFlagGlonass = QIODevice::Append;
|
|---|
| 343 | }
|
|---|
| 344 |
|
|---|
| 345 | _ephFileGlonass = new QFile(ephFileNameGlonass);
|
|---|
| 346 | _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
|
|---|
| 347 | _ephStreamGlonass = new QTextStream();
|
|---|
| 348 | _ephStreamGlonass->setDevice(_ephFileGlonass);
|
|---|
| 349 | }
|
|---|
| 350 |
|
|---|
| 351 | // Header - RINEX Version 3
|
|---|
| 352 | // ------------------------
|
|---|
| 353 | if (_rinexVers == 3) {
|
|---|
| 354 | if ( ! (appendFlagGPS & QIODevice::Append)) {
|
|---|
| 355 | QString line;
|
|---|
| 356 | line.sprintf(
|
|---|
| 357 | "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
|
|---|
| 358 | 3.0, "", "");
|
|---|
| 359 | *_ephStreamGPS << line;
|
|---|
| 360 |
|
|---|
| 361 | QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
|
|---|
| 362 | *_ephStreamGPS << _pgmName.toAscii().data()
|
|---|
| 363 | << _userName.toAscii().data()
|
|---|
| 364 | << hlp.toAscii().data()
|
|---|
| 365 | << "PGM / RUN BY / DATE" << endl;
|
|---|
| 366 |
|
|---|
| 367 | line.sprintf("%60sEND OF HEADER\n", "");
|
|---|
| 368 | *_ephStreamGPS << line;
|
|---|
| 369 |
|
|---|
| 370 | _ephStreamGPS->flush();
|
|---|
| 371 | }
|
|---|
| 372 | }
|
|---|
| 373 |
|
|---|
| 374 | // Headers - RINEX Version 2
|
|---|
| 375 | // -------------------------
|
|---|
| 376 | else if (_rinexVers == 2) {
|
|---|
| 377 | if (! (appendFlagGPS & QIODevice::Append)) {
|
|---|
| 378 | QString line;
|
|---|
| 379 | line.sprintf(
|
|---|
| 380 | "%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n", 2.11, "", "");
|
|---|
| 381 | *_ephStreamGPS << line;
|
|---|
| 382 |
|
|---|
| 383 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
|---|
| 384 | *_ephStreamGPS << _pgmName.toAscii().data()
|
|---|
| 385 | << _userName.toAscii().data()
|
|---|
| 386 | << hlp.toAscii().data()
|
|---|
| 387 | << "PGM / RUN BY / DATE" << endl;
|
|---|
| 388 |
|
|---|
| 389 | line.sprintf("%60sEND OF HEADER\n", "");
|
|---|
| 390 | *_ephStreamGPS << line;
|
|---|
| 391 |
|
|---|
| 392 | _ephStreamGPS->flush();
|
|---|
| 393 | }
|
|---|
| 394 | if (! (appendFlagGlonass & QIODevice::Append)) {
|
|---|
| 395 | QString line;
|
|---|
| 396 | line.sprintf(
|
|---|
| 397 | "%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",2.11,"","");
|
|---|
| 398 | *_ephStreamGlonass << line;
|
|---|
| 399 |
|
|---|
| 400 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
|---|
| 401 | *_ephStreamGlonass << _pgmName.toAscii().data()
|
|---|
| 402 | << _userName.toAscii().data()
|
|---|
| 403 | << hlp.toAscii().data()
|
|---|
| 404 | << "PGM / RUN BY / DATE" << endl;
|
|---|
| 405 |
|
|---|
| 406 | line.sprintf("%60sEND OF HEADER\n", "");
|
|---|
| 407 | *_ephStreamGlonass << line;
|
|---|
| 408 |
|
|---|
| 409 | _ephStreamGlonass->flush();
|
|---|
| 410 | }
|
|---|
| 411 | }
|
|---|
| 412 | }
|
|---|
| 413 | }
|
|---|
| 414 |
|
|---|
| 415 | // Print One GPS Ephemeris
|
|---|
| 416 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 417 | void bncApp::printGPSEph(gpsephemeris* ep, bool printFile) {
|
|---|
| 418 |
|
|---|
| 419 | QString lineV2;
|
|---|
| 420 | QString lineV3;
|
|---|
| 421 |
|
|---|
| 422 | struct converttimeinfo cti;
|
|---|
| 423 | converttime(&cti, ep->GPSweek, ep->TOC);
|
|---|
| 424 |
|
|---|
| 425 | lineV3.sprintf("G%02d %04d %02d %02d %02d %02d %02d %18.11e %18.11e %18.11e\n",
|
|---|
| 426 | ep->satellite, cti.year, cti.month, cti.day, cti.hour,
|
|---|
| 427 | cti.minute, cti.second, ep->clock_bias, ep->clock_drift,
|
|---|
| 428 | ep->clock_driftrate);
|
|---|
| 429 |
|
|---|
| 430 | lineV2.sprintf("%02d %02d %02d %02d %02d %02d%5.1f %18.11e %18.11e %18.11e\n",
|
|---|
| 431 | ep->satellite, cti.year%100, cti.month, cti.day, cti.hour,
|
|---|
| 432 | cti.minute, (double) cti.second, ep->clock_bias,
|
|---|
| 433 | ep->clock_drift, ep->clock_driftrate);
|
|---|
| 434 |
|
|---|
| 435 | QString line;
|
|---|
| 436 | QByteArray allLines;
|
|---|
| 437 |
|
|---|
| 438 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", (double)ep->IODE,
|
|---|
| 439 | ep->Crs, ep->Delta_n, ep->M0);
|
|---|
| 440 | allLines += line;
|
|---|
| 441 |
|
|---|
| 442 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->Cuc,
|
|---|
| 443 | ep->e, ep->Cus, ep->sqrt_A);
|
|---|
| 444 | allLines += line;
|
|---|
| 445 |
|
|---|
| 446 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n",
|
|---|
| 447 | (double) ep->TOE, ep->Cic, ep->OMEGA0, ep->Cis);
|
|---|
| 448 | allLines += line;
|
|---|
| 449 |
|
|---|
| 450 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->i0,
|
|---|
| 451 | ep->Crc, ep->omega, ep->OMEGADOT);
|
|---|
| 452 | allLines += line;
|
|---|
| 453 |
|
|---|
| 454 | double dd = 0;
|
|---|
| 455 | unsigned long ii = ep->flags;
|
|---|
| 456 | if(ii & GPSEPHF_L2CACODE)
|
|---|
| 457 | dd += 2.0;
|
|---|
| 458 | if(ii & GPSEPHF_L2PCODE)
|
|---|
| 459 | dd += 1.0;
|
|---|
| 460 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->IDOT, dd,
|
|---|
| 461 | (double) ep->GPSweek, ii & GPSEPHF_L2PCODEDATA ? 1.0 : 0.0);
|
|---|
| 462 | allLines += line;
|
|---|
| 463 |
|
|---|
| 464 | if(ep->URAindex <= 6) /* URA index */
|
|---|
| 465 | dd = ceil(10.0*pow(2.0, 1.0+((double)ep->URAindex)/2.0))/10.0;
|
|---|
| 466 | else
|
|---|
| 467 | dd = ceil(10.0*pow(2.0, ((double)ep->URAindex)/2.0))/10.0;
|
|---|
| 468 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", dd,
|
|---|
| 469 | ((double) ep->SVhealth), ep->TGD, ((double) ep->IODC));
|
|---|
| 470 | allLines += line;
|
|---|
| 471 |
|
|---|
| 472 | line.sprintf(" %18.11e %18.11e\n", ((double)ep->TOW), 0.0);
|
|---|
| 473 | allLines += line;
|
|---|
| 474 |
|
|---|
| 475 | printOutput(printFile, _ephStreamGPS, lineV2, lineV3, allLines);
|
|---|
| 476 | }
|
|---|
| 477 |
|
|---|
| 478 | // Print One Glonass Ephemeris
|
|---|
| 479 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 480 | void bncApp::printGlonassEph(glonassephemeris* ep, bool printFile) {
|
|---|
| 481 |
|
|---|
| 482 | int ww = ep->GPSWeek;
|
|---|
| 483 | int tow = ep->GPSTOW;
|
|---|
| 484 | struct converttimeinfo cti;
|
|---|
| 485 |
|
|---|
| 486 | updatetime(&ww, &tow, ep->tb*1000, 0);
|
|---|
| 487 | converttime(&cti, ww, tow);
|
|---|
| 488 |
|
|---|
| 489 | int tk = ep->tk-3*60*60;
|
|---|
| 490 | if (tk < 0) {
|
|---|
| 491 | tk += 86400;
|
|---|
| 492 | }
|
|---|
| 493 |
|
|---|
| 494 | QString lineV2;
|
|---|
| 495 | QString lineV3;
|
|---|
| 496 |
|
|---|
| 497 | lineV3.sprintf("R%02d %04d %02d %02d %02d %02d %02d %18.11e %18.11e %18.11e\n",
|
|---|
| 498 | ep->almanac_number, cti.year, cti.month, cti.day, cti.hour,
|
|---|
| 499 | cti.minute, cti.second, -ep->tau, ep->gamma, (double) tk);
|
|---|
| 500 |
|
|---|
| 501 | lineV2.sprintf("%02d %02d %02d %02d %02d %02d%5.1f %18.11e %18.11e %18.11e\n",
|
|---|
| 502 | ep->almanac_number, cti.year%100, cti.month, cti.day,
|
|---|
| 503 | cti.hour, cti.minute, (double) cti.second, -ep->tau,
|
|---|
| 504 | ep->gamma, (double) tk);
|
|---|
| 505 |
|
|---|
| 506 | QString line;
|
|---|
| 507 | QByteArray allLines;
|
|---|
| 508 |
|
|---|
| 509 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->x_pos,
|
|---|
| 510 | ep->x_velocity, ep->x_acceleration,
|
|---|
| 511 | (ep->flags & GLOEPHF_UNHEALTHY) ? 1.0 : 0.0);
|
|---|
| 512 | allLines += line;
|
|---|
| 513 |
|
|---|
| 514 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->y_pos,
|
|---|
| 515 | ep->y_velocity, ep->y_acceleration,
|
|---|
| 516 | (double) ep->frequency_number);
|
|---|
| 517 | allLines += line;
|
|---|
| 518 |
|
|---|
| 519 | line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->z_pos,
|
|---|
| 520 | ep->z_velocity, ep->z_acceleration, (double) ep->E);
|
|---|
| 521 | allLines += line;
|
|---|
| 522 |
|
|---|
| 523 | printOutput(printFile, _ephStreamGlonass, lineV2, lineV3, allLines);
|
|---|
| 524 | }
|
|---|
| 525 |
|
|---|
| 526 | // Output
|
|---|
| 527 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 528 | void bncApp::printOutput(bool printFile, QTextStream* stream,
|
|---|
| 529 | const QString& lineV2,
|
|---|
| 530 | const QString& lineV3,
|
|---|
| 531 | const QByteArray& allLines) {
|
|---|
| 532 | // Output into file
|
|---|
| 533 | // ----------------
|
|---|
| 534 | if (printFile && stream) {
|
|---|
| 535 | if (_rinexVers == 2) {
|
|---|
| 536 | *stream << lineV2.toAscii();
|
|---|
| 537 | }
|
|---|
| 538 | else {
|
|---|
| 539 | *stream << lineV3.toAscii();
|
|---|
| 540 | }
|
|---|
| 541 | *stream << allLines;
|
|---|
| 542 | stream->flush();
|
|---|
| 543 | }
|
|---|
| 544 |
|
|---|
| 545 | // Output into the socket
|
|---|
| 546 | // ----------------------
|
|---|
| 547 | if (_sockets) {
|
|---|
| 548 | QMutableListIterator<QTcpSocket*> is(*_sockets);
|
|---|
| 549 | while (is.hasNext()) {
|
|---|
| 550 | QTcpSocket* sock = is.next();
|
|---|
| 551 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
|---|
| 552 | if (sock->write(lineV3.toAscii()) == -1 ||
|
|---|
| 553 | sock->write(allLines) == -1) {
|
|---|
| 554 | delete sock;
|
|---|
| 555 | is.remove();
|
|---|
| 556 | }
|
|---|
| 557 | }
|
|---|
| 558 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
|---|
| 559 | delete sock;
|
|---|
| 560 | is.remove();
|
|---|
| 561 | }
|
|---|
| 562 | }
|
|---|
| 563 | }
|
|---|
| 564 | }
|
|---|
| 565 |
|
|---|
| 566 | // Set Port Number
|
|---|
| 567 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 568 | void bncApp::setPort(int port) {
|
|---|
| 569 | _port = port;
|
|---|
| 570 | if (_port != 0) {
|
|---|
| 571 | delete _server;
|
|---|
| 572 | _server = new QTcpServer;
|
|---|
| 573 | _server->listen(QHostAddress::Any, _port);
|
|---|
| 574 | connect(_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
|
|---|
| 575 | delete _sockets;
|
|---|
| 576 | _sockets = new QList<QTcpSocket*>;
|
|---|
| 577 | }
|
|---|
| 578 | }
|
|---|
| 579 |
|
|---|
| 580 | // Set Port Number
|
|---|
| 581 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 582 | void bncApp::setPortCorr(int port) {
|
|---|
| 583 | _portCorr = port;
|
|---|
| 584 | if (_portCorr != 0) {
|
|---|
| 585 | delete _serverCorr;
|
|---|
| 586 | _serverCorr = new QTcpServer;
|
|---|
| 587 | _serverCorr->listen(QHostAddress::Any, _portCorr);
|
|---|
| 588 | connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
|
|---|
| 589 | delete _socketsCorr;
|
|---|
| 590 | _socketsCorr = new QList<QTcpSocket*>;
|
|---|
| 591 | }
|
|---|
| 592 | }
|
|---|
| 593 |
|
|---|
| 594 | // New Connection
|
|---|
| 595 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 596 | void bncApp::slotNewConnection() {
|
|---|
| 597 | _sockets->push_back( _server->nextPendingConnection() );
|
|---|
| 598 | }
|
|---|
| 599 |
|
|---|
| 600 | // New Connection
|
|---|
| 601 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 602 | void bncApp::slotNewConnectionCorr() {
|
|---|
| 603 | _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
|
|---|
| 604 | }
|
|---|
| 605 |
|
|---|
| 606 | //
|
|---|
| 607 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 608 | void bncApp::slotQuit() {
|
|---|
| 609 | cout << "bncApp::slotQuit" << endl;
|
|---|
| 610 | delete _caster;
|
|---|
| 611 | quit();
|
|---|
| 612 | }
|
|---|
| 613 |
|
|---|
| 614 | //
|
|---|
| 615 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 616 | void bncApp::slotNewCorrLine(QString line, QString staID, long coTime) {
|
|---|
| 617 |
|
|---|
| 618 | QMutexLocker locker(&_mutex);
|
|---|
| 619 |
|
|---|
| 620 | if (!_socketsCorr) {
|
|---|
| 621 | return;
|
|---|
| 622 | }
|
|---|
| 623 |
|
|---|
| 624 | QSettings settings;
|
|---|
| 625 | _waitCoTime = settings.value("corrTime").toInt();
|
|---|
| 626 | if (_waitCoTime < 1) {
|
|---|
| 627 | _waitCoTime = 1;
|
|---|
| 628 | }
|
|---|
| 629 |
|
|---|
| 630 | // First time, set the _lastDumpSec immediately
|
|---|
| 631 | // --------------------------------------------
|
|---|
| 632 | if (_lastDumpCoSec == 0) {
|
|---|
| 633 | _lastDumpCoSec = coTime - 1;
|
|---|
| 634 | }
|
|---|
| 635 |
|
|---|
| 636 | // An old correction - throw it away
|
|---|
| 637 | // ---------------------------------
|
|---|
| 638 | if (coTime <= _lastDumpCoSec) {
|
|---|
| 639 | QString line = staID + ": Correction overaged by " +
|
|---|
| 640 | QString().sprintf(" %ld sec",
|
|---|
| 641 | _lastDumpCoSec - coTime + _waitCoTime);
|
|---|
| 642 | messagePrivate(line.toAscii());
|
|---|
| 643 | emit( newMessage(line.toAscii()) );
|
|---|
| 644 | return;
|
|---|
| 645 | }
|
|---|
| 646 |
|
|---|
| 647 | _corrs->insert(coTime, QString(line + " " + staID));
|
|---|
| 648 |
|
|---|
| 649 | // Dump Corrections
|
|---|
| 650 | // ----------------
|
|---|
| 651 | if (coTime - _waitCoTime > _lastDumpCoSec) {
|
|---|
| 652 | dumpCorrs(_lastDumpCoSec + 1, coTime - _waitCoTime);
|
|---|
| 653 | _lastDumpCoSec = coTime - _waitCoTime;
|
|---|
| 654 | }
|
|---|
| 655 | }
|
|---|
| 656 |
|
|---|
| 657 | // Dump Complete Correction Epochs
|
|---|
| 658 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 659 | void bncApp::dumpCorrs(long minTime, long maxTime) {
|
|---|
| 660 |
|
|---|
| 661 | for (long sec = minTime; sec <= maxTime; sec++) {
|
|---|
| 662 | QList<QString> allCorrs = _corrs->values(sec);
|
|---|
| 663 | QListIterator<QString> it(allCorrs);
|
|---|
| 664 | while (it.hasNext()) {
|
|---|
| 665 | QString corrLine = it.next() + "\n";
|
|---|
| 666 |
|
|---|
| 667 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
|---|
| 668 | while (is.hasNext()) {
|
|---|
| 669 | QTcpSocket* sock = is.next();
|
|---|
| 670 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
|---|
| 671 | if (sock->write(corrLine.toAscii()) == -1) {
|
|---|
| 672 | delete sock;
|
|---|
| 673 | is.remove();
|
|---|
| 674 | }
|
|---|
| 675 | }
|
|---|
| 676 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
|---|
| 677 | delete sock;
|
|---|
| 678 | is.remove();
|
|---|
| 679 | }
|
|---|
| 680 | }
|
|---|
| 681 | }
|
|---|
| 682 | _corrs->remove(sec);
|
|---|
| 683 | }
|
|---|
| 684 | }
|
|---|