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

Last change on this file since 6049 was 6049, checked in by mervart, 8 years ago
File size: 24.8 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: t_bncCore
30 *
31 * Purpose: This class implements the main application
32 *
33 * Author: L. Mervart
34 *
35 * Created: 29-Aug-2006
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42#include <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 "PPP/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_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
87 _glonassEph[ii-PRN_GLONASS_START] = 0;
88 }
89 for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
90 _galileoEph[ii-PRN_GALILEO_START] = 0;
91 }
92
93 // Eph file(s)
94 // -----------
95 _rinexVers = 0;
96 _ephFileGPS = 0;
97 _ephStreamGPS = 0;
98 _ephFileGlonass = 0;
99 _ephStreamGlonass = 0;
100 _ephFileGalileo = 0;
101 _ephStreamGalileo = 0;
102
103 _port = 0;
104 _server = 0;
105 _sockets = 0;
106
107 _portCorr = 0;
108 _serverCorr = 0;
109 _socketsCorr = 0;
110
111 _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
112#ifdef WIN32
113 _userName = QString("${USERNAME}");
114#else
115 _userName = QString("${USER}");
116#endif
117 expandEnvVar(_userName);
118 _userName = _userName.leftJustified(20, ' ', true);
119
120 _corrs = new QMultiMap<bncTime, QString>;
121
122 _dateAndTimeGPS = 0;
123
124 for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
125 _GLOFreq[ii] = 0;
126 }
127
128 _mainWindow = 0;
129
130 _pppMain = new BNC_PPP::t_pppMain();
131 qRegisterMetaType< QVector<double> >("QVector<double>");
132 qRegisterMetaType<bncTime>("bncTime");
133}
134
135// Destructor
136////////////////////////////////////////////////////////////////////////////
137t_bncCore::~t_bncCore() {
138 delete _logStream;
139 delete _logFile;
140 delete _ephStreamGPS;
141 delete _ephFileGPS;
142 delete _server;
143 delete _sockets;
144 delete _serverCorr;
145 delete _socketsCorr;
146 if (_rinexVers == 2) {
147 delete _ephStreamGlonass;
148 delete _ephFileGlonass;
149 }
150 for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
151 delete _gpsEph[ii-PRN_GPS_START];
152 }
153 for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
154 delete _glonassEph[ii-PRN_GLONASS_START];
155 }
156 for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
157 delete _galileoEph[ii-PRN_GALILEO_START];
158 }
159
160 delete _corrs;
161
162 delete _dateAndTimeGPS;
163
164 delete _rawFile;
165
166#ifdef USE_COMBINATION
167 delete _bncComb;
168#endif
169}
170
171// Write a Program Message
172////////////////////////////////////////////////////////////////////////////
173void t_bncCore::slotMessage(QByteArray msg, bool showOnScreen) {
174
175 QMutexLocker locker(&_mutexMessage);
176
177 messagePrivate(msg);
178 emit newMessage(msg, showOnScreen);
179}
180
181// Write a Program Message (private, no lock)
182////////////////////////////////////////////////////////////////////////////
183void t_bncCore::messagePrivate(const QByteArray& msg) {
184
185 // First time resolve the log file name
186 // ------------------------------------
187 QDate currDate = currentDateAndTimeGPS().date();
188 if (_logFileFlag == 0 || _fileDate != currDate) {
189 delete _logStream; _logStream = 0;
190 delete _logFile; _logFile = 0;
191 _logFileFlag = 1;
192 bncSettings settings;
193 QString logFileName = settings.value("logFile").toString();
194 if ( !logFileName.isEmpty() ) {
195 expandEnvVar(logFileName);
196 _logFile = new QFile(logFileName + "_" +
197 currDate.toString("yyMMdd").toAscii().data());
198 _fileDate = currDate;
199 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
200 _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
201 }
202 else {
203 _logFile->open(QIODevice::WriteOnly);
204 }
205 _logStream = new QTextStream();
206 _logStream->setDevice(_logFile);
207 }
208 }
209
210 if (_logStream) {
211 QByteArray msgLocal = msg;
212 if (msg.indexOf('\n') == 0) {
213 *_logStream << endl;
214 msgLocal = msg.mid(1);
215 }
216 *_logStream << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
217 *_logStream << msgLocal.data() << endl;
218 _logStream->flush();
219 _logFile->flush();
220 }
221}
222
223// New GPS Ephemeris
224////////////////////////////////////////////////////////////////////////////
225void t_bncCore::slotNewGPSEph(gpsephemeris* gpseph) {
226
227 QMutexLocker locker(&_mutex);
228
229 gpsephemeris copy_gpseph = *gpseph;
230 emit newEphGPS(copy_gpseph);
231
232 printEphHeader();
233
234 gpsephemeris** ee = &_gpsEph[gpseph->satellite-1];
235
236 if ( *ee != 0 &&
237 gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC == (*ee)->TOC ) {
238 checkEphemeris(*ee, gpseph);
239 }
240
241 if ( *ee == 0 ||
242 gpseph->GPSweek > (*ee)->GPSweek ||
243 (gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC > (*ee)->TOC) ) {
244 delete *ee;
245 *ee = gpseph;
246 printGPSEph(gpseph, true);
247 }
248 else {
249 printGPSEph(gpseph, false);
250 delete gpseph;
251 }
252}
253
254// New Glonass Ephemeris
255////////////////////////////////////////////////////////////////////////////
256void t_bncCore::slotNewGlonassEph(glonassephemeris* glonasseph, const QString& staID) {
257
258 QMutexLocker locker(&_mutex);
259
260 // Check wrong Ephemerides
261 // -----------------------
262 if (glonasseph->x_pos == 0.0 &&
263 glonasseph->y_pos == 0.0 &&
264 glonasseph->z_pos == 0.0) {
265 delete glonasseph;
266 return;
267 }
268
269 glonassephemeris copy_glonasseph = *glonasseph;
270 emit newEphGlonass(copy_glonasseph);
271
272 printEphHeader();
273
274 glonassephemeris** ee = &_glonassEph[glonasseph->almanac_number-1];
275
276 int wwOld, towOld, wwNew, towNew;
277 if (*ee != 0) {
278 wwOld = (*ee)->GPSWeek;
279 towOld = (*ee)->GPSTOW;
280 updatetime(&wwOld, &towOld, (*ee)->tb*1000, 0); // Moscow -> GPS
281
282 wwNew = glonasseph->GPSWeek;
283 towNew = glonasseph->GPSTOW;
284 updatetime(&wwNew, &towNew, glonasseph->tb*1000, 0); // Moscow -> GPS
285 }
286
287 if ( *ee == 0 ||
288 wwNew > wwOld ||
289 (wwNew == wwOld && towNew > towOld) ) {
290 delete *ee;
291 *ee = glonasseph;
292 printGlonassEph(glonasseph, true, staID);
293 }
294 else {
295 printGlonassEph(glonasseph, false, staID);
296 delete glonasseph;
297 }
298}
299
300// New Galileo Ephemeris
301////////////////////////////////////////////////////////////////////////////
302void t_bncCore::slotNewGalileoEph(galileoephemeris* galileoeph) {
303
304 QMutexLocker locker(&_mutex);
305
306 galileoephemeris copy_galileoeph = *galileoeph;
307 emit newEphGalileo(copy_galileoeph);
308
309 printEphHeader();
310
311 int galIndex = galileoeph->satellite;
312 /* GIOVE */
313 if(galIndex == 51) galIndex = 1;
314 else if(galIndex == 52) galIndex = 16;
315 if (galIndex < 0 || galIndex > PRN_GALILEO_END - PRN_GALILEO_START) {
316 emit( newMessage("Wrong Galileo Satellite Number", true) );
317 exit(1);
318 }
319
320 galileoephemeris** ee = &_galileoEph[galIndex];
321
322 if ( *ee == 0 ||
323 galileoeph->Week > (*ee)->Week ||
324 (galileoeph->Week == (*ee)->Week && galileoeph->TOC > (*ee)->TOC) ) {
325 delete *ee;
326 *ee = galileoeph;
327 printGalileoEph(galileoeph, true);
328 }
329 else {
330 printGalileoEph(galileoeph, false);
331 delete galileoeph;
332 }
333}
334
335// Print Header of the output File(s)
336////////////////////////////////////////////////////////////////////////////
337void t_bncCore::printEphHeader() {
338
339 bncSettings settings;
340
341 // Initialization
342 // --------------
343 if (_rinexVers == 0) {
344
345 if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
346 _rinexVers = 3;
347 }
348 else {
349 _rinexVers = 2;
350 }
351
352 _ephPath = settings.value("ephPath").toString();
353
354 if ( !_ephPath.isEmpty() ) {
355 if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
356 _ephPath += QDir::separator();
357 }
358 expandEnvVar(_ephPath);
359 }
360 }
361
362 // (Re-)Open output File(s)
363 // ------------------------
364 if (!_ephPath.isEmpty()) {
365
366 QDateTime datTim = currentDateAndTimeGPS();
367
368 QString ephFileNameGPS = _ephPath + "BRDC" +
369 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'));
370
371 QString hlpStr = bncRinex::nextEpochStr(datTim,
372 settings.value("ephIntr").toString());
373
374 if (_rinexVers == 3) {
375 ephFileNameGPS += hlpStr + datTim.toString(".yyP");
376 }
377 else {
378 ephFileNameGPS += hlpStr + datTim.toString(".yyN");
379 }
380
381 if (_ephFileNameGPS == ephFileNameGPS) {
382 return;
383 }
384 else {
385 _ephFileNameGPS = ephFileNameGPS;
386 }
387
388 for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
389 delete _gpsEph[ii-PRN_GPS_START];
390 _gpsEph[ii-PRN_GPS_START] = 0;
391 }
392 for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
393 delete _glonassEph[ii-PRN_GLONASS_START];
394 _glonassEph[ii-PRN_GLONASS_START] = 0;
395 }
396 for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
397 delete _galileoEph[ii-PRN_GALILEO_START];
398 _galileoEph[ii-PRN_GALILEO_START] = 0;
399 }
400
401 delete _ephStreamGPS;
402 delete _ephFileGPS;
403
404 QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
405 QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
406 QFlags<QIODevice::OpenModeFlag> appendFlagGalileo;
407
408 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
409 QFile::exists(ephFileNameGPS) ) {
410 appendFlagGPS = QIODevice::Append;
411 }
412
413 _ephFileGPS = new QFile(ephFileNameGPS);
414 _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
415 _ephStreamGPS = new QTextStream();
416 _ephStreamGPS->setDevice(_ephFileGPS);
417
418 if (_rinexVers == 3) {
419 _ephFileGlonass = _ephFileGPS;
420 _ephStreamGlonass = _ephStreamGPS;
421 _ephFileGalileo = _ephFileGPS;
422 _ephStreamGalileo = _ephStreamGPS;
423 }
424 else if (_rinexVers == 2) {
425 QString ephFileNameGlonass = _ephPath + "BRDC" +
426 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
427 hlpStr + datTim.toString(".yyG");
428
429 delete _ephStreamGlonass;
430 delete _ephFileGlonass;
431
432 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
433 QFile::exists(ephFileNameGlonass) ) {
434 appendFlagGlonass = QIODevice::Append;
435 }
436
437 _ephFileGlonass = new QFile(ephFileNameGlonass);
438 _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
439 _ephStreamGlonass = new QTextStream();
440 _ephStreamGlonass->setDevice(_ephFileGlonass);
441 }
442
443 // Header - RINEX Version 3
444 // ------------------------
445 if (_rinexVers == 3) {
446 if ( ! (appendFlagGPS & QIODevice::Append)) {
447 QString line;
448 line.sprintf(
449 "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
450 3.0, "", "");
451 *_ephStreamGPS << line;
452
453 QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
454 *_ephStreamGPS << _pgmName.toAscii().data()
455 << _userName.toAscii().data()
456 << hlp.toAscii().data()
457 << "PGM / RUN BY / DATE" << endl;
458
459 line.sprintf("%60sEND OF HEADER\n", "");
460 *_ephStreamGPS << line;
461
462 _ephStreamGPS->flush();
463 }
464 }
465
466 // Headers - RINEX Version 2
467 // -------------------------
468 else if (_rinexVers == 2) {
469 if (! (appendFlagGPS & QIODevice::Append)) {
470 QString line;
471 line.sprintf("%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n",
472 t_rnxNavFile::defaultRnxNavVersion2, "", "");
473 *_ephStreamGPS << line;
474
475 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
476 *_ephStreamGPS << _pgmName.toAscii().data()
477 << _userName.toAscii().data()
478 << hlp.toAscii().data()
479 << "PGM / RUN BY / DATE" << endl;
480
481 line.sprintf("%60sEND OF HEADER\n", "");
482 *_ephStreamGPS << line;
483
484 _ephStreamGPS->flush();
485 }
486 if (! (appendFlagGlonass & QIODevice::Append)) {
487 QString line;
488 line.sprintf("%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",
489 t_rnxNavFile::defaultRnxNavVersion2, "", "");
490 *_ephStreamGlonass << line;
491
492 QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
493 *_ephStreamGlonass << _pgmName.toAscii().data()
494 << _userName.toAscii().data()
495 << hlp.toAscii().data()
496 << "PGM / RUN BY / DATE" << endl;
497
498 line.sprintf("%60sEND OF HEADER\n", "");
499 *_ephStreamGlonass << line;
500
501 _ephStreamGlonass->flush();
502 }
503 }
504 }
505}
506
507// Print One GPS Ephemeris
508////////////////////////////////////////////////////////////////////////////
509void t_bncCore::printGPSEph(gpsephemeris* ep, bool printFile) {
510
511 t_ephGPS eph;
512 eph.set(ep);
513
514 QString strV2 = eph.toString(t_rnxNavFile::defaultRnxNavVersion2);
515 QString strV3 = eph.toString(t_rnxObsHeader::defaultRnxObsVersion3);
516
517 printOutput(printFile, _ephStreamGPS, strV2, strV3);
518}
519
520// Print One Glonass Ephemeris
521////////////////////////////////////////////////////////////////////////////
522void t_bncCore::printGlonassEph(glonassephemeris* ep, bool printFile, const QString& /* staID */) {
523
524 t_ephGlo eph;
525 eph.set(ep);
526
527 QString strV2 = eph.toString(t_rnxNavFile::defaultRnxNavVersion2);
528 QString strV3 = eph.toString(t_rnxObsHeader::defaultRnxObsVersion3);
529
530 //// beg test Dirk
531 // QString hlp = strV2;
532 // cout << hlp.replace('\n', ' ').toAscii().data() << ' ' << staID.toAscii().data() << endl;
533 //// end test Dirk
534
535 printOutput(printFile, _ephStreamGlonass, strV2, strV3);
536}
537
538// Print One Galileo Ephemeris
539////////////////////////////////////////////////////////////////////////////
540void t_bncCore::printGalileoEph(galileoephemeris* ep, bool printFile) {
541
542 t_ephGal eph;
543 eph.set(ep);
544
545 QString strV2 = eph.toString(t_rnxNavFile::defaultRnxNavVersion2);
546 QString strV3 = eph.toString(t_rnxObsHeader::defaultRnxObsVersion3);
547
548 printOutput(printFile, _ephStreamGalileo, strV2, strV3);
549}
550
551// Output
552////////////////////////////////////////////////////////////////////////////
553void t_bncCore::printOutput(bool printFile, QTextStream* stream,
554 const QString& strV2, const QString& strV3) {
555
556 // Output into file
557 // ----------------
558 if (printFile && stream) {
559 if (_rinexVers == 2) {
560 *stream << strV2.toAscii();
561 }
562 else {
563 *stream << strV3.toAscii();
564 }
565 stream->flush();
566 }
567
568 // Output into the socket
569 // ----------------------
570 if (_sockets) {
571 QMutableListIterator<QTcpSocket*> is(*_sockets);
572 while (is.hasNext()) {
573 QTcpSocket* sock = is.next();
574 if (sock->state() == QAbstractSocket::ConnectedState) {
575 if (sock->write(strV3.toAscii()) == -1) {
576 delete sock;
577 is.remove();
578 }
579 }
580 else if (sock->state() != QAbstractSocket::ConnectingState) {
581 delete sock;
582 is.remove();
583 }
584 }
585 }
586}
587
588// Set Port Number
589////////////////////////////////////////////////////////////////////////////
590void t_bncCore::setPort(int port) {
591 _port = port;
592 if (_port != 0) {
593 delete _server;
594 _server = new QTcpServer;
595 if ( !_server->listen(QHostAddress::Any, _port) ) {
596 slotMessage("t_bncCore: Cannot listen on ephemeris port", true);
597 }
598 connect(_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
599 delete _sockets;
600 _sockets = new QList<QTcpSocket*>;
601 }
602}
603
604// Set Port Number
605////////////////////////////////////////////////////////////////////////////
606void t_bncCore::setPortCorr(int port) {
607 _portCorr = port;
608 if (_portCorr != 0) {
609 delete _serverCorr;
610 _serverCorr = new QTcpServer;
611 if ( !_serverCorr->listen(QHostAddress::Any, _portCorr) ) {
612 slotMessage("t_bncCore: Cannot listen on correction port", true);
613 }
614 connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
615 delete _socketsCorr;
616 _socketsCorr = new QList<QTcpSocket*>;
617 }
618}
619
620// New Connection
621////////////////////////////////////////////////////////////////////////////
622void t_bncCore::slotNewConnection() {
623 _sockets->push_back( _server->nextPendingConnection() );
624}
625
626// New Connection
627////////////////////////////////////////////////////////////////////////////
628void t_bncCore::slotNewConnectionCorr() {
629 _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
630}
631
632//
633////////////////////////////////////////////////////////////////////////////
634void t_bncCore::slotQuit() {
635 cout << "t_bncCore::slotQuit" << endl;
636 delete _caster; _caster = 0;
637 qApp->quit();
638}
639
640//
641////////////////////////////////////////////////////////////////////////////
642void t_bncCore::slotNewCorrLine(QString line, QString staID, bncTime coTime) {
643
644 QMutexLocker locker(&_mutex);
645
646 // Combination of Corrections
647 // --------------------------
648#ifdef USE_COMBINATION
649 if (_bncComb) {
650 _bncComb->processCorrLine(staID, line);
651 }
652#endif
653
654 bncSettings settings;
655 _waitCoTime = settings.value("corrTime").toDouble();
656 if (_waitCoTime < 0.0) {
657 _waitCoTime = 0.0;
658 }
659
660 // First time, set the _lastCorrDumpTime
661 // -------------------------------------
662 if (!_lastCorrDumpTime[staID].valid()) {
663 _lastCorrDumpTime[staID] = coTime - 1.0;
664 }
665
666 // An old correction - throw it away
667 // ---------------------------------
668 if (_waitCoTime > 0.0 && coTime <= _lastCorrDumpTime[staID]) {
669 if (!_bncComb) {
670 QString line = staID + ": Correction for one sat neglected because overaged by " +
671 QString().sprintf(" %f sec",
672 _lastCorrDumpTime[staID] - coTime + _waitCoTime);
673 messagePrivate(line.toAscii());
674 emit( newMessage(line.toAscii(), true) );
675 }
676 return;
677 }
678
679 _corrs->insert(coTime, QString(line + " " + staID));
680
681 // Dump Corrections
682 // ----------------
683 if (_waitCoTime == 0.0) {
684 dumpCorrs();
685 }
686 else if (coTime - _waitCoTime > _lastCorrDumpTime[staID]) {
687 dumpCorrs(_lastCorrDumpTime[staID] + 1, coTime - _waitCoTime);
688 _lastCorrDumpTime[staID] = coTime - _waitCoTime;
689 }
690}
691
692// Dump Complete Correction Epochs
693////////////////////////////////////////////////////////////////////////////
694void t_bncCore::dumpCorrs(bncTime minTime, bncTime maxTime) {
695 QStringList allCorrs;
696 QMutableMapIterator<bncTime, QString> it(*_corrs);
697 while (it.hasNext()) {
698 it.next();
699 const bncTime& corrTime = it.key();
700 if (minTime <= corrTime && corrTime <= maxTime) {
701 allCorrs << it.value();
702 it.remove();
703 }
704 }
705 dumpCorrs(allCorrs);
706}
707
708// Dump all corrections
709////////////////////////////////////////////////////////////////////////////
710void t_bncCore::dumpCorrs() {
711 QStringList allCorrs;
712 QMutableMapIterator<bncTime, QString> it(*_corrs);
713 while (it.hasNext()) {
714 allCorrs << it.next().value();
715 it.remove();
716 }
717 dumpCorrs(allCorrs);
718}
719
720// Dump List of Corrections
721////////////////////////////////////////////////////////////////////////////
722void t_bncCore::dumpCorrs(const QStringList& allCorrs) {
723 emit newCorrections(allCorrs);
724 if (_socketsCorr) {
725 QListIterator<QString> it(allCorrs);
726 while (it.hasNext()) {
727 QString corrLine = it.next() + "\n";
728
729 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
730 while (is.hasNext()) {
731 QTcpSocket* sock = is.next();
732 if (sock->state() == QAbstractSocket::ConnectedState) {
733 if (sock->write(corrLine.toAscii()) == -1) {
734 delete sock;
735 is.remove();
736 }
737 }
738 else if (sock->state() != QAbstractSocket::ConnectingState) {
739 delete sock;
740 is.remove();
741 }
742 }
743 }
744 }
745}
746
747//
748////////////////////////////////////////////////////////////////////////////
749void t_bncCore::setConfFileName(const QString& confFileName) {
750 if (confFileName.isEmpty()) {
751 _confFileName = QDir::homePath() + QDir::separator()
752 + ".config" + QDir::separator()
753 + qApp->organizationName() + QDir::separator()
754 + qApp->applicationName() + ".bnc";
755 }
756 else {
757 _confFileName = confFileName;
758 }
759}
760
761// Raw Output
762////////////////////////////////////////////////////////////////////////////
763void t_bncCore::writeRawData(const QByteArray& data, const QByteArray& staID,
764 const QByteArray& format) {
765
766 QMutexLocker locker(&_mutex);
767
768 if (!_rawFile) {
769 bncSettings settings;
770 QByteArray fileName = settings.value("rawOutFile").toByteArray();
771 if (!fileName.isEmpty()) {
772 _rawFile = new bncRawFile(fileName, staID, bncRawFile::output);
773 }
774 }
775
776 if (_rawFile) {
777 _rawFile->writeRawData(data, staID, format);
778 }
779}
780
781// Get Glonass Slot Numbers from Global Array
782////////////////////////////////////////////////////////////////////////////
783void t_bncCore::getGlonassSlotNums(int GLOFreq[]) {
784
785 QMutexLocker locker(&_mutex);
786
787 for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
788 if (_GLOFreq[ii] != 0) {
789 GLOFreq[ii] = _GLOFreq[ii];
790 }
791 }
792}
793
794// Store Glonass Slot Numbers to Global Array
795////////////////////////////////////////////////////////////////////////////
796void t_bncCore::storeGlonassSlotNums(const int GLOFreq[]) {
797
798 QMutexLocker locker(&_mutex);
799
800 for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
801 if (GLOFreq[ii] != 0) {
802 _GLOFreq[ii] = GLOFreq[ii];
803 }
804 }
805}
806
807//
808////////////////////////////////////////////////////////////////////////////
809void t_bncCore::initCombination() {
810#ifdef USE_COMBINATION
811 _bncComb = new bncComb();
812 if (_bncComb->nStreams() < 1) {
813 delete _bncComb;
814 _bncComb = 0;
815 }
816#endif
817}
818
819//
820////////////////////////////////////////////////////////////////////////////
821void t_bncCore::stopCombination() {
822#ifdef USE_COMBINATION
823 delete _bncComb;
824 _bncComb = 0;
825#endif
826}
827
828// Check Ephemeris Consistency
829////////////////////////////////////////////////////////////////////////////
830void t_bncCore::checkEphemeris(gpsephemeris* oldEph, gpsephemeris* newEph) {
831 if (oldEph->clock_bias != newEph->clock_bias ||
832 oldEph->clock_drift != newEph->clock_drift ||
833 oldEph->clock_driftrate != newEph->clock_driftrate) {
834 QString msg = currentDateAndTimeGPS().toString(Qt::ISODate) +
835 QString(" %1 EPH DIFFERS\n").arg(oldEph->satellite);
836 messagePrivate(msg.toAscii());
837 }
838}
839
840
841//
842////////////////////////////////////////////////////////////////////////////
843bool t_bncCore::dateAndTimeGPSSet() const {
844 QMutexLocker locker(&_mutexDateAndTimeGPS);
845 if (_dateAndTimeGPS) {
846 return true;
847 }
848 else {
849 return false;
850 }
851}
852
853//
854////////////////////////////////////////////////////////////////////////////
855QDateTime t_bncCore::dateAndTimeGPS() const {
856 QMutexLocker locker(&_mutexDateAndTimeGPS);
857 if (_dateAndTimeGPS) {
858 return *_dateAndTimeGPS;
859 }
860 else {
861 return QDateTime();
862 }
863}
864
865//
866////////////////////////////////////////////////////////////////////////////
867void t_bncCore::setDateAndTimeGPS(QDateTime dateTime) {
868 QMutexLocker locker(&_mutexDateAndTimeGPS);
869 delete _dateAndTimeGPS;
870 _dateAndTimeGPS = new QDateTime(dateTime);
871}
872
873//
874////////////////////////////////////////////////////////////////////////////
875void t_bncCore::startPPP() {
876 _pppMain->start();
877}
878
879//
880////////////////////////////////////////////////////////////////////////////
881void t_bncCore::stopPPP() {
882 _pppMain->stop();
883 emit stopRinexPPP();
884}
Note: See TracBrowser for help on using the repository browser.