1656 Commits

Author SHA1 Message Date
Janice McLaughlin
17ff3e0667 Oceanic: fix up dive truncation issues, update memory layout
This fixes the dive truncation that happened with long dives due to the
removal of extra padding (commit a2100843b9cf: "Remove extra padding
from the end of the profile").  It turns out the rest of the profile was
in bits 13-15 (with bit 12 being something else).

Also update the memory layout and the baudrate for the i770R.

Signed-off-by: Janice McLaughlin <janice@moremobilesoftware.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-02 16:09:56 -07:00
Linus Torvalds
2518231577 Aqualung i770R: add packet send retry on reply failure
It seems to make things more robust.  Without this, the first packet in
particular seems to easily get lost, and the retry gets things going
again.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-01 16:21:42 -07:00
Linus Torvalds
c6c29f6e9a Merge branch 'master' of git://github.com/libdivecomputer/libdivecomputer into Subsurface-NG
Pull fix from Jef's upstream.

This fixes the end of dive garbage for newer Aqualung dive computers,
including the i770R.

* 'master' of git://github.com/libdivecomputer/libdivecomputer:
  Remove extra padding from the end of the profile
2018-10-01 15:19:52 -07:00
Linus Torvalds
07a33e88c3 First attempt at supporting the Aqualung i770R
This works over BLE, although the end result of a dive download is still
a bit wonky.  There remains some parsing problem that Jef says are
likely be common with the Pro Plus too.

The serial download doesn't work at all, for unknown reasons.  That
*should* be the easy part that "just works" and acts the way previous
similar dive computers have acted.  It's a standard FTDI chip (FT231X)
that exposes a serial connection, but there may be some setup required
to choose between USB and BLE that we do not know about right now.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-30 10:08:06 -07:00
Janice McLaughlin
a2100843b9 Remove extra padding from the end of the profile
Even after removing the pages padded with 0xFF bytes, there are still
some invalid sample pages present at the end of the profile. But it
turns out the number of valid profile pages is stored in the logbook
entry.

The only caveat is that the number of pages appears to be stored as a 12
bit number, which limits the total profile size to only 64Kb. We don't
known what happens for larger dives.
2018-09-30 09:54:18 +02:00
Linus Torvalds
5be8c17ea1 Mares bluetooth support tweaks
So it turns out that we really shouldn't send the command and arguments
as one single packet in all situations, because at least the Mares
Matrix really seems to want that "wait for ACK before sending
arguments".  See commit 59bfb0f3189b ("Add support for the Mares
Matrix") for details.

Also, because bluetooth is slow (and it looks like it's particularly
slow for us with the Qt bluetooth code for some reason), we don't want
to ask for big packets of data, because it seems to cause a buffer
overflow on the BlueLink Pro when the serial data from the dive computer
arrives faster than the bluetooth data can be sent to the downloading
side.

So when using the BLE transport, limit the packet size to 128 bytes and
disable the command splitting.

With this, I can download hundreds of kB of data from the Mares Quad Air
successfully over BLE. It's *slow*, but it works.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
v4.8.3
2018-09-27 10:48:15 -07:00
Linus Torvalds
f57c53470b Mares Icon HD family: send the command as one single write buffer
The Mares backend used to send the commands by splitting them up into
the two-byte command and the "rest", while waiting for the ACK byte
(0xAA) to come in between the two parts.

That seems to work fine for the serial side, but the the BLE packets, it
seems to cause too much of a delay between the command bytes and the
argument bytes, and the end result is that the Mares doesn't actually
act on the argument bytes at all, and just sends an EOF reply (0xEA).

The Mares app itself does seem to send them as two packets, but
apparently without actually waiting in between, avoiding the issue.

Let's just send the command as a single write, which makes at least my
loaner Mares Quad Air with the BlueLink Pro dongle happy.

We may need to revisit the details of this based on feedback.  But it
should speed up downloading too, by avoiding the roundtrip wait for the
ACK byte.

This affects all the computers in the Mares Icon HD family: Matrix,
Smart, Smart Apnea, Icon HD, Icon HD Net Ready, Puck Pro, Nemo Wide 2,
Puck 2, Quad Air, Smart Air and Quad.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-26 17:45:42 -07:00
Linus Torvalds
e97886a994 Fix dc_iostream_{read,write} debugging implementation
The dc_iostream_{read,write}() implementation had multiple issues:

 (a) it would return DC_STATUS_SUCCESS even if no iostream
     implementation existed.

     Yes, it would also return a zero "actual" bytes, but most backends
     don't even pass an "actual" pointer, so returning success was still
     completely insane.

     This one probably didn't matter, because all iostreams should have
     read and write members, but the return value was completely wrong
     if that ever were to happen.

 (b) The write side actually tested not whether a write function
     existed, but whether a read one existed.

     Again, this one probably didn't matter in practice, since an
     iostream without a read and write member doesn't make much sense,
     but the test was completely wrong regardless.

 (c) If the user passed in a NULL 'actual' pointer, the wrapper would
     ignore that, and pass in its own pointer instead, in order to know
     how many bytes to print for the debug message.

     But that means that the low-level read/write functions cannot know
     whether the user actually is able to handle a partial read or not.

     This one _definitely_ matters, because some protocols need to have
     a buffer for the whole incoming packet, but packerts may not always
     be full-size. The low-level protocol needs to know whether to wait
     for further packets (in order to fill the buffer) or to just return
     the partial data.

This fixes all of these issues.  If the user passes in a NULL actual
pointer (indicating that it needs all-or-nothing and is not ready to
handle a partial success), just loop over the IO until the buffer is
fully exhausted.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-26 11:22:23 -07:00
Dirk Hohndel
8120b11258 Revert "Shearwater: try to gracefully shut down the Bluetooth connection"
This reverts commit 437cc3e0cc9f88eedf27657c485cd55f23a4f2df.

Jef convinced me that this is fundamentally the wrong thing to try here.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-25 16:44:56 -07:00
Dirk Hohndel
32d62d6269 Shearwater: fix incorrect parsing of base address
I misunderstood the way the helper function worked. Thanks Jef for
pointing it out. The way I wrote the code we ended up doing undefined
shifts which explains why the data I got back seemed so random.

With this we should be able to simply act on the four known values for
the base address, with 0xDD000000 never an option by the time you got
here - but in the old code (prior to the PNF addition) we would have
fallen back to 0xC0000000, so let's do the same here.

Any other value is actually an unknown format and should be treated as
such.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-25 16:44:56 -07:00
Dirk Hohndel
91766d1ed0 Shearwater: better macro name
As Jef correctly points out, RDBI actually stands for Read Data by
Identifier, and the correct identifier here is Log Upload.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-25 16:44:56 -07:00
Linus Torvalds
f705ddefa8 Merge branch 'master' of git://github.com/libdivecomputer/libdivecomputer into Subsurface-NG
Pull Aqualung i100 support from Jef's upstream libdivecomputer.

Very similar to the I200, but with the header in a different location.

* 'master' of git://github.com/libdivecomputer/libdivecomputer:
  Add support for the Aqualung i100
2018-09-24 12:25:11 -07:00
Jef Driesen
e968f84999 Add support for the Aqualung i100 2018-09-24 10:11:42 +02:00
Linus Torvalds
0d1e8f1803 Merge git://github.com/libdivecomputer/libdivecomputer into Subsurface-NG
Merge upstream libdivecomputer changes from Jef Driesen.

A harmless build cleanup, and a small fix for the Mares Smart Apnea
temperature parsing.

* git://github.com/libdivecomputer/libdivecomputer:
  Fix the Mares Smart Apnea min/max temperature
  Fix the libusb and hidapi includes
2018-09-21 14:33:18 -07:00
Linus Torvalds
6f377182f5 garmin: relax FIT filename rules for Descent Mk1
When on the actual watch, the filename format for the FIT files ends up
being something like

    2018-09-21-10-23-36.fit

but then if you download the activity from the Garmin Connect activity
website, it might show up as a ZIP file that contains a file named
something like

    3030954326.fit

instead.

In order to make it easy to import these fit files that have been
downloaded from the Garmin cloud, relax the filename rules a bit.

NOTE! You still need to have the proper directory structure, and put
your FIT files in a subdirectory like

  <some path>/Garmin/Activity/

to match the way the FIT files show up when you mount the Garmin Descent
locally.  You can then point subsurface to <some path> when you do a
"download" from the Garmin Descent, regardless of whether it's an actual
case of the dive computer being mounted, or if you've downloaded the FIT
files to your local filesystem.

Reported-by: Andrew Trevor-Jones <atj777atj777@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-21 14:31:20 -07:00
Dirk Hohndel
fb70928c83 Shearwater parser: fix typo in Teric support
The surface pressure was read from the wrong location for PNF logs.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-18 15:09:14 -07:00
Linus Torvalds
8f2ac8f61e Merge branch 'teric' of git://github.com/Subsurface-divelog/libdc into Subsurface-NG
Merge Dirk's Shearwater Teric branch.

The Teric only supports Shearwater's new download format (PFN - Petrel
Native Format), and the old legacy format no longer works.

I'm sure there are issues, and Dirk just ended up ignoring an
unexplained format difference on Android, but without this you get
nothing.

[ Fixed up a format warning in the merge commit  - Linus ]

* 'teric' of git://github.com/Subsurface-divelog/libdc:
  Shearwater PNF support: fall back to default logbook style
  Shearwater: report error when parsing freedive
  Shearwater: add Teric to list of supported dive computers
  Shearwater: try to gracefully shut down the Bluetooth connection
  Shearwater: add helper to send bytes to the dive computer
  Shearwater Petrel Native Format parsing
  Shearwater: use the correct address to download dives
  Shearwater: detect which logbook format is support
  Detect Sherwater Teric
  Shearwater: skip deleted dives
v4.8.2
2018-09-12 09:12:10 -10:00
Dirk Hohndel
348387c6f6 Shearwater PNF support: fall back to default logbook style
On Android we appear to mis-interpret the response to the RDBI command.
Instead of failing, fall back to the default value (PNF for Teric,
Predator-like for everything else).

With this I can successfully download dive data from my Teric on
Android.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-12 10:54:39 -07:00
Linus Torvalds
5ad97bd6bb Suunto EON Steel: report TTS now that libdivecomputer has the interface
The data was always there, and we used to report it as the length of the
next deco stop, which didn't make much sense, but it was basically the
only interface that libdivecomputer had.

Now that we've added DC_SAMPLE_TTS, report TTS properly, and just report
the deco stop time (which the EON Steel doesn't actually give us) as one
minute whenever we have a ceiling.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-09 11:54:15 -07:00
Dirk Hohndel
ee7c14ecc3 Shearwater: report error when parsing freedive
Support for the 8 byte freedive samples has yet to be added. For now bail out.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-08 18:44:00 -07:00
Dirk Hohndel
d0a3336c82 Shearwater: add Teric to list of supported dive computers
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-08 18:37:50 -07:00
Dirk Hohndel
437cc3e0cc Shearwater: try to gracefully shut down the Bluetooth connection
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-08 18:37:50 -07:00
Dirk Hohndel
9379004b2d Shearwater: add helper to send bytes to the dive computer
This should allow us to gracefully shut down the communication with BLE devices.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-08 18:37:50 -07:00
Dirk Hohndel
34785f55ff Shearwater Petrel Native Format parsing
This will allow parsing dives from the Shearwater Teric, but depending on the
firmware could also be used on older models.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-08 18:37:50 -07:00
Dirk Hohndel
0cbcc0518c Shearwater: use the correct address to download dives
Replace the hardcoded address which the one we determined based on the logbook
type available.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-08 17:34:42 -07:00
Dirk Hohndel
f80024ed59 Shearwater: detect which logbook format is support
RDBI response tells us which format the dive computer supports.

Shearwater recommends to use the 'Petrel Native Format' for all dive computers
which support it, even those pre-Teric models which (depending on firmware)
might support both PNF and the older 'Predator-Like Format'.

They also recommend to ignore the 0x90...... format which is very similar to
PNF but without the final record and to use the older Predator Like Format in
that case.

Which format we use is determined by the base address used to download the
logbook entries.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-08 17:34:34 -07:00
Dirk Hohndel
12b90c693a Detect Sherwater Teric
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-08 17:26:21 -07:00
Dirk Hohndel
ec0029c4ce Shearwater: skip deleted dives
Without this change a deleted dive on device is treated like the end of the
dive list.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-07 17:08:26 -07:00
Jef Driesen
884f66a115 Fix the Mares Smart Apnea min/max temperature
The minimum and maximum temperature were mixed up.

Reported-By: Peter Balck <pbalck@gmail.com>
2018-09-07 10:23:17 +02:00
Linus Torvalds
a9c582e26f garmin: parse dive setting information fields
Based on information from Ryan January, who got it from his Garmin
contacts and got the go-ahead to share the data.

This is mainly the water density and deco model.  It has a few other
fields troo, but nothing necessarily worth reporting.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-05 18:22:07 -07:00
Linus Torvalds
c1c0303e04 garmin: update event descriptions
Based on information from Ryan January, who got it from his Garmin
contacts and got the go-ahead to share the data.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-05 17:49:51 -07:00
Dirk Hohndel
7779bdf581 Garmin: don't assume that the first device index is 0
While it seems like a safe assumption, the cost of being careful and assembling
the full record and taking the one for device_index 0 seems worth it to me.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-05 11:41:55 -07:00
Dirk Hohndel
416bf35977 garmin: adjust the model to reflect the FIT product code
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-04 17:54:36 -07:00
Dirk Hohndel
e02037bf84 garmin: extract the devinfo from the first FIT file we parse
A typical FIT file contains several DEVICE_INFO messages.  We need to
identify the one(s) for the creator (i.e.  the actual device, not a
sub-component).

Note, Garmin identifies the Descent Mk1 as product 2859.  I think we
should use this as the model number (instead of currently using 0.

Also, the vendor event is not to send the vendor name of the device, but
in order to send vendor specific events :-)

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-04 17:54:33 -07:00
Dirk Hohndel
ac25976258 garmin: ignore FIT files that aren't dives
Dives are identified by a sub_sport range of 53-57 in the SPORT message.

This means that we need to parse the files before we actually offer them to the
application, which means we parse them three times all together, but I don't
see a way around that. Thankfully parsing a memory buffer is reasonably fast.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-04 17:53:36 -07:00
Linus Torvalds
41303bbc70 garmin: improve on debug log output for unknown fields
Yes, the hexdump was simple, but it was really hard to read, and we can
do so much better, including taking empty data into account, and
formatting it by the actual size of the individual fields.

So this improves on the debug log, so that when we decide to try to
parse new field information, the data will be in a somewhat more legible
format that makes more sense.  And getting rid of the empty fields makes
it much clearer what data might be even remotely interesting.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-04 17:18:37 -07:00
Linus Torvalds
8f7e29e1f9 garmin: start decoding notifications and gas change events
The magic numbers in the decoding are all based on Wojciech Więckowski's
fit2subs python script.

The event decoding is incomplete, but it should be easy enough to add
new events as people figure them out or as the FIT SDK documentation
improves, whichever comes first.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-02 20:17:30 -07:00
Linus Torvalds
740222d216 garmin: don't suppress the time sample at zero time
The logic to suppress multiple redundant time samples in the garmin
parser also always suppressed the time sample at 0:00, which was not
intentional.

Fix it by simply making the "suppress before" logic be "suppress until"
instead.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-02 14:09:52 -07:00
Linus Torvalds
4a43392c78 Garmin: add DC_SAMPLE_CNS reporting
The code to parse it was already there, we just didn't report it.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-02 13:31:51 -07:00
Linus Torvalds
86540206db Add support for DC_SAMPLE_TTS - time to surface in seconds
Several dive computers support this, so why not have the proper
interface for it in libdivecomputer?

Triggered by the fact that the Python scripts to generate XML files from
the Garmin FIT files can import this information, but the native
libdivecomputer model couldn't.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-09-02 13:16:02 -07:00
Linus Torvalds
f6ea5f514a Merge branch 'garmin-descent' into Subsurface-NG
Merge the initial Garmin Descent Mk1 support.

This actually works well enough to be useful, even though there are a
few ugly details yet to be sorted out.

The download itself is fairly complete, but all event handling is
currently missing (warnings, gas changes, things like that).

Also, because of how libdivecomputer works, the "downloading" of dives
is entirely separate from the "parsing" of dives in the libdivecomputer
world.  And that is actually problematic for the Garmin Descent
downloader, because you actually need to parse the data to even figure
out whether it's actually a dive at all!

The Garmin Descent is also a fitness and general excercise tracker, so
people can (and do) use it for other sports than just diving, and so the
activities we download may end up not being dives at all, but other
events.

But before we parse them, we don't know, and we aren't really supposed
to parse them until after we've passed the data to the application and
it passes it back for parsing.  Nasty chicken-and-egg problem there..

So right now non-diving activities will just show up as very short
and/or shallow dives.

This is fixable by just parsing things an extra time, but I really wish
libdivecomputer would just stop thinking that downloading and parsing
are separate events.

* garmin-descent:
  Add dc_usb_storage_open to the symbols list
  garmin: only record gasmixes for cylinders that aren't enabled
  garmin: don't emit fake device info and vendor event
  garmin: add support for downloading gas mixes
  garmin: add GPS coordinate data and improve parser_get_field() reports
  garmin: actually start using the parsed data
  garmin: turn all the remaining unrecognized fields into DEBUG messages
  garmin: add a lot of new field definitions
  garmin: teach the parser to show undefined values for unknown fields too
  garmin: fix file length header parsing
  garmin: teach the parser about invalid values and more dates
  garmin: some fields are defined in all message types
  Garmin: start parsing definition records
  Garmin Descent Mk1: flesh out the actual downloading part
  Add Garmin Descent Mk1 skeleton
  Add 'USB storage' transport enumeration
2018-08-31 13:24:03 -07:00
Linus Torvalds
fe2a43e798 Add dc_usb_storage_open to the symbols list
Apparetly the Windows build needs this for the library building.

Reported-by: Wojciech Więckowski <xplwowi@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-08-31 13:21:56 -07:00
Linus Torvalds
63cd80c560 Merge https://github.com/libdivecomputer/libdivecomputer into Subsurface-NG
Merge upstream libdivecomputer changes from Jef Driesen.

* https://github.com/libdivecomputer/libdivecomputer:
  Add Travis CI integration
  Fix the transport command-line parameter
  Document dc_descriptor_get_model
  Include stddef.h in iostream.h
  Add support for the Mares Smart Air
  Fix the average depth for older OSTC dives
  Add support for the Oceanic Pro Plus X
2018-08-31 12:52:50 -07:00
Linus Torvalds
22a96bf395 garmin: only record gasmixes for cylinders that aren't enabled
This actually takes the gas status information into account, and doesn't
show gas mixes that are disabled.

All the Garmin Descent data now looks reasonable, but we're not
generating any events (so no warnings, but also no gas change events
etc).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-08-31 12:25:43 -07:00
Linus Torvalds
6a6e60c9bb garmin: don't emit fake device info and vendor event
The libdivecomputer model is just broken - we don't know this
information before parsing the dive.  But let's not emit a fake event
that generates bogus serial number data.  I thought I'd be able to fill
it in, but this really isn't reasonable, so disable it entirely for now.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-08-31 09:54:08 -07:00
Linus Torvalds
994efff75a garmin: add support for downloading gas mixes
This clarifies and generalizes the "pending sample data" a bit to also
work for gas mixes, since it's one of those things where you get
multiple fields in random order, and it needs to be batched up into one
"this gas for this cylinder" thing.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-08-31 09:44:37 -07:00
Jef Driesen
b1d434f0ea Fix the libusb and hidapi includes
The libusb and hidapi pkg-config files already add the subdirectory to
the header search path with:

   -I/usr/include/libusb-1.0
   -I/usr/include/hidapi

Therefore, using the subdirectory in the include statement is wrong. In
practice, this usualy works fine by accident, because the base directory
(/usr/include) is typically listed in the default search path of the
compiler. But that's not always true. For example when cross-compiling
or when using the PKG_CONFIG_LIBDIR environment variable.
2018-08-31 15:05:37 +02:00
Jef Driesen
631cfd8c45 Add Travis CI integration 2018-08-30 08:11:18 +02:00
Linus Torvalds
6b7c269c9c garmin: add GPS coordinate data and improve parser_get_field() reports
This adds all the GPS information I found, although for dives the
primary ones do seem to be the "session" entry and exit ones.

But I'm exporting all of them as strings, so that we can try to figure
out what they mean.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-08-29 17:52:07 -07:00
Linus Torvalds
c8e52081cd garmin: actually start using the parsed data
This gets me real profiles, with depth and temperature information.

Sadly, the temperature data seems to be in whole degrees C, which is not
good for diving.  But certainly not unheard of.

Also, while this does actually transfer a lot of other information too,
there are certainly things missing.  No gas information is gathered
(although we do parse it, we just don't save it), and none of the events
are parsed at all.

And the GPS information that we have isn't passed on yet, because there
are no libdivecomputer interfaces to do that.  I'll have to come up with
something.

But it's actually almost useful.  All the basics seem to be there.  How
*buggy* it is, I do not know, but the profiles don't look obviously
broken.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-08-29 15:55:48 -07:00