source: ntrip/trunk/BNC/bncapp.cpp@ 560

Last change on this file since 560 was 559, checked in by mervart, 19 years ago

* empty log message *

File size: 14.1 KB
RevLine 
[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
49using namespace std;
50
[523]51struct 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
60extern "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////////////////////////////////////////////////////////////////////////////
67bncApp::bncApp(int argc, char* argv[], bool GUIenabled) :
68 QApplication(argc, argv, GUIenabled) {
[109]69
[533]70 _bncVersion = "BNC 1.4";
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
93 _pgmName = _bncVersion.leftJustified(20, ' ', true);
94#ifdef WIN32
95 _userName = QString("${USERNAME}");
96#else
97 _userName = QString("${USER}");
98#endif
99 expandEnvVar(_userName);
100 _userName = _userName.leftJustified(20, ' ', true);
[82]101}
102
103// Destructor
104////////////////////////////////////////////////////////////////////////////
105bncApp::~bncApp() {
[109]106 delete _logStream;
107 delete _logFile;
[533]108 delete _ephStreamGPS;
109 delete _ephFileGPS;
[534]110 if (_rinexVers == 2) {
[533]111 delete _ephStreamGlonass;
112 delete _ephFileGlonass;
113 }
[516]114 for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
115 delete _gpsEph[ii-PRN_GPS_START];
116 }
117 for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
118 delete _glonassEph[ii-PRN_GLONASS_START];
119 }
[82]120}
121
122// Write a Program Message
123////////////////////////////////////////////////////////////////////////////
124void bncApp::slotMessage(const QByteArray msg) {
[150]125
[243]126 QMutexLocker locker(&_mutex);
127
[150]128 // First time resolve the log file name
129 // ------------------------------------
130 if (_logFileFlag == 0) {
131 _logFileFlag = 1;
132 QSettings settings;
133 QString logFileName = settings.value("logFile").toString();
134 if ( !logFileName.isEmpty() ) {
[151]135 expandEnvVar(logFileName);
[150]136 _logFile = new QFile(logFileName);
[275]137 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
138 _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
139 }
140 else {
141 _logFile->open(QIODevice::WriteOnly);
142 }
[150]143 _logStream = new QTextStream();
144 _logStream->setDevice(_logFile);
145 }
146 }
147
[109]148 if (_logStream) {
[335]149 *_logStream << QDate::currentDate().toString("yy-MM-dd ").toAscii().data();
[199]150 *_logStream << QTime::currentTime().toString("hh:mm:ss ").toAscii().data();
[109]151 *_logStream << msg.data() << endl;
152 _logStream->flush();
[82]153 }
154}
[511]155
[535]156// New GPS Ephemeris
[511]157////////////////////////////////////////////////////////////////////////////
158void bncApp::slotNewGPSEph(gpsephemeris* gpseph) {
[516]159
160 QMutexLocker locker(&_mutex);
161
[534]162 printEphHeader();
163
[533]164 if (!_ephStreamGPS) {
[517]165 delete gpseph;
166 return;
167 }
168
[532]169 gpsephemeris** ee = &_gpsEph[gpseph->satellite-1];
[538]170 if ( *ee == 0 ||
171 gpseph->GPSweek > (*ee)->GPSweek ||
172 gpseph->TOW > (*ee)->TOW ) {
[516]173 delete *ee;
174 *ee = gpseph;
175 printGPSEph(gpseph);
176 }
177 else {
178 delete gpseph;
179 }
[511]180}
181
[535]182// New Glonass Ephemeris
[511]183////////////////////////////////////////////////////////////////////////////
184void bncApp::slotNewGlonassEph(glonassephemeris* glonasseph) {
[516]185
186 QMutexLocker locker(&_mutex);
187
[534]188 printEphHeader();
189
[533]190 if (!_ephStreamGlonass) {
[517]191 delete glonasseph;
192 return;
193 }
194
[532]195 glonassephemeris** ee = &_glonassEph[glonasseph->almanac_number-1];
[531]196
[538]197 if ( *ee == 0 ||
198 glonasseph->GPSWeek > (*ee)->GPSWeek ||
199 glonasseph->GPSTOW > (*ee)->GPSTOW ) {
[531]200 delete *ee;
201 *ee = glonasseph;
202 printGlonassEph(glonasseph);
203 }
204 else {
205 delete glonasseph;
206 }
[511]207}
208
[535]209// Print Header of the output File(s)
[516]210////////////////////////////////////////////////////////////////////////////
211void bncApp::printEphHeader() {
[528]212
[535]213 QSettings settings;
214
[534]215 // Initialization
216 // --------------
217 if (_rinexVers == 0) {
[528]218
[533]219 if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
[534]220 _rinexVers = 3;
[533]221 }
222 else {
[534]223 _rinexVers = 2;
[533]224 }
[529]225
[533]226 _ephPath = settings.value("ephPath").toString();
227
228 if ( !_ephPath.isEmpty() ) {
229 if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
230 _ephPath += QDir::separator();
231 }
232 expandEnvVar(_ephPath);
233 }
[517]234 }
[533]235
[534]236 // (Re-)Open output File(s)
237 // ------------------------
[533]238 if (!_ephPath.isEmpty()) {
239
240 QDate date = QDate::currentDate();
241
[535]242 QString hlp = (_rinexVers == 3) ? "MIX_" : "GPS_";
243 QString ephFileNameGPS = _ephPath + hlp +
[533]244 QString("%1").arg(date.dayOfYear(), 3, 10, QChar('0')) +
245 date.toString("0.yyN");
246
247 if (_ephFileNameGPS == ephFileNameGPS) {
248 return;
249 }
250 else {
251 _ephFileNameGPS = ephFileNameGPS;
252 }
253
254 delete _ephStreamGPS;
255 delete _ephFileGPS;
256
[535]257 QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
[536]258 QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
259
[535]260 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
261 QFile::exists(ephFileNameGPS) ) {
262 appendFlagGPS = QIODevice::Append;
263 }
264
[533]265 _ephFileGPS = new QFile(ephFileNameGPS);
[535]266 _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
[533]267 _ephStreamGPS = new QTextStream();
268 _ephStreamGPS->setDevice(_ephFileGPS);
269
[534]270 if (_rinexVers == 3) {
[533]271 _ephFileGlonass = _ephFileGPS;
272 _ephStreamGlonass = _ephStreamGPS;
273 }
[534]274 else if (_rinexVers == 2) {
[533]275 QString ephFileNameGlonass = _ephPath + "GLO_" +
276 QString("%1").arg(date.dayOfYear(), 3, 10, QChar('0')) +
277 date.toString("0.yyN");
278
279 delete _ephStreamGlonass;
280 delete _ephFileGlonass;
281
[535]282 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
283 QFile::exists(ephFileNameGlonass) ) {
284 appendFlagGlonass = QIODevice::Append;
285 }
286
[533]287 _ephFileGlonass = new QFile(ephFileNameGlonass);
[535]288 _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
[533]289 _ephStreamGlonass = new QTextStream();
290 _ephStreamGlonass->setDevice(_ephFileGlonass);
291 }
292
[534]293 // Header - RINEX Version 3
294 // ------------------------
295 if (_rinexVers == 3) {
[537]296 if ( ! (appendFlagGPS & QIODevice::Append)) {
297 QString line;
298 line.sprintf(
299 "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
300 3.0, "", "");
301 *_ephStreamGPS << line;
302
[559]303 QString hlp = QDateTime::currentDateTime().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
304 *_ephStreamGPS << _pgmName.toAscii().data()
305 << _userName.toAscii().data()
306 << hlp.toAscii().data()
307 << "PGM / RUN BY / DATE" << endl;
308
309 line.sprintf("%60sEND OF HEADER\n", "");
[537]310 *_ephStreamGPS << line;
311
312 _ephStreamGPS->flush();
[535]313 }
[533]314 }
315
[536]316 // Headers - RINEX Version 2
317 // -------------------------
[534]318 else if (_rinexVers == 2) {
[536]319 if (! (appendFlagGPS & QIODevice::Append)) {
320 QString line;
321 line.sprintf(
322 "%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n", 2.1, "", "");
323 *_ephStreamGPS << line;
324
[559]325 QString hlp = QDate::currentDate().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
326 *_ephStreamGPS << _pgmName.toAscii().data()
327 << _userName.toAscii().data()
328 << hlp.toAscii().data()
329 << "PGM / RUN BY / DATE" << endl;
330
331 line.sprintf("%60sEND OF HEADER\n", "");
[536]332 *_ephStreamGPS << line;
[537]333
334 _ephStreamGPS->flush();
[536]335 }
336 if (! (appendFlagGlonass & QIODevice::Append)) {
337 QString line;
338 line.sprintf(
339 "%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",2.1,"","");
340 *_ephStreamGlonass << line;
341
[559]342 QString hlp = QDate::currentDate().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
343 *_ephStreamGlonass << _pgmName.toAscii().data()
344 << _userName.toAscii().data()
345 << hlp.toAscii().data()
346 << "PGM / RUN BY / DATE" << endl;
347
348 line.sprintf("%60sEND OF HEADER\n", "");
[536]349 *_ephStreamGlonass << line;
[537]350
351 _ephStreamGlonass->flush();
[536]352 }
[533]353 }
354 }
[516]355}
356
[535]357// Print One GPS Ephemeris
[516]358////////////////////////////////////////////////////////////////////////////
359void bncApp::printGPSEph(gpsephemeris* ep) {
[519]360
[533]361 if (_ephStreamGPS) {
362
[519]363 QString line;
364
[524]365 struct converttimeinfo cti;
366 converttime(&cti, ep->GPSweek, ep->TOC);
367
[534]368 if (_rinexVers == 3) {
[526]369 line.sprintf("G%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e",
[524]370 ep->satellite, cti.year, cti.month, cti.day, cti.hour,
371 cti.minute, cti.second, ep->clock_bias, ep->clock_drift,
372 ep->clock_driftrate);
[519]373 }
[534]374 else if (_rinexVers == 2) {
[526]375 line.sprintf("%02d %02d %02d %02d %02d %02d%05.1f%19.12e%19.12e%19.12e",
[524]376 ep->satellite, cti.year%100, cti.month, cti.day, cti.hour,
377 cti.minute, (double) cti.second, ep->clock_bias,
[519]378 ep->clock_drift, ep->clock_driftrate);
379 }
[533]380 *_ephStreamGPS << line << endl;
[520]381
[521]382 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", (double)ep->IODE,
[520]383 ep->Crs, ep->Delta_n, ep->M0);
[533]384 *_ephStreamGPS << line << endl;
[520]385
[521]386 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->Cuc,
[520]387 ep->e, ep->Cus, ep->sqrt_A);
[533]388 *_ephStreamGPS << line << endl;
[520]389
[521]390 line.sprintf(" %19.12e%19.12e%19.12e%19.12e",
[520]391 (double) ep->TOE, ep->Cic, ep->OMEGA0, ep->Cis);
[533]392 *_ephStreamGPS << line << endl;
[520]393
[521]394 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->i0,
[520]395 ep->Crc, ep->omega, ep->OMEGADOT);
[533]396 *_ephStreamGPS << line << endl;
[520]397
[519]398 double dd = 0;
399 unsigned long ii = ep->flags;
400 if(ii & GPSEPHF_L2CACODE)
401 dd += 2.0;
402 if(ii & GPSEPHF_L2PCODE)
403 dd += 1.0;
[521]404 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->IDOT, dd,
[520]405 (double) ep->GPSweek, ii & GPSEPHF_L2PCODEDATA ? 1.0 : 0.0);
[533]406 *_ephStreamGPS << line << endl;
[520]407
[519]408 if(ep->URAindex <= 6) /* URA index */
409 dd = ceil(10.0*pow(2.0, 1.0+((double)ep->URAindex)/2.0))/10.0;
410 else
411 dd = ceil(10.0*pow(2.0, ((double)ep->URAindex)/2.0))/10.0;
[521]412 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", dd,
[520]413 ((double) ep->SVhealth), ep->TGD, ((double) ep->IODC));
[533]414 *_ephStreamGPS << line << endl;
[519]415
[521]416 line.sprintf(" %19.12e%19.12e", ((double)ep->TOW), 0.0);
[533]417 *_ephStreamGPS << line << endl;
[519]418
[533]419 _ephStreamGPS->flush();
[517]420 }
[516]421}
422
[535]423// Print One Glonass Ephemeris
[516]424////////////////////////////////////////////////////////////////////////////
425void bncApp::printGlonassEph(glonassephemeris* ep) {
[523]426
[533]427 if (_ephStreamGlonass) {
[527]428 int ww = ep->GPSWeek;
429 int tow = ep->GPSTOW;
[525]430 struct converttimeinfo cti;
[523]431
[527]432 updatetime(&ww, &tow, ep->tb*1000, 1);
433 converttime(&cti, ww, tow);
[523]434
[527]435 int ii = ep->tk-3*60*60;
436 if (ii < 0) {
437 ii += 86400;
438 }
[525]439
440 QString line;
441
[534]442 if (_rinexVers == 3) {
[525]443 line.sprintf("R%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e",
444 ep->almanac_number, cti.year, cti.month, cti.day, cti.hour,
[527]445 cti.minute, cti.second, -ep->tau, ep->gamma, (double) ii);
[525]446 }
[534]447 else if (_rinexVers == 2) {
[525]448 line.sprintf("%02d %02d %02d %02d %02d %02d%5.1f%19.12e%19.12e%19.12e",
449 ep->almanac_number, cti.year%100, cti.month, cti.day,
450 cti.hour, cti.minute, (double) cti.second, -ep->tau,
[527]451 ep->gamma, (double) ii);
[525]452 }
[533]453 *_ephStreamGlonass << line << endl;
[525]454
455 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->x_pos,
456 ep->x_velocity, ep->x_acceleration,
457 (ep->flags & GLOEPHF_UNHEALTHY) ? 1.0 : 0.0);
[533]458 *_ephStreamGlonass << line << endl;
[525]459
460 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->y_pos,
461 ep->y_velocity, ep->y_acceleration,
462 (double) ep->frequency_number);
[533]463 *_ephStreamGlonass << line << endl;
[525]464
465 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->z_pos,
466 ep->z_velocity, ep->z_acceleration, (double) ep->E);
[533]467 *_ephStreamGlonass << line << endl;
[525]468
[533]469 _ephStreamGlonass->flush();
[517]470 }
[516]471}
Note: See TracBrowser for help on using the repository browser.