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

Last change on this file since 10040 was 10040, checked in by stuerze, 12 months ago

minor changes

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