1302 Commits

Author SHA1 Message Date
Berthold Stoeger
8a84ece7d0 Support for the Scubapro Aladin Sport Matrix.
The protocol is identical to the G2 protocol, with the exception of a
missing handshake.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-10-29 07:15:14 -07:00
Linus Torvalds
0099aeeb70 Merge git://git.libdivecomputer.org/libdivecomputer into Subsurface-branch
Merge with upstream libdivecomputer: USB HID fixes.

* git://git.libdivecomputer.org/libdivecomputer:
  Make the initialization thread-safe
  Initialize the usb library only once
2017-10-19 15:57:16 -04:00
Jef Driesen
f708eadcfd Make the initialization thread-safe
Perform the initialization inside a critical section.

Unfortunately Windows critical sections, which are the simplest
synchronization mechanism available on Windows, do not support static
initialization. A call to InitializeCriticalSection is required.
Therefore a simple spinlock, with an implementation based on atomic
operations, is used as a workaround.
2017-10-09 14:35:36 +02:00
Jef Driesen
7b920f5c42 Initialize the usb library only once
Initializing the hidapi library more than once is tricky. The hid_init()
function can be called multiple times, but the the hid_exit() function
will free the resources unconditionally, regardless of how many times
the hid_init() function has been called. The consequence is a premature
termination of the library.

To avoid this problem, the calls are reference counted. Note that this
workaround can't protect against calls made outside the libdivecomputer
code!

The libusb library doesn't suffer from this problem, because each
initialization returns a new context pointer. But for consistency, we
now also use a single reference counted libusb context.
2017-10-09 14:35:36 +02:00
Linus Torvalds
07f5777c71 Merge git://git.libdivecomputer.org/libdivecomputer into Subsurface-branch
Merge with upstream libdivecomputer:

 - workarounds for Windows libusb and hidapi issues

 - misc random cleanups/noise

 - rename DiveSystem to Ratio

 - make Cochran with better with FTDI

 - new support for: Suunto D4f, Ratio idive tank pressure, and Sherwood
   Insight temperature and Oceanic ndl/deco sample.

* git://git.libdivecomputer.org/libdivecomputer:
  Workaround for a Windows libusb issue
  Use a fixed size packet for sending
  Replace the size macro with the sizeof operator
  Use the correct printf format for the size_t type
  Move platform specific macros to a common header file
  Use the correct data type for the return value
  Rename the DiveSystem vendor to Ratio
  Fix the Sherwood Insight temperature
  Implement the ndl/deco sample
  Change communication parameter to work better with FTDI
  Retry read operations on failure
  Add support for the Suunto D4f
  Implement the tank pressure
2017-10-05 15:02:56 -07:00
Jef Driesen
bcb64b3297 Workaround for a Windows libusb issue
When libusb uses the Windows HID api internally, it does automatically
prepend a zero report ID to the data for devices which support only a
single report. But apparently it also returns a size of one byte extra!
As a workaround, the number of bytes is limited to the actual size.

See commit c9ed92d3f55c259931527a27d018eb5791a176dd for a similar issue
in the hidapi library.
2017-09-28 22:19:11 +02:00
Jef Driesen
ddb7276bf0 Use a fixed size packet for sending
The Windows HID api always expects to receive a fixed size buffer
(corresponding to the largest report supported by the device). But
unlike the hidapi library, the libusb library doesn't automatically pad
the buffer to the expected size when trying to send less bytes. Thus
when trying to submit the transfer, the underlying Windows api call
immediately fails with ERROR_INVALID_PARAMETER.

To workaround this problem, pad the data packet with zeros manually and
always send the entire packet (1 byte report ID and 32 bytes payload).
2017-09-28 22:06:21 +02:00
Jef Driesen
a28d2feb4f Replace the size macro with the sizeof operator 2017-09-28 22:06:14 +02:00
Jef Driesen
5a00224c93 Use the correct printf format for the size_t type 2017-09-28 22:02:53 +02:00
Jef Driesen
52e03944c0 Move platform specific macros to a common header file 2017-09-28 22:02:53 +02:00
Jef Driesen
b683eca5c8 Use the correct data type for the return value 2017-09-28 22:01:58 +02:00
Jef Driesen
87adab39d7 Rename the DiveSystem vendor to Ratio
At the time support for the Orca and iDive series was implemented, they
were being sold under the "DiveSystem" brand. But nowadays, the newer
iDive and iX3M series are being sold under the "Ratio" brand. Since this
frequently confuses end-users, let's rename the libdivecomputer vendor
name as well.

The Orca and the original iDive series remain under the DiveSystem
brand.
2017-09-28 22:00:09 +02:00
Jef Driesen
fa53d1351b Fix the Sherwood Insight temperature 2017-09-12 22:34:55 +02:00
Jef Driesen
50c4f18cf6 Implement the ndl/deco sample 2017-09-12 22:34:55 +02:00
John Van Ostrand
0220782aa8 Change communication parameter to work better with FTDI
The parameters used with the FTDI USB serial port drivers didn't work
well with directly with libftdi1. The new baud rate results in the same
effective baud rates for both.

The rbstream block size was reduced to help with the unreliability of
the libftdi communications.
2017-09-12 11:08:54 +02:00
John Van Ostrand
ca4c261f6e Retry read operations on failure
Using FTDI for custom I/O resulted in very unrealible reads. This patch
allows more reliable use of FTDI custom I/O, like what might be needed
when used on a mobile device like Android.

[Jef Driesen: Modified to retry only for non-fatal errors. This simply
restores the code from commit b3d2c603ddec9758fb36706bbde46ce23ca9f0ed,
which was removed in commit 55e8f83eb5d934e65fbf587d427de267f174c651.]
2017-09-12 11:06:38 +02:00
Jef Driesen
c839134130 Add support for the Suunto D4f 2017-09-11 08:25:51 +02:00
Jef Driesen
be8b95fdf9 Implement the tank pressure
With the new APOS4 firmware, the latest ix3m and idive models support a
wireless tank sensor. For dives without a tank pressure sensor, the
pressure field in the sample is zero. Thus the first non-zero value
indicates the presence of a tank sensor.
2017-09-07 10:26:07 +02:00
Linus Torvalds
c0f025b019 Merge git://git.libdivecomputer.org/libdivecomputer into Subsurface-branch
Merge with upstream libdivecomputer:

 - uwatec cleanups and fixes (G2/trimix parsing etc)

 - event and bookmark fixes for Oceanic, iDive/iX3M and Aqualung i300

* git://git.libdivecomputer.org/libdivecomputer:
  Use more descriptive names
  Use two passes to parse the profile data
  Fix the Uwatec trimix data format
  Implement the ndl/deco, rbt and bookmark samples
  Implement the setpoint sample for the iDive and iX3M
  Implement the ndl/deco sample for the Aqualung i300
  Update the msvc project file
2017-09-06 10:58:21 -07:00
John Van Ostrand
3602a324b8 Flagged Cochran DCs for FTDI communications
This with serial_ftdi.c changes and other libdivecomputer changes
enables Cochran DCs to work with libftdi on android devices.

Signed-off-by: John Van Ostrand <john@vanostrand.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-09-06 10:57:56 -07:00
Jef Driesen
cb2a4f4a72 Use more descriptive names
Those two samples are no longer unknown. The first one contains some
freedive related data, and the second one contains some additional data
with several sub types. At the moment only the tank and gas mix info is
used.
2017-09-02 10:34:23 +02:00
Jef Driesen
ce590b5bc9 Use two passes to parse the profile data
In the trimix data format, the tank and gas mix information is no longer
stored in the header, but in a special sample. Because this sample is
usually located at the end of the profile, the info isn't available yet
during the first pass. Hence the need for a second pass.

Without this change, the tank and gas mix samples will be missing unless
the caller calls the dc_parser_get_field() function before calling the
dc_parser_samples_foreach() function.
2017-09-02 10:12:44 +02:00
Jef Driesen
6b88bc1b8b Fix the Uwatec trimix data format
The trimix dive header is only 84 bytes large, instead of 0xB1 bytes.
The difference is quite hard to notice, because compared to the normal
Galileo data format, the majority of the fields are located at exactly
the same offset. But there are also some subtle differences, like the
settings field containing the freedive and gauge bits.

To fix this bug, a new header table is added. The rest of the code is
updated to use this new table instead of the old trimix flag. The only
place where the old flag is still used is for the decoding of the tank
and pressure sample.
2017-09-01 15:00:10 +02:00
Jef Driesen
26f5925c05 Implement the ndl/deco, rbt and bookmark samples 2017-08-25 21:25:21 +02:00
Jef Driesen
d954a500f6 Implement the setpoint sample for the iDive and iX3M 2017-08-22 08:40:55 +02:00
Dirk Hohndel
aa0b522ab8 Mark 3 more Shearwater dive computers as BLE
Technically this is inaccurate because while some Perdix and Petrel 2
models do in fact support dual stack, the Petrel only does BT. But
the Petrel 2 identifies itself as Petrel via BT, so we need to flag
them both here.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-08-20 21:01:31 -07:00
Linus Torvalds
d7503b05e2 Scubapro G2: add zero report type to USBHID packet write
Jef reports that this is required for HIDAPI, and while I would really
like to just make the report type part of the custom packet_io interface
instead of making it visible here, this is the minimal fix for now.

See commit d251b373becc ("Add a zero report ID to the commands"), which
does the same thing, except for the fact that we now need to treat BLE
and USB HID differently.

I may still end up teaching the USB HID custom-IO layer to add the
report ID byte, and just specify it at dc_usbhid_custom_io() time
instead.  That would make the G2 code not have to care about the
transfer protocol again.

(But the other user of USB HID - the Suunto EON Steel - has much bigger
protocol differences between USB HID and BLE, so the whole "try to be
protocol-agnostic" hope may be just a pipe dream anyway, and it's just
the Scubapro G2 that _could_ work that way).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-08-20 19:16:21 -07:00
Jef Driesen
abab44a74c Implement the ndl/deco sample for the Aqualung i300 2017-08-20 21:29:18 +02:00
Linus Torvalds
aed80fe7fd 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).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-08-19 14:35:05 -07:00
Linus Torvalds
928be1f45b Merge git://git.libdivecomputer.org/libdivecomputer into Subsurface-branch
Merge with upstream libdivecomputer from Jef:

 - more Cochran work from John Van Ostrand

 - new 'timesync' interface to synchronize the clock on a dive computer

 - support for Aqualung i200

 - misc updates (Cressi Leonardo fix, OSTC 3+ renaming, fix surface pressure on iX3M, idive salinity parsing)

 - HIDAPI work.

It turns out that HIDAPI is not compatible with libusb in the actual
packet sending path, so this will need some more cleanups - Jef doesn't
see the issue because he doesn't have a generic packet IO layer and
doesn't share packets with the BLE code.

* git://git.libdivecomputer.org/libdivecomputer: (25 commits)
  Add basic timezone support
  Add time synchronization to the example application
  Implement the new api for the HW devices
  Add support for synchronizing the device clock
  Use hidapi as the default USB HID library
  Workaround for a Windows hidapi issue
  Reset the number of bytes to zero on error
  Add a zero report ID to the commands
  Fix compatibility issue with hidapi
  Implement the salinity field
  Fix the atmospheric pressure for the iX3M
  Rename the OSTC 3+ to OSTC Plus
  Locate the most recent dive using the logbook pointers
  Add support for the Aqualung i200
  Add event handling to TM model
  Fix profile buffer size and address size
  Add three event codes
  Add support for the Commander TM
  Dump function no longer assumes reads begin at byte 0
  Remove unneeded function
  ...
2017-08-19 13:51:56 -07:00
Jef Driesen
156f54302d Add basic timezone support
Allthough most dive computers always use local time and don't support
timezones at all, there are a few exceptions. There are two different
sources of timezone information:

 - Some of the newer Uwatec/Scubapro devices use UTC internally and also
   support a timezone setting. This UTC offset is currently taken into
   account to obtain the dive date/time, but the UTC offset itself is
   lost.

 - Uwatec/Scubapro and Reefnet devices rely on the clock of the host
   system to synchronize the internal device clock and calculate the
   dive date/time. The consequence is that the resulting date/time is
   always in the timezone of the host system.

In order to preserve this timezone information, the dc_datetime_t
structure is extended with a new "timezone" field, containing the UTC
offset in seconds. Devices without timezone support will set the field
to the special value DC_TIMEZONE_NONE.

The dc_datetime_localtime() and dc_datetime_gmtime() functions will
automatically populate the new field with respectively the local
timezone offset and zero. The dc_datetime_mktime() function will take
into account the new timezone field for the conversion to UTC. The
special value DC_TIMEZONE_NONE is interpreted as zero.
2017-08-18 23:26:45 +02:00
Jef Driesen
22e0ab3d2b Implement the new api for the HW devices
The Heinrichs-Weikamp devices already supported clock synchronization by
means of a device specific function. This is now replaced with the new
api.
2017-08-18 23:17:33 +02:00
Jef Driesen
acb4a187fb Add support for synchronizing the device clock
Being able to synchronize the dive computer clock with the host system
is a very useful feature. Add the infrastructure to support this feature
through the public api.
2017-08-18 23:17:33 +02:00
Jef Driesen
eea02126a4 Use hidapi as the default USB HID library
On Windows, the hidapi library uses the standard Microsoft USB HID
driver, while libusb requires the installation of a different driver
(WinUSB or libusbK). But installing one of the libusb drivers breaks
compatibility with other applications using hidapi (Scubapro LogTRAK and
Suunto DM5) because only one driver can be active. Switching
libdivecomputer to hidapi avoids this problem.

On Linux, the hidapi library doesn't seem to offer any advantages over
libusb. Most distributions don't even have the hidapi library installed
by default. Because there are usually two variants of the hidapi library
available on Linux (hidapi-libusb and hidapi-hidraw), the autotools
build system won't be able to detect it out-of-the-box, and will
automatically fallback to the libusb implementation.

On Mac OS X, hidapi is already the default (and also the only option).
2017-08-18 23:15:55 +02:00
Jef Driesen
c9ed92d3f5 Workaround for a Windows hidapi issue
The Windows HID api always expects to receive a fixed size buffer
(corresponding to the largest report supported by the device). Therefore
the hidapi library internally pads the buffer with zeros to the expected
size, but apparently it also returns the size of the padded buffer! As a
workaround the number of bytes is limited to the actual size.
2017-08-18 23:15:55 +02:00
Jef Driesen
b82d5fcfff Reset the number of bytes to zero on error
The hidapi read and write functions return a negative value if an error
occurs. Those negative values should not be returned to the caller as
the actual number of bytes (or used in the logging). The value is reset
to zero instead.
2017-08-18 23:15:55 +02:00
Jef Driesen
d251b373be Add a zero report ID to the commands
The zero report ID byte is required when using the hidapi library. We
just never noticed this problem before, because we use libusb by
default, and libusb doesn't need the extra zero byte.
2017-08-18 23:15:55 +02:00
Jef Driesen
05c858bf96 Fix compatibility issue with hidapi
The hidapi library requires that the first byte contains the report ID.
For devices which support only a single report, the report ID byte
should be zero. The remaining bytes contain the actual report data.

Now, when hidapi uses libusb internally, it strips the zero report ID
byte again before passing the data to libusb. Thus in order to remain
compatible with the hidapi based implementation, our libusb based
implementation should do the same.
2017-08-18 23:15:55 +02:00
Jef Driesen
854ad13f16 Implement the salinity field 2017-08-17 08:49:38 +02:00
Jef Driesen
722160cd48 Fix the atmospheric pressure for the iX3M
The iX3M appears to store the atmosperic pressure in units of 1/10
millibar instead of 1 millibar.
2017-08-17 08:49:32 +02:00
Jef Driesen
133b7394c2 Rename the OSTC 3+ to OSTC Plus
The correct name for the OSTC 3+ is OSTC Plus nowadays. Allthough the
exact name doesn't really matter because all OSTC3 based models are
compatible, using the correct name should reduce confusing for
end-users.
2017-08-17 08:46:35 +02:00
Jef Driesen
2813d61f65 Locate the most recent dive using the logbook pointers
I received a bug report from a device which failed to download new dives
after a reset (probably caused by an empty battery). This reset appears
to reset the internal dive counter back to zero, and also resets the
write pointer back to the begin of the logbook ringbuffer, but leaves
the existing logbook entries in place. The result is that the logic to
find the most recent dive based on the highest internal dive counter,
will be wrong because it finds those old entries.

The discovery of the logbook (and profile) write pointers eliminates the
need to search for the most recent logbook entry.
2017-08-15 23:29:30 +02:00
Jef Driesen
f7bcbb5828 Add support for the Aqualung i200 2017-08-15 11:47:05 +02:00
John Van Ostrand
cdf7e8e635 Add event handling to TM model
For some reason I had never added event processing to this model.
2017-08-15 11:30:13 +02:00
John Van Ostrand
3f1131f80f Fix profile buffer size and address size
I dived the model enough to wrap the profile buffer and I was wrong
about where the end was. Also, the buffer starts 3 bytes after where it
could. We were treating profile pointers as 4 bytes when they are two
bytes. This worked most of the time when short tissues were clear
(tissue load follows the pointer).
2017-08-15 11:30:09 +02:00
John Van Ostrand
adef3f67fc Add three event codes
I found three previously undiscovered event codes.
2017-08-15 11:30:04 +02:00
John Van Ostrand
fb65726a55 Add support for the Commander TM
The Cochran Commander TM appears to be a first generation Commander with
limited storage and function compared to later models.

The main differences are:

 - The TM doesn't support high-speed transfer so use the 0x05 read
   command and don't change to a higher baud rate. Still reset to 9600
   to wait for the heartbeat.
 - The TM has a different config command (one byte).
 - The TM has only one config page.
2017-08-15 11:29:58 +02:00
John Van Ostrand
1d8f25ba9b Dump function no longer assumes reads begin at byte 0
For previously supported Cochran computers high-speed read of log and
profile data started at byte 0. Older models that lack the high-speed
transfer function use the standard speed read commands and so the log
and profile data are read at higher addresses.
2017-08-15 11:29:40 +02:00
John Van Ostrand
8b41e72cf7 Remove unneeded function
Since moving to per-dive download of profile data (and now rbstream
download) the data->sample_data_offset and data->sample_size variables
aren't used so calculating them doesn't make sense.
2017-08-15 11:29:05 +02:00
Jef Driesen
88b6e36e04 Use only a single read operation
The profile and throw-away data can be read all at once. This avoids the
need for an extra memory allocation and fixes a memory leak.
2017-08-15 11:28:57 +02:00