[PATCH] Limited support for Suunto DM4 import

Miika Turkia miika.turkia at gmail.com
Sun Mar 3 08:20:44 PST 2013


On Sun, Mar 3, 2013 at 5:51 PM, Dirk Hohndel <dirk at hohndel.org> wrote:
> Miika Turkia <miika.turkia at gmail.com> writes:
>
>> Basic functionality is implemented but at least support for multiple
>> cylinders and events is currently missing.
>>
>> Signed-off-by: Miika Turkia <miika.turkia at gmail.com>
>> ---
>>  Makefile    |   10 ++++-
>>  dive.h      |    2 +
>>  file.c      |   20 +++++++++
>>  gtk-gui.c   |    5 +++
>>  parse-xml.c |  130 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  5 files changed, 165 insertions(+), 2 deletions(-)
>>
>> diff --git a/Makefile b/Makefile
>> index 71e19f0..65932b5 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -6,6 +6,7 @@ INSTALL=install
>>  PKGCONFIG=pkg-config
>>  XML2CONFIG=xml2-config
>>  XSLCONFIG=xslt-config
>> +SQLITECONFIG=pkg-config
>
> why not use $(PKGCONFIG)? Oh yeah, that's what you do below, this
> variable isn't referenced anywhere else in the Makefile :-)

That is how the code evolves, and I just missed this when cleaning up.
Will be gone on the next version.

>> +#ifdef SQLITE3
>> +     fmt = strrchr(filename, '.');
>> +     if (fmt && !strcasecmp(fmt + 1, "DB")) {
>> +             if (!try_to_open_db(filename, &mem, error)) {
>> +                     free(mem.buffer);
>> +                     return;
>> +             }
>> +     }
>> +#endif
>
> This puzzles me - maybe I'm missing how this is supposed to work - is
> the database name the same as the filename? What happens if the user
> renames the file?

I am just checking the suffix of the file name. Now that I am thinking
on this, I suppose this might need a bit of rework. The default file
name for the Suunto database is DM4.db. However, it would be easier to
instruct the user to do a backup of the dive log and use that instead
of searching for the real DB from a directory structure that is partly
random. The backup can be saved with any desired name, but the default
backup suffix is .bak. And we should probably go for that instead.
Opinions?

>> +#ifdef SQLITE3
>> +int sde_dive(void *a_param, int argc, char **argv, char **column)
>
> Calling those parameters argc and **argv is playing mental games with
> me... somehow those two parameter names have a well defined meaning for
> me, so reading the code below completely threw me off... :-)

I have to agree with you. Definitely something that should be fixed.
And while I am at it I'll change the name of the function to dm4_dive
- sde is the old zipped xml after all.

>> +{
>> +     int i;
>> +     float *profileBlob;
>> +     unsigned char *tempBlob;
>> +     int *pressureBlob;
>> +     time_t when;
>> +     struct tm *tm;
>> +     int interval;
>> +
>> +     dive_start();
>> +     cur_dive->number = atoi(argv[0]);
>> +
>> +     /* Suunto saves time in 100 nano seconds, we'll need the time in
>
> SERIOUSLY? They are clearly completely on drugs.
>
>> +      * seconds.
>> +      */
>> +     when = (time_t)(atol(argv[1]) / 10000000);
>> +     tm = localtime(&when);
>> +
>> +     /* Suunto starts counting time in year 1, we need epoch */
>
> But why stop there? Don't they want to record dives for Hannibal as
> well?
>
>> +     /*
>> +      * DM4 stores Duration and DiveTime. It looks like DiveTime is
>> +      * 10 to 60 seconds shorter than Duration. However, I have no
>> +      * idea what is the difference and which one should be used.
>> +      */
>
> Looking at actual profiles it's often easy to figure these things
> out. It could be that Duration is the time the computer is "on" or "wet"
> while DiveTime is the time below a certain depth...

Well, initial inspection when comparing what Subsurface (with native
download) and the DM4 database gives makes me wonder even more.
Subsurface matches the DiveTime occasionally but most often is between
the Suunto values.

> Thanks for the patch. As I want to cut 3.0.1 tonight I'll hold off on
> applying it. Maybe you can make an old man happy and change the
> variables from argc/argv to something else. :-)

No problem, I was expecting to be doing some reworking on it before
getting it accepted :D

And would hope to get some test users (and hopefully another sample
database maybe even with multiple cylinders and some events on it).

miika


More information about the subsurface mailing list