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

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