summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--navit/attr.c37
-rw-r--r--navit/attr.h6
-rw-r--r--navit/attr_def.h1
-rw-r--r--navit/navit_shipped.xml2
-rw-r--r--navit/vehicle.c85
5 files changed, 81 insertions, 50 deletions
diff --git a/navit/attr.c b/navit/attr.c
index f05f9a20d..bf5ac89d5 100644
--- a/navit/attr.c
+++ b/navit/attr.c
@@ -99,6 +99,18 @@ attr_new_from_text(const char *name, const char *value)
}
g_free(type_str);
break;
+ case attr_attr_types:
+ count=0;
+ type_str=g_strdup(value);
+ str=type_str;
+ while ((tok=strtok(str, ","))) {
+ ret->u.attr_types=g_realloc(ret->u.attr_types, (count+2)*sizeof(enum attr_type));
+ ret->u.attr_types[count++]=attr_from_name(tok);
+ ret->u.attr_types[count]=attr_none;
+ str=NULL;
+ }
+ g_free(type_str);
+ break;
case attr_dash:
count=0;
type_str=g_strdup(value);
@@ -395,6 +407,11 @@ attr_data_size(struct attr *attr)
while (attr->u.item_types[i++] != type_none);
return i*sizeof(enum item_type);
}
+ if (attr->type == attr_attr_types) {
+ int i=0;
+ while (attr->u.attr_types[i++] != attr_none);
+ return i*sizeof(enum attr_type);
+ }
dbg(0,"size for %s unknown\n", attr_to_name(attr->type));
return 0;
}
@@ -544,3 +561,23 @@ attr_from_line(char *line, char *name, int *pos, char *val_ret, char *name_ret)
}
return 0;
}
+
+int
+attr_types_contains(enum attr_type *types, enum attr_type type)
+{
+ while (types && *types != attr_none) {
+ if (*types == type)
+ return 1;
+ types++;
+ }
+ return 0;
+}
+
+int
+attr_types_contains_default(enum attr_type *types, enum attr_type type, int deflt)
+{
+ if (!types) {
+ return deflt;
+ }
+ return attr_types_contains(types, type);
+}
diff --git a/navit/attr.h b/navit/attr.h
index c018bd663..65cfbe574 100644
--- a/navit/attr.h
+++ b/navit/attr.h
@@ -129,6 +129,7 @@ struct attr {
} range;
int *dash;
enum item_type *item_types;
+ enum attr_type *attr_types;
long long *num64;
} u;
};
@@ -147,15 +148,18 @@ int attr_generic_get_attr(struct attr **attrs, struct attr **def_attrs, enum att
struct attr **attr_generic_set_attr(struct attr **attrs, struct attr *attr);
struct attr **attr_generic_add_attr(struct attr **attrs, struct attr *attr);
struct attr **attr_generic_remove_attr(struct attr **attrs, struct attr *attr);
+enum attr_type attr_type_begin(enum attr_type type);
int attr_data_size(struct attr *attr);
void *attr_data_get(struct attr *attr);
void attr_data_set(struct attr *attr, void *data);
-void attr_data_set_le(struct attr * attr, void * data);
+void attr_data_set_le(struct attr *attr, void *data);
void attr_free(struct attr *attr);
struct attr *attr_dup(struct attr *attr);
void attr_list_free(struct attr **attrs);
struct attr **attr_list_dup(struct attr **attrs);
int attr_from_line(char *line, char *name, int *pos, char *val_ret, char *name_ret);
+int attr_types_contains(enum attr_type *types, enum attr_type type);
+int attr_types_contains_default(enum attr_type *types, enum attr_type type, int deflt);
/* end of prototypes */
#endif
#ifdef __cplusplus
diff --git a/navit/attr_def.h b/navit/attr_def.h
index e18ea57bb..a3a437e1a 100644
--- a/navit/attr_def.h
+++ b/navit/attr_def.h
@@ -261,6 +261,7 @@ ATTR(dash)
ATTR(sequence_range)
ATTR(angle_range)
ATTR(speed_range)
+ATTR(attr_types)
ATTR2(0x0004ffff,type_special_end)
ATTR2(0x00050000,type_double_begin)
ATTR(position_height)
diff --git a/navit/navit_shipped.xml b/navit/navit_shipped.xml
index bcc068b32..17598473e 100644
--- a/navit/navit_shipped.xml
+++ b/navit/navit_shipped.xml
@@ -59,7 +59,7 @@
<vehicle name="Local GPS" profilename="car" enabled="yes" active="1" source="gpsd://localhost" gpsd_query="w+xj" color="#0000ff">
<!-- Navit can write a tracklog in several formats (gpx, nmea or textfile): -->
- <!-- <log type="gpx" data="track_%Y%m%d-%i.gpx" flush_size="1000" flush_time="30"/> -->
+ <!-- <log type="gpx" attr_types="position_time_iso8601,position_direction,position_speed,profilename,position_radius" data="track_%Y%m%d-%i.gpx" flush_size="1000" flush_time="30"/> -->
<cursor w="26" h="26">
<itemgra>
<circle color="#0000ff" radius="24" width="2">
diff --git a/navit/vehicle.c b/navit/vehicle.c
index 77896bdac..8b4f477d5 100644
--- a/navit/vehicle.c
+++ b/navit/vehicle.c
@@ -53,59 +53,48 @@ vehicle_log_nmea(struct vehicle *this_, struct log *log)
static void
vehicle_log_gpx(struct vehicle *this_, struct log *log)
{
- struct attr pos_attr;
- struct attr radius_attr;
- struct attr time_attr;
- struct attr *profile_attr;
- struct attr speed_attr;
- struct attr course_attr;
- char buffer[256];
- char tbuf[256];
- char *timep;
- double zero = 0.0f;
- int free=0;
+ struct attr attr,*attrp;
+ enum attr_type *attr_types;
+ char *logstr;
+ char *extensions="\t<extensions>\n";
if (!this_->meth.position_attr_get)
return;
- if (!this_->meth.position_attr_get(this_->priv, attr_position_coord_geo, &pos_attr))
+ if (log_get_attr(log, attr_attr_types, &attr, NULL))
+ attr_types=attr.u.attr_types;
+ else
+ attr_types=NULL;
+ if (!this_->meth.position_attr_get(this_->priv, attr_position_coord_geo, &attr))
return;
- if (!this_->meth.position_attr_get(this_->priv, attr_position_radius, &radius_attr))
- radius_attr.u.numd = &zero;
- if (!this_->meth.position_attr_get(this_->priv, attr_position_speed, &speed_attr))
- speed_attr.u.numd = &zero;
- if (!this_->meth.position_attr_get(this_->priv, attr_position_direction, &course_attr))
- course_attr.u.numd = &zero;
- if (!this_->meth.position_attr_get(this_->priv, attr_position_time_iso8601, &time_attr)) {
- timep = current_to_iso8601();
- free=1;
- } else {
- timep = time_attr.u.str;
+ logstr=g_strdup_printf("<trkpt lat=\"%f\" lon=\"%f\">\n",attr.u.coord_geo->lat,attr.u.coord_geo->lng);
+ if (attr_types && attr_types_contains_default(attr_types, attr_position_time_iso8601, 0)) {
+ if (this_->meth.position_attr_get(this_->priv, attr_position_time_iso8601, &attr)) {
+ logstr=g_strconcat_printf(logstr,"\t<time>%s</time>\n",attr.u.str);
+ } else {
+ char *timep = current_to_iso8601();
+ logstr=g_strconcat_printf(logstr,"\t<time>%s</time>\n",timep);
+ g_free(timep);
+ }
}
-
- // 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<course>%.1f</course>\n"
- "\t<speed>%.2f</speed>\n"
- "\t<extensions>"
- "\t\t<radius>%.2f</radius>\n"
- "\t\t<navit:profilename>%s</navit:profilename>\n"
- "\t</extensions>\n"
- "</trkpt>\n",
- pos_attr.u.coord_geo->lat,
- pos_attr.u.coord_geo->lng,
- timep,
- (*course_attr.u.numd),
- (*speed_attr.u.numd),
- (*radius_attr.u.numd),
- profile_attr->u.str
- );
-
- if (free)
- g_free(timep);
+ if (attr_types_contains_default(attr_types, attr_position_direction,0) && this_->meth.position_attr_get(this_->priv, attr_position_direction, &attr))
+ logstr=g_strconcat_printf(logstr,"\t<course>%.1f</course>\n",*attr.u.numd);
+ if (attr_types_contains_default(attr_types, attr_position_speed, 0) && this_->meth.position_attr_get(this_->priv, attr_position_speed, &attr))
+ logstr=g_strconcat_printf(logstr,"\t<speed>%.2f</speed>\n",*attr.u.numd);
+ if (attr_types_contains_default(attr_types, attr_profilename, 0) && (attrp=attr_search(this_->attrs, NULL, attr_profilename))) {
+ logstr=g_strconcat_printf(logstr,"%s\t\t<navit:profilename>%s</navit:profilename>\n",extensions,attrp->u.str);
+ extensions="";
+ }
+ if (attr_types_contains_default(attr_types, attr_position_radius, 0) && this_->meth.position_attr_get(this_->priv, attr_position_radius, &attr)) {
+ logstr=g_strconcat_printf(logstr,"%s\t\t<navit:radius>%.2f</navit:radius>\n",extensions,*attr.u.numd);
+ extensions="";
+ }
+ if (!strcmp(extensions,"")) {
+ logstr=g_strconcat_printf(logstr,"\t</extensions>\n");
+
+ }
+ logstr=g_strconcat_printf(logstr,"</trkpt>\n");
+ log_printf(log,"%s",logstr);
+ g_free(logstr);
}
static void