add:core:GPX logs now include the current profile name of the logging vehicle
authorbustersnyvel <bustersnyvel@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 26 Jul 2009 20:12:15 +0000 (20:12 +0000)
committerbustersnyvel <bustersnyvel@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 26 Jul 2009 20:12:15 +0000 (20:12 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@2405 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/log.c
navit/log.h
navit/vehicle.c
navit/vehicle/gpsd/vehicle_gpsd.c

index fdba147..95b34e6 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <unistd.h>
 #include <fcntl.h>
+#include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -291,6 +292,22 @@ log_write(struct log *this_, char *data, int len)
 }
 
 void
+log_printf(struct log *this_, char *fmt, ...)
+{
+       char buffer[LOG_BUFFER_SIZE];
+       int size;
+       va_list ap;
+
+       va_start(ap, fmt);
+
+       // Format the string and write it to the log
+       size = vsnprintf(buffer, LOG_BUFFER_SIZE, fmt, ap);
+       log_write(this_, buffer, size);
+
+       va_end(ap);
+}
+
+void
 log_destroy(struct log *this_)
 {
        callback_destroy(this_->timer_callback);
index f17e90c..edb4433 100644 (file)
@@ -30,5 +30,14 @@ void log_set_header(struct log *this_, char *data, int len);
 void log_set_trailer(struct log *this_, char *data, int len);
 void log_write(struct log *this_, char *data, int len);
 void log_destroy(struct log *this_);
+
+#define LOG_BUFFER_SIZE 256
+/**
+ * printf-style writing to the log file. A buffer of LOG_BUFFER_SIZE
+ * bytes is preallocated for the complete format message, longer
+ * messages will be truncated.
+ */
+void log_printf(struct log *this_, char *fmt, ...);
+
 /* end of prototypes */
 #endif
index 7c63e84..e6f871d 100644 (file)
@@ -55,7 +55,7 @@ vehicle_log_gpx(struct vehicle *this_, struct log *log)
 {
        struct attr pos_attr;
        struct attr time_attr;
-       char buffer[256];
+       struct attr *profile_attr;
        char *timep;
        int free=0;
 
@@ -69,9 +69,21 @@ vehicle_log_gpx(struct vehicle *this_, struct log *log)
        } else {
                timep = time_attr.u.str;
        }
-       sprintf(buffer,"<trkpt lat=\"%f\" lon=\"%f\">\n\t<time>%s</time>\n</trkpt>\n",
-               pos_attr.u.coord_geo->lat, pos_attr.u.coord_geo->lng, timep);
-       log_write(log, buffer, strlen(buffer));
+
+       // get the profile name attribute
+       profile_attr = attr_search(this_->attrs, NULL, attr_profilename);
+
+       log_printf(log,
+                       "<trkpt lat=\"%f\" lon=\"%f\">\n"
+                       "\t<time>%s</time>\n"
+                       "\t<extensions><navit:profilename>%s</navit:profilename></extensions>\n"
+                       "</trkpt>\n",
+               pos_attr.u.coord_geo->lat,
+               pos_attr.u.coord_geo->lng,
+               timep,
+               profile_attr->u.str
+       );
+
        if (free)
                g_free(timep);
 }
@@ -100,8 +112,14 @@ vehicle_add_log(struct vehicle *this_, struct log *log)
        if (!strcmp(type_attr.u.str, "nmea")) {
                cb=callback_new_2(callback_cast(vehicle_log_nmea), this_, log);
        } else if (!strcmp(type_attr.u.str, "gpx")) {
-               char *header =
-                   "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<gpx version=\"1.0\" creator=\"Navit http://navit.sourceforge.net\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.topografix.com/GPX/1/0\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\n<trk>\n<trkseg>\n";
+               char *header = "<?xml version='1.0' encoding='UTF-8'?>\n"
+                       "<gpx version='1.1' creator='Navit http://navit.sourceforge.net'\n"
+                       "     xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"
+                       "     xmlns:navit='http://www.navit-project.org/schema/navit'\n"
+                       "     xmlns='http://www.topografix.com/GPX/1/1'\n"
+                       "     xsi:schemaLocation='http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd'>\n"
+                       "<trk>\n"
+                       "<trkseg>\n";
                char *trailer = "</trkseg>\n</trk>\n</gpx>\n";
                log_set_header(log, header, strlen(header));
                log_set_trailer(log, trailer, strlen(trailer));
index f2e0a5b..88a50a4 100644 (file)
@@ -51,7 +51,7 @@ static struct vehicle_priv {
        int fix_type;
        time_t fix_time;
        int sats;
-        int sats_signal;
+       int sats_signal;
        int sats_used;
        char *nmea_data;
        char *nmea_data_buf;