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

Last change on this file since 2405 was 2405, checked in by weber, 14 years ago

* empty log message *

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