diff options
author | bustersnyvel <bustersnyvel@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2009-07-26 20:12:15 +0000 |
---|---|---|
committer | bustersnyvel <bustersnyvel@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2009-07-26 20:12:15 +0000 |
commit | 395a74141c227c84a157e42861feb202d4a61355 (patch) | |
tree | 323af12bcfd4855ef426be98e5c57b2e02823e1c | |
parent | b126bb138207aaf249952b04ce10cee035b0858a (diff) | |
download | navit-svn-395a74141c227c84a157e42861feb202d4a61355.tar.gz |
add:core:GPX logs now include the current profile name of the logging vehicle
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit/navit@2405 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r-- | log.c | 17 | ||||
-rw-r--r-- | log.h | 9 | ||||
-rw-r--r-- | vehicle.c | 30 | ||||
-rw-r--r-- | vehicle/gpsd/vehicle_gpsd.c | 2 |
4 files changed, 51 insertions, 7 deletions
@@ -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); @@ -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 @@ -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)); diff --git a/vehicle/gpsd/vehicle_gpsd.c b/vehicle/gpsd/vehicle_gpsd.c index f2e0a5b0..88a50a41 100644 --- a/vehicle/gpsd/vehicle_gpsd.c +++ b/vehicle/gpsd/vehicle_gpsd.c @@ -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; |