From cab497ca08ab54b320bd4a706f5db6fb1be1e54e Mon Sep 17 00:00:00 2001 From: Asela Fernando Date: Tue, 10 Oct 2023 23:47:13 +1100 Subject: [PATCH 01/10] Initial commit --- headunit-desktop.pro | 1 + modules/gpsd/config.json | 21 +++++++++++++++++++ modules/gpsd/gpsd.pro | 26 +++++++++++++++++++++++ modules/gpsd/gpsdplugin.cpp | 30 +++++++++++++++++++++++++++ modules/gpsd/gpsdplugin.h | 41 +++++++++++++++++++++++++++++++++++++ modules/gpsd/qml.qrc | 6 ++++++ 6 files changed, 125 insertions(+) create mode 100644 modules/gpsd/config.json create mode 100644 modules/gpsd/gpsd.pro create mode 100644 modules/gpsd/gpsdplugin.cpp create mode 100644 modules/gpsd/gpsdplugin.h create mode 100644 modules/gpsd/qml.qrc diff --git a/headunit-desktop.pro b/headunit-desktop.pro index 8f9fea2..4c99e15 100644 --- a/headunit-desktop.pro +++ b/headunit-desktop.pro @@ -10,6 +10,7 @@ SUBDIRS = \ modules/welle-io \ # modules/navit \ # modules/fm-radio \ + modules/gpsd \ modules/hvac \ modules/sample \ modules/rpi \ diff --git a/modules/gpsd/config.json b/modules/gpsd/config.json new file mode 100644 index 0000000..3942065 --- /dev/null +++ b/modules/gpsd/config.json @@ -0,0 +1,21 @@ +{ + "name":"GPSD", + "label": "GPS", + "icon": "qrc:/GPSD/icons/icons8-satellite-100.png", + "config": { + "type": "loader", + "source": "qrc:/GPSD/settings.qml", + "settings": [ + { + "name": "host", + "type": "string", + "defaultValue": "127.0.0.1" + }, + { + "name": "port", + "type": "uint", + "defaultValue": 2947 + } + ] + } +} diff --git a/modules/gpsd/gpsd.pro b/modules/gpsd/gpsd.pro new file mode 100644 index 0000000..70febcc --- /dev/null +++ b/modules/gpsd/gpsd.pro @@ -0,0 +1,26 @@ +TEMPLATE = lib +CONFIG += c++11 plugin link_pkgconfig +QT += quick libQgpsmm +TARGET = $$qtLibraryTarget(gpsd-plugin) +DEFINES += QT_DEPRECATED_WARNINGS +INCLUDEPATH += $${PWD}/../../includes + +DESTDIR = $${OUT_PWD}/../../plugins + +include("../../config.pri") + +target.path = $${PREFIX}/plugins + +INSTALLS += target + +SOURCES += \ + gpsdplugin.cpp + +HEADERS += \ + gpsdplugin.h + +DISTFILES += \ + config.json + +RESOURCES += \ + qml.qrc diff --git a/modules/gpsd/gpsdplugin.cpp b/modules/gpsd/gpsdplugin.cpp new file mode 100644 index 0000000..b522922 --- /dev/null +++ b/modules/gpsd/gpsdplugin.cpp @@ -0,0 +1,30 @@ +#include "gpsdplugin.h" +#include + +GPSDPlugin::GPSDPlugin(QObject *parent) : QObject (parent) +{ + //m_pluginSettings.events = QStringList() << "MediaInput::position"; +} + +void GPSDPlugin::init() { + m_host = m_settings.value("host").toString(); + m_port = m_settings.value("port").toUInt(); +} + +QObject *GPSDPlugin::getContextProperty(){ + return this; +} + +void GPSDPlugin::eventMessage(QString id, QVariant message) { +} + +void GPSDPlugin::settingsChanged(const QString &key, const QVariant &){ + if(key == "host"){ + } + else if (key == "port") { + } +} + +void GPSDPlugin::PrintString(char *message, int length) { + qDebug() << "GPSD DEBUG : " << message; +} diff --git a/modules/gpsd/gpsdplugin.h b/modules/gpsd/gpsdplugin.h new file mode 100644 index 0000000..e9cba49 --- /dev/null +++ b/modules/gpsd/gpsdplugin.h @@ -0,0 +1,41 @@ +#ifndef GPSDPLUGIN_H +#define GPSDPLUGIN_H + +#include +#include +#include +#include +#include +#include + +class GPSDPlugin : public QObject, PluginInterface, PlatformCallbacks +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.aselafernando.headunit.gpsd" FILE "config.json") + Q_INTERFACES(PluginInterface) + + Q_PROPERTY(bool connected MEMBER m_connected NOTIFY connectedUpdated) + +public: + explicit GPSDPlugin(QObject *parent = nullptr); + + void init() override; + QObject *getContextProperty() override; + void PrintString(char * message, int length) override; + +public slots: + void eventMessage(QString id, QVariant message) override; + +signals: + void message(QString id, QVariant message); + void connectedUpdated(); + void action(QString id, QVariant message); + +private slots: + void settingsChanged(const QString &key, const QVariant &value); + +private: + bool m_connected; +}; + +#endif // GPSDPLUGIN_H diff --git a/modules/gpsd/qml.qrc b/modules/gpsd/qml.qrc new file mode 100644 index 0000000..0da8083 --- /dev/null +++ b/modules/gpsd/qml.qrc @@ -0,0 +1,6 @@ + + + settings.qml + icons/icons8-satellite-100.png + + From 34653c5d41c49d903c27a6af5c692f8cdaf801ca Mon Sep 17 00:00:00 2001 From: Asela Fernando Date: Tue, 10 Oct 2023 23:50:11 +1100 Subject: [PATCH 02/10] Added icon --- modules/gpsd/icons/icons8-satellite-100.png | Bin 0 -> 1480 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 modules/gpsd/icons/icons8-satellite-100.png diff --git a/modules/gpsd/icons/icons8-satellite-100.png b/modules/gpsd/icons/icons8-satellite-100.png new file mode 100644 index 0000000000000000000000000000000000000000..1e95fc008a42723774810b2aacb7d281e7d33f4f GIT binary patch literal 1480 zcmV;(1vmPMP)?6~H$X^Am83N(IjaJTT~(!cymC?)_!J50vNkB&2v` z92~YYHg$htk+BpwZu!p7fJcCb&8;deDNV}A02b!{z7+W0@|`bR9;Y8oMv6zqOjD1k zz$L&j%XhvG%y*QT?7S4<409_PS;&K)jH8zC-0PB&j1*v{e(34x^CF|&} z6yOfa$sN@fZiF&+0rM)>)oCfanwCP1GCD5>7z1`#PVPG$#;BqGi-B(~^}jTzjGUBz zbM^iKELUwtUl?;AuT=^S%1A}Zp1Pzk0vRbt88-pGq5702`izwOlyNg!9;l^^vSp;! zQubDDDIr=$YAxl}vQlD@Q6NQ!?w6`I1I!0rvz*+zSY;GQ`9QTDdQx=IFJp7;G76%^ z*Q<_5c>~zk78x04y>UOAR2Klo+9pE-tj-I$?=#yrzv`}wDdsf8fWJ{h)Yh25$P02g*Z#@E1EstaHb&9_NLBeS5v0H!P_ zxk^PuGBPy4jV3_Xk6wejQbj;gGBSXhf!}f`tV7+aRro3B?M+QVM+GneTn(%+KkF^4 z(}T5?DlG%JvnUlJW(g0P4FO!K0fd%PQO2Y%6(U-IYaGi;qmnY9jM7O%Q2?9?%$B>mJ{xshvu zryQTpq^ybM(YDU4u#sZ2nPx2qzB4}`(sz;Wb0pnp9*bq1(L{DwXerxlQcRge=6xG$ zVj1*#q)bP>;{3aJQ5lzQh{fZs6}>JNhQW zAtAEHnwGM)pxjzZnbJ~55u5TzITU+KxfMIl6qMUOh?G$V3O!Qxs92%*cuQ3&rlUVz zMM{XMEpU-#zpoQ2R_F~18Bogojxuwk1d_49#JAeB!jayZ*!;-7loWH3j}=J?C_~4! z^5|RGV$~uc_gY@_NqO2KB$Ki#kc_F;$#C4VwwM{jQd0C6U6t1g7kRFu-Z?{s0 z26)mk(9=?Gb4Yo%fADBxU-^LK$%-;IyWSf>#=h3d&;aKGKU0n8a#HfE2RB&e=v^{4 z7Ja6IjQy>akpbLOVfJuN?8}7i`&q6tnsQQXGRDlR`$BOgWE|*(jGUCJEoG;9g8DS~ z`U+F$4d$^^FZo=e%H^k2l47Q$r#mGh12_kG9QfGuA3vJkpD-i(S;u_JuesN*QuSnV z73Dm3SH_UBul$1N$^kqhrAp4@gxT*aO&KLZ_Zf#(!ztUIKI1Fk0+ky0r93cX-Q&I; zCqzcI+t-mgrb`QUoY4DyrG1+!kdno+^v Date: Wed, 11 Oct 2023 00:48:24 +1100 Subject: [PATCH 03/10] Added worker thread --- modules/gpsd/gpsd.pro | 3 +- modules/gpsd/gpsdplugin.cpp | 74 ++++++++++++++++++++++++++++++++++++- modules/gpsd/gpsdplugin.h | 49 ++++++++++++++++++++++-- modules/gpsd/settings.qml | 53 ++++++++++++++++++++++++++ 4 files changed, 173 insertions(+), 6 deletions(-) create mode 100644 modules/gpsd/settings.qml diff --git a/modules/gpsd/gpsd.pro b/modules/gpsd/gpsd.pro index 70febcc..1667295 100644 --- a/modules/gpsd/gpsd.pro +++ b/modules/gpsd/gpsd.pro @@ -1,6 +1,7 @@ TEMPLATE = lib CONFIG += c++11 plugin link_pkgconfig -QT += quick libQgpsmm +QT += quick +LIBS += -lgps TARGET = $$qtLibraryTarget(gpsd-plugin) DEFINES += QT_DEPRECATED_WARNINGS INCLUDEPATH += $${PWD}/../../includes diff --git a/modules/gpsd/gpsdplugin.cpp b/modules/gpsd/gpsdplugin.cpp index b522922..3399e4d 100644 --- a/modules/gpsd/gpsdplugin.cpp +++ b/modules/gpsd/gpsdplugin.cpp @@ -9,6 +9,28 @@ GPSDPlugin::GPSDPlugin(QObject *parent) : QObject (parent) void GPSDPlugin::init() { m_host = m_settings.value("host").toString(); m_port = m_settings.value("port").toUInt(); + //Run the data colleciton in another thread + GPSDWorker* worker = new GPSDWorker; + worker->moveToThread(&workerThread); + connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater); + connect(this, &GPSDPlugin::operate, worker, &GPSDWorker::connect); + connect(worker, &GPSDWorker::mode, this, &GPSDPlugin::handleMode); + connect(worker, &GPSDWorker::location, this, &GPSDPlugin::handleLocation); + workerThread.start(); + operate(); + qDebug() << "GPSD: Started worker thread: " << workerThread.isRunning(); +} + +void GPSDPlugin::handleMode(const int& result) { + this->m_mode = result; + emit modeUpdated(); +} + +void GPSDPlugin::handleLocation(const double& lat, const double& lon) { + this->m_latitude = lat; + this->m_longitude = lon; + emit latitudeUpdated(); + emit longitudeUpdated(); } QObject *GPSDPlugin::getContextProperty(){ @@ -18,6 +40,11 @@ QObject *GPSDPlugin::getContextProperty(){ void GPSDPlugin::eventMessage(QString id, QVariant message) { } +GPSDPlugin::~GPSDPlugin() { + workerThread.quit(); + workerThread.wait(); +} + void GPSDPlugin::settingsChanged(const QString &key, const QVariant &){ if(key == "host"){ } @@ -25,6 +52,51 @@ void GPSDPlugin::settingsChanged(const QString &key, const QVariant &){ } } -void GPSDPlugin::PrintString(char *message, int length) { +void GPSDPlugin::PrintString(const char *message) { qDebug() << "GPSD DEBUG : " << message; } + +void GPSDWorker::procData(struct gps_data_t * gps) { + if (gps->set & MODE_SET) { + emit mode(gps->fix.mode); + if(gps->fix.mode == 3 && gps->set & LATLON_SET) { + emit location(gps->fix.latitude, gps->fix.longitude); + } + } +} + +void GPSDWorker::getData() { + gpsmm gps_rec("localhost", DEFAULT_GPSD_PORT); + + if (gps_rec.stream(WATCH_ENABLE|WATCH_JSON) == NULL) { + qDebug() << "No GPSD running.\n"; + return; + } + + while(stopClient == false) { + struct gps_data_t* newdata; + + if (!gps_rec.waiting(5000000)) + continue; + + if ((newdata = gps_rec.read()) == NULL) { + qDebug() << "Read error.\n"; + return; + } else { + procData(newdata); + } + } +} + +void GPSDWorker::connect() { + stopClient = false; + getData(); +} + +void GPSDWorker::disconnect() { + stopClient = true; +} + +GPSDWorker::~GPSDWorker() { + stopClient = true; +} diff --git a/modules/gpsd/gpsdplugin.h b/modules/gpsd/gpsdplugin.h index e9cba49..b75d304 100644 --- a/modules/gpsd/gpsdplugin.h +++ b/modules/gpsd/gpsdplugin.h @@ -5,37 +5,78 @@ #include #include #include +#include #include #include -class GPSDPlugin : public QObject, PluginInterface, PlatformCallbacks +#include "libgpsmm.h" + +using namespace std; + +class GPSDPlugin : public QObject, PluginInterface { Q_OBJECT Q_PLUGIN_METADATA(IID "org.aselafernando.headunit.gpsd" FILE "config.json") Q_INTERFACES(PluginInterface) - Q_PROPERTY(bool connected MEMBER m_connected NOTIFY connectedUpdated) + //Q_PROPERTY(bool connected MEMBER m_connected NOTIFY connectedUpdated) + Q_PROPERTY(int mode MEMBER m_mode NOTIFY modeUpdated) + Q_PROPERTY(double longitude MEMBER m_longitude NOTIFY longitudeUpdated) + Q_PROPERTY(double latitude MEMBER m_latitude NOTIFY latitudeUpdated) + public: explicit GPSDPlugin(QObject *parent = nullptr); + ~GPSDPlugin(); void init() override; QObject *getContextProperty() override; - void PrintString(char * message, int length) override; + void PrintString(const char * message); public slots: void eventMessage(QString id, QVariant message) override; + void handleMode(const int& result); + void handleLocation(const double& lat, const double& lon); signals: void message(QString id, QVariant message); - void connectedUpdated(); + //void connectedUpdated(); void action(QString id, QVariant message); + void operate(); + void modeUpdated(); + void longitudeUpdated(); + void latitudeUpdated(); private slots: void settingsChanged(const QString &key, const QVariant &value); private: bool m_connected; + QString m_host = ""; + quint32 m_port = 0; + QThread workerThread; + int m_mode = 0; + double m_latitude = 0; + double m_longitude = 0; }; +class GPSDWorker : public QObject { + Q_OBJECT + +private: + void getData(); + void procData(struct gps_data_t * gps); + bool stopClient = false; + ~GPSDWorker(); + +public slots: + void connect(); + void disconnect(); + +signals: + void mode(const int& result); + void location(const double& latitude, const double& longitude); +}; + + #endif // GPSDPLUGIN_H diff --git a/modules/gpsd/settings.qml b/modules/gpsd/settings.qml new file mode 100644 index 0000000..529fb9f --- /dev/null +++ b/modules/gpsd/settings.qml @@ -0,0 +1,53 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.2 +import HUDTheme 1.0 +import HUDSettingsPage 1.0 +import QtQuick.Layouts 1.3 + +ThemeRoot { + id:__root + + Flickable { + anchors.fill: parent + contentHeight: column.height + flickableDirection: Flickable.VerticalFlick + ScrollBar.vertical: ThemeScrollBar { } + Column { + id: column + anchors.left: parent.left + anchors.right: parent.right + anchors.leftMargin: 0 + + SettingsPageItemTextfield { + id: host + width: parent.width + label: "Host" + onValueChanged: { + pluginSettings.host = value + } + value : pluginSettings.host + } + + SettingsPageItemTextfield { + id: port + width: parent.width + label: "Port" + onValueChanged: { + pluginSettings.port = value + } + value : pluginSettings.port + } + + SettingsPageItemHeader{ + width: parent.width + } + + } + } +} + +/*##^## +Designer { + D{i:0;autoSize:true;height:480;width:640} +} +##^##*/ From 0dcb38872093e402e50fc64e2d49b8ecc2f8f02d Mon Sep 17 00:00:00 2001 From: Asela Fernando Date: Wed, 11 Oct 2023 13:43:01 +1100 Subject: [PATCH 04/10] Fence can be modified through settings --- modules/gpsd/config.json | 59 ++++++++++++++- modules/gpsd/gpsdplugin.cpp | 135 +++++++++++++++++++++++++++------- modules/gpsd/gpsdplugin.h | 22 +++--- modules/gpsd/settings.qml | 140 +++++++++++++++++++++++++++++++++++- 4 files changed, 318 insertions(+), 38 deletions(-) diff --git a/modules/gpsd/config.json b/modules/gpsd/config.json index 3942065..0ceaf55 100644 --- a/modules/gpsd/config.json +++ b/modules/gpsd/config.json @@ -14,8 +14,63 @@ { "name": "port", "type": "uint", - "defaultValue": 2947 - } + "defaultValue": 0 + }, + { + "name": "fence", + "type": "int", + "defaultValue": -1 + }, + { + "name": "fence0pt0", + "type": "string", + "defaultValue": "-37.81377659455088, 144.9573499708269" + }, + { + "name": "fence0pt1", + "type": "string", + "defaultValue": "-37.81959883100442, 144.9600354951891" + }, + { + "name": "fence0pt2", + "type": "string", + "defaultValue": "-37.817398930901135, 144.96748872616857" + }, + { + "name": "fence0pt3", + "type": "string", + "defaultValue": "-37.81167088347648, 144.96478490480058" + }, + { + "name": "fence0pt4", + "type": "string", + "defaultValue": "-37.81229491021319, 144.96222285683766" + }, + { + "name": "fence0pt5", + "type": "string", + "defaultValue": "" + }, + { + "name": "fence0pt6", + "type": "string", + "defaultValue": "" + }, + { + "name": "fence0pt7", + "type": "string", + "defaultValue": "" + }, + { + "name": "fence0pt8", + "type": "string", + "defaultValue": "" + }, + { + "name": "fence0pt9", + "type": "string", + "defaultValue": "" + }, ] } } diff --git a/modules/gpsd/gpsdplugin.cpp b/modules/gpsd/gpsdplugin.cpp index 3399e4d..af60e74 100644 --- a/modules/gpsd/gpsdplugin.cpp +++ b/modules/gpsd/gpsdplugin.cpp @@ -1,24 +1,26 @@ #include "gpsdplugin.h" +#define _USE_MATH_DEFINES #include +double fences[1][10][2] = {{{17.529188, 78.361845}, + {17.529840, 78.361919}, + {17.529934, 78.362197}, + {17.530624, 78.362507}, + {17.530832, 78.363043}, + {17.530999, 78.363451}, + {17.530924, 78.363976}, + {17.529248, 78.363288}, + {17.529101, 78.362858}, + {17.529040, 78.362489}}}; + + GPSDPlugin::GPSDPlugin(QObject *parent) : QObject (parent) { //m_pluginSettings.events = QStringList() << "MediaInput::position"; } void GPSDPlugin::init() { - m_host = m_settings.value("host").toString(); - m_port = m_settings.value("port").toUInt(); - //Run the data colleciton in another thread - GPSDWorker* worker = new GPSDWorker; - worker->moveToThread(&workerThread); - connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater); - connect(this, &GPSDPlugin::operate, worker, &GPSDWorker::connect); - connect(worker, &GPSDWorker::mode, this, &GPSDPlugin::handleMode); - connect(worker, &GPSDWorker::location, this, &GPSDPlugin::handleLocation); - workerThread.start(); - operate(); - qDebug() << "GPSD: Started worker thread: " << workerThread.isRunning(); + startWorker(); } void GPSDPlugin::handleMode(const int& result) { @@ -26,11 +28,13 @@ void GPSDPlugin::handleMode(const int& result) { emit modeUpdated(); } -void GPSDPlugin::handleLocation(const double& lat, const double& lon) { +void GPSDPlugin::handleLocation(const double& lat, const double& lon, const bool& inFence) { this->m_latitude = lat; this->m_longitude = lon; + this->m_inFence = inFence; emit latitudeUpdated(); emit longitudeUpdated(); + emit inFenceUpdated(); } QObject *GPSDPlugin::getContextProperty(){ @@ -41,11 +45,53 @@ void GPSDPlugin::eventMessage(QString id, QVariant message) { } GPSDPlugin::~GPSDPlugin() { + stopWorker(); +} + +void GPSDPlugin::stopWorker() { workerThread.quit(); + workerThread.requestInterruption(); workerThread.wait(); } +void GPSDPlugin::startWorker() { + m_host = m_settings.value("host").toString(); + m_port = m_settings.value("port").toUInt(); + m_fence = m_settings.value("fence").toInt(); + + if (m_fence >= 0) { + //Get Fence Points + int fenceSize = sizeof(fences[m_fence])/sizeof(fences[m_fence][0]); + char buffer[11]; + for(int i = 0; i < fenceSize; i++) { + snprintf(buffer, 11, "fence0pt%d", i); + QString pt = m_settings.value(buffer).toString(); + QStringList pieces = pt.split(","); + if(pieces.length() == 2) { + fences[0][i][0] = pieces.value(0).toDouble(); + fences[0][i][1] = pieces.value(1).toDouble(); + } else { + fences[0][i][0] = 0; + fences[0][i][1] = 0; + } + } + } + + //Run the data colleciton in another thread + GPSDWorker* worker = new GPSDWorker; + worker->moveToThread(&workerThread); + connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater); + connect(this, &GPSDPlugin::operate, worker, &GPSDWorker::connect); + connect(worker, &GPSDWorker::mode, this, &GPSDPlugin::handleMode); + connect(worker, &GPSDWorker::location, this, &GPSDPlugin::handleLocation); + workerThread.start(); + operate(m_host, m_port, m_fence); + qDebug() << "GPSD: Started worker thread: " << workerThread.isRunning(); +} + void GPSDPlugin::settingsChanged(const QString &key, const QVariant &){ + stopWorker(); + startWorker(); if(key == "host"){ } else if (key == "port") { @@ -56,41 +102,76 @@ void GPSDPlugin::PrintString(const char *message) { qDebug() << "GPSD DEBUG : " << message; } +bool GPSDWorker::pointInPolygon(double lat, double lon) { + if (m_fence < 0) return false; + + int fenceSize = sizeof(fences[m_fence])/sizeof(fences[m_fence][0]); + double vectors[fenceSize][2]; + + for(int i = 0; i < fenceSize; i++){ + if(fences[m_fence][i][0] == 0 || fences[m_fence][i][1] == 0) { + fenceSize = i; + break; + } + vectors[i][0] = fences[m_fence][i][0] - lat; + vectors[i][1] = fences[m_fence][i][1] - lon; + } + + double angle = 0; + double num, den; + + for(int i = 0; i < fenceSize; i++){ + num = (vectors[i%fenceSize][0])*(vectors[(i+1)%fenceSize][0])+ (vectors[i%fenceSize][1])*(vectors[(i+1)%fenceSize][1]); + den = (sqrt(pow(vectors[i%fenceSize][0],2) + pow(vectors[i%fenceSize][1],2)))*(sqrt(pow(vectors[(i+1)%fenceSize][0],2) + pow(vectors[(i+1)%fenceSize][1],2))); + angle = angle + (180*acos(num/den)/M_PI); + } + + return (angle > 355 && angle < 365); +} + void GPSDWorker::procData(struct gps_data_t * gps) { - if (gps->set & MODE_SET) { - emit mode(gps->fix.mode); - if(gps->fix.mode == 3 && gps->set & LATLON_SET) { - emit location(gps->fix.latitude, gps->fix.longitude); - } + if (gps->set & MODE_SET) { + emit mode(gps->fix.mode); + if(gps->fix.mode > MODE_2D) { + if(gps->set & LATLON_SET) + emit location(gps->fix.latitude, gps->fix.longitude, pointInPolygon(gps->fix.latitude, gps->fix.longitude)); } + } } -void GPSDWorker::getData() { - gpsmm gps_rec("localhost", DEFAULT_GPSD_PORT); +void GPSDWorker::getData(std::string host, uint32_t port) { + gpsmm gps_rec(host.c_str(), DEFAULT_GPSD_PORT); + + if(port > 0 && port <= 65535) { + char buffer[6]; + snprintf(buffer, 6, "%d", port); + gpsmm gps_rec(host.c_str(), buffer); + } if (gps_rec.stream(WATCH_ENABLE|WATCH_JSON) == NULL) { - qDebug() << "No GPSD running.\n"; - return; + qDebug() << "GPSD: No GPSD running.\n"; + QThread::sleep(1); } - while(stopClient == false) { + while(stopClient == false && QThread::currentThread()->isInterruptionRequested() == false) { struct gps_data_t* newdata; if (!gps_rec.waiting(5000000)) continue; if ((newdata = gps_rec.read()) == NULL) { - qDebug() << "Read error.\n"; - return; + qDebug() << "GPSD: Read error\n"; + QThread::sleep(1); } else { procData(newdata); } } } -void GPSDWorker::connect() { +void GPSDWorker::connect(QString host, quint32 port, int fence) { stopClient = false; - getData(); + this->m_fence = fence; + getData(host.toStdString(), port); } void GPSDWorker::disconnect() { diff --git a/modules/gpsd/gpsdplugin.h b/modules/gpsd/gpsdplugin.h index b75d304..6ad56e6 100644 --- a/modules/gpsd/gpsdplugin.h +++ b/modules/gpsd/gpsdplugin.h @@ -23,7 +23,7 @@ class GPSDPlugin : public QObject, PluginInterface Q_PROPERTY(int mode MEMBER m_mode NOTIFY modeUpdated) Q_PROPERTY(double longitude MEMBER m_longitude NOTIFY longitudeUpdated) Q_PROPERTY(double latitude MEMBER m_latitude NOTIFY latitudeUpdated) - + Q_PROPERTY(bool inFence MEMBER m_inFence NOTIFY inFenceUpdated) public: explicit GPSDPlugin(QObject *parent = nullptr); @@ -36,46 +36,52 @@ class GPSDPlugin : public QObject, PluginInterface public slots: void eventMessage(QString id, QVariant message) override; void handleMode(const int& result); - void handleLocation(const double& lat, const double& lon); + void handleLocation(const double& lat, const double& lon, const bool& inFence); signals: void message(QString id, QVariant message); - //void connectedUpdated(); void action(QString id, QVariant message); - void operate(); + void operate(QString host, quint32 port, int fence); void modeUpdated(); void longitudeUpdated(); void latitudeUpdated(); + void inFenceUpdated(); private slots: void settingsChanged(const QString &key, const QVariant &value); private: - bool m_connected; QString m_host = ""; quint32 m_port = 0; + int m_fence = 0; QThread workerThread; int m_mode = 0; double m_latitude = 0; double m_longitude = 0; + bool m_inFence = false; + void stopWorker(); + void startWorker(); + }; class GPSDWorker : public QObject { Q_OBJECT private: - void getData(); + int m_fence = 0; + void getData(std::string host, uint32_t port); void procData(struct gps_data_t * gps); bool stopClient = false; + bool pointInPolygon(double lat, double lon); ~GPSDWorker(); public slots: - void connect(); + void connect(QString host, quint32 port, int fence); void disconnect(); signals: void mode(const int& result); - void location(const double& latitude, const double& longitude); + void location(const double& latitude, const double& longitude, const bool& inFence); }; diff --git a/modules/gpsd/settings.qml b/modules/gpsd/settings.qml index 529fb9f..aecaeca 100644 --- a/modules/gpsd/settings.qml +++ b/modules/gpsd/settings.qml @@ -37,7 +37,145 @@ ThemeRoot { } value : pluginSettings.port } - + + SettingsPageItemTextfield { + id: current_mode + width: parent.width + label: "Current Fix Mode" + value : pluginContext.mode + } + + SettingsPageItemTextfield { + id: current_latitude + width: parent.width + label: "Current Latitude" + value : pluginContext.latitude + } + + SettingsPageItemTextfield { + id: current_longitude + width: parent.width + label: "Current Longitude" + value : pluginContext.longitude + } + + SettingsPageItemTextfield { + id: current_inFence + width: parent.width + label: "Currently inside fence?" + value : pluginContext.inFence + } + + SettingsPageItemTextfield { + id: fence + width: parent.width + label: "Fence" + onValueChanged: { + pluginSettings.fence = value + } + value : pluginSettings.fence + } + + SettingsPageItemTextfield { + id: fence0pt0 + width: parent.width + label: "Fence 0 Point 0" + onValueChanged: { + pluginSettings.fence0pt0 = value + } + value : pluginSettings.fence0pt0 + } + + SettingsPageItemTextfield { + id: fence0pt1 + width: parent.width + label: "Fence 0 Point 1" + onValueChanged: { + pluginSettings.fence0pt1 = value + } + value : pluginSettings.fence0pt1 + } + + SettingsPageItemTextfield { + id: fence0pt2 + width: parent.width + label: "Fence 0 Point 2" + onValueChanged: { + pluginSettings.fence0pt2 = value + } + value : pluginSettings.fence0pt2 + } + + SettingsPageItemTextfield { + id: fence0pt3 + width: parent.width + label: "Fence 0 Point 3" + onValueChanged: { + pluginSettings.fence0pt3 = value + } + value : pluginSettings.fence0pt3 + } + + SettingsPageItemTextfield { + id: fence0pt4 + width: parent.width + label: "Fence 0 Point 4" + onValueChanged: { + pluginSettings.fence0pt4 = value + } + value : pluginSettings.fence0pt4 + } + + SettingsPageItemTextfield { + id: fence0pt5 + width: parent.width + label: "Fence 0 Point 5" + onValueChanged: { + pluginSettings.fence0pt5 = value + } + value : pluginSettings.fence0pt5 + } + + SettingsPageItemTextfield { + id: fence0pt6 + width: parent.width + label: "Fence 0 Point 6" + onValueChanged: { + pluginSettings.fence0pt6 = value + } + value : pluginSettings.fence0pt6 + } + + SettingsPageItemTextfield { + id: fence0pt7 + width: parent.width + label: "Fence 0 Point 7" + onValueChanged: { + pluginSettings.fence0pt7 = value + } + value : pluginSettings.fence0pt7 + } + + SettingsPageItemTextfield { + id: fence0pt8 + width: parent.width + label: "Fence 0 Point 8" + onValueChanged: { + pluginSettings.fence0pt8 = value + } + value : pluginSettings.fence0pt8 + } + + SettingsPageItemTextfield { + id: fence0pt9 + width: parent.width + label: "Fence 0 Point 9" + onValueChanged: { + pluginSettings.fence0pt9 = value + } + value : pluginSettings.fence0pt9 + } + SettingsPageItemHeader{ width: parent.width } From 8cdcf7574c452fa338371b7bba026f7aca01c499 Mon Sep 17 00:00:00 2001 From: Asela Fernando Date: Wed, 11 Oct 2023 15:08:40 +1100 Subject: [PATCH 05/10] Actions emitted reduced fence points to 4 --- modules/gpsd/config.json | 45 ++-------------- modules/gpsd/gpsdplugin.cpp | 17 ++++-- modules/gpsd/gpsdplugin.h | 4 +- modules/gpsd/settings.qml | 102 ++++++------------------------------ 4 files changed, 35 insertions(+), 133 deletions(-) diff --git a/modules/gpsd/config.json b/modules/gpsd/config.json index 0ceaf55..7e446db 100644 --- a/modules/gpsd/config.json +++ b/modules/gpsd/config.json @@ -17,60 +17,25 @@ "defaultValue": 0 }, { - "name": "fence", - "type": "int", - "defaultValue": -1 - }, - { - "name": "fence0pt0", + "name": "fence1pt1", "type": "string", "defaultValue": "-37.81377659455088, 144.9573499708269" }, { - "name": "fence0pt1", + "name": "fence1pt2", "type": "string", "defaultValue": "-37.81959883100442, 144.9600354951891" }, { - "name": "fence0pt2", + "name": "fence1pt3", "type": "string", "defaultValue": "-37.817398930901135, 144.96748872616857" }, { - "name": "fence0pt3", + "name": "fence1pt4", "type": "string", "defaultValue": "-37.81167088347648, 144.96478490480058" - }, - { - "name": "fence0pt4", - "type": "string", - "defaultValue": "-37.81229491021319, 144.96222285683766" - }, - { - "name": "fence0pt5", - "type": "string", - "defaultValue": "" - }, - { - "name": "fence0pt6", - "type": "string", - "defaultValue": "" - }, - { - "name": "fence0pt7", - "type": "string", - "defaultValue": "" - }, - { - "name": "fence0pt8", - "type": "string", - "defaultValue": "" - }, - { - "name": "fence0pt9", - "type": "string", - "defaultValue": "" - }, + } ] } } diff --git a/modules/gpsd/gpsdplugin.cpp b/modules/gpsd/gpsdplugin.cpp index af60e74..cfac95c 100644 --- a/modules/gpsd/gpsdplugin.cpp +++ b/modules/gpsd/gpsdplugin.cpp @@ -2,6 +2,7 @@ #define _USE_MATH_DEFINES #include +const int m_fence = 0; //only one fence double fences[1][10][2] = {{{17.529188, 78.361845}, {17.529840, 78.361919}, {17.529934, 78.362197}, @@ -32,9 +33,19 @@ void GPSDPlugin::handleLocation(const double& lat, const double& lon, const bool this->m_latitude = lat; this->m_longitude = lon; this->m_inFence = inFence; + emit latitudeUpdated(); emit longitudeUpdated(); emit inFenceUpdated(); + + QList location; + location.append(lat); + location.append(lon); + QVariant variant; + variant.setValue>(location); + + emit action("SYSTEM::GPSInFence", inFence); + emit action("SYSTEM::GPSLocation", variant); } QObject *GPSDPlugin::getContextProperty(){ @@ -57,14 +68,13 @@ void GPSDPlugin::stopWorker() { void GPSDPlugin::startWorker() { m_host = m_settings.value("host").toString(); m_port = m_settings.value("port").toUInt(); - m_fence = m_settings.value("fence").toInt(); if (m_fence >= 0) { //Get Fence Points int fenceSize = sizeof(fences[m_fence])/sizeof(fences[m_fence][0]); char buffer[11]; for(int i = 0; i < fenceSize; i++) { - snprintf(buffer, 11, "fence0pt%d", i); + snprintf(buffer, 11, "fence1pt%d", i + 1); QString pt = m_settings.value(buffer).toString(); QStringList pieces = pt.split(","); if(pieces.length() == 2) { @@ -168,9 +178,8 @@ void GPSDWorker::getData(std::string host, uint32_t port) { } } -void GPSDWorker::connect(QString host, quint32 port, int fence) { +void GPSDWorker::connect(QString host, quint32 port) { stopClient = false; - this->m_fence = fence; getData(host.toStdString(), port); } diff --git a/modules/gpsd/gpsdplugin.h b/modules/gpsd/gpsdplugin.h index 6ad56e6..e959f03 100644 --- a/modules/gpsd/gpsdplugin.h +++ b/modules/gpsd/gpsdplugin.h @@ -53,7 +53,6 @@ private slots: private: QString m_host = ""; quint32 m_port = 0; - int m_fence = 0; QThread workerThread; int m_mode = 0; double m_latitude = 0; @@ -68,7 +67,6 @@ class GPSDWorker : public QObject { Q_OBJECT private: - int m_fence = 0; void getData(std::string host, uint32_t port); void procData(struct gps_data_t * gps); bool stopClient = false; @@ -76,7 +74,7 @@ class GPSDWorker : public QObject { ~GPSDWorker(); public slots: - void connect(QString host, quint32 port, int fence); + void connect(QString host, quint32 port); void disconnect(); signals: diff --git a/modules/gpsd/settings.qml b/modules/gpsd/settings.qml index aecaeca..9b7226e 100644 --- a/modules/gpsd/settings.qml +++ b/modules/gpsd/settings.qml @@ -67,113 +67,43 @@ ThemeRoot { } SettingsPageItemTextfield { - id: fence + id: fence1pt1 width: parent.width - label: "Fence" + label: "Fence 1 Point 1" onValueChanged: { - pluginSettings.fence = value + pluginSettings.fence1pt1 = value } - value : pluginSettings.fence + value : pluginSettings.fence1pt1 } SettingsPageItemTextfield { - id: fence0pt0 + id: fence1pt2 width: parent.width - label: "Fence 0 Point 0" + label: "Fence 1 Point 2" onValueChanged: { - pluginSettings.fence0pt0 = value + pluginSettings.fence1pt2 = value } - value : pluginSettings.fence0pt0 + value : pluginSettings.fence1pt2 } SettingsPageItemTextfield { - id: fence0pt1 + id: fence1pt3 width: parent.width - label: "Fence 0 Point 1" + label: "Fence 1 Point 3" onValueChanged: { - pluginSettings.fence0pt1 = value + pluginSettings.fence1pt3 = value } - value : pluginSettings.fence0pt1 + value : pluginSettings.fence1pt3 } SettingsPageItemTextfield { - id: fence0pt2 + id: fence1pt4 width: parent.width - label: "Fence 0 Point 2" + label: "Fence 1 Point 4" onValueChanged: { - pluginSettings.fence0pt2 = value + pluginSettings.fence1pt4 = value } - value : pluginSettings.fence0pt2 - } - - SettingsPageItemTextfield { - id: fence0pt3 - width: parent.width - label: "Fence 0 Point 3" - onValueChanged: { - pluginSettings.fence0pt3 = value - } - value : pluginSettings.fence0pt3 - } - - SettingsPageItemTextfield { - id: fence0pt4 - width: parent.width - label: "Fence 0 Point 4" - onValueChanged: { - pluginSettings.fence0pt4 = value - } - value : pluginSettings.fence0pt4 - } - - SettingsPageItemTextfield { - id: fence0pt5 - width: parent.width - label: "Fence 0 Point 5" - onValueChanged: { - pluginSettings.fence0pt5 = value - } - value : pluginSettings.fence0pt5 - } - - SettingsPageItemTextfield { - id: fence0pt6 - width: parent.width - label: "Fence 0 Point 6" - onValueChanged: { - pluginSettings.fence0pt6 = value - } - value : pluginSettings.fence0pt6 - } - - SettingsPageItemTextfield { - id: fence0pt7 - width: parent.width - label: "Fence 0 Point 7" - onValueChanged: { - pluginSettings.fence0pt7 = value - } - value : pluginSettings.fence0pt7 - } - - SettingsPageItemTextfield { - id: fence0pt8 - width: parent.width - label: "Fence 0 Point 8" - onValueChanged: { - pluginSettings.fence0pt8 = value - } - value : pluginSettings.fence0pt8 - } - - SettingsPageItemTextfield { - id: fence0pt9 - width: parent.width - label: "Fence 0 Point 9" - onValueChanged: { - pluginSettings.fence0pt9 = value - } - value : pluginSettings.fence0pt9 + value : pluginSettings.fence1pt4 } SettingsPageItemHeader{ From 686bd575f919d14c814b343c4d58bdb7c50d5eec Mon Sep 17 00:00:00 2001 From: Asela Fernando Date: Wed, 11 Oct 2023 15:18:17 +1100 Subject: [PATCH 06/10] Fixed invalid point marker 0 can be a valid co-ordinate, now setting to -91 and -181 for latitude and longitude respectively to mark invalid values --- modules/gpsd/gpsdplugin.cpp | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/modules/gpsd/gpsdplugin.cpp b/modules/gpsd/gpsdplugin.cpp index cfac95c..aa7825c 100644 --- a/modules/gpsd/gpsdplugin.cpp +++ b/modules/gpsd/gpsdplugin.cpp @@ -3,17 +3,7 @@ #include const int m_fence = 0; //only one fence -double fences[1][10][2] = {{{17.529188, 78.361845}, - {17.529840, 78.361919}, - {17.529934, 78.362197}, - {17.530624, 78.362507}, - {17.530832, 78.363043}, - {17.530999, 78.363451}, - {17.530924, 78.363976}, - {17.529248, 78.363288}, - {17.529101, 78.362858}, - {17.529040, 78.362489}}}; - +double fences[1][4][2]; // 1 Fence, 4 Points = 2 Measurements (Lat/Lon) GPSDPlugin::GPSDPlugin(QObject *parent) : QObject (parent) { @@ -41,11 +31,11 @@ void GPSDPlugin::handleLocation(const double& lat, const double& lon, const bool QList location; location.append(lat); location.append(lon); - QVariant variant; - variant.setValue>(location); + QVariant locationVariant; + locationVariant.setValue>(location); emit action("SYSTEM::GPSInFence", inFence); - emit action("SYSTEM::GPSLocation", variant); + emit action("SYSTEM::GPSLocation", locationVariant); } QObject *GPSDPlugin::getContextProperty(){ @@ -74,15 +64,15 @@ void GPSDPlugin::startWorker() { int fenceSize = sizeof(fences[m_fence])/sizeof(fences[m_fence][0]); char buffer[11]; for(int i = 0; i < fenceSize; i++) { - snprintf(buffer, 11, "fence1pt%d", i + 1); + snprintf(buffer, 11, "fence%dpt%d", m_fence + 1, i + 1); QString pt = m_settings.value(buffer).toString(); QStringList pieces = pt.split(","); if(pieces.length() == 2) { - fences[0][i][0] = pieces.value(0).toDouble(); - fences[0][i][1] = pieces.value(1).toDouble(); + fences[m_fence][i][0] = pieces.value(0).toDouble(); + fences[m_fence][i][1] = pieces.value(1).toDouble(); } else { - fences[0][i][0] = 0; - fences[0][i][1] = 0; + fences[m_fence][i][0] = -91; //invalid latitude + fences[m_fence][i][1] = -181; //invalid longitude } } } @@ -119,7 +109,7 @@ bool GPSDWorker::pointInPolygon(double lat, double lon) { double vectors[fenceSize][2]; for(int i = 0; i < fenceSize; i++){ - if(fences[m_fence][i][0] == 0 || fences[m_fence][i][1] == 0) { + if(fences[m_fence][i][0] < -90 || fences[m_fence][i][1] < -180) { fenceSize = i; break; } From 9077c703b310ab84b995c016e269ae724b927844 Mon Sep 17 00:00:00 2001 From: Asela Fernando Date: Wed, 18 Oct 2023 16:13:29 +1100 Subject: [PATCH 07/10] Made location action data a QVariantMap --- modules/gpsd/gpsdplugin.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/gpsd/gpsdplugin.cpp b/modules/gpsd/gpsdplugin.cpp index aa7825c..a4d0293 100644 --- a/modules/gpsd/gpsdplugin.cpp +++ b/modules/gpsd/gpsdplugin.cpp @@ -28,14 +28,12 @@ void GPSDPlugin::handleLocation(const double& lat, const double& lon, const bool emit longitudeUpdated(); emit inFenceUpdated(); - QList location; - location.append(lat); - location.append(lon); - QVariant locationVariant; - locationVariant.setValue>(location); + QVariantMap location; + location.insert("latitude", lat); + location.insert("longitude", lon); emit action("SYSTEM::GPSInFence", inFence); - emit action("SYSTEM::GPSLocation", locationVariant); + emit action("SYSTEM::GPSLocation", location); } QObject *GPSDPlugin::getContextProperty(){ From 61573d62815383e8bd21d59fb9481a29cfc4d14d Mon Sep 17 00:00:00 2001 From: Asela Date: Thu, 19 Oct 2023 01:35:56 +1100 Subject: [PATCH 08/10] Changed messaging structure Messages are now only sent on change, default values for lat/lon are now invalid values (0 is a valid coordinate). --- modules/gpsd/gpsdplugin.cpp | 40 +++++++++++++++++++++---------------- modules/gpsd/gpsdplugin.h | 4 ++-- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/modules/gpsd/gpsdplugin.cpp b/modules/gpsd/gpsdplugin.cpp index a4d0293..bf7c671 100644 --- a/modules/gpsd/gpsdplugin.cpp +++ b/modules/gpsd/gpsdplugin.cpp @@ -15,25 +15,31 @@ void GPSDPlugin::init() { } void GPSDPlugin::handleMode(const int& result) { - this->m_mode = result; - emit modeUpdated(); + if(this->m_mode != result) { + this->m_mode = result; + emit modeUpdated(); + emit message("Mode", this->m_mode); + } } void GPSDPlugin::handleLocation(const double& lat, const double& lon, const bool& inFence) { - this->m_latitude = lat; - this->m_longitude = lon; - this->m_inFence = inFence; - - emit latitudeUpdated(); - emit longitudeUpdated(); - emit inFenceUpdated(); - - QVariantMap location; - location.insert("latitude", lat); - location.insert("longitude", lon); - - emit action("SYSTEM::GPSInFence", inFence); - emit action("SYSTEM::GPSLocation", location); + if(this->m_latitude != lat || this->m_longitude != lon) { + this->m_latitude = lat; + this->m_longitude = lon; + emit latitudeUpdated(); + emit longitudeUpdated(); + + QVariantMap location; + location.insert("latitude", this->m_latitude); + location.insert("longitude", this->m_longitude); + emit message("Location", location); + + if(this->m_inFence != inFence) { + this->m_inFence = inFence; + emit inFenceUpdated(); + emit message("InFence", inFence); + } + } } QObject *GPSDPlugin::getContextProperty(){ @@ -130,7 +136,7 @@ bool GPSDWorker::pointInPolygon(double lat, double lon) { void GPSDWorker::procData(struct gps_data_t * gps) { if (gps->set & MODE_SET) { emit mode(gps->fix.mode); - if(gps->fix.mode > MODE_2D) { + if(gps->fix.mode >= MODE_2D) { if(gps->set & LATLON_SET) emit location(gps->fix.latitude, gps->fix.longitude, pointInPolygon(gps->fix.latitude, gps->fix.longitude)); } diff --git a/modules/gpsd/gpsdplugin.h b/modules/gpsd/gpsdplugin.h index e959f03..ee8a75f 100644 --- a/modules/gpsd/gpsdplugin.h +++ b/modules/gpsd/gpsdplugin.h @@ -55,8 +55,8 @@ private slots: quint32 m_port = 0; QThread workerThread; int m_mode = 0; - double m_latitude = 0; - double m_longitude = 0; + double m_latitude = -91; + double m_longitude = -181; bool m_inFence = false; void stopWorker(); void startWorker(); From 3b4b940e2ba7f575cd51d34d56d1ae0f43c44ae2 Mon Sep 17 00:00:00 2001 From: Asela Date: Thu, 19 Oct 2023 19:20:25 +1100 Subject: [PATCH 09/10] Added more data --- modules/gpsd/gpsdplugin.cpp | 64 +++++++++++++++++++++++++++++++++---- modules/gpsd/gpsdplugin.h | 20 ++++++++++++ 2 files changed, 78 insertions(+), 6 deletions(-) diff --git a/modules/gpsd/gpsdplugin.cpp b/modules/gpsd/gpsdplugin.cpp index bf7c671..a2fac89 100644 --- a/modules/gpsd/gpsdplugin.cpp +++ b/modules/gpsd/gpsdplugin.cpp @@ -23,7 +23,7 @@ void GPSDPlugin::handleMode(const int& result) { } void GPSDPlugin::handleLocation(const double& lat, const double& lon, const bool& inFence) { - if(this->m_latitude != lat || this->m_longitude != lon) { + if((this->m_latitude != lat || this->m_longitude != lon) && this->m_mode >= MODE_2D) { this->m_latitude = lat; this->m_longitude = lon; emit latitudeUpdated(); @@ -32,6 +32,10 @@ void GPSDPlugin::handleLocation(const double& lat, const double& lon, const bool QVariantMap location; location.insert("latitude", this->m_latitude); location.insert("longitude", this->m_longitude); + location.insert("track", this->m_track); + location.insert("speed", this->m_speed); + location.insert("altitude", this->m_altitude); + location.insert("herr", this->m_herr); emit message("Location", location); if(this->m_inFence != inFence) { @@ -42,6 +46,34 @@ void GPSDPlugin::handleLocation(const double& lat, const double& lon, const bool } } +void GPSDPlugin::handleTrack(const double& track) { + if(this->m_track != track) { + this->m_track = track; + emit trackUpdated(); + } +} + +void GPSDPlugin::handleSpeed(const double& speed) { + if(this->m_speed != speed) { + this->m_speed = speed; + emit speedUpdated(); + } +} + +void GPSDPlugin::handleAltitude(const double& altitude) { + if(this->m_altitude != altitude) { + this->m_altitude = altitude; + emit altitudeUpdated(); + } +} + +void GPSDPlugin::handleHERR(const double& herr) { + if(this->m_herr != herr) { + this->m_herr = herr; + emit herrUpdated(); + } +} + QObject *GPSDPlugin::getContextProperty(){ return this; } @@ -88,6 +120,10 @@ void GPSDPlugin::startWorker() { connect(this, &GPSDPlugin::operate, worker, &GPSDWorker::connect); connect(worker, &GPSDWorker::mode, this, &GPSDPlugin::handleMode); connect(worker, &GPSDWorker::location, this, &GPSDPlugin::handleLocation); + connect(worker, &GPSDWorker::track, this, &GPSDPlugin::handleTrack); + connect(worker, &GPSDWorker::speed, this, &GPSDPlugin::handleSpeed); + connect(worker, &GPSDWorker::altitude, this, &GPSDPlugin::handleAltitude); + connect(worker, &GPSDWorker::herr, this, &GPSDPlugin::handleHERR); workerThread.start(); operate(m_host, m_port, m_fence); qDebug() << "GPSD: Started worker thread: " << workerThread.isRunning(); @@ -134,13 +170,29 @@ bool GPSDWorker::pointInPolygon(double lat, double lon) { } void GPSDWorker::procData(struct gps_data_t * gps) { +//TRACK_SET //bearing +//SPEED_SET//speed +//ALTITUDE_SET//atltitude +//HERR_SET//accuracy + if (gps->set & MODE_SET) { emit mode(gps->fix.mode); - if(gps->fix.mode >= MODE_2D) { - if(gps->set & LATLON_SET) - emit location(gps->fix.latitude, gps->fix.longitude, pointInPolygon(gps->fix.latitude, gps->fix.longitude)); - } + if(gps->fix.mode >= MODE_2D && gps->set & LATLON_SET) + emit location(gps->fix.latitude, gps->fix.longitude, pointInPolygon(gps->fix.latitude, gps->fix.longitude)); } + + if(gps->set & TRACK_SET) + emit track(gps->fix.track); + + if(gps->set & ALTITUDE_SET) + emit altitude(gps->fix.altitude); + + if(gps->set & SPEED_SET) + emit speed(gps->fix.speed); + + if(gps->set & HERR_SET) + emit herr(gps->fix.eph); + } void GPSDWorker::getData(std::string host, uint32_t port) { @@ -154,7 +206,7 @@ void GPSDWorker::getData(std::string host, uint32_t port) { if (gps_rec.stream(WATCH_ENABLE|WATCH_JSON) == NULL) { qDebug() << "GPSD: No GPSD running.\n"; - QThread::sleep(1); + return; } while(stopClient == false && QThread::currentThread()->isInterruptionRequested() == false) { diff --git a/modules/gpsd/gpsdplugin.h b/modules/gpsd/gpsdplugin.h index ee8a75f..0cd87e5 100644 --- a/modules/gpsd/gpsdplugin.h +++ b/modules/gpsd/gpsdplugin.h @@ -24,6 +24,10 @@ class GPSDPlugin : public QObject, PluginInterface Q_PROPERTY(double longitude MEMBER m_longitude NOTIFY longitudeUpdated) Q_PROPERTY(double latitude MEMBER m_latitude NOTIFY latitudeUpdated) Q_PROPERTY(bool inFence MEMBER m_inFence NOTIFY inFenceUpdated) + Q_PROPERTY(double track MEMBER m_track NOTIFY trackUpdated) + Q_PROPERTY(double speed MEMBER m_speed NOTIFY speedUpdated) + Q_PROPERTY(double altitude MEMBER m_altitude NOTIFY altitudeUpdated) + Q_PROPERTY(double herr MEMBER m_latitude NOTIFY herrUpdated) public: explicit GPSDPlugin(QObject *parent = nullptr); @@ -37,6 +41,10 @@ public slots: void eventMessage(QString id, QVariant message) override; void handleMode(const int& result); void handleLocation(const double& lat, const double& lon, const bool& inFence); + void handleTrack(const double& track); + void handleSpeed(const double& speed); + void handleAltitude(const double& altitude); + void handleHERR(const double& herr); signals: void message(QString id, QVariant message); @@ -46,6 +54,10 @@ public slots: void longitudeUpdated(); void latitudeUpdated(); void inFenceUpdated(); + void trackUpdated(); + void speedUpdated(); + void altitudeUpdated(); + void herrUpdated(); private slots: void settingsChanged(const QString &key, const QVariant &value); @@ -58,6 +70,10 @@ private slots: double m_latitude = -91; double m_longitude = -181; bool m_inFence = false; + double m_track = 0; + double m_speed = 0; + double m_altitude = 0; + double m_herr = 0; void stopWorker(); void startWorker(); @@ -80,6 +96,10 @@ public slots: signals: void mode(const int& result); void location(const double& latitude, const double& longitude, const bool& inFence); + void track(const double& track); + void speed(const double& speed); + void altitude(const double& altitude); + void herr(const double& herr); }; From 390c91d0465ec81b67401b36e240daa31220af0b Mon Sep 17 00:00:00 2001 From: Asela Date: Fri, 20 Oct 2023 10:02:30 +1100 Subject: [PATCH 10/10] Changed Horizontal Error reporting --- modules/gpsd/gpsdplugin.cpp | 33 +++++++++++++++++++-------------- modules/gpsd/gpsdplugin.h | 16 +++++++++++----- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/modules/gpsd/gpsdplugin.cpp b/modules/gpsd/gpsdplugin.cpp index a2fac89..4750df8 100644 --- a/modules/gpsd/gpsdplugin.cpp +++ b/modules/gpsd/gpsdplugin.cpp @@ -35,7 +35,9 @@ void GPSDPlugin::handleLocation(const double& lat, const double& lon, const bool location.insert("track", this->m_track); location.insert("speed", this->m_speed); location.insert("altitude", this->m_altitude); - location.insert("herr", this->m_herr); + location.insert("epx", this->m_epx); + location.insert("epy", this->m_epy); + location.insert("eph", this->m_eph); emit message("Location", location); if(this->m_inFence != inFence) { @@ -46,6 +48,21 @@ void GPSDPlugin::handleLocation(const double& lat, const double& lon, const bool } } +void GPSDPlugin::handleHERR(const double& epx, const double &epy, const double &eph) { + if(this->m_epx != epx) { + this->m_epx = epx; + emit epxUpdated(); + } + if(this->m_epy != epy) { + this->m_epy = epy; + emit epyUpdated(); + } + if(this->m_eph != eph) { + this->m_eph = eph; + emit ephUpdated(); + } +} + void GPSDPlugin::handleTrack(const double& track) { if(this->m_track != track) { this->m_track = track; @@ -67,13 +84,6 @@ void GPSDPlugin::handleAltitude(const double& altitude) { } } -void GPSDPlugin::handleHERR(const double& herr) { - if(this->m_herr != herr) { - this->m_herr = herr; - emit herrUpdated(); - } -} - QObject *GPSDPlugin::getContextProperty(){ return this; } @@ -170,11 +180,6 @@ bool GPSDWorker::pointInPolygon(double lat, double lon) { } void GPSDWorker::procData(struct gps_data_t * gps) { -//TRACK_SET //bearing -//SPEED_SET//speed -//ALTITUDE_SET//atltitude -//HERR_SET//accuracy - if (gps->set & MODE_SET) { emit mode(gps->fix.mode); if(gps->fix.mode >= MODE_2D && gps->set & LATLON_SET) @@ -191,7 +196,7 @@ void GPSDWorker::procData(struct gps_data_t * gps) { emit speed(gps->fix.speed); if(gps->set & HERR_SET) - emit herr(gps->fix.eph); + emit herr(gps->fix.epx, gps->fix.epy, gps->fix.eph); } diff --git a/modules/gpsd/gpsdplugin.h b/modules/gpsd/gpsdplugin.h index 0cd87e5..5e78cc4 100644 --- a/modules/gpsd/gpsdplugin.h +++ b/modules/gpsd/gpsdplugin.h @@ -27,7 +27,9 @@ class GPSDPlugin : public QObject, PluginInterface Q_PROPERTY(double track MEMBER m_track NOTIFY trackUpdated) Q_PROPERTY(double speed MEMBER m_speed NOTIFY speedUpdated) Q_PROPERTY(double altitude MEMBER m_altitude NOTIFY altitudeUpdated) - Q_PROPERTY(double herr MEMBER m_latitude NOTIFY herrUpdated) + Q_PROPERTY(double epx MEMBER m_epx NOTIFY epxUpdated) + Q_PROPERTY(double epy MEMBER m_epy NOTIFY epyUpdated) + Q_PROPERTY(double eph MEMBER m_eph NOTIFY ephUpdated) public: explicit GPSDPlugin(QObject *parent = nullptr); @@ -44,7 +46,7 @@ public slots: void handleTrack(const double& track); void handleSpeed(const double& speed); void handleAltitude(const double& altitude); - void handleHERR(const double& herr); + void handleHERR(const double& epx, const double& epy, const double& eph); signals: void message(QString id, QVariant message); @@ -57,7 +59,9 @@ public slots: void trackUpdated(); void speedUpdated(); void altitudeUpdated(); - void herrUpdated(); + void epxUpdated(); + void epyUpdated(); + void ephUpdated(); private slots: void settingsChanged(const QString &key, const QVariant &value); @@ -73,7 +77,9 @@ private slots: double m_track = 0; double m_speed = 0; double m_altitude = 0; - double m_herr = 0; + double m_epx = 0; + double m_epy = 0; + double m_eph = 0; void stopWorker(); void startWorker(); @@ -99,7 +105,7 @@ public slots: void track(const double& track); void speed(const double& speed); void altitude(const double& altitude); - void herr(const double& herr); + void herr(const double& epx, const double& epy, const double& eph); };