1648 Commits

Author SHA1 Message Date
Jef Driesen
c26755624d Fix the id string offset
Since commit 344bfab229a17c7227b9bec02f616505a8d9e998 only a subset of
the id string is used to detect the model. But because the offset was
never updated, the model detection always fails now.
2017-07-05 09:15:05 +02:00
Jef Driesen
7ce057d2ba Fix the progress events
I accidentally passed the address of the progress pointer to the
device_event_emit() function, instead of the pointer itself. Oops.
2017-07-04 14:58:52 +02:00
Linus Torvalds
0143be5497 Fix incorrect placement of -lz (zlib) in autotools build
When I added support for the new Suunto EON Steel bluetooth download, I
needed crc32(), and instead of cooking my own (libdivecomputer does do
its own versions of the simpler crc functions), I made libdivecomputer
just depend on zlib instead, which provides a convenient crc32() function.

But I didn't add the new linker flag (-lz) in the right place in the
automake.  It worked fine for me on Linux, but apparently not so well on
macos.

This fixes it.

Reported-and-tested-by: Benjamin <nystire@gmail.com>
Tested-by: Axel Richter <Axel.Richter@freenet.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-28 13:04:24 -07:00
Jef Driesen
cdcfef6c1a Merge branch 'g2' 2017-06-28 15:33:57 +02:00
Jef Driesen
3a05e0ecf0 Use the trimix data format 2017-06-28 15:32:39 +02:00
Jef Driesen
0a5623a949 Use the correct model number
The model number reported by the Scubapro G2 is 0x32.
2017-06-28 15:32:39 +02:00
Jef Driesen
7ee210f83f Enable more fine grained progress events
At the moment, the progress reporting will jump straight from about 0%
at the start of the download to 100% at the end of the download, without
any updates in between. This is improved by updating after every packet.
2017-06-28 15:32:39 +02:00
Jef Driesen
06259fed19 Abort with an error if the buffer is too small
Silently truncating the data packet if the buffer is too small will
result in a corrupt data stream.
2017-06-28 15:32:39 +02:00
Jef Driesen
eae071c97d Use the standard libdivecomputer error codes
The error code returned by the dc_usbhid_read() function should be
returned as-is, instead of being replaced with some generic error, which
gets translated again to DC_STATUS_IO in the caller.
2017-06-28 15:32:39 +02:00
Linus Torvalds
fcfee82cc8 Scubapro G2: add missed command packet logging
I did the packet logging for the received data side, but forgot to do
the same thing on the command transfer side, which makes the debug logs
a bit less useful.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-28 15:32:39 +02:00
Linus Torvalds
8c0ab03706 Scubapro G2: add back the initial handshake code
When doing the G2 downloader, I dropped the initial handshake as I tried
to keep the code minimal, and the handshake didn't seem to make any
difference what-so-ever to me.

And it probably doesn't matter for anybody else either.  But the code
isn't working for some people, and maybe it does actually matter.

More importantly, Scubapro's own LogTRAK application does send those two
initial commands, and it's probably a good idea to minimize the
differences between the different downloaders anyway, so add the
handshake sequence back in.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-28 15:32:39 +02:00
Linus Torvalds
4ef57b24bb Scubapro G2: clean up unused field
Jef Driesen correctly points out that the 'address' field is just
leftover from the IrDA code, and is meaningless for the USB HID
transport version of the Scubapro G2.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-28 15:32:39 +02:00
Linus Torvalds
f107d7c0d8 Add initial Scubapro G2 frontend
The back-end parser seems to be the same as for the Uwatec Smart (aka
Galileo Sol).  At least that's the assumption right now.

The downloader just uses USB HID (very similar to EON Steel) rather than
the horrible IrDA thing.

There's also eventually a BLE thing, but that's for the future.

This is an unholy mixture of the Uwatec Smart downloader logic and the
EON Steel usbhid transfer code.  The back-end is pure Uwatec Smart
(model 0x11, same as Galileo Sol).

I'm not at all sure this gets everything right, but it downloads
*something*.

[Jef Driesen: Renamed the backend to uwatec, and made some smaller
              cosmetic changes to match the existing coding style.]

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-28 15:32:39 +02:00
Linus Torvalds
208807180a Update the operations in 'custom_io' to consistent calling conventions
The serial ops used a legacy calling convention that passed in just the
pointer to the userdata pointer (ie the first argument to the functions
was "void **userdata").

That's actually very inconvenient, because the custom IO data can not
only contain other interesting information that was filled in by the
custom IO provider, it also made it harder to chain these things
together, as exemplified by the core to emulate serial over the packet
interface in the subsurface bluetooth code.

This also adds the 'dc_context_t' field that is passed to the packet
routine open.  That can allow the open routine to override the
'custom_io' details of the context at open time (to allow nested
custom_io operation).

Note that callers of the open function need to be aware that the
'custom_io' can be changed by the act of opening a custom_io, and the
value shouldn't be cached in some local variable.

Finally, this adds a new user-supplied opaque pointer

	dc_user_device_t *user_device;

to the custom_io descriptor.

The 'user_device' data is filled in when registering the custom_io with
data that the custom IO open() routines can use.  This is different from
the existing 'userdata' in that the 'user_device' is filled in before
dc_open_device() is called (and "open" can then use it to limit what
kinds of devices it looks for, for example).

In contrast, the existing 'userdata' field is filled in by the
"xyz_open()" routines, and contains the data necessary for the IO
itself.

The SSRF_CUSTOM_IO define is updated to v2 to indicate the new
interfaces.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-27 13:38:45 -07:00
Linus Torvalds
3aa40c6135 Merge branch 'BLE-downloaders' into Subsurface-branch
This merges the Suunto EON Steel and Scubapro G2 BLE downloading updates
into the main Subsurface branch.

The basic infrastructure had been done earlier, this is just the tweaks
to actually take advantage of the BLE GATT back-end in Subsurface for
those two dive computers.

The actual subsurface code that exposes BLE GATT interfaces has not been
made public yet, it's too ugly, and will probably make small children go
blind.  But I'll try to clean it up a bit and get it out for wider
testing asap.

* BLE-downloaders:
  Scubapro G2: update for BLE downloading
  Complete the EON Steel HDLC encoding/decoding work
  Teach the EON Steel about HDLC encoding of the command packets
2017-06-24 15:14:08 -07:00
Linus Torvalds
accc63df11 Scubapro G2: update for BLE downloading
The code actually almost worked as-is, but for a tiny detail: the USBHID
packet reception code always receives a full 64-byte packet, while BLE
GATT will return how much it actually received.

The other difference is that USB HID is so fast that it didn't make any
difference where the progress was updated, it took about a second to
download everything.

BLE GATT is not fast to begin with, and the G2 may be particularly slow.

So with the BLE backend, you really do want progress updates for each
packet received, because the dump is going to take a while...

But with the trivial packet verification change, and with the progress
report updates, everything "JustWorks(tm)" over BLE.

Of course, I haven't committed the actual Subsurface BLE transfer parts
yet, because they are some incredibly ugly stuff with fragile bits and
pieces.  But the fact that I can now download from two different dive
computers does mean that I think it's getting to the point where I will
just submit even my ugly code to Dirk.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-24 15:01:56 -07:00
Linus Torvalds
ca115b97e2 Complete the EON Steel HDLC encoding/decoding work
The previous patch did the HDLC encoding on packet send, this does the
HDLC decoding on the receive side.

In order to properly check the data integrity, the HDLC-encoded packet
needs to be fully received before it can be processed.  So while the HID
downloading continues to work packet-by-packet, the HDLC encoded BLE
GATT stream needs a temporary buffer for the data that gets filled as we
ask for the reply header.

Right now only the old USB HID path is actually tested, because I
haven't flushed out the packet receiving side in subsurface yet.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-23 16:41:22 -07:00
Linus Torvalds
c863db02f0 Teach the EON Steel about HDLC encoding of the command packets
The BLE GATT transport ends up using HDLC for the stream encoding,
unlike the USB HID side.  The EON Steel BLE GATT protocol actually does
that for both the commands and for the replies, but this converts only
the command side, because that's the simpler one.

The reply side code will need to be re-architected a bit, because right
now it is very much oriented towards beign able to do everything one
single packet at a time (which is true for USB HID) rather than treating
the packets as a stream of data (as is necessary for the CRC32
verification and to handle the escaping of the 0x7e/0x7d bytes in the
stream).

So with this change, you can't actually do a download over BLE, but I
was able to verify that the first command transfers correctly, and the
EON Steel replies to it over Bluetooth LE GATT.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-22 21:44:28 -07:00
Dirk Hohndel
70526a47eb Bump our private version
Given that this is a fairly significant change, this seems
justified.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-22 18:48:14 -07:00
Linus Torvalds
b7699b6985 Convert Suunto EON Steel and Scubapro G2 to dc_usbhid_custom_io helper
This means that they still default to their respective USB devices, but
you can now set custom IO structure to pass in your own data.

Not only will we hopefully have some kind of BLE support, you could also
use this to simply emulate packets from a log-file by having a packet
replay (or by actually emulating a device).  Of course, you can already
do this by actually emulating the device in a virtual environment, but
it might be useful for some kind of libdivecomputer testing environment.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-18 16:28:59 +09:00
Linus Torvalds
e590739260 usbhid: add helper function to create a usbhid 'custom_io_t'
Basically, this alows us to hide the usbhid code behind the custom_io
abstraction, so that a dive computer could either be given a supplied
custom_io structure, of if none is given, would create one for a USBHID
device.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-18 16:28:35 +09:00
Linus Torvalds
60efc308d2 Rename 'custom_serial' as 'custom_io' across the board
The custom IO handlers will be extended to not just do serial line
emulation (generally over Bluetooth rfcomm), but do BLE too.

BLE does not look like a serial protocol at all, it's packet-based, and
we may have to add specific routines to indicate which GATT endpoints to
use etc.  But like the traditional custom serial code, we want to do the
actual IO not from within libdivecomputer, but from the user of the
library (because the BLE support will require things like the Qt
Connectivity layer - and we do not want libdivecomputer to have to link
against something like Qt).

So this renames 'custom_serial' to 'custom_io', and instead names the
individual member function pointers 'serial_*' to make it clear that
those members are for serial communication.

It also adds new placeholders for packet_open/close/read/write.  Note
that while these may look similar to the serial counter-parts, they are
not the same or even necessarily mutually exclusive.  It is possible the
the caller fills in one or the other (or both), and they would be used
independently.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-18 16:28:24 +09:00
Jef Driesen
434e765128 Merge branch 'ix3m' 2017-06-16 09:00:26 +02:00
Jef Driesen
24621ed519 Improve the handling of unreadable dives
Dives that are reported by the dive computer as unreadable (for example
due to a power loss during the dive) are now skipped instead of being
reported as a fatal error. Those dives can't be retrieved, so there is
no good reason to abort the download.
2017-06-16 08:57:02 +02:00
Jef Driesen
3b967f9eb1 Improve the handling of devices without any dives
Don't return an error if the dive computer reports there are no dives
available!
2017-06-16 08:57:00 +02:00
Jef Driesen
5178c0f755 Add extra NAK error codes 2017-06-16 08:56:02 +02:00
Jef Driesen
35d1e6ff14 Propagate the error code to the caller 2017-06-16 08:09:32 +02:00
Linus Torvalds
e9754bac64 Scubapro G2: make the backend_table_t contain the right values for the G2
Not that anybody should ever use that old-style family/model thing
anyway, so I considered just removing the g2 entry instead.  But dctool
still uses this deprecated interfsce to pick a dive computer.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-15 18:22:50 +09:00
Linus Torvalds
323a606688 Scubapro G2: add missed command packet logging
I did the packet logging for the received data side, but forgot to do
the same thing on the command transfer side, which makes the debug logs
a bit less useful.

Of course, it turns out that a bug in subsurface means that the logging
never gets enabled anyway even when you ask for it, so right now this
particular misfeature didn't matter.  I'm hoping Tomaz/Dirk can fix the
UI widget problem.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-15 07:01:51 +09:00
Linus Torvalds
bae506397e Scubapro G2: add back the initial handshake code
When doing the G2 downloader, I dropped the initial handshake as I tried
to keep the code minimal, and the handshake didn't seem to make any
difference what-so-ever to me.

And it probably doesn't matter for anybody else either.  But the code
isn't working for some people, and maybe it does actually matter.

More importantly, Scubapro's own LogTRAK application does send those two
initial commands, and it's probably a good idea to minimize the
differences between the different downloaders anyway, so add the
handshake sequence back in.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-15 06:36:57 +09:00
Linus Torvalds
7f21c27b7a Scubapro G2: clean up unused field
Jef Driesen correctly points out that the 'address' field is just
leftover from the IrDA code, and is meaningless for the USB HID
transport version of the Scubapro G2.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-15 06:27:21 +09:00
Jef Driesen
31c68ba338 Automatically re-transmit corrupt data packets
Originally packets are only retried when a valid NAK packet with the
busy error code is received. The retrying is now enabled for other types
of errors also, such as data packets with checksum errors.
2017-06-14 16:36:40 +02:00
Linus Torvalds
df9984e123 Add initial Scubapro G2 frontend
The back-end parser seems to be the same as for the Uwatec Smart (aka
Galileo Sol).  At least that's the assumption right now.

The downloader just uses USB HID (very similar to EON Steel) rather than
the horrible IrDA thing.

There's also eventually a BLE thing, but that's for the future.

This is an unholy mixture of the Uwatec Smart downloader logic and the
EON Steel usbhid transfer code.  The back-end is pure Uwatec Smart
(model 0x11, same as Galileo Sol).

I'm not at all sure this gets everything right, but it downloads
*something*.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-08 22:16:14 -07:00
Jef Driesen
37392a03f2 Add a separate transport type for USB HID 2017-06-02 12:11:39 +02:00
Jef Driesen
58eebf4ece Add a bluetooth transport type 2017-06-02 12:11:39 +02:00
Jef Driesen
3c7bd525bb Add support for native bluetooth communication
For the time being, the bluetooth communication code is of very limited
use. It's not used anywhere in the library, and as an internal api it's
also not available to applications. It serves mainly as a reference
implementation for future use.

The implementation supports Windows and Linux.
2017-06-02 12:11:39 +02:00
Jef Driesen
404cea7417 Move the dummy IrDA implementation
The dummy IrDA implementation is integrated in the main file. The
appropriate implementation is selected using conditional compilation
based on the features detect by the autotools build system.
2017-06-02 12:11:39 +02:00
Kristaps Dzonsons
0b22a2ba33 Fix the Oceanic OCS freedive mode 2017-06-02 11:24:00 +02:00
Jef Driesen
4545730776 Report the average ppO2 in external O2 sensor mode only
Just like the ppO2 values from the O2 sensors, the average ppO2 should
be reported in external O2 sensor mode only.
2017-05-27 22:33:22 +02:00
John Van Ostrand
344bfab229 Altered model detection after seeing some bytes change after a firmware update. 2017-05-27 21:37:15 +02:00
Linus Torvalds
a0c5b5b53b Merge git://git.libdivecomputer.org/libdivecomputer into Subsurface-branch
Merge upstream libdivecomputer changes as requested by Jan Mulder.
 "DiveSystem iX3M:
   - Add support for new iX3M models
   - Add support for new iX3M APOS4 firmware
   - Add iX3M firmware version to the devinfo event (ix3m)

  Shearwater:
   - Report the ppO2 in external O2 sensor mode only (Shearwater)
   - Replace the constant offset with a scaling factor (Shearwater)
   - Apply the calibration correction only for the Predator
   - Report individual sensor values
   - Predator: don't report PPO2 unless in CC mode

  Misc:
   - Fix Sherwood Wisdom 3 memory layout
   - Implement read and write functions for OSTC3
   - Add support for Mares Quad
   - Fix uwatec handshaking error handling"

* 'master' of git://git.libdivecomputer.org/libdivecomputer:
  Add support for the new models
  Add support for the new iX3M APOS4 firmware
  Add the firmware version to the devinfo event
  Report the ppO2 in external O2 sensor mode only
  Replace the constant offset with a scaling factor
  Apply the calibration correction only for the Predator
  shearwater: Report individual sensor values
  Predator: don't report PPO2 unless in CC mode
  Fix the Sherwood Wisdom 3 memory layout
  Implement the read and write functions for the OSTC3
  Don't ignore handshaking errors
  Add support for the Mares Quad
2017-05-25 10:26:49 -07:00
Jef Driesen
e2d623fc65 Merge branch 'ix3m' 2017-05-24 07:18:19 +02:00
Jef Driesen
28947876a2 Add support for the new models 2017-05-24 07:18:02 +02:00
Jef Driesen
55b9307e19 Add support for the new iX3M APOS4 firmware
The new APOS4 firmware changed the data format and communication
protocol. The size of the samples changed from 54 to 64 bytes, and in
order to speedup the download, a single data packet contains 3 samples
at once. If the number of samples is not an exact multiple of three, the
last packet appears to contain garbage data.

For parsing, the firmware version is available in the dive header.
Unfortunately it can't be used for dives that are downloaded from a
device with the new firmware, but which have been recorded with an older
firmware. Such dives store the old firmware version in the dive header,
but they also use the new sample format. As a workaround, we inspect the
size of the dive.
2017-05-24 07:18:02 +02:00
Jef Driesen
2854453f26 Add the firmware version to the devinfo event 2017-05-23 09:16:52 +02:00
Jef Driesen
a66da4a45e Merge branch 'shearwater' 2017-05-11 18:21:58 +02:00
Jef Driesen
d6806ab494 Report the ppO2 in external O2 sensor mode only
The O2 sensor millivolt values are only valid if external O2 sensor
monitoring is enabled.

Note that the interpretation of the PPO2 status bit appears to be
reversed (0=external and 1=internal).

Reviewed-by: Anton Lundin <glance@acc.umu.se>
2017-05-11 16:18:43 +02:00
Jef Driesen
7e7cbd55b1 Replace the constant offset with a scaling factor
Correcting the Predator calibration value with a scaling factor produces
even more reasonable ppO2 values compared to using a constant offset.
The scaling factor of 2.2 is based on a linear regression between the
average ppO2 reported by the dive computer, and the average ppO2
calculated over all (calibrated) sensors using the raw calibration
value.

Reviewed-by: Anton Lundin <glance@acc.umu.se>
2017-05-11 16:18:36 +02:00
Jef Driesen
fe2d128b44 Apply the calibration correction only for the Predator
The calibration values for the Petrel are typically in the range 1600 to
2400, while for Predator they are much smaller, with values in the range
800 to 1400. The consequence is that the calculated ppO2 values are too
low for the Predator. Adding a constant offset of about 1000 changes the
calibration value to be in approximately the same range as the Petrel,
and hence more reasonable ppO2 values. But this correction should only
be applied for the Predator, and not the Petrel.

Reviewed-by: Anton Lundin <glance@acc.umu.se>
2017-05-11 16:18:23 +02:00
Anton Lundin
d3ca3e87bd shearwater: Report individual sensor values
This reads the reported mV values from the sensors, and based on the
calibration values converts it into a ppo2 value to report.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2017-05-11 07:58:03 +02:00