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

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