1900 Commits

Author SHA1 Message Date
Jef Driesen
39aad6bb52 Report an error for invalid ringbuffer pointers
Previously, invalid ringbuffer pointers were always handled during the
second pass. But that changed after the previous commit. If the invalid
pointer is located in the first logbook entry, this is now handled as
"no dives present". Fixed by returning the correct error code instead.
2020-02-24 09:21:33 +01:00
Jef Driesen
f93b2afcc8 Improve the empty logbook ringbuffer detection
If all the entries in the logbook ringbuffer happen to be empty, the
ringbuffer end pointer will not have a valid value. Creating the
ringbuffer stream will fail, and an error will be returned to the
caller. Fixed by adding an extra check, and exit if there are no dives.
2020-02-24 08:54:44 +01:00
Jef Driesen
1d235daf30 Skip the BLE handshake for the Pro Plus X
The Oceanic Pro Plus X does not seem to understand the BLE handshake
command. It just fails with a NAK byte (0xA5) as response.
2020-02-21 13:48:11 +01:00
Jef Driesen
ebb8715e2c Merge branch 'goa' 2020-02-13 11:10:35 +01:00
Jef Driesen
5dc7e54596 Implement the gas mix sample
The current gas mix index is stored in the 11th bit of the sample value.
2020-02-13 11:07:24 +01:00
Jef Driesen
59d9791446 Limit the depth value to 11 bits
The depth value is encoded with only 11 bits instead of 12 bits. The
extra bit contains the gas mix index. This resulted in wrong depths,
with values larger than 204.8m.
2020-02-13 11:05:25 +01:00
Janice McLaughlin
a01b9bc9b9 Add support for the Scubapro A1 2020-02-04 08:41:55 +01:00
Janice McLaughlin
4a60f89f4a Add support for the Sherwood Wisdom 4 2020-02-04 08:30:33 +01:00
Nick Shore
ba96b3092d Fix the vtpro datetime parsing
For the BCD encoded day field (range 1-31), two bits are sufficient to
represent the upper digit (range 0-3). The purpose of the highest bit is
unknown, but it's certainly not part of the day field, and needs to be
masked off.
2020-01-28 10:59:22 +01:00
Jef Driesen
f65e3cf39e Install the ioctl header file 2020-01-17 08:12:14 +01:00
Jef Driesen
4fe1b96689 Merge branch 'oceanic-ble' 2020-01-06 23:26:55 +01:00
Jef Driesen
cfd54ff80e Advertise the BLE support in the device descriptors
The bluetooth device filtering is based on the fact that the format of
the bluetooth device name is something like 'FQ001124', where the two
first letters are the ASCII representation of the model number (e.g.
'FQ' or 0x4651 for the i770R), and the six digits are the serial number.
2020-01-06 23:26:55 +01:00
Jef Driesen
4bc5ee90ef Fix the BLE device detection for the i770R and Pro Plus X
It seems that the BLE communication protocol is somewhat different from
the serial one in the version string: while the serial version tends to
show the memory size, the BLE version string has some other numeric
pattern.

Linus Torvalds reports the BLE pattern for the i770R is normally just
"0001", allthough he once also observed "0090" with the same dive
computer. A communication trace from a Pro Plus X also showed "0001".

We don't have enough information to guess the meaning of the number.
Regardless, for those two dive computers supporting BLE, make the
pattern simply ignore the last four digits, since they clearly vary.

Based-on-code-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-01-06 23:26:55 +01:00
Jef Driesen
4baf140d25 Implement the BLE handshaking
The BLE communication sends a handshake packet containing a passphrase
based on the serial number of the device. Sadly, we can't actually read
the serial number from the device until after this handshake has
successfully completed, which makes it a bit of a chicken-and-egg
problem from a communication standpoint. However, the serial number is
also exposed in the bluetooth device name the device advertizes, which
is the reason for the newly added DC_IOCTL_BLE_GET_NAME ioctl.

Thanks to Janice McLaughlin for pointing out the logic of this magic
handshake.

Based-on-code-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-01-06 23:26:42 +01:00
Jef Driesen
6ba0726a42 Implement the BLE packet sending and receiving
Based-on-code-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-01-06 21:29:24 +01:00
Jef Driesen
4923d3761e Read the entire data packet in a single operation
Refactor the packet receiving code to read the ack byte, the payload
data and the checksum all at once, with just a single read operation.
This is not only a bit more efficient, but will also simplify the BLE
support.
2020-01-06 21:29:24 +01:00
Jef Driesen
437db813d5 Remove the trailing zero byte from all commands
The trailing zero byte is present for historic reasons only. At the time
the Oceanic protocol was implemented, the Oceanic application send this
extra zero byte too, and we simply copied this behaviour. But more
recent versions no longer send it. Probably a small (harmless) bug that
was fixed.
2020-01-06 21:29:24 +01:00
Jef Driesen
4b2156d378 Fix a bug in the ACK/NAK handling
The write command is send as two separate packets. The first packet
contains the B2 command and the page number, and the second packet
contains the payload and checksum. Because the payload can contain
arbitrary data, the first byte of a packet is not necessary a command
byte. But the code to select the correct ack byte is based on this
assumption. Fixed by passing the expected ack byte.
2020-01-06 21:29:24 +01:00
Jef Driesen
91309a3d54 Remove an unnecessary function 2020-01-06 21:29:24 +01:00
Jef Driesen
a67bab58ca Merge branch 'ioctl' 2020-01-06 21:27:38 +01:00
Jef Driesen
e71278a13f Add an ioctl to retrieve the remote device name 2020-01-06 21:24:58 +01:00
Jef Driesen
c205299c02 Re-implement the set_latency function as an ioctl
The set_latency function is the perfect example of a feature that should
be implemented as an ioctl: it's only implemented by a single driver,
and the functionality is also highly platform specific.
2020-01-06 21:24:58 +01:00
Jef Driesen
0359a57fdc Add an ioctl function to the I/O interface
This new ioctl function allows to perform I/O stream specific requests
through a generic interface. This provides an easy way to extend the I/O
interface with some driver specific features, without having to modify
the public api.
2020-01-06 21:21:50 +01:00
Jef Driesen
be0e32b43b Merge branch 'poll' 2020-01-06 21:21:31 +01:00
Jef Driesen
af5716d685 Integrate the new poll function
Replace the manual polling, implemented using a combination of the
dc_iostream_get_available and dc_iostream_sleep functions, with the new
and more efficient poll function.
2020-01-06 13:44:07 +01:00
Jef Driesen
f6fa2b84bc Add a poll function to the I/O interface
The Linux implementation is very straighforward and just a lightweight
wrapper around the select function. But the Windows implementation is
much more complex, because the Windows event notification mechanism
behaves very different:

The WaitCommEvent function does not support a timeout and is always a
blocking call. The only way to implement a timeout is to use
asynchronous I/O (or overlapped I/O as it's called in the Windows API),
to run the operation in the background. This requires some additional
book keeping to keep track of the pending background operation.

The event mechanism is also edge triggered instead of level triggered,
and reading the event with the WaitCommEvent function clears the pending
event. Therefore, the state of the input buffer needs to be checked with
the ClearCommError function before and after the WaitCommEvent call.

The check before is necessary in case the event is already cleared by a
previous WaitCommEvent call, while there is still data present in the
input buffer. In this case, WaitCommEvent should not be called at all,
because it would wait until more data arrives.

The check afterwards is necessary in case WaitCommEvent reports a
pending event, while the data in the input buffer has already been
consumed. In this case, the current event must be ignored and
WaitCommEvent needs to be called again, to wait for the next event.
2020-01-06 13:44:07 +01:00
Jef Driesen
ef4bd94717 Add support for the Oceanic Veo 4.0 2020-01-06 13:33:33 +01:00
Jef Driesen
018198dc17 Increase the timeout to 3 seconds
The BLE communication is significant slower than usb-serial. The first
BLE data packet of each response often takes longer than one second to
arrive. This causes the first attempt to fail with a timeout. The second
attempt will appear to succeed, because it actually receives the
response of the first attempt. But now the next command will fail,
because it will receive the response of the second attempt of the
previous command.

Increasing the timeout and adding an extra delay before retrying, avoids
this problem.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-12-28 10:30:37 +01:00
Jef Driesen
02ae8d3fdb Fix the Aeris Manta memory layout
For the Aeris Manta, the end of the profile ringbuffer appears to depend
on the firmware version. For older firmware versions (1x), the end of
the ringbuffer is at address 0xFFF0, while for the newer versions (2x),
it's 0xFE00.

The code checks for firmware version 2B, because that's the lowest known
version in the 2x range.

Reported-by: Nick Shore <support@mac-dive.com>
2019-12-23 21:57:05 +01:00
Jef Driesen
9f3e0a7026 Add support for the Oceanic Pro Plus 4 2019-12-23 21:56:36 +01:00
Jef Driesen
ad297c1cc9 Strip the source directory from file names
Use the GCC 8 -fmacro-prefix-map option to strip the source directory
and change the __FILE__ macro into a relative path.
2019-12-21 20:57:06 +01:00
Nick Shore
03c8e350dd Fix the Oceanic Geo 4.0 memory layout 2019-12-20 11:04:52 +01:00
Jef Driesen
ae733fd8a8 Ignore all empty logbook entries
The logbook ringbuffer is always updated sequentially. Therefore, emtpy
entries can only be present after the oldest dive. However it appears
that under some special conditions (for example an empty battery during
the dive), the logbook entry is not always stored correctly, which can
result in an empty entry after all.

I suspect that at the start of each dive, the OSTC erases the next
available entry in the logbook ringbuffer and updates the internal write
pointer. Once the dive is finished, the actual content of the erased
logbook is written. Thus, when the OSTC runs out of battery power during
the dive, that last step never happens, and the erased entry remains in
place.

As a workaround, ignore all empty logbook entries instead of assuming we
reached the last dive.
2019-11-29 10:29:43 +01:00
Jef Driesen
b9a3606f37 Add a workaround for the hwOS ppO2 firmware bug
Due to a bug in the hwOS Tech firmware v3.03 to v3.07, and the hwOS
Sport firmware v10.57 to v10.63, the ppO2 divisor is sometimes not
correctly reset to zero when no ppO2 samples are being recorded.

Usually this condition can be detected by the fact that the length of
the extended sample will not have enough space left for the ppO2 sample
(9 bytes). As a workaround, reset the divisor back to zero to manually
disable the ppO2 samples.

In theory this detection method is not 100% reliable. There can still be
other sample types present in the extended sample. If their total size
is larger than 9 bytes, the bug will not be detected at all. Instead,
those bytes will get interpreted as the ppO2 sample, resulting in bogus
ppO2 values. Additionally, one of the other sample types will now run
out of space and cause the parsing to fail with an error. However, in
practice this risk is relative low. Most of the other samples are
relative small (1 or 2 bytes), so you would need many of them. That's
rather unlikely in most configurations. The only exception is the large
deco plan sample (15 bytes).
2019-11-22 22:59:25 +01:00
Jef Driesen
a5ba2f4e41 Use macros to encode the firmware version 2019-11-21 11:07:55 +01:00
Jef Driesen
612011249d Use symbolic constants for the sample types 2019-11-21 11:07:07 +01:00
Jef Driesen
b92cf6de69 Remove the obsolete hwos parameter
In commit 2829f7ebf9902170bf653d67dbe412a0a4f140cf, the hwos parameter
of the hw_ostc_parser_create() function was kept to preserve backwards
compatibility. Since the function has been removed from the public api,
the parameter can be removed now.
2019-11-21 11:07:07 +01:00
Jef Driesen
7f21998ad5 Limit the tank pressure workaround to hwOS devices
The workaround for the tank pressure in the previous commit is only
relevant for the newer hwOS based devices, and not for the original OSTC
devices. In practice this doesn't cause any problems because the
original OSTC doesn't support a tank pressure sensor, but nevertheless
it's better to use the correct condition.
2019-11-21 11:07:04 +01:00
Jef Driesen
ab230fd4e0 Fix the OSTC tank pressure decoding
The tank pressure is stored with a resolution of 1 bar instead of 0.1
bar. There is however one exception. The hwOS Sport firmware used a
resolution of 0.1 bar between versions 10.40 and 10.50.

Unfortunately the only way to distinguish the Sport from the Tech
variant is the different range of the version number (10.x vs 3.x). The
consequence is that this workaround will start to produce wrong results
once the firmware version number of the hwOS tech variant reaches the
10.x range. If that ever happens, this workaround should be removed
again!
2019-11-14 12:18:09 +01:00
Jef Driesen
21a9fa6879 Fix the Scubapro G2 HUD udev rule
The USB VID/PID numbers must not include the hexadecimal 0x prefix.
2019-11-14 10:06:50 +01:00
Jef Driesen
4bbcb6a8a1 Add the Mares Genius to the bluetooth filter
Use the prefix matcher because the bluetooth device name of the Mares
Genius appears to contain spaces at the end.
2019-11-14 10:06:39 +01:00
Jef Driesen
4c91309c56 Add firmware upgrade support for the Ratio computers 2019-11-14 09:43:35 +01:00
Jef Driesen
e215d10296 Add support for the Oceanic Geo 4.0 2019-10-23 09:09:59 +02:00
Jef Driesen
e2ae5f9525 Fix a buffer overflow
There are 8 opening/closing records instead of 7.
2019-10-22 20:58:50 +02:00
Jef Driesen
a7edb159fd Merge branch 'shearwater' 2019-09-27 08:07:50 +02:00
Jef Driesen
6c441bb402 Improve the support for multiple tank transmitters
Some of the newer Shearwater dive computers support up to 2 tank
pressure sensors. The tank pressure samples were already reported, but
the tank field with the corresponding begin/end pressure was still
missing.
2019-09-27 08:07:15 +02:00
Jef Driesen
e23c374cd8 Extract the log version immediately
To be able to collect the tank begin/end pressure, the log version needs
to be available earlier, because it's needed for parsing the tank
pressure data in the samples. Therefore, extract the log version
immediately after locating the opening record.
2019-09-24 14:00:25 +02:00
Jef Driesen
03ff5d32f2 Use a struct for the gasmix data 2019-09-24 14:00:01 +02:00
Jef Driesen
41b24adfcb Use a prefix match for the Suunto bluetooth name
The Suunto D5 bluetooth device name contains the serial number. Thus we
need to match only the prefix, instead of the full name.
2019-09-11 08:51:05 +02:00
Jef Driesen
ffeb6b2447 Update the Shearwater Nerd bluetooth names
Add the Shearwater Nerd 2 bluetooth device name.

The change to uppercase is purely cosmetic. The string comparisions are
not case-sensitive. But for documentation purposes it's good practice to
list the exact name as reported by the device.
2019-09-11 08:51:00 +02:00