Diffstat (limited to 'noncore/net/wellenreiter/gui/gps.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/wellenreiter/gui/gps.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/noncore/net/wellenreiter/gui/gps.cpp b/noncore/net/wellenreiter/gui/gps.cpp index a47b4ec..bd91e35 100644 --- a/noncore/net/wellenreiter/gui/gps.cpp +++ b/noncore/net/wellenreiter/gui/gps.cpp | |||
@@ -1,112 +1,116 @@ | |||
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 Wellenreiter II. | 4 | ** This file is part of Wellenreiter II. |
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 | 17 | ||
18 | /* OPIE */ | ||
19 | #include <opie2/odebug.h> | ||
20 | using namespace Opie::Core; | ||
21 | |||
18 | /* QT */ | 22 | /* QT */ |
19 | #include <qtextstream.h> | 23 | #include <qtextstream.h> |
20 | 24 | ||
21 | /* STD */ | 25 | /* STD */ |
22 | #include <stdlib.h> | 26 | #include <stdlib.h> |
23 | #include <unistd.h> | 27 | #include <unistd.h> |
24 | 28 | ||
25 | GPS::GPS( QObject* parent, const char * name ) | 29 | GPS::GPS( QObject* parent, const char * name ) |
26 | :QObject( parent, name ) | 30 | :QObject( parent, name ) |
27 | { | 31 | { |
28 | qDebug( "GPS::GPS()" ); | 32 | odebug << "GPS::GPS()" << oendl; |
29 | _socket = new QSocket( this, "gpsd commsock" ); | 33 | _socket = new QSocket( this, "gpsd commsock" ); |
30 | } | 34 | } |
31 | 35 | ||
32 | 36 | ||
33 | GPS::~GPS() | 37 | GPS::~GPS() |
34 | { | 38 | { |
35 | qDebug( "GPS::~GPS()" ); | 39 | odebug << "GPS::~GPS()" << oendl; |
36 | } | 40 | } |
37 | 41 | ||
38 | 42 | ||
39 | bool GPS::open( const QString& host, int port ) | 43 | bool GPS::open( const QString& host, int port ) |
40 | { | 44 | { |
41 | _socket->connectToHost( host, port ); | 45 | _socket->connectToHost( host, port ); |
42 | } | 46 | } |
43 | 47 | ||
44 | 48 | ||
45 | GpsLocation GPS::position() const | 49 | GpsLocation GPS::position() const |
46 | { | 50 | { |
47 | char buf[256]; | 51 | char buf[256]; |
48 | double lat = -111.0; | 52 | double lat = -111.0; |
49 | double lon = -111.0; | 53 | double lon = -111.0; |
50 | 54 | ||
51 | int result = _socket->writeBlock( "p\r\n", 3 ); | 55 | int result = _socket->writeBlock( "p\r\n", 3 ); |
52 | _socket->flush(); | 56 | _socket->flush(); |
53 | if ( result ) | 57 | if ( result ) |
54 | { | 58 | { |
55 | int numAvail = _socket->bytesAvailable(); | 59 | int numAvail = _socket->bytesAvailable(); |
56 | qDebug( "GPS write succeeded, %d bytes available for reading...", numAvail ); | 60 | odebug << "GPS write succeeded, " << numAvail << " bytes available for reading..." << oendl; |
57 | if ( numAvail ) | 61 | if ( numAvail ) |
58 | { | 62 | { |
59 | int numRead = _socket->readBlock( &buf[0], sizeof buf ); | 63 | int numRead = _socket->readBlock( &buf[0], sizeof buf ); |
60 | int numScan = ::sscanf( &buf[0], "GPSD,P=%lg %lg", &lat, &lon); | 64 | int numScan = ::sscanf( &buf[0], "GPSD,P=%lg %lg", &lat, &lon); |
61 | 65 | ||
62 | if ( numRead < 7 || numScan != 2 ) | 66 | if ( numRead < 7 || numScan != 2 ) |
63 | { | 67 | { |
64 | qDebug( "GPS read %d bytes succeeded, invalid response: '%s'", numRead, &buf[0] ); | 68 | odebug << "GPS read " << numRead << " bytes succeeded, invalid response: '" << &buf[0] << "'" << oendl; |
65 | return GpsLocation( -111, -111 ); | 69 | return GpsLocation( -111, -111 ); |
66 | } | 70 | } |
67 | else | 71 | else |
68 | { | 72 | { |
69 | return GpsLocation( lat, lon ); | 73 | return GpsLocation( lat, lon ); |
70 | } | 74 | } |
71 | } | 75 | } |
72 | } | 76 | } |
73 | return GpsLocation( -111, -111 ); | 77 | return GpsLocation( -111, -111 ); |
74 | } | 78 | } |
75 | 79 | ||
76 | 80 | ||
77 | QString GpsLocation::dmsPosition() const | 81 | QString GpsLocation::dmsPosition() const |
78 | { | 82 | { |
79 | if ( _latitude == -111 || _longitude == -111 ) | 83 | if ( _latitude == -111 || _longitude == -111 ) |
80 | return "N/A"; | 84 | return "N/A"; |
81 | if ( _latitude == 0.0 && _longitude == 0.0 ) | 85 | if ( _latitude == 0.0 && _longitude == 0.0 ) |
82 | return "NULL"; | 86 | return "NULL"; |
83 | 87 | ||
84 | /* compute latitude */ | 88 | /* compute latitude */ |
85 | 89 | ||
86 | QString dms = "N"; | 90 | QString dms = "N"; |
87 | if ( _latitude >= 0 ) dms.append( "+" ); | 91 | if ( _latitude >= 0 ) dms.append( "+" ); |
88 | 92 | ||
89 | int trunc = int( _latitude ); | 93 | int trunc = int( _latitude ); |
90 | float rest = _latitude - trunc; | 94 | float rest = _latitude - trunc; |
91 | 95 | ||
92 | float minf = rest * 60; | 96 | float minf = rest * 60; |
93 | int minutes = int( minf ); | 97 | int minutes = int( minf ); |
94 | 98 | ||
95 | rest = minf - minutes; | 99 | rest = minf - minutes; |
96 | int seconds = int( rest * 60 ); | 100 | int seconds = int( rest * 60 ); |
97 | 101 | ||
98 | dms.append( QString::number( trunc ) ); | 102 | dms.append( QString::number( trunc ) ); |
99 | dms.append( "° " ); | 103 | dms.append( "° " ); |
100 | dms.append( QString::number( ::abs( minutes ) ) ); | 104 | dms.append( QString::number( ::abs( minutes ) ) ); |
101 | dms.append( "' " ); | 105 | dms.append( "' " ); |
102 | dms.append( QString::number( ::abs( seconds ) ) ); | 106 | dms.append( QString::number( ::abs( seconds ) ) ); |
103 | dms.append( "'' " ); | 107 | dms.append( "'' " ); |
104 | 108 | ||
105 | /* compute longitude */ | 109 | /* compute longitude */ |
106 | 110 | ||
107 | dms.append( " | W" ); | 111 | dms.append( " | W" ); |
108 | if ( _longitude > 0 ) dms.append( "+" ); | 112 | if ( _longitude > 0 ) dms.append( "+" ); |
109 | 113 | ||
110 | trunc = int( _longitude ); | 114 | trunc = int( _longitude ); |
111 | rest = _longitude - trunc; | 115 | rest = _longitude - trunc; |
112 | 116 | ||