summaryrefslogtreecommitdiff
path: root/noncore/net/wellenreiter/gui/gps.cpp
Unidiff
Diffstat (limited to 'noncore/net/wellenreiter/gui/gps.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/gui/gps.cpp29
1 files changed, 16 insertions, 13 deletions
diff --git a/noncore/net/wellenreiter/gui/gps.cpp b/noncore/net/wellenreiter/gui/gps.cpp
index 3206655..288afee 100644
--- a/noncore/net/wellenreiter/gui/gps.cpp
+++ b/noncore/net/wellenreiter/gui/gps.cpp
@@ -1,66 +1,69 @@
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> 17#include <unistd.h>
18
19#include <qtextstream.h>
20
18GPS::GPS( QObject* parent, const char * name ) 21GPS::GPS( QObject* parent, const char * name )
19 :QObject( parent, name ) 22 :QObject( parent, name )
20{ 23{
21 qDebug( "GPS::GPS()" ); 24 qDebug( "GPS::GPS()" );
22 _socket = new QSocket( this, "gpsd commsock" ); 25 _socket = new QSocket( this, "gpsd commsock" );
23} 26}
24 27
25 28
26GPS::~GPS() 29GPS::~GPS()
27{ 30{
28 qDebug( "GPS::~GPS()" ); 31 qDebug( "GPS::~GPS()" );
29} 32}
30 33
31 34
32bool GPS::open( const QString& host, int port ) 35bool GPS::open( const QString& host, int port )
33{ 36{
34 _socket->connectToHost( host, port ); 37 _socket->connectToHost( host, port );
35} 38}
36 39
37 40
38float GPS::latitude() const 41GpsLocation GPS::position() const
39{ 42{
40 char buf[256]; 43 char buf[256];
41 44
42 int result = _socket->writeBlock( "p\r\n", 3 ); 45 int result = _socket->writeBlock( "p\r\n", 3 );
43 _socket->flush(); 46 _socket->flush();
44 if ( result ) 47 if ( result )
45 { 48 {
46 int numAvail = _socket->bytesAvailable(); 49 int numAvail = _socket->bytesAvailable();
47 qDebug( "GPS write succeeded, %d bytes available for reading...", numAvail ); 50 qDebug( "GPS write succeeded, %d bytes available for reading...", numAvail );
48 if ( numAvail ) 51 if ( numAvail )
49 { 52 {
53 QTextStream stream( _socket );
50 54
51 int num = _socket->readLine( &buf[0], sizeof buf ); 55 QString str;
52 if ( num ) 56 stream.readRawBytes( &buf[0], 7 );
53 { 57 float lat = -111.111;
54 qDebug( "GPS got %d bytes ['%s']", num, &buf[0] ); 58 stream >> lat;
55 return 0.0; 59 stream.skipWhiteSpace();
56 } 60 float lon = -111.111;
61 stream >> lon;
62 stream.readRawBytes( &buf[0], 200 ); // read and discard the stuff until EOF
63
64 return GpsLocation( lat, lon );
57 } 65 }
58 } 66 }
59 return -1.0; 67 return GpsLocation( -1.0, -1.0 );
60}
61
62
63float GPS::longitute() const
64{
65} 68}
66 69