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

Last change on this file since 11039 was 11039, checked in by stuerze, 5 days ago

updates regarding RTCM-SSR

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