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

Last change on this file since 9587 was 9587, checked in by stuerze, 5 months ago

minor changes

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