111 Commits

Author SHA1 Message Date
Jef Driesen
d47e1ce02b Add support for the Scubapro G3 and Luna 2.0
The new models appear to be compatible with the previous G2, but with
new model numbers and bluetooth names. The USB VID/PID for the G3 is
still unknown.

Reported-by: Greg McLaughlin <support@moremobilesoftware.com>
2024-01-10 09:01:59 +01:00
Jef Driesen
63f5a4d652 Remove the dc_parser_set_data function
The dc_parser_set_data() function allows to re-use a parser object for
multiple dives. The advantages of this feature are actually very limited
in practice. The reduction in memory consumption is almost negligible,
because the amount of internal state in the parser is typically very
small. But the implementation requires some additional complexity
because each backend needs code to reset its internal state. Therefore,
the function is removed and the data and size needs to be passed
directly to the dc_parser_new() and dc_parser_new2() functions instead.

Because keeping a reference to the data has also caused issues in the
past, especially for applications implemented in a garbage collected
language, the data will now also get copied internally.
2023-05-15 22:19:37 +02:00
Jef Driesen
4e24b3a277 Pass the sample struct by reference
Because the sample struct is passed by value, the size of the structure
can't be changed without also changing the function signature and
breaking backwards compatibility. This prevents adding new fields in the
future, to support some new features.

When passing the sample struct by reference using a pointer, the size of
the pointer does always remains the same.
2023-05-15 22:19:36 +02:00
Jef Driesen
becb8bd36e Add a usage field to the tank and gas mix
For gas consumption calculations it's very convenient to know whether a
tank is used for example in a sidemount configuration, or as
oxygen/diluent tank on a rebreather.

For rebreather dives, it's convenient to know whether a gas mix is used
as a closed-circuit mix (oxygen/diluent) or as an open circuit mix
(bailout).
2023-05-15 22:19:36 +02:00
Jef Driesen
a34e909a84 Change the units for the sample time to milliseconds
Some dive computers, especially freediving computers, supports multiple
samples per second. Since our smallest unit of time is one second, we
can't represent this, and the extra samples are dropped. Therefore, the
units are changed to milliseconds to prepare supporting this extra
resolution.
2023-05-15 22:19:34 +02:00
Jef Driesen
86fd58c8c6 Move the sign extension function to a common place 2023-03-23 19:43:16 +01:00
Jef Driesen
c5813d624a Add support for the Scubapro G2 TEK
The Scubapro G2 TEK is compatible with the G2, but with a new model
number.

Reported-by: Greg McLaughlin <support@moremobilesoftware.com>
2022-10-16 23:15:54 +02:00
Jef Driesen
12c77a228e Add a public api to configure the clock synchronization
For dive computers where the reference time (epoch) of the device is
unknown, libdivecomputer uses the current time of the device (devtime)
and the host system (systime) to synchronize both clocks.

Currently, both timestamps are passed directly to the constructor of the
parser. With the new public function, the application can adjust the
timestamps afterwards.
2022-08-11 17:36:26 +02:00
Jef Driesen
6ab140461a Add a public api to configure the depth calibration
Some dive computers store the depth as an absolute pressure value (in
bar). To convert to a depth value (in meters), the atmospheric pressure
and water density are required. For dive computers that do not have
those values available, libdivecomputer uses a default value. With the
new public api functions, applications can adjust those default values.

Some dive computers already provided a backend specific calibration
function. Those functions are now deprecated. They are kept around to
maintain backwards compatibility for now, but they will be removed in
the next version.
2022-08-11 17:36:15 +02:00
Jef Driesen
e6f091909b Remove unused time parameters
Since the clock synchronization has been removed (see commit
a1962558412b8c89a79656992c8e7f4d001065c2 for the details), those
parameters serve no purpose anymore.
2022-06-23 15:56:10 +02:00
Jef Driesen
8bfb965589 Move the C_ARRAY_SIZE macro to a common place 2022-05-23 12:14:00 +02:00
Jef Driesen
a8bcfb998b Restore the original standard gravity factor
The Uwatec/Scubapro dive computers are confirmed to internally use the
approximated standard gravity (10.0 m/s²) for the depth conversion.
Allthough this is technically wrong, users expect to get the same depth
values as their dive computer shows.

This partially reverts commit cfc9ddc380bdc5616893fc2af4e05204b5500ea2.
2021-10-03 11:37:59 +02:00
Jef Driesen
cfc9ddc380 Use the correct standard gravity factor
For manual depth calculations by divers, the standard gravity is
often approximated as 10.0 (e.g. 1 bar corresponds to 10 meter), but
libdivecomputer prefers to use the exact value of 9.80665 m/s².

For the McLean Extreme, it has been confirmed that the device also uses
the correct standard gravity internally for the conversion of the sample
depth.
2021-07-06 16:16:18 +02:00
Jef Driesen
cffda88ae8 Use SI units internally
Prefer SI units for internal constants (e.g. density) and calculations.
This results in more consistent conversion formulas across the different
backends.

For the Uwatec backend, this changes makes it also much more visible
that the unit for the depth is either 1 millibar (maximum depth) or 2
millibar (sample depth).
2021-07-06 16:16:18 +02:00
Jef Driesen
b186846a9e Fix negative depth values
The difference between two unsigned integers can be negative. To avoid
ending up with some very large positive values, an explicit cast to a
signed integer is required.

Depths are normally expected to be always positive, but near the surface
the pressure will be very close to the atmospheric pressure. Therefore
small negative values are not unusual.
2021-07-06 16:16:18 +02:00
Jef Driesen
da2446283a Move the unit conversion to the last moment
Processing the data in device units, and performing the unit conversion
only at the very last moment, avoids the need for intermediate floating
point math and thus possible rounding errors. In practice this is not
really an important issue, except for some case where a negative zero
value was returned.
2021-07-06 16:16:18 +02:00
Nick Shore
625f56b494 Add support for the Scubapro Aladin A2 2020-10-13 09:04:32 +02:00
Janice McLaughlin
a01b9bc9b9 Add support for the Scubapro A1 2020-02-04 08:41:55 +01:00
Jef Driesen
74957542bb Add support for the Scubapro G2 HUD
The G2 HUD is compatible with the G2, except for the new USB PID.
2019-04-23 10:00:08 +02:00
Jef Driesen
ab37d94ee9 Add a missing event descriptor
The Aladin Tec (and Tec 2G) sample descriptor table supports up to two
event bytes, but there is only a single event descriptor. This missing
descriptor causes a fatal error during parsing. Add a dummy descriptor
to avoid the error.
2018-06-11 12:54:50 +02:00
Dirk Hohndel
88cc5e1413 Cleanup: avoid undefined shift operation
Shifting a 32bit value by 32 is undefined.

Instead of using shifts to create the mask, explicitly create it by
subtracting 1 from the signbit value (and using bitwise NOT to fill all
the higher bits).

This commit looks confusing because Jef wanted me to not have two places
where I use the bitwise not. So instead of creating an equivalent mask
variable and not having to change the return statements we end up with a
mask that is the bitwise invert of what was there before this commit and
therefore the return statements need to change as well.

Coverity CID 207769

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01:00
Jef Driesen
428704b538 Add support for the Scubapro Aladin Square
The communication protocol is identical to the G2 protocol, but with a
different USB VID/PID (c251:2006).

Note that unlike the G2, the Aladin Square seems to support only 33 byte
USB HID packets (1 byte report id and 32 bytes payload), even when the
actual command is much smaller. Without padding the commands, the dive
computer doesn't reply at all. Because the padding is already there, to
support the Windows api, no further changes are necessary.
2017-11-16 16:33:11 +01:00
Berthold Stoeger
d0d4c7b994 Support for the Scubapro Aladin Sport Matrix.
The protocol is identical to the G2 protocol, with the exception of a
missing handshake.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-01 20:53:48 +01:00
Jef Driesen
a196255841 Replace the clock calibration with a fixed epoch
Currently the date/time parsing assumes the reference time (epoch) of
the device clock is unknown. Hence we retrieve the current time of the
device (devtime) and the host system (systime) during the download.
Since both timestamps represent the same instant in time, but with a
different reference time, we can calibrate the device clock as follows:

    ticks = parser->systime - (parser->devtime - timestamp) / 2

But this produces wrong results once the device clock has been adjusted
manually. Adjusting the device clock will suddenly increase (or
decrease) the devtime, while the systime continues ticking forwards
normally. Hence all dives recorded before the time adjustment will get
an incorrect date/time value.

Fortunately all devices appear to use a fixed epoch (2000-01-01 00:00:00
UTC) and we can simply replace the calibration with a hardcoded value.

Reported-By: Linus Torvalds <torvalds@linux-foundation.org>
2017-10-23 15:02:38 +02:00
Jef Driesen
cb2a4f4a72 Use more descriptive names
Those two samples are no longer unknown. The first one contains some
freedive related data, and the second one contains some additional data
with several sub types. At the moment only the tank and gas mix info is
used.
2017-09-02 10:34:23 +02:00
Jef Driesen
ce590b5bc9 Use two passes to parse the profile data
In the trimix data format, the tank and gas mix information is no longer
stored in the header, but in a special sample. Because this sample is
usually located at the end of the profile, the info isn't available yet
during the first pass. Hence the need for a second pass.

Without this change, the tank and gas mix samples will be missing unless
the caller calls the dc_parser_get_field() function before calling the
dc_parser_samples_foreach() function.
2017-09-02 10:12:44 +02:00
Jef Driesen
6b88bc1b8b Fix the Uwatec trimix data format
The trimix dive header is only 84 bytes large, instead of 0xB1 bytes.
The difference is quite hard to notice, because compared to the normal
Galileo data format, the majority of the fields are located at exactly
the same offset. But there are also some subtle differences, like the
settings field containing the freedive and gauge bits.

To fix this bug, a new header table is added. The rest of the code is
updated to use this new table instead of the old trimix flag. The only
place where the old flag is still used is for the decoding of the tank
and pressure sample.
2017-09-01 15:00:10 +02:00
Jef Driesen
156f54302d Add basic timezone support
Allthough most dive computers always use local time and don't support
timezones at all, there are a few exceptions. There are two different
sources of timezone information:

 - Some of the newer Uwatec/Scubapro devices use UTC internally and also
   support a timezone setting. This UTC offset is currently taken into
   account to obtain the dive date/time, but the UTC offset itself is
   lost.

 - Uwatec/Scubapro and Reefnet devices rely on the clock of the host
   system to synchronize the internal device clock and calculate the
   dive date/time. The consequence is that the resulting date/time is
   always in the timezone of the host system.

In order to preserve this timezone information, the dc_datetime_t
structure is extended with a new "timezone" field, containing the UTC
offset in seconds. Devices without timezone support will set the field
to the special value DC_TIMEZONE_NONE.

The dc_datetime_localtime() and dc_datetime_gmtime() functions will
automatically populate the new field with respectively the local
timezone offset and zero. The dc_datetime_mktime() function will take
into account the new timezone field for the conversion to UTC. The
special value DC_TIMEZONE_NONE is interpreted as zero.
2017-08-18 23:26:45 +02:00
Jef Driesen
3a05e0ecf0 Use the trimix data format 2017-06-28 15:32:39 +02:00
Jef Driesen
0a5623a949 Use the correct model number
The model number reported by the Scubapro G2 is 0x32.
2017-06-28 15:32:39 +02:00
Jef Driesen
d1a06e784c Remove deprecated functions from the public api
The vendor_product_parser_create() and vendor_product_device_open()
functions should be called indirectly, through the generic
dc_device_open() and dc_parser_new() functions. And the
vendor_product_extract_dives() functions are internal functions that
should never have been part of the public api in the first place.
2017-04-18 08:41:10 +02:00
Jef Driesen
640308c076 Disable freedive mode for the Uwatec Aladin Tec 2G
The Uwatec Aladin Tec 2G doesn't support freedive mode. This appears to
be a bug in SmartTrak and LogTrak. They both report gauge and air/nitrox
dives as apnea dives.
2017-03-27 21:36:11 +02:00
Jef Driesen
d0dbd1f6fd Remove the deprecated gas change events
The new gas mix sample has been around for a while now, and we're not
going to maintain the deprecated events forever.
2016-11-04 19:24:54 +01:00
Jef Driesen
decfa24f92 Fix the gas mix parsing for the Aladin Tec 2G.
Unlike the other models, the Aladin Tec 2G uses only a single byte to
store the oxygen percentage, and there is no need to manually re-map the
deco mix.

Normally, the oxygen percentage is stored using two bytes (little endian
byte order). Thus for a device supporting two gas mixes, four bytes will
be used, and the corresponding gas mix id for each byte is as follows:

  ID: 0 0 1 1

After re-mapping the id of the deco mix, this becomes:

  ID: 0 0 2 2

Since oxygen percentages are limited to the range 0-100%, the highest
byte (marked with an X) should always be zero and can thus be ignored:

  ID: 0 X 2 X

Now, because an oxygen percentage of zero indicates a disabled gas mix,
this is equivalent to a device supporting three (or even four) gas
mixes, each stored using only a single byte:

  ID: 0 1 2 3

We can take advantage of this knowledge to avoid having to re-map the
deco mix id.
2016-09-02 16:34:06 +02:00
Jef Driesen
0ab2d8ccda Use the new settings field for the salinity.
Since the salinity bit is stored in the settings, there is no need for a
separate salinity entry in the header tables.
2016-08-17 14:09:52 +02:00
Jef Driesen
bfcd707889 Fix the parsing of freedives.
In freedive mode the sample rate is only 1 second instead of 4 seconds.
The tank pressure fields appear to be re-used for some other (unknown)
purposes, and should be ignored.
2016-08-17 14:08:50 +02:00
Jef Driesen
8b0a048175 Detect the gauge and freedive mode correctly.
The gauge and freedive mode bits are stored in the settings field. The
location of the gauge bit appears to be the same for all models. For the
freedive bit it depends on the model, and also not all models support
it.
2016-08-17 08:10:36 +02:00
Jef Driesen
1226b47c6d Add the salinity field for the Aladin Tec. 2016-08-17 08:10:11 +02:00
Jef Driesen
769d90aca2 Add support for the Scubapro Mantis 2. 2016-08-14 10:07:45 +02:00
Thomas Gschwind
0a769cdd57 Add salinity and timezone fields to Aladin Tec 2G 2016-08-07 09:31:21 +02:00
Jef Driesen
ff29d218bb Use helper functions to allocate and free objects.
Both the allocation and initialization of the object data structure is
now moved to a single function. The corresponding deallocation function
is intended to free objects that have been allocated, but are not fully
initialized yet. The public cleanup function shouldn't be used in such
case, because it may try to release resources that haven't been
initialized yet.
2016-01-05 20:40:21 +01:00
Jef Driesen
9bc14dca10 Remove some boilerplate code from the cleanup functions.
Instead of freeing the object data structure in the backend specific
cleanup function, the memory is now freed automatically in the base
class function. This reduces the amount of boilerplate code in the
backends. Backends that don't allocate any additional resources, do no
longer require a cleanup function at all.
2016-01-05 20:40:21 +01:00
Jef Driesen
18d4d5dcc0 Switch to goto style error handling.
With the goto error handling, all cleanup code can be moved to a central
location and no longer needs to be duplicated multiple times.
2016-01-05 20:40:21 +01:00
Jef Driesen
06e0de6712 Add a new sample with the active gas mix.
The new gasmix sample contains the index of the active gas mix.

This new sample is intended as a replacement for the existing gas change
events (SAMPLE_EVENT_GASCHANGE and SAMPLE_EVENT_GASCHANGE2). To maintain
backwards compatibility, the legacy events are marked as deprecated but
not removed yet.
2015-12-21 14:03:39 +01:00
Jef Driesen
842c4ca466 Fix the salt water conversion.
The dive computer records the raw absolute pressure. To convert this
pressure value into a depth, we need to divide by the salinity factor,
not multiply!
2015-11-10 10:42:36 +01:00
Jef Driesen
ae70d1efba Fix the dive mode for the Galileo Trimix.
Parsing the gas mixes has been implemented a while ago, so this check is
no longer neccessary.
2015-10-29 09:28:56 +01:00
Jef Driesen
6f89e445e3 Convert the internal tank id to an index.
The internal Uwatec tank id should be converted to the libdivecomputer
tank index. If there is no corresponding tank, the tank pressure samples
are dropped for the following reasons:

Some models appear to record an absolute tank pressure sample, even if
there is no pressure sensor attached to the corresponding tank. In this
case only the tank index changes. The sample value simply retains the
last pressure of the previous tank. Since we don't have any real
pressure data, dropping those samples is fine.
2015-10-28 08:26:58 +01:00
Jef Driesen
3fa606a8a2 Fix the gas switches for Galileo Trimix.
The Galileo Trimix supports up to 10 tanks and gas mixes. However, the
existing alarm based gas switch events have only 2 bits available, and
can support at most 4 gas mixes. Therefore, the trimix variant stores
another 4 bit value in the second alarm byte.

For the first three gas mixes (and possibly also the fourth), both alarm
bytes appear to be always set to the same value. For the higher mixes,
the value in the first alarm byte is always zero. This doesn't cause any
problems, because in the data stream the second alarm byte is stored
after the first one, and our final value is always the last one.

The non-trimix variant also has the second alarm byte, but the gas mix
bits appear to be always zero. In order to avoid taking this zero as the
final value, a separate table is used for the trimix variant.
2015-09-17 11:24:16 +02:00
Jef Driesen
3ff890b3e2 Improve the detection of unused tanks.
The begin/end pressure for unused tanks is normally zero. But I noticed
that in some cases both pressure values are stored as 0xFFFF. Since that
corresponds to a pressure of 511.99 bar, this is most likely some
special magic value, and not a valid pressure.

Tanks where either the begin or end pressure is 0xFFFF are now ignored
too.
2015-08-28 07:28:26 +02:00
Jef Driesen
5381714d08 Fix a bug in the tank id.
Due to a bitshift with the wrong number of bits, the tank id was always
zero for the Uwatec trimix firmware.
2015-08-20 09:08:56 +02:00