Diffstat (limited to 'noncore/net/wellenreiter/gui/gps.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/wellenreiter/gui/gps.cpp | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/noncore/net/wellenreiter/gui/gps.cpp b/noncore/net/wellenreiter/gui/gps.cpp index 288afee..31f95ce 100644 --- a/noncore/net/wellenreiter/gui/gps.cpp +++ b/noncore/net/wellenreiter/gui/gps.cpp | |||
@@ -5,28 +5,32 @@ | |||
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | 15 | ||
16 | #include "gps.h" | 16 | #include "gps.h" |
17 | #include <unistd.h> | ||
18 | 17 | ||
18 | /* QT */ | ||
19 | #include <qtextstream.h> | 19 | #include <qtextstream.h> |
20 | 20 | ||
21 | /* STD */ | ||
22 | #include <stdlib.h> | ||
23 | #include <unistd.h> | ||
24 | |||
21 | GPS::GPS( QObject* parent, const char * name ) | 25 | GPS::GPS( QObject* parent, const char * name ) |
22 | :QObject( parent, name ) | 26 | :QObject( parent, name ) |
23 | { | 27 | { |
24 | qDebug( "GPS::GPS()" ); | 28 | qDebug( "GPS::GPS()" ); |
25 | _socket = new QSocket( this, "gpsd commsock" ); | 29 | _socket = new QSocket( this, "gpsd commsock" ); |
26 | } | 30 | } |
27 | 31 | ||
28 | 32 | ||
29 | GPS::~GPS() | 33 | GPS::~GPS() |
30 | { | 34 | { |
31 | qDebug( "GPS::~GPS()" ); | 35 | qDebug( "GPS::~GPS()" ); |
32 | } | 36 | } |
@@ -55,15 +59,73 @@ GpsLocation GPS::position() const | |||
55 | QString str; | 59 | QString str; |
56 | stream.readRawBytes( &buf[0], 7 ); | 60 | stream.readRawBytes( &buf[0], 7 ); |
57 | float lat = -111.111; | 61 | float lat = -111.111; |
58 | stream >> lat; | 62 | stream >> lat; |
59 | stream.skipWhiteSpace(); | 63 | stream.skipWhiteSpace(); |
60 | float lon = -111.111; | 64 | float lon = -111.111; |
61 | stream >> lon; | 65 | stream >> lon; |
62 | stream.readRawBytes( &buf[0], 200 ); // read and discard the stuff until EOF | 66 | stream.readRawBytes( &buf[0], 200 ); // read and discard the stuff until EOF |
63 | 67 | ||
64 | return GpsLocation( lat, lon ); | 68 | return GpsLocation( lat, lon ); |
65 | } | 69 | } |
66 | } | 70 | } |
67 | return GpsLocation( -1.0, -1.0 ); | 71 | return GpsLocation( -111.111, -111.111 ); |
68 | } | 72 | } |
69 | 73 | ||
74 | |||
75 | QString GpsLocation::dmsPosition() const | ||
76 | { | ||
77 | if ( _latitude == -111.111 || _longitude == -111.11 ) | ||
78 | return "N/A"; | ||
79 | if ( _latitude == 0.0 && _longitude == 0.0 ) | ||
80 | return "NULL"; | ||
81 | |||
82 | /* compute latitude */ | ||
83 | |||
84 | QString dms = "N"; | ||
85 | if ( _latitude >= 0 ) dms.append( "+" ); | ||
86 | |||
87 | int trunc = int( _latitude ); | ||
88 | float rest = _latitude - trunc; | ||
89 | |||
90 | float minf = rest * 60; | ||
91 | int minutes = int( minf ); | ||
92 | |||
93 | rest = minf - minutes; | ||
94 | int seconds = int( rest * 60 ); | ||
95 | |||
96 | dms.append( QString::number( trunc ) ); | ||
97 | dms.append( "° " ); | ||
98 | dms.append( QString::number( ::abs( minutes ) ) ); | ||
99 | dms.append( "' " ); | ||
100 | dms.append( QString::number( ::abs( seconds ) ) ); | ||
101 | dms.append( "'' " ); | ||
102 | |||
103 | /* compute longitude */ | ||
104 | |||
105 | dms.append( " | W" ); | ||
106 | if ( _longitude > 0 ) dms.append( "+" ); | ||
107 | |||
108 | trunc = int( _longitude ); | ||
109 | rest = _longitude - trunc; | ||
110 | |||
111 | minf = rest * 60; | ||
112 | minutes = int( minf ); | ||
113 | |||
114 | rest = minf - minutes; | ||
115 | seconds = int( rest * 60 ); | ||
116 | |||
117 | dms.append( QString::number( trunc ) ); | ||
118 | dms.append( "° " ); | ||
119 | dms.append( QString::number( ::abs( minutes ) ) ); | ||
120 | dms.append( "' " ); | ||
121 | dms.append( QString::number( ::abs( seconds ) ) ); | ||
122 | dms.append( "'' " ); | ||
123 | |||
124 | return dms; | ||
125 | } | ||
126 | |||
127 | |||
128 | |||
129 | |||
130 | |||
131 | |||