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