summaryrefslogtreecommitdiff
path: root/noncore/net/wellenreiter/gui/gps.cpp
Side-by-side diff
Diffstat (limited to 'noncore/net/wellenreiter/gui/gps.cpp') (more/less context) (show 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
@@ -12,12 +12,15 @@
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
**********************************************************************/
#include "gps.h"
#include <unistd.h>
+
+#include <qtextstream.h>
+
GPS::GPS( QObject* parent, const char * name )
:QObject( parent, name )
{
qDebug( "GPS::GPS()" );
_socket = new QSocket( this, "gpsd commsock" );
}
@@ -32,35 +35,35 @@ GPS::~GPS()
bool GPS::open( const QString& host, int port )
{
_socket->connectToHost( host, port );
}
-float GPS::latitude() const
+GpsLocation GPS::position() const
{
char buf[256];
int result = _socket->writeBlock( "p\r\n", 3 );
_socket->flush();
if ( result )
{
int numAvail = _socket->bytesAvailable();
qDebug( "GPS write succeeded, %d bytes available for reading...", numAvail );
if ( numAvail )
{
+ QTextStream stream( _socket );
- int num = _socket->readLine( &buf[0], sizeof buf );
- if ( num )
- {
- qDebug( "GPS got %d bytes ['%s']", num, &buf[0] );
- return 0.0;
- }
- }
+ QString str;
+ stream.readRawBytes( &buf[0], 7 );
+ float lat = -111.111;
+ stream >> lat;
+ stream.skipWhiteSpace();
+ float lon = -111.111;
+ stream >> lon;
+ stream.readRawBytes( &buf[0], 200 ); // read and discard the stuff until EOF
+
+ return GpsLocation( lat, lon );
}
- return -1.0;
}
-
-
-float GPS::longitute() const
-{
+ return GpsLocation( -1.0, -1.0 );
}