summaryrefslogtreecommitdiff
path: root/noncore/net/wellenreiter/gui/gps.cpp
Unidiff
Diffstat (limited to 'noncore/net/wellenreiter/gui/gps.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/wellenreiter/gui/gps.cpp66
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
@@ -11,16 +11,20 @@
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
21GPS::GPS( QObject* parent, const char * name ) 25GPS::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}
@@ -61,9 +65,67 @@ GpsLocation GPS::position() const
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
75QString 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