1641 Commits

Author SHA1 Message Date
Dirk Hohndel
76eb18ff18 Cleanup: avoid memory leak
Coverity CID 207731

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 08:30:28 -08:00
Dirk Hohndel
fc20155d52 Cleanup: avoid memory leak
Coverity CID 207773

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-28 08:35:23 -08:00
Dirk Hohndel
898ce52455 Cleanup: avoid memory leak
Coverity CID 207807

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-28 08:30:17 -08:00
Dirk Hohndel
ee1699177a Cleanup: avoid memory leaks
Coverity CID 207730
Coverity CID 207747

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-28 08:26:38 -08:00
Dirk Hohndel
ca3466e79c Cleanup: correctly handle upper bound of array
Coverity CID 207684
Coverity CID 207724
Coverity CID 207728

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-28 08:18:40 -08:00
Dirk Hohndel
8ae735a4d7 Merge branch 'ignore-build' of https://github.com/janmulder/libdc into Subsurface-branch v4.7.6 2017-12-12 16:09:51 -08:00
Linus Torvalds
a1472a7247 Merge branch 'Subsurface-branch' of github.com:Subsurface-divelog/libdc into Subsurface-branch
Merge with Dirk's cleanups.

I had intentionally not updated my tree while I was pondering the
upstream merge with Jef's iostream changes, so I didn't have Dirk's
cleanups in my tree when I did that big merge.

This merge was trivial in comparison.

* 'Subsurface-branch' of github.com:Subsurface-divelog/libdc:
  Correctly determine git SHA if libdivecomputer is a git submodule
  Disable a couple of overly aggressive warnings
  Add configure flag to explicitly enable BLE support
2017-12-12 14:02:53 -08:00
Linus Torvalds
8a34d822ff Merge remote-tracking branch 'jef/master' into Subsurface-branch
Rough merge of upstream libdivecomputer.

This is mainly about making the new iostream code upstream, although we
don't actually use it.

It abstracts out the the old serial and usbhid code, but we end up still
using our own 'custom_io' interface because the iostream code doesn't do
it right.

* jef/master:
  Correctly determine git SHA if libdivecomputer is a git submodule
  Don't accept a NULL pointer as parameter
  Add support for semi-closed circuit diving
  Detect dives with invalid profile data
  Implement the serial communication functions as no-ops
  Move the socket code to a common file
  Add support for a custom I/O implementation
  Port the USB HID code to the new I/O interface
  Port the bluetooth code to the new I/O interface
  Port the IrDA code to the new I/O interface
  Port the serial code to the new I/O interface
  Add a new abstract I/O interface
  Post release version bump to 0.7.0
2017-12-12 13:59:29 -08:00
Dirk Hohndel
ca1efdcecd Correctly determine git SHA if libdivecomputer is a git submodule
In the case of a submodule, the .git file is a text file pointing to the
correct module in the parent's .git folder. The git rev-parse works
correctly in both cases.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-07 15:54:48 +01:00
Dirk Hohndel
db70c581a6 Correctly determine git SHA if libdivecomputer is a git submodule
In the case of a submodule, the .git file is a text file pointing to the
correct module in the parent's .git folder. The git rev-parse works
correctly in both cases.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
v4.7.5
2017-12-06 21:23:22 -06:00
Dirk Hohndel
f5aee8198f Disable a couple of overly aggressive warnings
-Wextra and -Wpedantic are creating more noise than useful warnings.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-04 13:53:40 -08:00
Dirk Hohndel
506bcec3cd Add configure flag to explicitly enable BLE support
This way BLE dive computers that are otherwise conditional on USBHID will be
built on platforms that support them but don't have USBHID (like iOS).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-04 13:42:25 -08:00
Linus Torvalds
77f87bebe3 EON Steel: remove a few unused variables
Most of the new warnings due to compiler flags are just unnecessary
noise, but let's clean up at least the obvious and unquestionably valid
ones.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-12-04 10:43:20 -08:00
Linus Torvalds
54f6bff929 Merge tag 'v0.6.0' of git://git.libdivecomputer.org/libdivecomputer into Subsurface-branch
Sync up with upstream cersion 0.6.0.

Annoying merge, mainly because a lof of the changes Jef had done are
actually changes that came from our Subsurface branch, but in a
different form, because Jef doesn't actually take patches directly from
us.

Why? I don't know.

* tag 'v0.6.0' of git://git.libdivecomputer.org/libdivecomputer:
  Release version 0.6.0
  Fix some potential buffer overflows
  Fix some casts with constant pointers
  Enable some useful compiler warnings by default
  Generate html documentation from the manpages
  Fix the decoding of the ndl/deco information
  Decode the firmware version for the iDive series
  Add support for the Suunto Eon Core
  Locate the most recent dive
  Add EON Steel time sync capability
  Improve the progress events
  Detect the model number using the hardware type
  Shearwater: add support for remaining gas time
  Shearwater: extract tank sensor data for log version 7
  Shearwater: extract log version from header
2017-12-04 10:18:23 -08:00
Jan Mulder
8c443c5abc build: ignore the build from git
Now as a submodule, the change in libdivecomputer created by the
build process is annoying. Just ignore it.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-04 02:12:13 +01:00
Jef Driesen
42f8e012b7 Don't accept a NULL pointer as parameter
Immediately return an error instead of trying to pass the NULL pointer
to the underlying open system call.
2017-12-01 15:03:17 +01:00
Jef Driesen
f87720dff9 Add support for semi-closed circuit diving
Add a new type to distinguish between closed circuit (CCR) and
semi-closed circuit (SCR) diving. Some dive computers from HW and
DiveSystem/Ratio support this.

Because the CCR/SCR abbreviations are more commonly used, let's take the
opportunity to also rename the existing DC_DIVEMODE_CC. To preserve
backwards compatibility, a macro is added to map the old name to the new
one.

Reported-by: Jan Mulder <jlmulder@xs4all.nl>
2017-11-30 09:03:46 +01:00
Jef Driesen
76187c550a Detect dives with invalid profile data
The OSTC3 stores the dive headers and profile data in two separate
memory areas. There is a header area with fixed positions and a profile
area which is used as a ring buffer. Each dive header stores the
position of the profile data in the ring buffer.

Now, once there are more dive headers then room for the profiles, the
oldest profiles (but not the headers) are overwritten with new data.
Because the dive headers are not updated when their profile data gets
overwritten, they will now point to data that is no longer available.
The internal logbook detects this situation and does not display the
profile. But during the download, there is no such check, and the OSTC
will send invalid profile data.

This invalid profile data should be dropped on the receiver side.
Unfortunately implementing the exact same check as is done by the OSTC
itself isn't possible, because the OSTC doesn't send the 6 byte internal
header on which the check is based. As a workaround, the two byte
end-of-profile marker and the length field in the profile header is used
to detect overwritten profiles.
2017-11-30 09:03:46 +01:00
Jef Driesen
f98f5eba5f Merge branch 'iostream' 2017-11-26 23:07:57 +01:00
Jef Driesen
e22ba69819 Implement the serial communication functions as no-ops
For the socket based I/O stream implementations (IrDA and bluetooth) the
serial communication specific functions are meaningless. Implementing
them as no-ops allows the dive computer backends the call the I/O stream
functions unconditionally.

This is important for the bluetooth implementation, because bluetooth
enabled dive computers will be able to use both the native bluetooth
communication and the legacy bluetooth serial port emulation.
2017-11-26 23:00:33 +01:00
Jef Driesen
823303980e Move the socket code to a common file
A large part of the irda and bluetooth code is the Windows and BSD
socket code. Moving this code to a common file reduces code duplication.
2017-11-26 23:00:33 +01:00
Jef Driesen
283eaa1ca6 Add support for a custom I/O implementation
Wih the custom I/O implementation, an application can use its own
low-level I/O layer instead of using one of the built-in ones. The
application only needs to provide a set of callback functions, and
libdivecomputer will wrap them into a I/O stream.
2017-11-26 10:40:34 +01:00
Jef Driesen
cf9626efc3 Port the USB HID code to the new I/O interface 2017-11-25 10:26:49 +01:00
Jef Driesen
300ef5257b Port the bluetooth code to the new I/O interface 2017-11-25 10:26:49 +01:00
Jef Driesen
8f17055ec4 Port the IrDA code to the new I/O interface 2017-11-25 10:26:49 +01:00
Jef Driesen
7cd1656d1d Port the serial code to the new I/O interface 2017-11-25 10:26:49 +01:00
Jef Driesen
3ca27995e1 Add a new abstract I/O interface
The purpose of the new I/O interface is to provide a common interface
for all existing I/O implementations (serial, IrDA, bluetooth and USB
HID). With a common interface the dive computer backends can more easily
use different I/O implementations at runtime, without needing
significant code changes. For example bluetooth enabled devices can
easily switch between native bluetooth communication and serial port
emulation mode.

The new interface is modelled after the existing serial communication
api. Implementations where some of those functions are meaningless (e.g.
IrDA, bluetooth and USB), can just leave those functions unimplemented
(causing the call to fail with DC_STATUS_UNSUPPORTED), or implement it
as a no-op (always return DC_STATUS_SUCCESS).
2017-11-25 10:26:49 +01:00
Jef Driesen
b75095cefa Post release version bump to 0.7.0 2017-11-24 23:48:55 +01:00
Jef Driesen
1195abc2f4 Release version 0.6.0 v0.6.0 2017-11-24 23:47:58 +01:00
Jef Driesen
350893fb27 Fix some potential buffer overflows
Verify the buffer size before accessing its content!
2017-11-24 23:46:08 +01:00
Jef Driesen
68380b2ec0 Fix some casts with constant pointers
Casting away the const qualifier generates a compiler warning which can
easily be avoided by preserving the const qualifier.
2017-11-24 23:45:11 +01:00
Jef Driesen
91f5b34ae5 Enable some useful compiler warnings by default
Because some of those compiler warnings are GCC specific, they should
only be enabled if the compiler actually supports them. This is take
care of with some macros from the autoconf-archive.

To avoid breaking the build on systems that don't have those macros
installed (e.g. Mac OS X), they are included in the project.
2017-11-24 23:45:11 +01:00
Jef Driesen
cbaebc777d Generate html documentation from the manpages 2017-11-23 10:33:31 +01:00
Linus Torvalds
238a3734a5 Add support for new Suunto EON Core dive computer
Nick Shore reports that it seems to act exactly like an EON Steel, just
with a different USB device ID.

Acting like the EON Steel is not a surprise: it does seem to be the same
dive computer, just in a smaller and lighter package (same screen size,
but more compact body and without the stainless steel to make it less
than half the weight).  Looks like the battery is smaller, but the
electronics are likely the same.

We probably really should have some way to add new device ID's without
having to add whole new model numbers etc.  It's not the first time this
happens (see the Scubapro Aladin Square vs the G2), and it's likely not
the last time.

Reported-by: Nick Shore <support@mac-dive.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-11-19 15:36:39 -10:00
Jef Driesen
4ccfa51faf Fix the decoding of the ndl/deco information
With the new APOS4 firmware, both the tts and the duration of the first
deco stop are recorded while in deco. But compared with the older
firmware, the tts field has moved to a slightly different offset. And
contrary to the new documentation, it seems that the value for invalid
or infinite has also changed from 0xFFFF to 0x7FFF,

Note that for dives recorded with an older firmware version, the
duration of the first deco stop isn't available, and libdivecomputer
reports the tts instead. This is the same behaviour as before.

Reported-by: Janice McLaughlin <janice@moremobilesoftware.com>
2017-11-19 23:07:38 +01:00
Jef Driesen
93fc2f1c79 Decode the firmware version for the iDive series
For the older iDive series, the firmware is stored at a slightly
different offset.
2017-11-19 23:07:38 +01:00
Jef Driesen
4ffd514f76 Add support for the Suunto Eon Core
The Suunto Eon Core uses a different USB PID, but otherwise it's
compatible with the Eon Steel. It's probably an Eon Steel internally,
but with a smaller form factor.

To be able to distinguish between the two models and use the correct USB
PID, each model is assigned a different (artificial) model number.

Reported-by: Nick Shore <support@mac-dive.com>
2017-11-19 23:05:23 +01:00
Jef Driesen
812db650d4 Locate the most recent dive
The Suunto Eon Steel seems to have a limit of maximum 400 dives. Once
that limit is reached, the oldest dives get overwritten with newer
dives. But the order in which the dive entries are downloaded isn't
changed, and thus the most recent dive is no longer the last entry.

For the first 400 dives, the order is always straightforward:

   D001 D002  ... D399 D400

The most recent dive is always the last entry, and no special processing
is necessary. But once the limit is reached, the next few dives will
start to overwrite the oldest dives, but the order remains unchanged:

   D401 D402 ... D399 D400

Thus in order to return the dives in the correct order (newest first),
we can no longer assume the most recent dive is the last entry, and thus
we need to locate it manually.

The new algorithm is based on the assumption that the most recent dive
will have the hightest timestamp. And to be able to walk backwards
through all the entries, the list is assumed to be a circular list.
2017-11-19 23:05:23 +01:00
Linus Torvalds
f5df265300 Add EON Steel time sync capability
The EON Steel can use the new 'timesync' interface to set the time
automatically from the computer it is connected to.

This also regularizes the EON Steel command names a bit, and adds a few
new commands (you can also read the time etc, which this doesn't
actually use).

[Jef Driesen: Modified to follow the existing naming conventions, return
the correct error code and avoid arithmetic operations with signed
integers.]

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-11-19 23:05:23 +01:00
Jef Driesen
2ced18870d Improve the progress events
At the moment the progress events are reported for each download
operation separately. Combined with the fact that the size of the dives
isn't known in advance, and thus the progress events are based on a
worst case value, the user experience is far from optimal. In practice,
the progress goes from 0 to 100% for every manifest, and it stays close
to zero while downloading the dives.

This is improved by combining the individual progress events into a
single progress for the entire download. This global progress simply
counts the number of individual download operations. Since each
operation is now subdivided into a fixed number of steps, regardless of
the size of the transfer, the perceived speed is no longer constant.
2017-11-19 19:51:59 +01:00
Jef Driesen
2d7d5152b4 Detect the model number using the hardware type
The model number is stored in the final block of each dive. But for an
efficient implementation of the fingerprint feature, the devinfo event
should be emitted before downloading the manifests or the dives. Thus
reporting the correct model number is problematic.

Currently the model number is simply hardcoded to the value of the
Petrel. This is sufficient for the parser, because there the model
number is only used to distinguish the Predator from all the other
models. Now, because the petrel backend doesn't support the Predator,
and the predator backend (which supports both the Predator and Petrel)
can obtain the correct model number from the final block, the hardcoded
value works fine. Except of course for identifying the actual model!

Allthough there doesn't seems to be a command to retrieve the model
number directly, we can retrieve the hardware type and map that to the
model number.
2017-11-19 19:48:55 +01:00
Dirk Hohndel
63d6af8c41 Shearwater: add support for remaining gas time
[Jef Driesen: Update to the latest documentation.]

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-11-19 18:04:21 +01:00
Dirk Hohndel
7f22f4ac86 Shearwater: extract tank sensor data for log version 7
The first dive computer to support this is the Perdix AI. Interestingly,
this keeps track of two sensors at all times. I haven't seen data with
two sensors active, yet.

[Jef Driesen: Update to the latest documentation.]

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-11-19 18:04:21 +01:00
Dirk Hohndel
9f754dc563 Shearwater: extract log version from header
The earliest document I have references log version 6. There are
apparently older versions, but I don't know what the differences
are. Before version 7, the log version wasn't always reliably
stored, so we assume 6 is the minimum and use 7 (or later) if we
find it.

[Jef Driesen: Initialize and reset the cache correctly.]

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-11-19 18:04:21 +01:00
Linus Torvalds
c44d2a8faf Merge remote-tracking branch 'jef/master' into Subsurface-branch
Sync with the upstream version of the Aladin Square.

This picks the same model name that Jef picked in uwatec_smart_parser.c.

* jef/master:
  Add support for the Scubapro Aladin Square
2017-11-16 15:37:28 -08:00
Linus Torvalds
a2f358f0b5 Add support for Scubapro Aladin Square
It works like the G2, but has a different model number, and different USB device ID.

Lots-of-testing-by: Vincent <vavincavent@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-11-16 15:24:28 -08: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
Linus Torvalds
9d7335dc6d Merge git://git.libdivecomputer.org/libdivecomputer into Subsurface-branch
Merge with Jef's upstream libdivecomputer:

 - some OSTC parsing fixes, including getting the initial CNS into the
   first sample

 - syntactic cleanups to the Scubapro Aladin Sport Matrix support to
   match upstream

* git://git.libdivecomputer.org/libdivecomputer:
  OSTC: initialize initial CNS from header
  Use an out-of-range value as undefined
  Support for the Scubapro Aladin Sport Matrix.
2017-11-15 08:51:54 -08:00
Linus Torvalds
4dce920c79 Scubapro G2 usb: always use exactly 32-byte packets (plus report byte)
It turns out that the Scubapro G2 itself does not care at all, but
apparently some of the other dive computers that use the same protocol
do).

In particular, Vincent reports that his Scubapro Aladin Square downloads
ok with the USB ID's switched to c251:2006, but only if we send 32-byte
USB HID payload packets, even though the command itself is much smaller.
Otherwise it will simply not reply at all.

To actually download correctly, we'll still need to do some model-
specific USB ID updates, and there will be some model changes for the
Aladin Square, but this at least fixes the transport side.

Jef had actually already done this because of the Windows behavior side,
I just hadn't thought it could possibly matter. Mea Culpa.

Reported-and-tested-by: Vincent <vavincavent@gmail.com>
Cc: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Cc: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-11-15 08:42:35 -08:00
Jan Mulder
20d7d03a0d OSTC: initialize initial CNS from header
As the OSTC does not report a CNS value on the first sample, we need to
initialize it differently. This can be solved by using the initial CNS
value form the dive header, and storing that value in the first sample.
The resulting patch is very similar to 44f629f03a91a3b3.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-11-14 13:51:04 +01:00