1839 Commits

Author SHA1 Message Date
Linus Torvalds
81f95d3880 Mark the Aqualung i750TC as BLE-capable
Dirk got a log from Amin that shows

  Discovered new device: "EZ001945" "LE:{cb0ff33a-40d3-63eb-2764-11e63896534f}"
  Not recognized as dive computer

and that's the i750TC device model name.  It's not recognized as a dive
computer because subsurface don't have that EZ as a model version, but
even if it did, it would not try to use BLE to download because
libdivecomputer doesn't mark it as BLE capable.

But it appears that it is, so add the protocol marker (even if the log
Dirk has then shows a failure to connect, so not all is well).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
v5.0.1 v5.0.0
2021-01-23 11:11:53 -08:00
Linus Torvalds
38ebb81536 Merge branch 'master' of git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge with Jef's upstream libdivecomputer updates:

 - support new Ratio iX3M 2021 model IDs

 - support Mares Horizon, and fix the Mares Genius layout

 - add support for Shearwood Sage

 - various warning fixes, other minor details

* 'master' of git://github.com/libdivecomputer/libdivecomputer: (23 commits)
  Wait before sending the firmware data
  Add support for the new iX3M 2021 models
  Avoid generating the SIGPIPE signal
  Use an unsigned value to represent the undefined state
  Use an unsigned integer for the number of dives
  Use the cross-platform socket file descriptor type
  Limit the size to INT_MAX
  Define DC_TIMEZONE_NONE as a signed integer
  Use an unsigned integer for the length
  Fix -Wsign-compare compiler warnings
  Fix -Wshadow compiler warnings
  Fix -Wcast-qual compiler warning
  Fix -Wswitch compiler warning
  Remove unused variables
  Implement the rbt sample
  Use some more descriptive variable names
  Verify the oxygen and helium percentage
  Add support for the Mares Horizon
  Swap the object major and minor version
  Fix the Mares Genius memory layout
  ...
2021-01-23 11:00:50 -08:00
Jef Driesen
939470df52 Wait before sending the firmware data
Without the small delay, sending the first frame often fails. Trying to
read the ACK response byte just fails with a timeout, and no data is
received at all. The bootloader is probably not ready to receive data
yet.
2021-01-15 09:33:28 +01:00
Jef Driesen
0239329f06 Add support for the new iX3M 2021 models
The new iX3M 2021 models (refered to as 'iX3M with Sequared Buttons' in
the Ratio support section) identify as iX5M in the Bluetooth name.

Reported-by: Damian Zaremba <damian@damianzaremba.co.uk>
2021-01-15 08:59:46 +01:00
Jef Driesen
d5dffb70be Avoid generating the SIGPIPE signal
Handling the SIGPIPE signal in a library is tricky, because installing a
signal handler does affects the entire application. But we can at least
try to avoid generating the SIGPIPE signal ourselves. On Linux, that
requires the use of the MSG_NOSIGNAL flag, and on Mac and BSD setting
the SO_NOSIGPIPE socket option.
2021-01-07 21:39:47 +01:00
Jef Driesen
4ffd45c126 Merge branch 'warnings' 2021-01-05 13:01:48 +01:00
Jef Driesen
ba6a8a43f7 Use an unsigned value to represent the undefined state
This fixes some more -Wsign-compare compiler warnings.
2021-01-05 09:32:45 +01:00
Jef Driesen
5eddaeade6 Use an unsigned integer for the number of dives
Because the dive_count variable is decremented, it doesn't contain the
total number of dives, but the index of the last dive. A negative number
indicates no dives. The same result can be obtained by using the total
number of dives directly. That's not only more intuitive, but also fixes
a -Wsign-compare compiler warning.
2021-01-05 09:32:45 +01:00
Jef Driesen
fc76b4a258 Use the cross-platform socket file descriptor type
Windows and unix use a diferent data type for representing socket file
descriptors (SOCKET vs int). This mismatch results in a compiler warning
when comparing to S_INVALID.
2021-01-05 09:32:45 +01:00
Jef Driesen
b0cce363f1 Limit the size to INT_MAX
Allthough the input buffer size has type 'size_t', the return value of
the function has only type 'int'. Hence the function can't support input
buffers larger than INT_MAX.

This allows to fix a -Wsign-compare compiler warning: operand of ?:
changes signedness from ‘int’ to ‘size_t’ due to unsignedness of other
operand.
2021-01-05 09:32:45 +01:00
Jef Driesen
10a4ec0b08 Define DC_TIMEZONE_NONE as a signed integer
The hexadecimal value 0x80000000 is too large to be represented as a
signed 32bit integer. Therefore the default type for the constant is an
unsigned 32bit integer. This is a bit annoying because the timezone
field is actually defined as a signed integer, and thus comparisions
produce -Wsign-compare compiler warnings.

Fixed by switching to INT_MIN, which is the same underlying value but
interpreted as a signed integer.
2021-01-05 09:32:45 +01:00
Jef Driesen
0688b74099 Use an unsigned integer for the length
This avoids -Wsign-compare compiler warnings due to comparison of
integer expressions of different signedness.
2021-01-05 09:32:45 +01:00
Jef Driesen
1130b7eade Fix -Wsign-compare compiler warnings
Comparing signed and unsigned integer expressions can have unexpected
results because the signed integer will get promoted to an unsigned
integer. To avoid the warning, add an explicit cast to the unsigned
type, along with a check to catch negative values.
2021-01-05 09:32:45 +01:00
Jef Driesen
8f383ac531 Fix -Wshadow compiler warnings
Rename a few variables, parameters and functions to avoid shadowing
others.
2021-01-05 09:32:45 +01:00
Jef Driesen
7c9726da64 Fix -Wcast-qual compiler warning
String literals have the type 'char[N]' by default. Allthough they are
not really 'const', modifying a string literal is undefined behaviour.
Therefore, to avoid mistakes, libdivecomputer uses the -Wwrite-strings
compiler option to change the default type to 'const char[N]'.

The cast that triggers the -Wcast-qual warning can be avoided by using a
character array instead of string literal.
2021-01-04 20:20:52 +01:00
Jef Driesen
548fce69f8 Fix -Wswitch compiler warning
Add a default label to prevent warnings for all enum values not handled
in the switch statement. It's intentional in this piece of code.
2021-01-04 20:20:52 +01:00
Jef Driesen
b97acabb01 Remove unused variables 2021-01-04 20:20:52 +01:00
Jef Driesen
6c9a758648 Implement the rbt sample
The name of the RBT (Remaining Bottom Time) sample was taken from the
Uwatec dive computers. The actual definition depends on the dive
computer, but it usually corresponds to the air time remaining (with or
without some additional factors taken into account).
2021-01-04 20:20:03 +01:00
Jef Driesen
e592c7e7b7 Use some more descriptive variable names 2021-01-04 20:20:03 +01:00
Jef Driesen
cebf4089cc Verify the oxygen and helium percentage
The oxygen and helium percentage in the gas change event should
correspond to the percentages indicated in the dive header.
2021-01-04 20:20:03 +01:00
Jef Driesen
099fda0d2b Merge branch 'horizon' 2020-12-24 14:06:03 +01:00
Jef Driesen
8b06f2c31d Add support for the Mares Horizon
The Mares Horizon is a variant of the Mares Genius, with a few changes
to support SCR dives:

The dive header is slightly modified. There is an extra 8 byte field at
offset 0x18, which causes all later fields to have moved up with the
same amount. This difference is indicated in both the object minor
version (with a change from v0.0 to v0.1), and the logformat.

For the profile data, there is a new SDPT sample type which contains a
bit more information compared to the existing DPRS sample type. This
difference is indicated with a change in the object type (from 0 to 1).

The current implementation assumes a fixed order for the record types (a
DSTR record, a TISS record, zero or more DPRS/SDPT records with an AIRS
record every 4 sample, and finally a DEND record), and either only DPRS
or SDPT records but never a mixture of the two. If these assumptions
turns out to be incorrect, the implementation will need to be changed
significantly. Note that the assumption of the fixed order was already
present for the Genius.

Bluetooth support is currently disabled in the Horizon firmware, but
might be re-enabled in the future.
2020-12-24 13:52:47 +01:00
Jef Driesen
484e9dcdc3 Swap the object major and minor version 2020-12-24 11:33:18 +01:00
Jef Driesen
9438064afc Fix the Mares Genius memory layout
The Mares Genius appears to have 16M of flash memory, and it also
supports 4K packets.
2020-12-24 11:28:03 +01:00
Jef Driesen
6ab4ac7f7f Merge branch 'oceanic-ringbuffer-pointers' 2020-12-24 11:16:09 +01:00
Jef Driesen
9eddbe88be Skip logbook entries with invalid pointers
Since logbook entries with invalid ringbuffer pointers are considered a
fatal error, the download is aborted. The result is that any remaining
entries, located after the invalid entry, can't be downloaded at all.

This can be avoided by skipping the problematic entry instead of
aborting the download.
2020-12-01 11:05:37 +01:00
Jef Driesen
e53e7cf961 Re-use the common error handling code
There is no need to duplicate the error cleanup code everywhere. Break
out of the while loop and cleanup at the end of the function.
2020-12-01 11:04:56 +01:00
Jef Driesen
90a08ad845 Add support for the Sherwood Sage
The Sherwood Sage appears to be very similar to the Aeris A300CS. For
the BLE communication the handshake fails and is disabled.

Reported-By: Nick Shore <support@mac-dive.com>
2020-11-26 14:13:57 +01:00
Linus Torvalds
e58a5866bb Merge git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge upstream libdivecomputer from Jef:

 - support the Scubapro Aladin A2

 - improve Cressi Goa support

 - parse and report Oceanic firmware versions

* 'master' of git://github.com/libdivecomputer/libdivecomputer:
  Report the firmware version in the devinfo event
  Refactor the version string matching to use one table
  Parse the firmware version
  Add support for Cressi Goa gauge and freedives
  Add the extra 5 bytes containing the divemode
  Add a function to insert data anywhere in the buffer
  Add support for the Scubapro Aladin A2
v4.9.10 v4.9.9 v4.9.8
2020-11-08 16:04:40 -08:00
Dirk Hohndel
4fc85409da bugfix: only sort non-NULL array
Unclear if this is needed.

This might address CID 363698

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-31 15:10:25 -07:00
Dirk Hohndel
47be86eb79 fix incorrect comparison
Operator precedence gets me every time. Equally binds stronger
than bitwise logical operation.

Fixes CID 363699

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-31 15:09:04 -07:00
Linus Torvalds
1712b99f79 Merge branch 'Garmin-Mk2i' into Subsurface-DS9
This merges the FIT file parsing extensions to actually parse the
pressure data from the new Garmin Descent Mk2i.

There is more data there about cylinder sizing etc that we can parse,
but this is enough to make things useful.  At least for the test cases I
have access to so far.

* Garmin-Mk2i:
  Garmin Descent Mk2i: add support for parsing cylinder pressure data
  Garmin: add skeleton for the new fields for the Descent Mk2/Mk2i
2020-10-30 12:40:53 -07:00
Linus Torvalds
89b1cc4f28 Garmin Descent Mk2i: add support for parsing cylinder pressure data
Very early trial at parsing the pressure data from the Garmin tank pods.
It seems to work for the test-cases I have.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-10-30 12:37:19 -07:00
Dirk Hohndel
3a300a6a8f
Merge pull request #25 from subsurface/mtp
Garmin Descent Mk2/Mk2i MTP support
2020-10-30 10:53:17 -07:00
Linus Torvalds
c4a3db4ac1 Garmin: add skeleton for the new fields for the Descent Mk2/Mk2i
This adds the field definitions, but doesn't actually report the data
yet.  But just having the definitions makes the debug output a lot
easier to read through.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-10-30 10:50:00 -07:00
Dirk Hohndel
9554e87431 Garmin: support .FIT files from filesystem even for MTP devices
If the caller provides us with a path name, we should not try to connect to the
dive computer via MTP, but instead read the .FIT files from the path provided.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-30 10:01:29 -07:00
Dirk Hohndel
ea3e542450 Garmin: add MTP support
Create parallel helper functions that use libmtp to walk the file tree on the
device and to then read a specific file from the device into our dc_buffer.
MTP is not a file system, it's an object storage, that just happens to allow
object names and parent/child relationships between objects. As a result we
need to remember those file ids for MTP downloads.

The mtp_get_file_list function is rather complex as it includes both the
initial communication with the device and the code to walk the object tree and
then create the list of file.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-29 13:48:01 -07:00
Dirk Hohndel
05e066b2ff Garmin: refactor the code to prepare for MTP support
Breaking things into helper function makes it much easier to then support both
regular file operations and MTP.

This includes some mild whitespace cleanups for consistency.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-29 13:21:10 -07:00
Dirk Hohndel
8df5c15db9 Garmin: add the Descent Mk2/Mk2i
Just like for the Descent Mk1 this uses the internal Garmin model number (as
indicated in the FIT format) as model, not the USB product ID.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-29 13:21:10 -07:00
Dirk Hohndel
e1bbdd5e65 Garmin: pass the model to the device_open function
We do this for a few other device where we need slightly different behavior,
depending on the specific model.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-27 15:26:20 -07:00
Jef Driesen
7f553c1276 Merge branch 'oceanic-firmware-version' 2020-10-27 11:14:29 +01:00
Jef Driesen
b7850e9cbf Report the firmware version in the devinfo event 2020-10-27 10:54:40 +01:00
Jef Driesen
50f3ba3189 Refactor the version string matching to use one table
With just a single table, the version string matching not only becomes
simpler, but adding new layouts also requires no code changes anymore.

For devices that need different layouts depending on the firmware
version (e.g. Oceanic Atom 2.0 and Aeris Manta), the table may contain
multiple entries with the different firmware versions. The only
requirement is that the entry with the highest firmware version must be
listed first.
2020-10-27 10:54:40 +01:00
Jef Driesen
014a15ba62 Parse the firmware version
The patterns used for the version string have the firmware version
masked out because it varies. We can re-use those masks to extract the
firmware version.
2020-10-27 09:43:25 +01:00
Jef Driesen
5b133233f7 Merge branch 'goa-freedive' 2020-10-20 13:58:54 +02:00
Jef Driesen
c77a311a89 Add support for Cressi Goa gauge and freedives
The gauge and freedives have a slightly different data format compared
to scuba dives. The main difference is the size of the header and two
new sample types.
2020-10-20 13:56:20 +02:00
Jef Driesen
57cd11fffe Add the extra 5 bytes containing the divemode
The logbook header has 5 bytes extra, which are not present in the dive
header. Those 5 extra bytes contain the dive mode, which is required for
parsing the dive data. Therefore, insert all 5 bytes again and update
the parser.

The remaining 4 bytes appear to be some 32 bit address. They are not
used for anything right now, but are preserved as well in case they are
needed in the future.
2020-10-20 13:56:20 +02:00
Jef Driesen
fe9a3d9a10 Add a function to insert data anywhere in the buffer
The memory buffer already supported appending and prepending data, but
not inserting data anywhere in the buffer. That's exactly what the new
function does. The free space is still maintained at either the start or
the end of the buffer.
2020-10-20 13:56:20 +02:00
Nick Shore
625f56b494 Add support for the Scubapro Aladin A2 2020-10-13 09:04:32 +02:00
Linus Torvalds
0ebd5d3879 Garmin Descent: clear dive data in between dives
This actually got broken long ago (and before the new "Subsurface-DS9"
branch: when I converted the Garmin parser to use the generic field
cache, I missed the fact that the parser now cleared _only_ that generic
part of the per-dive cache in between different dives.

The GPS information, and the general dive information would be left
alone in between dives, and could leak from one dive to the next.

Most of the time you don't notice, because dives tend to all have the
same information, so the stale data would get overwritten when parsing
the next dive.  But that isn't _always_ true - particularly for the GPS
information, not all the data necessarily always exists.

So clear all the per-dive data when starting to parse a new dive.

This puts the non-gps data all in one sub-structure, so that it's easy
to clear that too in one go - even though that part of the data probably
always does get opverwritten by the new dive data.

Reported-by: @brysconsulting
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-09-29 16:54:48 -07:00