• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • plugins
  • positionprovider
  • gpsd
GpsdConnection.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2009 Eckhart Wörner <ewoerner@kde.org>
9 // Copyright 2011 Bastian Holst <bastianholst@gmx.de>
10 //
11 
12 #include "GpsdConnection.h"
13 
14 #include "MarbleDebug.h"
15 
16 #include <QTime>
17 
18 #include <errno.h>
19 #include <clocale>
20 
21 using namespace Marble;
22 /* TRANSLATOR Marble::GpsdConnection */
23 
24 const int gpsUpdateInterval = 1000; // ms
25 const int gpsWaitTimeout = 200; // ms
26 
27 GpsdConnection::GpsdConnection( QObject* parent )
28  : QObject( parent ),
29 #if defined( GPSD_API_MAJOR_VERSION ) && ( GPSD_API_MAJOR_VERSION >= 5 )
30  m_gpsd( "localhost", DEFAULT_GPSD_PORT ),
31 #endif
32  m_timer( 0 )
33 {
34  m_oldLocale = setlocale( LC_NUMERIC, NULL );
35  setlocale( LC_NUMERIC, "C" );
36  connect( &m_timer, SIGNAL(timeout()), this, SLOT(update()) );
37 }
38 
39 GpsdConnection::~GpsdConnection()
40 {
41  setlocale( LC_NUMERIC, m_oldLocale );
42 }
43 
44 void GpsdConnection::initialize()
45 {
46  m_timer.stop();
47  bool success = false;
48 #if defined( GPSD_API_MAJOR_VERSION ) && ( GPSD_API_MAJOR_VERSION >= 5 )
49  success = true;
50 #else
51  gps_data_t* data = m_gpsd.open();
52  success = ( data != 0 );
53 #endif
54 #if defined( GPSD_API_MAJOR_VERSION ) && ( GPSD_API_MAJOR_VERSION >= 3 ) && defined( WATCH_ENABLE )
55  if ( success ) {
56  success = (m_gpsd.stream( WATCH_ENABLE ) != NULL);
57  }
58 #endif
59  if ( success ) {
60  m_status = PositionProviderStatusAcquiring;
61  emit statusChanged( m_status );
62  m_timer.start( gpsUpdateInterval );
63  }
64  else {
65  // There is also gps_errstr() for libgps version >= 2.90,
66  // but it doesn't return a sensible error description
67  switch ( errno ) {
68  case NL_NOSERVICE:
69  m_error = tr("Internal gpsd error (cannot get service entry)");
70  break;
71  case NL_NOHOST:
72  m_error = tr("Internal gpsd error (cannot get host entry)");
73  break;
74  case NL_NOPROTO:
75  m_error = tr("Internal gpsd error (cannot get protocol entry)");
76  break;
77  case NL_NOSOCK:
78  m_error = tr("Internal gpsd error (unable to create socket)");
79  break;
80  case NL_NOSOCKOPT:
81  m_error = tr("Internal gpsd error (unable to set socket option)");
82  break;
83  case NL_NOCONNECT:
84  m_error = tr("No GPS device found by gpsd.");
85  break;
86  default:
87  m_error = tr("Unknown error when opening gpsd connection");
88  break;
89  }
90 
91  m_status = PositionProviderStatusError;
92  emit statusChanged( m_status );
93 
94  mDebug() << "Connection to gpsd failed, no position info available: " << m_error;
95  }
96 }
97 
98 void GpsdConnection::update()
99 {
100 #if defined( GPSD_API_MAJOR_VERSION ) && ( GPSD_API_MAJOR_VERSION >= 4 ) && defined( PACKET_SET )
101  gps_data_t *data = 0;
102 
103  QTime watchdog;
104  watchdog.start();
105 
106 #if defined( GPSD_API_MAJOR_VERSION ) && ( GPSD_API_MAJOR_VERSION >= 5 )
107  while ( m_gpsd.waiting( 0 ) && watchdog.elapsed() < gpsWaitTimeout ) {
108  gps_data_t *currentData = m_gpsd.read();
109 #else
110  while ( m_gpsd.waiting() && watchdog.elapsed() < gpsWaitTimeout ) {
111  gps_data_t *currentData = m_gpsd.poll();
112 #endif
113 
114  if( currentData && currentData->set & PACKET_SET ) {
115  data = currentData;
116  }
117  }
118 
119  if ( data ) {
120  emit gpsdInfo( *data );
121  }
122 #else
123 #if defined( GPSD_API_MAJOR_VERSION ) && ( GPSD_API_MAJOR_VERSION == 3 ) && defined( PACKET_SET )
124  gps_data_t *data = m_gpsd.poll();
125 #else
126  gps_data_t* data = m_gpsd.query( "o" );
127 #endif
128 
129  if ( data ) {
130  emit gpsdInfo( *data );
131  }
132  else if ( m_status != PositionProviderStatusAcquiring ) {
133  mDebug() << "Lost connection to gpsd, trying to re-open.";
134  initialize();
135  }
136 #endif
137 }
138 
139 QString GpsdConnection::error() const
140 {
141  return m_error;
142 }
143 
144 #include "GpsdConnection.moc"
Marble::GpsdConnection::gpsdInfo
void gpsdInfo(gps_data_t data)
Marble::GpsdConnection::initialize
void initialize()
Definition: GpsdConnection.cpp:44
gpsWaitTimeout
const int gpsWaitTimeout
Definition: GpsdConnection.cpp:25
QObject
MarbleDebug.h
Marble::GpsdConnection::statusChanged
void statusChanged(PositionProviderStatus status) const
Marble::GpsdConnection::error
QString error() const
Definition: GpsdConnection.cpp:139
Marble::PositionProviderStatusError
Definition: PositionProviderPluginInterface.h:26
gpsUpdateInterval
const int gpsUpdateInterval
Definition: GpsdConnection.cpp:24
Marble::GpsdConnection::GpsdConnection
GpsdConnection(QObject *parent=0)
Definition: GpsdConnection.cpp:27
Marble::GpsdConnection::~GpsdConnection
~GpsdConnection()
Definition: GpsdConnection.cpp:39
GpsdConnection.h
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:31
Marble::PositionProviderStatusAcquiring
Definition: PositionProviderPluginInterface.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:50 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal