1900 Commits

Author SHA1 Message Date
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
Linus Torvalds
d52dfb002d Merge git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge updates from Jef's upstream branch.

Fix Mares Genius salinity parsing, and a possible buffer overflow in the
Liquivision Lynx parser.

This also has Jef's copy of Dirk's Shearwater PNF parsing fix that we
already had in our tree.

* 'master' of git://github.com/libdivecomputer/libdivecomputer:
  Fix a buffer overflow
  fix Shearwater PNF parsing for Petrel / Petrel 2
  Fix a bug in the salt and fresh water parsing
v4.9.7
2020-09-21 12:22:30 -07:00
Linus Torvalds
1801023c68 Merge branch 'cleanup' of https://github.com/subsurface/libdc into Subsurface-DS9
Pull coverity fixes from Dirk Hohndel.

* 'cleanup' of https://github.com/subsurface/libdc:
  fix some coverity errors
2020-09-21 12:21:36 -07:00
Dirk Hohndel
a004fdffed fix some coverity errors
CID 350142: Resource leak
CID 350154: Resource leak
CID 360641: Resource leak
CID 350147: Possibly not null-terminated strings

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-21 12:05:57 -07:00
Jef Driesen
c6ea7afb76 Fix a buffer overflow
The existing check accepts the number of array elements as a valid
index. That's clearly wrong for zero based indexing, and would result in
a buffer overflow.
2020-09-21 11:49:35 +02:00
Dirk Hohndel
469d3ee177 fix Shearwater PNF parsing for Petrel / Petrel 2
At some point (possibly around v71 of their firmware), Shearwater implemented
PNF for the Petrel and Petrel 2. Those are of course not air integrated, and
apparently don't support adjustable sample rate, so the log data doesn't include
opening and closing record 5. Instead of failing when those aren't found, we
should simply only access those when they actually exist.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-21 09:39:12 +02:00
Linus Torvalds
8cfd2aacaf Merge branch 'shearwaterPNFfix' of github.com:Subsurface-divelog/libdc into Subsurface-DS9
Pull Shearwater PNF parsing fix from Dirk:
 "The parser assumed that all opening/closing records were required.

  But it seems that for the Petrel / Petrel 2 they actually aren't,
  specifically record 5 is missing.

  Which makes sense, as that one only contains air integration stuff
  plus the sample interval (which isn't configurable on the older dive
  computers)"

* 'shearwaterPNFfix' of github.com:Subsurface-divelog/libdc:
  fix Shearwater PNF parsing for Petrel / Petrel 2
2020-09-19 12:01:02 -07:00
Dirk Hohndel
8e1335e372 fix Shearwater PNF parsing for Petrel / Petrel 2
At some point (possibly around v71 of their firmware), Shearwater implemented
PNF for the Petrel and Petrel 2. Those are of course not air integrated, and
apparently don't support adjustable sample rate, so the log data doesn't include
opening and closing record 5. Instead of failing when those aren't found, we
should simply only access those when they actually exist.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-19 10:29:55 -07:00
Jef Driesen
8a10e545d4 Fix a bug in the salt and fresh water parsing
The original Mares Genius support was based on Mares Dive Organizer
2.25, which has a bug in the salinity parsing. The latest version 2.26
has this bug fixed.

Reported-by: Greg McLaughlin <gregm@somemore.com>
2020-09-18 17:29:52 +02:00
Dirk Hohndel
7d26fb6a13 Add BLE transport for McLean Extreme
As suggested by Linus.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-15 13:37:18 -07:00
Linus Torvalds
2e63eaec16 Merge git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Pull McLean Extreme fix from Jef Driesen.

The McLean Extreme sample interval was wrong, causing imported dives to
appear twice as long as long as they should.

* git://github.com/libdivecomputer/libdivecomputer:
  Fix the sample interval
2020-09-15 10:39:06 -07:00
Jef Driesen
2909863573 Fix the sample interval
The McLean Extreme records a sample every 10 seconds instead of every 20
seconds. This resulted in dive durations that were twice as long as
expected.

Reported-by: David Carron <david_de_carron@hotmail.com>
2020-09-15 15:06:12 +02:00
Linus Torvalds
39dc77d669 Shearwater Teric: remove our local support for the TAG INFO_EVENT
This mostly reverts commit cb7f47b ("Shearwater Teric: add support for
the TAG INFO_EVENT") because upstream libdivecomputer now does this
natively as of commit 3e89e1b ("Add support for parsing info events").

Also, the way this had been done, it looks like it had basically
disabled the support for LOG_RECORD_FREEDIVE_SAMPLE, although nobody
seems to have ever complained, so presumably there aren't a lot of
freedivers using Shearwater dive computers and subsurface.

With this, our main differences with Jef are just the string interface
code, and the fact that we still stop parsing at LOG_RECORD_FINAL.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-09-12 12:22:50 -07:00
Linus Torvalds
d6153a5a07 Merge branch 'Subsurface-DS9' of github.com:Subsurface-divelog/libdc into Subsurface-DS9
Merge Dirk's Peregrine support with Jef's.

Jef had some extra logic, and otherwise the same, so this is just a
history merge with no content difference.

* 'Subsurface-DS9' of github.com:Subsurface-divelog/libdc:
  Add basic detection for Shearwater Peregrine
2020-09-12 12:00:37 -07:00
Linus Torvalds
f33814c13c Merge git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge upstrean libdivecomputer updates from Jef Driesen:

 - a different way to work around the windows 'instance' craziness

 - minor updates to the Shearwater parser

* git://github.com/libdivecomputer/libdivecomputer:
  Add support for parsing info events
  Add support for the Shearwater Peregrine
  Fix a conflict with the Windows header files
  Add a missing parameter for the USB HID filter
2020-09-12 11:55:52 -07:00
Dirk Hohndel
ad566ab04f Add basic detection for Shearwater Peregrine
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-08-21 16:11:53 -07:00
Jef Driesen
3e89e1b871 Add support for parsing info events 2020-08-22 00:27:11 +02:00
Jef Driesen
e2ecd96daa Add support for the Shearwater Peregrine 2020-08-22 00:05:32 +02:00
Jef Driesen
7a4c5e919f Fix a conflict with the Windows header files
In one of the Windows system header files, an "interface" macro is
defined as:

  #define interface struct

This results in some very strange build errors when also including the
descriptor-private.h header file. That's because the dc_usb_params_t
struct has a member field named "interface":

  typedef struct dc_usb_params_t {
      unsigned int interface;
      unsigned char endpoint_in;
      unsigned char endpoint_out;
  } dc_usb_params_t;

As a workaround, define the WIN32_LEAN_AND_MEAN macro before including
the windows.h header file. This excludes some less common Windows API
declarations, including the above one.
2020-08-21 23:56:52 +02:00
Jef Driesen
51b1ae925c Add a missing parameter for the USB HID filter
In commit 57f0ce6d7902117cfc4d0d6b401b516fc93ca488, an extra parameter
was added to the dc_descriptor_filter() function. But I only updated the
libusb code path and forgot to do the same for the hidapi variant.
2020-08-21 17:57:47 +02:00
Linus Torvalds
1df0e13cc4 Fix for absolutely wonderful Windows feature
It turns out that Windows is more of a PoC than I ever imagined.  The
system headers will have something like this in it:

  #define __STRUCT__ struct
  #define interface __STRUCT__

which means that using the identifier "interface" will result in
completely indecipherable error messages from a Windows compiler.

That's some truly broken stinking garbage.  It's not like "interface" is
even a bad identifier.

Let's just #undef this crazy feature.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-08-20 14:06:46 -07:00
Linus Torvalds
378b9c1aec Fix HIDAPI breakage
When Jef added a filter parameter in commit 57f0ce6 ("Add support for
filter parameters") he didn't do the HIDAPI case, because who uses
HIDAPI?

Windows and OS X, it would seem.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-08-20 13:28:28 -07:00
Linus Torvalds
3c1e763a47 Merge git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge upstream changes by Jef Driesen:

 - add support for Liquivision dive computers

 - add support for the Aqualung i470TC

 - extract out Atomic Aquatics Cobalt USB support as a iostream

 - misc fixes

* git://github.com/libdivecomputer/libdivecomputer:
  Fix the OSTC4 firmware upgrade
  Handle a negative number of bytes as an error
  Update the example application
  Use the new USB transport for the Atomic Aquatics Cobalt
  Add an I/O implementation for USB communication
  Add support for filter parameters
  Disable direct access to the filter function
  Increase the receive timeout to 5 seconds
  Fix the McLean Extreme bluetooth name
  Add support for Liquivision dive computers
  Add support for the Aqualung i470TC
2020-08-20 12:36:38 -07:00
Jef Driesen
9dace57814 Fix the OSTC4 firmware upgrade
Commit d1b865d192afc9efde337b5cff8a239366f15565 breaks the OSTC4
firmware upgrade because the OSTC4 expects to receive the service init
command and the service key all at once, before sending any response.

The hwOS firmware still reads the service init command one byte at a
time, and sends the echo immediately after each byte. But in the
meantime, the hwos firmware has also been optimized. The processing time
for an incoming byte is now always faster then the time it takes for the
next byte to physically arrive via the serial line between the USB/BT
chip and the processor. Thus, even without any buffering, sending all
bytes at once should no longer be a problem.

This partially reverts commit d1b865d192afc9efde337b5cff8a239366f15565.

Reported-by: Anton Lundin <glance@acc.umu.se>
Suggested-by: Ralph Lembcke <mail@ralph-lembcke.de>
2020-08-20 15:29:15 +02:00
Jef Driesen
c77551b366 Handle a negative number of bytes as an error
There is no reason for libusb to ever return a negative number of bytes,
but due to the use of a signed integer, it's technically possible. And
because libdivecomputer returns an unsigned integer, such a negative
number would be reported as a very large size.
2020-08-11 15:22:31 +02:00
Jef Driesen
33a20bd2b8 Merge branch 'iostream-usb' 2020-08-11 15:22:07 +02:00
Jef Driesen
5380b247af Update the example application
The application is now responsible for setting up the USB based I/O
stream.
2020-08-11 15:16:36 +02:00
Jef Driesen
c72dc4aa73 Use the new USB transport for the Atomic Aquatics Cobalt
Replace the hardcoded libusb based code with the new USB I/O transport.
This enables the use of a custom I/O on platforms where libusb is not
available.
2020-08-11 15:16:36 +02:00
Jef Driesen
c84bbd93a3 Add an I/O implementation for USB communication
The USB communication is now also implemented as an I/O stream
transport. Unlike most I/O devices, USB communication supports multiple
interfaces and endpoints. This requires some some special care:

In the general case, autodetection isn't really possible without
additional knowledge. Hence the need for the filter parameters to pass
this kind of information.

The implementation assumes two bulk endpoints for the standard
read/write interface. Communication with the control endpoint is
supported through the new DC_IOCTL_USB_CONTROL_{READ,WRITE} ioctl's.
2020-08-11 15:16:36 +02:00
Jef Driesen
57f0ce6d79 Add support for filter parameters
The filter parameter provides a mechanism to pass some additional
information, needed to configure the I/O stream, back to the caller.
2020-08-03 11:51:59 +02:00
Jef Driesen
edacbb2f13 Disable direct access to the filter function
Replace the small helper function to retrieve the function pointer and
then call the function, with another helper function to call the filter
function directly. This way the function pointer doesn't need to be
exposed at all.
2020-08-03 11:51:59 +02:00
Jef Driesen
6986840c0d Increase the receive timeout to 5 seconds
When the fingerprint feature isn't used (or with a timestamp of zero),
the response to the SIZE (0xC6) and DATA (0xC4) commands is received
almost instantly:

    [0.302704] W: C60000000010270000
    [0.366727] R: DCF90F00
    [0.367829] W: C40000000010270000
    [0.394812] R: E0F90F00

But when the fingerprint feature is used (with a non-zero timestamp),
there is a noticable delay:

    [0.341218] W: C64CEB204D10270000
    [1.927905] R: FE0B0000
    [1.931610] W: C44CEB204D10270000
    [5.092081] R: 020C0000

In this particular case, the total amount of dive data was close to 1M
bytes, which pushed the delay over the 3 second timeout, and caused the
download to fail. Increasing the timeout to 5 seconds fixed the problem.

The most likely explanation is that the dive computer needs to scan its
internal logbook to determine which dives and how many bytes to send.
Because that involves reading relative slow flash memory, this can take
up to a few seconds, especially if there are many dives present.

The duration of the delay also depends on the value of the fingerprint
timestamp: the less dives we try to download, the longer the delay! I
suspect that's because the most recent dives are located near the end of
the logbook. Hence, the less dives we request, the more dives the dive
computer needs to skip.

Below are some timings for downloading espectively 792410, 531856 and
270850 bytes from the same dive computer, but with a different
fingerprint value:

    [0.216305] W: C6F8D5C84510270000
    [0.373511] R: 56170C00
    [0.378929] W: C4F8D5C84510270000
    [0.661388] R: 5A170C00

    [0.236246] W: C620D80F4810270000
    [0.559608] R: 8C1D0800
    [0.563755] W: C420D80F4810270000
    [1.171631] R: 901D0800

    [0.246193] W: C654E6434A10270000
    [0.826365] R: FE210400
    [0.831760] W: C454E6434A10270000
    [1.974351] R: 02220400
2020-08-03 11:48:33 +02:00
Jef Driesen
cdd618e683 Fix the McLean Extreme bluetooth name 2020-07-26 17:27:49 +02:00
Jef Driesen
71a149d776 Add support for Liquivision dive computers 2020-07-09 17:02:32 +02:00
Linus Torvalds
6935fe717a Merge branch 'Oceans-S1' into Subsurface-DS9
Add initial support for the Oceans S1.

This expands a bit on the generic functions for the field-cache code,
and uses that to then add a fairly minimal Oceans S1 downloader.

And while it's minimal, it downloads about everything the S1 offers,
which is mainly just depth and temperature.

There are a few fields that it currently doesn't use, notably the
events and NDL information that the dive computer presumably reports in
the auxiliary data that comes in the sample, but without documentation
and more testing I'm not comfortable parsing that.

There's also some "current dive computer state" that isn't imported,
like the battery status.  I know how to read it, but it's not per-dive
data that could be added as extra fields: it's literally just the
current dive computer battery state at the time of the download.

The Oceans team said they'll provide more information about the
download, so this might be expanded in the future, but it seems fairly
usable even in this form.

Thanks to Dhaval Giani for sending me his Oceans S1 as a loaner, and to
Seth Garrison for doing the initial BLE packet dumps that made me think
it was fairly easily doable.

* Oceans-S1:
  Oceans S1: polish up the downloading logic for usability
  Oceans S1: actually download all dives and parse them
  Oceans S1: fill out core download protocol details
  Oceans S1: start filling in protocol details
  Oceans S1: start documenting the download format and first packets
  Add skeleton for Oceans S1 downloader
  Add generic dc_field_get() helper
2020-06-25 11:33:12 -07:00
Linus Torvalds
6b22340ddc Merge git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge upstream libdivecomputer updates from Jef Driesen:

 - Jef merged the EON Steel dive sorting fix we had in our branch: one
   less difference to upstream

 - Jef merged the McLean Extreme support with some updates and cleanups,
   this just takes all his changes.

 - manual pages for iostream

 - various minor fixes and updates from Jef

* git://github.com/libdivecomputer/libdivecomputer:
  Update the gitignore file
  Update the man pages for the new iostream functions
  Purge the serial port buffer during initialization
  Add support for the McLean Extreme
  Suunto Eon Steel: sort the dive list properly
  Remove the salinity compensation
  Fix the hwOS ppO2 bug for firmware v3.08
2020-06-25 11:24:00 -07:00
Linus Torvalds
8d17c3c01c Oceans S1: polish up the downloading logic for usability
This adds a few finishing touches to actually download dives in the
expected order (newest first), which fixes the handling of already
downloaded dives.

It also adds the fingerprinting code to optimize the downloading a bit.

Finally, it handles cancellation in the middle.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-25 10:40:41 -07:00
Linus Torvalds
da8ae52b50 Oceans S1: actually download all dives and parse them
This isn't perfect - we don't do the whole dive fingerprint etc, so
right now it always downloads all dives.

To make matters worse, it downloads dives oldest first, which then
confuses the subsurface downloader that expects newest first.

So there's stuff to clean up, but the basic profile data is all there.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-24 17:09:34 -07:00
Linus Torvalds
91658dd167 Oceans S1: fill out core download protocol details
All of the Oceans S1 protocol seems to be basically ASCII data, but the
bigger chunks of data (the dive list, and the actual dive profiles) are
chunked in 512-byte pieces with sequence numbers and what looks like
some checksum.

This doesn't check the checksum yet, but the basic "download data" seems
to work.

Note that the code doesn't actually _parse_ said data yet, nor create an
actual dive list.  So this is very much only very incremental progress,
but this seems to have been the nastiest part of the actual protocol.

Knock wood.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-24 14:18:57 -07:00
Linus Torvalds
ae58a66d9a Oceans S1: start filling in protocol details
This does the time sync command, which is particularly simple.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-23 15:45:27 -07:00