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

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

* empty log message *

File size: 9.8 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
51const int RINEX_3 = 1;
52
53struct converttimeinfo {
54 int second; /* seconds of GPS time [0..59] */
55 int minute; /* minutes of GPS time [0..59] */
56 int hour; /* hour of GPS time [0..24] */
57 int day; /* day of GPS time [1..28..30(31)*/
58 int month; /* month of GPS time [1..12]*/
59 int year; /* year of GPS time [1980..] */
60};
61
62extern "C" {
63 void converttime(struct converttimeinfo *c, int week, int tow);
64 void updatetime(int *week, int *tow, int tk, int fixnumleap);
65 int HandleRunBy(char *buffer, int buffersize, const char **u, int rinex3);
66}
67
68
69// Constructor
70////////////////////////////////////////////////////////////////////////////
71bncApp::bncApp(int argc, char* argv[], bool GUIenabled) :
72 QApplication(argc, argv, GUIenabled) {
73
74 _logFileFlag = 0;
75 _logFile = 0;
76 _logStream = 0;
77
78 _bncVersion = "BNC 1.4";
79
80 // Lists of Ephemeris
81 // ------------------
82 _ephFile = 0;
83 _ephStream = 0;
84 for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
85 _gpsEph[ii-PRN_GPS_START] = 0;
86 }
87 for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
88 _glonassEph[ii-PRN_GLONASS_START] = 0;
89 }
90
91 // Eph file
92 // --------
93 _ephFile = 0;
94 _ephStream = 0;
95 QString ephFileName = "TEST.EPH";
96 //// QString ephFileName = settings.value("ephFile").toString();
97 if ( !ephFileName.isEmpty() ) {
98 expandEnvVar(ephFileName);
99 _ephFile = new QFile(ephFileName);
100 _ephFile->open(QIODevice::WriteOnly);
101 _ephStream = new QTextStream();
102 _ephStream->setDevice(_ephFile);
103 printEphHeader();
104 }
105}
106
107// Destructor
108////////////////////////////////////////////////////////////////////////////
109bncApp::~bncApp() {
110 delete _logStream;
111 delete _logFile;
112 delete _ephStream;
113 delete _ephFile;
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 }
120}
121
122// Write a Program Message
123////////////////////////////////////////////////////////////////////////////
124void bncApp::slotMessage(const QByteArray msg) {
125
126 QMutexLocker locker(&_mutex);
127
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() ) {
135 expandEnvVar(logFileName);
136 _logFile = new QFile(logFileName);
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 }
143 _logStream = new QTextStream();
144 _logStream->setDevice(_logFile);
145 }
146 }
147
148 if (_logStream) {
149 *_logStream << QDate::currentDate().toString("yy-MM-dd ").toAscii().data();
150 *_logStream << QTime::currentTime().toString("hh:mm:ss ").toAscii().data();
151 *_logStream << msg.data() << endl;
152 _logStream->flush();
153 }
154}
155
156//
157////////////////////////////////////////////////////////////////////////////
158void bncApp::slotNewGPSEph(gpsephemeris* gpseph) {
159
160 QMutexLocker locker(&_mutex);
161
162 if (!_ephStream) {
163 delete gpseph;
164 return;
165 }
166
167 gpsephemeris** ee = &_gpsEph[gpseph->satellite-PRN_GPS_START];
168 if ( *ee == 0 || (*ee)->IODE != gpseph->IODE ) {
169 delete *ee;
170 *ee = gpseph;
171 printGPSEph(gpseph);
172 }
173 else {
174 delete gpseph;
175 }
176}
177
178//
179////////////////////////////////////////////////////////////////////////////
180void bncApp::slotNewGlonassEph(glonassephemeris* glonasseph) {
181
182 QMutexLocker locker(&_mutex);
183
184 if (!_ephStream) {
185 delete glonasseph;
186 return;
187 }
188
189 glonassephemeris** ee =
190 &_glonassEph[glonasseph->almanac_number-PRN_GLONASS_START];
191
192 if ( *ee == 0 || (*ee)->GPSWeek != glonasseph->GPSWeek ||
193 (*ee)->GPSTOW != glonasseph->GPSTOW ) {
194 delete *ee;
195 *ee = glonasseph;
196 printGlonassEph(glonasseph);
197 }
198 else {
199 delete glonasseph;
200 }
201}
202
203//
204////////////////////////////////////////////////////////////////////////////
205void bncApp::printEphHeader() {
206 if (_ephStream) {
207 QString line;
208
209 line.sprintf(
210 "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
211 3.0, "", "");
212 *_ephStream << line;
213
214 char buffer[100];
215 HandleRunBy(buffer, sizeof(buffer), 0, RINEX_3);
216 line.sprintf("%s\n%60sEND OF HEADER\n", buffer, "");
217 *_ephStream << line;
218
219 _ephStream->flush();
220 }
221}
222
223
224//
225////////////////////////////////////////////////////////////////////////////
226void bncApp::printGPSEph(gpsephemeris* ep) {
227
228 if (_ephStream) {
229
230 QString line;
231
232 struct converttimeinfo cti;
233 converttime(&cti, ep->GPSweek, ep->TOC);
234
235 if (RINEX_3) {
236 line.sprintf("G%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e",
237 ep->satellite, cti.year, cti.month, cti.day, cti.hour,
238 cti.minute, cti.second, ep->clock_bias, ep->clock_drift,
239 ep->clock_driftrate);
240 }
241 else {
242 line.sprintf("%02d %02d %02d %02d %02d %02d%05.1f%19.12e%19.12e%19.12e",
243 ep->satellite, cti.year%100, cti.month, cti.day, cti.hour,
244 cti.minute, (double) cti.second, ep->clock_bias,
245 ep->clock_drift, ep->clock_driftrate);
246 }
247 *_ephStream << line << endl;
248
249 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", (double)ep->IODE,
250 ep->Crs, ep->Delta_n, ep->M0);
251 *_ephStream << line << endl;
252
253 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->Cuc,
254 ep->e, ep->Cus, ep->sqrt_A);
255 *_ephStream << line << endl;
256
257 line.sprintf(" %19.12e%19.12e%19.12e%19.12e",
258 (double) ep->TOE, ep->Cic, ep->OMEGA0, ep->Cis);
259 *_ephStream << line << endl;
260
261 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->i0,
262 ep->Crc, ep->omega, ep->OMEGADOT);
263 *_ephStream << line << endl;
264
265 double dd = 0;
266 unsigned long ii = ep->flags;
267 if(ii & GPSEPHF_L2CACODE)
268 dd += 2.0;
269 if(ii & GPSEPHF_L2PCODE)
270 dd += 1.0;
271 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->IDOT, dd,
272 (double) ep->GPSweek, ii & GPSEPHF_L2PCODEDATA ? 1.0 : 0.0);
273 *_ephStream << line << endl;
274
275 if(ep->URAindex <= 6) /* URA index */
276 dd = ceil(10.0*pow(2.0, 1.0+((double)ep->URAindex)/2.0))/10.0;
277 else
278 dd = ceil(10.0*pow(2.0, ((double)ep->URAindex)/2.0))/10.0;
279 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", dd,
280 ((double) ep->SVhealth), ep->TGD, ((double) ep->IODC));
281 *_ephStream << line << endl;
282
283 line.sprintf(" %19.12e%19.12e", ((double)ep->TOW), 0.0);
284 *_ephStream << line << endl;
285
286 _ephStream->flush();
287 }
288}
289
290//
291////////////////////////////////////////////////////////////////////////////
292void bncApp::printGlonassEph(glonassephemeris* ep) {
293
294 if (_ephStream) {
295 int ww = ep->GPSWeek;
296 int tow = ep->GPSTOW;
297 struct converttimeinfo cti;
298
299 updatetime(&ww, &tow, ep->tb*1000, 1);
300 converttime(&cti, ww, tow);
301
302 int ii = ep->tk-3*60*60;
303 if (ii < 0) {
304 ii += 86400;
305 }
306
307 QString line;
308
309 if (RINEX_3) {
310 line.sprintf("R%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e",
311 ep->almanac_number, cti.year, cti.month, cti.day, cti.hour,
312 cti.minute, cti.second, -ep->tau, ep->gamma, (double) ii);
313 }
314 else {
315 line.sprintf("%02d %02d %02d %02d %02d %02d%5.1f%19.12e%19.12e%19.12e",
316 ep->almanac_number, cti.year%100, cti.month, cti.day,
317 cti.hour, cti.minute, (double) cti.second, -ep->tau,
318 ep->gamma, (double) ii);
319 }
320 *_ephStream << line << endl;
321
322 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->x_pos,
323 ep->x_velocity, ep->x_acceleration,
324 (ep->flags & GLOEPHF_UNHEALTHY) ? 1.0 : 0.0);
325 *_ephStream << line << endl;
326
327 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->y_pos,
328 ep->y_velocity, ep->y_acceleration,
329 (double) ep->frequency_number);
330 *_ephStream << line << endl;
331
332 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->z_pos,
333 ep->z_velocity, ep->z_acceleration, (double) ep->E);
334 *_ephStream << line << endl;
335
336 _ephStream->flush();
337 }
338}
Note: See TracBrowser for help on using the repository browser.