2041 Commits

Author SHA1 Message Date
Jef Driesen
083b1eb8de Move the Visual Studio project to the contrib directory
With this change all the alternative build systems are now located in
the contrib directory.
2023-04-07 20:35:05 +02:00
Jef Driesen
118f6d79ba Add a basic Android build system
Add a basic Android.mk for building with the Android NDK. This can serve
as a good starting point for developers integrating libdivecomputer into
an Android application.

Co-authored-by: Sven Knoch <info@divinglog.de>
2023-04-07 20:35:02 +02:00
Jef Driesen
cf221de9b7 Disable the getopt argument permutation on Android
On Android operating systems, the getopt() function is posix compliant
and thus the option processing stops when the first non-option is found.
But the getopt_long() function permutes the argument vector, just like
the GNU implementation.

Using a leading '+' character in the option string disables the
permutation again.
2023-04-07 14:04:00 +02:00
Jef Driesen
86fd58c8c6 Move the sign extension function to a common place 2023-03-23 19:43:16 +01:00
Jef Driesen
1930b9eb59 Merge branch 'checksums' 2023-03-23 19:41:11 +01:00
Jef Driesen
554855cc7d Add the 16-bit CRC-ANSI functions
Yet another family of 16-bit CRC function. The only difference with the
already available CRC-CCITT algorithm is the choice of the polynomial.
2023-03-23 19:31:01 +01:00
Jef Driesen
27b471e76b Document the properties of the CRC functions 2023-03-23 19:30:23 +01:00
Jef Driesen
00033e4af0 Rename the 32-bit CRC functions
The new names make it easier to identify the normal and reflected
variant of the CRC function.
2023-03-23 19:30:23 +01:00
Jef Driesen
d327aea6ff Add a reflected variant of the 16-bit CRC-CCITT
The reflected variant of a CRC does reverse the bits of each input byte
and requires a different lookup table for an efficient implementation.
2023-03-23 19:28:37 +01:00
Jef Driesen
12f44f3410 Add an extra parameter for the xorout value
This change allows to calculate some more variants of the CRC-CCITT
algorithm with a single function.
2023-03-23 19:28:24 +01:00
Jef Driesen
2ba9904757 Fix the OSTC4 diluent changes
The hwos devices support 5 gas mixes for open-circuit and 5 diluents for
CCR dives. Internally, both sets are stored separately, but depending on
the dive mode only one of both sets gets stored in the dive header. The
gas change event contains the index of the corresponding gas mix or
diluent, and should always be in the range 1 to 5.

The OSTC4 behaves a bit different from the other hwOS models and uses
index 6 to 10 for the diluents. That means the index needs to be
adjusted to refer to the correct mix in the dive header.

Reported-by: Michael Keller <github@ike.ch>
2023-02-23 23:46:13 +01:00
Jef Driesen
255a2dbb9a Keep open-circuit and diluent gas mixes separately
The OSTC stores either the OC gas mixes or the CCR diluents depending on
the dive mode. For CCR dives, there is also bailout to an OC gas
possible, and those gas mixes are added dynamically to the manual gas
mixes.

The Shearwater dive computers store both the configured OC gas mixes and
CCR diluents in the header.

In both cases, the gas change events should reference the correct type
of gas mix. This patch takes care of that.
2023-02-17 15:00:49 +01:00
Jef Driesen
ee78d6f65b Parse some extra gas mix information
Keep track of the gas mix type, and whether the gas mix is enabled or
not. Right now this extra information isn't really used for anything
yet, but it's available for future use.
2023-02-17 14:45:05 +01:00
Jef Driesen
328812e95b Limit the index to the fixed gas mixes
The index in the gas change event should refer to the one of the fixed
gas mixes. All gas mixes with a higher index are either manual or
bailout gas mixes, and are reported with different events containing an
O2 and He percentages instead.
2023-02-17 14:45:05 +01:00
Jef Driesen
98c7887e9c Handle dives without a valid gas mix more explicit
Dives without a valid gas mix in the sample data (e.g. both the O2 and
He set to zero) are currently ignored by accident. Because the
o2_previous and he_previous variables were initialized to zero, those
invalid gas mixes were not processed.

Add an explicit check for such gas mixes to make this more obvious.
2023-02-17 14:43:32 +01:00
Jef Driesen
5fd9317533 Ignore all gas mixes for freedives
For freedives it makes no sense to report any gas mixes. The freedives
also use a different sample format, which doesn't generate any gas
change events.
2023-02-17 14:41:01 +01:00
Jef Driesen
9787bb7ac9 Always include all gas mixes defined in the header
Especially among technical divers, it's not uncommon to carry spare
tanks that will only be used in emergency situations (for example a
rebreather with one or more bailout tanks). Since those gas mixes are
not used throughout the dive, they were also not reported to the
application.

Fixed by reporting all configured gas mixes. Applications can still
obtain the previous result after manually inspecting the gas switch
events in the samples and filtering out the unused gas mixes.

This partially reverts commit c8b166dadbf961e17a9bd1cc28db3d92832ddf72.
2023-02-16 14:05:53 +01:00
Jef Driesen
201be561d4 Add support for the new Excursion v6+ firmware
The new Excursion v6 firmware supports some new commands for accessing
the dive index, and also uses a completely new data format. To preserve
backwards compatibility in the download logic to some extent, some
critical fields such as the profile length, remain stored at identical
offsets.

The new data format now contains a version field to allow for future
modifications. This version field is located at byte offset 3, which
corresponds to the highest byte of the 32 bit dive number in the old
format. Thus, unless someone manages to reach 16M dives, this field will
always be zero for the old format.

Co-authored-by: Ryan Gardner <ryebrye@gmail.com>
2023-02-09 08:17:32 +01:00
Jef Driesen
78373d827b Add support for the HP CCR tank pressure
For the HP CCR mode, the O2 and diluent tank pressure was stored in the
T1 and T2 tank pressure fields. Starting from log version 14 they moved
to dedicated fields in the EXT sample, next to the T3 and T4 tank
pressure. Thus the maximum number of tanks increased from 4 to 6.
2023-02-03 07:56:47 +01:00
Jef Driesen
4e83b1642c Use the correct field for the setpoint sample
This only happened to work correctly because both the setpoint and ppO2
field have the same data type and are located at the same offset in the
union.
2023-01-27 09:25:58 +01:00
Jef Driesen
9eef8c50c0 Add support for the Oceans S1
The Oceans S1 uses a plaintext and line based communication protocol
over BLE. The larger payloads, which also contain plaintext data, are
transferred using the XMODEM-CRC protocol.

Based-on-code-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-01-25 14:17:29 +01:00
Jef Driesen
86e9cc3443 Add support for the Deepblu Cosmiq+
The Deepblu Cosmiq+ uses a plaintext and line based communication
protocol over BLE, where the binary payload data is encoded as
hexadecimal characters.

Based-on-code-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-01-25 13:32:14 +01:00
Jef Driesen
3ce34a0b6d Add missing functions for accessing big/little endian values
There are functions for reading 8, 16, 24 and 32-bit big and little
endian values, but the corresponding functions for writing such values
are not always available. The 64-bit variants are also missing.
2023-01-25 13:32:14 +01:00
Jef Driesen
187f8d625b Move the snprintf functions to the platform module
Moving the implementation of the snprintf wrapper functions to the
platform module allows to re-use the same implementation throughout the
entire codebase.
2023-01-25 13:32:14 +01:00
Jef Driesen
fca64faa3c Merge branch 'proplus4' 2023-01-25 12:15:50 +01:00
Jef Driesen
e0e3bc8994 Repeat the handshake every few packets
The Oceanic Pro Plus 4 appears to "disconnect" somehow after about 30
seconds. The BLE connection remains up, but the dive computer simply
stops responding to commands. The download fails with a timeout error,
and the end-user can only download a few dives at most.

The Android DiverLog+ application appears to keep the connection alive
by re-sending the version and handshake commands once in a while. Copy
this behaviour by repeating those two commands every 50 read requests.
During testing, that's approximately every 25 seconds.

Note that both commands are required, sending only one of them does not
fix the problem.
2023-01-25 12:13:08 +01:00
Jef Driesen
ceae89e149 Enable big page support
The Oceanic Pro Plus 4 appears to support the big page B4 and B8 read
commands, but with some strange twists:

 * When sending the B8 read command, a 256 byte packet is received. The
   checksums of the packet are valid, but the upper half of the payload
   data is always filled with zero bytes. That means we can't use this
   command.

 * The B4 read command appears to use a 2 byte checksum instead of the
   normal 1 byte checksum. That means we can use this command with a
   small model specific tweak.
2023-01-23 21:13:52 +01:00
Jef Driesen
3414f72f60 Remove the model number from the vtpro struct
The model number is now also available in the common struct. There is no
need to store it twice. The auto-detected model number from the version
table is also more reliable than the one passed by the caller.
2023-01-23 21:10:10 +01:00
Jef Driesen
d0857c49ec Add the model number to the version table
With the model number in the version table, the version string can be
mapped to the corresponding model number. This allows to implement some
model specific behaviour already before being able to read the model
number.

In most cases, there is a simple one to one relationship between the
version string and the model number, but there are also a few
exceptions:

 * For the Sherwood Wisdom 2 and 3, and the Beuchat Mundial 2 and 3,
   each variant has a different model number, but the first part of the
   version string is identical. The difference is in the firmware
   version part. Handling this correctly requires two entries in the
   table.

 * For the Oceanic OC1 there are 3 different model numbers, and only 2
   different version strings. That means there is no correct mapping
   possible.
2023-01-23 21:10:10 +01:00
Jef Driesen
f59cbf0fe5 Move all model numbers to the common header 2023-01-23 21:10:10 +01:00
Jef Driesen
45b9ee8376 Remove a duplicated include statement 2023-01-23 21:10:10 +01:00
Jef Driesen
cf81ac79b3 Add support for the 300bar pressure sensor
The new 300bar pressure transmitter records the pressure in units of
2bar, because otherwise the value doesn't fit into an 8-bit integer.
2023-01-19 16:18:42 +01:00
Jef Driesen
90bb40e5ea Fix the iX3M 2 decompression algorithms
The iX3M 2021 and iX3M 2 models use different values for the
decompression algorithm.
2023-01-19 14:50:00 +01:00
Jef Driesen
bf268d79b4 Fix parsing dives using dual Buhlmann and VPM algorithm
Some iX3M models support a dual mode Buhlmann and VPM decompression
algorithm. Currently libdivecomputer is only capable of reporting one of
those two algorithms, but that's still better than returning an error.
2023-01-17 08:19:58 +01:00
Nikolay Zhekov
989c992154 Add Shearwater Perdix AI hardware ID 2023-01-07 19:50:34 +01:00
Jef Driesen
b1f4ad94eb Fix the decoding of the CNS value
The CNS value is reported as a fraction instead of a percentage.
2023-01-06 17:16:29 +01:00
Jef Driesen
547b1cfd15 Parse the timezone setting
Since firmware version 5B and later, a timezone offset is available.
2023-01-06 17:16:29 +01:00
Jef Driesen
9019805f52 Validate the parameter before calling the vtable function
This removes the need to validate the date/time pointer in every single
backend.
2022-12-21 14:55:50 +01:00
Jef Driesen
f4fae1b9f6 Add some workarounds for the msvc compiler 2022-12-21 14:55:50 +01:00
Jef Driesen
094a225363 Detect the posix unistd.h header file
The getopt function is defined in the unistd.h header file. This header
file is only available on posix compatible systems. For example, on
Windows it's not available when building without mingw.
2022-12-21 14:55:12 +01:00
Jef Driesen
79c9c5b7f9 Add support for the Oceanic Geo Air
The Oceanic Geo Air appears to be compatible with the OC1.
2022-12-08 23:16:31 +01:00
Jef Driesen
59a0844ee6 Fix the progress events when no dives are present
When no dives are present, the maximum value for the progress events is
set to zero, which triggers an assert. Fixed by letting the progress
events reach 100% instead.
2022-12-03 13:29:10 +01:00
Jef Driesen
ed0b21beae Increase the BLE packet size
In the latest G2 firmware v2.0, the size of the BLE packets increased to
101 bytes (with a one byte header and 100 bytes of actual payload). This
caused the download to fail, because the internal buffer was suddenly
too small for those larger packets.

These larger packets are most likely due to an update in the BLE stack
of the dive computer. Originally, the maximum BLE packet size was just
20 bytes (excluding the 4 byte L2CAP header and 3 bytes GATT header),
but BLE 4.2 increased the maximum packet size to 244 bytes (or 251 bytes
with the headers).

The USB HID code path keeps using the same fixed size packets as before.
2022-12-02 13:45:50 +01:00
Jef Driesen
755f23fdfa Ignore the first byte of the BLE packets
The first byte of the BLE packets does no longer contain the size of the
payload. Since BLE supports variable sized packets, we can simply ignore
this byte and obtain the payload size from the BLE packet size.
2022-12-01 14:12:41 +01:00
Jef Driesen
db2540485e Link hidapi statically against libgcc
When compiling a 32bit dll with the mingw-w64 compiler, some 64bit
integer arithmetic operations are implemented using functions from
libgcc (e.g. __udivdi3 and __umoddi3 from libgcc_s_dw2-1.dll). This
unexpected dependency is inconvenient for applications.

The run-time dependency can be avoid by linking statically.
2022-11-25 21:54:34 +01:00
Jef Driesen
2577afed55 Update libusb and hidapi in the CI builds
The current hidapi version (v0.10.1) fails to build with newer autoconf
versions (v2.70) due to a duplicated AC_CONFIG_MACRO_DIR macro in the
configure.ac file. This is fixed in newer versions.
2022-11-25 21:52:23 +01:00
Jef Driesen
2c5ebef594 Add udev rules for hidraw devices
The hidapi-hidraw variant of the hidapi library needs access to the
specific /dev/hidraw* device nodes. The existing udev rules for the USB
devices don't apply to the hidraw device nodes.
2022-11-25 13:25:23 +01:00
Jef Driesen
913a65fde6 Allow to specify the hidapi library variant
On Linux, the hidapi library is usually available in two variants:
hidapi-libusb and hidapi-hidraw. By default, the autotools build system
won't be able to detect those variants (due to the difference in the
name) and will automatically fallback to the libusb implementation
instead.

If for some reason the hidapi library should be used, the preferred
hidapi variant can now be specified during configuation with a
parameter:

  ./configure --with-hidapi=hidapi-libusb|hidapi-hidraw

The default value for the parameter remains 'hidapi'.
2022-11-25 13:25:23 +01:00
Jef Driesen
5218d3921a Read the software and hardware version 2022-11-23 08:37:25 +01:00
Jef Driesen
6874130743 Add the return type to the function definition
In commit 12c77a228e84f1ceed520b6afb53b4b64ea9def6, the return type of
the function was accidentally omitted.
2022-11-19 17:43:46 +01:00