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

Last change on this file since 937 was 464, checked in by weber, 17 years ago

* empty log message *

File size: 2.7 KB
RevLine 
[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"
50
[124]51using namespace std;
52
[83]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}
[124]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}
[210]81
[218]82void currentGPSWeeks(int& week, double& sec) {
[210]83
[271]84 QDateTime currDateTime = QDateTime::currentDateTime().toUTC();
85 QDate currDate = currDateTime.date();
86 QTime currTime = currDateTime.time();
[210]87
[271]88 week = int( (double(currDate.toJulianDay()) - 2444244.5) / 7 );
[218]89
[271]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;
[210]95}
Note: See TracBrowser for help on using the repository browser.