1 |
|
---|
2 | /* -------------------------------------------------------------------------
|
---|
3 | * BKG NTRIP Client
|
---|
4 | * -------------------------------------------------------------------------
|
---|
5 | *
|
---|
6 | * Class: bncutils
|
---|
7 | *
|
---|
8 | * Purpose: Auxiliary Functions
|
---|
9 | *
|
---|
10 | * Author: L. Mervart
|
---|
11 | *
|
---|
12 | * Created: 30-Aug-2006
|
---|
13 | *
|
---|
14 | * Changes:
|
---|
15 | *
|
---|
16 | * -----------------------------------------------------------------------*/
|
---|
17 |
|
---|
18 | #include <iostream>
|
---|
19 | #include <ctime>
|
---|
20 | #include <math.h>
|
---|
21 |
|
---|
22 | #include <QRegExp>
|
---|
23 | #include <QStringList>
|
---|
24 | #include <QDateTime>
|
---|
25 |
|
---|
26 | #include "bncutils.h"
|
---|
27 |
|
---|
28 | using namespace std;
|
---|
29 |
|
---|
30 | void expandEnvVar(QString& str) {
|
---|
31 |
|
---|
32 | QRegExp rx("(\\$\\{.+\\})");
|
---|
33 |
|
---|
34 | if (rx.indexIn(str) != -1) {
|
---|
35 | QStringListIterator it(rx.capturedTexts());
|
---|
36 | if (it.hasNext()) {
|
---|
37 | QString rxStr = it.next();
|
---|
38 | QString envVar = rxStr.mid(2,rxStr.length()-3);
|
---|
39 | str.replace(rxStr, qgetenv(envVar.toAscii()));
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | }
|
---|
44 |
|
---|
45 | QDateTime dateAndTimeFromGPSweek(int GPSWeek, double GPSWeeks) {
|
---|
46 |
|
---|
47 | static const QDate zeroEpoch(1980, 1, 6);
|
---|
48 |
|
---|
49 | QDate date(zeroEpoch);
|
---|
50 | QTime time(0,0,0,0);
|
---|
51 |
|
---|
52 | int weekDays = int(GPSWeeks) / 86400;
|
---|
53 | date = date.addDays( GPSWeek * 7 + weekDays );
|
---|
54 | time = time.addMSecs( int( (GPSWeeks - 86400 * weekDays) * 1e3 ) );
|
---|
55 |
|
---|
56 | return QDateTime(date,time);
|
---|
57 | }
|
---|
58 |
|
---|
59 | void currentGPSWeeks(int& week, double& sec) {
|
---|
60 |
|
---|
61 | QDateTime currDateTime = QDateTime::currentDateTime().toUTC();
|
---|
62 | QDate currDate = currDateTime.date();
|
---|
63 | QTime currTime = currDateTime.time();
|
---|
64 |
|
---|
65 | week = int( (double(currDate.toJulianDay()) - 2444244.5) / 7 );
|
---|
66 |
|
---|
67 | sec = (currDate.dayOfWeek() % 7) * 24.0 * 3600.0 +
|
---|
68 | currTime.hour() * 3600.0 +
|
---|
69 | currTime.minute() * 60.0 +
|
---|
70 | currTime.second() +
|
---|
71 | currTime.msec() / 1000.0;
|
---|
72 | }
|
---|