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