source: ntrip/trunk/BNC/src/bnccore.cpp@ 10092

Last change on this file since 10092 was 10091, checked in by stuerze, 2 years ago

same changes for future developments towards station individual navigation files

File size: 24.9 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 *
[5072]29 * Class: t_bncCore
[82]30 *
31 * Purpose: This class implements the main application
32 *
33 * Author: L. Mervart
34 *
35 * Created: 29-Aug-2006
36 *
[7291]37 * Changes:
[82]38 *
39 * -----------------------------------------------------------------------*/
40
[1029]41#include <iostream>
[6461]42#include <sstream>
[150]43#include <QMessageBox>
[519]44#include <cmath>
[82]45
[7291]46#include "bnccore.h"
47#include "bncutils.h"
48#include "bncrinex.h"
49#include "bncsettings.h"
50#include "bncversion.h"
51#include "ephemeris.h"
52#include "rinex/rnxobsfile.h"
53#include "rinex/rnxnavfile.h"
[6051]54#include "pppMain.h"
[7298]55#include "combination/bnccomb.h"
[82]56
57using namespace std;
58
[7291]59// Singleton
[5084]60////////////////////////////////////////////////////////////////////////////
[5861]61t_bncCore* t_bncCore::instance() {
[5084]62 static t_bncCore _bncCore;
[5861]63 return &_bncCore;
[5084]64}
65
[82]66// Constructor
67////////////////////////////////////////////////////////////////////////////
[6441]68t_bncCore::t_bncCore() : _ephUser(false) {
[150]69 _logFileFlag = 0;
70 _logFile = 0;
71 _logStream = 0;
[2519]72 _rawFile = 0;
[5729]73 _caster = 0;
[152]74
[533]75 // Eph file(s)
76 // -----------
[534]77 _rinexVers = 0;
[533]78 _ephFileGPS = 0;
79 _ephStreamGPS = 0;
80 _ephFileGlonass = 0;
81 _ephStreamGlonass = 0;
[2770]82 _ephFileGalileo = 0;
83 _ephStreamGalileo = 0;
[6384]84 _ephFileSBAS = 0;
85 _ephStreamSBAS = 0;
[559]86
[6451]87 _portEph = 0;
88 _serverEph = 0;
89 _socketsEph = 0;
[589]90
[937]91 _portCorr = 0;
92 _serverCorr = 0;
93 _socketsCorr = 0;
94
[2011]95 _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
[559]96#ifdef WIN32
97 _userName = QString("${USERNAME}");
98#else
99 _userName = QString("${USER}");
100#endif
101 expandEnvVar(_userName);
[973]102
[6151]103 _userName = _userName.leftJustified(20, ' ', true);
[5846]104 _dateAndTimeGPS = 0;
[6151]105 _mainWindow = 0;
[2673]106
[5899]107 _pppMain = new BNC_PPP::t_pppMain();
[6486]108 qRegisterMetaType< QVector<double> > ("QVector<double>");
109 qRegisterMetaType<bncTime> ("bncTime");
110 qRegisterMetaType<t_ephGPS> ("t_ephGPS");
111 qRegisterMetaType<t_ephGlo> ("t_ephGlo");
112 qRegisterMetaType<t_ephGal> ("t_ephGal");
113 qRegisterMetaType<t_ephSBAS> ("t_ephSBAS");
[6598]114 qRegisterMetaType<t_ephBDS> ("t_ephBDS");
[6486]115 qRegisterMetaType<QList<t_orbCorr> > ("QList<t_orbCorr>");
116 qRegisterMetaType<QList<t_clkCorr> > ("QList<t_clkCorr>");
117 qRegisterMetaType<QList<t_satCodeBias> > ("QList<t_satCodeBias>");
118 qRegisterMetaType<QList<t_satPhaseBias> > ("QList<t_satPhaseBias>");
119 qRegisterMetaType<t_vTec> ("t_vTec");
[82]120}
121
122// Destructor
123////////////////////////////////////////////////////////////////////////////
[5072]124t_bncCore::~t_bncCore() {
[109]125 delete _logStream;
126 delete _logFile;
[533]127 delete _ephStreamGPS;
128 delete _ephFileGPS;
[6451]129 delete _serverEph;
130 delete _socketsEph;
[937]131 delete _serverCorr;
132 delete _socketsCorr;
[534]133 if (_rinexVers == 2) {
[533]134 delete _ephStreamGlonass;
135 delete _ephFileGlonass;
136 }
[975]137
[5846]138 delete _dateAndTimeGPS;
[9822]139 if (_rawFile) {
140 delete _rawFile;
141 }
142
[10040]143 bncComb::destruct();
144
[7856]145 delete _pppMain;
[82]146}
147
148// Write a Program Message
149////////////////////////////////////////////////////////////////////////////
[5072]150void t_bncCore::slotMessage(QByteArray msg, bool showOnScreen) {
[10027]151 if (msg.isEmpty()) {
152 return;
153 }
[1218]154 QMutexLocker locker(&_mutexMessage);
[243]155
[990]156 messagePrivate(msg);
[1299]157 emit newMessage(msg, showOnScreen);
[990]158}
159
160// Write a Program Message (private, no lock)
161////////////////////////////////////////////////////////////////////////////
[5072]162void t_bncCore::messagePrivate(const QByteArray& msg) {
[990]163
[150]164 // First time resolve the log file name
165 // ------------------------------------
[1549]166 QDate currDate = currentDateAndTimeGPS().date();
167 if (_logFileFlag == 0 || _fileDate != currDate) {
[3034]168 delete _logStream; _logStream = 0;
169 delete _logFile; _logFile = 0;
[150]170 _logFileFlag = 1;
[1535]171 bncSettings settings;
[150]172 QString logFileName = settings.value("logFile").toString();
173 if ( !logFileName.isEmpty() ) {
[151]174 expandEnvVar(logFileName);
[7291]175 _logFile = new QFile(logFileName + "_" +
[8127]176 currDate.toString("yyMMdd").toLatin1().data());
[1549]177 _fileDate = currDate;
[275]178 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
179 _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
180 }
181 else {
182 _logFile->open(QIODevice::WriteOnly);
183 }
[150]184 _logStream = new QTextStream();
185 _logStream->setDevice(_logFile);
186 }
187 }
188
[109]189 if (_logStream) {
[3371]190 QByteArray msgLocal = msg;
191 if (msg.indexOf('\n') == 0) {
[9819]192 *_logStream << "\r\n";
[3371]193 msgLocal = msg.mid(1);
194 }
[8127]195 *_logStream << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toLatin1().data();
[9819]196 *_logStream << msgLocal.data() << "\r\n";
[109]197 _logStream->flush();
[3637]198 _logFile->flush();
[82]199 }
200}
[511]201
[7291]202//
[511]203////////////////////////////////////////////////////////////////////////////
[6520]204t_irc t_bncCore::checkPrintEph(t_eph* eph) {
[516]205 QMutexLocker locker(&_mutex);
[6520]206 t_irc ircPut = _ephUser.putNewEph(eph, true);
[9772]207#ifdef BNC_DEBUG_BCEP
[9767]208 if (eph->checkState() == t_eph::unhealthy) {
209 messagePrivate(QString("%1: UNHEALTHY %2:%3")
[9217]210 .arg(eph->receptStaID())
[9765]211 .arg(eph->navTypeString(eph->navType(), eph->prn(), 99.0))
212 .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1());
[6519]213 }
[9768]214 if (eph->checkState() == t_eph::bad) {
[9767]215 messagePrivate(QString("%1: WRONG %2:%3")
[9217]216 .arg(eph->receptStaID())
[9765]217 .arg(eph->navTypeString(eph->navType(), eph->prn(), 99.0))
218 .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1());
[7208]219 }
[9772]220 if (eph->checkState() == t_eph::outdated) {
[9767]221 messagePrivate(QString("%1: OUTDATED %2:%3")
[9217]222 .arg(eph->receptStaID())
[9765]223 .arg(eph->navTypeString(eph->navType(), eph->prn(), 99.0))
224 .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1());
[8215]225 }
[9379]226#endif
[534]227 printEphHeader();
[10091]228 //printEphHeader(eph->receptStaID());
[6520]229 printEph(*eph, (ircPut == success));
230 return success;
[511]231}
[6520]232
[7291]233// New GPS Ephemeris
[6520]234////////////////////////////////////////////////////////////////////////////
235void t_bncCore::slotNewGPSEph(t_ephGPS eph) {
236 if (checkPrintEph(&eph) == success) {
237 emit newGPSEph(eph);
238 }
239}
[7291]240
[535]241// New Glonass Ephemeris
[511]242////////////////////////////////////////////////////////////////////////////
[6432]243void t_bncCore::slotNewGlonassEph(t_ephGlo eph) {
[6520]244 if (checkPrintEph(&eph) == success) {
245 emit newGlonassEph(eph);
[6519]246 }
[511]247}
248
[2770]249// New Galileo Ephemeris
250////////////////////////////////////////////////////////////////////////////
[6432]251void t_bncCore::slotNewGalileoEph(t_ephGal eph) {
[6520]252 if (checkPrintEph(&eph) == success) {
253 emit newGalileoEph(eph);
[6519]254 }
[6432]255}
[2772]256
[6432]257// New SBAS Ephemeris
258////////////////////////////////////////////////////////////////////////////
259void t_bncCore::slotNewSBASEph(t_ephSBAS eph) {
[6520]260 if (checkPrintEph(&eph) == success) {
261 emit newSBASEph(eph);
[6519]262 }
[2770]263}
264
[6598]265// New BDS Ephemeris
[6595]266////////////////////////////////////////////////////////////////////////////
[6598]267void t_bncCore::slotNewBDSEph(t_ephBDS eph) {
[6595]268 if (checkPrintEph(&eph) == success) {
[6598]269 emit newBDSEph(eph);
[6595]270 }
271}
[6432]272
[535]273// Print Header of the output File(s)
[516]274////////////////////////////////////////////////////////////////////////////
[10091]275void t_bncCore::printEphHeader(QString receptStaID) {
[528]276
[1535]277 bncSettings settings;
[7999]278 QStringList comments;
[10091]279 bool separateFiles = false;// Qt::CheckState(settings.value("ephFilePerStation").toInt());
[535]280
[7999]281 QListIterator<QString> it(settings.value("mountPoints").toStringList());
282 while (it.hasNext()) {
283 QStringList hlp = it.next().split(" ");
284 if (hlp.size() < 7)
285 continue;
286 QUrl url(hlp[0]);
287 QString decoder = hlp[1];
[10091]288 if (!separateFiles) {
289 comments.append("Source: " + decoder +
290 " " + QUrl::toAce(url.host()) +
291 "/" + url.path().mid(1).toLatin1());
292 }
[7999]293 }
294
[534]295 // Initialization
296 // --------------
297 if (_rinexVers == 0) {
[528]298
[9760]299 _rinexVers = settings.value("ephVersion").toInt();
[529]300
[533]301 _ephPath = settings.value("ephPath").toString();
302
303 if ( !_ephPath.isEmpty() ) {
304 if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
305 _ephPath += QDir::separator();
306 }
307 expandEnvVar(_ephPath);
308 }
[517]309 }
[533]310
[534]311 // (Re-)Open output File(s)
312 // ------------------------
[533]313 if (!_ephPath.isEmpty()) {
314
[1154]315 QDateTime datTim = currentDateAndTimeGPS();
[533]316
[10091]317 QString ephFileNameGPS = _ephPath; // + "BRDC";
[533]318
[10091]319 (separateFiles) ? ephFileNameGPS += receptStaID.left(4) :
320 ephFileNameGPS += "BRDC";
321
[7291]322 QString hlpStr = bncRinex::nextEpochStr(datTim,
[9760]323 settings.value("ephIntr").toString(), _rinexVers);
[584]324
[9760]325 if (_rinexVers > 2) {
[8354]326 QString country = "WRD"; // WORLD
327 QString monNum = "0";
328 QString recNum = "0";
[10091]329 if (separateFiles && receptStaID.size() >= 9) {
330 monNum = receptStaID.mid(4,1);
331 recNum = receptStaID.mid(5,1);
332 country = receptStaID.mid(6,3);
333 }
[8354]334 ephFileNameGPS += QString("%1").arg(monNum, 1, 10) +
335 QString("%1").arg(recNum, 1, 10) +
336 country +
337 "_S_" + // stream
338 QString("%1").arg(datTim.date().year()) +
339 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
340 hlpStr + // HM_period
341 "_MN.rnx"; // mixed BRDC
[575]342 }
[7179]343 else { // RNX v2.11
344 ephFileNameGPS += QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
345 hlpStr + datTim.toString(".yyN");
[575]346 }
[563]347
[533]348 if (_ephFileNameGPS == ephFileNameGPS) {
349 return;
350 }
351 else {
352 _ephFileNameGPS = ephFileNameGPS;
353 }
354
355 delete _ephStreamGPS;
356 delete _ephFileGPS;
357
[535]358 QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
[536]359 QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
360
[535]361 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
362 QFile::exists(ephFileNameGPS) ) {
363 appendFlagGPS = QIODevice::Append;
364 }
365
[533]366 _ephFileGPS = new QFile(ephFileNameGPS);
[535]367 _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
[533]368 _ephStreamGPS = new QTextStream();
369 _ephStreamGPS->setDevice(_ephFileGPS);
370
[9760]371 if (_rinexVers > 2) {
[533]372 _ephFileGlonass = _ephFileGPS;
373 _ephStreamGlonass = _ephStreamGPS;
[2770]374 _ephFileGalileo = _ephFileGPS;
375 _ephStreamGalileo = _ephStreamGPS;
[6384]376 _ephFileSBAS = _ephFileGPS;
377 _ephStreamSBAS = _ephStreamGPS;
[533]378 }
[9760]379 else {
[583]380 QString ephFileNameGlonass = _ephPath + "BRDC" +
[563]381 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
[575]382 hlpStr + datTim.toString(".yyG");
[533]383
384 delete _ephStreamGlonass;
385 delete _ephFileGlonass;
386
[535]387 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
388 QFile::exists(ephFileNameGlonass) ) {
389 appendFlagGlonass = QIODevice::Append;
390 }
391
[533]392 _ephFileGlonass = new QFile(ephFileNameGlonass);
[535]393 _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
[533]394 _ephStreamGlonass = new QTextStream();
395 _ephStreamGlonass->setDevice(_ephFileGlonass);
396 }
397
[534]398 // Header - RINEX Version 3
399 // ------------------------
[9760]400 if (_rinexVers > 2) {
[537]401 if ( ! (appendFlagGPS & QIODevice::Append)) {
[9765]402 double rinexVersion = defaultRnxNavVersion4;
403 if (_rinexVers < 4.0) {
404 rinexVersion = defaultRnxNavVersion3;
405 }
[9675]406 QString line = QString().asprintf("%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
[9765]407 rinexVersion, "", "");
[537]408 *_ephStreamGPS << line;
[9675]409 line.clear();
[7291]410
[1154]411 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
[8127]412 *_ephStreamGPS << _pgmName.toLatin1().data()
413 << _userName.toLatin1().data()
414 << hlp.toLatin1().data()
[9675]415 << "PGM / RUN BY / DATE\n";
[559]416
[7999]417 QStringListIterator it(comments);
418 while (it.hasNext()) {
419 *_ephStreamGPS << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
420 }
421
[9765]422 if (_rinexVers == 4) {
423 int leapSecs = gnumleap(datTim.date().year(), datTim.date().month(), datTim.date().day());
424 *_ephStreamGPS << QString("%1").arg(leapSecs, 6, 10, QLatin1Char(' ')).left(60).leftJustified(60)
425 << "LEAP SECONDS\n";
426 }
427
[9675]428 line = QString().asprintf("%60sEND OF HEADER\n", "");
[537]429 *_ephStreamGPS << line;
[7291]430
[537]431 _ephStreamGPS->flush();
[535]432 }
[533]433 }
434
[536]435 // Headers - RINEX Version 2
436 // -------------------------
[9760]437 else {
[536]438 if (! (appendFlagGPS & QIODevice::Append)) {
[9675]439 QString line = QString().asprintf("%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n",
[8127]440 defaultRnxNavVersion2, "", "");
[536]441 *_ephStreamGPS << line;
[9675]442 line.clear();
[7291]443
[1154]444 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
[8127]445 *_ephStreamGPS << _pgmName.toLatin1().data()
446 << _userName.toLatin1().data()
447 << hlp.toLatin1().data()
[9675]448 << "PGM / RUN BY / DATE\n";
[559]449
[7999]450 QStringListIterator it(comments);
451 while (it.hasNext()) {
452 *_ephStreamGPS << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
453 }
454
[9675]455 line = QString().asprintf("%60sEND OF HEADER\n", "");
[536]456 *_ephStreamGPS << line;
[537]457
458 _ephStreamGPS->flush();
[536]459 }
460 if (! (appendFlagGlonass & QIODevice::Append)) {
[9675]461 QString line = QString().asprintf("%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",
[8127]462 defaultRnxNavVersion2, "", "");
[536]463 *_ephStreamGlonass << line;
[9675]464 line.clear();
[7291]465
[1154]466 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
[8127]467 *_ephStreamGlonass << _pgmName.toLatin1().data()
468 << _userName.toLatin1().data()
469 << hlp.toLatin1().data()
[9675]470 << "PGM / RUN BY / DATE\n";
[559]471
[7999]472 QStringListIterator it(comments);
473 while (it.hasNext()) {
474 *_ephStreamGlonass << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
475 }
476
[9675]477 line = QString().asprintf("%60sEND OF HEADER\n", "");
[536]478 *_ephStreamGlonass << line;
[537]479
480 _ephStreamGlonass->flush();
[536]481 }
[533]482 }
483 }
[516]484}
485
[6432]486// Print One Ephemeris
[516]487////////////////////////////////////////////////////////////////////////////
[6432]488void t_bncCore::printEph(const t_eph& eph, bool printFile) {
[519]489
[8127]490 QString strV2 = eph.toString(defaultRnxNavVersion2);
[9483]491 QString strV3 = eph.toString(defaultRnxNavVersion3);
[9760]492 QString strV4 = eph.toString(defaultRnxNavVersion4);
[941]493
[7026]494 if (_rinexVers == 2 && eph.type() == t_eph::GLONASS) {
[9760]495 printOutputEph(printFile, _ephStreamGlonass, strV2, strV3, strV4);
[7026]496 }
497 else if(_rinexVers == 2 && eph.type() == t_eph::GPS) {
[9760]498 printOutputEph(printFile, _ephStreamGPS, strV2, strV3, strV4);
[7026]499 }
[9765]500 else if (_rinexVers >= 3) {
[9760]501 printOutputEph(printFile, _ephStreamGPS, strV2, strV3, strV4);
[7026]502 }
[941]503}
504
505// Output
506////////////////////////////////////////////////////////////////////////////
[6451]507void t_bncCore::printOutputEph(bool printFile, QTextStream* stream,
[9760]508 const QString& strV2, const QString& strV3,
509 const QString& strV4) {
[9770]510 QString strVx;
511 if (_rinexVers == 2) {
512 strVx = strV2;
513 }
514 else if (_rinexVers == 3) {
515 strVx = strV3;
516 }
517 else if (_rinexVers == 4) {
518 strVx = strV4;
519 }
[4020]520
[590]521 // Output into file
522 // ----------------
[943]523 if (printFile && stream) {
[9770]524 *stream << strVx.toLatin1();
[943]525 stream->flush();
[517]526 }
[590]527
528 // Output into the socket
529 // ----------------------
[6451]530 if (_socketsEph) {
531 QMutableListIterator<QTcpSocket*> is(*_socketsEph);
[590]532 while (is.hasNext()) {
533 QTcpSocket* sock = is.next();
534 if (sock->state() == QAbstractSocket::ConnectedState) {
[9770]535 if (sock->write(strVx.toLatin1()) == -1) {
[642]536 delete sock;
537 is.remove();
538 }
[590]539 }
[642]540 else if (sock->state() != QAbstractSocket::ConnectingState) {
541 delete sock;
542 is.remove();
543 }
[590]544 }
545 }
[516]546}
[589]547
[591]548// Set Port Number
549////////////////////////////////////////////////////////////////////////////
[6451]550void t_bncCore::setPortEph(int port) {
551 _portEph = port;
552 if (_portEph != 0) {
553 delete _serverEph;
554 _serverEph = new QTcpServer;
[8921]555 _serverEph->setProxy(QNetworkProxy::NoProxy);
[6451]556 if ( !_serverEph->listen(QHostAddress::Any, _portEph) ) {
[8918]557 QString message = "t_bncCore: Cannot listen on ephemeris port "
[8921]558 + QByteArray::number(_portEph) + ": "
559 + _serverEph->errorString();
[8918]560 slotMessage(message.toLatin1(), true);
[1228]561 }
[6451]562 connect(_serverEph, SIGNAL(newConnection()), this, SLOT(slotNewConnectionEph()));
563 delete _socketsEph;
564 _socketsEph = new QList<QTcpSocket*>;
[591]565 }
566}
567
[937]568// Set Port Number
569////////////////////////////////////////////////////////////////////////////
[5072]570void t_bncCore::setPortCorr(int port) {
[937]571 _portCorr = port;
572 if (_portCorr != 0) {
[942]573 delete _serverCorr;
[937]574 _serverCorr = new QTcpServer;
[8921]575 _serverCorr->setProxy(QNetworkProxy::NoProxy);
[1228]576 if ( !_serverCorr->listen(QHostAddress::Any, _portCorr) ) {
[8918]577 QString message = "t_bncCore: Cannot listen on correction port "
[8921]578 + QByteArray::number(_portCorr) + ": "
579 + _serverCorr->errorString();
[8918]580 slotMessage(message.toLatin1(), true);
[1228]581 }
[937]582 connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
[942]583 delete _socketsCorr;
[937]584 _socketsCorr = new QList<QTcpSocket*>;
585 }
586}
587
[589]588// New Connection
589////////////////////////////////////////////////////////////////////////////
[6451]590void t_bncCore::slotNewConnectionEph() {
591 _socketsEph->push_back( _serverEph->nextPendingConnection() );
[589]592}
593
[937]594// New Connection
595////////////////////////////////////////////////////////////////////////////
[5072]596void t_bncCore::slotNewConnectionCorr() {
[937]597 _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
598}
599
[7291]600//
[621]601////////////////////////////////////////////////////////////////////////////
[5072]602void t_bncCore::slotQuit() {
[5729]603 delete _caster; _caster = 0;
[5066]604 qApp->quit();
[621]605}
606
[7291]607//
[936]608////////////////////////////////////////////////////////////////////////////
[6141]609void t_bncCore::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
[6151]610 QMutexLocker locker(&_mutex);
[6141]611 emit newOrbCorrections(orbCorrections);
[6151]612 if (_socketsCorr) {
[6455]613 ostringstream out;
[7291]614 t_orbCorr::writeEpoch(&out, orbCorrections);
[6455]615 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
616 while (is.hasNext()) {
617 QTcpSocket* sock = is.next();
618 if (sock->state() == QAbstractSocket::ConnectedState) {
619 if (sock->write(out.str().c_str()) == -1) {
[6151]620 delete sock;
621 is.remove();
622 }
623 }
[6455]624 else if (sock->state() != QAbstractSocket::ConnectingState) {
625 delete sock;
626 is.remove();
627 }
[6151]628 }
629 }
[6141]630}
[974]631
[7291]632//
[6141]633////////////////////////////////////////////////////////////////////////////
634void t_bncCore::slotNewClkCorrections(QList<t_clkCorr> clkCorrections) {
[974]635 QMutexLocker locker(&_mutex);
[6151]636 emit newClkCorrections(clkCorrections);
[3109]637 if (_socketsCorr) {
[6455]638 ostringstream out;
[7291]639 t_clkCorr::writeEpoch(&out, clkCorrections);
[6455]640 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
641 while (is.hasNext()) {
642 QTcpSocket* sock = is.next();
643 if (sock->state() == QAbstractSocket::ConnectedState) {
644 if (sock->write(out.str().c_str()) == -1) {
[3109]645 delete sock;
646 is.remove();
647 }
[937]648 }
[6455]649 else if (sock->state() != QAbstractSocket::ConnectingState) {
650 delete sock;
651 is.remove();
652 }
[937]653 }
654 }
[936]655}
[1538]656
[7291]657//
[1538]658////////////////////////////////////////////////////////////////////////////
[6480]659void t_bncCore::slotNewCodeBiases(QList<t_satCodeBias> codeBiases) {
[6485]660 QMutexLocker locker(&_mutex);
661 emit newCodeBiases(codeBiases);
662 if (_socketsCorr) {
663 ostringstream out;
[7291]664 t_satCodeBias::writeEpoch(&out, codeBiases);
[6485]665 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
666 while (is.hasNext()) {
667 QTcpSocket* sock = is.next();
668 if (sock->state() == QAbstractSocket::ConnectedState) {
669 if (sock->write(out.str().c_str()) == -1) {
670 delete sock;
671 is.remove();
672 }
673 }
674 else if (sock->state() != QAbstractSocket::ConnectingState) {
675 delete sock;
676 is.remove();
677 }
678 }
679 }
[6480]680}
681
[7291]682//
[6480]683////////////////////////////////////////////////////////////////////////////
[6484]684void t_bncCore::slotNewPhaseBiases(QList<t_satPhaseBias> phaseBiases) {
[6485]685 QMutexLocker locker(&_mutex);
686 emit newPhaseBiases(phaseBiases);
687 if (_socketsCorr) {
688 ostringstream out;
[7291]689 t_satPhaseBias::writeEpoch(&out, phaseBiases);
[6485]690 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
691 while (is.hasNext()) {
692 QTcpSocket* sock = is.next();
693 if (sock->state() == QAbstractSocket::ConnectedState) {
694 if (sock->write(out.str().c_str()) == -1) {
695 delete sock;
696 is.remove();
697 }
698 }
699 else if (sock->state() != QAbstractSocket::ConnectingState) {
700 delete sock;
701 is.remove();
702 }
703 }
704 }
[6484]705}
706
[7291]707//
[6484]708////////////////////////////////////////////////////////////////////////////
709void t_bncCore::slotNewTec(t_vTec vTec) {
[6485]710 QMutexLocker locker(&_mutex);
711 emit newTec(vTec);
712 if (_socketsCorr) {
713 ostringstream out;
[7291]714 t_vTec::write(&out, vTec);
[6485]715 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
716 while (is.hasNext()) {
717 QTcpSocket* sock = is.next();
718 if (sock->state() == QAbstractSocket::ConnectedState) {
719 if (sock->write(out.str().c_str()) == -1) {
720 delete sock;
721 is.remove();
722 }
723 }
724 else if (sock->state() != QAbstractSocket::ConnectingState) {
725 delete sock;
726 is.remove();
727 }
728 }
729 }
[6484]730}
731
[7291]732//
[6484]733////////////////////////////////////////////////////////////////////////////
[5072]734void t_bncCore::setConfFileName(const QString& confFileName) {
[4169]735 if (confFileName.isEmpty()) {
[7291]736 _confFileName = QDir::homePath() + QDir::separator()
[4169]737 + ".config" + QDir::separator()
[5066]738 + qApp->organizationName() + QDir::separator()
739 + qApp->applicationName() + ".bnc";
[1538]740 }
[4169]741 else {
742 _confFileName = confFileName;
743 }
[1538]744}
[2385]745
746// Raw Output
747////////////////////////////////////////////////////////////////////////////
[5072]748void t_bncCore::writeRawData(const QByteArray& data, const QByteArray& staID,
[2518]749 const QByteArray& format) {
[2385]750
[2386]751 QMutexLocker locker(&_mutex);
752
[2519]753 if (!_rawFile) {
[2386]754 bncSettings settings;
[2519]755 QByteArray fileName = settings.value("rawOutFile").toByteArray();
756 if (!fileName.isEmpty()) {
[3524]757 _rawFile = new bncRawFile(fileName, staID, bncRawFile::output);
[2407]758 }
[2386]759 }
760
[2519]761 if (_rawFile) {
762 _rawFile->writeRawData(data, staID, format);
[2386]763 }
[2385]764}
[2672]765
[7291]766//
[2909]767////////////////////////////////////////////////////////////////////////////
[10040]768void t_bncCore::initCombination() {
769 bncComb::getInstance();
770 if (BNC_CMB->nStreams() < 1) {
771 bncComb::destruct();
[2909]772 }
773}
[3231]774
[7291]775//
[3231]776////////////////////////////////////////////////////////////////////////////
[5072]777void t_bncCore::stopCombination() {
[10040]778 bncComb::destruct();
[3231]779}
[4167]780
[5846]781//
782////////////////////////////////////////////////////////////////////////////
783bool t_bncCore::dateAndTimeGPSSet() const {
784 QMutexLocker locker(&_mutexDateAndTimeGPS);
785 if (_dateAndTimeGPS) {
786 return true;
787 }
788 else {
789 return false;
790 }
791}
792
793//
794////////////////////////////////////////////////////////////////////////////
795QDateTime t_bncCore::dateAndTimeGPS() const {
796 QMutexLocker locker(&_mutexDateAndTimeGPS);
797 if (_dateAndTimeGPS) {
798 return *_dateAndTimeGPS;
799 }
800 else {
801 return QDateTime();
802 }
803}
804
805//
806////////////////////////////////////////////////////////////////////////////
807void t_bncCore::setDateAndTimeGPS(QDateTime dateTime) {
808 QMutexLocker locker(&_mutexDateAndTimeGPS);
809 delete _dateAndTimeGPS;
810 _dateAndTimeGPS = new QDateTime(dateTime);
811}
[5900]812
813//
814////////////////////////////////////////////////////////////////////////////
[5946]815void t_bncCore::startPPP() {
816 _pppMain->start();
[5900]817}
818
819//
820////////////////////////////////////////////////////////////////////////////
821void t_bncCore::stopPPP() {
[5903]822 _pppMain->stop();
[5972]823 emit stopRinexPPP();
[5900]824}
[6383]825
Note: See TracBrowser for help on using the repository browser.