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

Last change on this file since 9212 was 9212, checked in by stuerze, 21 months ago
File size: 23.8 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 if (eph->checkState() == t_eph::bad) {
204 messagePrivate("WRONG EPHEMERIS\n" + eph->toString(3.0).toLatin1());
205 return failure;
206 }
207 else if (eph->checkState() == t_eph::outdated) {
208 messagePrivate(QString("OUTDATED EPHEMERIS %1 received from %2 (%4)")
209 .arg(eph->prn().toString().c_str()).arg(eph->receptStaID())
210 .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 3.0)).toLatin1());
211 return failure;
212 }
213 else if (eph->checkState() == t_eph::unhealthy) {
214 messagePrivate(QString("UNHEALTHY EPHEMERIS %1 received from %2 (%4)")
215 .arg(eph->prn().toString().c_str()).arg(eph->receptStaID())
216 .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 3.0)).toLatin1());
217 }
218 printEphHeader();
219 printEph(*eph, (ircPut == success));
220 return success;
221}
222
223// New GPS Ephemeris
224////////////////////////////////////////////////////////////////////////////
225void t_bncCore::slotNewGPSEph(t_ephGPS eph) {
226 if (checkPrintEph(&eph) == success) {
227 emit newGPSEph(eph);
228 }
229}
230
231// New Glonass Ephemeris
232////////////////////////////////////////////////////////////////////////////
233void t_bncCore::slotNewGlonassEph(t_ephGlo eph) {
234 if (checkPrintEph(&eph) == success) {
235 emit newGlonassEph(eph);
236 }
237}
238
239// New Galileo Ephemeris
240////////////////////////////////////////////////////////////////////////////
241void t_bncCore::slotNewGalileoEph(t_ephGal eph) {
242 if (checkPrintEph(&eph) == success) {
243 emit newGalileoEph(eph);
244 }
245}
246
247// New SBAS Ephemeris
248////////////////////////////////////////////////////////////////////////////
249void t_bncCore::slotNewSBASEph(t_ephSBAS eph) {
250 if (checkPrintEph(&eph) == success) {
251 emit newSBASEph(eph);
252 }
253}
254
255// New BDS Ephemeris
256////////////////////////////////////////////////////////////////////////////
257void t_bncCore::slotNewBDSEph(t_ephBDS eph) {
258 if (checkPrintEph(&eph) == success) {
259 emit newBDSEph(eph);
260 }
261}
262
263// Print Header of the output File(s)
264////////////////////////////////////////////////////////////////////////////
265void t_bncCore::printEphHeader() {
266
267 bncSettings settings;
268 QStringList comments;
269
270 QListIterator<QString> it(settings.value("mountPoints").toStringList());
271 while (it.hasNext()) {
272 QStringList hlp = it.next().split(" ");
273 if (hlp.size() < 7)
274 continue;
275 QUrl url(hlp[0]);
276 QString decoder = hlp[1];
277 comments.append("Source: " + decoder +
278 " " + QUrl::toAce(url.host()) +
279 "/" + url.path().mid(1).toLatin1());
280 }
281
282 // Initialization
283 // --------------
284 if (_rinexVers == 0) {
285
286 if ( Qt::CheckState(settings.value("ephV2").toInt()) == Qt::Checked) {
287 _rinexVers = 2;
288 }
289 else {
290 _rinexVers = 3;
291 }
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 bool ephV2 = (_rinexVers == 2)? true : false;
312
313 QString hlpStr = bncRinex::nextEpochStr(datTim,
314 settings.value("ephIntr").toString(), ephV2);
315
316 if (_rinexVers == 3) {
317 QString country = "WRD"; // WORLD
318 QString monNum = "0";
319 QString recNum = "0";
320 ephFileNameGPS += QString("%1").arg(monNum, 1, 10) +
321 QString("%1").arg(recNum, 1, 10) +
322 country +
323 "_S_" + // stream
324 QString("%1").arg(datTim.date().year()) +
325 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
326 hlpStr + // HM_period
327 "_MN.rnx"; // mixed BRDC
328 }
329 else { // RNX v2.11
330 ephFileNameGPS += QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
331 hlpStr + datTim.toString(".yyN");
332 }
333
334 if (_ephFileNameGPS == ephFileNameGPS) {
335 return;
336 }
337 else {
338 _ephFileNameGPS = ephFileNameGPS;
339 }
340
341 delete _ephStreamGPS;
342 delete _ephFileGPS;
343
344 QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
345 QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
346
347 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
348 QFile::exists(ephFileNameGPS) ) {
349 appendFlagGPS = QIODevice::Append;
350 }
351
352 _ephFileGPS = new QFile(ephFileNameGPS);
353 _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
354 _ephStreamGPS = new QTextStream();
355 _ephStreamGPS->setDevice(_ephFileGPS);
356
357 if (_rinexVers == 3) {
358 _ephFileGlonass = _ephFileGPS;
359 _ephStreamGlonass = _ephStreamGPS;
360 _ephFileGalileo = _ephFileGPS;
361 _ephStreamGalileo = _ephStreamGPS;
362 _ephFileSBAS = _ephFileGPS;
363 _ephStreamSBAS = _ephStreamGPS;
364 }
365 else if (_rinexVers == 2) {
366 QString ephFileNameGlonass = _ephPath + "BRDC" +
367 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
368 hlpStr + datTim.toString(".yyG");
369
370 delete _ephStreamGlonass;
371 delete _ephFileGlonass;
372
373 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
374 QFile::exists(ephFileNameGlonass) ) {
375 appendFlagGlonass = QIODevice::Append;
376 }
377
378 _ephFileGlonass = new QFile(ephFileNameGlonass);
379 _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
380 _ephStreamGlonass = new QTextStream();
381 _ephStreamGlonass->setDevice(_ephFileGlonass);
382 }
383
384 // Header - RINEX Version 3
385 // ------------------------
386 if (_rinexVers == 3) {
387 if ( ! (appendFlagGPS & QIODevice::Append)) {
388 QString line;
389 line.sprintf(
390 "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
391 defaultRnxNavVersion3, "", "");
392 *_ephStreamGPS << line;
393
394 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
395 *_ephStreamGPS << _pgmName.toLatin1().data()
396 << _userName.toLatin1().data()
397 << hlp.toLatin1().data()
398 << "PGM / RUN BY / DATE" << endl;
399
400 QStringListIterator it(comments);
401 while (it.hasNext()) {
402 *_ephStreamGPS << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
403 }
404
405 line.sprintf("%60sEND OF HEADER\n", "");
406 *_ephStreamGPS << line;
407
408 _ephStreamGPS->flush();
409 }
410 }
411
412 // Headers - RINEX Version 2
413 // -------------------------
414 else if (_rinexVers == 2) {
415 if (! (appendFlagGPS & QIODevice::Append)) {
416 QString line;
417 line.sprintf("%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n",
418 defaultRnxNavVersion2, "", "");
419 *_ephStreamGPS << line;
420
421 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
422 *_ephStreamGPS << _pgmName.toLatin1().data()
423 << _userName.toLatin1().data()
424 << hlp.toLatin1().data()
425 << "PGM / RUN BY / DATE" << endl;
426
427 QStringListIterator it(comments);
428 while (it.hasNext()) {
429 *_ephStreamGPS << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
430 }
431
432 line.sprintf("%60sEND OF HEADER\n", "");
433 *_ephStreamGPS << line;
434
435 _ephStreamGPS->flush();
436 }
437 if (! (appendFlagGlonass & QIODevice::Append)) {
438 QString line;
439 line.sprintf("%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",
440 defaultRnxNavVersion2, "", "");
441 *_ephStreamGlonass << line;
442
443 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
444 *_ephStreamGlonass << _pgmName.toLatin1().data()
445 << _userName.toLatin1().data()
446 << hlp.toLatin1().data()
447 << "PGM / RUN BY / DATE" << endl;
448
449 QStringListIterator it(comments);
450 while (it.hasNext()) {
451 *_ephStreamGlonass << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
452 }
453
454 line.sprintf("%60sEND OF HEADER\n", "");
455 *_ephStreamGlonass << line;
456
457 _ephStreamGlonass->flush();
458 }
459 }
460 }
461}
462
463// Print One Ephemeris
464////////////////////////////////////////////////////////////////////////////
465void t_bncCore::printEph(const t_eph& eph, bool printFile) {
466
467 QString strV2 = eph.toString(defaultRnxNavVersion2);
468 QString strV3 = eph.toString(defaultRnxObsVersion3);
469
470 if (_rinexVers == 2 && eph.type() == t_eph::GLONASS) {
471 printOutputEph(printFile, _ephStreamGlonass, strV2, strV3);
472 }
473 else if(_rinexVers == 2 && eph.type() == t_eph::GPS) {
474 printOutputEph(printFile, _ephStreamGPS, strV2, strV3);
475 }
476 else if (_rinexVers == 3) {
477 printOutputEph(printFile, _ephStreamGPS, strV2, strV3);
478 }
479}
480
481// Output
482////////////////////////////////////////////////////////////////////////////
483void t_bncCore::printOutputEph(bool printFile, QTextStream* stream,
484 const QString& strV2, const QString& strV3) {
485
486 // Output into file
487 // ----------------
488 if (printFile && stream) {
489 if (_rinexVers == 2) {
490 *stream << strV2.toLatin1();
491 }
492 else {
493 *stream << strV3.toLatin1();
494 }
495 stream->flush();
496 }
497
498 // Output into the socket
499 // ----------------------
500 if (_socketsEph) {
501 QMutableListIterator<QTcpSocket*> is(*_socketsEph);
502 while (is.hasNext()) {
503 QTcpSocket* sock = is.next();
504 if (sock->state() == QAbstractSocket::ConnectedState) {
505 if (sock->write(strV3.toLatin1()) == -1) {
506 delete sock;
507 is.remove();
508 }
509 }
510 else if (sock->state() != QAbstractSocket::ConnectingState) {
511 delete sock;
512 is.remove();
513 }
514 }
515 }
516}
517
518// Set Port Number
519////////////////////////////////////////////////////////////////////////////
520void t_bncCore::setPortEph(int port) {
521 _portEph = port;
522 if (_portEph != 0) {
523 delete _serverEph;
524 _serverEph = new QTcpServer;
525 _serverEph->setProxy(QNetworkProxy::NoProxy);
526 if ( !_serverEph->listen(QHostAddress::Any, _portEph) ) {
527 QString message = "t_bncCore: Cannot listen on ephemeris port "
528 + QByteArray::number(_portEph) + ": "
529 + _serverEph->errorString();
530 slotMessage(message.toLatin1(), true);
531 }
532 connect(_serverEph, SIGNAL(newConnection()), this, SLOT(slotNewConnectionEph()));
533 delete _socketsEph;
534 _socketsEph = new QList<QTcpSocket*>;
535 }
536}
537
538// Set Port Number
539////////////////////////////////////////////////////////////////////////////
540void t_bncCore::setPortCorr(int port) {
541 _portCorr = port;
542 if (_portCorr != 0) {
543 delete _serverCorr;
544 _serverCorr = new QTcpServer;
545 _serverCorr->setProxy(QNetworkProxy::NoProxy);
546 if ( !_serverCorr->listen(QHostAddress::Any, _portCorr) ) {
547 QString message = "t_bncCore: Cannot listen on correction port "
548 + QByteArray::number(_portCorr) + ": "
549 + _serverCorr->errorString();
550 slotMessage(message.toLatin1(), true);
551 }
552 connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
553 delete _socketsCorr;
554 _socketsCorr = new QList<QTcpSocket*>;
555 }
556}
557
558// New Connection
559////////////////////////////////////////////////////////////////////////////
560void t_bncCore::slotNewConnectionEph() {
561 _socketsEph->push_back( _serverEph->nextPendingConnection() );
562}
563
564// New Connection
565////////////////////////////////////////////////////////////////////////////
566void t_bncCore::slotNewConnectionCorr() {
567 _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
568}
569
570//
571////////////////////////////////////////////////////////////////////////////
572void t_bncCore::slotQuit() {
573 delete _caster; _caster = 0;
574 qApp->quit();
575}
576
577//
578////////////////////////////////////////////////////////////////////////////
579void t_bncCore::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
580 QMutexLocker locker(&_mutex);
581 emit newOrbCorrections(orbCorrections);
582 if (_socketsCorr) {
583 ostringstream out;
584 t_orbCorr::writeEpoch(&out, orbCorrections);
585 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
586 while (is.hasNext()) {
587 QTcpSocket* sock = is.next();
588 if (sock->state() == QAbstractSocket::ConnectedState) {
589 if (sock->write(out.str().c_str()) == -1) {
590 delete sock;
591 is.remove();
592 }
593 }
594 else if (sock->state() != QAbstractSocket::ConnectingState) {
595 delete sock;
596 is.remove();
597 }
598 }
599 }
600}
601
602//
603////////////////////////////////////////////////////////////////////////////
604void t_bncCore::slotNewClkCorrections(QList<t_clkCorr> clkCorrections) {
605 QMutexLocker locker(&_mutex);
606 emit newClkCorrections(clkCorrections);
607 if (_socketsCorr) {
608 ostringstream out;
609 t_clkCorr::writeEpoch(&out, clkCorrections);
610 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
611 while (is.hasNext()) {
612 QTcpSocket* sock = is.next();
613 if (sock->state() == QAbstractSocket::ConnectedState) {
614 if (sock->write(out.str().c_str()) == -1) {
615 delete sock;
616 is.remove();
617 }
618 }
619 else if (sock->state() != QAbstractSocket::ConnectingState) {
620 delete sock;
621 is.remove();
622 }
623 }
624 }
625}
626
627//
628////////////////////////////////////////////////////////////////////////////
629void t_bncCore::slotNewCodeBiases(QList<t_satCodeBias> codeBiases) {
630 QMutexLocker locker(&_mutex);
631 emit newCodeBiases(codeBiases);
632 if (_socketsCorr) {
633 ostringstream out;
634 t_satCodeBias::writeEpoch(&out, codeBiases);
635 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
636 while (is.hasNext()) {
637 QTcpSocket* sock = is.next();
638 if (sock->state() == QAbstractSocket::ConnectedState) {
639 if (sock->write(out.str().c_str()) == -1) {
640 delete sock;
641 is.remove();
642 }
643 }
644 else if (sock->state() != QAbstractSocket::ConnectingState) {
645 delete sock;
646 is.remove();
647 }
648 }
649 }
650}
651
652//
653////////////////////////////////////////////////////////////////////////////
654void t_bncCore::slotNewPhaseBiases(QList<t_satPhaseBias> phaseBiases) {
655 QMutexLocker locker(&_mutex);
656 emit newPhaseBiases(phaseBiases);
657 if (_socketsCorr) {
658 ostringstream out;
659 t_satPhaseBias::writeEpoch(&out, phaseBiases);
660 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
661 while (is.hasNext()) {
662 QTcpSocket* sock = is.next();
663 if (sock->state() == QAbstractSocket::ConnectedState) {
664 if (sock->write(out.str().c_str()) == -1) {
665 delete sock;
666 is.remove();
667 }
668 }
669 else if (sock->state() != QAbstractSocket::ConnectingState) {
670 delete sock;
671 is.remove();
672 }
673 }
674 }
675}
676
677//
678////////////////////////////////////////////////////////////////////////////
679void t_bncCore::slotNewTec(t_vTec vTec) {
680 QMutexLocker locker(&_mutex);
681 emit newTec(vTec);
682 if (_socketsCorr) {
683 ostringstream out;
684 t_vTec::write(&out, vTec);
685 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
686 while (is.hasNext()) {
687 QTcpSocket* sock = is.next();
688 if (sock->state() == QAbstractSocket::ConnectedState) {
689 if (sock->write(out.str().c_str()) == -1) {
690 delete sock;
691 is.remove();
692 }
693 }
694 else if (sock->state() != QAbstractSocket::ConnectingState) {
695 delete sock;
696 is.remove();
697 }
698 }
699 }
700}
701
702//
703////////////////////////////////////////////////////////////////////////////
704void t_bncCore::setConfFileName(const QString& confFileName) {
705 if (confFileName.isEmpty()) {
706 _confFileName = QDir::homePath() + QDir::separator()
707 + ".config" + QDir::separator()
708 + qApp->organizationName() + QDir::separator()
709 + qApp->applicationName() + ".bnc";
710 }
711 else {
712 _confFileName = confFileName;
713 }
714}
715
716// Raw Output
717////////////////////////////////////////////////////////////////////////////
718void t_bncCore::writeRawData(const QByteArray& data, const QByteArray& staID,
719 const QByteArray& format) {
720
721 QMutexLocker locker(&_mutex);
722
723 if (!_rawFile) {
724 bncSettings settings;
725 QByteArray fileName = settings.value("rawOutFile").toByteArray();
726 if (!fileName.isEmpty()) {
727 _rawFile = new bncRawFile(fileName, staID, bncRawFile::output);
728 }
729 }
730
731 if (_rawFile) {
732 _rawFile->writeRawData(data, staID, format);
733 }
734}
735
736//
737////////////////////////////////////////////////////////////////////////////
738void t_bncCore::initCombination() {
739 _bncComb = new bncComb();
740 if (_bncComb->nStreams() < 1) {
741 delete _bncComb;
742 _bncComb = 0;
743 }
744}
745
746//
747////////////////////////////////////////////////////////////////////////////
748void t_bncCore::stopCombination() {
749 delete _bncComb;
750 _bncComb = 0;
751}
752
753//
754////////////////////////////////////////////////////////////////////////////
755bool t_bncCore::dateAndTimeGPSSet() const {
756 QMutexLocker locker(&_mutexDateAndTimeGPS);
757 if (_dateAndTimeGPS) {
758 return true;
759 }
760 else {
761 return false;
762 }
763}
764
765//
766////////////////////////////////////////////////////////////////////////////
767QDateTime t_bncCore::dateAndTimeGPS() const {
768 QMutexLocker locker(&_mutexDateAndTimeGPS);
769 if (_dateAndTimeGPS) {
770 return *_dateAndTimeGPS;
771 }
772 else {
773 return QDateTime();
774 }
775}
776
777//
778////////////////////////////////////////////////////////////////////////////
779void t_bncCore::setDateAndTimeGPS(QDateTime dateTime) {
780 QMutexLocker locker(&_mutexDateAndTimeGPS);
781 delete _dateAndTimeGPS;
782 _dateAndTimeGPS = new QDateTime(dateTime);
783}
784
785//
786////////////////////////////////////////////////////////////////////////////
787void t_bncCore::startPPP() {
788 _pppMain->start();
789}
790
791//
792////////////////////////////////////////////////////////////////////////////
793void t_bncCore::stopPPP() {
794 _pppMain->stop();
795 emit stopRinexPPP();
796}
797
Note: See TracBrowser for help on using the repository browser.