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

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