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

Last change on this file since 991 was 991, checked in by mervart, 16 years ago

* empty log message *

File size: 19.5 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
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 QSettings settings;
114 _lastDumpCoSec = 0;
115 _waitCoTime = settings.value("corrTime").toInt();
116 if (_waitCoTime < 1) {
117 _waitCoTime = 1;
118 }
[975]119
120 _corrs = new QMultiMap<long, QString>;
[82]121}
122
123// Destructor
124////////////////////////////////////////////////////////////////////////////
125bncApp::~bncApp() {
[109]126 delete _logStream;
127 delete _logFile;
[533]128 delete _ephStreamGPS;
129 delete _ephFileGPS;
[589]130 delete _server;
131 delete _sockets;
[937]132 delete _serverCorr;
133 delete _socketsCorr;
[534]134 if (_rinexVers == 2) {
[533]135 delete _ephStreamGlonass;
136 delete _ephFileGlonass;
137 }
[516]138 for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
139 delete _gpsEph[ii-PRN_GPS_START];
140 }
141 for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
142 delete _glonassEph[ii-PRN_GLONASS_START];
143 }
[975]144
145 delete _corrs;
[82]146}
147
148// Write a Program Message
149////////////////////////////////////////////////////////////////////////////
150void bncApp::slotMessage(const QByteArray msg) {
[150]151
[243]152 QMutexLocker locker(&_mutex);
153
[990]154 messagePrivate(msg);
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) {
[566]182 *_logStream << QDateTime::currentDateTime().toUTC().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
[534]194 printEphHeader();
195
[532]196 gpsephemeris** ee = &_gpsEph[gpseph->satellite-1];
[538]197 if ( *ee == 0 ||
198 gpseph->GPSweek > (*ee)->GPSweek ||
[594]199 (gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC > (*ee)->TOC) ) {
[516]200 delete *ee;
201 *ee = gpseph;
[600]202 printGPSEph(gpseph, true);
[516]203 }
204 else {
[600]205 printGPSEph(gpseph, false);
[516]206 delete gpseph;
207 }
[511]208}
209
[535]210// New Glonass Ephemeris
[511]211////////////////////////////////////////////////////////////////////////////
212void bncApp::slotNewGlonassEph(glonassephemeris* glonasseph) {
[516]213
214 QMutexLocker locker(&_mutex);
215
[534]216 printEphHeader();
217
[532]218 glonassephemeris** ee = &_glonassEph[glonasseph->almanac_number-1];
[531]219
[578]220 int wwOld, towOld, wwNew, towNew;
[577]221 if (*ee != 0) {
[578]222 wwOld = (*ee)->GPSWeek;
223 towOld = (*ee)->GPSTOW;
[901]224 updatetime(&wwOld, &towOld, (*ee)->tb*1000, 0);
[577]225
[578]226 wwNew = glonasseph->GPSWeek;
227 towNew = glonasseph->GPSTOW;
[901]228 updatetime(&wwNew, &towNew, glonasseph->tb*1000, 0);
[577]229 }
230
[578]231 if ( *ee == 0 ||
232 wwNew > wwOld ||
233 (wwNew == wwOld && towNew > towOld) ) {
[531]234 delete *ee;
235 *ee = glonasseph;
[600]236 printGlonassEph(glonasseph, true);
[531]237 }
238 else {
[600]239 printGlonassEph(glonasseph, false);
[531]240 delete glonasseph;
241 }
[511]242}
243
[535]244// Print Header of the output File(s)
[516]245////////////////////////////////////////////////////////////////////////////
246void bncApp::printEphHeader() {
[528]247
[535]248 QSettings settings;
249
[534]250 // Initialization
251 // --------------
252 if (_rinexVers == 0) {
[528]253
[533]254 if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
[534]255 _rinexVers = 3;
[533]256 }
257 else {
[534]258 _rinexVers = 2;
[533]259 }
[529]260
[533]261 _ephPath = settings.value("ephPath").toString();
262
263 if ( !_ephPath.isEmpty() ) {
264 if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
265 _ephPath += QDir::separator();
266 }
267 expandEnvVar(_ephPath);
268 }
[517]269 }
[533]270
[534]271 // (Re-)Open output File(s)
272 // ------------------------
[533]273 if (!_ephPath.isEmpty()) {
274
[566]275 QDateTime datTim = QDateTime::currentDateTime().toUTC();
[533]276
[583]277 QString ephFileNameGPS = _ephPath + "BRDC" +
[563]278 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'));
[533]279
[647]280 QString hlpStr = bncRinex::nextEpochStr(datTim,
281 settings.value("ephIntr").toString());
[584]282
[575]283 if (_rinexVers == 3) {
284 ephFileNameGPS += hlpStr + datTim.toString(".yyP");
285 }
286 else {
287 ephFileNameGPS += hlpStr + datTim.toString(".yyN");
288 }
[563]289
[533]290 if (_ephFileNameGPS == ephFileNameGPS) {
291 return;
292 }
293 else {
294 _ephFileNameGPS = ephFileNameGPS;
295 }
296
[575]297 for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
298 delete _gpsEph[ii-PRN_GPS_START];
299 _gpsEph[ii-PRN_GPS_START] = 0;
300 }
301 for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
302 delete _glonassEph[ii-PRN_GLONASS_START];
303 _glonassEph[ii-PRN_GLONASS_START] = 0;
304 }
305
[533]306 delete _ephStreamGPS;
307 delete _ephFileGPS;
308
[535]309 QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
[536]310 QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
311
[535]312 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
313 QFile::exists(ephFileNameGPS) ) {
314 appendFlagGPS = QIODevice::Append;
315 }
316
[533]317 _ephFileGPS = new QFile(ephFileNameGPS);
[535]318 _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
[533]319 _ephStreamGPS = new QTextStream();
320 _ephStreamGPS->setDevice(_ephFileGPS);
321
[534]322 if (_rinexVers == 3) {
[533]323 _ephFileGlonass = _ephFileGPS;
324 _ephStreamGlonass = _ephStreamGPS;
325 }
[534]326 else if (_rinexVers == 2) {
[583]327 QString ephFileNameGlonass = _ephPath + "BRDC" +
[563]328 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
[575]329 hlpStr + datTim.toString(".yyG");
[533]330
331 delete _ephStreamGlonass;
332 delete _ephFileGlonass;
333
[535]334 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
335 QFile::exists(ephFileNameGlonass) ) {
336 appendFlagGlonass = QIODevice::Append;
337 }
338
[533]339 _ephFileGlonass = new QFile(ephFileNameGlonass);
[535]340 _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
[533]341 _ephStreamGlonass = new QTextStream();
342 _ephStreamGlonass->setDevice(_ephFileGlonass);
343 }
344
[534]345 // Header - RINEX Version 3
346 // ------------------------
347 if (_rinexVers == 3) {
[537]348 if ( ! (appendFlagGPS & QIODevice::Append)) {
349 QString line;
350 line.sprintf(
351 "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
352 3.0, "", "");
353 *_ephStreamGPS << line;
354
[566]355 QString hlp = QDateTime::currentDateTime().toUTC().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
[559]356 *_ephStreamGPS << _pgmName.toAscii().data()
357 << _userName.toAscii().data()
358 << hlp.toAscii().data()
359 << "PGM / RUN BY / DATE" << endl;
360
361 line.sprintf("%60sEND OF HEADER\n", "");
[537]362 *_ephStreamGPS << line;
363
364 _ephStreamGPS->flush();
[535]365 }
[533]366 }
367
[536]368 // Headers - RINEX Version 2
369 // -------------------------
[534]370 else if (_rinexVers == 2) {
[536]371 if (! (appendFlagGPS & QIODevice::Append)) {
372 QString line;
373 line.sprintf(
[565]374 "%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n", 2.11, "", "");
[536]375 *_ephStreamGPS << line;
376
[566]377 QString hlp = QDateTime::currentDateTime().toUTC().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
[559]378 *_ephStreamGPS << _pgmName.toAscii().data()
379 << _userName.toAscii().data()
380 << hlp.toAscii().data()
381 << "PGM / RUN BY / DATE" << endl;
382
383 line.sprintf("%60sEND OF HEADER\n", "");
[536]384 *_ephStreamGPS << line;
[537]385
386 _ephStreamGPS->flush();
[536]387 }
388 if (! (appendFlagGlonass & QIODevice::Append)) {
389 QString line;
390 line.sprintf(
[582]391 "%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",2.11,"","");
[536]392 *_ephStreamGlonass << line;
393
[566]394 QString hlp = QDateTime::currentDateTime().toUTC().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
[559]395 *_ephStreamGlonass << _pgmName.toAscii().data()
396 << _userName.toAscii().data()
397 << hlp.toAscii().data()
398 << "PGM / RUN BY / DATE" << endl;
399
400 line.sprintf("%60sEND OF HEADER\n", "");
[536]401 *_ephStreamGlonass << line;
[537]402
403 _ephStreamGlonass->flush();
[536]404 }
[533]405 }
406 }
[516]407}
408
[535]409// Print One GPS Ephemeris
[516]410////////////////////////////////////////////////////////////////////////////
[600]411void bncApp::printGPSEph(gpsephemeris* ep, bool printFile) {
[519]412
[941]413 QString lineV2;
414 QString lineV3;
[533]415
[590]416 struct converttimeinfo cti;
417 converttime(&cti, ep->GPSweek, ep->TOC);
[941]418
419 lineV3.sprintf("G%02d %04d %02d %02d %02d %02d %02d %18.11e %18.11e %18.11e\n",
[589]420 ep->satellite, cti.year, cti.month, cti.day, cti.hour,
421 cti.minute, cti.second, ep->clock_bias, ep->clock_drift,
422 ep->clock_driftrate);
[941]423
424 lineV2.sprintf("%02d %02d %02d %02d %02d %02d%5.1f %18.11e %18.11e %18.11e\n",
[590]425 ep->satellite, cti.year%100, cti.month, cti.day, cti.hour,
426 cti.minute, (double) cti.second, ep->clock_bias,
427 ep->clock_drift, ep->clock_driftrate);
[520]428
[941]429 QString line;
430 QByteArray allLines;
431
[894]432 line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", (double)ep->IODE,
[590]433 ep->Crs, ep->Delta_n, ep->M0);
434 allLines += line;
435
[894]436 line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->Cuc,
[590]437 ep->e, ep->Cus, ep->sqrt_A);
438 allLines += line;
[520]439
[894]440 line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n",
[590]441 (double) ep->TOE, ep->Cic, ep->OMEGA0, ep->Cis);
442 allLines += line;
443
[894]444 line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->i0,
[590]445 ep->Crc, ep->omega, ep->OMEGADOT);
446 allLines += line;
[520]447
[590]448 double dd = 0;
449 unsigned long ii = ep->flags;
450 if(ii & GPSEPHF_L2CACODE)
451 dd += 2.0;
452 if(ii & GPSEPHF_L2PCODE)
453 dd += 1.0;
[894]454 line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->IDOT, dd,
[590]455 (double) ep->GPSweek, ii & GPSEPHF_L2PCODEDATA ? 1.0 : 0.0);
456 allLines += line;
[520]457
[590]458 if(ep->URAindex <= 6) /* URA index */
459 dd = ceil(10.0*pow(2.0, 1.0+((double)ep->URAindex)/2.0))/10.0;
460 else
461 dd = ceil(10.0*pow(2.0, ((double)ep->URAindex)/2.0))/10.0;
[894]462 line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", dd,
[590]463 ((double) ep->SVhealth), ep->TGD, ((double) ep->IODC));
464 allLines += line;
[519]465
[894]466 line.sprintf(" %18.11e %18.11e\n", ((double)ep->TOW), 0.0);
[590]467 allLines += line;
[519]468
[943]469 printOutput(printFile, _ephStreamGPS, lineV2, lineV3, allLines);
[516]470}
471
[535]472// Print One Glonass Ephemeris
[516]473////////////////////////////////////////////////////////////////////////////
[600]474void bncApp::printGlonassEph(glonassephemeris* ep, bool printFile) {
[523]475
[590]476 int ww = ep->GPSWeek;
477 int tow = ep->GPSTOW;
478 struct converttimeinfo cti;
[523]479
[901]480 updatetime(&ww, &tow, ep->tb*1000, 0);
[590]481 converttime(&cti, ww, tow);
[525]482
[885]483 int tk = ep->tk-3*60*60;
484 if (tk < 0) {
485 tk += 86400;
[590]486 }
[525]487
[941]488 QString lineV2;
489 QString lineV3;
490
491 lineV3.sprintf("R%02d %04d %02d %02d %02d %02d %02d %18.11e %18.11e %18.11e\n",
[590]492 ep->almanac_number, cti.year, cti.month, cti.day, cti.hour,
[885]493 cti.minute, cti.second, -ep->tau, ep->gamma, (double) tk);
[941]494
495 lineV2.sprintf("%02d %02d %02d %02d %02d %02d%5.1f %18.11e %18.11e %18.11e\n",
[590]496 ep->almanac_number, cti.year%100, cti.month, cti.day,
497 cti.hour, cti.minute, (double) cti.second, -ep->tau,
[885]498 ep->gamma, (double) tk);
[590]499
[941]500 QString line;
501 QByteArray allLines;
502
[894]503 line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->x_pos,
[590]504 ep->x_velocity, ep->x_acceleration,
505 (ep->flags & GLOEPHF_UNHEALTHY) ? 1.0 : 0.0);
506 allLines += line;
507
[894]508 line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->y_pos,
[590]509 ep->y_velocity, ep->y_acceleration,
510 (double) ep->frequency_number);
511 allLines += line;
512
[894]513 line.sprintf(" %18.11e %18.11e %18.11e %18.11e\n", ep->z_pos,
[590]514 ep->z_velocity, ep->z_acceleration, (double) ep->E);
515 allLines += line;
[525]516
[943]517 printOutput(printFile, _ephStreamGlonass, lineV2, lineV3, allLines);
[941]518}
519
520// Output
521////////////////////////////////////////////////////////////////////////////
[943]522void bncApp::printOutput(bool printFile, QTextStream* stream,
523 const QString& lineV2,
[941]524 const QString& lineV3,
525 const QByteArray& allLines) {
[590]526 // Output into file
527 // ----------------
[943]528 if (printFile && stream) {
[941]529 if (_rinexVers == 2) {
[943]530 *stream << lineV2.toAscii();
[941]531 }
532 else {
[943]533 *stream << lineV3.toAscii();
[941]534 }
[943]535 *stream << allLines;
536 stream->flush();
[517]537 }
[590]538
539 // Output into the socket
540 // ----------------------
541 if (_sockets) {
[642]542 QMutableListIterator<QTcpSocket*> is(*_sockets);
[590]543 while (is.hasNext()) {
544 QTcpSocket* sock = is.next();
545 if (sock->state() == QAbstractSocket::ConnectedState) {
[941]546 if (sock->write(lineV3.toAscii()) == -1 ||
547 sock->write(allLines) == -1) {
[642]548 delete sock;
549 is.remove();
550 }
[590]551 }
[642]552 else if (sock->state() != QAbstractSocket::ConnectingState) {
553 delete sock;
554 is.remove();
555 }
[590]556 }
557 }
[516]558}
[589]559
[591]560// Set Port Number
561////////////////////////////////////////////////////////////////////////////
562void bncApp::setPort(int port) {
563 _port = port;
564 if (_port != 0) {
[942]565 delete _server;
[591]566 _server = new QTcpServer;
567 _server->listen(QHostAddress::Any, _port);
568 connect(_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
[942]569 delete _sockets;
[591]570 _sockets = new QList<QTcpSocket*>;
571 }
572}
573
[937]574// Set Port Number
575////////////////////////////////////////////////////////////////////////////
576void bncApp::setPortCorr(int port) {
577 _portCorr = port;
578 if (_portCorr != 0) {
[942]579 delete _serverCorr;
[937]580 _serverCorr = new QTcpServer;
581 _serverCorr->listen(QHostAddress::Any, _portCorr);
582 connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
[942]583 delete _socketsCorr;
[937]584 _socketsCorr = new QList<QTcpSocket*>;
585 }
586}
587
[589]588// New Connection
589////////////////////////////////////////////////////////////////////////////
590void bncApp::slotNewConnection() {
591 _sockets->push_back( _server->nextPendingConnection() );
592}
593
[937]594// New Connection
595////////////////////////////////////////////////////////////////////////////
596void bncApp::slotNewConnectionCorr() {
597 _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
598}
599
[621]600//
601////////////////////////////////////////////////////////////////////////////
602void bncApp::slotQuit() {
603 cout << "bncApp::slotQuit" << endl;
604 delete _caster;
605 quit();
606}
607
[936]608//
609////////////////////////////////////////////////////////////////////////////
[974]610void bncApp::slotNewCorrLine(QString line, QString staID, long coTime) {
611
612 QMutexLocker locker(&_mutex);
613
614 if (!_socketsCorr) {
615 return;
616 }
617
618 // First time, set the _lastDumpSec immediately
619 // --------------------------------------------
620 if (_lastDumpCoSec == 0) {
621 _lastDumpCoSec = coTime - 1;
622 }
623
[975]624 // An old correction - throw it away
625 // ---------------------------------
626 if (coTime <= _lastDumpCoSec) {
[990]627 QString line = "old correction: " + staID +
628 QString().sprintf(" age %ld",
629 _lastDumpCoSec - coTime + _waitCoTime);
[991]630 messagePrivate(line.toAscii());
[975]631 return;
632 }
633
634 _corrs->insert(coTime, QString(line + " " + staID));
635
[976]636 // Dump Corrections
637 // ----------------
638 if (coTime - _waitCoTime > _lastDumpCoSec) {
639 dumpCorrs(_lastDumpCoSec + 1, coTime - _waitCoTime);
640 _lastDumpCoSec = coTime - _waitCoTime;
641 }
642}
643
644// Dump Complete Correction Epochs
645////////////////////////////////////////////////////////////////////////////
646void bncApp::dumpCorrs(long minTime, long maxTime) {
647
648 for (long sec = minTime; sec <= maxTime; sec++) {
649 QList<QString> allCorrs = _corrs->values(sec);
650 QListIterator<QString> it(allCorrs);
651 while (it.hasNext()) {
652 QString corrLine = it.next() + "\n";
653
654 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
655 while (is.hasNext()) {
656 QTcpSocket* sock = is.next();
657 if (sock->state() == QAbstractSocket::ConnectedState) {
658 if (sock->write(corrLine.toAscii()) == -1) {
659 delete sock;
660 is.remove();
661 }
662 }
663 else if (sock->state() != QAbstractSocket::ConnectingState) {
664 delete sock;
665 is.remove();
666 }
[937]667 }
668 }
[976]669 _corrs->remove(sec);
[937]670 }
[936]671}
Note: See TracBrowser for help on using the repository browser.