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

Last change on this file since 526 was 526, checked in by mervart, 17 years ago

* empty log message *

File size: 9.2 KB
Line 
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
49using namespace std;
50
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
66// Constructor
67////////////////////////////////////////////////////////////////////////////
68bncApp::bncApp(int argc, char* argv[], bool GUIenabled) :
69 QApplication(argc, argv, GUIenabled) {
70
71 _logFileFlag = 0;
72 _logFile = 0;
73 _logStream = 0;
74
75 _bncVersion = "BNC 1.4";
76
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 }
102}
103
104// Destructor
105////////////////////////////////////////////////////////////////////////////
106bncApp::~bncApp() {
107 delete _logStream;
108 delete _logFile;
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 }
117}
118
119// Write a Program Message
120////////////////////////////////////////////////////////////////////////////
121void bncApp::slotMessage(const QByteArray msg) {
122
123 QMutexLocker locker(&_mutex);
124
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() ) {
132 expandEnvVar(logFileName);
133 _logFile = new QFile(logFileName);
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 }
140 _logStream = new QTextStream();
141 _logStream->setDevice(_logFile);
142 }
143 }
144
145 if (_logStream) {
146 *_logStream << QDate::currentDate().toString("yy-MM-dd ").toAscii().data();
147 *_logStream << QTime::currentTime().toString("hh:mm:ss ").toAscii().data();
148 *_logStream << msg.data() << endl;
149 _logStream->flush();
150 }
151}
152
153//
154////////////////////////////////////////////////////////////////////////////
155void bncApp::slotNewGPSEph(gpsephemeris* gpseph) {
156
157 QMutexLocker locker(&_mutex);
158
159 if (!_ephStream) {
160 delete gpseph;
161 return;
162 }
163
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 }
173}
174
175//
176////////////////////////////////////////////////////////////////////////////
177void bncApp::slotNewGlonassEph(glonassephemeris* glonasseph) {
178
179 QMutexLocker locker(&_mutex);
180
181 if (!_ephStream) {
182 delete glonasseph;
183 return;
184 }
185
186 delete glonasseph;
187}
188
189//
190////////////////////////////////////////////////////////////////////////////
191void bncApp::printEphHeader() {
192 if (_ephStream) {
193 *_ephStream << QDate::currentDate().toString("yy-MM-dd ").toAscii().data();
194 *_ephStream << QTime::currentTime().toString("hh:mm:ss ").toAscii().data();
195 _ephStream->flush();
196 }
197}
198
199const int RINEX_3 = 1;
200
201//
202////////////////////////////////////////////////////////////////////////////
203void bncApp::printGPSEph(gpsephemeris* ep) {
204
205 if (_ephStream) {
206
207 QString line;
208
209 struct converttimeinfo cti;
210 converttime(&cti, ep->GPSweek, ep->TOC);
211
212 if (RINEX_3) {
213 line.sprintf("G%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e",
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);
217 }
218 else {
219 line.sprintf("%02d %02d %02d %02d %02d %02d%05.1f%19.12e%19.12e%19.12e",
220 ep->satellite, cti.year%100, cti.month, cti.day, cti.hour,
221 cti.minute, (double) cti.second, ep->clock_bias,
222 ep->clock_drift, ep->clock_driftrate);
223 }
224 *_ephStream << line << endl;
225
226 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", (double)ep->IODE,
227 ep->Crs, ep->Delta_n, ep->M0);
228 *_ephStream << line << endl;
229
230 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->Cuc,
231 ep->e, ep->Cus, ep->sqrt_A);
232 *_ephStream << line << endl;
233
234 line.sprintf(" %19.12e%19.12e%19.12e%19.12e",
235 (double) ep->TOE, ep->Cic, ep->OMEGA0, ep->Cis);
236 *_ephStream << line << endl;
237
238 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->i0,
239 ep->Crc, ep->omega, ep->OMEGADOT);
240 *_ephStream << line << endl;
241
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;
248 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->IDOT, dd,
249 (double) ep->GPSweek, ii & GPSEPHF_L2PCODEDATA ? 1.0 : 0.0);
250 *_ephStream << line << endl;
251
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;
256 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", dd,
257 ((double) ep->SVhealth), ep->TGD, ((double) ep->IODC));
258 *_ephStream << line << endl;
259
260 line.sprintf(" %19.12e%19.12e", ((double)ep->TOW), 0.0);
261 *_ephStream << line << endl;
262
263 _ephStream->flush();
264 }
265}
266
267//
268////////////////////////////////////////////////////////////////////////////
269void bncApp::printGlonassEph(glonassephemeris* ep) {
270
271 if (_ephStream) {
272 int w = ep->GPSWeek, tow = ep->GPSTOW, i;
273 struct converttimeinfo cti;
274
275 updatetime(&w, &tow, ep->tb*1000, 1);
276 converttime(&cti, w, tow);
277
278 i = ep->tk-3*60*60; if(i < 0) i += 86400;
279
280 QString line;
281
282 if (RINEX_3) {
283 line.sprintf("R%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e",
284 ep->almanac_number, cti.year, cti.month, cti.day, cti.hour,
285 cti.minute, cti.second, -ep->tau, ep->gamma, (double) i);
286 }
287 else {
288 line.sprintf("%02d %02d %02d %02d %02d %02d%5.1f%19.12e%19.12e%19.12e",
289 ep->almanac_number, cti.year%100, cti.month, cti.day,
290 cti.hour, cti.minute, (double) cti.second, -ep->tau,
291 ep->gamma, (double) i);
292 }
293 *_ephStream << line << endl;
294
295 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->x_pos,
296 ep->x_velocity, ep->x_acceleration,
297 (ep->flags & GLOEPHF_UNHEALTHY) ? 1.0 : 0.0);
298 *_ephStream << line << endl;
299
300 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->y_pos,
301 ep->y_velocity, ep->y_acceleration,
302 (double) ep->frequency_number);
303 *_ephStream << line << endl;
304
305 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->z_pos,
306 ep->z_velocity, ep->z_acceleration, (double) ep->E);
307 *_ephStream << line << endl;
308
309 _ephStream->flush();
310 }
311}
Note: See TracBrowser for help on using the repository browser.