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

Last change on this file since 6429 was 6384, checked in by mervart, 10 years ago
File size: 24.9 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 <QMessageBox>
43#include <cmath>
44
45#include "bnccore.h"
46#include "bncutils.h"
47#include "bncrinex.h"
48#include "bncsettings.h"
49#include "bncversion.h"
50#include "ephemeris.h"
51#include "rinex/rnxobsfile.h"
52#include "rinex/rnxnavfile.h"
53#include "pppMain.h"
54
55#ifdef USE_COMBINATION
56# include "combination/bnccomb.h"
57#endif
58
59using namespace std;
60
61// Singleton
62////////////////////////////////////////////////////////////////////////////
63t_bncCore* t_bncCore::instance() {
64 static t_bncCore _bncCore;
65 return &_bncCore;
66}
67
68// Constructor
69////////////////////////////////////////////////////////////////////////////
70t_bncCore::t_bncCore() {
71 _GUIenabled = true;
72 _logFileFlag = 0;
73 _logFile = 0;
74 _logStream = 0;
75 _rawFile = 0;
76 _caster = 0;
77#ifdef USE_COMBINATION
78 _bncComb = 0;
79#endif
80
81 // Lists of Ephemeris
82 // ------------------
83 for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
84 _gpsEph[ii-PRN_GPS_START] = 0;
85 }
86 for (int ii = PRN_QZSS_START; ii <= PRN_QZSS_END; ii++) {
87 _qzssEph[ii-PRN_QZSS_START] = 0;
88 }
89 for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
90 _glonassEph[ii-PRN_GLONASS_START] = 0;
91 }
92 for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
93 _galileoEph[ii-PRN_GALILEO_START] = 0;
94 }
95 for (int ii = PRN_SBAS_START; ii <= PRN_SBAS_END; ii++) {
96 _sbasEph[ii-PRN_SBAS_START] = 0;
97 }
98
99 // Eph file(s)
100 // -----------
101 _rinexVers = 0;
102 _ephFileGPS = 0;
103 _ephStreamGPS = 0;
104 _ephFileGlonass = 0;
105 _ephStreamGlonass = 0;
106 _ephFileGalileo = 0;
107 _ephStreamGalileo = 0;
108 _ephFileSBAS = 0;
109 _ephStreamSBAS = 0;
110
111 _port = 0;
112 _server = 0;
113 _sockets = 0;
114
115 _portCorr = 0;
116 _serverCorr = 0;
117 _socketsCorr = 0;
118
119 _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
120#ifdef WIN32
121 _userName = QString("${USERNAME}");
122#else
123 _userName = QString("${USER}");
124#endif
125 expandEnvVar(_userName);
126
127 _userName = _userName.leftJustified(20, ' ', true);
128 _dateAndTimeGPS = 0;
129 _mainWindow = 0;
130
131 _pppMain = new BNC_PPP::t_pppMain();
132 qRegisterMetaType< QVector<double> >("QVector<double>");
133 qRegisterMetaType<bncTime>("bncTime");
134}
135
136// Destructor
137////////////////////////////////////////////////////////////////////////////
138t_bncCore::~t_bncCore() {
139 delete _logStream;
140 delete _logFile;
141 delete _ephStreamGPS;
142 delete _ephFileGPS;
143 delete _server;
144 delete _sockets;
145 delete _serverCorr;
146 delete _socketsCorr;
147 if (_rinexVers == 2) {
148 delete _ephStreamGlonass;
149 delete _ephFileGlonass;
150 }
151 for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
152 delete _gpsEph[ii-PRN_GPS_START];
153 }
154 for (int ii = PRN_QZSS_START; ii <= PRN_QZSS_END; ii++) {
155 delete _qzssEph[ii-PRN_QZSS_START];
156 }
157 for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
158 delete _glonassEph[ii-PRN_GLONASS_START];
159 }
160 for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
161 delete _galileoEph[ii-PRN_GALILEO_START];
162 }
163 for (int ii = PRN_SBAS_START; ii <= PRN_SBAS_END; ii++) {
164 delete _sbasEph[ii-PRN_SBAS_START];
165 }
166
167 delete _dateAndTimeGPS;
168 delete _rawFile;
169
170#ifdef USE_COMBINATION
171 delete _bncComb;
172#endif
173}
174
175// Write a Program Message
176////////////////////////////////////////////////////////////////////////////
177void t_bncCore::slotMessage(QByteArray msg, bool showOnScreen) {
178
179 QMutexLocker locker(&_mutexMessage);
180
181 messagePrivate(msg);
182 emit newMessage(msg, showOnScreen);
183}
184
185// Write a Program Message (private, no lock)
186////////////////////////////////////////////////////////////////////////////
187void t_bncCore::messagePrivate(const QByteArray& msg) {
188
189 // First time resolve the log file name
190 // ------------------------------------
191 QDate currDate = currentDateAndTimeGPS().date();
192 if (_logFileFlag == 0 || _fileDate != currDate) {
193 delete _logStream; _logStream = 0;
194 delete _logFile; _logFile = 0;
195 _logFileFlag = 1;
196 bncSettings settings;
197 QString logFileName = settings.value("logFile").toString();
198 if ( !logFileName.isEmpty() ) {
199 expandEnvVar(logFileName);
200 _logFile = new QFile(logFileName + "_" +
201 currDate.toString("yyMMdd").toAscii().data());
202 _fileDate = currDate;
203 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
204 _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
205 }
206 else {
207 _logFile->open(QIODevice::WriteOnly);
208 }
209 _logStream = new QTextStream();
210 _logStream->setDevice(_logFile);
211 }
212 }
213
214 if (_logStream) {
215 QByteArray msgLocal = msg;
216 if (msg.indexOf('\n') == 0) {
217 *_logStream << endl;
218 msgLocal = msg.mid(1);
219 }
220 *_logStream << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
221 *_logStream << msgLocal.data() << endl;
222 _logStream->flush();
223 _logFile->flush();
224 }
225}
226
227// New GPS Ephemeris
228////////////////////////////////////////////////////////////////////////////
229void t_bncCore::slotNewGPSEph(gpsephemeris* gpseph) {
230
231 QMutexLocker locker(&_mutex);
232
233 gpsephemeris copy_gpseph = *gpseph;
234 emit newEphGPS(copy_gpseph);
235
236 printEphHeader();
237
238 gpsephemeris** ee = &_gpsEph[gpseph->satellite-1];
239 if (PRN_GPS_START <= gpseph->satellite && gpseph->satellite <= PRN_GPS_END) {
240 ee = &_gpsEph[gpseph->satellite - PRN_GPS_START];
241 }
242 else if (PRN_QZSS_START <= gpseph->satellite && gpseph->satellite <= PRN_QZSS_END) {
243 ee = &_qzssEph[gpseph->satellite - PRN_QZSS_START];
244 }
245
246 if ( *ee != 0 && gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC == (*ee)->TOC ) {
247 checkEphemeris(*ee, gpseph);
248 }
249
250 if ( *ee == 0 ||
251 gpseph->GPSweek > (*ee)->GPSweek ||
252 (gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC > (*ee)->TOC) ) {
253 delete *ee;
254 *ee = gpseph;
255 printGPSEph(gpseph, true);
256 }
257 else {
258 printGPSEph(gpseph, false);
259 delete gpseph;
260 }
261}
262
263// New Glonass Ephemeris
264////////////////////////////////////////////////////////////////////////////
265void t_bncCore::slotNewGlonassEph(glonassephemeris* glonasseph, const QString& staID) {
266
267 QMutexLocker locker(&_mutex);
268
269 // Check wrong Ephemerides
270 // -----------------------
271 if (glonasseph->x_pos == 0.0 &&
272 glonasseph->y_pos == 0.0 &&
273 glonasseph->z_pos == 0.0) {
274 delete glonasseph;
275 return;
276 }
277
278 glonassephemeris copy_glonasseph = *glonasseph;
279 emit newEphGlonass(copy_glonasseph);
280
281 printEphHeader();
282
283 glonassephemeris** ee = &_glonassEph[glonasseph->almanac_number-1];
284
285 int wwOld, towOld, wwNew, towNew;
286 if (*ee != 0) {
287 wwOld = (*ee)->GPSWeek;
288 towOld = (*ee)->GPSTOW;
289 updatetime(&wwOld, &towOld, (*ee)->tb*1000, 0); // Moscow -> GPS
290
291 wwNew = glonasseph->GPSWeek;
292 towNew = glonasseph->GPSTOW;
293 updatetime(&wwNew, &towNew, glonasseph->tb*1000, 0); // Moscow -> GPS
294 }
295
296 if ( *ee == 0 ||
297 wwNew > wwOld ||
298 (wwNew == wwOld && towNew > towOld) ) {
299 delete *ee;
300 *ee = glonasseph;
301 printGlonassEph(glonasseph, true, staID);
302 }
303 else {
304 printGlonassEph(glonasseph, false, staID);
305 delete glonasseph;
306 }
307}
308
309// New Galileo Ephemeris
310////////////////////////////////////////////////////////////////////////////
311void t_bncCore::slotNewGalileoEph(galileoephemeris* galileoeph) {
312
313 QMutexLocker locker(&_mutex);
314
315 galileoephemeris copy_galileoeph = *galileoeph;
316 emit newEphGalileo(copy_galileoeph);
317
318 printEphHeader();
319
320 int galIndex = galileoeph->satellite;
321 /* GIOVE */
322 if(galIndex == 51) galIndex = 1;
323 else if(galIndex == 52) galIndex = 16;
324 if (galIndex < 0 || galIndex > PRN_GALILEO_END - PRN_GALILEO_START) {
325 emit( newMessage("Wrong Galileo Satellite Number", true) );
326 exit(1);
327 }
328
329 galileoephemeris** ee = &_galileoEph[galIndex];
330
331 if ( *ee == 0 ||
332 galileoeph->Week > (*ee)->Week ||
333 (galileoeph->Week == (*ee)->Week && galileoeph->TOC > (*ee)->TOC) ) {
334 delete *ee;
335 *ee = galileoeph;
336 printGalileoEph(galileoeph, true);
337 }
338 else {
339 printGalileoEph(galileoeph, false);
340 delete galileoeph;
341 }
342}
343
344// Print Header of the output File(s)
345////////////////////////////////////////////////////////////////////////////
346void t_bncCore::printEphHeader() {
347
348 bncSettings settings;
349
350 // Initialization
351 // --------------
352 if (_rinexVers == 0) {
353
354 if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
355 _rinexVers = 3;
356 }
357 else {
358 _rinexVers = 2;
359 }
360
361 _ephPath = settings.value("ephPath").toString();
362
363 if ( !_ephPath.isEmpty() ) {
364 if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
365 _ephPath += QDir::separator();
366 }
367 expandEnvVar(_ephPath);
368 }
369 }
370
371 // (Re-)Open output File(s)
372 // ------------------------
373 if (!_ephPath.isEmpty()) {
374
375 QDateTime datTim = currentDateAndTimeGPS();
376
377 QString ephFileNameGPS = _ephPath + "BRDC" +
378 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'));
379
380 QString hlpStr = bncRinex::nextEpochStr(datTim,
381 settings.value("ephIntr").toString());
382
383 if (_rinexVers == 3) {
384 ephFileNameGPS += hlpStr + datTim.toString(".yyP");
385 }
386 else {
387 ephFileNameGPS += hlpStr + datTim.toString(".yyN");
388 }
389
390 if (_ephFileNameGPS == ephFileNameGPS) {
391 return;
392 }
393 else {
394 _ephFileNameGPS = ephFileNameGPS;
395 }
396
397 for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
398 delete _gpsEph[ii-PRN_GPS_START];
399 _gpsEph[ii-PRN_GPS_START] = 0;
400 }
401 for (int ii = PRN_QZSS_START; ii <= PRN_QZSS_END; ii++) {
402 delete _qzssEph[ii-PRN_QZSS_START];
403 _qzssEph[ii-PRN_QZSS_START] = 0;
404 }
405 for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
406 delete _glonassEph[ii-PRN_GLONASS_START];
407 _glonassEph[ii-PRN_GLONASS_START] = 0;
408 }
409 for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
410 delete _galileoEph[ii-PRN_GALILEO_START];
411 _galileoEph[ii-PRN_GALILEO_START] = 0;
412 }
413 for (int ii = PRN_SBAS_START; ii <= PRN_SBAS_END; ii++) {
414 delete _sbasEph[ii-PRN_SBAS_START];
415 _sbasEph[ii-PRN_SBAS_START] = 0;
416 }
417
418 delete _ephStreamGPS;
419 delete _ephFileGPS;
420
421 QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
422 QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
423
424 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
425 QFile::exists(ephFileNameGPS) ) {
426 appendFlagGPS = QIODevice::Append;
427 }
428
429 _ephFileGPS = new QFile(ephFileNameGPS);
430 _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
431 _ephStreamGPS = new QTextStream();
432 _ephStreamGPS->setDevice(_ephFileGPS);
433
434 if (_rinexVers == 3) {
435 _ephFileGlonass = _ephFileGPS;
436 _ephStreamGlonass = _ephStreamGPS;
437 _ephFileGalileo = _ephFileGPS;
438 _ephStreamGalileo = _ephStreamGPS;
439 _ephFileSBAS = _ephFileGPS;
440 _ephStreamSBAS = _ephStreamGPS;
441 }
442 else if (_rinexVers == 2) {
443 QString ephFileNameGlonass = _ephPath + "BRDC" +
444 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
445 hlpStr + datTim.toString(".yyG");
446
447 delete _ephStreamGlonass;
448 delete _ephFileGlonass;
449
450 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
451 QFile::exists(ephFileNameGlonass) ) {
452 appendFlagGlonass = QIODevice::Append;
453 }
454
455 _ephFileGlonass = new QFile(ephFileNameGlonass);
456 _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
457 _ephStreamGlonass = new QTextStream();
458 _ephStreamGlonass->setDevice(_ephFileGlonass);
459 }
460
461 // Header - RINEX Version 3
462 // ------------------------
463 if (_rinexVers == 3) {
464 if ( ! (appendFlagGPS & QIODevice::Append)) {
465 QString line;
466 line.sprintf(
467 "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
468 3.0, "", "");
469 *_ephStreamGPS << line;
470
471 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
472 *_ephStreamGPS << _pgmName.toAscii().data()
473 << _userName.toAscii().data()
474 << hlp.toAscii().data()
475 << "PGM / RUN BY / DATE" << endl;
476
477 line.sprintf("%60sEND OF HEADER\n", "");
478 *_ephStreamGPS << line;
479
480 _ephStreamGPS->flush();
481 }
482 }
483
484 // Headers - RINEX Version 2
485 // -------------------------
486 else if (_rinexVers == 2) {
487 if (! (appendFlagGPS & QIODevice::Append)) {
488 QString line;
489 line.sprintf("%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n",
490 t_rnxNavFile::defaultRnxNavVersion2, "", "");
491 *_ephStreamGPS << line;
492
493 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
494 *_ephStreamGPS << _pgmName.toAscii().data()
495 << _userName.toAscii().data()
496 << hlp.toAscii().data()
497 << "PGM / RUN BY / DATE" << endl;
498
499 line.sprintf("%60sEND OF HEADER\n", "");
500 *_ephStreamGPS << line;
501
502 _ephStreamGPS->flush();
503 }
504 if (! (appendFlagGlonass & QIODevice::Append)) {
505 QString line;
506 line.sprintf("%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",
507 t_rnxNavFile::defaultRnxNavVersion2, "", "");
508 *_ephStreamGlonass << line;
509
510 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
511 *_ephStreamGlonass << _pgmName.toAscii().data()
512 << _userName.toAscii().data()
513 << hlp.toAscii().data()
514 << "PGM / RUN BY / DATE" << endl;
515
516 line.sprintf("%60sEND OF HEADER\n", "");
517 *_ephStreamGlonass << line;
518
519 _ephStreamGlonass->flush();
520 }
521 }
522 }
523}
524
525// Print One GPS Ephemeris
526////////////////////////////////////////////////////////////////////////////
527void t_bncCore::printGPSEph(gpsephemeris* ep, bool printFile) {
528
529 t_ephGPS eph;
530 eph.set(ep);
531
532 QString strV2 = eph.toString(t_rnxNavFile::defaultRnxNavVersion2);
533 QString strV3 = eph.toString(t_rnxObsHeader::defaultRnxObsVersion3);
534
535 printOutput(printFile, _ephStreamGPS, strV2, strV3);
536}
537
538// Print One Glonass Ephemeris
539////////////////////////////////////////////////////////////////////////////
540void t_bncCore::printGlonassEph(glonassephemeris* ep, bool printFile, const QString& /* staID */) {
541
542 t_ephGlo eph;
543 eph.set(ep);
544
545 QString strV2 = eph.toString(t_rnxNavFile::defaultRnxNavVersion2);
546 QString strV3 = eph.toString(t_rnxObsHeader::defaultRnxObsVersion3);
547
548 //// beg test Dirk
549 // QString hlp = strV2;
550 // cout << hlp.replace('\n', ' ').toAscii().data() << ' ' << staID.toAscii().data() << endl;
551 //// end test Dirk
552
553 printOutput(printFile, _ephStreamGlonass, strV2, strV3);
554}
555
556// Print One Galileo Ephemeris
557////////////////////////////////////////////////////////////////////////////
558void t_bncCore::printGalileoEph(galileoephemeris* ep, bool printFile) {
559
560 t_ephGal eph;
561 eph.set(ep);
562
563 QString strV2 = eph.toString(t_rnxNavFile::defaultRnxNavVersion2);
564 QString strV3 = eph.toString(t_rnxObsHeader::defaultRnxObsVersion3);
565
566 printOutput(printFile, _ephStreamGalileo, strV2, strV3);
567}
568
569// Output
570////////////////////////////////////////////////////////////////////////////
571void t_bncCore::printOutput(bool printFile, QTextStream* stream,
572 const QString& strV2, const QString& strV3) {
573
574 // Output into file
575 // ----------------
576 if (printFile && stream) {
577 if (_rinexVers == 2) {
578 *stream << strV2.toAscii();
579 }
580 else {
581 *stream << strV3.toAscii();
582 }
583 stream->flush();
584 }
585
586 // Output into the socket
587 // ----------------------
588 if (_sockets) {
589 QMutableListIterator<QTcpSocket*> is(*_sockets);
590 while (is.hasNext()) {
591 QTcpSocket* sock = is.next();
592 if (sock->state() == QAbstractSocket::ConnectedState) {
593 if (sock->write(strV3.toAscii()) == -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// Set Port Number
607////////////////////////////////////////////////////////////////////////////
608void t_bncCore::setPort(int port) {
609 _port = port;
610 if (_port != 0) {
611 delete _server;
612 _server = new QTcpServer;
613 if ( !_server->listen(QHostAddress::Any, _port) ) {
614 slotMessage("t_bncCore: Cannot listen on ephemeris port", true);
615 }
616 connect(_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
617 delete _sockets;
618 _sockets = new QList<QTcpSocket*>;
619 }
620}
621
622// Set Port Number
623////////////////////////////////////////////////////////////////////////////
624void t_bncCore::setPortCorr(int port) {
625 _portCorr = port;
626 if (_portCorr != 0) {
627 delete _serverCorr;
628 _serverCorr = new QTcpServer;
629 if ( !_serverCorr->listen(QHostAddress::Any, _portCorr) ) {
630 slotMessage("t_bncCore: Cannot listen on correction port", true);
631 }
632 connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
633 delete _socketsCorr;
634 _socketsCorr = new QList<QTcpSocket*>;
635 }
636}
637
638// New Connection
639////////////////////////////////////////////////////////////////////////////
640void t_bncCore::slotNewConnection() {
641 _sockets->push_back( _server->nextPendingConnection() );
642}
643
644// New Connection
645////////////////////////////////////////////////////////////////////////////
646void t_bncCore::slotNewConnectionCorr() {
647 _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
648}
649
650//
651////////////////////////////////////////////////////////////////////////////
652void t_bncCore::slotQuit() {
653 delete _caster; _caster = 0;
654 qApp->quit();
655}
656
657//
658////////////////////////////////////////////////////////////////////////////
659void t_bncCore::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
660 QMutexLocker locker(&_mutex);
661 emit newOrbCorrections(orbCorrections);
662 if (_socketsCorr) {
663 QListIterator<t_orbCorr> it(orbCorrections);
664 while (it.hasNext()) {
665 const t_orbCorr& corr = it.next();
666 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
667 while (is.hasNext()) {
668 QTcpSocket* sock = is.next();
669 if (sock->state() == QAbstractSocket::ConnectedState) {
670 if (sock->write(corr.toLine().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//
685////////////////////////////////////////////////////////////////////////////
686void t_bncCore::slotNewClkCorrections(QList<t_clkCorr> clkCorrections) {
687 QMutexLocker locker(&_mutex);
688 emit newClkCorrections(clkCorrections);
689 if (_socketsCorr) {
690 QListIterator<t_clkCorr> it(clkCorrections);
691 while (it.hasNext()) {
692 const t_clkCorr& corr = it.next();
693 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
694 while (is.hasNext()) {
695 QTcpSocket* sock = is.next();
696 if (sock->state() == QAbstractSocket::ConnectedState) {
697 if (sock->write(corr.toLine().c_str()) == -1) {
698 delete sock;
699 is.remove();
700 }
701 }
702 else if (sock->state() != QAbstractSocket::ConnectingState) {
703 delete sock;
704 is.remove();
705 }
706 }
707 }
708 }
709}
710
711//
712////////////////////////////////////////////////////////////////////////////
713void t_bncCore::setConfFileName(const QString& confFileName) {
714 if (confFileName.isEmpty()) {
715 _confFileName = QDir::homePath() + QDir::separator()
716 + ".config" + QDir::separator()
717 + qApp->organizationName() + QDir::separator()
718 + qApp->applicationName() + ".bnc";
719 }
720 else {
721 _confFileName = confFileName;
722 }
723}
724
725// Raw Output
726////////////////////////////////////////////////////////////////////////////
727void t_bncCore::writeRawData(const QByteArray& data, const QByteArray& staID,
728 const QByteArray& format) {
729
730 QMutexLocker locker(&_mutex);
731
732 if (!_rawFile) {
733 bncSettings settings;
734 QByteArray fileName = settings.value("rawOutFile").toByteArray();
735 if (!fileName.isEmpty()) {
736 _rawFile = new bncRawFile(fileName, staID, bncRawFile::output);
737 }
738 }
739
740 if (_rawFile) {
741 _rawFile->writeRawData(data, staID, format);
742 }
743}
744
745//
746////////////////////////////////////////////////////////////////////////////
747void t_bncCore::initCombination() {
748#ifdef USE_COMBINATION
749 _bncComb = new bncComb();
750 if (_bncComb->nStreams() < 1) {
751 delete _bncComb;
752 _bncComb = 0;
753 }
754#endif
755}
756
757//
758////////////////////////////////////////////////////////////////////////////
759void t_bncCore::stopCombination() {
760#ifdef USE_COMBINATION
761 delete _bncComb;
762 _bncComb = 0;
763#endif
764}
765
766// Check Ephemeris Consistency
767////////////////////////////////////////////////////////////////////////////
768void t_bncCore::checkEphemeris(gpsephemeris* oldEph, gpsephemeris* newEph) {
769 if (oldEph->clock_bias != newEph->clock_bias ||
770 oldEph->clock_drift != newEph->clock_drift ||
771 oldEph->clock_driftrate != newEph->clock_driftrate) {
772 QString msg = currentDateAndTimeGPS().toString(Qt::ISODate) +
773 QString(" %1 EPH DIFFERS\n").arg(oldEph->satellite);
774 messagePrivate(msg.toAscii());
775 }
776}
777
778
779//
780////////////////////////////////////////////////////////////////////////////
781bool t_bncCore::dateAndTimeGPSSet() const {
782 QMutexLocker locker(&_mutexDateAndTimeGPS);
783 if (_dateAndTimeGPS) {
784 return true;
785 }
786 else {
787 return false;
788 }
789}
790
791//
792////////////////////////////////////////////////////////////////////////////
793QDateTime t_bncCore::dateAndTimeGPS() const {
794 QMutexLocker locker(&_mutexDateAndTimeGPS);
795 if (_dateAndTimeGPS) {
796 return *_dateAndTimeGPS;
797 }
798 else {
799 return QDateTime();
800 }
801}
802
803//
804////////////////////////////////////////////////////////////////////////////
805void t_bncCore::setDateAndTimeGPS(QDateTime dateTime) {
806 QMutexLocker locker(&_mutexDateAndTimeGPS);
807 delete _dateAndTimeGPS;
808 _dateAndTimeGPS = new QDateTime(dateTime);
809}
810
811//
812////////////////////////////////////////////////////////////////////////////
813void t_bncCore::startPPP() {
814 _pppMain->start();
815}
816
817//
818////////////////////////////////////////////////////////////////////////////
819void t_bncCore::stopPPP() {
820 _pppMain->stop();
821 emit stopRinexPPP();
822}
823
824// New SBAS Ephemeris
825////////////////////////////////////////////////////////////////////////////
826void t_bncCore::slotNewSBASEph(sbasephemeris* sbaseph) {
827 QMutexLocker locker(&_mutex);
828
829 // Check wrong Ephemerides
830 // -----------------------
831 if (sbaseph->x_pos == 0.0 &&
832 sbaseph->y_pos == 0.0 &&
833 sbaseph->z_pos == 0.0) {
834 delete sbaseph;
835 return;
836 }
837
838 sbasephemeris copy_sbaseph = *sbaseph;
839 emit newEphSBAS(copy_sbaseph);
840
841 printEphHeader();
842
843 sbasephemeris** ee = &_sbasEph[sbaseph->satellite - PRN_SBAS_START];
844
845 bool replace = false;
846 if (*ee != 0) {
847 bncTime oldTime((*ee)->GPSweek_TOE, double((*ee)->TOE));
848 bncTime newTime(sbaseph->GPSweek_TOE, double(sbaseph->TOE));
849 if (newTime > oldTime) {
850 replace = true;
851 }
852 }
853
854 if ( *ee == 0 || replace) {
855 delete *ee;
856 *ee = sbaseph;
857 printSBASEph(sbaseph, true);
858 }
859 else {
860 printSBASEph(sbaseph, false);
861 delete sbaseph;
862 }
863}
864
865// Print One SBAS Ephemeris
866////////////////////////////////////////////////////////////////////////////
867void t_bncCore::printSBASEph(sbasephemeris* ep, bool printFile) {
868
869 t_ephSBAS eph;
870 eph.set(ep);
871
872 QString strV2 = eph.toString(t_rnxNavFile::defaultRnxNavVersion2);
873 QString strV3 = eph.toString(t_rnxObsHeader::defaultRnxObsVersion3);
874
875 printOutput(printFile, _ephStreamSBAS, strV2, strV3);
876}
Note: See TracBrowser for help on using the repository browser.