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

Last change on this file since 1049 was 1044, checked in by zdenek, 16 years ago

Zdenek Lukes: a) added logic for RTCM 2.3 messages 20/21 decoding

b) added logic for cycle slip flags (slip counters or lock time indicators) handling

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 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
[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
[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() {
[1029]606 cout << "bncApp::slotQuit" << endl;
[621]607 delete _caster;
608 quit();
609}
610
[936]611//
612////////////////////////////////////////////////////////////////////////////
[974]613void bncApp::slotNewCorrLine(QString line, QString staID, long coTime) {
614
615 QMutexLocker locker(&_mutex);
616
617 if (!_socketsCorr) {
618 return;
619 }
620
[995]621 QSettings settings;
622 _waitCoTime = settings.value("corrTime").toInt();
623 if (_waitCoTime < 1) {
624 _waitCoTime = 1;
625 }
626
[974]627 // First time, set the _lastDumpSec immediately
628 // --------------------------------------------
629 if (_lastDumpCoSec == 0) {
630 _lastDumpCoSec = coTime - 1;
631 }
632
[975]633 // An old correction - throw it away
634 // ---------------------------------
635 if (coTime <= _lastDumpCoSec) {
[1035]636 QString line = staID + ": Correction overaged by " +
637 QString().sprintf(" %ld sec",
[990]638 _lastDumpCoSec - coTime + _waitCoTime);
[991]639 messagePrivate(line.toAscii());
[994]640 emit( newMessage(line.toAscii()) );
[975]641 return;
642 }
643
644 _corrs->insert(coTime, QString(line + " " + staID));
645
[976]646 // Dump Corrections
647 // ----------------
648 if (coTime - _waitCoTime > _lastDumpCoSec) {
649 dumpCorrs(_lastDumpCoSec + 1, coTime - _waitCoTime);
650 _lastDumpCoSec = coTime - _waitCoTime;
651 }
652}
653
654// Dump Complete Correction Epochs
655////////////////////////////////////////////////////////////////////////////
656void bncApp::dumpCorrs(long minTime, long maxTime) {
657
658 for (long sec = minTime; sec <= maxTime; sec++) {
659 QList<QString> allCorrs = _corrs->values(sec);
660 QListIterator<QString> it(allCorrs);
661 while (it.hasNext()) {
662 QString corrLine = it.next() + "\n";
663
664 QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
665 while (is.hasNext()) {
666 QTcpSocket* sock = is.next();
667 if (sock->state() == QAbstractSocket::ConnectedState) {
668 if (sock->write(corrLine.toAscii()) == -1) {
669 delete sock;
670 is.remove();
671 }
672 }
673 else if (sock->state() != QAbstractSocket::ConnectingState) {
674 delete sock;
675 is.remove();
676 }
[937]677 }
678 }
[976]679 _corrs->remove(sec);
[937]680 }
[936]681}
Note: See TracBrowser for help on using the repository browser.