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

Last change on this file since 1629 was 1600, checked in by weber, 16 years ago

* empty log message *

File size: 5.2 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"
[1155]50#include "bncapp.h"
[83]51
[124]52using namespace std;
53
[1381]54//
55////////////////////////////////////////////////////////////////////////////
[83]56void expandEnvVar(QString& str) {
57
58 QRegExp rx("(\\$\\{.+\\})");
59
60 if (rx.indexIn(str) != -1) {
61 QStringListIterator it(rx.capturedTexts());
62 if (it.hasNext()) {
63 QString rxStr = it.next();
64 QString envVar = rxStr.mid(2,rxStr.length()-3);
65 str.replace(rxStr, qgetenv(envVar.toAscii()));
66 }
67 }
68
69}
[124]70
[1381]71//
72////////////////////////////////////////////////////////////////////////////
[124]73QDateTime dateAndTimeFromGPSweek(int GPSWeek, double GPSWeeks) {
74
75 static const QDate zeroEpoch(1980, 1, 6);
76
77 QDate date(zeroEpoch);
78 QTime time(0,0,0,0);
79
80 int weekDays = int(GPSWeeks) / 86400;
81 date = date.addDays( GPSWeek * 7 + weekDays );
82 time = time.addMSecs( int( (GPSWeeks - 86400 * weekDays) * 1e3 ) );
83
84 return QDateTime(date,time);
85}
[210]86
[1381]87//
88////////////////////////////////////////////////////////////////////////////
[218]89void currentGPSWeeks(int& week, double& sec) {
[210]90
[1155]91 QDateTime currDateTime;
92 int leapsecond = 0;
93
94 if ( ((bncApp*) qApp)->_currentDateAndTimeGPS ) {
95 currDateTime = *(((bncApp*) qApp)->_currentDateAndTimeGPS);
96 }
97 else {
98 currDateTime = QDateTime::currentDateTime().toUTC();
99 if (currDateTime.date().year() >= 2009) {
100 leapsecond = 15;
101 }
102 else {
103 leapsecond = 14;
104 }
105 }
106
[271]107 QDate currDate = currDateTime.date();
108 QTime currTime = currDateTime.time();
[210]109
[1036]110 week = int( (double(currDate.toJulianDay()) - 2444244.5) / 7 );
111
112 sec = (currDate.dayOfWeek() % 7) * 24.0 * 3600.0 +
113 currTime.hour() * 3600.0 +
114 currTime.minute() * 60.0 +
115 currTime.second() +
116 currTime.msec() / 1000.0 +
117 leapsecond;
118}
[1154]119
[1381]120//
121////////////////////////////////////////////////////////////////////////////
[1154]122QDateTime currentDateAndTimeGPS() {
123 int GPSWeek;
124 double GPSWeeks;
125 currentGPSWeeks(GPSWeek, GPSWeeks);
126 return dateAndTimeFromGPSweek(GPSWeek, GPSWeeks);
127}
128
[1381]129//
130////////////////////////////////////////////////////////////////////////////
[1595]131QByteArray ggaString(const QByteArray& latitude,
132 const QByteArray& longitude,
133 const QByteArray& height) {
[1381]134
135 double lat = strtod(latitude,NULL);
136 double lon = strtod(longitude,NULL);
[1595]137 double hei = strtod(height,NULL);
[1381]138
139 const char* flagN="N";
140 const char* flagE="E";
141 if (lon >180.) {lon=(lon-360.)*(-1.); flagE="W";}
142 if ((lon < 0.) && (lon >= -180.)) {lon=lon*(-1.); flagE="W";}
143 if (lon < -180.) {lon=(lon+360.); flagE="E";}
144 if (lat < 0.) {lat=lat*(-1.); flagN="S";}
145 QTime ttime(QDateTime::currentDateTime().toUTC().time());
146 int lat_deg = (int)lat;
147 double lat_min=(lat-lat_deg)*60.;
148 int lon_deg = (int)lon;
149 double lon_min=(lon-lon_deg)*60.;
150 int hh = 0 , mm = 0;
151 double ss = 0.0;
152 hh=ttime.hour();
153 mm=ttime.minute();
154 ss=(double)ttime.second()+0.001*ttime.msec();
155 QString gga;
[1506]156 gga += "GPGGA,";
[1381]157 gga += QString("%1%2%3,").arg((int)hh, 2, 10, QLatin1Char('0')).arg((int)mm, 2, 10, QLatin1Char('0')).arg((int)ss, 2, 10, QLatin1Char('0'));
158 gga += QString("%1%2,").arg((int)lat_deg,2, 10, QLatin1Char('0')).arg(lat_min, 7, 'f', 4, QLatin1Char('0'));
159 gga += flagN;
160 gga += QString(",%1%2,").arg((int)lon_deg,3, 10, QLatin1Char('0')).arg(lon_min, 7, 'f', 4, QLatin1Char('0'));
[1595]161 gga += flagE + QString(",1,05,1.00");
[1599]162 gga += QString(",%1,").arg(hei, 2, 'f', 1);
[1595]163 gga += QString("M,10.000,M,,");
[1381]164 int xori;
165 char XOR = 0;
166 char *Buff =gga.toAscii().data();
167 int iLen = strlen(Buff);
168 for (xori = 0; xori < iLen; xori++) {
169 XOR ^= (char)Buff[xori];
170 }
[1506]171 gga = "$" + gga + QString("*%1").arg(XOR, 2, 16, QLatin1Char('0'));
[1381]172
[1387]173 return gga.toAscii();
[1381]174}
Note: See TracBrowser for help on using the repository browser.