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 <QMessageBox>
|
---|
43 | #include <cmath>
|
---|
44 |
|
---|
45 | #include "bncapp.h"
|
---|
46 | #include "bncutils.h"
|
---|
47 | #include "bncrinex.h"
|
---|
48 | #include "bncsettings.h"
|
---|
49 | #include "bncversion.h"
|
---|
50 | #include "bnccomb.h"
|
---|
51 |
|
---|
52 | using namespace std;
|
---|
53 |
|
---|
54 | // Constructor
|
---|
55 | ////////////////////////////////////////////////////////////////////////////
|
---|
56 | bncApp::bncApp(int& argc, char* argv[], bool GUIenabled) :
|
---|
57 | QApplication(argc, argv, GUIenabled) {
|
---|
58 |
|
---|
59 | _logFileFlag = 0;
|
---|
60 | _logFile = 0;
|
---|
61 | _logStream = 0;
|
---|
62 | _caster = 0;
|
---|
63 | _rawFile = 0;
|
---|
64 |
|
---|
65 | // Lists of Ephemeris
|
---|
66 | // ------------------
|
---|
67 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
---|
68 | _gpsEph[ii-PRN_GPS_START] = 0;
|
---|
69 | }
|
---|
70 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
---|
71 | _glonassEph[ii-PRN_GLONASS_START] = 0;
|
---|
72 | }
|
---|
73 | for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
|
---|
74 | _galileoEph[ii-PRN_GALILEO_START] = 0;
|
---|
75 | }
|
---|
76 |
|
---|
77 | // Eph file(s)
|
---|
78 | // -----------
|
---|
79 | _rinexVers = 0;
|
---|
80 | _ephFileGPS = 0;
|
---|
81 | _ephStreamGPS = 0;
|
---|
82 | _ephFileGlonass = 0;
|
---|
83 | _ephStreamGlonass = 0;
|
---|
84 | _ephFileGalileo = 0;
|
---|
85 | _ephStreamGalileo = 0;
|
---|
86 |
|
---|
87 | _port = 0;
|
---|
88 | _server = 0;
|
---|
89 | _sockets = 0;
|
---|
90 |
|
---|
91 | _portCorr = 0;
|
---|
92 | _serverCorr = 0;
|
---|
93 | _socketsCorr = 0;
|
---|
94 |
|
---|
95 | _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
|
---|
96 | #ifdef WIN32
|
---|
97 | _userName = QString("${USERNAME}");
|
---|
98 | #else
|
---|
99 | _userName = QString("${USER}");
|
---|
100 | #endif
|
---|
101 | expandEnvVar(_userName);
|
---|
102 | _userName = _userName.leftJustified(20, ' ', true);
|
---|
103 |
|
---|
104 | _lastDumpCoSec = 0;
|
---|
105 |
|
---|
106 | _corrs = new QMultiMap<long, QString>;
|
---|
107 |
|
---|
108 | _currentDateAndTimeGPS = 0;
|
---|
109 |
|
---|
110 | for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
|
---|
111 | _GLOFreq[ii] = 0;
|
---|
112 | }
|
---|
113 |
|
---|
114 | _bncComb = new bncComb();
|
---|
115 | }
|
---|
116 |
|
---|
117 | // Destructor
|
---|
118 | ////////////////////////////////////////////////////////////////////////////
|
---|
119 | bncApp::~bncApp() {
|
---|
120 | delete _logStream;
|
---|
121 | delete _logFile;
|
---|
122 | delete _ephStreamGPS;
|
---|
123 | delete _ephFileGPS;
|
---|
124 | delete _server;
|
---|
125 | delete _sockets;
|
---|
126 | delete _serverCorr;
|
---|
127 | delete _socketsCorr;
|
---|
128 | if (_rinexVers == 2) {
|
---|
129 | delete _ephStreamGlonass;
|
---|
130 | delete _ephFileGlonass;
|
---|
131 | }
|
---|
132 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
---|
133 | delete _gpsEph[ii-PRN_GPS_START];
|
---|
134 | }
|
---|
135 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
---|
136 | delete _glonassEph[ii-PRN_GLONASS_START];
|
---|
137 | }
|
---|
138 | for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
|
---|
139 | delete _galileoEph[ii-PRN_GALILEO_START];
|
---|
140 | }
|
---|
141 |
|
---|
142 | delete _corrs;
|
---|
143 |
|
---|
144 | delete _currentDateAndTimeGPS;
|
---|
145 |
|
---|
146 | delete _rawFile;
|
---|
147 |
|
---|
148 | delete _bncComb;
|
---|
149 | }
|
---|
150 |
|
---|
151 | // Write a Program Message
|
---|
152 | ////////////////////////////////////////////////////////////////////////////
|
---|
153 | void bncApp::slotMessage(QByteArray msg, bool showOnScreen) {
|
---|
154 |
|
---|
155 | QMutexLocker locker(&_mutexMessage);
|
---|
156 |
|
---|
157 | messagePrivate(msg);
|
---|
158 | emit newMessage(msg, showOnScreen);
|
---|
159 | }
|
---|
160 |
|
---|
161 | // Write a Program Message (private, no lock)
|
---|
162 | ////////////////////////////////////////////////////////////////////////////
|
---|
163 | void bncApp::messagePrivate(const QByteArray& msg) {
|
---|
164 |
|
---|
165 | // First time resolve the log file name
|
---|
166 | // ------------------------------------
|
---|
167 | QDate currDate = currentDateAndTimeGPS().date();
|
---|
168 | if (_logFileFlag == 0 || _fileDate != currDate) {
|
---|
169 | delete _logFile;
|
---|
170 | _logFileFlag = 1;
|
---|
171 | bncSettings settings;
|
---|
172 | QString logFileName = settings.value("logFile").toString();
|
---|
173 | if ( !logFileName.isEmpty() ) {
|
---|
174 | expandEnvVar(logFileName);
|
---|
175 | _logFile = new QFile(logFileName + "_" +
|
---|
176 | currDate.toString("yyMMdd").toAscii().data());
|
---|
177 | _fileDate = currDate;
|
---|
178 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
179 | _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
---|
180 | }
|
---|
181 | else {
|
---|
182 | _logFile->open(QIODevice::WriteOnly);
|
---|
183 | }
|
---|
184 | _logStream = new QTextStream();
|
---|
185 | _logStream->setDevice(_logFile);
|
---|
186 | }
|
---|
187 | }
|
---|
188 |
|
---|
189 | if (_logStream) {
|
---|
190 | *_logStream << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
|
---|
191 | *_logStream << msg.data() << endl;
|
---|
192 | _logStream->flush();
|
---|
193 | }
|
---|
194 | }
|
---|
195 |
|
---|
196 | // New GPS Ephemeris
|
---|
197 | ////////////////////////////////////////////////////////////////////////////
|
---|
198 | void bncApp::slotNewGPSEph(gpsephemeris* gpseph) {
|
---|
199 |
|
---|
200 | QMutexLocker locker(&_mutex);
|
---|
201 |
|
---|
202 | gpsephemeris copy_gpseph = *gpseph;
|
---|
203 | emit newEphGPS(copy_gpseph);
|
---|
204 |
|
---|
205 | printEphHeader();
|
---|
206 |
|
---|
207 | gpsephemeris** ee = &_gpsEph[gpseph->satellite-1];
|
---|
208 |
|
---|
209 | if ( *ee == 0 ||
|
---|
210 | gpseph->GPSweek > (*ee)->GPSweek ||
|
---|
211 | (gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC > (*ee)->TOC) ) {
|
---|
212 | delete *ee;
|
---|
213 | *ee = gpseph;
|
---|
214 | printGPSEph(gpseph, true);
|
---|
215 | }
|
---|
216 | else {
|
---|
217 | printGPSEph(gpseph, false);
|
---|
218 | delete gpseph;
|
---|
219 | }
|
---|
220 | }
|
---|
221 |
|
---|
222 | // New Glonass Ephemeris
|
---|
223 | ////////////////////////////////////////////////////////////////////////////
|
---|
224 | void bncApp::slotNewGlonassEph(glonassephemeris* glonasseph) {
|
---|
225 |
|
---|
226 | QMutexLocker locker(&_mutex);
|
---|
227 |
|
---|
228 | glonassephemeris copy_glonasseph = *glonasseph;
|
---|
229 | emit newEphGlonass(copy_glonasseph);
|
---|
230 |
|
---|
231 | printEphHeader();
|
---|
232 |
|
---|
233 | glonassephemeris** ee = &_glonassEph[glonasseph->almanac_number-1];
|
---|
234 |
|
---|
235 | int wwOld, towOld, wwNew, towNew;
|
---|
236 | if (*ee != 0) {
|
---|
237 | wwOld = (*ee)->GPSWeek;
|
---|
238 | towOld = (*ee)->GPSTOW;
|
---|
239 | updatetime(&wwOld, &towOld, (*ee)->tb*1000, 0); // Moscow -> GPS
|
---|
240 |
|
---|
241 | wwNew = glonasseph->GPSWeek;
|
---|
242 | towNew = glonasseph->GPSTOW;
|
---|
243 | updatetime(&wwNew, &towNew, glonasseph->tb*1000, 0); // Moscow -> GPS
|
---|
244 | }
|
---|
245 |
|
---|
246 | if ( *ee == 0 ||
|
---|
247 | wwNew > wwOld ||
|
---|
248 | (wwNew == wwOld && towNew > towOld) ) {
|
---|
249 | delete *ee;
|
---|
250 | *ee = glonasseph;
|
---|
251 | printGlonassEph(glonasseph, true);
|
---|
252 | }
|
---|
253 | else {
|
---|
254 | printGlonassEph(glonasseph, false);
|
---|
255 | delete glonasseph;
|
---|
256 | }
|
---|
257 | }
|
---|
258 |
|
---|
259 | // New Galileo Ephemeris
|
---|
260 | ////////////////////////////////////////////////////////////////////////////
|
---|
261 | void bncApp::slotNewGalileoEph(galileoephemeris* galileoeph) {
|
---|
262 |
|
---|
263 | QMutexLocker locker(&_mutex);
|
---|
264 |
|
---|
265 | galileoephemeris copy_galileoeph = *galileoeph;
|
---|
266 | emit newEphGalileo(copy_galileoeph);
|
---|
267 |
|
---|
268 | printEphHeader();
|
---|
269 |
|
---|
270 | int galIndex = galileoeph->satellite - 51;
|
---|
271 | if (galIndex < 0 || galIndex > PRN_GALILEO_END - PRN_GALILEO_START) {
|
---|
272 | emit( newMessage("Wrong Galileo Satellite Number", true) );
|
---|
273 | exit(1);
|
---|
274 | }
|
---|
275 |
|
---|
276 | galileoephemeris** ee = &_galileoEph[galIndex];
|
---|
277 |
|
---|
278 | if ( *ee == 0 ||
|
---|
279 | galileoeph->Week > (*ee)->Week ||
|
---|
280 | (galileoeph->Week == (*ee)->Week && galileoeph->TOC > (*ee)->TOC) ) {
|
---|
281 | delete *ee;
|
---|
282 | *ee = galileoeph;
|
---|
283 | printGalileoEph(galileoeph, true);
|
---|
284 | }
|
---|
285 | else {
|
---|
286 | printGalileoEph(galileoeph, false);
|
---|
287 | delete galileoeph;
|
---|
288 | }
|
---|
289 | }
|
---|
290 |
|
---|
291 | // Print Header of the output File(s)
|
---|
292 | ////////////////////////////////////////////////////////////////////////////
|
---|
293 | void bncApp::printEphHeader() {
|
---|
294 |
|
---|
295 | bncSettings settings;
|
---|
296 |
|
---|
297 | // Initialization
|
---|
298 | // --------------
|
---|
299 | if (_rinexVers == 0) {
|
---|
300 |
|
---|
301 | if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
|
---|
302 | _rinexVers = 3;
|
---|
303 | }
|
---|
304 | else {
|
---|
305 | _rinexVers = 2;
|
---|
306 | }
|
---|
307 |
|
---|
308 | _ephPath = settings.value("ephPath").toString();
|
---|
309 |
|
---|
310 | if ( !_ephPath.isEmpty() ) {
|
---|
311 | if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
|
---|
312 | _ephPath += QDir::separator();
|
---|
313 | }
|
---|
314 | expandEnvVar(_ephPath);
|
---|
315 | }
|
---|
316 | }
|
---|
317 |
|
---|
318 | // (Re-)Open output File(s)
|
---|
319 | // ------------------------
|
---|
320 | if (!_ephPath.isEmpty()) {
|
---|
321 |
|
---|
322 | QDateTime datTim = currentDateAndTimeGPS();
|
---|
323 |
|
---|
324 | QString ephFileNameGPS = _ephPath + "BRDC" +
|
---|
325 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'));
|
---|
326 |
|
---|
327 | QString hlpStr = bncRinex::nextEpochStr(datTim,
|
---|
328 | settings.value("ephIntr").toString());
|
---|
329 |
|
---|
330 | if (_rinexVers == 3) {
|
---|
331 | ephFileNameGPS += hlpStr + datTim.toString(".yyP");
|
---|
332 | }
|
---|
333 | else {
|
---|
334 | ephFileNameGPS += hlpStr + datTim.toString(".yyN");
|
---|
335 | }
|
---|
336 |
|
---|
337 | if (_ephFileNameGPS == ephFileNameGPS) {
|
---|
338 | return;
|
---|
339 | }
|
---|
340 | else {
|
---|
341 | _ephFileNameGPS = ephFileNameGPS;
|
---|
342 | }
|
---|
343 |
|
---|
344 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
---|
345 | delete _gpsEph[ii-PRN_GPS_START];
|
---|
346 | _gpsEph[ii-PRN_GPS_START] = 0;
|
---|
347 | }
|
---|
348 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
---|
349 | delete _glonassEph[ii-PRN_GLONASS_START];
|
---|
350 | _glonassEph[ii-PRN_GLONASS_START] = 0;
|
---|
351 | }
|
---|
352 | for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
|
---|
353 | delete _galileoEph[ii-PRN_GALILEO_START];
|
---|
354 | _galileoEph[ii-PRN_GALILEO_START] = 0;
|
---|
355 | }
|
---|
356 |
|
---|
357 | delete _ephStreamGPS;
|
---|
358 | delete _ephFileGPS;
|
---|
359 |
|
---|
360 | QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
|
---|
361 | QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
|
---|
362 | QFlags<QIODevice::OpenModeFlag> appendFlagGalileo;
|
---|
363 |
|
---|
364 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
---|
365 | QFile::exists(ephFileNameGPS) ) {
|
---|
366 | appendFlagGPS = QIODevice::Append;
|
---|
367 | }
|
---|
368 |
|
---|
369 | _ephFileGPS = new QFile(ephFileNameGPS);
|
---|
370 | _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
|
---|
371 | _ephStreamGPS = new QTextStream();
|
---|
372 | _ephStreamGPS->setDevice(_ephFileGPS);
|
---|
373 |
|
---|
374 | if (_rinexVers == 3) {
|
---|
375 | _ephFileGlonass = _ephFileGPS;
|
---|
376 | _ephStreamGlonass = _ephStreamGPS;
|
---|
377 | _ephFileGalileo = _ephFileGPS;
|
---|
378 | _ephStreamGalileo = _ephStreamGPS;
|
---|
379 | }
|
---|
380 | else if (_rinexVers == 2) {
|
---|
381 | QString ephFileNameGlonass = _ephPath + "BRDC" +
|
---|
382 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
383 | hlpStr + datTim.toString(".yyG");
|
---|
384 |
|
---|
385 | delete _ephStreamGlonass;
|
---|
386 | delete _ephFileGlonass;
|
---|
387 |
|
---|
388 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
---|
389 | QFile::exists(ephFileNameGlonass) ) {
|
---|
390 | appendFlagGlonass = QIODevice::Append;
|
---|
391 | }
|
---|
392 |
|
---|
393 | _ephFileGlonass = new QFile(ephFileNameGlonass);
|
---|
394 | _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
|
---|
395 | _ephStreamGlonass = new QTextStream();
|
---|
396 | _ephStreamGlonass->setDevice(_ephFileGlonass);
|
---|
397 | }
|
---|
398 |
|
---|
399 | // Header - RINEX Version 3
|
---|
400 | // ------------------------
|
---|
401 | if (_rinexVers == 3) {
|
---|
402 | if ( ! (appendFlagGPS & QIODevice::Append)) {
|
---|
403 | QString line;
|
---|
404 | line.sprintf(
|
---|
405 | "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
|
---|
406 | 3.0, "", "");
|
---|
407 | *_ephStreamGPS << line;
|
---|
408 |
|
---|
409 | QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
|
---|
410 | *_ephStreamGPS << _pgmName.toAscii().data()
|
---|
411 | << _userName.toAscii().data()
|
---|
412 | << hlp.toAscii().data()
|
---|
413 | << "PGM / RUN BY / DATE" << endl;
|
---|
414 |
|
---|
415 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
416 | *_ephStreamGPS << line;
|
---|
417 |
|
---|
418 | _ephStreamGPS->flush();
|
---|
419 | }
|
---|
420 | }
|
---|
421 |
|
---|
422 | // Headers - RINEX Version 2
|
---|
423 | // -------------------------
|
---|
424 | else if (_rinexVers == 2) {
|
---|
425 | if (! (appendFlagGPS & QIODevice::Append)) {
|
---|
426 | QString line;
|
---|
427 | line.sprintf(
|
---|
428 | "%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n", 2.10, "", "");
|
---|
429 | *_ephStreamGPS << line;
|
---|
430 |
|
---|
431 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
432 | *_ephStreamGPS << _pgmName.toAscii().data()
|
---|
433 | << _userName.toAscii().data()
|
---|
434 | << hlp.toAscii().data()
|
---|
435 | << "PGM / RUN BY / DATE" << endl;
|
---|
436 |
|
---|
437 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
438 | *_ephStreamGPS << line;
|
---|
439 |
|
---|
440 | _ephStreamGPS->flush();
|
---|
441 | }
|
---|
442 | if (! (appendFlagGlonass & QIODevice::Append)) {
|
---|
443 | QString line;
|
---|
444 | line.sprintf(
|
---|
445 | "%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",2.10,"","");
|
---|
446 | *_ephStreamGlonass << line;
|
---|
447 |
|
---|
448 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
449 | *_ephStreamGlonass << _pgmName.toAscii().data()
|
---|
450 | << _userName.toAscii().data()
|
---|
451 | << hlp.toAscii().data()
|
---|
452 | << "PGM / RUN BY / DATE" << endl;
|
---|
453 |
|
---|
454 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
455 | *_ephStreamGlonass << line;
|
---|
456 |
|
---|
457 | _ephStreamGlonass->flush();
|
---|
458 | }
|
---|
459 | }
|
---|
460 | }
|
---|
461 | }
|
---|
462 |
|
---|
463 | // Print One GPS Ephemeris
|
---|
464 | ////////////////////////////////////////////////////////////////////////////
|
---|
465 | void bncApp::printGPSEph(gpsephemeris* ep, bool printFile) {
|
---|
466 |
|
---|
467 | QString lineV2;
|
---|
468 | QString lineV3;
|
---|
469 |
|
---|
470 | struct converttimeinfo cti;
|
---|
471 | converttime(&cti, ep->GPSweek, ep->TOC);
|
---|
472 |
|
---|
473 | lineV3.sprintf("G%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e\n",
|
---|
474 | ep->satellite, cti.year, cti.month, cti.day, cti.hour,
|
---|
475 | cti.minute, cti.second, ep->clock_bias, ep->clock_drift,
|
---|
476 | ep->clock_driftrate);
|
---|
477 |
|
---|
478 | lineV2.sprintf("%02d %02d %02d %02d %02d %02d%5.1f%19.12e%19.12e%19.12e\n",
|
---|
479 | ep->satellite, cti.year%100, cti.month, cti.day, cti.hour,
|
---|
480 | cti.minute, (double) cti.second, ep->clock_bias,
|
---|
481 | ep->clock_drift, ep->clock_driftrate);
|
---|
482 |
|
---|
483 | QString line;
|
---|
484 | QByteArray allLines;
|
---|
485 |
|
---|
486 | QByteArray fmt;
|
---|
487 | QByteArray fmt2;
|
---|
488 | if (_rinexVers == 2) {
|
---|
489 | fmt = " %19.12e%19.12e%19.12e%19.12e\n";
|
---|
490 | fmt2 = " %19.12e%19.12e\n";
|
---|
491 | }
|
---|
492 | else {
|
---|
493 | fmt = " %19.12e%19.12e%19.12e%19.12e\n";
|
---|
494 | fmt2 = " %19.12e%19.12e\n";
|
---|
495 | }
|
---|
496 |
|
---|
497 | line.sprintf(fmt.data(), (double)ep->IODE, ep->Crs, ep->Delta_n, ep->M0);
|
---|
498 | allLines += line;
|
---|
499 |
|
---|
500 | line.sprintf(fmt.data(), ep->Cuc, ep->e, ep->Cus, ep->sqrt_A);
|
---|
501 | allLines += line;
|
---|
502 |
|
---|
503 | line.sprintf(fmt.data(), (double) ep->TOE, ep->Cic, ep->OMEGA0, ep->Cis);
|
---|
504 | allLines += line;
|
---|
505 |
|
---|
506 | line.sprintf(fmt.data(), ep->i0, ep->Crc, ep->omega, ep->OMEGADOT);
|
---|
507 | allLines += line;
|
---|
508 |
|
---|
509 | double dd = 0;
|
---|
510 | unsigned long ii = ep->flags;
|
---|
511 | if(ii & GPSEPHF_L2CACODE)
|
---|
512 | dd += 2.0;
|
---|
513 | if(ii & GPSEPHF_L2PCODE)
|
---|
514 | dd += 1.0;
|
---|
515 | line.sprintf(fmt.data(), ep->IDOT, dd, (double) ep->GPSweek,
|
---|
516 | ii & GPSEPHF_L2PCODEDATA ? 1.0 : 0.0);
|
---|
517 | allLines += line;
|
---|
518 |
|
---|
519 | if(ep->URAindex <= 6) /* URA index */
|
---|
520 | dd = ceil(10.0*pow(2.0, 1.0+((double)ep->URAindex)/2.0))/10.0;
|
---|
521 | else
|
---|
522 | dd = ceil(10.0*pow(2.0, ((double)ep->URAindex)/2.0))/10.0;
|
---|
523 | line.sprintf(fmt.data(), dd, ((double) ep->SVhealth), ep->TGD,
|
---|
524 | ((double) ep->IODC));
|
---|
525 | allLines += line;
|
---|
526 |
|
---|
527 | line.sprintf(fmt2.data(), ((double)ep->TOW), 0.0);
|
---|
528 | allLines += line;
|
---|
529 |
|
---|
530 | printOutput(printFile, _ephStreamGPS, lineV2, lineV3, allLines);
|
---|
531 | }
|
---|
532 |
|
---|
533 | // Print One Glonass Ephemeris
|
---|
534 | ////////////////////////////////////////////////////////////////////////////
|
---|
535 | void bncApp::printGlonassEph(glonassephemeris* ep, bool printFile) {
|
---|
536 |
|
---|
537 | int ww = ep->GPSWeek;
|
---|
538 | int tow = ep->GPSTOW;
|
---|
539 | struct converttimeinfo cti;
|
---|
540 |
|
---|
541 | updatetime(&ww, &tow, ep->tb*1000, 1); // Moscow -> UTC
|
---|
542 | converttime(&cti, ww, tow);
|
---|
543 |
|
---|
544 | int tk = ep->tk-3*60*60;
|
---|
545 | if (tk < 0) {
|
---|
546 | tk += 86400;
|
---|
547 | }
|
---|
548 |
|
---|
549 | QString lineV2;
|
---|
550 | QString lineV3;
|
---|
551 |
|
---|
552 | lineV3.sprintf("R%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e\n",
|
---|
553 | ep->almanac_number, cti.year, cti.month, cti.day, cti.hour,
|
---|
554 | cti.minute, cti.second, -ep->tau, ep->gamma, (double) tk);
|
---|
555 |
|
---|
556 | lineV2.sprintf("%02d %02d %02d %02d %02d %02d%5.1f%19.12e%19.12e%19.12e\n",
|
---|
557 | ep->almanac_number, cti.year%100, cti.month, cti.day,
|
---|
558 | cti.hour, cti.minute, (double) cti.second, -ep->tau,
|
---|
559 | ep->gamma, (double) tk);
|
---|
560 |
|
---|
561 | QString line;
|
---|
562 | QByteArray allLines;
|
---|
563 |
|
---|
564 | QByteArray fmt;
|
---|
565 | if (_rinexVers == 2) {
|
---|
566 | fmt = " %19.12e%19.12e%19.12e%19.12e\n";
|
---|
567 | }
|
---|
568 | else {
|
---|
569 | fmt = " %19.12e%19.12e%19.12e%19.12e\n";
|
---|
570 | }
|
---|
571 |
|
---|
572 | line.sprintf(fmt.data(), ep->x_pos, ep->x_velocity, ep->x_acceleration,
|
---|
573 | (ep->flags & GLOEPHF_UNHEALTHY) ? 1.0 : 0.0);
|
---|
574 | allLines += line;
|
---|
575 |
|
---|
576 | line.sprintf(fmt.data(), ep->y_pos, ep->y_velocity, ep->y_acceleration,
|
---|
577 | (double) ep->frequency_number);
|
---|
578 | allLines += line;
|
---|
579 |
|
---|
580 | line.sprintf(fmt.data(), ep->z_pos, ep->z_velocity, ep->z_acceleration,
|
---|
581 | (double) ep->E);
|
---|
582 | allLines += line;
|
---|
583 |
|
---|
584 | printOutput(printFile, _ephStreamGlonass, lineV2, lineV3, allLines);
|
---|
585 | }
|
---|
586 |
|
---|
587 | // Print One Galileo Ephemeris
|
---|
588 | ////////////////////////////////////////////////////////////////////////////
|
---|
589 | void bncApp::printGalileoEph(galileoephemeris* ep, bool printFile) {
|
---|
590 |
|
---|
591 | QString lineV2;
|
---|
592 | QString lineV3;
|
---|
593 |
|
---|
594 | struct converttimeinfo cti;
|
---|
595 | converttime(&cti, ep->Week, ep->TOC);
|
---|
596 |
|
---|
597 | lineV3.sprintf("E%02d %04d %02d %02d %02d %02d %02d%19.12e%19.12e%19.12e\n",
|
---|
598 | ep->satellite, cti.year, cti.month, cti.day, cti.hour,
|
---|
599 | cti.minute, cti.second, ep->clock_bias, ep->clock_drift,
|
---|
600 | ep->clock_driftrate);
|
---|
601 |
|
---|
602 | QString line;
|
---|
603 | QByteArray allLines;
|
---|
604 |
|
---|
605 | const QByteArray fmt4 = " %19.12e%19.12e%19.12e%19.12e\n";
|
---|
606 | const QByteArray fmt3 = " %19.12e%19.12e%19.12e\n";
|
---|
607 | const QByteArray fmt1 = " %19.12e\n";
|
---|
608 |
|
---|
609 | line.sprintf(fmt4.data(), (double)ep->IODnav, ep->Crs, ep->Delta_n, ep->M0);
|
---|
610 | allLines += line;
|
---|
611 |
|
---|
612 | line.sprintf(fmt4.data(), ep->Cuc, ep->e, ep->Cus, ep->sqrt_A);
|
---|
613 | allLines += line;
|
---|
614 |
|
---|
615 | line.sprintf(fmt4.data(), (double) ep->TOE, ep->Cic, ep->OMEGA0, ep->Cis);
|
---|
616 | allLines += line;
|
---|
617 |
|
---|
618 | line.sprintf(fmt4.data(), ep->i0, ep->Crc, ep->omega, ep->OMEGADOT);
|
---|
619 | allLines += line;
|
---|
620 |
|
---|
621 | double dataSources = 0.0; // TODO
|
---|
622 | line.sprintf(fmt3.data(), ep->IDOT, dataSources, (double) ep->Week);
|
---|
623 | allLines += line;
|
---|
624 |
|
---|
625 | double health = 0.0; // TODO
|
---|
626 | double BGD_1_5B = ep->BGD_1_5A; // TODO
|
---|
627 | line.sprintf(fmt4.data(), (double) ep->SISA, health, ep->BGD_1_5A, BGD_1_5B);
|
---|
628 | allLines += line;
|
---|
629 |
|
---|
630 | double transmissionTimeOfMessage = 0.9999e9; // unknown (Rinex v3 standard)
|
---|
631 | line.sprintf(fmt1.data(), transmissionTimeOfMessage);
|
---|
632 | allLines += line;
|
---|
633 |
|
---|
634 | printOutput(printFile, _ephStreamGalileo, lineV2, lineV3, allLines);
|
---|
635 | }
|
---|
636 |
|
---|
637 | // Output
|
---|
638 | ////////////////////////////////////////////////////////////////////////////
|
---|
639 | void bncApp::printOutput(bool printFile, QTextStream* stream,
|
---|
640 | const QString& lineV2,
|
---|
641 | const QString& lineV3,
|
---|
642 | const QByteArray& allLines) {
|
---|
643 | // Output into file
|
---|
644 | // ----------------
|
---|
645 | if (printFile && stream) {
|
---|
646 | if (_rinexVers == 2) {
|
---|
647 | *stream << lineV2.toAscii();
|
---|
648 | }
|
---|
649 | else {
|
---|
650 | *stream << lineV3.toAscii();
|
---|
651 | }
|
---|
652 | *stream << allLines;
|
---|
653 | stream->flush();
|
---|
654 | }
|
---|
655 |
|
---|
656 | // Output into the socket
|
---|
657 | // ----------------------
|
---|
658 | if (_sockets) {
|
---|
659 | QMutableListIterator<QTcpSocket*> is(*_sockets);
|
---|
660 | while (is.hasNext()) {
|
---|
661 | QTcpSocket* sock = is.next();
|
---|
662 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
663 | if (sock->write(lineV3.toAscii()) == -1 ||
|
---|
664 | sock->write(allLines) == -1) {
|
---|
665 | delete sock;
|
---|
666 | is.remove();
|
---|
667 | }
|
---|
668 | }
|
---|
669 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
670 | delete sock;
|
---|
671 | is.remove();
|
---|
672 | }
|
---|
673 | }
|
---|
674 | }
|
---|
675 | }
|
---|
676 |
|
---|
677 | // Set Port Number
|
---|
678 | ////////////////////////////////////////////////////////////////////////////
|
---|
679 | void bncApp::setPort(int port) {
|
---|
680 | _port = port;
|
---|
681 | if (_port != 0) {
|
---|
682 | delete _server;
|
---|
683 | _server = new QTcpServer;
|
---|
684 | if ( !_server->listen(QHostAddress::Any, _port) ) {
|
---|
685 | slotMessage("bncApp: Cannot listen on ephemeris port", true);
|
---|
686 | }
|
---|
687 | connect(_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
|
---|
688 | delete _sockets;
|
---|
689 | _sockets = new QList<QTcpSocket*>;
|
---|
690 | }
|
---|
691 | }
|
---|
692 |
|
---|
693 | // Set Port Number
|
---|
694 | ////////////////////////////////////////////////////////////////////////////
|
---|
695 | void bncApp::setPortCorr(int port) {
|
---|
696 | _portCorr = port;
|
---|
697 | if (_portCorr != 0) {
|
---|
698 | delete _serverCorr;
|
---|
699 | _serverCorr = new QTcpServer;
|
---|
700 | if ( !_serverCorr->listen(QHostAddress::Any, _portCorr) ) {
|
---|
701 | slotMessage("bncApp: Cannot listen on correction port", true);
|
---|
702 | }
|
---|
703 | connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
|
---|
704 | delete _socketsCorr;
|
---|
705 | _socketsCorr = new QList<QTcpSocket*>;
|
---|
706 | }
|
---|
707 | }
|
---|
708 |
|
---|
709 | // New Connection
|
---|
710 | ////////////////////////////////////////////////////////////////////////////
|
---|
711 | void bncApp::slotNewConnection() {
|
---|
712 | _sockets->push_back( _server->nextPendingConnection() );
|
---|
713 | }
|
---|
714 |
|
---|
715 | // New Connection
|
---|
716 | ////////////////////////////////////////////////////////////////////////////
|
---|
717 | void bncApp::slotNewConnectionCorr() {
|
---|
718 | _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
|
---|
719 | }
|
---|
720 |
|
---|
721 | //
|
---|
722 | ////////////////////////////////////////////////////////////////////////////
|
---|
723 | void bncApp::slotQuit() {
|
---|
724 | cout << "bncApp::slotQuit" << endl;
|
---|
725 | delete _caster;
|
---|
726 | quit();
|
---|
727 | }
|
---|
728 |
|
---|
729 | //
|
---|
730 | ////////////////////////////////////////////////////////////////////////////
|
---|
731 | void bncApp::slotNewCorrLine(QString line, QString staID, long coTime) {
|
---|
732 |
|
---|
733 | QMutexLocker locker(&_mutex);
|
---|
734 |
|
---|
735 | // Combination of Corrections
|
---|
736 | // --------------------------
|
---|
737 | if (_bncComb) {
|
---|
738 | _bncComb->processCorrLine(staID, line);
|
---|
739 | }
|
---|
740 |
|
---|
741 | bncSettings settings;
|
---|
742 | _waitCoTime = settings.value("corrTime").toInt();
|
---|
743 | if (_waitCoTime < 1) {
|
---|
744 | _waitCoTime = 1;
|
---|
745 | }
|
---|
746 |
|
---|
747 | // First time, set the _lastDumpSec immediately
|
---|
748 | // --------------------------------------------
|
---|
749 | if (_lastDumpCoSec == 0) {
|
---|
750 | _lastDumpCoSec = coTime - 1;
|
---|
751 | }
|
---|
752 |
|
---|
753 | // An old correction - throw it away
|
---|
754 | // ---------------------------------
|
---|
755 | if (coTime <= _lastDumpCoSec) {
|
---|
756 | QString line = staID + ": Correction for one sat neglected because overaged by " +
|
---|
757 | QString().sprintf(" %ld sec",
|
---|
758 | _lastDumpCoSec - coTime + _waitCoTime);
|
---|
759 | messagePrivate(line.toAscii());
|
---|
760 | emit( newMessage(line.toAscii(), true) );
|
---|
761 | return;
|
---|
762 | }
|
---|
763 |
|
---|
764 | _corrs->insert(coTime, QString(line + " " + staID));
|
---|
765 |
|
---|
766 | // Dump Corrections
|
---|
767 | // ----------------
|
---|
768 | if (coTime - _waitCoTime > _lastDumpCoSec) {
|
---|
769 | dumpCorrs(_lastDumpCoSec + 1, coTime - _waitCoTime);
|
---|
770 | _lastDumpCoSec = coTime - _waitCoTime;
|
---|
771 | }
|
---|
772 | }
|
---|
773 |
|
---|
774 | // Dump Complete Correction Epochs
|
---|
775 | ////////////////////////////////////////////////////////////////////////////
|
---|
776 | void bncApp::dumpCorrs(long minTime, long maxTime) {
|
---|
777 |
|
---|
778 | for (long sec = minTime; sec <= maxTime; sec++) {
|
---|
779 | QList<QString> allCorrs = _corrs->values(sec);
|
---|
780 | emit newCorrections(allCorrs);
|
---|
781 | if (_socketsCorr) {
|
---|
782 | QListIterator<QString> it(allCorrs);
|
---|
783 | while (it.hasNext()) {
|
---|
784 | QString corrLine = it.next() + "\n";
|
---|
785 |
|
---|
786 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
787 | while (is.hasNext()) {
|
---|
788 | QTcpSocket* sock = is.next();
|
---|
789 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
790 | if (sock->write(corrLine.toAscii()) == -1) {
|
---|
791 | delete sock;
|
---|
792 | is.remove();
|
---|
793 | }
|
---|
794 | }
|
---|
795 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
796 | delete sock;
|
---|
797 | is.remove();
|
---|
798 | }
|
---|
799 | }
|
---|
800 | }
|
---|
801 | }
|
---|
802 | _corrs->remove(sec);
|
---|
803 | }
|
---|
804 | }
|
---|
805 |
|
---|
806 | //
|
---|
807 | ////////////////////////////////////////////////////////////////////////////
|
---|
808 | void bncApp::setConfFileName(const QString& confFileName) {
|
---|
809 | if (confFileName.isEmpty()) {
|
---|
810 | _confFileName = QDir::homePath() + QDir::separator()
|
---|
811 | + ".config" + QDir::separator()
|
---|
812 | + organizationName() + QDir::separator()
|
---|
813 | + applicationName() + ".ini";
|
---|
814 | }
|
---|
815 | else {
|
---|
816 | _confFileName = confFileName;
|
---|
817 | }
|
---|
818 | }
|
---|
819 |
|
---|
820 | // Raw Output
|
---|
821 | ////////////////////////////////////////////////////////////////////////////
|
---|
822 | void bncApp::writeRawData(const QByteArray& data, const QByteArray& staID,
|
---|
823 | const QByteArray& format) {
|
---|
824 |
|
---|
825 | QMutexLocker locker(&_mutex);
|
---|
826 |
|
---|
827 | if (!_rawFile) {
|
---|
828 | bncSettings settings;
|
---|
829 | QByteArray fileName = settings.value("rawOutFile").toByteArray();
|
---|
830 | if (!fileName.isEmpty()) {
|
---|
831 | _rawFile = new bncRawFile(fileName, format, bncRawFile::output);
|
---|
832 | }
|
---|
833 | }
|
---|
834 |
|
---|
835 | if (_rawFile) {
|
---|
836 | _rawFile->writeRawData(data, staID, format);
|
---|
837 | }
|
---|
838 | }
|
---|
839 |
|
---|
840 | // Get Glonass Slot Numbers from Global Array
|
---|
841 | ////////////////////////////////////////////////////////////////////////////
|
---|
842 | void bncApp::getGlonassSlotNums(int GLOFreq[]) {
|
---|
843 |
|
---|
844 | QMutexLocker locker(&_mutex);
|
---|
845 |
|
---|
846 | for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
|
---|
847 | if (_GLOFreq[ii] != 0) {
|
---|
848 | GLOFreq[ii] = _GLOFreq[ii];
|
---|
849 | }
|
---|
850 | }
|
---|
851 | }
|
---|
852 |
|
---|
853 | // Store Glonass Slot Numbers to Global Array
|
---|
854 | ////////////////////////////////////////////////////////////////////////////
|
---|
855 | void bncApp::storeGlonassSlotNums(const int GLOFreq[]) {
|
---|
856 |
|
---|
857 | QMutexLocker locker(&_mutex);
|
---|
858 |
|
---|
859 | for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
|
---|
860 | if (GLOFreq[ii] != 0) {
|
---|
861 | _GLOFreq[ii] = GLOFreq[ii];
|
---|
862 | }
|
---|
863 | }
|
---|
864 | }
|
---|