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
@@ -1,69 +1,131 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
4** This file is part of Opie Environment. 4** This file is part of Opie Environment.
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
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}
27 31
28 32
29GPS::~GPS() 33GPS::~GPS()
30{ 34{
31 qDebug( "GPS::~GPS()" ); 35 qDebug( "GPS::~GPS()" );
32} 36}
33 37
34 38
35bool GPS::open( const QString& host, int port ) 39bool GPS::open( const QString& host, int port )
36{ 40{
37 _socket->connectToHost( host, port ); 41 _socket->connectToHost( host, port );
38} 42}
39 43
40 44
41GpsLocation GPS::position() const 45GpsLocation GPS::position() const
42{ 46{
43 char buf[256]; 47 char buf[256];
44 48
45 int result = _socket->writeBlock( "p\r\n", 3 ); 49 int result = _socket->writeBlock( "p\r\n", 3 );
46 _socket->flush(); 50 _socket->flush();
47 if ( result ) 51 if ( result )
48 { 52 {
49 int numAvail = _socket->bytesAvailable(); 53 int numAvail = _socket->bytesAvailable();
50 qDebug( "GPS write succeeded, %d bytes available for reading...", numAvail ); 54 qDebug( "GPS write succeeded, %d bytes available for reading...", numAvail );
51 if ( numAvail ) 55 if ( numAvail )
52 { 56 {
53 QTextStream stream( _socket ); 57 QTextStream stream( _socket );
54 58
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
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