Add:Core:Made log items of gpx log configurable
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 31 Aug 2009 17:14:42 +0000 (17:14 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 31 Aug 2009 17:14:42 +0000 (17:14 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@2538 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/attr.c
navit/attr.h
navit/attr_def.h
navit/navit_shipped.xml
navit/vehicle.c

index f05f9a2..bf5ac89 100644 (file)
@@ -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);        
+}
index c018bd6..65cfbe5 100644 (file)
@@ -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
index e18ea57..a3a437e 100644 (file)
@@ -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)
index bcc068b..1759847 100644 (file)
@@ -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">
index 77896bd..8b4f477 100644 (file)
@@ -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