From 4c13339d2d4a8021f42d04998d5c4d7b77f81ca1 Mon Sep 17 00:00:00 2001
From: Marcel Huber <m1huber@hsr.ch>
Date: Mon, 16 Jan 2012 17:40:23 +0100
Subject: Created sip files for gps related objects

At least they compile but should be reviewed by a sip-expert.
---
 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(+), 0 deletions(-)
 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 230f646..89987c3 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 6fb4030..0dd3f50 100644
--- a/python/core/core.sip
+++ b/python/core/core.sip
@@ -91,3 +91,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 0000000..e5f25d1
--- /dev/null
+++ b/python/core/qgsgpsconnection.sip
@@ -0,0 +1,71 @@
+struct QgsSatelliteInfo {
+%TypeHeaderCode
+#include <qgsgpsconnection.h>
+%End
+	int id;
+	bool inUse;
+	int elevation;
+	int azimuth;
+	int signal;
+};
+
+struct QgsGPSInformation {
+%TypeHeaderCode
+#include <qgsgpsconnection.h>
+%End
+	double latitude;
+	double longitude;
+	double elevation;
+	double speed; //in km/h
+	double direction;
+	QList<QgsSatelliteInfo> 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<int> 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 <qgsgpsconnection.h>
+%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 0000000..c135bef
--- /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 <qgsgpsconnectionregistry.h>
+%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<const QgsGPSConnection*> connectionList() const;
+
+protected:
+	QgsGPSConnectionRegistry();
+};
diff --git a/python/core/qgsgpsdconnection.sip b/python/core/qgsgpsdconnection.sip
new file mode 100644
index 0000000..f0109e1
--- /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 0000000..17c3a57
--- /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<QPair<QString, QString> > 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 0000000..50a2ce6
--- /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);
+};
-- 
1.7.7

