[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 |
|
---|
| 65 |
|
---|
[82] | 66 | // Constructor
|
---|
| 67 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 68 | bncApp::bncApp(int argc, char* argv[], bool GUIenabled) :
|
---|
| 69 | QApplication(argc, argv, GUIenabled) {
|
---|
[109] | 70 |
|
---|
[150] | 71 | _logFileFlag = 0;
|
---|
| 72 | _logFile = 0;
|
---|
| 73 | _logStream = 0;
|
---|
[152] | 74 |
|
---|
[476] | 75 | _bncVersion = "BNC 1.4";
|
---|
[519] | 76 |
|
---|
[516] | 77 | // Lists of Ephemeris
|
---|
| 78 | // ------------------
|
---|
| 79 | _ephFile = 0;
|
---|
| 80 | _ephStream = 0;
|
---|
| 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
|
---|
| 89 | // --------
|
---|
| 90 | _ephFile = 0;
|
---|
| 91 | _ephStream = 0;
|
---|
| 92 | QString ephFileName = "TEST.EPH";
|
---|
| 93 | //// QString ephFileName = settings.value("ephFile").toString();
|
---|
| 94 | if ( !ephFileName.isEmpty() ) {
|
---|
| 95 | expandEnvVar(ephFileName);
|
---|
| 96 | _ephFile = new QFile(ephFileName);
|
---|
| 97 | _ephFile->open(QIODevice::WriteOnly);
|
---|
| 98 | _ephStream = new QTextStream();
|
---|
| 99 | _ephStream->setDevice(_ephFile);
|
---|
| 100 | printEphHeader();
|
---|
| 101 | }
|
---|
[82] | 102 | }
|
---|
| 103 |
|
---|
| 104 | // Destructor
|
---|
| 105 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 106 | bncApp::~bncApp() {
|
---|
[109] | 107 | delete _logStream;
|
---|
| 108 | delete _logFile;
|
---|
[516] | 109 | delete _ephStream;
|
---|
| 110 | delete _ephFile;
|
---|
| 111 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
---|
| 112 | delete _gpsEph[ii-PRN_GPS_START];
|
---|
| 113 | }
|
---|
| 114 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
---|
| 115 | delete _glonassEph[ii-PRN_GLONASS_START];
|
---|
| 116 | }
|
---|
[82] | 117 | }
|
---|
| 118 |
|
---|
| 119 | // Write a Program Message
|
---|
| 120 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 121 | void bncApp::slotMessage(const QByteArray msg) {
|
---|
[150] | 122 |
|
---|
[243] | 123 | QMutexLocker locker(&_mutex);
|
---|
| 124 |
|
---|
[150] | 125 | // First time resolve the log file name
|
---|
| 126 | // ------------------------------------
|
---|
| 127 | if (_logFileFlag == 0) {
|
---|
| 128 | _logFileFlag = 1;
|
---|
| 129 | QSettings settings;
|
---|
| 130 | QString logFileName = settings.value("logFile").toString();
|
---|
| 131 | if ( !logFileName.isEmpty() ) {
|
---|
[151] | 132 | expandEnvVar(logFileName);
|
---|
[150] | 133 | _logFile = new QFile(logFileName);
|
---|
[275] | 134 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
| 135 | _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
---|
| 136 | }
|
---|
| 137 | else {
|
---|
| 138 | _logFile->open(QIODevice::WriteOnly);
|
---|
| 139 | }
|
---|
[150] | 140 | _logStream = new QTextStream();
|
---|
| 141 | _logStream->setDevice(_logFile);
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 |
|
---|
[109] | 145 | if (_logStream) {
|
---|
[335] | 146 | *_logStream << QDate::currentDate().toString("yy-MM-dd ").toAscii().data();
|
---|
[199] | 147 | *_logStream << QTime::currentTime().toString("hh:mm:ss ").toAscii().data();
|
---|
[109] | 148 | *_logStream << msg.data() << endl;
|
---|
| 149 | _logStream->flush();
|
---|
[82] | 150 | }
|
---|
| 151 | }
|
---|
[511] | 152 |
|
---|
| 153 | //
|
---|
| 154 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 155 | void bncApp::slotNewGPSEph(gpsephemeris* gpseph) {
|
---|
[516] | 156 |
|
---|
| 157 | QMutexLocker locker(&_mutex);
|
---|
| 158 |
|
---|
[517] | 159 | if (!_ephStream) {
|
---|
| 160 | delete gpseph;
|
---|
| 161 | return;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
[516] | 164 | gpsephemeris** ee = &_gpsEph[gpseph->satellite-PRN_GPS_START];
|
---|
| 165 | if ( *ee == 0 || (*ee)->IODE != gpseph->IODE ) {
|
---|
| 166 | delete *ee;
|
---|
| 167 | *ee = gpseph;
|
---|
| 168 | printGPSEph(gpseph);
|
---|
| 169 | }
|
---|
| 170 | else {
|
---|
| 171 | delete gpseph;
|
---|
| 172 | }
|
---|
[511] | 173 | }
|
---|
| 174 |
|
---|
| 175 | //
|
---|
| 176 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 177 | void bncApp::slotNewGlonassEph(glonassephemeris* glonasseph) {
|
---|
[516] | 178 |
|
---|
| 179 | QMutexLocker locker(&_mutex);
|
---|
| 180 |
|
---|
[517] | 181 | if (!_ephStream) {
|
---|
| 182 | delete glonasseph;
|
---|
| 183 | return;
|
---|
| 184 | }
|
---|
| 185 |
|
---|
[512] | 186 | delete glonasseph;
|
---|
[511] | 187 | }
|
---|
| 188 |
|
---|
[516] | 189 | //
|
---|
| 190 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 191 | void bncApp::printEphHeader() {
|
---|
[517] | 192 | if (_ephStream) {
|
---|
| 193 | *_ephStream << QDate::currentDate().toString("yy-MM-dd ").toAscii().data();
|
---|
| 194 | *_ephStream << QTime::currentTime().toString("hh:mm:ss ").toAscii().data();
|
---|
[518] | 195 | _ephStream->flush();
|
---|
[517] | 196 | }
|
---|
[516] | 197 | }
|
---|
| 198 |
|
---|
[525] | 199 | const int RINEX_3 = 1;
|
---|
| 200 |
|
---|
[516] | 201 | //
|
---|
| 202 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 203 | void bncApp::printGPSEph(gpsephemeris* ep) {
|
---|
[519] | 204 |
|
---|
[517] | 205 | if (_ephStream) {
|
---|
[519] | 206 |
|
---|
| 207 | QString line;
|
---|
| 208 |
|
---|
[524] | 209 | struct converttimeinfo cti;
|
---|
| 210 | converttime(&cti, ep->GPSweek, ep->TOC);
|
---|
| 211 |
|
---|
[519] | 212 | if (RINEX_3) {
|
---|
[526] | 213 | line.sprintf("G%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e",
|
---|
[524] | 214 | ep->satellite, cti.year, cti.month, cti.day, cti.hour,
|
---|
| 215 | cti.minute, cti.second, ep->clock_bias, ep->clock_drift,
|
---|
| 216 | ep->clock_driftrate);
|
---|
[519] | 217 | }
|
---|
| 218 | else {
|
---|
[526] | 219 | line.sprintf("%02d %02d %02d %02d %02d %02d%05.1f%19.12e%19.12e%19.12e",
|
---|
[524] | 220 | ep->satellite, cti.year%100, cti.month, cti.day, cti.hour,
|
---|
| 221 | cti.minute, (double) cti.second, ep->clock_bias,
|
---|
[519] | 222 | ep->clock_drift, ep->clock_driftrate);
|
---|
| 223 | }
|
---|
[520] | 224 | *_ephStream << line << endl;
|
---|
| 225 |
|
---|
[521] | 226 | line.sprintf(" %19.12e%19.12e%19.12e%19.12e", (double)ep->IODE,
|
---|
[520] | 227 | ep->Crs, ep->Delta_n, ep->M0);
|
---|
| 228 | *_ephStream << line << endl;
|
---|
| 229 |
|
---|
[521] | 230 | line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->Cuc,
|
---|
[520] | 231 | ep->e, ep->Cus, ep->sqrt_A);
|
---|
| 232 | *_ephStream << line << endl;
|
---|
| 233 |
|
---|
[521] | 234 | line.sprintf(" %19.12e%19.12e%19.12e%19.12e",
|
---|
[520] | 235 | (double) ep->TOE, ep->Cic, ep->OMEGA0, ep->Cis);
|
---|
| 236 | *_ephStream << line << endl;
|
---|
| 237 |
|
---|
[521] | 238 | line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->i0,
|
---|
[520] | 239 | ep->Crc, ep->omega, ep->OMEGADOT);
|
---|
| 240 | *_ephStream << line << endl;
|
---|
| 241 |
|
---|
[519] | 242 | double dd = 0;
|
---|
| 243 | unsigned long ii = ep->flags;
|
---|
| 244 | if(ii & GPSEPHF_L2CACODE)
|
---|
| 245 | dd += 2.0;
|
---|
| 246 | if(ii & GPSEPHF_L2PCODE)
|
---|
| 247 | dd += 1.0;
|
---|
[521] | 248 | line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->IDOT, dd,
|
---|
[520] | 249 | (double) ep->GPSweek, ii & GPSEPHF_L2PCODEDATA ? 1.0 : 0.0);
|
---|
| 250 | *_ephStream << line << endl;
|
---|
| 251 |
|
---|
[519] | 252 | if(ep->URAindex <= 6) /* URA index */
|
---|
| 253 | dd = ceil(10.0*pow(2.0, 1.0+((double)ep->URAindex)/2.0))/10.0;
|
---|
| 254 | else
|
---|
| 255 | dd = ceil(10.0*pow(2.0, ((double)ep->URAindex)/2.0))/10.0;
|
---|
[521] | 256 | line.sprintf(" %19.12e%19.12e%19.12e%19.12e", dd,
|
---|
[520] | 257 | ((double) ep->SVhealth), ep->TGD, ((double) ep->IODC));
|
---|
| 258 | *_ephStream << line << endl;
|
---|
[519] | 259 |
|
---|
[521] | 260 | line.sprintf(" %19.12e%19.12e", ((double)ep->TOW), 0.0);
|
---|
[520] | 261 | *_ephStream << line << endl;
|
---|
[519] | 262 |
|
---|
[518] | 263 | _ephStream->flush();
|
---|
[517] | 264 | }
|
---|
[516] | 265 | }
|
---|
| 266 |
|
---|
| 267 | //
|
---|
| 268 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 269 | void bncApp::printGlonassEph(glonassephemeris* ep) {
|
---|
[523] | 270 |
|
---|
[517] | 271 | if (_ephStream) {
|
---|
[527] | 272 | int ww = ep->GPSWeek;
|
---|
| 273 | int tow = ep->GPSTOW;
|
---|
[525] | 274 | struct converttimeinfo cti;
|
---|
[523] | 275 |
|
---|
[527] | 276 | updatetime(&ww, &tow, ep->tb*1000, 1);
|
---|
| 277 | converttime(&cti, ww, tow);
|
---|
[523] | 278 |
|
---|
[527] | 279 | int ii = ep->tk-3*60*60;
|
---|
| 280 | if (ii < 0) {
|
---|
| 281 | ii += 86400;
|
---|
| 282 | }
|
---|
[525] | 283 |
|
---|
| 284 | QString line;
|
---|
| 285 |
|
---|
| 286 | if (RINEX_3) {
|
---|
| 287 | line.sprintf("R%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e",
|
---|
| 288 | ep->almanac_number, cti.year, cti.month, cti.day, cti.hour,
|
---|
[527] | 289 | cti.minute, cti.second, -ep->tau, ep->gamma, (double) ii);
|
---|
[525] | 290 | }
|
---|
| 291 | else {
|
---|
| 292 | line.sprintf("%02d %02d %02d %02d %02d %02d%5.1f%19.12e%19.12e%19.12e",
|
---|
| 293 | ep->almanac_number, cti.year%100, cti.month, cti.day,
|
---|
| 294 | cti.hour, cti.minute, (double) cti.second, -ep->tau,
|
---|
[527] | 295 | ep->gamma, (double) ii);
|
---|
[525] | 296 | }
|
---|
| 297 | *_ephStream << line << endl;
|
---|
| 298 |
|
---|
| 299 | line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->x_pos,
|
---|
| 300 | ep->x_velocity, ep->x_acceleration,
|
---|
| 301 | (ep->flags & GLOEPHF_UNHEALTHY) ? 1.0 : 0.0);
|
---|
| 302 | *_ephStream << line << endl;
|
---|
| 303 |
|
---|
| 304 | line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->y_pos,
|
---|
| 305 | ep->y_velocity, ep->y_acceleration,
|
---|
| 306 | (double) ep->frequency_number);
|
---|
| 307 | *_ephStream << line << endl;
|
---|
| 308 |
|
---|
| 309 | line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->z_pos,
|
---|
| 310 | ep->z_velocity, ep->z_acceleration, (double) ep->E);
|
---|
| 311 | *_ephStream << line << endl;
|
---|
| 312 |
|
---|
[518] | 313 | _ephStream->flush();
|
---|
[517] | 314 | }
|
---|
[516] | 315 | }
|
---|