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

Last change on this file since 1202 was 1171, checked in by mervart, 17 years ago

* empty log message *

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