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

Last change on this file since 11066 was 11066, checked in by stuerze, 4 days ago

further fixes and initial import for ssr qc

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