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>
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>
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
...
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.
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.
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).
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.
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.
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.
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.
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.
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.
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).
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.
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.
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.
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.
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
...
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>
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>
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>
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>
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>
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>
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.
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.
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.
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.