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

Last change on this file since 9767 was 9767, checked in by stuerze, 22 months ago

minor changes

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