[PATCH 2/2] Add support for baud rates setting in Gypsy
Bastien Nocera
hadess at hadess.net
Wed Apr 28 09:43:00 PDT 2010
Which allows crummy GPSes like mine to function properly.
---
configure.ac | 3 ++-
providers/gypsy/geoclue-gypsy.c | 39 +++++++++++++++++++++++++++++++++++----
2 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/configure.ac b/configure.ac
index 5d2d192..999f7d9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -149,6 +149,7 @@ PROVIDER_SUBDIRS="example hostip geonames nominatim manual plazes localnet yahoo
# gypsy / gpsd / skyhook
# -----------------------------------------------------------
+GYPSY_REQUIRED=0.7.1
AC_ARG_ENABLE(gypsy,
AS_HELP_STRING([--enable-gypsy=@<:@no/yes/auto@:>@],
[build with gypsy support]), ,
@@ -157,7 +158,7 @@ AC_ARG_ENABLE(gypsy,
if test "x$enable_gypsy" != "xno"; then
PKG_CHECK_MODULES(GYPSY,
[
- gypsy
+ gypsy >= $GYPSY_REQUIRED
], have_gypsy="yes", have_gypsy="no")
if test "x$have_gypsy" = "xyes"; then
diff --git a/providers/gypsy/geoclue-gypsy.c b/providers/gypsy/geoclue-gypsy.c
index 2b67a1c..bc390ce 100644
--- a/providers/gypsy/geoclue-gypsy.c
+++ b/providers/gypsy/geoclue-gypsy.c
@@ -38,7 +38,8 @@ typedef struct {
GcProvider parent;
char *device_name;
-
+ guint baud_rate;
+
GypsyControl *control;
GypsyDevice *device;
GypsyPosition *position;
@@ -378,17 +379,28 @@ set_options (GcIfaceGeoclue *gc,
GError **error)
{
GeoclueGypsy *gypsy = GEOCLUE_GYPSY (gc);
- GValue *device_value;
+ GValue *device_value, *baud_rate_value;
const char *device_name;
char *path;
+ int baud_rate;
device_value = g_hash_table_lookup (options,
"org.freedesktop.Geoclue.GPSDevice");
device_name = device_value ? g_value_get_string (device_value) : NULL;
+ baud_rate_value = g_hash_table_lookup (options,
+ "org.freedesktop.Geoclue.GPSBaudRate");
+ baud_rate = baud_rate_value ? g_value_get_int (baud_rate_value) : 0;
- if (g_strcmp0 (gypsy->device_name, device_name) == 0)
+ if (g_strcmp0 (gypsy->device_name, device_name) == 0 &&
+ gypsy->baud_rate == baud_rate)
return TRUE;
+ /* Disconnect from the old device, if any */
+ if (gypsy->device != NULL) {
+ g_object_unref (gypsy->device);
+ gypsy->device = NULL;
+ }
+
g_free (gypsy->device_name);
gypsy->device_name = NULL;
@@ -397,7 +409,8 @@ set_options (GcIfaceGeoclue *gc,
}
gypsy->device_name = g_strdup (device_name);
- g_print ("Gypsy provider using '%s'\n", gypsy->device_name);
+ gypsy->baud_rate = baud_rate;
+ g_print ("Gypsy provider using '%s' at %d bps\n", gypsy->device_name, gypsy->baud_rate);
path = gypsy_control_create (gypsy->control, gypsy->device_name,
error);
if (*error != NULL) {
@@ -426,6 +439,24 @@ set_options (GcIfaceGeoclue *gc,
G_CALLBACK (accuracy_changed), gypsy);
g_debug ("starting device");
+ if (gypsy->baud_rate != 0) {
+ GHashTable *goptions;
+ GValue speed_val = { 0, };
+ GError *err = NULL;
+
+ g_value_init (&speed_val, G_TYPE_UINT);
+ g_value_set_uint (&speed_val, gypsy->baud_rate);
+ goptions = g_hash_table_new (g_str_hash,
+ g_str_equal);
+ g_hash_table_insert (goptions, "BaudRate", &speed_val);
+ if (!gypsy_device_set_start_options (gypsy->device,
+ goptions,
+ &err)) {
+ g_warning ("Error: %s", err->message);
+ g_error_free (err);
+ }
+ g_hash_table_destroy (goptions);
+ }
gypsy_device_start (gypsy->device, error);
if (*error != NULL) {
g_print ("Error - %s?\n", (*error)->message);
--
1.7.0.1
--=-pko3i9kxq5x/Wypyv0In--
More information about the GeoClue
mailing list