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

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