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>
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>
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
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
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>
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>
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>
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>
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
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>
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>
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.
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.
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.
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).
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.
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>
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>
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>
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.
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>
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.
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.
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>
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>
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
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>