From 83f95b8fa78c51cb502c2025029368820c831849 Mon Sep 17 00:00:00 2001 From: Marco Hugentobler Date: Wed, 1 Feb 2012 16:08:37 +0100 Subject: [PATCH] Add sip files for gps connection. Patch from Marcel Huber, ticket #4826 --- python/CMakeLists.txt | 2 + python/core/core.sip | 6 ++ python/core/qgsgpsconnection.sip | 71 ++++++++++++++++++++++++ python/core/qgsgpsconnectionregistry.sip | 20 +++++++ python/core/qgsgpsdconnection.sip | 13 +++++ python/core/qgsgpsdetector.sip | 20 +++++++ python/core/qgsnmeaconnection.sip | 25 +++++++++ 7 files changed, 157 insertions(+) create mode 100644 python/core/qgsgpsconnection.sip create mode 100644 python/core/qgsgpsconnectionregistry.sip create mode 100644 python/core/qgsgpsdconnection.sip create mode 100644 python/core/qgsgpsdetector.sip create mode 100644 python/core/qgsnmeaconnection.sip diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 230f646bc8f2..89987c3c663d 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -29,6 +29,8 @@ INCLUDE_DIRECTORIES( ../src/core ../src/core/composer + ../src/core/gps + ../src/core/gps/qextserialport ../src/core/raster ../src/core/renderer ../src/core/spatialindex diff --git a/python/core/core.sip b/python/core/core.sip index 4f6b5bb1a149..4ef76583a141 100644 --- a/python/core/core.sip +++ b/python/core/core.sip @@ -92,3 +92,9 @@ %Include qgsnetworkaccessmanager.sip %Include symbology-ng-core.sip + +%Include qgsgpsconnection.sip +%Include qgsgpsconnectionregistry.sip +%Include qgsgpsdconnection.sip +%Include qgsnmeaconnection.sip +%Include qgsgpsdetector.sip diff --git a/python/core/qgsgpsconnection.sip b/python/core/qgsgpsconnection.sip new file mode 100644 index 000000000000..e5f25d1ef446 --- /dev/null +++ b/python/core/qgsgpsconnection.sip @@ -0,0 +1,71 @@ +struct QgsSatelliteInfo { +%TypeHeaderCode +#include +%End + int id; + bool inUse; + int elevation; + int azimuth; + int signal; +}; + +struct QgsGPSInformation { +%TypeHeaderCode +#include +%End + double latitude; + double longitude; + double elevation; + double speed; //in km/h + double direction; + QList satellitesInView; + double pdop; + double hdop; + double vdop; + QDateTime utcDateTime; + QChar fixMode; + int fixType; + int quality; // from GPGGA + int satellitesUsed; // from GPGGA + QChar status; // from GPRMC A,V + QList satPrn; // list of SVs in use; needed for QgsSatelliteInfo.inUse and other uses + bool satInfoComplete; // based on GPGSV sentences - to be used to determine when to graph signal and satellite position +}; + +/**Abstract base class for connection to a GPS device*/ +class QgsGPSConnection: QObject { +%TypeHeaderCode +#include +%End +public: + enum Status { + NotConnected, Connected, DataReceived, GPSDataReceived + }; + + /**Constructor + @param dev input device for the connection (e.g. serial device). The class takes ownership of the object + @param pollIntervall update intervall in milliseconds*/ + QgsGPSConnection(QIODevice* dev); + virtual ~QgsGPSConnection(); + /**Opens connection to device*/ + bool connect(); + /**Closes connection to device*/ + bool close(); + + /**Sets the GPS source. The class takes ownership of the device class*/ + void setSource(QIODevice* source); + + /**Returns the status. Possible state are not connected, connected, data received*/ + Status status() const; + + /**Returns the current gps information (lat, lon, etc.)*/ + QgsGPSInformation currentGPSInformation() const; + +signals: + void stateChanged( const QgsGPSInformation& info ); + void nmeaSentenceReceived(const QString& substring); // added to capture 'raw' data + +protected slots: + /**Parse available data source content*/ + virtual void parseData() = 0; +}; diff --git a/python/core/qgsgpsconnectionregistry.sip b/python/core/qgsgpsconnectionregistry.sip new file mode 100644 index 000000000000..c135bef128fc --- /dev/null +++ b/python/core/qgsgpsconnectionregistry.sip @@ -0,0 +1,20 @@ +/**A singleton class to register / unregister existing GPS connections such that the information + is available to all classes and plugins*/ +class QgsGPSConnectionRegistry { +%TypeHeaderCode +#include +%End +public: + static QgsGPSConnectionRegistry* instance(); + ~QgsGPSConnectionRegistry(); + + /**Inserts a connection into the registry. The connection is owned by the registry class until it is unregistered again*/ + void registerConnection(QgsGPSConnection* c); + /**Unregisters connection. The registry does no longer own the connection*/ + void unregisterConnection(QgsGPSConnection* c); + + QList connectionList() const; + +protected: + QgsGPSConnectionRegistry(); +}; diff --git a/python/core/qgsgpsdconnection.sip b/python/core/qgsgpsdconnection.sip new file mode 100644 index 000000000000..f0109e1ca1cb --- /dev/null +++ b/python/core/qgsgpsdconnection.sip @@ -0,0 +1,13 @@ +/**Evaluates NMEA sentences coming from gpsd*/ +class QgsGpsdConnection: QgsNMEAConnection { +%TypeHeaderCode +#include "qgsgpsdconnection.h" +%End +public: + QgsGpsdConnection(QString host, qint16 port, QString device); + ~QgsGpsdConnection(); + +private slots: + void connected(); + void error(QAbstractSocket::SocketError); +}; diff --git a/python/core/qgsgpsdetector.sip b/python/core/qgsgpsdetector.sip new file mode 100644 index 000000000000..17c3a575be65 --- /dev/null +++ b/python/core/qgsgpsdetector.sip @@ -0,0 +1,20 @@ +// Class to detect the GPS port +class QgsGPSDetector: QObject { +%TypeHeaderCode +#include "qgsgpsdetector.h" +%End +public: + QgsGPSDetector(QString portName); + ~QgsGPSDetector(); + + static QList > availablePorts(); + +public slots: + void advance(); + void detected(const QgsGPSInformation&); + void connDestroyed(QObject *); + +signals: + void detected( QgsGPSConnection * ); + void detectionFailed(); +}; diff --git a/python/core/qgsnmeaconnection.sip b/python/core/qgsnmeaconnection.sip new file mode 100644 index 000000000000..50a2ce6b4042 --- /dev/null +++ b/python/core/qgsnmeaconnection.sip @@ -0,0 +1,25 @@ +/**Evaluates NMEA sentences coming from a GPS device*/ +class QgsNMEAConnection: QgsGPSConnection { +%TypeHeaderCode +#include "qgsnmeaconnection.h" +%End +public: + QgsNMEAConnection(QIODevice *dev); + ~QgsNMEAConnection(); + + //bool poll( QgsGPSInformation& info, int maxTime ); + +protected slots: + /**Parse available data source content*/ + void parseData(); + +protected: + /**Splits mStringBuffer into sentences and calls libnmea*/ + void processStringBuffer(); + //handle the different sentence type + void processGGASentence(const char* data, int len); + void processRMCSentence(const char* data, int len); + void processGSVSentence(const char* data, int len); + void processVTGSentence(const char* data, int len); + void processGSASentence(const char* data, int len); +};