source: ntrip/trunk/BNC/bncutils.cpp@ 1148

Last change on this file since 1148 was 1036, checked in by weber, 16 years ago

* empty log message *

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