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

Last change on this file since 340 was 280, checked in by mervart, 18 years ago

* empty log message *

File size: 2.7 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters,
3// written by Leos Mervart.
4//
5// Copyright (C) 2006
6// German Federal Agency for Cartography and Geodesy (BKG)
7// http://www.bkg.bund.de
8// Czech Technical University Prague, Department of Advanced Geodesy
9// http://www.fsv.cvut.cz
10//
11// Email: euref-ip@bkg.bund.de
12//
13// This program is free software; you can redistribute it and/or
14// modify it under the terms of the GNU General Public License
15// as published by the Free Software Foundation, version 2.
16//
17// This program is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU General Public License for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with this program; if not, write to the Free Software
24// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26/* -------------------------------------------------------------------------
27 * BKG NTRIP Client
28 * -------------------------------------------------------------------------
29 *
30 * Class: bncutils
31 *
32 * Purpose: Auxiliary Functions
33 *
34 * Author: L. Mervart
35 *
36 * Created: 30-Aug-2006
37 *
38 * Changes:
39 *
40 * -----------------------------------------------------------------------*/
41
42#include <iostream>
43#include <ctime>
44#include <math.h>
45
46#include <QRegExp>
47#include <QStringList>
48#include <QDateTime>
49
50#include "bncutils.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 = QDateTime::currentDateTime().toUTC();
86 QDate currDate = currDateTime.date();
87 QTime currTime = currDateTime.time();
88
89 week = int( (double(currDate.toJulianDay()) - 2444244.5) / 7 );
90
91 sec = (currDate.dayOfWeek() % 7) * 24.0 * 3600.0 +
92 currTime.hour() * 3600.0 +
93 currTime.minute() * 60.0 +
94 currTime.second() +
95 currTime.msec() / 1000.0;
96}
Note: See TracBrowser for help on using the repository browser.