1518 Commits

Author SHA1 Message Date
Jef Driesen
01ccb7ce4b Fix a few memory leaks
The file list isn't freed when an error occurs, and the strings returned
from the lookup_enum function are dynamically allocated and thus should
be freed as well.
2018-04-03 21:10:04 +02:00
Jef Driesen
96bac1de13 Fix some compiler warnings
The descriptor strings are dynamically allocated and owned by the
struct. The const qualifiers are a bit misleading here, and result in
warnings when trying to free the pointers again.
2018-04-03 21:10:04 +02:00
Jef Driesen
ea2272d4b0 Fix a build error for msvc
The msvc build needs the platform header for the non-standard _snprintf
function.
2018-04-03 21:06:48 +02:00
Jef Driesen
2c7d1fe39f Use 64bit arithmetic to avoid overflow
The multiplication is evaluated using 32bit arithmetic, and then stored
in a 64bit integer. The 32bit integer overflow can be avoided by casting
to a 64bit type first.
2018-04-03 21:06:48 +02:00
Jef Driesen
54fef8e093 Add support for using an optional device descriptor
The device descriptor is either mandatory for a certain command (with
DCTOOL_CONFIG_DESCRIPTOR) or always NULL. But for some commands it will
be useful to support an optional descriptor as well. To support this, we
always try to lookup the device descriptor whenever the corresponding
command-line options are set.
2018-04-03 21:06:48 +02:00
Jef Driesen
0026fbd289 Re-write the slip encoding and decoding
The write function is modified to always fill the buffer completely
before sending out the data. For escaped characters, the previous
implementation needed to append two bytes at once. Thus, if there was
only space left for a single byte, the buffer got flushed early with one
byte still unused. This can be avoid by appending one byte at a time.

The read function is modified to use a simple state machine with only a
single read call. This is mainly preparation to support reading and
processing larger data packets instead of just single bytes.
2018-04-03 21:06:48 +02:00
Jef Driesen
b62f160dd5 Workaround for an OSTC4 issue
I received a bug report complaining that the most recent dives did not
get downloaded. It turns out that the internal dive number in the
logbook entries got reset back to zero somehow:

Logbook   0: empty
...
Logbook 209: empty
Logbook 210: 1
Logbook 211: 2
...
Logbook 235: 26
Logbook 236: 27
Logbook 237: 0
Logbook 238: 1
...
Logbook 254: 17
Logbook 255: 18

This confuses the logic to locate the most recent dive. Because that
logic assumes that the entry with the highest internal dive number is
always the most recent dive, it finds logbook entry #236 instead of the
correct entry #255. Now, when processing the logbook entries backwards,
it stops at those empty entries, and thus never reaches then newest
entries #237 to #255.

The workaround is based on the fact that the OSTC4, unlike the other
hwos based models, already re-orders the logbook entries and always
sends the most recent logbook entry last. So we can ignore the dive
number and simply use the last non-empty entry.
2018-04-03 21:06:48 +02:00
Linus Torvalds
c15d422f75 Suunto EON Steel: set date too when doing device timesync
I'd never noticed this before, since my date had always been already set
correctly, but the timesync with the EON Steel only set the time, not
the date.

The fix is trivial, since the code already filled in the datetime data,
it just didn't do the SET_DATE command.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-04-03 21:01:39 +02:00
Jef Driesen
5207fcd86b Add support for the dive mode
The Dive Rite NiTek Q supports OC and CC samples. For reporting the dive
mode, any dive containing at least one CC sample is considered to be a
CCR dive.
2018-03-09 21:35:51 +01:00
Jef Driesen
38ff1f75dd Remove the half-duplex emulation from the I/O api
Now that the half-duplex emulation code isn't used anymore, it can be
removed from the I/O stream api.
2018-03-05 09:08:21 +01:00
Jef Driesen
4897a8351b Handle the half-duplex emulation in the vyper2 backend
The half-duplex emulation is basically a workaround for a timing problem
in the vyper2 backend. Since no other dive computer backend uses or
needs this feature, it makes no sense to support this at the I/O layer.
It can be implemented directly in the vyper2 backend instead.
2018-03-05 09:08:21 +01:00
Jef Driesen
ee31f24cfb Use the new timer for the timestamps in the logging
Replace the platform specific code with the new timers.
2018-03-05 09:08:21 +01:00
Jef Driesen
eb4c150024 Use the new timer for the timeout calculations
Replace the gettimeofday() based implementation with the new monotonic
timers. This makes the implementation more robust against unexpected
adjustments of the clock.
2018-03-05 09:08:21 +01:00
Jef Driesen
a8adb16c0d Add a high resolution timer module
The new timer module provides an cross-platform interface for a high
resolution monotonic clock. The timestamps are always relative to the
creation of the timer and their unit is one microseconds.

The timers can be used for logging, measuring elapsed time and
implementing timeouts.
2018-03-05 08:44:14 +01:00
Jef Driesen
becaf02ab6 Add functions for converting bluetooth addresses 2018-03-04 20:49:49 +01:00
Jef Driesen
efd47cd9a1 Add support for the OSTC 2 TR
The OSTC 2 TR add supports for one or more tank pressure transmitters,
and the active transmitter is linked to the active gas mix.
2018-02-17 10:22:44 +01:00
Jef Driesen
0ac15dffd3 Add a workaround for invalid logbook begin pointers
Unfortunately there are several devices where an invalid logbook begin
pointer occurs relative frequently. Typical examples are the Oceanic VT
4.1 and the Sherwood Wisdom 2. In such cases, the strict validation of
the pointer causes the download to fail, without being able to download
any dives at all.

Since the begin pointer is only needed to detect the oldest logbook
entry, we can fall back to downloading the entire logbook ringbuffer. If
we're lucky (and we usually are), we can detect the oldest entry by
inspecting the logbook entries once they are downloaded (e.g. presence
of uninitialized entries) and then the download will finish succesfully.
In the worst case scenario, we'll be able to download at least some
dives before hitting another error.
2018-02-06 13:00:57 +01:00
Jef Driesen
05f5522210 Let the ringbuffer function handle a full ringbuffer
The ringbuffer_distance() function has a parameter to specify whether a
ringbuffer with identical begin/end pointers should be considered an
empty or a full ringbuffer. Hence there is no need to handle the case of
a full ringbuffer manually.
2018-02-06 13:00:34 +01:00
Jef Driesen
9117b593fc Suppress the warning if no O2 sensors are present
The warning about disabling the O2 sensors due to factory default
calibration values, applies only if there is at least one calibrated O2
sensor present.

This has no effect on the calibration bits, because those are already
zero if there are no calibrated O2 sensors present.
2018-02-05 19:58:22 +01:00
Jef Driesen
85eef19f8f Integrate the connect step into the open function
There is no need to expose the two step connection setup of the
underlying socket interface in the public api. Doing so may complicate
the implementation on platforms where the native api is not based on the
socket interface (e.g. Mac OS X).

Note that the function to connect based on the IrDA service name is
removed. It's not used anywhere in libdivecomputer and since IrDA is an
outdated technology nowadays, it's unlikely we'll need it in the future.
2018-02-04 21:21:42 +01:00
Jef Driesen
695212ddf8 Merge branch 'discovery' 2018-02-04 21:21:42 +01:00
Jef Driesen
0ce3bd3e6d Implement some filter functions 2018-02-04 21:21:42 +01:00
Jef Driesen
30e4060817 Add suport for applying a filter function
The device descriptors are extended with a filter function. During the
device discovery, this filter function is used to return only devices
that match a known dive computer.

The filtering is optional, and can be disabled by passing a NULL pointer
for the device descriptor when creating the iterator with one of the
dc_xxx_iterator_new() functions.
2018-02-04 21:21:42 +01:00
Jef Driesen
ca91500ed5 Re-write the device discovery using the iterator api
Replacing the callback based interface with an iterator based interface,
results in a more extensible abstraction with a common interface for
each of the built-in I/O implementations (serial, usbhid, irda and
bluetooth).
2018-02-04 21:21:16 +01:00
Jef Driesen
296fad2d9d Cleanup the iterator internals 2018-01-30 22:00:41 +01:00
Jef Driesen
f992d201ad Simplify the conditional compilation
Move the global variables inside an existing conditionally compiled
block, to remove some of the #ifdef's.
2018-01-30 21:21:21 +01:00
Jef Driesen
931d1857ce Disable some Windows specific compiler warnings
The -Wno-pedantic-ms-format option is only needed for the MinGW target.
But for some reason, the AX_APPEND_COMPILE_FLAGS macro enables the
option for all other GCC targets too. But during compilation GCC outputs
the warning "unrecognized command line option".
2018-01-30 21:21:21 +01:00
Jef Driesen
90eed3c790 Use SDP to auto-detect the rfcomm port number
When the port number is set to zero (which is an invalid value), detect
the port number automatically. On Windows, we can simply supply the UUID
of the serial port service, and the Windows api will take care of the
discovery. On Linux (bluez), the SDP discovery needs to be performed
manually to retrieve the port number.
2018-01-30 21:21:21 +01:00
Jef Driesen
6d5ac37f99 Use the actual IrDA device names 2018-01-30 21:21:21 +01:00
Jef Driesen
9e169c9a3f Use the correct data type for the temperature
Temperatures are reported as a floating point values and not as
(unsigned) integers.
2018-01-30 21:20:53 +01:00
Jef Driesen
3e36cad5ee Disable O2 sensors with default calibration values
If all (calibrated) sensors still have their factory default calibration
values (2100), they are probably not calibrated properly. To avoid
returning incorrect ppO2 values to the application, they are manually
disabled (e.g. marked as uncalibrated).
2018-01-30 19:56:49 +01:00
Jef Driesen
9ca91ca584 Add support for the Seac Jack
The Seac Jack is compatible with the DiveSystem/Ratio dive computers.
2018-01-30 19:52:27 +01:00
Jef Driesen
0ae9e355f8 Check for memory allocation errors
Appending data to the buffer may fail if a memory allocation is
necessary to enlarge the buffer. Hence the return value of the
dc_buffer_append() call should always be checked, unless the memory was
already pre-allocated or the check is deferred after the last operation.
2018-01-29 15:06:58 +01:00
Jef Driesen
c194f559d8 Erase the buffer before calling the vtable function
This guarantees that the backend will always receive an empty buffer,
and eliminates the need to clear the buffer manually in every single
backend.
2018-01-09 15:54:44 +01:00
Jef Driesen
d23bc6e089 Replace hardcoded size with the sizeof operator 2018-01-09 15:54:44 +01:00
Jef Driesen
c3556d81c9 Use the correct model number for the Shearwater Nerd 2
Unlike the Shearwater Petrel, the Shearwater Nerd 2 appears to have a
distinct model number from the Nerd.

Reported-by: Janice McLaughlin <janice@moremobilesoftware.com>
2018-01-09 15:53:52 +01:00
Jef Driesen
21b0f01852 Merge branch 'coverity' 2018-01-04 20:23:50 +01:00
Dirk Hohndel
4335c9b9eb Cleanup: remove confusing NULL check
device has already been dereferenced before we ever get here

Coverity CID 207713
Coverity CID 207780

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01:00
Dirk Hohndel
4144e0c7ff Cleanup: bail on error
Coverity CID 207809

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01:00
Dirk Hohndel
2f097e54fe Cleanup: consistently check return value of iostream functions
Coverity CID 215197
Coverity CID 215200

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01:00
Dirk Hohndel
4e93b9a8f8 Cleanup: check return value of ioctl()
It's checked for all the other invocations...

Coverity CID 207796

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01:00
Dirk Hohndel
e22adbb3f9 Cleanup: remove dead code and return the correct return code
Coverity CID 207700

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01: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
Dirk Hohndel
71f76819c0 Cleanup: ensure string is 0 terminated
The Linux kernel uses the sir_name as a standard C string (in one
instance copying it into a 60 char buffer using kstrncpy with a length
limit of 60), we therefore need to ensure that it is 0 terminated.

Since the existing code didn't notify the caller if we were truncating
the string at 25 characters, I didn't add such a warning/error for
truncating at 24 characters.

I was not able to find documentation on how Windows uses irdaServiceName
but since this is implementing the same standard, the same change was
made to the Windows code.

In both cases I replaced the hardcoded length of 25 with a sizeof()
argument (but both Linux and Windows hard code that length in their
headers, so it seems unlikely this would ever change).

Coverity CID 207790

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01:00
Dirk Hohndel
5997caf45f Cleanup: avoid memory leak
Coverity CID 207731

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01:00
Dirk Hohndel
681720e96a Cleanup: avoid memory leak
Coverity CID 207773

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01:00
Dirk Hohndel
96e6bf5848 Cleanup: avoid memory leaks
Coverity CID 207730
Coverity CID 207747

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:45:40 +01:00
Dirk Hohndel
bd00ddea17 Cleanup: correctly handle upper bound of array
Coverity CID 207684
Coverity CID 207724
Coverity CID 207728

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:45:40 +01:00
Jef Driesen
81f3fdd854 Fix a mistake in the error checking
This is a small bug that was introduced long time ago, with commit
84563c6303a4ab263ea19c973d3f0bbfe6fc0955.
2017-12-13 09:54:55 +01:00
Janice
a833992ed6 Add support for the Mares Quad Air 2017-12-13 09:50:52 +01:00