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

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

* empty log message *

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