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

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

* empty log message *

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