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

Last change on this file since 1229 was 1155, checked in by mervart, 16 years ago

* empty log message *

File size: 3.2 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#include "bncapp.h"
51
52using namespace std;
53
54void 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}
68
69QDateTime 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}
82
83void currentGPSWeeks(int& week, double& sec) {
84
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
101 QDate currDate = currDateTime.date();
102 QTime currTime = currDateTime.time();
103
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}
113
114QDateTime currentDateAndTimeGPS() {
115 int GPSWeek;
116 double GPSWeeks;
117 currentGPSWeeks(GPSWeek, GPSWeeks);
118 return dateAndTimeFromGPSweek(GPSWeek, GPSWeeks);
119}
120
Note: See TracBrowser for help on using the repository browser.