[83] | 1 |
|
---|
| 2 | /* -------------------------------------------------------------------------
|
---|
[93] | 3 | * BKG NTRIP Client
|
---|
[83] | 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 |
|
---|
[124] | 18 | #include <iostream>
|
---|
[218] | 19 | #include <ctime>
|
---|
[124] | 20 |
|
---|
[83] | 21 | #include <QRegExp>
|
---|
| 22 | #include <QStringList>
|
---|
| 23 |
|
---|
| 24 | #include "bncutils.h"
|
---|
| 25 |
|
---|
[124] | 26 | using namespace std;
|
---|
| 27 |
|
---|
[83] | 28 | void expandEnvVar(QString& str) {
|
---|
| 29 |
|
---|
| 30 | QRegExp rx("(\\$\\{.+\\})");
|
---|
| 31 |
|
---|
| 32 | if (rx.indexIn(str) != -1) {
|
---|
| 33 | QStringListIterator it(rx.capturedTexts());
|
---|
| 34 | if (it.hasNext()) {
|
---|
| 35 | QString rxStr = it.next();
|
---|
| 36 | QString envVar = rxStr.mid(2,rxStr.length()-3);
|
---|
| 37 | str.replace(rxStr, qgetenv(envVar.toAscii()));
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | }
|
---|
[124] | 42 |
|
---|
| 43 | QDateTime dateAndTimeFromGPSweek(int GPSWeek, double GPSWeeks) {
|
---|
| 44 |
|
---|
| 45 | static const QDate zeroEpoch(1980, 1, 6);
|
---|
| 46 |
|
---|
| 47 | QDate date(zeroEpoch);
|
---|
| 48 | QTime time(0,0,0,0);
|
---|
| 49 |
|
---|
| 50 | int weekDays = int(GPSWeeks) / 86400;
|
---|
| 51 | date = date.addDays( GPSWeek * 7 + weekDays );
|
---|
| 52 | time = time.addMSecs( int( (GPSWeeks - 86400 * weekDays) * 1e3 ) );
|
---|
| 53 |
|
---|
| 54 | return QDateTime(date,time);
|
---|
| 55 | }
|
---|
[210] | 56 |
|
---|
[218] | 57 | double MJD(int year, int month, double day) {
|
---|
| 58 | if( month <= 2 ) {
|
---|
| 59 | year = year - 1;
|
---|
| 60 | month = month + 12;
|
---|
| 61 | }
|
---|
| 62 | int ii = year/100;
|
---|
| 63 | int kk = 2 - ii + ii/4;
|
---|
| 64 | double mjd = (365.25*year - fmod( 365.25*year, 1.0 )) - 679006.0
|
---|
| 65 | + floor( 30.6001*(month + 1) ) + day + kk;
|
---|
| 66 | return mjd;
|
---|
| 67 | }
|
---|
[210] | 68 |
|
---|
[218] | 69 | void MJD_GPSWeeks(double mjd, int& week, double& sec) {
|
---|
| 70 | double deltat = mjd - 44244.0 ;
|
---|
| 71 | week = (long) floor(deltat/7.0);
|
---|
| 72 | sec = (deltat - (week)*7.0)*86400.0;
|
---|
| 73 | }
|
---|
[210] | 74 |
|
---|
[218] | 75 | void currentGPSWeeks(int& week, double& sec) {
|
---|
[210] | 76 |
|
---|
[218] | 77 | time_t ltime;
|
---|
| 78 | struct tm *gmt;
|
---|
[210] | 79 |
|
---|
[218] | 80 | time(<ime);
|
---|
| 81 | gmt = gmtime(<ime);
|
---|
| 82 |
|
---|
| 83 | double dayFrac = (( gmt->tm_sec / 60.0
|
---|
| 84 | + gmt->tm_min ) / 60.0
|
---|
| 85 | + gmt->tm_hour ) / 24.0;
|
---|
| 86 |
|
---|
| 87 | double mjd = MJD(1900+gmt->tm_year, gmt->tm_mon+1, gmt->tm_mday+1+dayFrac);
|
---|
| 88 |
|
---|
| 89 | cout << 1900+gmt->tm_year << " " << gmt->tm_mon+1 << " " << gmt->tm_mday+1
|
---|
| 90 | << " " << gmt->tm_hour
|
---|
| 91 | << " " << gmt->tm_min
|
---|
| 92 | << " " << gmt->tm_sec << endl;
|
---|
| 93 |
|
---|
| 94 | MJD_GPSWeeks(mjd, week, sec);
|
---|
[210] | 95 | }
|
---|