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

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