]> git.street.me.uk Git - andy/viking.git/blobdiff - src/datasource_gps.c
Improve documentation of background.c
[andy/viking.git] / src / datasource_gps.c
index e7de72e27fbf8fb6dadc75777b95ca9899aed009..3e6ccced7c861e555321d3dc3bf07c251a1fcf01 100644 (file)
@@ -2,6 +2,8 @@
  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
  *
  * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
  *
  * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
+ * Copyright (C) 2006, Alex Foobarian <foobarian@gmail.com>
+ * Copyright (C) 2010, Rob Norris <rw_norris@hotmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include "config.h"
 #endif
 #include <string.h>
 #include "config.h"
 #endif
 #include <string.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 
 
+#include <glib/gstdio.h>
 #include <glib/gprintf.h>
 #include <glib/gi18n.h>
 
 #include <glib/gprintf.h>
 #include <glib/gi18n.h>
 
@@ -52,6 +58,7 @@ VikDataSourceInterface vik_datasource_gps_interface = {
   VIK_DATASOURCE_CREATENEWLAYER,
   VIK_DATASOURCE_INPUTTYPE_NONE,
   TRUE,
   VIK_DATASOURCE_CREATENEWLAYER,
   VIK_DATASOURCE_INPUTTYPE_NONE,
   TRUE,
+  TRUE,
   (VikDataSourceInitFunc)              datasource_gps_init_func,
   (VikDataSourceCheckExistenceFunc)    NULL,
   (VikDataSourceAddSetupWidgetsFunc)   datasource_gps_add_setup_widgets,
   (VikDataSourceInitFunc)              datasource_gps_init_func,
   (VikDataSourceCheckExistenceFunc)    NULL,
   (VikDataSourceAddSetupWidgetsFunc)   datasource_gps_add_setup_widgets,
@@ -119,9 +126,15 @@ static void datasource_gps_get_cmd_string ( gpointer user_data, gchar **babelarg
 #endif
   if (!strcmp(proto, "Garmin")) {
     device = "garmin";
 #endif
   if (!strcmp(proto, "Garmin")) {
     device = "garmin";
-  } else {
+  } else if (!strcmp(proto, "Magellan")) {
     device = "magellan";
   }
     device = "magellan";
   }
+  else if (!strcmp(proto, "DeLorme")) {
+    device = "delbin";
+  }
+  else {
+    device = "navilink";
+  }
 
   *babelargs = g_strdup_printf("-D 9 -t -w -i %s", device);
   /* device points to static content => no free */
 
   *babelargs = g_strdup_printf("-D 9 -t -w -i %s", device);
   /* device points to static content => no free */
@@ -165,7 +178,11 @@ static void datasource_gps_off ( gpointer user_data, gchar **babelargs, gchar **
 #endif
   if (!strcmp(proto, "Garmin")) {
     device = "garmin,power_off";
 #endif
   if (!strcmp(proto, "Garmin")) {
     device = "garmin,power_off";
-  } else {
+  }
+  else if (!strcmp(proto, "NAViLink")) {
+    device = "navilink,power_off";
+  }
+  else {
     return;
   }
 
     return;
   }
 
@@ -281,6 +298,18 @@ static void datasource_gps_progress ( BabelProgressCode c, gpointer data, acq_di
       }
       g_strfreev(tokens);
     }
       }
       g_strfreev(tokens);
     }
+    /* eg: "Unit:\teTrex Legend HCx Software Version 2.90\n" */
+    if (strstr(line, "Unit:")) {
+      gchar **tokens = g_strsplit(line, "\t", 0);
+      int n_tokens = 0;
+      while (tokens[n_tokens])
+        n_tokens++;
+
+      if (n_tokens > 1) {
+        set_gps_info(tokens[1], w);
+      }
+      g_strfreev(tokens);
+    }
     if (strstr(line, "RECORD")) { 
       int lsb, msb, cnt;
 
     if (strstr(line, "RECORD")) { 
       int lsb, msb, cnt;
 
@@ -313,6 +342,8 @@ void datasource_gps_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpo
   w->proto_b = GTK_COMBO_BOX(gtk_combo_box_new_text ());
   gtk_combo_box_append_text (w->proto_b, "Garmin");
   gtk_combo_box_append_text (w->proto_b, "Magellan");
   w->proto_b = GTK_COMBO_BOX(gtk_combo_box_new_text ());
   gtk_combo_box_append_text (w->proto_b, "Garmin");
   gtk_combo_box_append_text (w->proto_b, "Magellan");
+  gtk_combo_box_append_text (w->proto_b, "DeLorme");
+  gtk_combo_box_append_text (w->proto_b, "NAViLink");
   gtk_combo_box_set_active (w->proto_b, 0);
   g_object_ref(w->proto_b);
 
   gtk_combo_box_set_active (w->proto_b, 0);
   g_object_ref(w->proto_b);
 
@@ -321,16 +352,23 @@ void datasource_gps_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpo
 #ifdef WINDOWS
   gtk_combo_box_append_text (w->ser_b, "com1");
 #else
 #ifdef WINDOWS
   gtk_combo_box_append_text (w->ser_b, "com1");
 #else
-  gtk_combo_box_append_text (w->ser_b, "/dev/ttyS0");
-  gtk_combo_box_append_text (w->ser_b, "/dev/ttyS1");
-  gtk_combo_box_append_text (w->ser_b, "/dev/ttyUSB0");
-  gtk_combo_box_append_text (w->ser_b, "/dev/ttyUSB1");
+  /* Here just try to see if the device is available which gets passed onto gpsbabel
+     List USB devices first as these will generally only be present if autogenerated by udev or similar
+     User is still able to set their own free text entry */
+  if (g_access ("/dev/ttyUSB0", R_OK) == 0)
+    gtk_combo_box_append_text (w->ser_b, "/dev/ttyUSB0");
+  if (g_access ("/dev/ttyUSB1", R_OK) == 0)
+    gtk_combo_box_append_text (w->ser_b, "/dev/ttyUSB1");
+  if (g_access ("/dev/ttyS0", R_OK) == 0)
+    gtk_combo_box_append_text (w->ser_b, "/dev/ttyS0");
+  if (g_access ("/dev/ttyS1", R_OK) == 0)
+    gtk_combo_box_append_text (w->ser_b, "/dev/ttyS1");
 #endif
   gtk_combo_box_append_text (w->ser_b, "usb:");
   gtk_combo_box_set_active (w->ser_b, 0);
   g_object_ref(w->ser_b);
 
 #endif
   gtk_combo_box_append_text (w->ser_b, "usb:");
   gtk_combo_box_set_active (w->ser_b, 0);
   g_object_ref(w->ser_b);
 
-  w->off_request_l = gtk_label_new (_("Turn Off After Transfer\n(Garmin Only)"));
+  w->off_request_l = gtk_label_new (_("Turn Off After Transfer\n(Garmin/NAViLink Only)"));
   w->off_request_b = GTK_CHECK_BUTTON ( gtk_check_button_new () );
 
   box = GTK_TABLE(gtk_table_new(2, 3, FALSE));
   w->off_request_b = GTK_CHECK_BUTTON ( gtk_check_button_new () );
 
   box = GTK_TABLE(gtk_table_new(2, 3, FALSE));