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

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