From: martin-s Date: Thu, 14 Feb 2008 11:45:49 +0000 (+0000) Subject: Fix:Core:Fixed nmea logging (at least for vehicle_file) X-Git-Tag: navit-0.5.0.5194svn~4287 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=37ee92a766dd4dd6241f6987f54086af04a3be7a;p=profile%2Fivi%2Fnavit.git Fix:Core:Fixed nmea logging (at least for vehicle_file) git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@864 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- diff --git a/navit/src/attr_def.h b/navit/src/attr_def.h index 98771df..b77617c 100644 --- a/navit/src/attr_def.h +++ b/navit/src/attr_def.h @@ -89,6 +89,7 @@ ATTR(source) ATTR(description) ATTR(gc_type) ATTR(layout) +ATTR(position_nmea) ATTR2(0x0003ffff,type_string_end) ATTR(order_limit) ATTR2(0x00050000,type_double_start) diff --git a/navit/src/vehicle.c b/navit/src/vehicle.c index 153f37f..a4baf21 100644 --- a/navit/src/vehicle.c +++ b/navit/src/vehicle.c @@ -20,6 +20,12 @@ struct vehicle { static void vehicle_log_nmea(struct vehicle *this_, struct log *log) { + struct attr pos_attr; + if (!this_->meth.position_attr_get) + return; + if (!this_->meth.position_attr_get(this_->priv, attr_position_nmea, &pos_attr)) + return; + log_write(log, pos_attr.u.str, strlen(pos_attr.u.str)); } static void diff --git a/navit/src/vehicle/file/vehicle_file.c b/navit/src/vehicle/file/vehicle_file.c index 94d071a..f0a81ff 100644 --- a/navit/src/vehicle/file/vehicle_file.c +++ b/navit/src/vehicle/file/vehicle_file.c @@ -41,6 +41,8 @@ struct vehicle_priv { GIOChannel *iochan; char *buffer; int buffer_pos; + char *nmea_data; + char *nmea_data_buf; struct coord_geo geo; double speed; @@ -201,7 +203,7 @@ vehicle_file_enable_watch_timer(gpointer t) static void vehicle_file_parse(struct vehicle_priv *priv, char *buffer) { - char *p, *item[16]; + char *nmea_data_buf, *p, *item[16]; double lat, lng; int i, bcsum; int len = strlen(buffer); @@ -210,7 +212,7 @@ vehicle_file_parse(struct vehicle_priv *priv, char *buffer) dbg(1, "buffer='%s'\n", buffer); for (;;) { if (len < 4) { - dbg(0, "too short\n"); + dbg(0, "'%s' too short\n", buffer); return; } if (buffer[len - 1] == '\r' || buffer[len - 1] == '\n') @@ -219,25 +221,32 @@ vehicle_file_parse(struct vehicle_priv *priv, char *buffer) break; } if (buffer[0] != '$') { - dbg(0, "no leading $\n"); + dbg(0, "no leading $ in '%s'\n", buffer); return; } if (buffer[len - 3] != '*') { - dbg(0, "no *XX\n"); + dbg(0, "no *XX in '%s'\n", buffer); return; } for (i = 1; i < len - 3; i++) { csum ^= (unsigned char) (buffer[i]); } if (!sscanf(buffer + len - 2, "%x", &bcsum)) { - dbg(0, "no checksum\n"); + dbg(0, "no checksum in '%s'\n", buffer); return; } if (bcsum != csum) { - dbg(0, "wrong checksum\n"); + dbg(0, "wrong checksum in '%s'\n", buffer); return; } + if (!priv->nmea_data_buf || strlen(priv->nmea_data_buf) < 65536) { + nmea_data_buf=g_strconcat(priv->nmea_data_buf ? priv->nmea_data_buf : "", buffer, "\n", NULL); + g_free(priv->nmea_data_buf); + priv->nmea_data_buf=nmea_data_buf; + } else { + dbg(0, "nmea buffer overflow, discarding '%s'\n", buffer); + } i = 0; p = buffer; while (i < 16) { @@ -275,6 +284,9 @@ vehicle_file_parse(struct vehicle_priv *priv, char *buffer) sscanf(item[6], "%d", &priv->status); sscanf(item[7], "%d", &priv->sats_used); priv->height = g_ascii_strtod(item[9], NULL); + g_free(priv->nmea_data); + priv->nmea_data=priv->nmea_data_buf; + priv->nmea_data_buf=NULL; callback_list_call_0(priv->cbl); @@ -410,6 +422,11 @@ vehicle_file_position_attr_get(struct vehicle_priv *priv, case attr_position_coord_geo: attr->u.coord_geo = &priv->geo; break; + case attr_position_nmea: + attr->u.str=priv->nmea_data; + if (! attr->u.str) + return 0; + break; default: return 0; }