source: ntrip/trunk/BNC/src/bncapp.cpp@ 5067

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