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

Last change on this file since 1027 was 1024, checked in by zdenek, 16 years ago

Zdenek Lukes: added logic for decoding of message 20/21 from RTCM 2.3 streams

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