[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.
|
---|
[83] | 24 |
|
---|
| 25 | /* -------------------------------------------------------------------------
|
---|
[93] | 26 | * BKG NTRIP Client
|
---|
[83] | 27 | * -------------------------------------------------------------------------
|
---|
| 28 | *
|
---|
| 29 | * Class: bncutils
|
---|
| 30 | *
|
---|
| 31 | * Purpose: Auxiliary Functions
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 30-Aug-2006
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
[124] | 41 | #include <iostream>
|
---|
[218] | 42 | #include <ctime>
|
---|
[221] | 43 | #include <math.h>
|
---|
[124] | 44 |
|
---|
[83] | 45 | #include <QRegExp>
|
---|
| 46 | #include <QStringList>
|
---|
[271] | 47 | #include <QDateTime>
|
---|
[83] | 48 |
|
---|
| 49 | #include "bncutils.h"
|
---|
[1155] | 50 | #include "bncapp.h"
|
---|
[83] | 51 |
|
---|
[124] | 52 | using namespace std;
|
---|
| 53 |
|
---|
[83] | 54 | void expandEnvVar(QString& str) {
|
---|
| 55 |
|
---|
| 56 | QRegExp rx("(\\$\\{.+\\})");
|
---|
| 57 |
|
---|
| 58 | if (rx.indexIn(str) != -1) {
|
---|
| 59 | QStringListIterator it(rx.capturedTexts());
|
---|
| 60 | if (it.hasNext()) {
|
---|
| 61 | QString rxStr = it.next();
|
---|
| 62 | QString envVar = rxStr.mid(2,rxStr.length()-3);
|
---|
| 63 | str.replace(rxStr, qgetenv(envVar.toAscii()));
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | }
|
---|
[124] | 68 |
|
---|
| 69 | QDateTime dateAndTimeFromGPSweek(int GPSWeek, double GPSWeeks) {
|
---|
| 70 |
|
---|
| 71 | static const QDate zeroEpoch(1980, 1, 6);
|
---|
| 72 |
|
---|
| 73 | QDate date(zeroEpoch);
|
---|
| 74 | QTime time(0,0,0,0);
|
---|
| 75 |
|
---|
| 76 | int weekDays = int(GPSWeeks) / 86400;
|
---|
| 77 | date = date.addDays( GPSWeek * 7 + weekDays );
|
---|
| 78 | time = time.addMSecs( int( (GPSWeeks - 86400 * weekDays) * 1e3 ) );
|
---|
| 79 |
|
---|
| 80 | return QDateTime(date,time);
|
---|
| 81 | }
|
---|
[210] | 82 |
|
---|
[218] | 83 | void currentGPSWeeks(int& week, double& sec) {
|
---|
[210] | 84 |
|
---|
[1155] | 85 | QDateTime currDateTime;
|
---|
| 86 | int leapsecond = 0;
|
---|
| 87 |
|
---|
| 88 | if ( ((bncApp*) qApp)->_currentDateAndTimeGPS ) {
|
---|
| 89 | currDateTime = *(((bncApp*) qApp)->_currentDateAndTimeGPS);
|
---|
| 90 | }
|
---|
| 91 | else {
|
---|
| 92 | currDateTime = QDateTime::currentDateTime().toUTC();
|
---|
| 93 | if (currDateTime.date().year() >= 2009) {
|
---|
| 94 | leapsecond = 15;
|
---|
| 95 | }
|
---|
| 96 | else {
|
---|
| 97 | leapsecond = 14;
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[271] | 101 | QDate currDate = currDateTime.date();
|
---|
| 102 | QTime currTime = currDateTime.time();
|
---|
[210] | 103 |
|
---|
[1036] | 104 | week = int( (double(currDate.toJulianDay()) - 2444244.5) / 7 );
|
---|
| 105 |
|
---|
| 106 | sec = (currDate.dayOfWeek() % 7) * 24.0 * 3600.0 +
|
---|
| 107 | currTime.hour() * 3600.0 +
|
---|
| 108 | currTime.minute() * 60.0 +
|
---|
| 109 | currTime.second() +
|
---|
| 110 | currTime.msec() / 1000.0 +
|
---|
| 111 | leapsecond;
|
---|
| 112 | }
|
---|
[1154] | 113 |
|
---|
| 114 | QDateTime currentDateAndTimeGPS() {
|
---|
| 115 | int GPSWeek;
|
---|
| 116 | double GPSWeeks;
|
---|
| 117 | currentGPSWeeks(GPSWeek, GPSWeeks);
|
---|
| 118 | return dateAndTimeFromGPSweek(GPSWeek, GPSWeeks);
|
---|
| 119 | }
|
---|
| 120 |
|
---|