Commit graph

12 commits

Author SHA1 Message Date
Dirk Hohndel
08db242e0e Avoid ignoring file read errors
This fixes a bunch of Coverity warnings.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-03 10:02:55 -04:00
Miika Turkia
1533191176 Datatrak parsing
I have some trouble understanding this code, but as there is a clear
bug involved (null dereference), I ask others to verify if I am onto
something. And if datatrak import still works with this patch.

From af2935622b1f00f373ed38c8e3194e25504372b6 Mon Sep 17 00:00:00 2001
From: Miika Turkia <miika.turkia@gmail.com>
Date: Wed, 9 Sep 2015 18:03:45 +0300
Subject: [PATCH] Fix null dereference and parsing logic

Null dereference in the first change is obviously a bug.

The parsing logic I only assume to be wrong and suggest that we discard
dives that are deemed to be bogus.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-09 17:29:13 -07:00
Dirk Hohndel
e03b553e80 Make created dive site uuid deterministic
Having random uuids seemed like a good idea, but there are several
situations where they really cause problems. One is merging dive file
imports from V2 logfiles. Another is testing such imports.

Instead of making the uuid random we now hash the name and add the
timestamp of the first dive associated with this dive site to the hash
(first in this context is "first encountered" with no guarantee that it is
the chronologically first). This way V2 imports create deterministic uuids
but uuid conflicts are still extremely unlikely, even if the user has
multiple dive sites with the same name.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-25 10:43:48 -07:00
Dirk Hohndel
b1538c809d Code cleanup
Make precedence of && over || explicit.
Explicitly convert between char * and unsigned char *.
Don't assign potentially negative return code to an unsigend variable.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-06 13:59:14 -07:00
Dirk Hohndel
e76675d4df Whitespace cleanup
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-06 13:58:12 -07:00
Claudiu Olteanu
15704da703 Remove some white spaces
Make this code compliant with CodingStyle

Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-03-24 09:45:39 -07:00
Claudiu Olteanu
1e22f5ea29 Resolve some memory leak on datatrak source
The result of byte_to_bits should be freed by the caller.
This patch frees the memory allocated by that function.
Also there were some memory leaks in data_import and
read_file_header functions when an error occured.

Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-03-24 09:45:18 -07:00
Salvador Cuñat
c8583fcea3 Improve error management
Show error messages in main window, instead of stdout.
Use translated strings.
Remove redundant error message.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-03-23 08:40:48 -07:00
Salvador Cuñat
4571aa7ac6 Avoid duplicities on dive sites while importing
Instead of create an uuid for every imported dive, check if it exists. If not
create a new one.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-03-19 11:20:06 -07:00
Salvador Cuñat
f1ab6dd386 Add support for divemode if dive is SCR
Not necesary for OC as this is the default.

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-03-19 11:19:40 -07:00
Lubomir I. Ivanov
2a1a868db2 datatrak: some codings style fixes and fopen() usage
- subsurface_fopen() is needed
- translated one puts("") message
- sizeof(unsigned char | char) is always 1
- pointer symbol (*) location
- padding fixes
- braces fixes

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-03-11 07:38:22 -07:00
Salvador Cuñat
44b55bd1a2 Import Datatrak/WLog files
Sequentially parses a file, expected to be a Datatrak/WLog divelog, and
converts the dive info into Subsurface's dive structure.

As my first DC, back in 90s, was an Aladin Air X, the obvious choice of log
software was DTrak (Win version). After using it for some time we moved to WLog
(shareware software more user friendly than Dtrak, printing capable, and still
better, it runs under wine, which, as linux user, was definitive for me). Then,
some years later, my last Aladin died and I moved to an OSTC, forcing me to
look for a software that support this DC.
I found JDivelog which was capable of import Dtrak logs and used it for some
time until discovered Subsurface existence and devoted to it.

The fact was that importing Dtrak dives in JDivelog and then re-importing them
in Subsurface caused a significant data loss (mainly in the profile events and
alarms) and weird location of some other info in the dive notes (mostly tag
items in the original Dtrak software). This situation can't actually be solved
with tools like divelogs.de which causes similar if no greater data loss.

Although this won't be a core feature for Subsurface, I expect it can be useful
for some other divers as has been for me.

Comments and issues:

Datatrak/Wlog files include a lot of diving data which are not directly
supported in Subsurface, in these cases we choose mostly to use "tags".

The lack of some important info in Datatrak archives (e.g. tank's initial
pressure) forces us to do some arbitrary assumptions (e.g. initial pressure =
200 bar).

There might be archives coming directly from old DOS days, as first versions
of Datatrak run on that OS; they were coded CP437 or CP850, while dive logs
coming from Win versions seems to be coded CP1252. Finally, Wlog seems to use a
mixed confusing style. Program directly converts some of the old encoded chars
to iso8859 but is expected there be some issues with non alphabetic chars, e.g.
"ª".

There are two text fields: "Other activities" and "Dive notes", both limited to
256 char size. We have merged them in Subsurface's "Dive Notes" although the
first one could be "tagged", but we're unsure that the user had filled it in
a tag friendly way.

WLog adds some information to the dive and lets the user to write more than
256 chars notes. This is achieved, while keeping compatibility with DTrak
divelogs, by adding a complementary file named equally as the .log file and
with .add extension where all this info is stored.  We have, still, not worked
with this complementary files.

This work is based on the paper referenced in butracker #194 which has some
errors (e.g. beginning of log and beginning of dive are changed) and a lot of
bytes of unknown meaning. Example.log shows, at least, one more byte than those
referred in the paper for the O2 Aladin computer, this could be a byte referred
to the use of SCR but the lack of an OC dive with O2 computer makes impossible
for us to compare.

The only way we have figured out to distinguish a priori between SCR and non
SCR dives with O2 computers is that the dives are tagged with a "rebreather"
tag. Obviously this is not a very trusty way of doing things. In SCR dives,
the O2% in mix means, probably, the maximum O2% in the circuit, not the O2%
of the EAN mix in the tanks, which would be unknown in this case.

The list of DCs related in bug #194 paper seems incomplete, we have added
one or two from WLog and discarded those which are known to exist but whose
model is unknown, grouping them under the imaginative name of "unknown". The
list can easily be increased in the future if we ever know the models
identifiers.
BTW, in Example.log, 0x00 identifier is used for some DC dives and from my own
divelogs is inferred that 0x00 is used for manually entered dives, this could
easily be an error in Example.log coming from a preproduction DC model.

Example.log which is shipped in datatrak package is included in dives
directory for testing pourposes.

[Dirk Hohndel: some small cleanups, merged with latest master, support
               divesites, remove the pointless memset() before free() calls
	       add to cmake build]

Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-03-10 10:03:08 -07:00