Commit graph

27 commits

Author SHA1 Message Date
Miika Turkia
db6acfdd27 Update Shearwater sample time calculation
At least Shearwater Cloud seems to use multiple formats for sample time
recorded in the database. Sometimes the time is in seconds, sometimes in
milliseconds, and sometime it is something I have no idea about. Thus
switching to calculating the sample id myself and using sample interval
to calculate the actual sample time. Seems to be more reliable than
trying to guess what format Shearwater is using for this specific dive.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-19 11:20:27 -07:00
Miika Turkia
a7bed157b5 Grab the first gas on Shearwater import
The logic to retrieve gas changes from Shearwater cloud database is
detecting only when the O2/He chnages. This change will grab the initial
gas. (Problem was only shown when there was a gas changee in the log, so
cingle cylinder dives were working fine.)

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15 08:47:51 -07:00
Miika Turkia
23efcef58a Fix a bug on Shearwater cloud gas changes
Gas change is done to the cylinder we just found and not the last
cylinder. Also switching the variable name to index as we are actually
using that value outside the loop.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15 08:47:51 -07:00
Miika Turkia
b5c00c89e6 Import cylinder pressure correctly
Shearwater apparently stores correct pressures nowadays, so getting rid
of a hack to import double pressures.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15 08:47:51 -07:00
Miika Turkia
dee2b510bb Ignore gas changes if we one line contains bogus O2
This will ignore the gas changes that would be caused by Shearwater
cloud saving rows with 0 values in them.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15 08:47:51 -07:00
Miika Turkia
b8b67f239b New field for timestamp in shearwater cloud DB
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15 08:47:51 -07:00
Miika Turkia
06e6bcecb7 Shearwater cloud import: ignore bogus rows
A sample log I received contains a lot of rows with 0 values in it. This
will ignore the obviously bogus ones. (However, we might miss the first
sample if that is recorded at time 0.)

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15 08:47:51 -07:00
Berthold Stoeger
794066b236 Cylinders: access cylinders with get_cylinder()
Instead of accessing the cylinder table directly, use the get_cylinder()
function. This gives less unwieldy expressions. But more importantly,
the function does bound checking. This is crucial for now as the code
hasn't be properly audited since the change to arbitrarily sized
cylinder tables. Accesses of invalid cylinder indexes may lead to
silent data-corruption that is sometimes not even noticed by
valgrind. Returning NULL instead of an invalid pointer will make
debugging much easier.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
8df3705152 Cleanup: return cylinder from cylinder_start() in parser
Most callers of this function accessed the newly generated cylinder
immediately after calling this function. Thus, for convenience,
return the added cylinder. This avoids a number of verbose expressions.

On the flip side, cylinder_start() now has to be cast to
function returning void in a the "nesting" function table.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Berthold Stoeger
7c9f46acd2 Core: remove MAX_CYLINDERS restriction
Instead of using fixed size arrays, use a new cylinder_table structure.
The code copies the weightsystem code, but is significantly more complex
because cylinders are such an integral part of the core.

Two functions to access the cylinders were added:
get_cylinder() and get_or_create_cylinder()
The former does a simple array access and supposes that the cylinder
exists. The latter is used by the parser(s) and if a cylinder with
the given id does not exist, cylinders up to that id are generated.

One point will make C programmers cringe: the cylinder structure is
passed by value. This is due to the way the table-macros work. A
refactoring of the table macros is planned. It has to be noted that
the size of a cylinder_t is 64 bytes, i.e. 8 long words on a 64-bit
architecture, so passing on the stack is probably not even significantly
slower than passing as reference.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09 19:19:04 +01:00
Dirk Hohndel
d3d51b175d Cleanup: pass NULL pointer for error string pointer
Since we never did anything with the error string, why even ask for it.
And this way we don't have to deal with the memory returned, either.

Found by Coverity. Fixes CIDs 350124, 350113, 350106, 350099, 350091

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-10-26 19:17:53 -07:00
Berthold Stoeger
37146c5742 Parser: parse into custom dive site table
To extend the undo system to dive sites, the importers and downloaders
must not parse directly into the global dive site table. Instead,
pass a dive_site_table argument to parse into.

For now, always pass the global dive_site_table so that this commit
should not cause any functional change.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
7e33369dc8 Parser: add trip_table parameter to parsing functions
To allow parsing into arbitrary trip_tables, add the corresponding
parameter to the parsing functions and the parser state. Currently,
all callers pass the global trip_table so there should be no change
in functionality. These arguments will be replaced in subsequent commits.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09 20:58:04 -08:00
Miika Turkia
fd5aad7192 Use state structure for sample rate info
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2019-01-03 06:56:48 +02:00
Miika Turkia
9c42345494 Use correct value for PO2
averagePPO2 appears to be correct value instead of currentPPO2SetPoint.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2019-01-01 15:32:27 +02:00
Miika Turkia
5930cb52de Grab correct setpoint on Shearwater cloud import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-12-31 06:21:53 +02:00
Miika Turkia
01365b8c4b Use different time field as it seems to be more correct
The starTimestamp is 4 hours apart on 2 different DCs within the sample
log. DiveDate on the dive_logs table seems to be correct, but must be
converted from human readable format.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-12-30 16:31:51 +02:00
Miika Turkia
5e0f105114 Sample rate varies between dives
Seems that Shearwater cloud stores sample rate into the database and
it is not constant within the log.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-12-29 22:39:55 +02:00
Miika Turkia
2bc7aa5fc7 Initial support for Shearwater Cloud
This works to some extent to part of a sample log I received. However,
still quite a bit more work is needed.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-12-29 21:32:55 +02:00
Miika Turkia
a0d7b76dd0 Shearwater import: dive id might be large than int
I encountered this while implementing Shearwater Cloud import, but it
makes sense to increase the size for dive id for Shearwater Desktop as
well.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-12-29 21:31:12 +02:00
Berthold Stoeger
138f27f65d Parser: make parser (mostly) reentrant
Introduce a parser_state structure, which describes (most) of the
global parser state. Create such a structure in the entry routines
to the parser and pass it down to the individual functions. The
parser state is initialized and freed with the init_parser_state()
and free_parser_state() functions.

The main benefits are:
1) Isolation of parser state.
2) Keeping the global name space tidy.
3) Prevent memory leaks which could happen in truncated files by
   freeing all the parser state after parse.

A somewhat controversial point might be that the individual
parsing functions are split in those that need parser-state and
those that don't. This means that there are now two versions of
the MATCH macro, viz. one for the former and one for the latter.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-23 08:06:17 +01:00
Miika Turkia
7d2c08aed0 Remove unnecessary {}
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-05-27 23:18:01 +03:00
Miika Turkia
a929c86584 Shearwater import: avoid running atoi multiple times
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-05-27 23:18:01 +03:00
Miika Turkia
295c63211c Shearwater import: support for DC reported ceiling
This adds support for DC reported ceiling when importing the Shearwater
Desktop database. Both AI and non-AI versions are tested, but not all
possible paths. For non-AI the DC reported ceiling was from
firstStopDepth and for the AI version it was from the decoCeiling field.

I do not currently know when each of these fields are used, but at least
this works on my test data.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-05-27 23:18:01 +03:00
jan Iversen
061be82e31 core: replace (void) with UNUSED(x) and include ssrf.h
Unused parameters in C are "silenced" by adding UNUSED(x)

Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-24 08:34:14 -07:00
Dirk Hohndel
d577467f97 Core: introduce new subsurface-string header
First small step to shrinking dive.h.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14 10:13:39 -07:00
Miika Turkia
4325ae8d24 Move Shearwater DB import into its own file
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-11-29 01:22:17 +01:00