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

Last change on this file since 528 was 528, checked in by mervart, 18 years ago

* empty log message *

File size: 9.3 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
65
[82]66// Constructor
67////////////////////////////////////////////////////////////////////////////
68bncApp::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////////////////////////////////////////////////////////////////////////////
106bncApp::~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////////////////////////////////////////////////////////////////////////////
121void 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////////////////////////////////////////////////////////////////////////////
155void 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////////////////////////////////////////////////////////////////////////////
177void 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////////////////////////////////////////////////////////////////////////////
191void bncApp::printEphHeader() {
[517]192 if (_ephStream) {
[528]193 QString line;
194
195 line.sprintf(
196 "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
197 3.0, "", "");
198 *_ephStream << line;
199
200 line.sprintf("%s\n%60sEND OF HEADER\n", "bnc", "");
201 *_ephStream << line;
202
[518]203 _ephStream->flush();
[517]204 }
[516]205}
206
[525]207const int RINEX_3 = 1;
208
[516]209//
210////////////////////////////////////////////////////////////////////////////
211void bncApp::printGPSEph(gpsephemeris* ep) {
[519]212
[517]213 if (_ephStream) {
[519]214
215 QString line;
216
[524]217 struct converttimeinfo cti;
218 converttime(&cti, ep->GPSweek, ep->TOC);
219
[519]220 if (RINEX_3) {
[526]221 line.sprintf("G%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e",
[524]222 ep->satellite, cti.year, cti.month, cti.day, cti.hour,
223 cti.minute, cti.second, ep->clock_bias, ep->clock_drift,
224 ep->clock_driftrate);
[519]225 }
226 else {
[526]227 line.sprintf("%02d %02d %02d %02d %02d %02d%05.1f%19.12e%19.12e%19.12e",
[524]228 ep->satellite, cti.year%100, cti.month, cti.day, cti.hour,
229 cti.minute, (double) cti.second, ep->clock_bias,
[519]230 ep->clock_drift, ep->clock_driftrate);
231 }
[520]232 *_ephStream << line << endl;
233
[521]234 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", (double)ep->IODE,
[520]235 ep->Crs, ep->Delta_n, ep->M0);
236 *_ephStream << line << endl;
237
[521]238 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->Cuc,
[520]239 ep->e, ep->Cus, ep->sqrt_A);
240 *_ephStream << line << endl;
241
[521]242 line.sprintf(" %19.12e%19.12e%19.12e%19.12e",
[520]243 (double) ep->TOE, ep->Cic, ep->OMEGA0, ep->Cis);
244 *_ephStream << line << endl;
245
[521]246 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->i0,
[520]247 ep->Crc, ep->omega, ep->OMEGADOT);
248 *_ephStream << line << endl;
249
[519]250 double dd = 0;
251 unsigned long ii = ep->flags;
252 if(ii & GPSEPHF_L2CACODE)
253 dd += 2.0;
254 if(ii & GPSEPHF_L2PCODE)
255 dd += 1.0;
[521]256 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->IDOT, dd,
[520]257 (double) ep->GPSweek, ii & GPSEPHF_L2PCODEDATA ? 1.0 : 0.0);
258 *_ephStream << line << endl;
259
[519]260 if(ep->URAindex <= 6) /* URA index */
261 dd = ceil(10.0*pow(2.0, 1.0+((double)ep->URAindex)/2.0))/10.0;
262 else
263 dd = ceil(10.0*pow(2.0, ((double)ep->URAindex)/2.0))/10.0;
[521]264 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", dd,
[520]265 ((double) ep->SVhealth), ep->TGD, ((double) ep->IODC));
266 *_ephStream << line << endl;
[519]267
[521]268 line.sprintf(" %19.12e%19.12e", ((double)ep->TOW), 0.0);
[520]269 *_ephStream << line << endl;
[519]270
[518]271 _ephStream->flush();
[517]272 }
[516]273}
274
275//
276////////////////////////////////////////////////////////////////////////////
277void bncApp::printGlonassEph(glonassephemeris* ep) {
[523]278
[517]279 if (_ephStream) {
[527]280 int ww = ep->GPSWeek;
281 int tow = ep->GPSTOW;
[525]282 struct converttimeinfo cti;
[523]283
[527]284 updatetime(&ww, &tow, ep->tb*1000, 1);
285 converttime(&cti, ww, tow);
[523]286
[527]287 int ii = ep->tk-3*60*60;
288 if (ii < 0) {
289 ii += 86400;
290 }
[525]291
292 QString line;
293
294 if (RINEX_3) {
295 line.sprintf("R%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e",
296 ep->almanac_number, cti.year, cti.month, cti.day, cti.hour,
[527]297 cti.minute, cti.second, -ep->tau, ep->gamma, (double) ii);
[525]298 }
299 else {
300 line.sprintf("%02d %02d %02d %02d %02d %02d%5.1f%19.12e%19.12e%19.12e",
301 ep->almanac_number, cti.year%100, cti.month, cti.day,
302 cti.hour, cti.minute, (double) cti.second, -ep->tau,
[527]303 ep->gamma, (double) ii);
[525]304 }
305 *_ephStream << line << endl;
306
307 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->x_pos,
308 ep->x_velocity, ep->x_acceleration,
309 (ep->flags & GLOEPHF_UNHEALTHY) ? 1.0 : 0.0);
310 *_ephStream << line << endl;
311
312 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->y_pos,
313 ep->y_velocity, ep->y_acceleration,
314 (double) ep->frequency_number);
315 *_ephStream << line << endl;
316
317 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->z_pos,
318 ep->z_velocity, ep->z_acceleration, (double) ep->E);
319 *_ephStream << line << endl;
320
[518]321 _ephStream->flush();
[517]322 }
[516]323}
Note: See TracBrowser for help on using the repository browser.