vitosmt patch - timezone parameter

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

vitosmt patch - timezone parameter

Etasse
- Added time zone offset parameter to vitosmt
- Added two test cases to testo (3 reference files attached)

Index: README
===================================================================
RCS file: /cvsroot/gpsbabel/gpsbabel/README,v
retrieving revision 1.97
diff -u -r1.97 README
--- README 21 Jun 2005 05:17:33 -0000 1.97
+++ README 22 Jun 2005 03:38:45 -0000
@@ -837,8 +837,16 @@
     VitoSMT
 
  Vito Navigator II is a Pocket PC GPS application.  This format reads
- a Vito Navigator II .SMT track file in waypoint mode.  It is still
- a work in progress.
+ a Vito Navigator II .SMT track file and can work in either waypoint
+ or track mode.  The tzoffset parameter is used to set the UTC offset
+ of the imput file.
+
+ for example, process a file that was produced in Eastern Daylight
+ Time (-4h from UTC):
+ gpsbabel -i vitosmt,tzoffset=-4 -f vitosmt.smt
+
+ A file that was produced in France Daylight Savings time:
+ gpsbabel -i vitosmt,tzoffset=1 -f paris.smt
 
 
 DATA FILTERS
Index: testo
===================================================================
RCS file: /cvsroot/gpsbabel/gpsbabel/testo,v
retrieving revision 1.82
diff -u -r1.82 testo
--- testo 20 Jun 2005 14:58:16 -0000 1.82
+++ testo 22 Jun 2005 03:38:46 -0000
@@ -711,7 +711,9 @@
 # Vito Navigator II .smt tests
 #
 rm -f ${TMPDIR}/vitosmt*
-${PNAME} -i vitosmt -f reference/vitosmt.smt -o gpx -F
${TMPDIR}/vitosmt.gpx
+${PNAME}    -i vitosmt,tzoffset=-4 -f reference/vitosmt.smt -o gpx -F
${TMPDIR}/vitosmt.gpx
 compare ${TMPDIR}/vitosmt.gpx reference/vitosmt.gpx
+${PNAME} -t -i vitosmt,tzoffset=-4 -f reference/vitosmt.smt -o gpx -F
${TMPDIR}/vitosmt_t.gpx
+compare ${TMPDIR}/vitosmt_t.gpx reference/track/vitosmt_t.gpx
 
 exit 0
Index: vitosmt.c
===================================================================
RCS file: /cvsroot/gpsbabel/gpsbabel/vitosmt.c,v
retrieving revision 1.1
diff -u -r1.1 vitosmt.c
--- vitosmt.c 20 Jun 2005 14:58:35 -0000 1.1
+++ vitosmt.c 22 Jun 2005 03:38:46 -0000
@@ -26,7 +26,8 @@
 #define MYNAME "vitosmt"
 #include "defs.h"
 
-FILE *infile;
+FILE *infile;
+static char *   arg_tzoffset=NULL;
 
 static unsigned long
 ReadLong(FILE * f)
@@ -83,16 +84,20 @@
  unsigned short version =0;
  unsigned long count =0;
  const unsigned long recsize =64;
- unsigned short stringlen =0;
- static int serial =0;
-
-/* route_head *track_head =0; */
+ unsigned short stringlen =0;
+ route_head *track_head =0;
  waypoint *wpt_tmp =0;
  double latrad =0;
  double lonrad =0;
  double elev =0;
  unsigned char* timestamp =0;
  struct tm tmStruct ={0,0,0,0,0,0,0,0,0};
+ int iTzoffset =0;
+
+ /* Compute offset between local time zone and time offset argument */
+ if (arg_tzoffset) {
+ iTzoffset = get_tz_offset() - (unsigned int)
60*60*atof(arg_tzoffset);
+ }
 
  /*
  * 24 bytes header
@@ -104,19 +109,20 @@
  ReadLong(infile); /* 599 */
  ReadLong(infile); /* 600 */
 
-/* track_head = route_head_alloc(); */
-/* route_add_head(track_head); */
-
-
  while (count) {
  /*
  * 64 bytes of data
  */
+ if (feof(infile)||ferror(infile))
+ {
+ break;
+ }
+
  latrad =ReadDouble(infile); /* WGS84 latitude in radians */
  lonrad =ReadDouble(infile); /* WGS84 longitude in radians */
  elev =ReadDouble(infile); /* elevation in meters */
- timestamp =ReadRecord(infile,8); /* local time */
- Skip(infile,32); /* remainder, unknown fmt */
+ timestamp =ReadRecord(infile,5); /* local time */
+ Skip(infile,35); /* remainder, unknown fmt */
 
  wpt_tmp = waypt_new();
 
@@ -129,19 +135,32 @@
  tmStruct.tm_mday =timestamp[2];
  tmStruct.tm_hour =timestamp[3];
  tmStruct.tm_min =timestamp[4];
- tmStruct.tm_sec =timestamp[5];
+ tmStruct.tm_sec =0;
  tmStruct.tm_isdst =-1;
 
- wpt_tmp->creation_time = mktime(&tmStruct); /* + get_tz_offset(); */
-
- wpt_tmp->shortname = (char *) xmalloc(10);
- snprintf(wpt_tmp->shortname, 10, "SMT%04d",++serial);
+ wpt_tmp->creation_time = mktime(&tmStruct) - iTzoffset;
  wpt_tmp->wpt_flags.shortname_is_synthetic = 1;
-
- waypt_add(wpt_tmp);
 
- xfree(timestamp);
+ switch (global_opts.objective)
+ {
+ case wptdata:
+ waypt_add(wpt_tmp);
+ break;
+ case trkdata:
+ if (track_head == NULL) {
+ track_head = route_head_alloc();
+ track_add_head(track_head);
+ }
+ route_add_wpt(track_head, wpt_tmp);
+ break;
+ default:
+ fatal(MYNAME ": This file type only supports "
+ "waypoint or track (-w or -t) mode.");
+
+ break;
+ }
 
+ xfree(timestamp);
 
  count--;
  }
@@ -153,6 +172,12 @@
  fatal(MYNAME ":Not enough information is known about this format to
write it.\n");
 }
 
+static
+arglist_t vitosmt_args[] = {
+ {"tzoffset", &arg_tzoffset, "Time zone offset of SMT file (hours)",
NULL, ARGTYPE_FLOAT },
+ {0, 0, 0, 0, 0}
+};
+
 ff_vecs_t vitosmt_vecs = {
  ff_type_file,
  { ff_cap_read, ff_cap_read, ff_cap_none},
@@ -163,5 +188,5 @@
  vitosmt_read,
  NULL,
  NULL,
- NULL
+ vitosmt_args
 };


       

       
               
__________________________________________________________
Lèche-vitrine ou lèche-écran ?
magasinage.yahoo.ca

vitosmt.smt (20K) Download Attachment
vitosmt.gpx (34K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: vitosmt patch - timezone parameter

Robert Lipe
Etasse wrote:
> - Added time zone offset parameter to vitosmt

I like this idea, but we're tripped up in the details somewhere.  I had
to adjust tzoffset to -7 in testo to make it work which makes me suspect
either I've missed a patch or something doesn't work the way you think
it works.  Can you please chase this a little more?

I've committed this just to help us keep our respective sanity.

Thanx.
RJL


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Gpsbabel-code mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gpsbabel-code
Reply | Threaded
Open this post in threaded view
|

vitosmt 20050622 patch - timezone parameter, seconds, and everything else

Etasse
--- Robert Lipe <[hidden email]> wrote :
> I like this idea, but we're tripped up in the details somewhere.  I
had
> to adjust tzoffset to -7 in testo to make it work which makes me
> suspect either I've missed a patch or something doesn't work the
> way you think it works.  Can you please chase this a little more?
>
> I've committed this just to help us keep our respective sanity.

"Hmph.  Let's try that again." -- Daffy Duck in Rabbit Fire

Finally figured it out by looking at gpx.c:xml_parse_time(). The proper
way is to ADD get_tz_offset then SUBTRACT the desired timezone
difference from the mktime() call.  It didn't help that I put an
(unsigned int) typecast in front of my tzoffset argv, throwing away the
minus *blush*

Oh well, my mind must be too highly trained to notice rookie mistakes
like that.  ;-)

Also, I'm happy to report I've decoded almost every piece of data in
the SMT format.  We now have seconds/centiseconds, speed, heading and
DOP.  There doesn't seem to be a place to put the last three so I threw
the works in the notes field along with a hex dump of the 3 remaining
mystery bytes.

TODO:  produce new testo reference files containing the newly
discovered values.

So here's the patch:
____________________
Index: README
===================================================================
RCS file: /cvsroot/gpsbabel/gpsbabel/README,v
retrieving revision 1.97
diff -u -r1.97 README
--- README 21 Jun 2005 05:17:33 -0000 1.97
+++ README 23 Jun 2005 01:19:17 -0000
@@ -837,8 +837,16 @@
     VitoSMT
 
  Vito Navigator II is a Pocket PC GPS application.  This format reads
- a Vito Navigator II .SMT track file in waypoint mode.  It is still
- a work in progress.
+ a Vito Navigator II .SMT track file and can work in either waypoint
+ or track mode.  The tzoffset parameter is used to set the UTC offset
+ of the imput file.
+
+ for example, process a file that was produced in Eastern Daylight
+ Time (-4h from UTC):
+ gpsbabel -i vitosmt,tzoffset=-4 -f vitosmt.smt
+
+ A file that was produced in France Daylight Savings time:
+ gpsbabel -i vitosmt,tzoffset=1 -f paris.smt
 
 
 DATA FILTERS
Index: testo
===================================================================
RCS file: /cvsroot/gpsbabel/gpsbabel/testo,v
retrieving revision 1.82
diff -u -r1.82 testo
--- testo 20 Jun 2005 14:58:16 -0000 1.82
+++ testo 23 Jun 2005 01:19:17 -0000
@@ -711,7 +711,9 @@
 # Vito Navigator II .smt tests
 #
 rm -f ${TMPDIR}/vitosmt*
-${PNAME} -i vitosmt -f reference/vitosmt.smt -o gpx -F
${TMPDIR}/vitosmt.gpx
+${PNAME}    -i vitosmt,tzoffset=-4 -f reference/vitosmt.smt -o gpx -F
${TMPDIR}/vitosmt.gpx
 compare ${TMPDIR}/vitosmt.gpx reference/vitosmt.gpx
+${PNAME} -t -i vitosmt,tzoffset=-4 -f reference/vitosmt.smt -o gpx -F
${TMPDIR}/vitosmt_t.gpx
+compare ${TMPDIR}/vitosmt_t.gpx reference/track/vitosmt_t.gpx
 
 exit 0
Index: vitosmt.c
===================================================================
RCS file: /cvsroot/gpsbabel/gpsbabel/vitosmt.c,v
retrieving revision 1.1
diff -u -r1.1 vitosmt.c
--- vitosmt.c 20 Jun 2005 14:58:35 -0000 1.1
+++ vitosmt.c 23 Jun 2005 01:19:17 -0000
@@ -26,7 +26,8 @@
 #define MYNAME "vitosmt"
 #include "defs.h"
 
-FILE *infile;
+FILE *infile;
+static char *   arg_tzoffset=NULL;
 
 static unsigned long
 ReadLong(FILE * f)
@@ -83,16 +84,28 @@
  unsigned short version =0;
  unsigned long count =0;
  const unsigned long recsize =64;
- unsigned short stringlen =0;
- static int serial =0;
-
-/* route_head *track_head =0; */
+ unsigned short stringlen =0;
+ route_head *track_head =0;
  waypoint *wpt_tmp =0;
  double latrad =0;
  double lonrad =0;
  double elev =0;
  unsigned char* timestamp =0;
  struct tm tmStruct ={0,0,0,0,0,0,0,0,0};
+ double seconds =0.0;
+ double speed =0.0;
+ double heading =0.0;
+ double dop =0.0;
+ unsigned char* unknown =0;
+ char shortname[10] ="\0";
+ char description[40] ="\0";
+ int serial =0;
+ int iTzoffset =0;
+
+ /* Compute offset between local time zone and time offset argument */
+ if (arg_tzoffset) {
+ iTzoffset = get_tz_offset() - (int)(60*60*atof(arg_tzoffset));
+ }
 
  /*
  * 24 bytes header
@@ -104,19 +117,24 @@
  ReadLong(infile); /* 599 */
  ReadLong(infile); /* 600 */
 
-/* track_head = route_head_alloc(); */
-/* route_add_head(track_head); */
-
-
  while (count) {
  /*
  * 64 bytes of data
  */
+ if (feof(infile)||ferror(infile))
+ {
+ break;
+ }
+
  latrad =ReadDouble(infile); /* WGS84 latitude in radians */
  lonrad =ReadDouble(infile); /* WGS84 longitude in radians */
  elev =ReadDouble(infile); /* elevation in meters */
- timestamp =ReadRecord(infile,8); /* local time */
- Skip(infile,32); /* remainder, unknown fmt */
+ timestamp =ReadRecord(infile,5); /* local time */
+ seconds =ReadDouble(infile); /* seconds */
+ speed =ReadDouble(infile);    /* possibly ground speed, unknown
units*/
+ heading =ReadDouble(infile); /* heading in degrees */
+ dop =ReadDouble(infile); /* dilution of precision */
+ unknown =ReadRecord(infile,3); /* remainder, unknown fmt */
 
  wpt_tmp = waypt_new();
 
@@ -129,19 +147,42 @@
  tmStruct.tm_mday =timestamp[2];
  tmStruct.tm_hour =timestamp[3];
  tmStruct.tm_min =timestamp[4];
- tmStruct.tm_sec =timestamp[5];
+ tmStruct.tm_sec =(int)floor(seconds);
  tmStruct.tm_isdst =-1;
 
- wpt_tmp->creation_time = mktime(&tmStruct); /* + get_tz_offset(); */
-
- wpt_tmp->shortname = (char *) xmalloc(10);
- snprintf(wpt_tmp->shortname, 10, "SMT%04d",++serial);
- wpt_tmp->wpt_flags.shortname_is_synthetic = 1;
+ wpt_tmp->creation_time = mktime(&tmStruct) + iTzoffset;
+ wpt_tmp->centiseconds = fmod(100*seconds+0.5,100);
+
+ snprintf(shortname, sizeof shortname-1 , "WP%04d", ++serial);
+ snprintf(description, sizeof description-1,
+ "Spd=%.1lf Hdg=%03.0lf DoP=%4.1lf Flg=%02x%02x%02x",
+ speed,heading,dop,unknown[0],unknown[1],unknown[2]);
 
- waypt_add(wpt_tmp);
+ wpt_tmp->shortname = xstrdup(shortname);
+ wpt_tmp->wpt_flags.shortname_is_synthetic = 1;
+ wpt_tmp->notes = xstrdup(description);
 
- xfree(timestamp);
+ switch (global_opts.objective)
+ {
+ case wptdata:
+ waypt_add(wpt_tmp);
+ break;
+ case trkdata:
+ if (track_head == NULL) {
+ track_head = route_head_alloc();
+ track_add_head(track_head);
+ }
+ route_add_wpt(track_head, wpt_tmp);
+ break;
+ default:
+ fatal(MYNAME ": This file type only supports "
+ "waypoint or track (-w or -t) mode.");
 
+ break;
+ }
+
+ xfree(timestamp);
+ xfree(unknown);
 
  count--;
  }
@@ -153,6 +194,12 @@
  fatal(MYNAME ":Not enough information is known about this format to
write it.\n");
 }
 
+static
+arglist_t vitosmt_args[] = {
+ {"tzoffset", &arg_tzoffset, "Time zone offset of SMT file (hours)",
NULL, ARGTYPE_FLOAT },
+ {0, 0, 0, 0, 0}
+};
+
 ff_vecs_t vitosmt_vecs = {
  ff_type_file,
  { ff_cap_read, ff_cap_read, ff_cap_none},
@@ -163,5 +210,5 @@
  vitosmt_read,
  NULL,
  NULL,
- NULL
+ vitosmt_args
 };




       

       
               
__________________________________________________________
Lèche-vitrine ou lèche-écran ?
magasinage.yahoo.ca


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Gpsbabel-code mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gpsbabel-code
Reply | Threaded
Open this post in threaded view
|

Re: vitosmt 20050622 patch - timezone parameter, seconds, and everything else

Robert Lipe
> "Hmph.  Let's try that again." -- Daffy Duck in Rabbit Fire

:-)  

> Finally figured it out by looking at gpx.c:xml_parse_time(). The proper
> way is to ADD get_tz_offset then SUBTRACT the desired timezone
> difference from the mktime() call.  

This stuff can indeed get tangly.  About half the ISO C functions do
local time and about half do GMT and there's rarely an indication which
is which.  The needed logic can get ugly.

> Also, I'm happy to report I've decoded almost every piece of data in
> the SMT format.  We now have seconds/centiseconds, speed, heading and
> DOP.  There doesn't seem to be a place to put the last three so I threw

Neat.

I've kind of resisted the urge to have the last three because so few
programs support them and because they strike me as kind of misguided to
associate with a point.  A number of our internal operations would have
to be enhanced to support things like heading - for example, if you run
a track through the route simplifier, heading and speed would need to be
recomputed after we toss points and when doing merges, it's not at all
clear to me what we should do with those fields.

I'm not saying I'm opposed to adding them to struct waypoint, but it's
not trivial to keep those things sensible as they propogate around our
innards.

> TODO:  produce new testo reference files containing the newly
> discovered values.

Please do.  We do get a number of failures of this form:

12,15c12,15
< <time>2005-05-09T22:02:01Z</time>
<   <name>WP0001</name>
<   <cmt>Spd=0.0 Hdg=000 DoP=30.6 Flg=080703</cmt>
<   <desc>Spd=0.0 Hdg=000 DoP=30.6 Flg=080703</desc>
---
> <time>2005-05-09T23:02:00Z</time>
>   <name>WPT001</name>
>   <cmt>WPT001</cmt>
>   <desc>WPT001</desc>

> So here's the patch:

I've applied this.

For the next go round, please either send the patch as an attachment
instead of sucking it right into the message or turn off line wrap in
your mailer/editor so I don't have to manually rejoin the long lines.

Thanx!
RJL



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Gpsbabel-code mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gpsbabel-code
Reply | Threaded
Open this post in threaded view
|

vitosmt 20050623 patch - the kitchen sink

Etasse
> This stuff can indeed get tangly.  About half the ISO C functions do
> local time and about half do GMT and there's rarely an indication
> which is which.  The needed logic can get ugly.

I think I found a bug in gpx.c  When the XMM <time> is parsed into the
struct tm, tm_isdt is set to 0 and mktime incorrectly adjusts for
daylight savings.  Setting it to -1 seems to prevent that.  

> I've kind of resisted the urge to have the last three because so few
> programs support them and because they strike me as kind of misguided
> to associate with a point.  
  [...]
> I'm not saying I'm opposed to adding them to struct waypoint, but
> it's not trivial to keep those things sensible as they propogate
> around our innards.

No need to bend over backwards for that stuff.  I just thought it would
be nice to stick them somewhere so they don't get 'lost in the
translation'.


Here's yet another patchfile, lost of new goodies now:
- Nailed the time conversion bug once and for all
- Removed tzoffset parameter, turns out the timestamp is UTC after all
- Ability to write .SMT tracks  Gave it a try, didn't crash my PPC so I
went for it.  Still left in a big warning.
- Fixed vitosmt test cases testo (tzoffset removed)
- added mkwintesto to MSVC project, .dsp .dsw changed
- Fixed mkwintesto.c, it was not handling <$PNAME> properly, especially
when using | pipeing
 
Note:  the vitosmt.smt reference file seems to have been corrupted in
the CVS, I am sending the correct one.

Attached:
 vitosmt_20050623.patch (17k)
 msvc/mkwintesto.dsp (5k)
 reference/vitosmt.smt (19k)
 reference/vitosmt.gpx
 reference/track/vitosmt_t.gpx (50k)
 

Yahoo! Mail - Votre e-mail personnel et gratuit qui vous suit partout !
 Créez votre Yahoo! Mail sur http://mail.yahoo.fr

vitosmt_20050623.patch (18K) Download Attachment
mkwintesto.dsp (5K) Download Attachment
vitosmt.smt (20K) Download Attachment
vitosmt.gpx (13K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: vitosmt 20050623 patch - the kitchen sink

Robert Lipe
> I think I found a bug in gpx.c  When the XMM <time> is parsed into the
> struct tm, tm_isdt is set to 0 and mktime incorrectly adjusts for
> daylight savings.  Setting it to -1 seems to prevent that.  

That's entirely possible.   I'll look at that soon.

> Here's yet another patchfile, lost of new goodies now:

Lovely.  Can you please update to the current code (cvs up) and then
resend that patch?

> - Ability to write .SMT tracks  Gave it a try, didn't crash my PPC so I
> went for it.  Still left in a big warning.

This is wrong if the endianness of your computer differs from the
endianness if the file:

+void^M
+WriteDouble(void* ptr, double d)^M
+{^M
+  memcpy(ptr, &d, 8);^M
+  return;^M
+}^M
+^M

You need to call le_read64 to ensure things are swapped correctly.


+       le_write32(&workbuffer[position],subversion);^M
+       position += sizeof(long);^M
+       le_write32(&workbuffer[position],count);^M
+       position += sizeof(long);^M

Think about LP64 hosts.  (Longs and pointers are 64 bits, ints are 32.)
On those, a host long will be 64 bits and this code will break.  Since
you know the target thingy is 4 bytes, just use "4" here.

> Note:  the vitosmt.smt reference file seems to have been corrupted in
> the CVS, I am sending the correct one.

I probably forgot to set the binary flag on that.  


> Attached:
>  vitosmt_20050623.patch (17k)
>  msvc/mkwintesto.dsp (5k)
>  reference/vitosmt.smt (19k)
>  reference/vitosmt.gpx
>  reference/track/vitosmt_t.gpx (50k)

I've applied the last four.  If you could update your tree and send a
diff/patch that applies against that, I'll drop that top one in.

Thanx for working through this.

RJL

--
Support GPSBabel by helping to improve it or fund those that that have
done so.  Visit:

        http://sourceforge.net/donate/index.php?group_id=58972


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Gpsbabel-code mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gpsbabel-code