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

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