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

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