source: ntrip/branches/BNC_LM/bncapp.cpp@ 10166

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