| 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 |
|
|---|
| 46 | #include "bncapp.h"
|
|---|
| 47 | #include "bncutils.h"
|
|---|
| 48 |
|
|---|
| 49 | using namespace std;
|
|---|
| 50 |
|
|---|
| 51 | // Constructor
|
|---|
| 52 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 53 | bncApp::bncApp(int argc, char* argv[], bool GUIenabled) :
|
|---|
| 54 | QApplication(argc, argv, GUIenabled) {
|
|---|
| 55 |
|
|---|
| 56 | _logFileFlag = 0;
|
|---|
| 57 | _logFile = 0;
|
|---|
| 58 | _logStream = 0;
|
|---|
| 59 |
|
|---|
| 60 | _bncVersion = "BNC 1.4";
|
|---|
| 61 |
|
|---|
| 62 | // Lists of Ephemeris
|
|---|
| 63 | // ------------------
|
|---|
| 64 | _ephFile = 0;
|
|---|
| 65 | _ephStream = 0;
|
|---|
| 66 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
|---|
| 67 | _gpsEph[ii-PRN_GPS_START] = 0;
|
|---|
| 68 | }
|
|---|
| 69 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
|---|
| 70 | _glonassEph[ii-PRN_GLONASS_START] = 0;
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | // Eph file
|
|---|
| 74 | // --------
|
|---|
| 75 | _ephFile = 0;
|
|---|
| 76 | _ephStream = 0;
|
|---|
| 77 | QString ephFileName = "TEST.EPH";
|
|---|
| 78 | //// QString ephFileName = settings.value("ephFile").toString();
|
|---|
| 79 | if ( !ephFileName.isEmpty() ) {
|
|---|
| 80 | expandEnvVar(ephFileName);
|
|---|
| 81 | _ephFile = new QFile(ephFileName);
|
|---|
| 82 | _ephFile->open(QIODevice::WriteOnly);
|
|---|
| 83 | _ephStream = new QTextStream();
|
|---|
| 84 | _ephStream->setDevice(_ephFile);
|
|---|
| 85 | printEphHeader();
|
|---|
| 86 | }
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | // Destructor
|
|---|
| 90 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 91 | bncApp::~bncApp() {
|
|---|
| 92 | delete _logStream;
|
|---|
| 93 | delete _logFile;
|
|---|
| 94 | delete _ephStream;
|
|---|
| 95 | delete _ephFile;
|
|---|
| 96 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
|---|
| 97 | delete _gpsEph[ii-PRN_GPS_START];
|
|---|
| 98 | }
|
|---|
| 99 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
|---|
| 100 | delete _glonassEph[ii-PRN_GLONASS_START];
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | // Write a Program Message
|
|---|
| 105 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 106 | void bncApp::slotMessage(const QByteArray msg) {
|
|---|
| 107 |
|
|---|
| 108 | QMutexLocker locker(&_mutex);
|
|---|
| 109 |
|
|---|
| 110 | // First time resolve the log file name
|
|---|
| 111 | // ------------------------------------
|
|---|
| 112 | if (_logFileFlag == 0) {
|
|---|
| 113 | _logFileFlag = 1;
|
|---|
| 114 | QSettings settings;
|
|---|
| 115 | QString logFileName = settings.value("logFile").toString();
|
|---|
| 116 | if ( !logFileName.isEmpty() ) {
|
|---|
| 117 | expandEnvVar(logFileName);
|
|---|
| 118 | _logFile = new QFile(logFileName);
|
|---|
| 119 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
|---|
| 120 | _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
|---|
| 121 | }
|
|---|
| 122 | else {
|
|---|
| 123 | _logFile->open(QIODevice::WriteOnly);
|
|---|
| 124 | }
|
|---|
| 125 | _logStream = new QTextStream();
|
|---|
| 126 | _logStream->setDevice(_logFile);
|
|---|
| 127 | }
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | if (_logStream) {
|
|---|
| 131 | *_logStream << QDate::currentDate().toString("yy-MM-dd ").toAscii().data();
|
|---|
| 132 | *_logStream << QTime::currentTime().toString("hh:mm:ss ").toAscii().data();
|
|---|
| 133 | *_logStream << msg.data() << endl;
|
|---|
| 134 | _logStream->flush();
|
|---|
| 135 | }
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | //
|
|---|
| 139 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 140 | void bncApp::slotNewGPSEph(gpsephemeris* gpseph) {
|
|---|
| 141 |
|
|---|
| 142 | QMutexLocker locker(&_mutex);
|
|---|
| 143 |
|
|---|
| 144 | if (!_ephStream) {
|
|---|
| 145 | delete gpseph;
|
|---|
| 146 | return;
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | gpsephemeris** ee = &_gpsEph[gpseph->satellite-PRN_GPS_START];
|
|---|
| 150 | if ( *ee == 0 || (*ee)->IODE != gpseph->IODE ) {
|
|---|
| 151 | delete *ee;
|
|---|
| 152 | *ee = gpseph;
|
|---|
| 153 | printGPSEph(gpseph);
|
|---|
| 154 | }
|
|---|
| 155 | else {
|
|---|
| 156 | delete gpseph;
|
|---|
| 157 | }
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | //
|
|---|
| 161 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 162 | void bncApp::slotNewGlonassEph(glonassephemeris* glonasseph) {
|
|---|
| 163 |
|
|---|
| 164 | QMutexLocker locker(&_mutex);
|
|---|
| 165 |
|
|---|
| 166 | if (!_ephStream) {
|
|---|
| 167 | delete glonasseph;
|
|---|
| 168 | return;
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | delete glonasseph;
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | //
|
|---|
| 175 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 176 | void bncApp::printEphHeader() {
|
|---|
| 177 | if (_ephStream) {
|
|---|
| 178 | *_ephStream << QDate::currentDate().toString("yy-MM-dd ").toAscii().data();
|
|---|
| 179 | *_ephStream << QTime::currentTime().toString("hh:mm:ss ").toAscii().data();
|
|---|
| 180 | _ephStream->flush();
|
|---|
| 181 | }
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | //
|
|---|
| 185 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 186 | void bncApp::printGPSEph(gpsephemeris* ep) {
|
|---|
| 187 |
|
|---|
| 188 | const int RINEX_3 = 1;
|
|---|
| 189 |
|
|---|
| 190 | if (_ephStream) {
|
|---|
| 191 |
|
|---|
| 192 | QDateTime datTim = dateAndTimeFromGPSweek(ep->GPSweek, ep->TOC);
|
|---|
| 193 |
|
|---|
| 194 | QString line;
|
|---|
| 195 |
|
|---|
| 196 | if (RINEX_3) {
|
|---|
| 197 | line.sprintf("G%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e\n",
|
|---|
| 198 | ep->satellite, datTim.date().year(),
|
|---|
| 199 | datTim.date().month(), datTim.date().day(),
|
|---|
| 200 | datTim.time().hour(), datTim.time().minute(),
|
|---|
| 201 | datTim.time().second(), ep->clock_bias,
|
|---|
| 202 | ep->clock_drift, ep->clock_driftrate);
|
|---|
| 203 | }
|
|---|
| 204 | else {
|
|---|
| 205 | line.sprintf("%02d %02d %02d %02d %02d %02d%05.1f%19.12e%19.12e%19.12e\n",
|
|---|
| 206 | ep->satellite, datTim.date().year()%100,
|
|---|
| 207 | datTim.date().month(), datTim.date().day(),
|
|---|
| 208 | datTim.time().hour(), datTim.time().minute(),
|
|---|
| 209 | (double) datTim.time().second(), ep->clock_bias,
|
|---|
| 210 | ep->clock_drift, ep->clock_driftrate);
|
|---|
| 211 | }
|
|---|
| 212 | line.sprintf(" %19.12e%19.12e%19.12e%19.12e\n", (double)ep->IODE,
|
|---|
| 213 | ep->Crs, ep->Delta_n, ep->M0);
|
|---|
| 214 | line.sprintf(" %19.12e%19.12e%19.12e%19.12e\n", ep->Cuc,
|
|---|
| 215 | ep->e, ep->Cus, ep->sqrt_A);
|
|---|
| 216 | line.sprintf(" %19.12e%19.12e%19.12e%19.12e\n",
|
|---|
| 217 | (double) ep->TOE, ep->Cic, ep->OMEGA0, ep->Cis);
|
|---|
| 218 | line.sprintf(" %19.12e%19.12e%19.12e%19.12e\n", ep->i0,
|
|---|
| 219 | ep->Crc, ep->omega, ep->OMEGADOT);
|
|---|
| 220 | double dd = 0;
|
|---|
| 221 | unsigned long ii = ep->flags;
|
|---|
| 222 | if(ii & GPSEPHF_L2CACODE)
|
|---|
| 223 | dd += 2.0;
|
|---|
| 224 | if(ii & GPSEPHF_L2PCODE)
|
|---|
| 225 | dd += 1.0;
|
|---|
| 226 | line.sprintf(" %19.12e%19.12e%19.12e%19.12e\n", ep->IDOT, dd,
|
|---|
| 227 | (double) ep->GPSweek, ii & GPSEPHF_L2PCODEDATA ? 1.0 : 0.0);
|
|---|
| 228 | if(ep->URAindex <= 6) /* URA index */
|
|---|
| 229 | dd = ceil(10.0*pow(2.0, 1.0+((double)ep->URAindex)/2.0))/10.0;
|
|---|
| 230 | else
|
|---|
| 231 | dd = ceil(10.0*pow(2.0, ((double)ep->URAindex)/2.0))/10.0;
|
|---|
| 232 | /* 15 indicates not to use satellite. We can't handle this special
|
|---|
| 233 | case, so we create a high "non"-accuracy value. */
|
|---|
| 234 | line.sprintf(" %19.12e%19.12e%19.12e%19.12e\n", dd,
|
|---|
| 235 | ((double) ep->SVhealth), ep->TGD, ((double) ep->IODC));
|
|---|
| 236 |
|
|---|
| 237 | line.sprintf(" %19.12e%19.12e\n", ((double)ep->TOW), 0.0);
|
|---|
| 238 |
|
|---|
| 239 | _ephStream->flush();
|
|---|
| 240 | }
|
|---|
| 241 | }
|
|---|
| 242 |
|
|---|
| 243 | //
|
|---|
| 244 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 245 | void bncApp::printGlonassEph(glonassephemeris* ep) {
|
|---|
| 246 | if (_ephStream) {
|
|---|
| 247 | *_ephStream << "GLONASS: " << ep->almanac_number << endl;
|
|---|
| 248 | _ephStream->flush();
|
|---|
| 249 | }
|
|---|
| 250 | }
|
|---|