[Gpsbabel-code] [patch] read support for VITO SmartMap .vtt track files
Brought to you by:
robertl
From: Jeremy E. <ara...@gm...> - 2007-03-19 17:55:12
|
VITO SmartMap <http://vitotechnology.com/en/products/ smartmap_nokia_series60.html> is one of the few GPS apps that works well on Series 60 smartphones like my old Nokia 3660. Unfortunately, it uses proprietary map and track formats, but I worked out most of the track format yesterday after staring at a hex dump for several hours. This patch adds partial read support (coordinates, altititude, time) for the SmartMap .vtt track file format to gpsbabel. The implementation is mostly lifted from vitosmt.c. It compiles and works with the 1.3.3 release and CVS HEAD. I haven't completely figured out the formats for course heading and what I suspect are the DOP/sat count/fix type fields, so it ignores that information. Hopefully I can add that as well as write support and a decent test file soon. Thanks for a great tool, everyone! Patch follows. Jeremy Ehrhardt Index: Makefile.in =================================================================== RCS file: /cvsroot/gpsbabel/gpsbabel/Makefile.in,v retrieving revision 1.80 diff -u -r1.80 Makefile.in --- Makefile.in 26 Feb 2007 00:37:15 -0000 1.80 +++ Makefile.in 19 Mar 2007 04:46:17 -0000 @@ -54,7 +54,7 @@ tef_xml.o maggeo.o pathaway.o vitosmt.o gdb.o bcr.o coto.o \ ignrando.o stmwpp.o msroute.o cst.o nmn4.o mag_pdb.o compegps.o \ yahoo.o unicsv.o wfff_xml.o garmin_txt.o axim_gpb.o gpssim.o \ - wbt-200.o stmsdf.o gtrnctr.o dmtlog.o raymarine.o alan.o + wbt-200.o stmsdf.o gtrnctr.o dmtlog.o raymarine.o alan.o vitovtt.o FILTERS=position.o radius.o duplicate.o arcdist.o polygon.o smplrout.o \ reverse_route.o sort.o stackfilter.o trackfilter.o discard.o \ Index: vecs.c =================================================================== RCS file: /cvsroot/gpsbabel/gpsbabel/vecs.c,v retrieving revision 1.147 diff -u -r1.147 vecs.c --- vecs.c 27 Jan 2007 21:37:49 -0000 1.147 +++ vecs.c 19 Mar 2007 04:46:17 -0000 @@ -114,6 +114,7 @@ extern ff_vecs_t raymarine_vecs; extern ff_vecs_t alanwpr_vecs; extern ff_vecs_t alantrl_vecs; +extern ff_vecs_t vitovtt_vecs; static vecs_t vec_list[] = { @@ -630,6 +631,12 @@ "Alan Map500 tracklogs (.trl)", "trl" }, + { + &vitovtt_vecs, + "vitovtt", + "Vito SmartMap tracks (.vtt)", + "vtt" + }, { NULL, NULL, Index: vitovtt.c =================================================================== RCS file: vitovtt.c diff -N vitovtt.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ vitovtt.c 19 Mar 2007 04:46:17 -0000 @@ -0,0 +1,188 @@ +/* + Read Vito SmartMap .vtt tracks + + Copyright (C) 2007 Jeremy Ehrhardt, je...@ca... + + based on vitosmc.c, which is + Copyright (C) 2005 Etienne TASSE + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA + + */ + +#include <stddef.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> + +#define MYNAME "vitovtt" +#include "defs.h" + +#define TM_YEAR_ZERO 1900 +#define TM_MONTH_ZERO 1 + +static FILE *infile = 0; +static int count = 0; + +const int vitovtt_version = 3; +const size_t vitovtt_headersize = 16; +const size_t vitovtt_datasize = 32; + +const double vitovtt_latitudescale = 20000000.0; +const double vitovtt_longitudescale = 10000000.0; +const int vitovtt_secondscale = 30000000; +const int vitovtt_microsecondscale = 30; + +static double +ReadFloat(FILE * f) +{ + float result = 0; + + fread(&result, sizeof (result), 1, f); + return le_read_float(&result); +} + +static int +ReadInt(FILE * f) +{ + gbint32 result = 0; + + fread(&result, sizeof (result), 1, f); + return le_read32(&result); +} + +static int +ReadShort(FILE * f) +{ + gbint16 result = 0; + + fread(&result, sizeof (result), 1, f); + return le_read16(&result); +} + +#define ReadByte fgetc + +static void +rd_init(const char *fname) +{ + infile = xfopen(fname, "rb", MYNAME); +} + +static void +rd_deinit(void) +{ + fclose(infile); +} + +static void +vitovtt_read(void) +{ + int version = 0; + route_head *route_head = 0; + waypoint *wpt_tmp = 0; + int scaled_lat = 0; + int scaled_lon = 0; + double altitude = 0; + struct tm tmStruct; + int scaled_sec = 0; + int microseconds = 0; + double speed = 0; + int course = 0; + int status = 0; + int serial = 0; + + memset(&tmStruct, 0, sizeof(tmStruct)); + + /* Read the header. */ + version = ReadInt(infile); + count = ReadInt(infile); + + if (version!=vitovtt_version) { + + fatal("%s (%d) reading file. Unsupported version %d\n", + MYNAME, __LINE__, version ); + } + + while (count) { + /* Read an entry. */ + scaled_lat = ReadInt(infile); + scaled_lon = ReadInt(infile); + altitude = ReadFloat(infile); + tmStruct.tm_year = ReadShort(infile) - TM_YEAR_ZERO; + tmStruct.tm_mon = ReadByte(infile) - TM_MONTH_ZERO; + tmStruct.tm_mday = ReadByte(infile); + tmStruct.tm_hour = ReadByte(infile); + tmStruct.tm_min = ReadByte(infile); + scaled_sec = ReadInt(infile); + speed = ReadFloat(infile); + course = ReadShort(infile); + status = ReadInt(infile); + + wpt_tmp = waypt_new(); + + wpt_tmp->latitude = scaled_lat / vitovtt_latitudescale; + wpt_tmp->longitude = scaled_lon / vitovtt_longitudescale; + wpt_tmp->altitude = altitude; + + tmStruct.tm_sec = scaled_sec / vitovtt_secondscale; + microseconds = (scaled_sec % vitovtt_secondscale) / vitovtt_microsecondscale; + wpt_tmp->creation_time = mkgmtime(&tmStruct); + wpt_tmp->microseconds = microseconds; + + /* + * TODO: interpret speed, course, status + */ + + wpt_tmp->shortname = xcalloc(16,1); + snprintf(wpt_tmp->shortname, 15 , "WP%04d", ++serial); + + if (doing_wpts) /* process as waypoints */ + { + waypt_add(wpt_tmp); + } + else if (doing_rtes) /* process as route */ + { + if (route_head == NULL) { + route_head = route_head_alloc(); + route_add_head(route_head); + } + route_add_wpt(route_head, wpt_tmp); + } + else /* default track mode */ + { + if (route_head == NULL) { + route_head = route_head_alloc(); + track_add_head(route_head); + } + track_add_wpt(route_head, wpt_tmp); + } + + count--; + } +} + +ff_vecs_t vitovtt_vecs = { + ff_type_file, + { ff_cap_read, ff_cap_read, ff_cap_read }, + rd_init, + NULL, + rd_deinit, + NULL, + vitovtt_read, + NULL, + NULL, + NULL, + CET_CHARSET_UTF8, 1 /* do nothing | CET-REVIEW */ +}; |