1313 Commits

Author SHA1 Message Date
Jef Driesen
aafdbe8baa Fix the date for the Oceanic Datamask. 2016-02-16 20:38:03 +01:00
Jef Driesen
d2e150319b Fix the decoding of negative temperatures.
Due to a firmware bug, negative temperatures are stored incorrectly and
a workaround is necessary to recover the correct value.
2016-02-04 20:44:30 +01:00
Jef Driesen
67a3697a4d Disable the getopt argument permutation on BSD systems.
On BSD based operating systems (which includes Mac OS X), 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.
2016-01-30 23:00:17 +01:00
Jef Driesen
5add68b2d5 Use the optreset variable on BSD systems.
On BSD based operating systems the optreset variable should be used to
reset the internal getopt state. Setting optind to zero is a GNU
extension.
2016-01-30 23:00:17 +01:00
Jef Driesen
ade8619ea6 Don't assume malloc sets errno to ENOMEM.
Although many implementations (including glibc) set errno on failure,
this is not required by the C standard.
2016-01-26 20:32:22 +01:00
Jef Driesen
4228899f59 Reduce the conditional compilation for Windows.
With a few compatibility macros and helper variables, the amount of
conditional compilation can be greatly reduced.
2016-01-26 20:32:22 +01:00
Jef Driesen
4475d69814 Use the error code returned by the WSAStartup function.
Unlike the other socket functions, the WSAStartup() function returns the
extended error code directly. A call to the WSAGetLastError() function
is not needed and should not be used.
2016-01-21 20:11:36 +01:00
Jef Driesen
0acdee08a1 Merge branch 'f11' 2016-01-18 13:04:07 +01:00
Jef Driesen
6b3874121d Don't ignore zero depth samples in freedive mode.
In freedive mode, samples are only 2 or 4 bytes large, thus a sample
containing all 0x00 bytes represents a zero depth value and not some
invalid data that should be ignored.
2016-01-18 13:03:48 +01:00
Jef Driesen
789fdb4d9a Remove the footer sample for the F10 and F11.
The F10 and F11 don't seem to have a special footer sample after the
profile data. Those 8 bytes appear to be valid sample data.
2016-01-18 13:03:47 +01:00
Jef Driesen
ca032783a2 Fix the decoding of the dive time.
I originally assumed the second byte contains the hour, but that turns
out to be wrong. At least some of the bits have a different meaning.
With only seconds and minutes, the maximum divetime is limited to at
most 99 minutes and 59 seconds. That shouldn't be a problem for
freedives.
2016-01-18 13:03:47 +01:00
Jef Driesen
49af321bc5 Use the correct sample rate from the header.
The Oceanic and Aeris F11 have a configurable sample rate. The possible
sample intervals are 2, 1, 0.5 and 0.25 seconds. Since our smallest unit
of time is one second, we can't represent the last two, and the extra
samples will get dropped for now.
2016-01-18 13:03:47 +01:00
Jef Driesen
9d856e5a36 Fix the memory layout for the Oceanic F11. 2016-01-18 13:03:47 +01:00
Jef Driesen
9520ecddbc Add support for the Oceanic F11.
This appears to be an Oceanic branded version of the Aeris F11.
2016-01-18 13:03:47 +01:00
Jef Driesen
0afa60bd97 Return a more appropriate error code.
The DC_STATUS_IO code is intended for reporting low-level I/O errors.
That's not the case here, and there are more appropriate error codes
available.
2016-01-18 12:56:49 +01: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
f1c0249053 Simplify the error handling in the close function.
When the close function returns, all resources should be freed,
regardless of whether an error has occured or not. The error code is
purely informative.

However, in order to return the first error code, which is usually the
most interesting one, the current implementation is unnecessary
complicated. If an error occurs, there is no need to exit immediately.
Simply store the error code unless there is already a previous one, and
then continue.
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
0fb6f5a7fa Merge branch 'dctool' 2016-01-05 20:39:52 +01:00
Jef Driesen
013882f3f2 Add the fwupdate command. 2016-01-05 20:38:47 +01:00
Jef Driesen
ce472ffa19 Add the read and write commands. 2016-01-05 20:38:47 +01:00
Jef Driesen
195c4c7a7e Add the download command. 2016-01-05 20:38:47 +01:00
Jef Driesen
bfbb56c781 Add the dump command. 2016-01-04 19:50:51 +01:00
Jef Driesen
ff7c3f6901 Add the list command. 2016-01-04 19:50:51 +01:00
Jef Driesen
4dee95d352 Add the version command. 2016-01-04 19:50:51 +01:00
Jef Driesen
38c9ebc74e Add the help command. 2016-01-04 19:50:51 +01:00
Jef Driesen
57a54f824c Add helper functions for converting hexadecimal data. 2016-01-04 19:50:51 +01:00
Jef Driesen
8f61648a39 Add helper functions for reading/writing binary files. 2016-01-04 19:50:51 +01:00
Jef Driesen
5188f5c25f Add a helper function for translating status codes. 2016-01-04 19:50:51 +01:00
Jef Driesen
655e9ad312 Add a default event handler. 2016-01-04 19:50:51 +01:00
Jef Driesen
28d8759294 Setup the cancel signal handler. 2016-01-04 19:50:51 +01:00
Jef Driesen
f0e5edc50b Setup the device descriptor. 2016-01-04 19:50:51 +01:00
Jef Driesen
3c57060d95 Setup the library context. 2016-01-04 19:50:51 +01:00
Jef Driesen
689e1f1f55 Change the format for error and warning messages.
Use the same format as used for printing the error and warning messages
from libdivecomputer itself.
2016-01-04 19:50:51 +01:00
Jef Driesen
b5503e53fd Add a more modular example application.
The universal application works well, but is quite difficult to extend
with more functionality. Therefore a new and more modular application is
needed. The new dctool application will support multiple sub-commands,
to carry out specific actions. Extending the application will be as easy
as adding new commands.
2016-01-04 19:50:51 +01:00
Jef Driesen
dd779d531a Fix the date parsing for several models.
To store the day (range 1 to 31) as a binary encoded value, only 5 bits
are required. The extra 6th bit is part of the year. The year is also
not BCD encoded. This happened to work by accident, because for a single
nibble, the current implementation of the bcd2dec() function returns the
binary value.
2016-01-04 19:30:40 +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
d839852953 Parse the profile to retrieve the bailout gas mixes.
In CC mode, only the diluents are stored in the header. The list with
the OC gas mixes, which are used for bailout, are not stored in the
header. In order to retrieve the bailout mixes too, we need to parse the
profile and add them to the manual gas mixes.
2015-12-21 12:58:02 +01:00
Jef Driesen
5c6c4cccc7 Add support for the DiveSystem iX3M series.
The protocol of the iX3M series is almost identical to the protocol of
the iDive series. The main difference is that the command bytes and the
size of the response packets have been changed. In order to be able to
communicate with the correct set of commands, the user needs to supply
the correct number now. To maintain backwards compatibility, a new
variant of the open function is added.
2015-12-14 12:23:31 +01:00
Jef Driesen
d516376ce7 Improve the support for pseudo terminals.
Apparantly Fedora applies a custom patch to glibc's tcsetattr()
function, which adds an extra check to verify the PARENB/CREAD/CSIZE
bits in the termios c_cflag field.

However, in commit 197b9f09421111e03588c94d55a72aa6ec624c63 we already
discovered that for pty's, some of the termios settings make no sense at
all, and therefore the Linux kernel always does:

    tty->termios.c_cflag &= ~(CSIZE | PARENB);
    tty->termios.c_cflag |= (CS8 | CREAD);

Thus, instead of ignoring such nonsense termios settings, the kernel
changes the termios structure to reflect what pty's actually do. The
consequence is that these settings will not stick, and cause the extra
check in the Fedora specific patch to fail.

To workaround this problem, we ignore the error when building
libdivecomputer with pty support enabled.
2015-12-10 19:41:41 +01:00
Gilbert J. M. Forkel
07c9cf8950 Correctly detect a device without any dives.
If the dive computer has not recorded any dives yet, the profile pointer
isn't valid and contains the default value 0xFFFFFFFF. There is no need
to return an error in this case.
2015-12-10 14:53:45 +01:00
Jef Driesen
a4838e7cfc Fix the layout for the Oceanic Atom 1.0.
The profile ringbuffer starts already at address 0x0440 instead of
0x0A40. The logbook ringbuffer is therefore a bit smaller too.
2015-12-06 17:40:41 +01:00
Jef Driesen
a155fb717b Add extra debug information to the error messages.
With the extra debug information it's easier to investigate the
underlying problem, without needing a debugger.
2015-12-06 17:40:02 +01:00
Jef Driesen
9ee3a10390 Add a workaround for a missing initial gas mix.
In some rare cases, the initial gas mix contains the value 0xFF. This
value is obviously outside the expected range (1-5), and therefore
causes the parsing to fail. It's not really clear how this can happen.

As a workaround for the fatal error, we now ignore the invalid value and
simply proceed without a gas mix.
2015-12-06 17:38:03 +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
4552558e87 Use an output parameter for the number of bytes.
With the number of bytes returned separately from the error code, we can
immediately return the correct error code.
2015-11-10 08:24:15 +01:00
Jef Driesen
fb5f7ad971 Use the GCC printf format attribute.
This enables the compiler to check the arguments against a printf style
format string in all calls to the logging functions.
2015-11-06 07:52:27 +01:00
Jef Driesen
0a20eae342 Prefer the C99 identifier for the function name.
The GCC 5 compiler with -Wpedantic enabled generates warnings for the
non-standard predefined identifier __FUNCTION___. These warnings can be
avoided by using the C99 identifier __func__ instead.
2015-11-06 07:51:42 +01:00
Jef Driesen
84d67c5544 Add support for the new OSTC logbook format.
With the new logbook format version 0x24, the OSTC no longer stores the
date/time at the end of the dive, but at the start of the dive.
2015-10-29 09:50:37 +01:00