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

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

* empty log message *

File size: 7.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
51// Constructor
52////////////////////////////////////////////////////////////////////////////
53bncApp::bncApp(int argc, char* argv[], bool GUIenabled) :
54 QApplication(argc, argv, GUIenabled) {
55
56 _logFileFlag = 0;
57 _logFile = 0;
58 _logStream = 0;
59
60 _bncVersion = "BNC 1.4";
61
62 // Lists of Ephemeris
63 // ------------------
64 _ephFile = 0;
65 _ephStream = 0;
66 for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
67 _gpsEph[ii-PRN_GPS_START] = 0;
68 }
69 for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
70 _glonassEph[ii-PRN_GLONASS_START] = 0;
71 }
72
73 // Eph file
74 // --------
75 _ephFile = 0;
76 _ephStream = 0;
77 QString ephFileName = "TEST.EPH";
78 //// QString ephFileName = settings.value("ephFile").toString();
79 if ( !ephFileName.isEmpty() ) {
80 expandEnvVar(ephFileName);
81 _ephFile = new QFile(ephFileName);
82 _ephFile->open(QIODevice::WriteOnly);
83 _ephStream = new QTextStream();
84 _ephStream->setDevice(_ephFile);
85 printEphHeader();
86 }
87}
88
89// Destructor
90////////////////////////////////////////////////////////////////////////////
91bncApp::~bncApp() {
92 delete _logStream;
93 delete _logFile;
94 delete _ephStream;
95 delete _ephFile;
96 for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
97 delete _gpsEph[ii-PRN_GPS_START];
98 }
99 for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
100 delete _glonassEph[ii-PRN_GLONASS_START];
101 }
102}
103
104// Write a Program Message
105////////////////////////////////////////////////////////////////////////////
106void bncApp::slotMessage(const QByteArray msg) {
107
108 QMutexLocker locker(&_mutex);
109
110 // First time resolve the log file name
111 // ------------------------------------
112 if (_logFileFlag == 0) {
113 _logFileFlag = 1;
114 QSettings settings;
115 QString logFileName = settings.value("logFile").toString();
116 if ( !logFileName.isEmpty() ) {
117 expandEnvVar(logFileName);
118 _logFile = new QFile(logFileName);
119 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
120 _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
121 }
122 else {
123 _logFile->open(QIODevice::WriteOnly);
124 }
125 _logStream = new QTextStream();
126 _logStream->setDevice(_logFile);
127 }
128 }
129
130 if (_logStream) {
131 *_logStream << QDate::currentDate().toString("yy-MM-dd ").toAscii().data();
132 *_logStream << QTime::currentTime().toString("hh:mm:ss ").toAscii().data();
133 *_logStream << msg.data() << endl;
134 _logStream->flush();
135 }
136}
137
138//
139////////////////////////////////////////////////////////////////////////////
140void bncApp::slotNewGPSEph(gpsephemeris* gpseph) {
141
142 QMutexLocker locker(&_mutex);
143
144 if (!_ephStream) {
145 delete gpseph;
146 return;
147 }
148
149 gpsephemeris** ee = &_gpsEph[gpseph->satellite-PRN_GPS_START];
150 if ( *ee == 0 || (*ee)->IODE != gpseph->IODE ) {
151 delete *ee;
152 *ee = gpseph;
153 printGPSEph(gpseph);
154 }
155 else {
156 delete gpseph;
157 }
158}
159
160//
161////////////////////////////////////////////////////////////////////////////
162void bncApp::slotNewGlonassEph(glonassephemeris* glonasseph) {
163
164 QMutexLocker locker(&_mutex);
165
166 if (!_ephStream) {
167 delete glonasseph;
168 return;
169 }
170
171 delete glonasseph;
172}
173
174//
175////////////////////////////////////////////////////////////////////////////
176void bncApp::printEphHeader() {
177 if (_ephStream) {
178 *_ephStream << QDate::currentDate().toString("yy-MM-dd ").toAscii().data();
179 *_ephStream << QTime::currentTime().toString("hh:mm:ss ").toAscii().data();
180 _ephStream->flush();
181 }
182}
183
184//
185////////////////////////////////////////////////////////////////////////////
186void bncApp::printGPSEph(gpsephemeris* ep) {
187
188 const int RINEX_3 = 1;
189
190 if (_ephStream) {
191
192 QDateTime datTim = dateAndTimeFromGPSweek(ep->GPSweek, ep->TOC);
193
194 QString line;
195
196 if (RINEX_3) {
197 line.sprintf("G%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e",
198 ep->satellite, datTim.date().year(),
199 datTim.date().month(), datTim.date().day(),
200 datTim.time().hour(), datTim.time().minute(),
201 datTim.time().second(), ep->clock_bias,
202 ep->clock_drift, ep->clock_driftrate);
203 }
204 else {
205 line.sprintf("%02d %02d %02d %02d %02d %02d%05.1f%19.12e%19.12e%19.12e",
206 ep->satellite, datTim.date().year()%100,
207 datTim.date().month(), datTim.date().day(),
208 datTim.time().hour(), datTim.time().minute(),
209 (double) datTim.time().second(), ep->clock_bias,
210 ep->clock_drift, ep->clock_driftrate);
211 }
212 *_ephStream << line << endl;
213
214 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", (double)ep->IODE,
215 ep->Crs, ep->Delta_n, ep->M0);
216 *_ephStream << line << endl;
217
218 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->Cuc,
219 ep->e, ep->Cus, ep->sqrt_A);
220 *_ephStream << line << endl;
221
222 line.sprintf(" %19.12e%19.12e%19.12e%19.12e",
223 (double) ep->TOE, ep->Cic, ep->OMEGA0, ep->Cis);
224 *_ephStream << line << endl;
225
226 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->i0,
227 ep->Crc, ep->omega, ep->OMEGADOT);
228 *_ephStream << line << endl;
229
230 double dd = 0;
231 unsigned long ii = ep->flags;
232 if(ii & GPSEPHF_L2CACODE)
233 dd += 2.0;
234 if(ii & GPSEPHF_L2PCODE)
235 dd += 1.0;
236 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", ep->IDOT, dd,
237 (double) ep->GPSweek, ii & GPSEPHF_L2PCODEDATA ? 1.0 : 0.0);
238 *_ephStream << line << endl;
239
240 if(ep->URAindex <= 6) /* URA index */
241 dd = ceil(10.0*pow(2.0, 1.0+((double)ep->URAindex)/2.0))/10.0;
242 else
243 dd = ceil(10.0*pow(2.0, ((double)ep->URAindex)/2.0))/10.0;
244 line.sprintf(" %19.12e%19.12e%19.12e%19.12e", dd,
245 ((double) ep->SVhealth), ep->TGD, ((double) ep->IODC));
246 *_ephStream << line << endl;
247
248 line.sprintf(" %19.12e%19.12e", ((double)ep->TOW), 0.0);
249 *_ephStream << line << endl;
250
251 _ephStream->flush();
252 }
253}
254
255//
256////////////////////////////////////////////////////////////////////////////
257void bncApp::printGlonassEph(glonassephemeris* ep) {
258 if (_ephStream) {
259 *_ephStream << "GLONASS: " << ep->almanac_number << endl;
260 _ephStream->flush();
261 }
262}
Note: See TracBrowser for help on using the repository browser.