Commit 1ed9d3df authored by Angus Ainslie's avatar Angus Ainslie
Browse files

debian/patches/pureos: add VTG patches



Cache and use VTG sentences from GNSS device if they are available
If there are no VTG messages the calculate speed and heading from
GGA messages.
Signed-off-by: default avatarAngus Ainslie <angus@akkea.ca>
parent 4ff2032f
Pipeline #70817 passed with stages
in 3 minutes and 37 seconds
From 8719387d45da48353e103ec4aedd70cefec5a036 Mon Sep 17 00:00:00 2001
From: Angus Ainslie <angus@akkea.ca>
Date: Tue, 31 Aug 2021 12:35:56 -0700
Subject: [PATCH 1/4] gclue-location.c: parse VTG messages
Parse the heading and speed from the VTG message.
Signed-off-by: Angus Ainslie <angus@akkea.ca>
---
src/gclue-location.c | 53 ++++++++++++++++++++++++++++++++++++++++++++
src/gclue-location.h | 4 ++++
2 files changed, 57 insertions(+)
diff --git a/src/gclue-location.c b/src/gclue-location.c
index 3190f6e..6b7bf8b 100644
--- a/src/gclue-location.c
+++ b/src/gclue-location.c
@@ -656,6 +656,59 @@ out:
return location;
}
+/**
+ * gclue_location_create_from_vtg:
+ * @gga: NMEA VTG sentence
+ * @error: Place-holder for errors.
+ *
+ * Creates a new #GClueLocation object from a VTG sentence.
+ *
+ * Returns: a new #GClueLocation object, or %NULL on error. Unref using
+ * #g_object_unref() when done with it.
+ **/
+GClueLocation *
+gclue_location_create_from_vtg (const char *vtg, GError **error)
+{
+ GClueLocation *location = NULL;
+ gdouble heading, speed, speedMS;
+ char **parts;
+
+ parts = g_strsplit (vtg, ",", -1);
+ if (g_strv_length (parts) < 8) {
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ "Invalid NMEA VTG sentence");
+ goto out;
+ }
+
+ if (parts[2][0] == 'T')
+ heading = g_ascii_strtod (parts[1], NULL); /* true north heading */
+ else if (parts[4][0] == 'M')
+ heading = g_ascii_strtod (parts[3], NULL); /* magnetic north heading */
+
+ if (parts[8][0] == 'K') {
+ speed = g_ascii_strtod (parts[7], NULL); /* speed in KPH */
+ speedMS = speed * 1000. / 3600.0;
+ } else if (parts[6][0] == 'N') {
+ speed = g_ascii_strtod (parts[5], NULL); /* speed in knots */
+ speedMS = speed / 1.944;
+ }
+
+ location = g_object_new (GCLUE_TYPE_LOCATION,
+ NULL);
+
+ g_object_set (location, "speed", speedMS, NULL);
+ g_debug ("vtg heading %f", heading);
+ g_object_set (location, "heading", heading, NULL);
+ g_debug ("vtg speed %f", speedMS);
+
+
+out:
+ g_strfreev (parts);
+ return location;
+}
+
/**
* gclue_location_duplicate:
* @location: the #GClueLocation instance to duplicate.
diff --git a/src/gclue-location.h b/src/gclue-location.h
index 00b18bb..7d836e1 100644
--- a/src/gclue-location.h
+++ b/src/gclue-location.h
@@ -141,6 +141,10 @@ GClueLocation *gclue_location_create_from_gga
(const char *gga,
GError **error);
+GClueLocation *gclue_location_create_from_vtg
+ (const char *vtg,
+ GError **error);
+
GClueLocation *gclue_location_duplicate
(GClueLocation *location);
--
2.25.1
From ee432be348a36c14f6f0c65f6644406f61324d04 Mon Sep 17 00:00:00 2001
From: Angus Ainslie <angus@akkea.ca>
Date: Tue, 31 Aug 2021 12:37:19 -0700
Subject: [PATCH 2/4] gclue-nmea-source.c: add VTG handling
Handle VTG messages for heading and speed.
Signed-off-by: Angus Ainslie <angus@akkea.ca>
---
src/gclue-nmea-source.c | 48 +++++++++++++++++++++++++----------------
1 file changed, 30 insertions(+), 18 deletions(-)
diff --git a/src/gclue-nmea-source.c b/src/gclue-nmea-source.c
index c57da68..5505404 100644
--- a/src/gclue-nmea-source.c
+++ b/src/gclue-nmea-source.c
@@ -47,6 +47,8 @@ struct _GClueNMEASourcePrivate {
AvahiServiceInfo *active_service;
+ GClueLocation *vtg_loc;
+
/* List of all services but only the most accurate one is used. */
GList *all_services;
};
@@ -443,14 +445,14 @@ browse_callback (AvahiServiceBrowser *service_browser,
}
static void
-on_read_gga_sentence (GObject *object,
+on_read_nmea_sentence (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
GClueNMEASource *source = GCLUE_NMEA_SOURCE (user_data);
GDataInputStream *data_input_stream = G_DATA_INPUT_STREAM (object);
GError *error = NULL;
- GClueLocation *location;
+ GClueLocation *location = NULL;
gsize data_size = 0 ;
char *message;
@@ -482,24 +484,34 @@ on_read_gga_sentence (GObject *object,
}
g_debug ("Network source sent: \"%s\"", message);
- if (!g_str_has_prefix (message, "$GAGGA") && /* Galieo */
- !g_str_has_prefix (message, "$GBGGA") && /* BeiDou */
- !g_str_has_prefix (message, "$BDGGA") && /* BeiDou */
- !g_str_has_prefix (message, "$GLGGA") && /* GLONASS */
- !g_str_has_prefix (message, "$GNGGA") && /* GNSS (combined) */
- !g_str_has_prefix (message, "$GPGGA") && /* GPS, SBAS, QZSS */
- !g_str_has_prefix (message, "$QZGGA")) { /* QZSS */
- g_debug ("Ignoring non-GGA sentence from NMEA source");
-
- goto READ_NEXT_LINE;
- }
-
- location = gclue_location_create_from_gga (message, &error);
+ if (g_str_has_prefix (message, "$GAGGA") || /* Galieo */
+ g_str_has_prefix (message, "$GBGGA") || /* BeiDou */
+ g_str_has_prefix (message, "$BDGGA") || /* BeiDou */
+ g_str_has_prefix (message, "$GLGGA") || /* GLONASS */
+ g_str_has_prefix (message, "$GNGGA") || /* GNSS (combined) */
+ g_str_has_prefix (message, "$GPGGA") || /* GPS, SBAS, QZSS */
+ g_str_has_prefix (message, "$QZGGA")) { /* QZSS */
+ g_debug ("reading GGA sentence from NMEA source");
+
+ location = gclue_location_create_from_gga (message, &error);
+ } else if (g_str_has_prefix (message, "$GAVTG") || /* Galieo */
+ g_str_has_prefix (message, "$GBVTG") || /* BeiDou */
+ g_str_has_prefix (message, "$BDVTG") || /* BeiDou */
+ g_str_has_prefix (message, "$GLVTG") || /* GLONASS */
+ g_str_has_prefix (message, "$GNVTG") || /* GNSS (combined) */
+ g_str_has_prefix (message, "$GPVTG") || /* GPS, SBAS, QZSS */
+ g_str_has_prefix (message, "$QZVTG")) { /* QZSS */
+ g_debug ("reading VTG sentence from NMEA source");
+
+ source->priv->vtg_loc = gclue_location_create_from_vtg (message, &error);
+ } else {
+ g_debug ("ignoring sentence from NMEA source");
+ }
if (error != NULL) {
g_warning ("Error: %s", error->message);
g_clear_error (&error);
- } else {
+ } else if (location != NULL) {
gclue_location_source_set_location
(GCLUE_LOCATION_SOURCE (source), location);
}
@@ -508,7 +520,7 @@ READ_NEXT_LINE:
g_data_input_stream_read_line_async (data_input_stream,
G_PRIORITY_DEFAULT,
source->priv->cancellable,
- on_read_gga_sentence,
+ on_read_nmea_sentence,
source);
}
@@ -543,7 +555,7 @@ on_connection_to_location_server (GObject *object,
g_data_input_stream_read_line_async (data_input_stream,
G_PRIORITY_DEFAULT,
source->priv->cancellable,
- on_read_gga_sentence,
+ on_read_nmea_sentence,
source);
}
--
2.25.1
From 6bac9170232a026e51cb52be1d36eba08326522b Mon Sep 17 00:00:00 2001
From: Angus Ainslie <angus@akkea.ca>
Date: Fri, 3 Sep 2021 07:07:37 -0700
Subject: [PATCH 3/4] gclue-nmea-source.c: calculate speed and heading instead
of vtg
Signed-off-by: Angus Ainslie <angus@akkea.ca>
---
src/gclue-nmea-source.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/src/gclue-nmea-source.c b/src/gclue-nmea-source.c
index 5505404..8a5a736 100644
--- a/src/gclue-nmea-source.c
+++ b/src/gclue-nmea-source.c
@@ -452,9 +452,10 @@ on_read_nmea_sentence (GObject *object,
GClueNMEASource *source = GCLUE_NMEA_SOURCE (user_data);
GDataInputStream *data_input_stream = G_DATA_INPUT_STREAM (object);
GError *error = NULL;
- GClueLocation *location = NULL;
+ GClueLocation *location = NULL, *prev_location;
gsize data_size = 0 ;
char *message;
+ gdouble speed, heading;
message = g_data_input_stream_read_line_finish (data_input_stream,
result,
@@ -512,11 +513,39 @@ on_read_nmea_sentence (GObject *object,
g_warning ("Error: %s", error->message);
g_clear_error (&error);
} else if (location != NULL) {
+ g_debug ("updating location from NMEA source");
+ prev_location = gclue_location_source_get_location (GCLUE_LOCATION_SOURCE (source));
+ if (source->priv->vtg_loc && speed != GCLUE_LOCATION_SPEED_UNKNOWN) {
+ /* trust the vtg speed */
+ speed = gclue_location_get_speed (source->priv->vtg_loc);
+
+ gclue_location_set_speed (location, speed);
+ g_debug ("vtg speed %f", speed);
+ } else {
+ gclue_location_set_speed_from_prev_location (location, prev_location);
+ speed = gclue_location_get_speed (location);
+ g_debug ("prev loc speed %f", speed);
+ }
+
+ if (source->priv->vtg_loc && heading != GCLUE_LOCATION_HEADING_UNKNOWN) {
+ /* trust the vtg heading */
+ heading = gclue_location_get_heading (source->priv->vtg_loc);
+
+ gclue_location_set_heading (location, heading);
+ g_debug ("vtg heading %f", heading);
+ } else {
+ gclue_location_set_heading_from_prev_location (location, prev_location);
+ heading = gclue_location_get_heading (location);
+ g_debug ("prev loc heading %f", heading);
+ }
+
gclue_location_source_set_location
(GCLUE_LOCATION_SOURCE (source), location);
}
READ_NEXT_LINE:
+ g_debug ("setting callback for next line");
+
g_data_input_stream_read_line_async (data_input_stream,
G_PRIORITY_DEFAULT,
source->priv->cancellable,
--
2.25.1
From 3b3275067ecffe90b7c716d30a6f073b9daf6309 Mon Sep 17 00:00:00 2001
From: Angus Ainslie <angus@akkea.ca>
Date: Mon, 6 Sep 2021 11:53:38 -0700
Subject: [PATCH 4/4] gclue-location.c: Accuracy should never be 0
Signed-off-by: Angus Ainslie <angus@akkea.ca>
---
src/gclue-location.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/gclue-location.c b/src/gclue-location.c
index 6b7bf8b..4001ee8 100644
--- a/src/gclue-location.c
+++ b/src/gclue-location.c
@@ -407,7 +407,7 @@ get_accuracy_from_hdop (gdouble hdop)
* http://en.wikipedia.org/wiki/Dilution_of_precision_%28GPS%29#Meaning_of_DOP_Values
*/
if (hdop <= 1)
- return 0;
+ return 0.3;
else if (hdop <= 2)
return 1;
else if (hdop <= 5)
--
2.25.1
......@@ -15,3 +15,7 @@ pureos/0002-src-gclue-nmea-source.c-add-a-unix-socket-file-optio.patch
pureos/0003-src-gclue-nmea-source.c-add-the-Unix-socket-nmea-sou.patch
pureos/0004-gclue-config-read-nmea-socket-from-config-file.patch
pureos/geoclue.conf.in-add-a-unix-socket-option.patch
pureos/0001-gclue-location.c-parse-VTG-messages.patch
pureos/0002-gclue-nmea-source.c-add-VTG-handling.patch
pureos/0003-gclue-nmea-source.c-calculate-speed-and-heading-inst.patch
pureos/0004-gclue-location.c-Accuracy-should-never-be-0.patch
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment