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

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