source: ntrip/trunk/BNS/bnsutils.cpp@ 780

Last change on this file since 780 was 775, checked in by mervart, 17 years ago

* empty log message *

File size: 2.5 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Server
3 * -------------------------------------------------------------------------
4 *
5 * Class: bncutils
6 *
7 * Purpose: Auxiliary Functions
8 *
9 * Author: L. Mervart
10 *
11 * Created: 08-Apr-2008
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include <iostream>
18#include <ctime>
19#include <math.h>
20
21#include <QRegExp>
22#include <QStringList>
23#include <QDateTime>
24
25#include "bnsutils.h"
26
27using namespace std;
28
29//
30////////////////////////////////////////////////////////////////////////////
31void expandEnvVar(QString& str) {
32
33 QRegExp rx("(\\$\\{.+\\})");
34
35 if (rx.indexIn(str) != -1) {
36 QStringListIterator it(rx.capturedTexts());
37 if (it.hasNext()) {
38 QString rxStr = it.next();
39 QString envVar = rxStr.mid(2,rxStr.length()-3);
40 str.replace(rxStr, qgetenv(envVar.toAscii()));
41 }
42 }
43
44}
45
46//
47////////////////////////////////////////////////////////////////////////////
48QDateTime dateAndTimeFromGPSweek(int GPSWeek, double GPSWeeks) {
49
50 static const QDate zeroEpoch(1980, 1, 6);
51
52 QDate date(zeroEpoch);
53 QTime time(0,0,0,0);
54
55 int weekDays = int(GPSWeeks) / 86400;
56 date = date.addDays( GPSWeek * 7 + weekDays );
57 time = time.addMSecs( int( (GPSWeeks - 86400 * weekDays) * 1e3 ) );
58
59 return QDateTime(date,time);
60}
61
62//
63////////////////////////////////////////////////////////////////////////////
64void GPSweekFromDateAndTime(const QDateTime& dateTime,
65 int& GPSWeek, double& GPSWeeks) {
66
67 static const QDateTime zeroEpoch(QDate(1980, 1, 6));
68
69 GPSWeek = zeroEpoch.daysTo(dateTime) / 7;
70
71 int weekDay = dateTime.date().dayOfWeek() + 1; // Qt: Monday = 1
72 if (weekDay > 7) weekDay = 1;
73
74 GPSWeeks = (weekDay - 1) * 86400.0
75 - dateTime.time().msecsTo(QTime()) / 1e3;
76}
77
78//
79////////////////////////////////////////////////////////////////////////////
80void currentGPSWeeks(int& week, double& sec) {
81
82 QDateTime currDateTime = QDateTime::currentDateTime().toUTC();
83 QDate currDate = currDateTime.date();
84 QTime currTime = currDateTime.time();
85
86 week = int( (double(currDate.toJulianDay()) - 2444244.5) / 7 );
87
88 sec = (currDate.dayOfWeek() % 7) * 24.0 * 3600.0 +
89 currTime.hour() * 3600.0 +
90 currTime.minute() * 60.0 +
91 currTime.second() +
92 currTime.msec() / 1000.0;
93}
Note: See TracBrowser for help on using the repository browser.