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

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