1552 Commits

Author SHA1 Message Date
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
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
838f730fb2 Merge branch 'timesync' 2017-08-18 23:23:36 +02:00
Jef Driesen
215d1155f8 Add time synchronization to the example application 2017-08-18 23:17:33 +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
db0e1691cc Merge branch 'hidapi' 2017-08-18 23:16:26 +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
Jef Driesen
813400ec54 Merge branch 'cochran' 2017-08-15 11:39:32 +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
John Van Ostrand
cd5eb61e90 Make rbstream pagesize smaller and device specific
The progress bar was taking 18 seconds between updates on a Commander II
when using a 128K pagesize. Since devices differ in their baud rates, it
makes sense to use smaller pages on slower devices. This change reduces
it to 32K on a Commander II and to 64K on EMC devices.
2017-08-15 11:28:19 +02:00
John Van Ostrand
55e8f83eb5 Use rbstream for reading profile data
Per-dive reading of the DC takes too long because of latency on read
commands. The rbstream solves this by reading ahead in large blocks.
2017-08-15 11:28:09 +02:00
Jef Driesen
4e0c2e4650 Remove non-existing function from header
The dc_device_version() function has been removed from the public api
long time ago.
2017-08-11 08:22:53 +02:00
Jef Driesen
535d612a93 Use the correct type in the leonardo vtable 2017-08-02 09:19:03 +02:00
Linus Torvalds
9fd6635cf6 Merge branch 'master' of git://git.libdivecomputer.org/libdivecomputer into Subsurface-branch
Merge with upstream libdivecomputer from Jef:

 - Jef merged my Scubapro G2 work, but renamed everything, and didn't
   get the newer IO model code. Very annoying.

   I went along with changing the G2 model family name to
   DC_FAMILY_UWATEC_G2 just to keep some of the basic infrastructure
   more easily mergeable.  But his uwatec_g2 version is not usable.

 - Cochran updates from John Van Ostrand

 - Misc improvements from Jef:
    * divesystems idive improvements
    * Oceanic OCS freedive mode
    * ppO2 callback cleanup

 - Some transport type work:
    * changes to IRDA configuration
    * basic bluetooth rfcomm transport mode

* 'master' of git://git.libdivecomputer.org/libdivecomputer: (35 commits)
  Removed unused code
  Fixed duplicate gasmix event reports
  Added decompression event handling for the Commander
  Fix bad profiles when profile ringbuffer wraps around
  Changed cochran_comander_profile_size function parameters
  Fixed location and encoding of Commander II pointers
  Use a local variable for the layout pointer
  Add new EMC device model string
  Add support for Pre-21000 s/n Commander dive computers
  Fix problems with wrapped logbook ringbuffer
  Retry read operations on failure
  Change profile download to be incremental
  Fix the id string offset
  Fix the progress events
  Use the trimix data format
  Use the correct model number
  Enable more fine grained progress events
  Abort with an error if the buffer is too small
  Use the standard libdivecomputer error codes
  Scubapro G2: add missed command packet logging
  ...
2017-07-10 14:00:47 -07:00
Linus Torvalds
eed75cb0be Clean up Shearwater string handling
And remove the nasty and disgusting transmitter data handling code that
Dirk added to work around his misunderstanding of the parsing code.

This code now collects the various states of the transmitter batteries
throughout a dive and reports the most meaningful summary in the end. It
also rewrites the rest of the string handling code to be architecturally
cleaner.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-09 14:36:05 -07:00
Dirk Hohndel
4a3f7a7cce Mark DC descriptors with supported transport
The syntax is trivial.
"// FTDI" for FTDI cable support
"// BT"   for classic Bluetooth support
"// BLE"  for Bluetooth LE support

We can then parse this information during the Subsurface build process
and create the (hopefully correct) support matrix for dive computer
download from the mobile apps.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-08 15:25:22 -07:00
Dirk Hohndel
8ea8cebb4e Shearwater: correctly handle the different models
That weird 'petrel' argument and member variable can easily be replaced
by looking at the model.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-07 18:00:54 -07:00
Dirk Hohndel
6f4776d6c4 Shearwater: detect the hardware type
Stop pretending that all the devices since the Petrel are the same. They
actually aren't. So let's detect them and correctly identify them.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-07 17:29:41 -07:00
Dirk Hohndel
04073759a8 Shearwater: add transmitter battery information
This should be a STRING callback, but those come from the header and we
don't have the information until after we have parsed all the samples.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-07 16:36:50 -07:00
Dirk Hohndel
84ad5aa5ad Shearwater: report battery type for logversion >= 7
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-07 16:36:50 -07:00
Dirk Hohndel
41417fbe59 Shearwater: add support for remaining gas time
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-07 16:36:50 -07:00
Dirk Hohndel
8736a6dca1 Shearwater: extract tank sensor data for log version 7
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.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-07 09:54:50 -07:00
Dirk Hohndel
d85481cefd Shearwater: extrac log version from header
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.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-07 07:04:13 -07:00
Jef Driesen
b8b94c46fc Merge branch 'cochran' 2017-07-05 13:12:27 +02:00
John Van Ostrand
fd1557f634 Removed unused code 2017-07-05 13:11:33 +02:00
John Van Ostrand
2c5e787b77 Fixed duplicate gasmix event reports
Newer cochran DCs record a gas change event at the begining of a
dive. The code creates a gas change before processing samples so
with newer DCs this resulted in duplicate events.
2017-07-05 13:11:33 +02:00
John Van Ostrand
094b635f87 Added decompression event handling for the Commander
I finally found an example of decompression on a Commander II computer
and it seems to be identical to the EMC.
2017-07-05 13:11:33 +02:00
John Van Ostrand
e1b679912a Fix bad profiles when profile ringbuffer wraps around
The method used to calculate the data used by dives (to determine when
we run out of ringbuffer) incorrectly didn't include surface sample
data. Ten to twenty minute of sample data is recorded at the surface in
case the diver re-descends, continuing the dive. The code then thought
that older dive profiles were not yet overwritten. The improper data was
returned to the user.
2017-07-05 13:11:33 +02:00
John Van Ostrand
9c795e6e4e Changed cochran_comander_profile_size function parameters
This function is much more useful if it works like a
ringbuffer_distance() function. It assumed the wrong values when
calculating profile size and it didn't have easy access to values it
needed to properly calculate profile sizes.

It makes sense to keep since it validates pointers.
2017-07-05 13:11:33 +02:00
John Van Ostrand
48d93e9404 Fixed location and encoding of Commander II pointers
Commander II pointers to profile ringbuffer data was wrong. After seeing
the Commander I encoding I realized the Commander II encoding of RB
pointers was in a flipped word big endian format. It only appeared to be
in normal big endian format because of an adjacent pointer that usually
shared the same first two bytes.
2017-07-05 13:11:33 +02:00
John Van Ostrand
3545bf158a Use a local variable for the layout pointer 2017-07-05 13:11:33 +02:00
John Van Ostrand
3a2f2ff0c3 Add new EMC device model string 2017-07-05 13:11:33 +02:00