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

Last change on this file since 2011 was 2011, checked in by mervart, 14 years ago

* empty log message *

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