source: ntrip/trunk/BNC/bncapp.cpp@ 2770

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