Compare commits

...

168 Commits

Author SHA1 Message Date
Dirk Hohndel
8ae735a4d7 Merge branch 'ignore-build' of https://github.com/janmulder/libdc into Subsurface-branch 2017-12-12 16:09:51 -08:00
Linus Torvalds
a1472a7247 Merge branch 'Subsurface-branch' of github.com:Subsurface-divelog/libdc into Subsurface-branch
Merge with Dirk's cleanups.

I had intentionally not updated my tree while I was pondering the
upstream merge with Jef's iostream changes, so I didn't have Dirk's
cleanups in my tree when I did that big merge.

This merge was trivial in comparison.

* 'Subsurface-branch' of github.com:Subsurface-divelog/libdc:
  Correctly determine git SHA if libdivecomputer is a git submodule
  Disable a couple of overly aggressive warnings
  Add configure flag to explicitly enable BLE support
2017-12-12 14:02:53 -08:00
Linus Torvalds
8a34d822ff Merge remote-tracking branch 'jef/master' into Subsurface-branch
Rough merge of upstream libdivecomputer.

This is mainly about making the new iostream code upstream, although we
don't actually use it.

It abstracts out the the old serial and usbhid code, but we end up still
using our own 'custom_io' interface because the iostream code doesn't do
it right.

* jef/master:
  Correctly determine git SHA if libdivecomputer is a git submodule
  Don't accept a NULL pointer as parameter
  Add support for semi-closed circuit diving
  Detect dives with invalid profile data
  Implement the serial communication functions as no-ops
  Move the socket code to a common file
  Add support for a custom I/O implementation
  Port the USB HID code to the new I/O interface
  Port the bluetooth code to the new I/O interface
  Port the IrDA code to the new I/O interface
  Port the serial code to the new I/O interface
  Add a new abstract I/O interface
  Post release version bump to 0.7.0
2017-12-12 13:59:29 -08:00
Dirk Hohndel
db70c581a6 Correctly determine git SHA if libdivecomputer is a git submodule
In the case of a submodule, the .git file is a text file pointing to the
correct module in the parent's .git folder. The git rev-parse works
correctly in both cases.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-06 21:23:22 -06:00
Dirk Hohndel
f5aee8198f Disable a couple of overly aggressive warnings
-Wextra and -Wpedantic are creating more noise than useful warnings.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-04 13:53:40 -08:00
Dirk Hohndel
506bcec3cd Add configure flag to explicitly enable BLE support
This way BLE dive computers that are otherwise conditional on USBHID will be
built on platforms that support them but don't have USBHID (like iOS).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-04 13:42:25 -08:00
Linus Torvalds
77f87bebe3 EON Steel: remove a few unused variables
Most of the new warnings due to compiler flags are just unnecessary
noise, but let's clean up at least the obvious and unquestionably valid
ones.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-12-04 10:43:20 -08:00
Linus Torvalds
54f6bff929 Merge tag 'v0.6.0' of git://git.libdivecomputer.org/libdivecomputer into Subsurface-branch
Sync up with upstream cersion 0.6.0.

Annoying merge, mainly because a lof of the changes Jef had done are
actually changes that came from our Subsurface branch, but in a
different form, because Jef doesn't actually take patches directly from
us.

Why? I don't know.

* tag 'v0.6.0' of git://git.libdivecomputer.org/libdivecomputer:
  Release version 0.6.0
  Fix some potential buffer overflows
  Fix some casts with constant pointers
  Enable some useful compiler warnings by default
  Generate html documentation from the manpages
  Fix the decoding of the ndl/deco information
  Decode the firmware version for the iDive series
  Add support for the Suunto Eon Core
  Locate the most recent dive
  Add EON Steel time sync capability
  Improve the progress events
  Detect the model number using the hardware type
  Shearwater: add support for remaining gas time
  Shearwater: extract tank sensor data for log version 7
  Shearwater: extract log version from header
2017-12-04 10:18:23 -08:00
Jan Mulder
8c443c5abc build: ignore the build from git
Now as a submodule, the change in libdivecomputer created by the
build process is annoying. Just ignore it.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-04 02:12:13 +01:00
Linus Torvalds
238a3734a5 Add support for new Suunto EON Core dive computer
Nick Shore reports that it seems to act exactly like an EON Steel, just
with a different USB device ID.

Acting like the EON Steel is not a surprise: it does seem to be the same
dive computer, just in a smaller and lighter package (same screen size,
but more compact body and without the stainless steel to make it less
than half the weight).  Looks like the battery is smaller, but the
electronics are likely the same.

We probably really should have some way to add new device ID's without
having to add whole new model numbers etc.  It's not the first time this
happens (see the Scubapro Aladin Square vs the G2), and it's likely not
the last time.

Reported-by: Nick Shore <support@mac-dive.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-11-19 15:36:39 -10:00
Linus Torvalds
c44d2a8faf Merge remote-tracking branch 'jef/master' into Subsurface-branch
Sync with the upstream version of the Aladin Square.

This picks the same model name that Jef picked in uwatec_smart_parser.c.

* jef/master:
  Add support for the Scubapro Aladin Square
2017-11-16 15:37:28 -08:00
Linus Torvalds
a2f358f0b5 Add support for Scubapro Aladin Square
It works like the G2, but has a different model number, and different USB device ID.

Lots-of-testing-by: Vincent <vavincavent@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-11-16 15:24:28 -08:00
Linus Torvalds
9d7335dc6d Merge git://git.libdivecomputer.org/libdivecomputer into Subsurface-branch
Merge with Jef's upstream libdivecomputer:

 - some OSTC parsing fixes, including getting the initial CNS into the
   first sample

 - syntactic cleanups to the Scubapro Aladin Sport Matrix support to
   match upstream

* git://git.libdivecomputer.org/libdivecomputer:
  OSTC: initialize initial CNS from header
  Use an out-of-range value as undefined
  Support for the Scubapro Aladin Sport Matrix.
2017-11-15 08:51:54 -08:00
Linus Torvalds
4dce920c79 Scubapro G2 usb: always use exactly 32-byte packets (plus report byte)
It turns out that the Scubapro G2 itself does not care at all, but
apparently some of the other dive computers that use the same protocol
do).

In particular, Vincent reports that his Scubapro Aladin Square downloads
ok with the USB ID's switched to c251:2006, but only if we send 32-byte
USB HID payload packets, even though the command itself is much smaller.
Otherwise it will simply not reply at all.

To actually download correctly, we'll still need to do some model-
specific USB ID updates, and there will be some model changes for the
Aladin Square, but this at least fixes the transport side.

Jef had actually already done this because of the Windows behavior side,
I just hadn't thought it could possibly matter. Mea Culpa.

Reported-and-tested-by: Vincent <vavincavent@gmail.com>
Cc: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Cc: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-11-15 08:42:35 -08:00
Linus Torvalds
7de3a549ee EON Steel: explicitly sort the dive directory listing
The code relied on the dives being ordered by date in the directory
listing, which is normally true.  But once the dive computer fills up
(after 400 dives or so), it starts re-using entries in the dive list,
and the dive directory is no longer ordered by date.

This matters because we want to download the latest dives first, since
subsurface will generally stop downloading once it finds an existing
dive.

NOTE! If you screw up the date on the dive computer, the old behavior
was possibly more to your liking, since - as long as the dive list
hadn't filled up - it wouldn't really order by date, but by dive
creation.

However, I don't see any way to get that information once the dive list
has filled up, so "order by dive date" is as good as it gets.

If you do screw up dates, and you want to download new dives that are
"older" than the dives you already have, you will need to basically set
the "download all dives" flag, and then select the new dives manually.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-11-03 10:58:10 -07:00
Berthold Stoeger
06c34fc8b0 Fix model number of the Scubapro Aladin Sport Matrix.
The model number was wrong. Mea culpa.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-11-01 08:28:08 -07:00
Linus Torvalds
e177b28627 Merge git://git.libdivecomputer.org/libdivecomputer into Subsurface-branch
Pull Uwatec date handling fix from Jef Driesen.

This merges with upstream libdivecomputer, where Jef fixed the overly
complicated and fragile date parsing of the Uwatec smart backend.

It used to try to guess the base epoch of the dive computer by comparing
current time on the dive computer with the current time on the
downloader, but if the time and date of either was wrong (and the date
on dive computers often is) that would get the wrong answer.

* git://git.libdivecomputer.org/libdivecomputer:
  Replace the clock calibration with a fixed epoch
2017-10-29 07:16:25 -07:00
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
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
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
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
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
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
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
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
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
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
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
Jan Mulder
9df029a704 OSTC3: add battery percentage
From firmware version 2.15, the battery percentage is shown on the
unit (in the logbook that is, it was shown on the display for a very
long time). The used byte in the OSTC3 seems to be populated since
firmware version 2.10. The new percentage data is added to the
"battery at end" voltage data, and a V is added to denote the unit
of the voltage.

In addition, reordered the DC_FIELD_STRINGs a little, so that the
serial is on top.

Further, changed BUFLEN to 32 (as in 84eb59c) due the the length
of the new battery notation.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-04-30 22:10:35 +02:00
Linus Torvalds
29135bcdf8 Merge git://git.libdivecomputer.org/libdivecomputer into Subsurface-branch
Merge upstream libdivecomputer changes from Jef Driesen.

The most noticeable part is Jen Mulder's OSTC3 initial setpoint
addition, which fixes the OSTC3 data in CCR3 mode.

But also various cleanups and fixups from Jef.

* 'master' of git://git.libdivecomputer.org/libdivecomputer:
  OSTC3: set initial setpoint in profile data
  Remove unused parameters
  Cleanup the extract dives functions
  Remove unnecessary helper functions
  Remove deprecated functions from the public api
  Remove unnecessary include statements
  Fix the firmware version and serial number
  Add support for the Uwatec Aladin Tec 3G
2017-04-29 16:37:40 -07:00
Linus Torvalds
b04f393b97 Merge git://git.libdivecomputer.org/libdivecomputer into Subsurface-branch
Merge upstream libdivecomputer changes from Jef Driesen.

No major changes and no conflicts except for a trivial one where Jef had
marked a couple of private functions 'static' and our versions had
extended the argument lists of those functions.

This just updates to the current upstream state of libdivecomputer,
where the bulk of the changes come mainly from the new ringbuffer helper
code, but there are various other small misc fixes and cleanups.

* git://git.libdivecomputer.org/libdivecomputer:
  Disable the deco events
  Replace the deco events with a deco sample
  Report errors from the close function
  Mark the private function as static
  Fix a bug in the tank pressure samples
  Disable freedive mode for the Uwatec Aladin Tec 2G
  Mark the private function as static
  Fix some compiler warnings
  Fix some more null pointer dereferences
  Use a more efficient download algorithm
  Use the new ringbuffer stream
  Add a common ringbuffer reading algorithm
  Improve the robustness of the IrDA I/O code
  Fix a few null pointer dereferences
  Fix the number of gas mixes
  Always use the sample timestamp as the base value
2017-04-12 08:24:04 -07:00
Jan Mulder
84eb59c3ce Prevent buffer overrun
When compiled with older Microsoft libraries, the unsafe implemention of
snprintf results in non-null terminated strings, causing numerous subsequent
issues. This fix just enlarges the used buffer to accommdate longer strings.
A more complete solution would include the use more recent Microsoft libraries in
the build process. The larger buffer is still need then, to prevent trucated
(but proper null terminated) strings.

ref: https://github.com/Subsurface-divelog/subsurface/issues/301

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-04-12 12:45:17 +02:00
Dirk Hohndel
ca04147126 Merge pull request #2 from torvalds/upstream-from-jef
Pull upstream updates from jef
2017-02-01 21:49:21 -08:00
Linus Torvalds
71cf0a5c69 Merge branch 'master' of git://git.libdivecomputer.org/libdivecomputer into sync-with-upstream
Merge upstream libdivecomputer changes from Jef Driesen.

The most notable one is how libdivecomputer no longer sends the
GASCHANGE events, but uses DC_SAMPLE_GASMIX instead.

We still turn it into a SAMPLE_EVENT_GASCHANGE2 event internally in
subsurface, since we want all the normal event handling to trigger.

* 'master' of git://git.libdivecomputer.org/libdivecomputer: (21 commits)
  Document the date/time functions
  Document the public api with man pages
  Add support for the Cressi Drake
  Detect overwritten dive profiles
  Ignore tank pressure if no sensor is attached
  Add support for the tank field
  Add support for the salinity field
  Use the sample interval from the settings
  Update the Aqualung i750TC parser
  Toggle the DTR line during setup
  Implement the read function
  Add doxygen documentation to the build system
  Add support for the Aqualung i750TC
  Fix the Windows version resource build
  Force the dive mode to gauge
  Add support for the dive mode
  Report the initial gas mix on the first sample
  Remove the deprecated gas change events
  Add support for the Hollis DG02.
  Add support for the Oceanic F10.
  ...
2017-01-16 16:01:10 -08:00
Anton Lundin
3f74840f4c Fix bug in ostc deco info string parsing
The code was just if instead of else if by accident.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-01-08 14:16:17 -08:00
Anton Lundin
2e650b68ae Teach ostc deco model info strings about OSTC4 VPM
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-01-08 13:49:06 -08:00
Anton Lundin
6fccf5923f Correct shearwater Deco model info string
The literal % where in the wrong place.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-01-08 13:49:06 -08:00
Anton Lundin
a6421b2f7b Correct firmware string for OSTC4
OSTC4 stores firmware in another format than OSTC3's.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-01-08 11:54:49 -08:00
Anton Lundin
19b560d9b2 Fix logging of Custom Write
This way we actually trace print the written buffer, even if the caller
doesn't care about how much data he/she actually wrote.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-01-08 11:54:49 -08:00
Linus Torvalds
534dd2f34b Merge tag 'v0.5.0' of git://git.libdivecomputer.org/libdivecomputer into Subsurface-branch
Merge upstream version 0.5.0.

Some small updates from Jef Driesen since the last sync, but let's sync
with the real 0.5.0 release.

* tag 'v0.5.0' of git://git.libdivecomputer.org/libdivecomputer:
  Release version 0.5.0.
  Include the public header in the implementation file.
  Add explicit casts for the msvc C++ compiler.
  Add some workarounds for the msvc compiler.
  Update the msvc project file.
  Add missing header files to the Makefiles.
  Add support for the Subgear XP-Air
2016-09-30 14:10:59 -07:00
Linus Torvalds
4ec7283841 Merge branch 'master' of git://git.libdivecomputer.org/libdivecomputer into Subsurface-branch
Merge with Jef Driesen's upstream.

Jef has updated his branch with about half of the EON Steel fixes, but
still refuses to admit that the string model is much superior to his
crazy "random numbers that can't actually describe anything properly"
model, and left out all those parts.

But Jef also made a generic HID layer thing that cleans things up (but
causes a spurious warning about a failed usb hid read due to the "clean
out old data" code that *expects& the failure), and fixed his version of
the HW Frog firmware, so this cleans up that issue.

We also now have that gas mix parsing fix for the Aladin Tec 2G properly
merged, so that our cherry-pick won't cause merge issues later.

* 'master' of git://git.libdivecomputer.org/libdivecomputer:
  Fix the firmware version for the HW Frog.
  Use the new USB HID backend for the Eon Steel.
  Add a dummy backend for systems without USB HID support.
  Use the hidapi library on Mac OS X.
  Add a new USB HID communication backend.
  Add a configure option to build without libusb.
  Restore the sample events.
  Suunto EON Steel: initialize the tank 'gasmix' index
  Suunto EON Steel: do the proper enum lookup for a few more cases
  Suunto EON Steel: fix the event begin/end flag
  Suunto EON Steel: split out gas info parsing
  EON Steel: look up enum descriptor strings
  EON Steel: pass in the type descriptor to samples that need it
  EON Steel: mark tank cache initialized when filling it in
  EON Steel: fix uninitialized field cache entries
  Initial Suunto EON Steel CCR support
  Suunto EON Steel: add descriptor debugging output
  Add tank size reporting for Suunto EON Steel
  Fix the gas mix parsing for the Aladin Tec 2G.
2016-09-19 10:41:42 -07:00
Dirk Hohndel
11fec04865 fix compile error
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-18 08:27:24 -07:00
Gaetan Bisson
af84bd10fd export new symbol, needed by subsurface
Signed-off-by: Gaetan Bisson <bisson@archlinux.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-18 07:31:37 -07:00
Jef Driesen
a568c756a1 Fix the gas mix parsing for the Aladin Tec 2G.
Unlike the other models, the Aladin Tec 2G uses only a single byte to
store the oxygen percentage, and there is no need to manually re-map the
deco mix.

Normally, the oxygen percentage is stored using two bytes (little endian
byte order). Thus for a device supporting two gas mixes, four bytes will
be used, and the corresponding gas mix id for each byte is as follows:

  ID: 0 0 1 1

After re-mapping the id of the deco mix, this becomes:

  ID: 0 0 2 2

Since oxygen percentages are limited to the range 0-100%, the highest
byte (marked with an X) should always be zero and can thus be ignored:

  ID: 0 X 2 X

Now, because an oxygen percentage of zero indicates a disabled gas mix,
this is equivalent to a device supporting three (or even four) gas
mixes, each stored using only a single byte:

  ID: 0 1 2 3

We can take advantage of this knowledge to avoid having to re-map the
deco mix id.
2016-09-18 07:15:30 -07:00
Anton Lundin
3ea2795bf1 Fix merge error of AQUAI300 memory layout
This removes the additional entry for AQUAI300, as it was done in "Fix
the memory layout for the Aqualung i300." (1e22760f9102ac).

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-18 07:14:23 -07:00
Anton Lundin
89111ebb2a Build example applications by default again
A while back, the example applications where broken in our
Subsurface-branch, and got disabled by default. This re-enables them to
sync better with upstream.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-18 07:14:14 -07:00
Anton Lundin
a6538ae7da Set error status if transfer fails in close
This fixes whats probably was a merge error. This is a resync with
upstream.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-18 07:13:55 -07:00
Anton Lundin
f7d2086675 Don't overwrite status
This removes whats probably a merge error, that overwrites the return
status.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-18 07:13:44 -07:00
Anton Lundin
4c5b51f851 Add blank row to match upstream
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-18 07:13:27 -07:00
Anton Lundin
20d268acdb Remove last traces of our old custom serial code
This is just to make future merges easier.

There were nothing left of Claudiu's code in those files, so thats why i
removed the copyright lines.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-18 07:13:13 -07:00
Anton Lundin
94e7a77d01 Re-implement custom serial in a new way
This re-implements the custom serial concept in a new way. This way
doesn't touch any of the backend code, it just introduces a optional
redirection layer in the existing serial backends.

This implementation supports more serial operations to, so we can
support more backends this way.

Hooking into the existing serial backends might look ugly but its
probably the best way to make sure this patch conflicts as little as
possible with upstream.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-09-17 14:09:37 -07:00
Anton Lundin
7e086f697d Remove the old custom serial code
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-09-17 14:09:37 -07:00
Linus Torvalds
f9db4ca97c Merge git://git.libdivecomputer.org/libdivecomputer into Subsurface-branch
This is a rough merge of the upstream libdivecomputer changes.

I say "rough", because this disables the custom serial code as it
clashes very badly with Jef's new dc_serial_t abstraction.

Anton Lundin has patches on top of this to re-introduce the custom code
in a way that integrates better with the upstream libdivecomputer state.

* git://git.libdivecomputer.org/libdivecomputer: (42 commits)
  Add support for the Sherwood Vision.
  Fix the decoding of the maximum depth.
  Improve the default layout detection.
  Add a warning for unsupported devices.
  Fix the temperature for the Tusa Zen Air.
  Add support for the Aqualung i550T.
  Use the new settings field for the salinity.
  Fix the parsing of freedives.
  Detect the gauge and freedive mode correctly.
  Add the salinity field for the Aladin Tec.
  Add support for the Scubapro Mantis 2.
  Fix the decoding of the dive time.
  Add support for the Scubapro Mantis.
  Fix the Aeris 500AI serial number.
  Add the serial number encoding to the layout.
  Add salinity and timezone fields to Aladin Tec 2G
  Add NDL and RBT for the ATOM31 and I450T
  Add support for the new extended hardware descriptor.
  Update the OSTC device descriptors.
  Add a workaround for an OSTC4 firmware bug.
  ...
2016-09-17 14:08:32 -07:00
Linus Torvalds
ed8b8f1221 Suunto EON Steel: extend our string space
We only used to save 16 extended strings per dive from the EON Steel
download, which is _plenty_: it's not like we actually generate that
many strings.  Firmware version, battery status, transmitter info -
there's just not that many strings.

Oops.

Except if you have lots of transmitters.  Then each wireless transmitter
will have three strings each, for transmitter ID and beginning/ending
battery status.

I only have one, but Andreas Klein has four.  And it took me
embarrassingly long to realize that he really did have them on the
dives, because after the first two transmitter IDs got recorded, the
string space filled up and we silently dropped the rest.

But I have learnt my lesson.  Future generations will talk about how I
said "32 strings will be enough for anybody".

But at least it should be enough for a few more transmitters.  Somebody
should extend this some better way, but I'm still chasing other issues.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-08-29 21:45:33 -07:00
Linus Torvalds
6fa9f1566f Suunto EON Steel: initialize the tank 'gasmix' index
The gasmix query interface considers cylinders and gas mixes independent
things, so the tank data structure has a pointer to the gasmix index.

But the EON Steel treats cylinders as just having a gasmix (and so does
subsurface, for that matter), so the gasmix index for the tank is just
the same as the tank index.

But we never filled it in, so you'd always see a "gas index" of zero,
and subsurface would end up warning each time about how the gasmix index
doesn't match the cylinder index (but because subsurface actually agreed
with EON Steel, it worked despite the warning).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-08-29 21:45:19 -07:00
Linus Torvalds
d11d30999b Suunto EON Steel: do the proper enum lookup for a few more cases
Instead of hardcoding the enum values for setpoint type and gas type,
use "lookup_enum()" to actually parse the enum data and use that.

I don't think this matters right now, since the numeric translations
haven't changed, but it is the RigthThing(tm) to do.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-08-29 21:45:06 -07:00
Anton Lundin
cba786df2f Fix deco model strings in hw parser
The new version of the log book format broke the string handling.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-08-20 08:24:13 -07:00
Anton Lundin
4527c77a6b Add strings as extradata in xml
This teaches the dctool about the subsurface special field strings, and
saves them in the xml output in a way which is compatible with
subsurface.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-08-20 08:24:02 -07:00
Linus Torvalds
406dbf3dae Add severity indication to the event flags for the Suunto EON Steel
This way Subsurface can show different icons depending on what kind of
event we report.

This also fixes a bug where the begin/end marker was mistakenly added as
the value instead of as flag.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-23 17:07:38 +09:00
Linus Torvalds
8fb4018db3 Suunto EON Steel: add transmitter battery state reporting
I'm not sure how reliable it is, and older wireless tank pods had a bug
in the reporting (looks like the battery voltage range calibration was
done incorrectly, and it reports 0% battery for new batteries).

But depending on how well it actually works when the batteries start
getting weak, the transmitter battery reporting is potentially *very*
useful.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-21 19:58:29 +09:00
Linus Torvalds
8eb1c1232e Suunto EON Steel: add surface time reporting
For some reason I hadn't reported surface time.  It's trivial to do
especially now that we have the varargs string adding function.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-21 19:58:29 +09:00
Linus Torvalds
7fe87f36b5 Suunto EON Steel: split out gas info parsing
The dive gas parsing cases can be split out into a helper function to
keep things more manageable.  Especially since there will be a couple
more cases coming up.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-21 19:58:29 +09:00
Linus Torvalds
4599405078 Suunto EON Steel: add 'varargs' version of 'add_string()' function
.. and use it for the cases that used to do this by hand (Personal
Adjustment and Desaturation Time).

There will be more users coming up.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-21 19:58:29 +09:00
Linus Torvalds
69d26e00b0 Suunto EON Steel: add desaturation time reporting
The EON Steel reports it in seconds remaining after the dive.  That's a
bit excessive, but I guess SI units is where it's at.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-21 19:58:29 +09:00
Linus Torvalds
5d4e1f97db Suunto EON Steel: add dive state event reporting
Now that we support string events and don't need to try to figure out
some libdivecomputer event number that doesn't exist, it's easy to add
the proper support for the dive state reporting that the EON Steel has.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-21 19:58:29 +09:00
Linus Torvalds
3547c72111 EON Steel: look up enum descriptor strings
It turns out you can't hardcode the enum numbers either, since they
change from dive to dive (or possibly firmware version to firmware
version).

So do it right, and actually parse the string descriptor for the enum.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-21 19:58:29 +09:00
Linus Torvalds
1b5ccf5983 EON Steel: pass in the type descriptor to samples that need it
The samples that take 'enum' types need the type descriptor to parse
what the enum type means.

This doesn't actually use the data yet, I need to add parsing of the
enum descriptor string.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-21 19:58:29 +09:00
Linus Torvalds
79e2e3b0b5 Add 'string' event type
The event numbers are an indecipherable mess, and Suunto EON Steel has
notifications, events and warnings that just don't fit.  Plus they
really come as strings from the EON Steel anyway.

So add a "SAMPLE_EVENT_STRING" type, and for that type the event has a
"const char *name" instead of the odd and meaningless flags/value pair.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-21 19:58:29 +09:00
Linus Torvalds
2e26ae4708 Make the tank "type" field more useful
Right now it only has an indication of whether the cylinder size is
imperial or metric, which is frankly quite useless.

Turn it into a bitmask instead, where we keep the imperial/metric data
for compatibility, but add another two bits that say that it's a CC
cylinder, and whether it's the oxygen or diluent cylinder.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-21 19:58:29 +09:00
Linus Torvalds
f38e8fe9ee EON Steel: mark tank cache initialized when filling it in
The previous commit fixed the cache initialization testing, and
uncovered the fact that the tank size cache initialization didn't set
the initialized bit correctly.  That oversight had been hidden by the
fact that we then tested the bit wrongly, so not setting it right didn't
use to matter as long as there were other higher cache bits that were
set.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-17 12:07:39 +09:00
Linus Torvalds
0aeae321dc EON Steel: fix uninitialized field cache entries
The check for whether we had initialized a field in the EON Steel cache
data structure was wrong, causing some entries to be returned
successfully even if their field had never been initialized.

In most cases, it didn't matter, since the cache data was initialized to
zero (which is a fine default for uninitialized data), so most of the
time it didn't matter.

But for the recently added dive mode field, this caused OC dives to be
returned as freedives, for example.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-07-16 15:58:57 +09:00
Linus Torvalds
de7ed23bec Initial Suunto EON Steel CCR support
This does the basic divemode and setpoint parsing for the EON Steel, and
gets the CCR download right in the big picture.

The cylinder information is still confusing and incorrect, but this is a
big step in the right direction.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-06-21 13:08:09 -07:00
Linus Torvalds
341b7c2dad Suunto EON Steel: add descriptor debugging output
.. every time I look for a new feature I add debug code to print out all
the descriptors.  So let's just do it once and for all.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-06-21 13:08:03 -07:00
Dirk Hohndel
26b027cad8 Merge branch 'partsOfMaster' into Subsurface-branch 2016-06-12 23:10:48 -07:00
Jef Driesen
5361bc06bd Fix the nitrox gas mix parsing.
Mares Darwin compatible devices support a nitrox mode. The nitrogen
percentage should only be taken into account when the dive mode is set
to nitrox, because the last used value remains in place for air dives.
2016-06-12 23:10:37 -07:00
Jef Driesen
87facc940b Add support for the dive mode field. 2016-06-12 23:10:22 -07:00
Jef Driesen
bdc1c1349e Fix the length of the Vyper Novo gas change event.
Just like the Suunto DX, the Vyper Novo uses 5 bytes for the 0x06 gas
change event.
2016-06-12 23:09:54 -07:00
Jef Driesen
f67bdcd080 Add support for the Aqualung i300. 2016-06-12 23:09:43 -07:00
Dirk Hohndel
2015546952 Merge branch 'master' into Subsurface-branch 2016-04-26 09:35:06 -07:00
Dirk Hohndel
480e54ace7 Fix OSTC3 merge errors
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-19 17:37:25 -07:00
Dirk Hohndel
ecebda3b19 Fix Shearwater breakage caused by bad merging
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-18 05:55:12 -07:00
Miika Turkia
6c6752d87e Add dummy serial number usage to dctool
After adding support for serial number on dc parsers on
libdivecomputer's Subsurface branch, we need to add the serial parameter
to parser calls as well. Just using 0...

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-16 08:32:14 -07:00
Dirk Hohndel
8356e22e61 Merge branch 'master' into Subsurface-branch 2016-04-09 08:29:44 -07:00
Dirk Hohndel
515dc17914 Fix merge error that causes double free when downloading from EON Steel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-03-30 19:51:25 -05:00
Jef Driesen
cb0584adc1 Get the gas mixes from the sample data.
The Shearwater devices support adding, removing or editing gas mixes
during the dive. The pre-defined gas mixes available in the opening and
closing block are only a snapshot of the configuration at the start and
at the end of the dive. Thus by editing the gas mixes during the dive
it's possible to switch to a gas mix that is not present in the opening
(or even the closing block). The parser doesn't support that.

To avoid this problem, we now collect the available gas mixes from the
sample data. As a side effect we only return those gas mixes that are
effectively used during the dive.
2016-03-23 14:47:09 -07:00
Jef Driesen
f37b4b06db Cache the dive mode internally.
This simply moves the code to the get the dive mode from its own
function into the existing caching function.
2016-03-23 14:47:09 -07:00
Jef Driesen
aa2f670224 Add support for the Shearwater Perdix. 2016-03-23 14:47:09 -07:00
John Van Ostrand
af30fbb3f8 Add support for the Cochran Commander and EMC. 2016-03-23 14:47:09 -07:00
Dirk Hohndel
b13d8da426 Don't build examples by default
They are broken in this branch.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-03-23 14:47:09 -07:00
Jef Driesen
7f6348b066 Add support for the Uwatec Aladin Sport.
The Aladin Sport appears to be compatible with the Aladin 2G.
2016-03-23 14:47:09 -07:00
Jef Driesen
95d69ea30d Add support for the Suunto Zoop/Vyper Novo.
The Zoop Novo and Vyper Novo are compatible with respectively the D4i
and D6i.
2016-03-23 14:47:09 -07:00
Jef Driesen
cc12560b29 The new D6i data format support 3 gas mixes. 2016-03-23 14:47:09 -07:00
Jef Driesen
784844d8dd Add support for the new D4i and D6i data format.
One of the newer D4i and D6i firmware versions (for example v1.5.9),
introduces a new variant of the data format. The new dive header is 8
bytes larger. The correct variant can be detected by means of the
logbook id tag at the start of the header.
2016-03-23 14:47:09 -07:00
Jef Driesen
2fc31b72e7 Add support for the HW OSTC 4.
Except for the firmware update and a few other minor differences, the
new OSTC4 is backwards compatible with the OSTC3.
2016-03-23 14:47:08 -07:00
Jef Driesen
2e0db552ad Read and cache the hardware descriptor.
By reading the hardware descriptor immediately after entering download
or service mode, we can identify the specific model and adapt to minor
differences in the communication protocol.
2016-03-23 14:26:45 -07:00
Jef Driesen
6bb60bba31 Pass an array to the checksum function. 2016-03-23 14:25:14 -07:00
Dirk Hohndel
28f8cf6e19 Add configure option to disable checking for libusb and hidapi
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-03-06 10:05:45 -08:00
Dirk Hohndel
55a44a73bb One more merge fix
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-28 06:34:57 +01:00
Dirk Hohndel
7c33c633fb Merge branch 'master' into Subsurface-branch
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-02-27 22:17:36 +01:00
Dirk Hohndel
e227a4c5a7 Merge branch 'master' into Subsurface-branch 2015-12-14 09:33:53 -08:00
Dirk Hohndel
8bb373e514 Merge branch 'master' into Subsurface-branch 2015-12-07 09:48:39 -08:00
Dirk Hohndel
290f2781ea Merge branch 'master' into Subsurface-branch 2015-11-06 22:24:56 -08:00
Dirk Hohndel
4f321aef40 Merge branch 'master' into Subsurface-branch 2015-10-27 19:52:32 +09:00
Robert C. Helling
92a1919cf5 Mention Shearwater Nerd alongside with Petrel 2
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-22 20:33:50 +09:00
Dirk Hohndel
2106cb2dab Add tank size reporting for Suunto EON Steel
Sadly the data we get from the EON Steel is a bit of a mess.
It doesn't really tell us if the data is metric or imperial (it always sends
both wet volume and working pressure). And in imperial mode the Suunto
engineers seem a bit confused. The pressure given (entered on the dive computer
in psi) is sent to us not in bar, not in atm... it's "something". As far as I
can tell it's a constant factor of 1.00069182389937 different from bar.
And the wet sizes are a bit to small to get the cuft size the user entered.
But instead of trying to guess and fix the mess, we just pass it through...

So this is somewhat useful, but not really what most users will want.

Linus started this commit with a few lines that parsed the right values out of
the data stream from the Suunto EON Steel. I then added the implementation of
the infrastructure to convert the raw data and report it back to the caller.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-22 20:29:43 +09:00
Anton Lundin
854f58fa32 Cleanup and correct CCR detection
== has precedence over & and would have needed some parenthesis.

Instead of that, this moves that code into the block below which
already contains a correct CCR check.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-18 16:43:15 -07:00
Dirk Hohndel
058538e628 Use hidapi for Suunto EON Steel on Mac
libusb on Mac doesn't support HID devices.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-18 10:39:55 -07:00
Anton Lundin
138fd856bd Add deco model info strings to shearwater parser
This adds two strings describing the deco model information of the dive.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-14 05:52:53 -07:00
Dirk Hohndel
1ccf937aa3 Merge branch 'master' into Subsurface-branch 2015-10-13 19:23:32 -07:00
Dirk Hohndel
da0073c971 Merge branch 'master' into Subsurface-branch 2015-10-02 06:18:51 -04:00
Claudiu Olteanu
8932b2a936 Fix dc_serial_native_open return check for Shearwater family
The dc_serial_native_open method doesn't return -1 on failures.
The failure errors can be DC_STATUS_INVALIDARGS, DC_STATUS_NOMEMORY,
DC_STATUS_IO.

Therefore we should check if the returned value is equal to
DC_STATUS_SUCCESS and pass it further.

Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-07 07:33:51 -07:00
Dirk Hohndel
9c7d1102d4 Fix compile errors on Mac
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-04 10:43:37 -07:00
Claudiu Olteanu
ad4bcffa23 Use custom set_timeout callback for Shearwater family
Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:48:47 -07:00
Claudiu Olteanu
f103553df1 Use the custom set_timeout callback for HW_OSTC 3 family
Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:48:38 -07:00
Claudiu Olteanu
a6274a3a55 Add set_timeout callback for serial custom implementation
The new callback will be usefull when we will implement the support
for Windows. The implementation of native serial set_timeout method
uses a HANDLER on Windows and we will use the WinSock2 API which has
a socket descriptor.

Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:48:32 -07:00
Gaetan Bisson
adfff2d4a7 Add new functions to list of exported symbols
This is required in order to build those new public functions into the
shared library.

Signed-off-by: Gaetan Bisson <bisson@archlinux.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:48:25 -07:00
Linus Torvalds
f0e695b089 EON Steel: expose the gas switch cylinder in the "flags" field
This seems to be the simplest extension to the SAMPLE_EVENT_GASCHANGE2
format: the "value" remains the oddly encoded gas mix, but the "flags"
value (if non-zero) now contains the actual cylinder number we switch
to.

This will need a trivial patch to subsurface to take advantage of the
new data too.  But then we can actually distinguish between cylinders
that have the same gas mix.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:48:09 -07:00
Linus Torvalds
fe2448e34f Add EON Steel personal adjustment parsing
Suunto calls it "Conservatism" in the dump, but "Personal adjustment" in
at least some of the documentation. That's what we expose it as.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:48:00 -07:00
Linus Torvalds
7fd201a400 Add EON Steel dive mode and transmitter ID information
This adds the divemode name (Nitrox, Trimix, Gauge, or whatever custon
name) and the transmitter ID as extra string information when
downloading from the EON Steel.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:47:54 -07:00
Linus Torvalds
c39dda89bc Suunto EON Steel: populate various string data
The EON Steel saves the dive computer firmware versions etc per dive,
which is really nice for upgrades: old dives done with older firmware
still show the firmware at the time of the dive.  That, in turn, is nice
because we can use it for a reliable dive ID - dive time with serial
number etc.

This uses the new DC_FIELD_STRING model to feed the hw/sw information to
the application, since we need the parser to access it.  It also returns
battery state and deco model information.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:47:48 -07:00
Claudiu Olteanu
0c8886ce70 Implement custom open device method for SHEARWATER family
Create a custom open method for SHEARWATER family.
This method can be used to pass a reference to a dc_serial_t
structure. In this way the applications can implement their
own implementation for a serial communication and set their
callbacks for the basic serial functions.

Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:47:33 -07:00
Claudiu Olteanu
53ccc4f43b Use the dc_serial_t structure in SHEARWATER family
Use the new structure in the SHEARWATER family implementation.
This patch opens a native serial device and use it
for the serial communication.

Also the patch uses the set of callback functions saved in the
dc_serial_t structure.

Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:47:33 -07:00
Claudiu Olteanu
8c3e44aa0c Implement custom device open method
This method can be used by external applications to open a
device and to pass their custom implementation for the
serial communication.

Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:47:33 -07:00
Claudiu Olteanu
5dbaa7a053 Implement custom open method for HW OSTC 3 family
Create a custom open method for HW OSTC3 family.
This method can be used to pass a reference to a dc_serial_t
structure. In this way the applications can implement their
own implementation for a serial communication and set their
callbacks for the basic serial functions.

Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:47:33 -07:00
Claudiu Olteanu
69bd993233 Use the dc_serial_t structure in HW OSTC family 3
Open a native serial device and use it in the HW OSTC3
implementation.

This patch replaces the old serial structure with the
new one, which can be used for custom serial implementations.

Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:47:33 -07:00
Claudiu Olteanu
a50a1e0688 Create a generic way to represent any type of serial communication
Add a structure which holds references to basic operations
on a serial communication. This can be used to pass a set
of function pointer callbacks in order to create a custom
implementation for serial communication.

Add a generic structure to represent the needed information
for a serial communication.

Implement the initialization method where the user can
pass a set of function pointer callbacks and set some
custom data for the serial device.

Create open method for the native serial implementation.

Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:47:33 -07:00
Claudiu Olteanu
b9e3f40d59 Extend the transport enum descriptor for serial communication
Add a new transport type which can be used to identify
Bluetooth serial communication.

Signed-off-by Claudiu Oleanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:47:33 -07:00
Anton Lundin
f184b45e09 Correct firmware version string from OSTC's
The format string was incorrect, producing firmware numbers as 3.2
instead of 3.02 as is the current OSTC firmware version.

This was reported via hw's forum:
http://forum.heinrichsweikamp.com/read.php?2,14550,14552

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:47:33 -07:00
Dirk Hohndel
0ff1dd15f5 Predator: don't report PPO2 unless in CC mode
Sending this in OC mode is redundant and might confuse applications that
assume they only get PPO2 data in CC mode.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:47:33 -07:00
Dirk Hohndel
fb15ef18f6 Don't report errors if we can't set serial mode
That's just silly and breaks using the simulator.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:47:33 -07:00
Anton Lundin
3a17156be6 Add deco model info strings to hw parser
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:47:33 -07:00
Dirk Hohndel
1f24f67565 Make it easier to detect our branch of libdivecomputer
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:47:18 -07:00
Dirk Hohndel
5ecc65799c Mark a library built from our branch as such
This way it will be obvious when people report their libdivecomputer
version that they are using our branch

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:46:55 -07:00
Linus Torvalds
ddfdb6c306 Fix suunto serial numbers
libdivecomputer has already done the "byte to decimal" conversion.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:41:50 -07:00
Dirk Hohndel
b85f2333be Support serial number for Suuntu Vyper2 family of devices
We have the correct firmware in the devinfo, but that's the firmware the
dive computer is on NOW, not necessarily the firmware it was using when
recording the dive.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:41:43 -07:00
Dirk Hohndel
06426af656 Support firmware and serial number for Shearwater Petrel
This should work with the Predator as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:41:20 -07:00
Dirk Hohndel
f459155b54 Support serial number as DC_FIELD_STRING on atom2 backend
This has been verified with a few of the models, it needs much more
testing to make sure this is generally correct.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:40:35 -07:00
Dirk Hohndel
ebe6704747 Add support to return serial number to OSTC devices
This data isn't per dive, but it makes sense to return it here as a
string (we already return it as unsigned int in the devinfo event after
opening the device).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:40:09 -07:00
Dirk Hohndel
5f76249923 Pass the serial number from the devinfo to the OSTC parsers
This way we can analyze the data in the parser and return it to the
application.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:39:52 -07:00
Dirk Hohndel
0ddec2b50f Support FW Version on OSTC devices
And add battery voltage and desat for the Frog.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:39:45 -07:00
Dirk Hohndel
8f4038d4cd Add DC_FIELD_STRING support to OSTC parser
Just support a few of the most useful values. There are several more we
could and should add.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:39:36 -07:00
Dirk Hohndel
d90417da38 Add DC_FIELD_STRING support to Shearwater Petrel parser
Just support a few of the most useful values. There are several more we
could and should add.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:14:57 -07:00
Dirk Hohndel
f902f5882c Add DC_FIELD_STRING support to Atomics Aquatics Cobalt parser
Just support a few of the most useful values. There are several more we
could and should add.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:14:09 -07:00
Linus Torvalds
eac8e98ee7 parser: add DC_FIELD_STRING field type for parse-time information
This can be used to return almost arbitrary information to the dive log
application at dive parse time, by returning a number of strings (with a
descriptor) for dive state.

NOTE! The strings are supposed to be human-readable, so that the dive
log application can just show them unedited - and without understanding
them - to the user, together with the description.  So if your dive
computer supports returning a battery voltage, for example, you can
return it as a

  { "Voltage", "4.449V" }

descriptor/value string pair, and the application could then put these
string pairs together and show (somewhere) an informational line like
"Voltage: 4.449V" along with the other information you return.

Some dive log applications migth recognize particular descriptor strings
and use them specially to fill in other information (ie serial numbers,
weight and suit information etc), but in general the interface is very
much meant to be informational free-form for a human user.

So do *not* use this interface to encode things that are not human-
readable.  Serial numbers or version information that is meaningful to
humans are fine. But random encoded data structures are not.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-26 10:13:51 -07:00
39 changed files with 1588 additions and 496 deletions

2
.gitignore vendored
View File

@ -82,3 +82,5 @@ Makefile.in
/src/libdivecomputer.la /src/libdivecomputer.la
/src/libdivecomputer.rc /src/libdivecomputer.rc
/src/revision.h /src/revision.h
/build

View File

@ -2,7 +2,7 @@
m4_define([dc_version_major],[0]) m4_define([dc_version_major],[0])
m4_define([dc_version_minor],[7]) m4_define([dc_version_minor],[7])
m4_define([dc_version_micro],[0]) m4_define([dc_version_micro],[0])
m4_define([dc_version_suffix],[devel]) m4_define([dc_version_suffix],[devel-Subsurface-branch])
m4_define([dc_version],dc_version_major.dc_version_minor.dc_version_micro[]m4_ifset([dc_version_suffix],-[dc_version_suffix])) m4_define([dc_version],dc_version_major.dc_version_minor.dc_version_micro[]m4_ifset([dc_version_suffix],-[dc_version_suffix]))
# Libtool versioning. # Libtool versioning.
@ -60,6 +60,15 @@ AC_ARG_ENABLE([doc],
[], [enable_doc=yes]) [], [enable_doc=yes])
AM_CONDITIONAL([ENABLE_DOC], [test "x$enable_doc" = "xyes"]) AM_CONDITIONAL([ENABLE_DOC], [test "x$enable_doc" = "xyes"])
# BLE support
AC_ARG_ENABLE([ble],
[AS_HELP_STRING([--enable-ble=@<:@yes/no@:>@],
[Enable BLE dive computers @<:@default=yes@:>@])],
[], [enable_ble=no])
AS_IF([test "x$enable_ble" = "xyes"], [
AC_DEFINE(ENABLE_BLE, [1], [Enable support for BLE dive computers.])
])
# Checks for programs. # Checks for programs.
AC_PROG_CC AC_PROG_CC
AC_PROG_CC_C99 AC_PROG_CC_C99
@ -173,9 +182,7 @@ AC_CHECK_FUNCS([getopt_long])
# Checks for supported compiler options. # Checks for supported compiler options.
AX_APPEND_COMPILE_FLAGS([ \ AX_APPEND_COMPILE_FLAGS([ \
-pedantic \
-Wall \ -Wall \
-Wextra \
-Wshadow \ -Wshadow \
-Wrestrict \ -Wrestrict \
-Wformat=2 \ -Wformat=2 \

View File

@ -400,6 +400,24 @@ dctool_xml_output_write (dctool_output_t *abstract, dc_parser_t *parser, const u
convert_pressure(atmospheric, output->units)); convert_pressure(atmospheric, output->units));
} }
message ("Parsing strings.\n");
int idx;
for (idx = 0; idx < 100; idx++) {
dc_field_string_t str = { NULL };
status = dc_parser_get_field(parser, DC_FIELD_STRING, idx, &str);
if (status != DC_STATUS_SUCCESS && status != DC_STATUS_UNSUPPORTED) {
ERROR ("Error parsing strings");
goto cleanup;
}
if (status == DC_STATUS_UNSUPPORTED)
break;
if (!str.desc || !str.value)
break;
fprintf (output->ostream, "<extradata key='%s' value='%s' />\n",
str.desc, str.value);
}
// Parse the sample data. // Parse the sample data.
message ("Parsing the sample data.\n"); message ("Parsing the sample data.\n");
status = dc_parser_samples_foreach (parser, sample_cb, &sampledata); status = dc_parser_samples_foreach (parser, sample_cb, &sampledata);

View File

@ -3,6 +3,7 @@ libdivecomputer_HEADERS = \
version.h \ version.h \
common.h \ common.h \
context.h \ context.h \
custom_io.h \
buffer.h \ buffer.h \
descriptor.h \ descriptor.h \
iterator.h \ iterator.h \

View File

@ -23,6 +23,7 @@
#define DC_CONTEXT_H #define DC_CONTEXT_H
#include "common.h" #include "common.h"
#include "custom_io.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -30,6 +31,9 @@ extern "C" {
typedef struct dc_context_t dc_context_t; typedef struct dc_context_t dc_context_t;
/* Opaque libdivecomputer *user* data structure */
typedef struct dc_user_device_t dc_user_device_t;
typedef enum dc_loglevel_t { typedef enum dc_loglevel_t {
DC_LOGLEVEL_NONE, DC_LOGLEVEL_NONE,
DC_LOGLEVEL_ERROR, DC_LOGLEVEL_ERROR,
@ -47,6 +51,9 @@ dc_context_new (dc_context_t **context);
dc_status_t dc_status_t
dc_context_free (dc_context_t *context); dc_context_free (dc_context_t *context);
dc_status_t
dc_context_set_custom_io (dc_context_t *context, dc_custom_io_t *custom_io, dc_user_device_t *);
dc_status_t dc_status_t
dc_context_set_loglevel (dc_context_t *context, dc_loglevel_t loglevel); dc_context_set_loglevel (dc_context_t *context, dc_loglevel_t loglevel);

View File

@ -0,0 +1,71 @@
#ifndef CUSTOM_IO_H
#define CUSTOM_IO_H
#include <libdivecomputer/iostream.h>
#include "common.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct dc_context_t;
struct dc_user_device_t;
/*
* Two different pointers to user-supplied data.
*
* The 'userdata' pointer is for the IO routines themselves,
* generally filled in by the 'xyz_open()' routine with whatever
* file descriptor etc information.
*
* The 'user_device' pointer is set when registering the
* custom IO with the download context, and has whatever
* data the downloader needs.
*
* The two are very different. The userdata is "per instance",
* and when nesting custom IO handlers, each level would
* generally have its own userdata, that would be specific
* to that particular set of IO routines.
*
* In contrast, the user_device is filled in when the
* download context is created, before open() is even called,
* and isn't specific to the IO routines, but to the download
* as a whole.
*/
typedef struct dc_custom_io_t
{
void *userdata;
struct dc_user_device_t *user_device;
// Custom serial (generally BT rfcomm)
dc_status_t (*serial_open) (struct dc_custom_io_t *io, struct dc_context_t *, const char *name);
dc_status_t (*serial_close) (struct dc_custom_io_t *io);
dc_status_t (*serial_read) (struct dc_custom_io_t *io, void* data, size_t size, size_t *actual);
dc_status_t (*serial_write) (struct dc_custom_io_t *io, const void* data, size_t size, size_t *actual);
dc_status_t (*serial_purge) (struct dc_custom_io_t *io, dc_direction_t);
dc_status_t (*serial_get_available) (struct dc_custom_io_t *io, size_t *value);
dc_status_t (*serial_set_timeout) (struct dc_custom_io_t *io, long timeout);
dc_status_t (*serial_configure) (struct dc_custom_io_t *io, unsigned int baudrate, unsigned int databits, dc_parity_t parity, dc_stopbits_t stopbits, dc_flowcontrol_t flowcontrol);
dc_status_t (*serial_set_dtr) (struct dc_custom_io_t *io, int level);
dc_status_t (*serial_set_rts) (struct dc_custom_io_t *io, int level);
dc_status_t (*serial_set_halfduplex) (struct dc_custom_io_t *io, unsigned int value);
dc_status_t (*serial_set_break) (struct dc_custom_io_t *io, unsigned int level);
//dc_serial_set_latency (dc_serial_t *device, unsigned int milliseconds) - Unused
//dc_serial_get_lines (dc_serial_t *device, unsigned int *value) - Unused
//dc_serial_flush (dc_serial_t *device) - No device interaction
//dc_serial_sleep (dc_serial_t *device, unsigned int timeout) - No device interaction
// Custom packet transfer (generally BLE GATT)
int packet_size;
dc_status_t (*packet_open) (struct dc_custom_io_t *, struct dc_context_t *, const char *);
dc_status_t (*packet_close) (struct dc_custom_io_t *);
dc_status_t (*packet_read) (struct dc_custom_io_t *, void* data, size_t size, size_t *actual);
dc_status_t (*packet_write) (struct dc_custom_io_t *, const void* data, size_t size, size_t *actual);
} dc_custom_io_t;
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* CUSTOM_IO_H */

View File

@ -58,6 +58,9 @@ dc_descriptor_get_type (dc_descriptor_t *descriptor);
unsigned int unsigned int
dc_descriptor_get_model (dc_descriptor_t *descriptor); dc_descriptor_get_model (dc_descriptor_t *descriptor);
unsigned int
dc_descriptor_get_serial (dc_descriptor_t *descriptor);
dc_transport_t dc_transport_t
dc_descriptor_get_transport (dc_descriptor_t *descriptor); dc_descriptor_get_transport (dc_descriptor_t *descriptor);

View File

@ -62,9 +62,13 @@ typedef enum dc_field_type_t {
DC_FIELD_TEMPERATURE_MAXIMUM, DC_FIELD_TEMPERATURE_MAXIMUM,
DC_FIELD_TANK_COUNT, DC_FIELD_TANK_COUNT,
DC_FIELD_TANK, DC_FIELD_TANK,
DC_FIELD_DIVEMODE DC_FIELD_DIVEMODE,
DC_FIELD_STRING,
} dc_field_type_t; } dc_field_type_t;
// Make it easy to test support compile-time with "#ifdef DC_FIELD_STRING"
#define DC_FIELD_STRING DC_FIELD_STRING
typedef enum parser_sample_event_t { typedef enum parser_sample_event_t {
SAMPLE_EVENT_NONE, SAMPLE_EVENT_NONE,
SAMPLE_EVENT_DECOSTOP, SAMPLE_EVENT_DECOSTOP,
@ -92,24 +96,31 @@ typedef enum parser_sample_event_t {
SAMPLE_EVENT_HEADING, SAMPLE_EVENT_HEADING,
SAMPLE_EVENT_TISSUELEVEL, SAMPLE_EVENT_TISSUELEVEL,
SAMPLE_EVENT_GASCHANGE2, /* Deprecated: replaced by DC_SAMPLE_GASMIX. */ SAMPLE_EVENT_GASCHANGE2, /* Deprecated: replaced by DC_SAMPLE_GASMIX. */
SAMPLE_EVENT_STRING,
} parser_sample_event_t; } parser_sample_event_t;
/* To let the compile know we have this */
#define SAMPLE_EVENT_STRING SAMPLE_EVENT_STRING
/* For backwards compatibility */ /* For backwards compatibility */
#define SAMPLE_EVENT_UNKNOWN SAMPLE_EVENT_FLOOR #define SAMPLE_EVENT_UNKNOWN SAMPLE_EVENT_FLOOR
typedef enum parser_sample_flags_t { typedef enum parser_sample_flags_t {
SAMPLE_FLAGS_NONE = 0, SAMPLE_FLAGS_NONE = 0,
SAMPLE_FLAGS_BEGIN = (1 << 0), SAMPLE_FLAGS_BEGIN = (1 << 0),
SAMPLE_FLAGS_END = (1 << 1) SAMPLE_FLAGS_END = (1 << 1),
SAMPLE_FLAGS_SEVERITY_MASK = (7 << 2),
} parser_sample_flags_t; } parser_sample_flags_t;
#define SAMPLE_FLAGS_SEVERITY_SHIFT 2
typedef enum parser_sample_vendor_t { typedef enum parser_sample_vendor_t {
SAMPLE_VENDOR_NONE, SAMPLE_VENDOR_NONE,
SAMPLE_VENDOR_UWATEC_ALADIN, SAMPLE_VENDOR_UWATEC_ALADIN,
SAMPLE_VENDOR_UWATEC_SMART, SAMPLE_VENDOR_UWATEC_SMART,
SAMPLE_VENDOR_OCEANIC_VTPRO, SAMPLE_VENDOR_OCEANIC_VTPRO,
SAMPLE_VENDOR_OCEANIC_VEO250, SAMPLE_VENDOR_OCEANIC_VEO250,
SAMPLE_VENDOR_OCEANIC_ATOM2 SAMPLE_VENDOR_OCEANIC_ATOM2,
} parser_sample_vendor_t; } parser_sample_vendor_t;
typedef enum dc_water_t { typedef enum dc_water_t {
@ -148,11 +159,17 @@ typedef struct dc_gasmix_t {
#define DC_GASMIX_UNKNOWN 0xFFFFFFFF #define DC_GASMIX_UNKNOWN 0xFFFFFFFF
typedef enum dc_tankvolume_t { typedef unsigned int dc_tankinfo_t;
DC_TANKVOLUME_NONE, #define DC_TANKINFO_METRIC 1
DC_TANKVOLUME_METRIC, #define DC_TANKINFO_IMPERIAL 2
DC_TANKVOLUME_IMPERIAL, #define DC_TANKINFO_CC_DILUENT 4
} dc_tankvolume_t; #define DC_TANKINFO_CC_O2 8
// For backwards compatibility
#define DC_TANKVOLUME_NONE 0
#define DC_TANKVOLUME_METRIC DC_TANKINFO_METRIC
#define DC_TANKVOLUME_IMPERIAL DC_TANKINFO_IMPERIAL
/* /*
* Tank volume * Tank volume
@ -179,13 +196,18 @@ typedef enum dc_tankvolume_t {
typedef struct dc_tank_t { typedef struct dc_tank_t {
unsigned int gasmix; /* Gas mix index, or DC_GASMIX_UNKNOWN */ unsigned int gasmix; /* Gas mix index, or DC_GASMIX_UNKNOWN */
dc_tankvolume_t type; /* Tank type */ dc_tankinfo_t type; /* Tank type - metric/imperial and oc/cc */
double volume; /* Volume (liter) */ double volume; /* Volume (liter) */
double workpressure; /* Work pressure (bar) */ double workpressure; /* Work pressure (bar) */
double beginpressure; /* Begin pressure (bar) */ double beginpressure; /* Begin pressure (bar) */
double endpressure; /* End pressure (bar) */ double endpressure; /* End pressure (bar) */
} dc_tank_t; } dc_tank_t;
typedef struct dc_field_string_t {
const char *desc;
const char *value;
} dc_field_string_t;
typedef union dc_sample_value_t { typedef union dc_sample_value_t {
unsigned int time; unsigned int time;
double depth; double depth;
@ -197,6 +219,7 @@ typedef union dc_sample_value_t {
struct { struct {
unsigned int type; unsigned int type;
unsigned int time; unsigned int time;
const char *name;
unsigned int flags; unsigned int flags;
unsigned int value; unsigned int value;
} event; } event;

View File

@ -26,6 +26,10 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/* use these defines to detect Subsurface specific features */
#define SSRF_LIBDC_VERSION 2
#define SSRF_CUSTOM_IO 2
#define DC_VERSION "@DC_VERSION@" #define DC_VERSION "@DC_VERSION@"
#define DC_VERSION_MAJOR @DC_VERSION_MAJOR@ #define DC_VERSION_MAJOR @DC_VERSION_MAJOR@
#define DC_VERSION_MINOR @DC_VERSION_MINOR@ #define DC_VERSION_MINOR @DC_VERSION_MINOR@

View File

@ -3,7 +3,7 @@ AM_CFLAGS = $(LIBUSB_CFLAGS) $(HIDAPI_CFLAGS) $(BLUEZ_CFLAGS)
lib_LTLIBRARIES = libdivecomputer.la lib_LTLIBRARIES = libdivecomputer.la
libdivecomputer_la_LIBADD = $(LIBUSB_LIBS) $(HIDAPI_LIBS) $(BLUEZ_LIBS) -lm libdivecomputer_la_LIBADD = $(LIBUSB_LIBS) $(HIDAPI_LIBS) $(BLUEZ_LIBS) -lm -lz
libdivecomputer_la_LDFLAGS = \ libdivecomputer_la_LDFLAGS = \
-version-info $(DC_VERSION_LIBTOOL) \ -version-info $(DC_VERSION_LIBTOOL) \
-no-undefined \ -no-undefined \
@ -32,6 +32,7 @@ libdivecomputer_la_SOURCES = \
suunto_vyper2.h suunto_vyper2.c \ suunto_vyper2.h suunto_vyper2.c \
suunto_d9.h suunto_d9.c suunto_d9_parser.c \ suunto_d9.h suunto_d9.c suunto_d9_parser.c \
suunto_eonsteel.h suunto_eonsteel.c suunto_eonsteel_parser.c \ suunto_eonsteel.h suunto_eonsteel.c suunto_eonsteel_parser.c \
scubapro_g2.h scubapro_g2.c \
reefnet_sensus.h reefnet_sensus.c reefnet_sensus_parser.c \ reefnet_sensus.h reefnet_sensus.c reefnet_sensus_parser.c \
reefnet_sensuspro.h reefnet_sensuspro.c reefnet_sensuspro_parser.c \ reefnet_sensuspro.h reefnet_sensuspro.c reefnet_sensuspro_parser.c \
reefnet_sensusultra.h reefnet_sensusultra.c reefnet_sensusultra_parser.c \ reefnet_sensusultra.h reefnet_sensusultra.c reefnet_sensusultra_parser.c \
@ -39,7 +40,6 @@ libdivecomputer_la_SOURCES = \
uwatec_memomouse.h uwatec_memomouse.c uwatec_memomouse_parser.c \ uwatec_memomouse.h uwatec_memomouse.c uwatec_memomouse_parser.c \
uwatec_smart.h uwatec_smart.c uwatec_smart_parser.c \ uwatec_smart.h uwatec_smart.c uwatec_smart_parser.c \
uwatec_meridian.h uwatec_meridian.c \ uwatec_meridian.h uwatec_meridian.c \
uwatec_g2.h uwatec_g2.c \
oceanic_common.h oceanic_common.c \ oceanic_common.h oceanic_common.c \
oceanic_atom2.h oceanic_atom2.c oceanic_atom2_parser.c \ oceanic_atom2.h oceanic_atom2.c oceanic_atom2_parser.c \
oceanic_veo250.h oceanic_veo250.c oceanic_veo250_parser.c \ oceanic_veo250.h oceanic_veo250.c oceanic_veo250_parser.c \
@ -83,6 +83,7 @@ libdivecomputer_la_SOURCES += irda.h irda.c
libdivecomputer_la_SOURCES += usbhid.h usbhid.c libdivecomputer_la_SOURCES += usbhid.h usbhid.c
libdivecomputer_la_SOURCES += bluetooth.h bluetooth.c libdivecomputer_la_SOURCES += bluetooth.h bluetooth.c
libdivecomputer_la_SOURCES += custom.h custom.c libdivecomputer_la_SOURCES += custom.h custom.c
libdivecomputer_la_SOURCES += custom_io.c
if OS_WIN32 if OS_WIN32
libdivecomputer_la_SOURCES += libdivecomputer.rc libdivecomputer_la_SOURCES += libdivecomputer.rc

View File

@ -20,6 +20,12 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include <libdivecomputer/units.h> #include <libdivecomputer/units.h>
@ -129,6 +135,9 @@ atomics_cobalt_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *dateti
} }
#define BUFLEN 16
static dc_status_t static dc_status_t
atomics_cobalt_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value) atomics_cobalt_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value)
{ {
@ -143,6 +152,9 @@ atomics_cobalt_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, un
dc_tank_t *tank = (dc_tank_t *) value; dc_tank_t *tank = (dc_tank_t *) value;
double atmospheric = 0.0; double atmospheric = 0.0;
char buf[BUFLEN];
dc_field_string_t *string = (dc_field_string_t *) value;
if (parser->atmospheric) if (parser->atmospheric)
atmospheric = parser->atmospheric; atmospheric = parser->atmospheric;
else else
@ -208,6 +220,29 @@ atomics_cobalt_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, un
return DC_STATUS_DATAFORMAT; return DC_STATUS_DATAFORMAT;
} }
break; break;
case DC_FIELD_STRING:
switch(flags) {
case 0: // Serialnr
string->desc = "Serial";
snprintf(buf, BUFLEN, "%c%c%c%c-%c%c%c%c", p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11]);
break;
case 1: // Program Version
string->desc = "Program Version";
snprintf(buf, BUFLEN, "%.2f", array_uint16_le(p + 30) / 100.0);
break;
case 2: // Boot Version
string->desc = "Boot Version";
snprintf(buf, BUFLEN, "%.2f", array_uint16_le(p + 32) / 100.0);
break;
case 3: // Nofly
string->desc = "NoFly Time";
snprintf(buf, BUFLEN, "%0u:%02u", p[0x52], p[0x53]);
break;
default:
return DC_STATUS_UNSUPPORTED;
}
string->value = strdup(buf);
break;
default: default:
return DC_STATUS_UNSUPPORTED; return DC_STATUS_UNSUPPORTED;
} }

View File

@ -27,6 +27,7 @@
#endif #endif
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/custom_io.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -71,6 +72,12 @@ dc_context_syserror (dc_context_t *context, dc_loglevel_t loglevel, const char *
dc_status_t dc_status_t
dc_context_hexdump (dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *prefix, const unsigned char data[], unsigned int size); dc_context_hexdump (dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *prefix, const unsigned char data[], unsigned int size);
dc_custom_io_t*
_dc_context_custom_io (dc_context_t *context);
dc_status_t
dc_custom_io_serial_open(dc_iostream_t **out, dc_context_t *context, const char *name);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -32,6 +32,7 @@
#endif #endif
#include "context-private.h" #include "context-private.h"
#include <libdivecomputer/custom_io.h>
struct dc_context_t { struct dc_context_t {
dc_loglevel_t loglevel; dc_loglevel_t loglevel;
@ -45,6 +46,8 @@ struct dc_context_t {
struct timeval timestamp; struct timeval timestamp;
#endif #endif
#endif #endif
dc_custom_io_t *custom_io;
dc_user_device_t *user_device;
}; };
#ifdef ENABLE_LOGGING #ifdef ENABLE_LOGGING
@ -195,6 +198,8 @@ dc_context_new (dc_context_t **out)
#endif #endif
#endif #endif
context->custom_io = NULL;
*out = context; *out = context;
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
@ -208,6 +213,24 @@ dc_context_free (dc_context_t *context)
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }
dc_status_t
dc_context_set_custom_io (dc_context_t *context, dc_custom_io_t *custom_io, dc_user_device_t *user_device)
{
if (context == NULL)
return DC_STATUS_INVALIDARGS;
context->custom_io = custom_io;
custom_io->user_device = user_device;
return DC_STATUS_SUCCESS;
}
dc_custom_io_t*
_dc_context_custom_io (dc_context_t *context)
{
return context->custom_io;
}
dc_status_t dc_status_t
dc_context_set_loglevel (dc_context_t *context, dc_loglevel_t loglevel) dc_context_set_loglevel (dc_context_t *context, dc_loglevel_t loglevel)
{ {

231
src/custom_io.c Normal file
View File

@ -0,0 +1,231 @@
/*
* libdivecomputer
*
* Copyright (C) 2017 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#include <stdlib.h> // malloc, free
#include <libdivecomputer/context.h>
#include "iostream-private.h"
#include "common-private.h"
#include "context-private.h"
/*
* This is shamelessly stolen from src/custom.c, to make it
* work with the subsurface custom_io model.
*/
typedef struct dc_custom_t {
/* Base class. */
dc_iostream_t base;
/* Internal state. */
dc_context_t *context;
} dc_custom_t;
static dc_status_t
dc_custom_set_timeout (dc_iostream_t *abstract, int timeout)
{
dc_custom_t *custom = (dc_custom_t *) abstract;
dc_custom_io_t *io = _dc_context_custom_io(custom->context);
if (!io->serial_set_timeout)
return DC_STATUS_SUCCESS;
return io->serial_set_timeout(io, timeout);
}
static dc_status_t
dc_custom_set_latency (dc_iostream_t *abstract, unsigned int value)
{
return DC_STATUS_SUCCESS;
}
static dc_status_t
dc_custom_set_halfduplex (dc_iostream_t *abstract, unsigned int value)
{
dc_custom_t *custom = (dc_custom_t *) abstract;
dc_custom_io_t *io = _dc_context_custom_io(custom->context);
if (!io->serial_set_halfduplex)
return DC_STATUS_SUCCESS;
return io->serial_set_halfduplex(io, value);
}
static dc_status_t
dc_custom_set_break (dc_iostream_t *abstract, unsigned int value)
{
dc_custom_t *custom = (dc_custom_t *) abstract;
dc_custom_io_t *io = _dc_context_custom_io(custom->context);
if (!io->serial_set_break)
return DC_STATUS_SUCCESS;
return io->serial_set_break(io, value);
}
static dc_status_t
dc_custom_set_dtr (dc_iostream_t *abstract, unsigned int value)
{
dc_custom_t *custom = (dc_custom_t *) abstract;
dc_custom_io_t *io = _dc_context_custom_io(custom->context);
if (!io->serial_set_dtr)
return DC_STATUS_SUCCESS;
return io->serial_set_dtr(io, value);
}
static dc_status_t
dc_custom_set_rts (dc_iostream_t *abstract, unsigned int value)
{
dc_custom_t *custom = (dc_custom_t *) abstract;
dc_custom_io_t *io = _dc_context_custom_io(custom->context);
if (!io->serial_set_rts)
return DC_STATUS_SUCCESS;
return io->serial_set_rts(io, value);
}
static dc_status_t
dc_custom_get_lines (dc_iostream_t *abstract, unsigned int *value)
{
return DC_STATUS_SUCCESS;
}
static dc_status_t
dc_custom_get_available (dc_iostream_t *abstract, size_t *value)
{
dc_custom_t *custom = (dc_custom_t *) abstract;
dc_custom_io_t *io = _dc_context_custom_io(custom->context);
if (!io->serial_get_available)
return DC_STATUS_SUCCESS;
return io->serial_get_available(io, value);
}
static dc_status_t
dc_custom_configure (dc_iostream_t *abstract, unsigned int baudrate, unsigned int databits, dc_parity_t parity, dc_stopbits_t stopbits, dc_flowcontrol_t flowcontrol)
{
dc_custom_t *custom = (dc_custom_t *) abstract;
dc_custom_io_t *io = _dc_context_custom_io(custom->context);
if (!io->serial_configure)
return DC_STATUS_SUCCESS;
return io->serial_configure(io, baudrate, databits, parity, stopbits, flowcontrol);
}
static dc_status_t
dc_custom_read (dc_iostream_t *abstract, void *data, size_t size, size_t *actual)
{
dc_custom_t *custom = (dc_custom_t *) abstract;
dc_custom_io_t *io = _dc_context_custom_io(custom->context);
if (!io->serial_read)
return DC_STATUS_SUCCESS;
return io->serial_read(io, data, size, actual);
}
static dc_status_t
dc_custom_write (dc_iostream_t *abstract, const void *data, size_t size, size_t *actual)
{
dc_custom_t *custom = (dc_custom_t *) abstract;
dc_custom_io_t *io = _dc_context_custom_io(custom->context);
if (!io->serial_write)
return DC_STATUS_SUCCESS;
return io->serial_write(io, data, size, actual);
}
static dc_status_t
dc_custom_flush (dc_iostream_t *abstract)
{
return DC_STATUS_SUCCESS;
}
static dc_status_t
dc_custom_purge (dc_iostream_t *abstract, dc_direction_t direction)
{
dc_custom_t *custom = (dc_custom_t *) abstract;
dc_custom_io_t *io = _dc_context_custom_io(custom->context);
if (!io->serial_purge)
return DC_STATUS_SUCCESS;
return io->serial_purge(io, direction);
}
static dc_status_t
dc_custom_sleep (dc_iostream_t *abstract, unsigned int milliseconds)
{
return DC_STATUS_SUCCESS;
}
static dc_status_t
dc_custom_close (dc_iostream_t *abstract)
{
dc_custom_t *custom = (dc_custom_t *) abstract;
dc_custom_io_t *io = _dc_context_custom_io(custom->context);
if (!io->serial_close)
return DC_STATUS_SUCCESS;
return io->serial_close(io);
}
static const dc_iostream_vtable_t dc_custom_vtable = {
sizeof(dc_custom_t),
dc_custom_set_timeout, /* set_timeout */
dc_custom_set_latency, /* set_latency */
dc_custom_set_halfduplex, /* set_halfduplex */
dc_custom_set_break, /* set_break */
dc_custom_set_dtr, /* set_dtr */
dc_custom_set_rts, /* set_rts */
dc_custom_get_lines, /* get_lines */
dc_custom_get_available, /* get_received */
dc_custom_configure, /* configure */
dc_custom_read, /* read */
dc_custom_write, /* write */
dc_custom_flush, /* flush */
dc_custom_purge, /* purge */
dc_custom_sleep, /* sleep */
dc_custom_close, /* close */
};
dc_status_t
dc_custom_io_serial_open(dc_iostream_t **out, dc_context_t *context, const char *name)
{
dc_custom_io_t *io = _dc_context_custom_io(context);
dc_custom_t *custom;
custom = (dc_custom_t *) dc_iostream_allocate (context, &dc_custom_vtable);
if (!custom) {
ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY;
}
custom->context = context;
*out = (dc_iostream_t *) custom;
return io->serial_open(io, context, name);
}

View File

@ -53,6 +53,7 @@ struct dc_descriptor_t {
const char *product; const char *product;
dc_family_t type; dc_family_t type;
unsigned int model; unsigned int model;
unsigned int serial;
}; };
/* /*
@ -64,53 +65,53 @@ struct dc_descriptor_t {
static const dc_descriptor_t g_descriptors[] = { static const dc_descriptor_t g_descriptors[] = {
/* Suunto Solution */ /* Suunto Solution */
{"Suunto", "Solution", DC_FAMILY_SUUNTO_SOLUTION, 0}, {"Suunto", "Solution", DC_FAMILY_SUUNTO_SOLUTION, 0}, // FTDI
/* Suunto Eon */ /* Suunto Eon */
{"Suunto", "Eon", DC_FAMILY_SUUNTO_EON, 0}, {"Suunto", "Eon", DC_FAMILY_SUUNTO_EON, 0}, // FTDI
{"Suunto", "Solution Alpha", DC_FAMILY_SUUNTO_EON, 0}, {"Suunto", "Solution Alpha", DC_FAMILY_SUUNTO_EON, 0}, // FTDI
{"Suunto", "Solution Nitrox", DC_FAMILY_SUUNTO_EON, 0}, {"Suunto", "Solution Nitrox", DC_FAMILY_SUUNTO_EON, 0}, // FTDI
/* Suunto Vyper */ /* Suunto Vyper */
{"Suunto", "Spyder", DC_FAMILY_SUUNTO_VYPER, 0x01}, {"Suunto", "Spyder", DC_FAMILY_SUUNTO_VYPER, 0x01}, // FTDI
{"Suunto", "Stinger", DC_FAMILY_SUUNTO_VYPER, 0x03}, {"Suunto", "Stinger", DC_FAMILY_SUUNTO_VYPER, 0x03}, // FTDI
{"Suunto", "Mosquito", DC_FAMILY_SUUNTO_VYPER, 0x04}, {"Suunto", "Mosquito", DC_FAMILY_SUUNTO_VYPER, 0x04}, // FTDI
{"Suunto", "D3", DC_FAMILY_SUUNTO_VYPER, 0x05}, {"Suunto", "D3", DC_FAMILY_SUUNTO_VYPER, 0x05}, // FTDI
{"Suunto", "Vyper", DC_FAMILY_SUUNTO_VYPER, 0x0A}, {"Suunto", "Vyper", DC_FAMILY_SUUNTO_VYPER, 0x0A}, // FTDI
{"Suunto", "Vytec", DC_FAMILY_SUUNTO_VYPER, 0X0B}, {"Suunto", "Vytec", DC_FAMILY_SUUNTO_VYPER, 0X0B}, // FTDI
{"Suunto", "Cobra", DC_FAMILY_SUUNTO_VYPER, 0X0C}, {"Suunto", "Cobra", DC_FAMILY_SUUNTO_VYPER, 0X0C}, // FTDI
{"Suunto", "Gekko", DC_FAMILY_SUUNTO_VYPER, 0X0D}, {"Suunto", "Gekko", DC_FAMILY_SUUNTO_VYPER, 0X0D}, // FTDI
{"Suunto", "Zoop", DC_FAMILY_SUUNTO_VYPER, 0x16}, {"Suunto", "Zoop", DC_FAMILY_SUUNTO_VYPER, 0x16}, // FTDI
/* Suunto Vyper 2 */ /* Suunto Vyper 2 */
{"Suunto", "Vyper 2", DC_FAMILY_SUUNTO_VYPER2, 0x10}, {"Suunto", "Vyper 2", DC_FAMILY_SUUNTO_VYPER2, 0x10}, // FTDI
{"Suunto", "Cobra 2", DC_FAMILY_SUUNTO_VYPER2, 0x11}, {"Suunto", "Cobra 2", DC_FAMILY_SUUNTO_VYPER2, 0x11}, // FTDI
{"Suunto", "Vyper Air", DC_FAMILY_SUUNTO_VYPER2, 0x13}, {"Suunto", "Vyper Air", DC_FAMILY_SUUNTO_VYPER2, 0x13}, // FTDI
{"Suunto", "Cobra 3", DC_FAMILY_SUUNTO_VYPER2, 0x14}, {"Suunto", "Cobra 3", DC_FAMILY_SUUNTO_VYPER2, 0x14}, // FTDI
{"Suunto", "HelO2", DC_FAMILY_SUUNTO_VYPER2, 0x15}, {"Suunto", "HelO2", DC_FAMILY_SUUNTO_VYPER2, 0x15}, // FTDI
/* Suunto D9 */ /* Suunto D9 */
{"Suunto", "D9", DC_FAMILY_SUUNTO_D9, 0x0E}, {"Suunto", "D9", DC_FAMILY_SUUNTO_D9, 0x0E}, // FTDI
{"Suunto", "D6", DC_FAMILY_SUUNTO_D9, 0x0F}, {"Suunto", "D6", DC_FAMILY_SUUNTO_D9, 0x0F}, // FTDI
{"Suunto", "D4", DC_FAMILY_SUUNTO_D9, 0x12}, {"Suunto", "D4", DC_FAMILY_SUUNTO_D9, 0x12}, // FTDI
{"Suunto", "D4i", DC_FAMILY_SUUNTO_D9, 0x19}, {"Suunto", "D4i", DC_FAMILY_SUUNTO_D9, 0x19}, // FTDI
{"Suunto", "D6i", DC_FAMILY_SUUNTO_D9, 0x1A}, {"Suunto", "D6i", DC_FAMILY_SUUNTO_D9, 0x1A}, // FTDI
{"Suunto", "D9tx", DC_FAMILY_SUUNTO_D9, 0x1B}, {"Suunto", "D9tx", DC_FAMILY_SUUNTO_D9, 0x1B}, // FTDI
{"Suunto", "DX", DC_FAMILY_SUUNTO_D9, 0x1C}, {"Suunto", "DX", DC_FAMILY_SUUNTO_D9, 0x1C}, // FTDI
{"Suunto", "Vyper Novo", DC_FAMILY_SUUNTO_D9, 0x1D}, {"Suunto", "Vyper Novo", DC_FAMILY_SUUNTO_D9, 0x1D}, // FTDI
{"Suunto", "Zoop Novo", DC_FAMILY_SUUNTO_D9, 0x1E}, {"Suunto", "Zoop Novo", DC_FAMILY_SUUNTO_D9, 0x1E}, // FTDI
{"Suunto", "D4f", DC_FAMILY_SUUNTO_D9, 0x20}, {"Suunto", "D4f", DC_FAMILY_SUUNTO_D9, 0x20}, // FTDI
/* Suunto EON Steel */ /* Suunto EON Steel */
#ifdef USBHID #if defined(USBHID) || defined(ENABLE_BLE)
{"Suunto", "EON Steel", DC_FAMILY_SUUNTO_EONSTEEL, 0}, {"Suunto", "EON Steel", DC_FAMILY_SUUNTO_EONSTEEL, 0}, // BLE
{"Suunto", "EON Core", DC_FAMILY_SUUNTO_EONSTEEL, 1}, {"Suunto", "EON Core", DC_FAMILY_SUUNTO_EONSTEEL, 1}, // BLE
#endif #endif
/* Uwatec Aladin */ /* Uwatec Aladin */
{"Uwatec", "Aladin Air Twin", DC_FAMILY_UWATEC_ALADIN, 0x1C}, {"Uwatec", "Aladin Air Twin", DC_FAMILY_UWATEC_ALADIN, 0x1C}, // FTDI
{"Uwatec", "Aladin Sport Plus", DC_FAMILY_UWATEC_ALADIN, 0x3E}, {"Uwatec", "Aladin Sport Plus", DC_FAMILY_UWATEC_ALADIN, 0x3E}, // FTDI
{"Uwatec", "Aladin Pro", DC_FAMILY_UWATEC_ALADIN, 0x3F}, {"Uwatec", "Aladin Pro", DC_FAMILY_UWATEC_ALADIN, 0x3F}, // FTDI
{"Uwatec", "Aladin Air Z", DC_FAMILY_UWATEC_ALADIN, 0x44}, {"Uwatec", "Aladin Air Z", DC_FAMILY_UWATEC_ALADIN, 0x44}, // FTDI
{"Uwatec", "Aladin Air Z O2", DC_FAMILY_UWATEC_ALADIN, 0xA4}, {"Uwatec", "Aladin Air Z O2", DC_FAMILY_UWATEC_ALADIN, 0xA4}, // FTDI
{"Uwatec", "Aladin Air Z Nitrox", DC_FAMILY_UWATEC_ALADIN, 0xF4}, {"Uwatec", "Aladin Air Z Nitrox", DC_FAMILY_UWATEC_ALADIN, 0xF4}, // FTDI
{"Uwatec", "Aladin Pro Ultra", DC_FAMILY_UWATEC_ALADIN, 0xFF}, {"Uwatec", "Aladin Pro Ultra", DC_FAMILY_UWATEC_ALADIN, 0xFF}, // FTDI
/* Uwatec Memomouse */ /* Uwatec Memomouse */
{"Uwatec", "Memomouse", DC_FAMILY_UWATEC_MEMOMOUSE, 0}, {"Uwatec", "Memomouse", DC_FAMILY_UWATEC_MEMOMOUSE, 0}, // FTDI
/* Uwatec Smart */ /* Uwatec Smart */
#ifdef IRDA #ifdef IRDA
{"Uwatec", "Smart Pro", DC_FAMILY_UWATEC_SMART, 0x10}, {"Uwatec", "Smart Pro", DC_FAMILY_UWATEC_SMART, 0x10},
@ -138,91 +139,91 @@ static const dc_descriptor_t g_descriptors[] = {
{"Scubapro", "Chromis", DC_FAMILY_UWATEC_MERIDIAN, 0x24}, {"Scubapro", "Chromis", DC_FAMILY_UWATEC_MERIDIAN, 0x24},
{"Scubapro", "Mantis 2", DC_FAMILY_UWATEC_MERIDIAN, 0x26}, {"Scubapro", "Mantis 2", DC_FAMILY_UWATEC_MERIDIAN, 0x26},
/* Scubapro G2 */ /* Scubapro G2 */
#ifdef USBHID #if defined(USBHID) || defined(ENABLE_BLE)
{"Scubapro", "Aladin Sport Matrix", DC_FAMILY_UWATEC_G2, 0x17}, {"Scubapro", "Aladin Sport Matrix", DC_FAMILY_UWATEC_G2, 0x17}, // BLE
{"Scubapro", "Aladin Square", DC_FAMILY_UWATEC_G2, 0x22}, {"Scubapro", "Aladin Square", DC_FAMILY_UWATEC_G2, 0x22},
{"Scubapro", "G2", DC_FAMILY_UWATEC_G2, 0x32}, {"Scubapro", "G2", DC_FAMILY_UWATEC_G2, 0x32}, // BLE
#endif #endif
/* Reefnet */ /* Reefnet */
{"Reefnet", "Sensus", DC_FAMILY_REEFNET_SENSUS, 1}, {"Reefnet", "Sensus", DC_FAMILY_REEFNET_SENSUS, 1},
{"Reefnet", "Sensus Pro", DC_FAMILY_REEFNET_SENSUSPRO, 2}, {"Reefnet", "Sensus Pro", DC_FAMILY_REEFNET_SENSUSPRO, 2},
{"Reefnet", "Sensus Ultra", DC_FAMILY_REEFNET_SENSUSULTRA, 3}, {"Reefnet", "Sensus Ultra", DC_FAMILY_REEFNET_SENSUSULTRA, 3},
/* Oceanic VT Pro */ /* Oceanic VT Pro */
{"Aeris", "500 AI", DC_FAMILY_OCEANIC_VTPRO, 0x4151}, {"Aeris", "500 AI", DC_FAMILY_OCEANIC_VTPRO, 0x4151}, // FTDI
{"Oceanic", "Versa Pro", DC_FAMILY_OCEANIC_VTPRO, 0x4155}, {"Oceanic", "Versa Pro", DC_FAMILY_OCEANIC_VTPRO, 0x4155}, // FTDI
{"Aeris", "Atmos 2", DC_FAMILY_OCEANIC_VTPRO, 0x4158}, {"Aeris", "Atmos 2", DC_FAMILY_OCEANIC_VTPRO, 0x4158}, // FTDI
{"Oceanic", "Pro Plus 2", DC_FAMILY_OCEANIC_VTPRO, 0x4159}, {"Oceanic", "Pro Plus 2", DC_FAMILY_OCEANIC_VTPRO, 0x4159}, // FTDI
{"Aeris", "Atmos AI", DC_FAMILY_OCEANIC_VTPRO, 0x4244}, {"Aeris", "Atmos AI", DC_FAMILY_OCEANIC_VTPRO, 0x4244}, // FTDI
{"Oceanic", "VT Pro", DC_FAMILY_OCEANIC_VTPRO, 0x4245}, {"Oceanic", "VT Pro", DC_FAMILY_OCEANIC_VTPRO, 0x4245}, // FTDI
{"Sherwood", "Wisdom", DC_FAMILY_OCEANIC_VTPRO, 0x4246}, {"Sherwood", "Wisdom", DC_FAMILY_OCEANIC_VTPRO, 0x4246}, // FTDI
{"Aeris", "Elite", DC_FAMILY_OCEANIC_VTPRO, 0x424F}, {"Aeris", "Elite", DC_FAMILY_OCEANIC_VTPRO, 0x424F}, // FTDI
/* Oceanic Veo 250 */ /* Oceanic Veo 250 */
{"Genesis", "React Pro", DC_FAMILY_OCEANIC_VEO250, 0x4247}, {"Genesis", "React Pro", DC_FAMILY_OCEANIC_VEO250, 0x4247}, // FTDI
{"Oceanic", "Veo 200", DC_FAMILY_OCEANIC_VEO250, 0x424B}, {"Oceanic", "Veo 200", DC_FAMILY_OCEANIC_VEO250, 0x424B}, // FTDI
{"Oceanic", "Veo 250", DC_FAMILY_OCEANIC_VEO250, 0x424C}, {"Oceanic", "Veo 250", DC_FAMILY_OCEANIC_VEO250, 0x424C}, // FTDI
{"Seemann", "XP5", DC_FAMILY_OCEANIC_VEO250, 0x4251}, {"Seemann", "XP5", DC_FAMILY_OCEANIC_VEO250, 0x4251}, // FTDI
{"Oceanic", "Veo 180", DC_FAMILY_OCEANIC_VEO250, 0x4252}, {"Oceanic", "Veo 180", DC_FAMILY_OCEANIC_VEO250, 0x4252}, // FTDI
{"Aeris", "XR-2", DC_FAMILY_OCEANIC_VEO250, 0x4255}, {"Aeris", "XR-2", DC_FAMILY_OCEANIC_VEO250, 0x4255}, // FTDI
{"Sherwood", "Insight", DC_FAMILY_OCEANIC_VEO250, 0x425A}, {"Sherwood", "Insight", DC_FAMILY_OCEANIC_VEO250, 0x425A}, // FTDI
{"Hollis", "DG02", DC_FAMILY_OCEANIC_VEO250, 0x4352}, {"Hollis", "DG02", DC_FAMILY_OCEANIC_VEO250, 0x4352}, // FTDI
/* Oceanic Atom 2.0 */ /* Oceanic Atom 2.0 */
{"Oceanic", "Atom 1.0", DC_FAMILY_OCEANIC_ATOM2, 0x4250}, {"Oceanic", "Atom 1.0", DC_FAMILY_OCEANIC_ATOM2, 0x4250}, // FTDI
{"Aeris", "Epic", DC_FAMILY_OCEANIC_ATOM2, 0x4257}, {"Aeris", "Epic", DC_FAMILY_OCEANIC_ATOM2, 0x4257}, // FTDI
{"Oceanic", "VT3", DC_FAMILY_OCEANIC_ATOM2, 0x4258}, {"Oceanic", "VT3", DC_FAMILY_OCEANIC_ATOM2, 0x4258}, // FTDI
{"Aeris", "Elite T3", DC_FAMILY_OCEANIC_ATOM2, 0x4259}, {"Aeris", "Elite T3", DC_FAMILY_OCEANIC_ATOM2, 0x4259}, // FTDI
{"Oceanic", "Atom 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4342}, {"Oceanic", "Atom 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4342}, // FTDI
{"Oceanic", "Geo", DC_FAMILY_OCEANIC_ATOM2, 0x4344}, {"Oceanic", "Geo", DC_FAMILY_OCEANIC_ATOM2, 0x4344}, // FTDI
{"Aeris", "Manta", DC_FAMILY_OCEANIC_ATOM2, 0x4345}, {"Aeris", "Manta", DC_FAMILY_OCEANIC_ATOM2, 0x4345}, // FTDI
{"Aeris", "XR-1 NX", DC_FAMILY_OCEANIC_ATOM2, 0x4346}, {"Aeris", "XR-1 NX", DC_FAMILY_OCEANIC_ATOM2, 0x4346}, // FTDI
{"Oceanic", "Datamask", DC_FAMILY_OCEANIC_ATOM2, 0x4347}, {"Oceanic", "Datamask", DC_FAMILY_OCEANIC_ATOM2, 0x4347}, // FTDI
{"Aeris", "Compumask", DC_FAMILY_OCEANIC_ATOM2, 0x4348}, {"Aeris", "Compumask", DC_FAMILY_OCEANIC_ATOM2, 0x4348}, // FTDI
{"Aeris", "F10", DC_FAMILY_OCEANIC_ATOM2, 0x434D}, {"Aeris", "F10", DC_FAMILY_OCEANIC_ATOM2, 0x434D}, // FTDI
{"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x434E}, {"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x434E}, // FTDI
{"Sherwood", "Wisdom 2", DC_FAMILY_OCEANIC_ATOM2, 0x4350}, {"Sherwood", "Wisdom 2", DC_FAMILY_OCEANIC_ATOM2, 0x4350}, // FTDI
{"Sherwood", "Insight 2", DC_FAMILY_OCEANIC_ATOM2, 0x4353}, {"Sherwood", "Insight 2", DC_FAMILY_OCEANIC_ATOM2, 0x4353}, // FTDI
{"Genesis", "React Pro White", DC_FAMILY_OCEANIC_ATOM2, 0x4354}, {"Genesis", "React Pro White", DC_FAMILY_OCEANIC_ATOM2, 0x4354}, // FTDI
{"Tusa", "Element II (IQ-750)", DC_FAMILY_OCEANIC_ATOM2, 0x4357}, {"Tusa", "Element II (IQ-750)", DC_FAMILY_OCEANIC_ATOM2, 0x4357}, // FTDI
{"Oceanic", "Veo 1.0", DC_FAMILY_OCEANIC_ATOM2, 0x4358}, {"Oceanic", "Veo 1.0", DC_FAMILY_OCEANIC_ATOM2, 0x4358}, // FTDI
{"Oceanic", "Veo 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4359}, {"Oceanic", "Veo 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4359}, // FTDI
{"Oceanic", "Veo 3.0", DC_FAMILY_OCEANIC_ATOM2, 0x435A}, {"Oceanic", "Veo 3.0", DC_FAMILY_OCEANIC_ATOM2, 0x435A}, // FTDI
{"Tusa", "Zen (IQ-900)", DC_FAMILY_OCEANIC_ATOM2, 0x4441}, {"Tusa", "Zen (IQ-900)", DC_FAMILY_OCEANIC_ATOM2, 0x4441}, // FTDI
{"Tusa", "Zen Air (IQ-950)", DC_FAMILY_OCEANIC_ATOM2, 0x4442}, {"Tusa", "Zen Air (IQ-950)", DC_FAMILY_OCEANIC_ATOM2, 0x4442}, // FTDI
{"Aeris", "Atmos AI 2", DC_FAMILY_OCEANIC_ATOM2, 0x4443}, {"Aeris", "Atmos AI 2", DC_FAMILY_OCEANIC_ATOM2, 0x4443}, // FTDI
{"Oceanic", "Pro Plus 2.1", DC_FAMILY_OCEANIC_ATOM2, 0x4444}, {"Oceanic", "Pro Plus 2.1", DC_FAMILY_OCEANIC_ATOM2, 0x4444}, // FTDI
{"Oceanic", "Geo 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4446}, {"Oceanic", "Geo 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4446}, // FTDI
{"Oceanic", "VT4", DC_FAMILY_OCEANIC_ATOM2, 0x4447}, {"Oceanic", "VT4", DC_FAMILY_OCEANIC_ATOM2, 0x4447}, // FTDI
{"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x4449}, {"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x4449}, // FTDI
{"Beuchat", "Voyager 2G", DC_FAMILY_OCEANIC_ATOM2, 0x444B}, {"Beuchat", "Voyager 2G", DC_FAMILY_OCEANIC_ATOM2, 0x444B}, // FTDI
{"Oceanic", "Atom 3.0", DC_FAMILY_OCEANIC_ATOM2, 0x444C}, {"Oceanic", "Atom 3.0", DC_FAMILY_OCEANIC_ATOM2, 0x444C}, // FTDI
{"Hollis", "DG03", DC_FAMILY_OCEANIC_ATOM2, 0x444D}, {"Hollis", "DG03", DC_FAMILY_OCEANIC_ATOM2, 0x444D}, // FTDI
{"Oceanic", "OCS", DC_FAMILY_OCEANIC_ATOM2, 0x4450}, {"Oceanic", "OCS", DC_FAMILY_OCEANIC_ATOM2, 0x4450}, // FTDI
{"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x4451}, {"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x4451}, // FTDI
{"Oceanic", "VT 4.1", DC_FAMILY_OCEANIC_ATOM2, 0x4452}, {"Oceanic", "VT 4.1", DC_FAMILY_OCEANIC_ATOM2, 0x4452}, // FTDI
{"Aeris", "Epic", DC_FAMILY_OCEANIC_ATOM2, 0x4453}, {"Aeris", "Epic", DC_FAMILY_OCEANIC_ATOM2, 0x4453}, // FTDI
{"Aeris", "Elite T3", DC_FAMILY_OCEANIC_ATOM2, 0x4455}, {"Aeris", "Elite T3", DC_FAMILY_OCEANIC_ATOM2, 0x4455}, // FTDI
{"Oceanic", "Atom 3.1", DC_FAMILY_OCEANIC_ATOM2, 0x4456}, {"Oceanic", "Atom 3.1", DC_FAMILY_OCEANIC_ATOM2, 0x4456}, // FTDI
{"Aeris", "A300 AI", DC_FAMILY_OCEANIC_ATOM2, 0x4457}, {"Aeris", "A300 AI", DC_FAMILY_OCEANIC_ATOM2, 0x4457}, // FTDI
{"Sherwood", "Wisdom 3", DC_FAMILY_OCEANIC_ATOM2, 0x4458}, {"Sherwood", "Wisdom 3", DC_FAMILY_OCEANIC_ATOM2, 0x4458}, // FTDI
{"Aeris", "A300", DC_FAMILY_OCEANIC_ATOM2, 0x445A}, {"Aeris", "A300", DC_FAMILY_OCEANIC_ATOM2, 0x445A}, // FTDI
{"Hollis", "TX1", DC_FAMILY_OCEANIC_ATOM2, 0x4542}, {"Hollis", "TX1", DC_FAMILY_OCEANIC_ATOM2, 0x4542}, // FTDI
{"Beuchat", "Mundial 2", DC_FAMILY_OCEANIC_ATOM2, 0x4543}, {"Beuchat", "Mundial 2", DC_FAMILY_OCEANIC_ATOM2, 0x4543}, // FTDI
{"Sherwood", "Amphos", DC_FAMILY_OCEANIC_ATOM2, 0x4545}, {"Sherwood", "Amphos", DC_FAMILY_OCEANIC_ATOM2, 0x4545}, // FTDI
{"Sherwood", "Amphos Air", DC_FAMILY_OCEANIC_ATOM2, 0x4546}, {"Sherwood", "Amphos Air", DC_FAMILY_OCEANIC_ATOM2, 0x4546}, // FTDI
{"Oceanic", "Pro Plus 3", DC_FAMILY_OCEANIC_ATOM2, 0x4548}, {"Oceanic", "Pro Plus 3", DC_FAMILY_OCEANIC_ATOM2, 0x4548}, // FTDI
{"Aeris", "F11", DC_FAMILY_OCEANIC_ATOM2, 0x4549}, {"Aeris", "F11", DC_FAMILY_OCEANIC_ATOM2, 0x4549}, // FTDI
{"Oceanic", "OCi", DC_FAMILY_OCEANIC_ATOM2, 0x454B}, {"Oceanic", "OCi", DC_FAMILY_OCEANIC_ATOM2, 0x454B}, // FTDI
{"Aeris", "A300CS", DC_FAMILY_OCEANIC_ATOM2, 0x454C}, {"Aeris", "A300CS", DC_FAMILY_OCEANIC_ATOM2, 0x454C}, // FTDI
{"Beuchat", "Mundial 3", DC_FAMILY_OCEANIC_ATOM2, 0x4550}, {"Beuchat", "Mundial 3", DC_FAMILY_OCEANIC_ATOM2, 0x4550}, // FTDI
{"Oceanic", "F10", DC_FAMILY_OCEANIC_ATOM2, 0x4553}, {"Oceanic", "F10", DC_FAMILY_OCEANIC_ATOM2, 0x4553}, // FTDI
{"Oceanic", "F11", DC_FAMILY_OCEANIC_ATOM2, 0x4554}, {"Oceanic", "F11", DC_FAMILY_OCEANIC_ATOM2, 0x4554}, // FTDI
{"Subgear", "XP-Air", DC_FAMILY_OCEANIC_ATOM2, 0x4555}, {"Subgear", "XP-Air", DC_FAMILY_OCEANIC_ATOM2, 0x4555}, // FTDI
{"Sherwood", "Vision", DC_FAMILY_OCEANIC_ATOM2, 0x4556}, {"Sherwood", "Vision", DC_FAMILY_OCEANIC_ATOM2, 0x4556}, // FTDI
{"Oceanic", "VTX", DC_FAMILY_OCEANIC_ATOM2, 0x4557}, {"Oceanic", "VTX", DC_FAMILY_OCEANIC_ATOM2, 0x4557}, // FTDI
{"Aqualung", "i300", DC_FAMILY_OCEANIC_ATOM2, 0x4559}, {"Aqualung", "i300", DC_FAMILY_OCEANIC_ATOM2, 0x4559}, // FTDI
{"Aqualung", "i750TC", DC_FAMILY_OCEANIC_ATOM2, 0x455A}, {"Aqualung", "i750TC", DC_FAMILY_OCEANIC_ATOM2, 0x455A}, // FTDI
{"Aqualung", "i450T", DC_FAMILY_OCEANIC_ATOM2, 0x4641}, {"Aqualung", "i450T", DC_FAMILY_OCEANIC_ATOM2, 0x4641}, // FTDI
{"Aqualung", "i550", DC_FAMILY_OCEANIC_ATOM2, 0x4642}, {"Aqualung", "i550", DC_FAMILY_OCEANIC_ATOM2, 0x4642}, // FTDI
{"Aqualung", "i200", DC_FAMILY_OCEANIC_ATOM2, 0x4646}, {"Aqualung", "i200", DC_FAMILY_OCEANIC_ATOM2, 0x4646}, // FTDI
/* Mares Nemo */ /* Mares Nemo */
{"Mares", "Nemo", DC_FAMILY_MARES_NEMO, 0}, {"Mares", "Nemo", DC_FAMILY_MARES_NEMO, 0},
{"Mares", "Nemo Steel", DC_FAMILY_MARES_NEMO, 0}, {"Mares", "Nemo Steel", DC_FAMILY_MARES_NEMO, 0},
@ -251,22 +252,22 @@ static const dc_descriptor_t g_descriptors[] = {
{"Mares", "Puck 2", DC_FAMILY_MARES_ICONHD , 0x1F}, {"Mares", "Puck 2", DC_FAMILY_MARES_ICONHD , 0x1F},
{"Mares", "Quad", DC_FAMILY_MARES_ICONHD , 0x29}, {"Mares", "Quad", DC_FAMILY_MARES_ICONHD , 0x29},
/* Heinrichs Weikamp */ /* Heinrichs Weikamp */
{"Heinrichs Weikamp", "OSTC", DC_FAMILY_HW_OSTC, 0}, {"Heinrichs Weikamp", "OSTC", DC_FAMILY_HW_OSTC, 0}, // FTDI
{"Heinrichs Weikamp", "OSTC Mk2", DC_FAMILY_HW_OSTC, 1}, {"Heinrichs Weikamp", "OSTC Mk2", DC_FAMILY_HW_OSTC, 1}, // FTDI
{"Heinrichs Weikamp", "OSTC 2N", DC_FAMILY_HW_OSTC, 2}, {"Heinrichs Weikamp", "OSTC 2N", DC_FAMILY_HW_OSTC, 2}, // FTDI
{"Heinrichs Weikamp", "OSTC 2C", DC_FAMILY_HW_OSTC, 3}, {"Heinrichs Weikamp", "OSTC 2C", DC_FAMILY_HW_OSTC, 3}, // FTDI
{"Heinrichs Weikamp", "Frog", DC_FAMILY_HW_FROG, 0}, {"Heinrichs Weikamp", "Frog", DC_FAMILY_HW_FROG, 0}, // FTDI
{"Heinrichs Weikamp", "OSTC 2", DC_FAMILY_HW_OSTC3, 0x11}, {"Heinrichs Weikamp", "OSTC 2", DC_FAMILY_HW_OSTC3, 0x11}, // FTDI
{"Heinrichs Weikamp", "OSTC 2", DC_FAMILY_HW_OSTC3, 0x13}, {"Heinrichs Weikamp", "OSTC 2", DC_FAMILY_HW_OSTC3, 0x13}, // FTDI
{"Heinrichs Weikamp", "OSTC 2", DC_FAMILY_HW_OSTC3, 0x1B}, {"Heinrichs Weikamp", "OSTC 2", DC_FAMILY_HW_OSTC3, 0x1B}, // FTDI
{"Heinrichs Weikamp", "OSTC 3", DC_FAMILY_HW_OSTC3, 0x0A}, {"Heinrichs Weikamp", "OSTC 3", DC_FAMILY_HW_OSTC3, 0x0A}, // FTDI
{"Heinrichs Weikamp", "OSTC Plus", DC_FAMILY_HW_OSTC3, 0x13}, {"Heinrichs Weikamp", "OSTC Plus", DC_FAMILY_HW_OSTC3, 0x13}, // FTDI // BT
{"Heinrichs Weikamp", "OSTC Plus", DC_FAMILY_HW_OSTC3, 0x1A}, {"Heinrichs Weikamp", "OSTC Plus", DC_FAMILY_HW_OSTC3, 0x1A}, // FTDI // BT
{"Heinrichs Weikamp", "OSTC 4", DC_FAMILY_HW_OSTC3, 0x3B}, {"Heinrichs Weikamp", "OSTC 4", DC_FAMILY_HW_OSTC3, 0x3B}, // BT
{"Heinrichs Weikamp", "OSTC cR", DC_FAMILY_HW_OSTC3, 0x05}, {"Heinrichs Weikamp", "OSTC cR", DC_FAMILY_HW_OSTC3, 0x05}, // FTDI
{"Heinrichs Weikamp", "OSTC cR", DC_FAMILY_HW_OSTC3, 0x07}, {"Heinrichs Weikamp", "OSTC cR", DC_FAMILY_HW_OSTC3, 0x07}, // FTDI
{"Heinrichs Weikamp", "OSTC Sport", DC_FAMILY_HW_OSTC3, 0x12}, {"Heinrichs Weikamp", "OSTC Sport", DC_FAMILY_HW_OSTC3, 0x12}, // FTDI // BT
{"Heinrichs Weikamp", "OSTC Sport", DC_FAMILY_HW_OSTC3, 0x13}, {"Heinrichs Weikamp", "OSTC Sport", DC_FAMILY_HW_OSTC3, 0x13}, // FTDI // BT
/* Cressi Edy */ /* Cressi Edy */
{"Tusa", "IQ-700", DC_FAMILY_CRESSI_EDY, 0x05}, {"Tusa", "IQ-700", DC_FAMILY_CRESSI_EDY, 0x05},
{"Cressi", "Edy", DC_FAMILY_CRESSI_EDY, 0x08}, {"Cressi", "Edy", DC_FAMILY_CRESSI_EDY, 0x08},
@ -286,14 +287,14 @@ static const dc_descriptor_t g_descriptors[] = {
{"Atomic Aquatics", "Cobalt 2", DC_FAMILY_ATOMICS_COBALT, 2}, {"Atomic Aquatics", "Cobalt 2", DC_FAMILY_ATOMICS_COBALT, 2},
#endif #endif
/* Shearwater Predator */ /* Shearwater Predator */
{"Shearwater", "Predator", DC_FAMILY_SHEARWATER_PREDATOR, 2}, {"Shearwater", "Predator", DC_FAMILY_SHEARWATER_PREDATOR, 2}, // BT
/* Shearwater Petrel */ /* Shearwater Petrel family */
{"Shearwater", "Petrel", DC_FAMILY_SHEARWATER_PETREL, 3}, {"Shearwater", "Petrel", DC_FAMILY_SHEARWATER_PETREL, 3}, // BT // BLE
{"Shearwater", "Petrel 2", DC_FAMILY_SHEARWATER_PETREL, 3}, {"Shearwater", "Petrel 2", DC_FAMILY_SHEARWATER_PETREL, 3}, // BT // BLE
{"Shearwater", "Nerd", DC_FAMILY_SHEARWATER_PETREL, 4}, {"Shearwater", "Nerd", DC_FAMILY_SHEARWATER_PETREL, 4}, // BT
{"Shearwater", "Nerd 2", DC_FAMILY_SHEARWATER_PETREL, 4}, {"Shearwater", "Nerd 2", DC_FAMILY_SHEARWATER_PETREL, 4}, // BLE
{"Shearwater", "Perdix", DC_FAMILY_SHEARWATER_PETREL, 5}, {"Shearwater", "Perdix", DC_FAMILY_SHEARWATER_PETREL, 5}, // BT // BLE
{"Shearwater", "Perdix AI", DC_FAMILY_SHEARWATER_PETREL, 6}, {"Shearwater", "Perdix AI", DC_FAMILY_SHEARWATER_PETREL, 6}, // BLE
/* Dive Rite NiTek Q */ /* Dive Rite NiTek Q */
{"Dive Rite", "NiTek Q", DC_FAMILY_DIVERITE_NITEKQ, 0}, {"Dive Rite", "NiTek Q", DC_FAMILY_DIVERITE_NITEKQ, 0},
/* Citizen Hyper Aqualand */ /* Citizen Hyper Aqualand */
@ -321,12 +322,12 @@ static const dc_descriptor_t g_descriptors[] = {
{"Ratio", "iDive Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x44}, {"Ratio", "iDive Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x44},
{"Ratio", "iDive Tech+", DC_FAMILY_DIVESYSTEM_IDIVE, 0x45}, {"Ratio", "iDive Tech+", DC_FAMILY_DIVESYSTEM_IDIVE, 0x45},
/* Cochran Commander */ /* Cochran Commander */
{"Cochran", "Commander TM", DC_FAMILY_COCHRAN_COMMANDER, 0}, {"Cochran", "Commander TM", DC_FAMILY_COCHRAN_COMMANDER, 0}, // FTDI
{"Cochran", "Commander I", DC_FAMILY_COCHRAN_COMMANDER, 1}, {"Cochran", "Commander I", DC_FAMILY_COCHRAN_COMMANDER, 1}, // FTDI
{"Cochran", "Commander II", DC_FAMILY_COCHRAN_COMMANDER, 2}, {"Cochran", "Commander II", DC_FAMILY_COCHRAN_COMMANDER, 2}, // FTDI
{"Cochran", "EMC-14", DC_FAMILY_COCHRAN_COMMANDER, 3}, {"Cochran", "EMC-14", DC_FAMILY_COCHRAN_COMMANDER, 3}, // FTDI
{"Cochran", "EMC-16", DC_FAMILY_COCHRAN_COMMANDER, 4}, {"Cochran", "EMC-16", DC_FAMILY_COCHRAN_COMMANDER, 4}, // FTDI
{"Cochran", "EMC-20H", DC_FAMILY_COCHRAN_COMMANDER, 5}, {"Cochran", "EMC-20H", DC_FAMILY_COCHRAN_COMMANDER, 5}, // FTDI
}; };
typedef struct dc_descriptor_iterator_t { typedef struct dc_descriptor_iterator_t {
@ -433,6 +434,15 @@ dc_descriptor_get_model (dc_descriptor_t *descriptor)
return descriptor->model; return descriptor->model;
} }
unsigned int
dc_descriptor_get_serial (dc_descriptor_t *descriptor)
{
if (descriptor == NULL)
return 0;
return descriptor->serial;
}
dc_transport_t dc_transport_t
dc_descriptor_get_transport (dc_descriptor_t *descriptor) dc_descriptor_get_transport (dc_descriptor_t *descriptor)
{ {

View File

@ -33,7 +33,6 @@
#include "reefnet_sensuspro.h" #include "reefnet_sensuspro.h"
#include "reefnet_sensusultra.h" #include "reefnet_sensusultra.h"
#include "uwatec_aladin.h" #include "uwatec_aladin.h"
#include "uwatec_g2.h"
#include "uwatec_memomouse.h" #include "uwatec_memomouse.h"
#include "uwatec_meridian.h" #include "uwatec_meridian.h"
#include "uwatec_smart.h" #include "uwatec_smart.h"
@ -51,6 +50,7 @@
#include "cressi_leonardo.h" #include "cressi_leonardo.h"
#include "zeagle_n2ition3.h" #include "zeagle_n2ition3.h"
#include "atomics_cobalt.h" #include "atomics_cobalt.h"
#include "scubapro_g2.h"
#include "shearwater_petrel.h" #include "shearwater_petrel.h"
#include "shearwater_predator.h" #include "shearwater_predator.h"
#include "diverite_nitekq.h" #include "diverite_nitekq.h"
@ -125,7 +125,7 @@ dc_device_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descr
rc = suunto_d9_device_open (&device, context, name, dc_descriptor_get_model (descriptor)); rc = suunto_d9_device_open (&device, context, name, dc_descriptor_get_model (descriptor));
break; break;
case DC_FAMILY_SUUNTO_EONSTEEL: case DC_FAMILY_SUUNTO_EONSTEEL:
rc = suunto_eonsteel_device_open (&device, context, dc_descriptor_get_model (descriptor)); rc = suunto_eonsteel_device_open (&device, context, name, dc_descriptor_get_model(descriptor));
break; break;
case DC_FAMILY_UWATEC_ALADIN: case DC_FAMILY_UWATEC_ALADIN:
rc = uwatec_aladin_device_open (&device, context, name); rc = uwatec_aladin_device_open (&device, context, name);
@ -140,7 +140,7 @@ dc_device_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descr
rc = uwatec_meridian_device_open (&device, context, name); rc = uwatec_meridian_device_open (&device, context, name);
break; break;
case DC_FAMILY_UWATEC_G2: case DC_FAMILY_UWATEC_G2:
rc = uwatec_g2_device_open (&device, context, dc_descriptor_get_model (descriptor)); rc = scubapro_g2_device_open (&device, context, name, dc_descriptor_get_model (descriptor));
break; break;
case DC_FAMILY_REEFNET_SENSUS: case DC_FAMILY_REEFNET_SENSUS:
rc = reefnet_sensus_device_open (&device, context, name); rc = reefnet_sensus_device_open (&device, context, name);

View File

@ -35,7 +35,7 @@ dc_status_t
hw_ostc_device_open (dc_device_t **device, dc_context_t *context, const char *name); hw_ostc_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t dc_status_t
hw_ostc_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int hwos); hw_ostc_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int serial, unsigned int hwos);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -35,7 +35,7 @@ dc_status_t
hw_ostc3_device_open (dc_device_t **device, dc_context_t *context, const char *name); hw_ostc3_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t dc_status_t
hw_ostc3_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model); hw_ostc3_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int serial, unsigned int model);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -20,6 +20,12 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include "libdivecomputer/units.h" #include "libdivecomputer/units.h"
@ -61,8 +67,14 @@
#define OSTC3_APNEA 3 #define OSTC3_APNEA 3
#define OSTC3_PSCR 4 #define OSTC3_PSCR 4
#define OSTC3_ZHL16 0
#define OSTC3_ZHL16_GF 1
#define OSTC4_VPM 2
#define OSTC4 0x3B #define OSTC4 0x3B
#define UNSUPPORTED 0xFFFFFFFF
typedef struct hw_ostc_sample_info_t { typedef struct hw_ostc_sample_info_t {
unsigned int type; unsigned int type;
unsigned int divisor; unsigned int divisor;
@ -78,7 +90,13 @@ typedef struct hw_ostc_layout_t {
unsigned int salinity; unsigned int salinity;
unsigned int duration; unsigned int duration;
unsigned int temperature; unsigned int temperature;
unsigned int battery;
unsigned int desat;
unsigned int firmware; unsigned int firmware;
unsigned int deco_info1;
unsigned int deco_info2;
unsigned int decomode;
unsigned int battery_percentage;
} hw_ostc_layout_t; } hw_ostc_layout_t;
typedef struct hw_ostc_gasmix_t { typedef struct hw_ostc_gasmix_t {
@ -90,6 +108,7 @@ typedef struct hw_ostc_parser_t {
dc_parser_t base; dc_parser_t base;
unsigned int hwos; unsigned int hwos;
unsigned int model; unsigned int model;
unsigned int serial;
// Cached fields. // Cached fields.
unsigned int cached; unsigned int cached;
unsigned int version; unsigned int version;
@ -127,7 +146,13 @@ static const hw_ostc_layout_t hw_ostc_layout_ostc = {
43, /* salinity */ 43, /* salinity */
47, /* duration */ 47, /* duration */
13, /* temperature */ 13, /* temperature */
34, /* battery volt after dive */
17, /* desat */
32, /* firmware */ 32, /* firmware */
49, /* deco_info1 */
50, /* deco_info1 */
51, /* decomode */
0, /* battery percentage TBD */
}; };
static const hw_ostc_layout_t hw_ostc_layout_frog = { static const hw_ostc_layout_t hw_ostc_layout_frog = {
@ -139,7 +164,13 @@ static const hw_ostc_layout_t hw_ostc_layout_frog = {
43, /* salinity */ 43, /* salinity */
47, /* duration */ 47, /* duration */
19, /* temperature */ 19, /* temperature */
34, /* battery volt after dive */
23, /* desat */
32, /* firmware */ 32, /* firmware */
49, /* deco_info1 */
50, /* deco_info2 */
51, /* decomode */
0, /* battery percentage TBD */
}; };
static const hw_ostc_layout_t hw_ostc_layout_ostc3 = { static const hw_ostc_layout_t hw_ostc_layout_ostc3 = {
@ -151,7 +182,13 @@ static const hw_ostc_layout_t hw_ostc_layout_ostc3 = {
70, /* salinity */ 70, /* salinity */
75, /* duration */ 75, /* duration */
22, /* temperature */ 22, /* temperature */
50, /* battery volt after dive */
26, /* desat */
48, /* firmware */ 48, /* firmware */
77, /* deco_info1 */
78, /* deco_info2 */
79, /* decomode */
59, /* battery percentage */
}; };
static unsigned int static unsigned int
@ -251,7 +288,7 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser)
} }
} }
// The first fixed setpoint is the initial setpoint in CCR mode. // The first fixed setpoint is the initial setpoint in CCR mode.
if (data[82] == OSTC3_CC) { if (data[82] == OSTC3_CC) {
initial_setpoint = data[60]; initial_setpoint = data[60];
} }
// Initial CNS // Initial CNS
@ -294,7 +331,7 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser)
} }
static dc_status_t static dc_status_t
hw_ostc_parser_create_internal (dc_parser_t **out, dc_context_t *context, unsigned int hwos, unsigned int model) hw_ostc_parser_create_internal (dc_parser_t **out, dc_context_t *context, unsigned int serial, unsigned int hwos, unsigned int model)
{ {
hw_ostc_parser_t *parser = NULL; hw_ostc_parser_t *parser = NULL;
@ -324,6 +361,7 @@ hw_ostc_parser_create_internal (dc_parser_t **out, dc_context_t *context, unsign
parser->gasmix[i].oxygen = 0; parser->gasmix[i].oxygen = 0;
parser->gasmix[i].helium = 0; parser->gasmix[i].helium = 0;
} }
parser->serial = serial;
*out = (dc_parser_t *) parser; *out = (dc_parser_t *) parser;
@ -332,15 +370,15 @@ hw_ostc_parser_create_internal (dc_parser_t **out, dc_context_t *context, unsign
dc_status_t dc_status_t
hw_ostc_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int hwos) hw_ostc_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int serial, unsigned int hwos)
{ {
return hw_ostc_parser_create_internal (out, context, hwos, 0); return hw_ostc_parser_create_internal (out, context, serial, hwos, 0);
} }
dc_status_t dc_status_t
hw_ostc3_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) hw_ostc3_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int serial, unsigned int model)
{ {
return hw_ostc_parser_create_internal (out, context, 1, model); return hw_ostc_parser_create_internal (out, context, serial, 1, model);
} }
static dc_status_t static dc_status_t
@ -428,6 +466,8 @@ hw_ostc_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime)
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }
#define BUFLEN 32
static dc_status_t static dc_status_t
hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value) hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value)
{ {
@ -452,9 +492,12 @@ hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned
dc_gasmix_t *gasmix = (dc_gasmix_t *) value; dc_gasmix_t *gasmix = (dc_gasmix_t *) value;
dc_salinity_t *water = (dc_salinity_t *) value; dc_salinity_t *water = (dc_salinity_t *) value;
dc_field_string_t *string = (dc_field_string_t *) value;
unsigned int salinity = data[layout->salinity]; unsigned int salinity = data[layout->salinity];
if (version == 0x23 || version == 0x24) if (version == 0x23 || version == 0x24)
salinity += 100; salinity += 100;
char buf[BUFLEN];
if (value) { if (value) {
switch (type) { switch (type) {
@ -550,6 +593,79 @@ hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned
return DC_STATUS_UNSUPPORTED; return DC_STATUS_UNSUPPORTED;
} }
break; break;
case DC_FIELD_STRING:
switch(flags) {
case 0: /* serial */
string->desc = "Serial";
snprintf(buf, BUFLEN, "%u", parser->serial);
break;
case 1: /* battery */
string->desc = "Battery at end";
unsigned int percentage = (unsigned int) data[layout->battery_percentage];
if (percentage != 0xFF && (version == 0x23 || version == 0x24)) {
percentage = percentage>100? 100: percentage;
snprintf(buf, BUFLEN, "%.2fV, %u%% remaining",
array_uint16_le (data + layout->battery) / 1000.0,
percentage);
} else {
snprintf(buf, BUFLEN, "%.2fV", array_uint16_le (data + layout->battery) / 1000.0);
}
break;
case 2: /* desat */
string->desc = "Desat time";
snprintf(buf, BUFLEN, "%0u:%02u", array_uint16_le (data + layout->desat) / 60,
array_uint16_le (data + layout->desat) % 60);
break;
case 3: /* firmware */
string->desc = "FW Version";
/* OSTC4 stores firmware as XXXX XYYY YYZZ ZZZB, -> X.Y.Z beta? */
if (parser->model == OSTC4) {
int firmwareOnDevice = array_uint16_le (data + layout->firmware);
unsigned char X = 0, Y = 0, Z = 0, beta = 0;
X = (firmwareOnDevice & 0xF800) >> 11;
Y = (firmwareOnDevice & 0x07C0) >> 6;
Z = (firmwareOnDevice & 0x003E) >> 1;
beta = firmwareOnDevice & 0x0001;
snprintf(buf, BUFLEN, "%u.%u.%u%s\n", X, Y, Z, beta? "beta": "");
} else {
snprintf(buf, BUFLEN, "%0u.%02u", data[layout->firmware], data[layout->firmware + 1]);
}
break;
case 4: /* Deco model */
string->desc = "Deco model";
if (((version == 0x23 || version == 0x24) && data[layout->decomode] == OSTC3_ZHL16) ||
(version == 0x22 && data[layout->decomode] == FROG_ZHL16) ||
(version == 0x21 && (data[layout->decomode] == OSTC_ZHL16_OC || data[layout->decomode] == OSTC_ZHL16_CC)))
strncpy(buf, "ZH-L16", BUFLEN);
else if (((version == 0x23 || version == 0x24) && data[layout->decomode] == OSTC3_ZHL16_GF) ||
(version == 0x22 && data[layout->decomode] == FROG_ZHL16_GF) ||
(version == 0x21 && (data[layout->decomode] == OSTC_ZHL16_OC_GF || data[layout->decomode] == OSTC_ZHL16_CC_GF)))
strncpy(buf, "ZH-L16-GF", BUFLEN);
else if (((version == 0x24) && data[layout->decomode] == OSTC4_VPM))
strncpy(buf, "VPM", BUFLEN);
else
return DC_STATUS_DATAFORMAT;
break;
case 5: /* Deco model info */
string->desc = "Deco model info";
if (((version == 0x23 || version == 0x24) && data[layout->decomode] == OSTC3_ZHL16) ||
(version == 0x22 && data[layout->decomode] == FROG_ZHL16) ||
(version == 0x21 && (data[layout->decomode] == OSTC_ZHL16_OC || data[layout->decomode] == OSTC_ZHL16_CC)))
snprintf(buf, BUFLEN, "Saturation %u, Desaturation %u", layout->deco_info1, layout->deco_info2);
else if (((version == 0x23 || version == 0x24) && data[layout->decomode] == OSTC3_ZHL16_GF) ||
(version == 0x22 && data[layout->decomode] == FROG_ZHL16_GF) ||
(version == 0x21 && (data[layout->decomode] == OSTC_ZHL16_OC_GF || data[layout->decomode] == OSTC_ZHL16_CC_GF)))
snprintf(buf, BUFLEN, "GF %u/%u", data[layout->deco_info1], data[layout->deco_info2]);
else
return DC_STATUS_DATAFORMAT;
break;
default:
return DC_STATUS_UNSUPPORTED;
}
string->value = strdup(buf);
break;
default: default:
return DC_STATUS_UNSUPPORTED; return DC_STATUS_UNSUPPORTED;
} }

View File

@ -21,6 +21,7 @@ dc_context_new
dc_context_free dc_context_free
dc_context_set_loglevel dc_context_set_loglevel
dc_context_set_logfunc dc_context_set_logfunc
dc_context_set_custom_io
dc_iterator_next dc_iterator_next
dc_iterator_free dc_iterator_free

View File

@ -36,7 +36,7 @@ dc_status_t
oceanic_atom2_device_open (dc_device_t **device, dc_context_t *context, const char *name, unsigned int model); oceanic_atom2_device_open (dc_device_t **device, dc_context_t *context, const char *name, unsigned int model);
dc_status_t dc_status_t
oceanic_atom2_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); oceanic_atom2_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model, unsigned int serial);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -20,6 +20,8 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <libdivecomputer/units.h> #include <libdivecomputer/units.h>
@ -102,6 +104,7 @@ struct oceanic_atom2_parser_t {
unsigned int model; unsigned int model;
unsigned int headersize; unsigned int headersize;
unsigned int footersize; unsigned int footersize;
unsigned int serial;
// Cached fields. // Cached fields.
unsigned int cached; unsigned int cached;
unsigned int header; unsigned int header;
@ -131,7 +134,7 @@ static const dc_parser_vtable_t oceanic_atom2_parser_vtable = {
dc_status_t dc_status_t
oceanic_atom2_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) oceanic_atom2_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int serial)
{ {
oceanic_atom2_parser_t *parser = NULL; oceanic_atom2_parser_t *parser = NULL;
@ -176,6 +179,7 @@ oceanic_atom2_parser_create (dc_parser_t **out, dc_context_t *context, unsigned
parser->headersize = 5 * PAGESIZE; parser->headersize = 5 * PAGESIZE;
} }
parser->serial = serial;
parser->cached = 0; parser->cached = 0;
parser->header = 0; parser->header = 0;
parser->footer = 0; parser->footer = 0;
@ -366,6 +370,7 @@ oceanic_atom2_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetim
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }
#define BUF_LEN 16
static dc_status_t static dc_status_t
oceanic_atom2_parser_cache (oceanic_atom2_parser_t *parser) oceanic_atom2_parser_cache (oceanic_atom2_parser_t *parser)
@ -502,6 +507,9 @@ oceanic_atom2_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, uns
dc_gasmix_t *gasmix = (dc_gasmix_t *) value; dc_gasmix_t *gasmix = (dc_gasmix_t *) value;
dc_salinity_t *water = (dc_salinity_t *) value; dc_salinity_t *water = (dc_salinity_t *) value;
dc_field_string_t *string = (dc_field_string_t *) value;
char buf[BUF_LEN];
if (value) { if (value) {
switch (type) { switch (type) {
@ -557,6 +565,17 @@ oceanic_atom2_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, uns
return DC_STATUS_DATAFORMAT; return DC_STATUS_DATAFORMAT;
} }
break; break;
case DC_FIELD_STRING:
switch(flags) {
case 0: /* Serial */
string->desc = "Serial";
snprintf(buf, BUF_LEN, "%06u", parser->serial);
break;
default:
return DC_STATUS_UNSUPPORTED;
}
string->value = strdup(buf);
break;
default: default:
return DC_STATUS_UNSUPPORTED; return DC_STATUS_UNSUPPORTED;
} }

View File

@ -51,7 +51,6 @@
#include "zeagle_n2ition3.h" #include "zeagle_n2ition3.h"
#include "atomics_cobalt.h" #include "atomics_cobalt.h"
#include "shearwater_petrel.h" #include "shearwater_petrel.h"
#include "shearwater_predator.h"
#include "diverite_nitekq.h" #include "diverite_nitekq.h"
#include "citizen_aqualand.h" #include "citizen_aqualand.h"
#include "divesystem_idive.h" #include "divesystem_idive.h"
@ -64,7 +63,7 @@
#define REACTPROWHITE 0x4354 #define REACTPROWHITE 0x4354
static dc_status_t static dc_status_t
dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t family, unsigned int model, unsigned int devtime, dc_ticks_t systime) dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t family, unsigned int model, unsigned int serial, unsigned int devtime, dc_ticks_t systime)
{ {
dc_status_t rc = DC_STATUS_SUCCESS; dc_status_t rc = DC_STATUS_SUCCESS;
dc_parser_t *parser = NULL; dc_parser_t *parser = NULL;
@ -87,7 +86,7 @@ dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t fa
break; break;
case DC_FAMILY_SUUNTO_VYPER2: case DC_FAMILY_SUUNTO_VYPER2:
case DC_FAMILY_SUUNTO_D9: case DC_FAMILY_SUUNTO_D9:
rc = suunto_d9_parser_create (&parser, context, model); rc = suunto_d9_parser_create (&parser, context, model, serial);
break; break;
case DC_FAMILY_SUUNTO_EONSTEEL: case DC_FAMILY_SUUNTO_EONSTEEL:
rc = suunto_eonsteel_parser_create(&parser, context, model); rc = suunto_eonsteel_parser_create(&parser, context, model);
@ -120,7 +119,7 @@ dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t fa
if (model == REACTPROWHITE) if (model == REACTPROWHITE)
rc = oceanic_veo250_parser_create (&parser, context, model); rc = oceanic_veo250_parser_create (&parser, context, model);
else else
rc = oceanic_atom2_parser_create (&parser, context, model); rc = oceanic_atom2_parser_create (&parser, context, model, serial);
break; break;
case DC_FAMILY_MARES_NEMO: case DC_FAMILY_MARES_NEMO:
case DC_FAMILY_MARES_PUCK: case DC_FAMILY_MARES_PUCK:
@ -133,11 +132,11 @@ dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t fa
rc = mares_iconhd_parser_create (&parser, context, model); rc = mares_iconhd_parser_create (&parser, context, model);
break; break;
case DC_FAMILY_HW_OSTC: case DC_FAMILY_HW_OSTC:
rc = hw_ostc_parser_create (&parser, context, 0); rc = hw_ostc_parser_create (&parser, context, serial, 0);
break; break;
case DC_FAMILY_HW_FROG: case DC_FAMILY_HW_FROG:
case DC_FAMILY_HW_OSTC3: case DC_FAMILY_HW_OSTC3:
rc = hw_ostc3_parser_create (&parser, context, model); rc = hw_ostc3_parser_create (&parser, context, serial, model);
break; break;
case DC_FAMILY_CRESSI_EDY: case DC_FAMILY_CRESSI_EDY:
case DC_FAMILY_ZEAGLE_N2ITION3: case DC_FAMILY_ZEAGLE_N2ITION3:
@ -150,10 +149,8 @@ dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t fa
rc = atomics_cobalt_parser_create (&parser, context); rc = atomics_cobalt_parser_create (&parser, context);
break; break;
case DC_FAMILY_SHEARWATER_PREDATOR: case DC_FAMILY_SHEARWATER_PREDATOR:
rc = shearwater_predator_parser_create (&parser, context, model);
break;
case DC_FAMILY_SHEARWATER_PETREL: case DC_FAMILY_SHEARWATER_PETREL:
rc = shearwater_petrel_parser_create (&parser, context, model); rc = shearwater_common_parser_create (&parser, context, model, serial);
break; break;
case DC_FAMILY_DIVERITE_NITEKQ: case DC_FAMILY_DIVERITE_NITEKQ:
rc = diverite_nitekq_parser_create (&parser, context); rc = diverite_nitekq_parser_create (&parser, context);
@ -183,7 +180,9 @@ dc_parser_new (dc_parser_t **out, dc_device_t *device)
return DC_STATUS_INVALIDARGS; return DC_STATUS_INVALIDARGS;
return dc_parser_new_internal (out, device->context, return dc_parser_new_internal (out, device->context,
dc_device_get_type (device), device->devinfo.model, dc_device_get_type (device),
device->devinfo.model,
device->devinfo.serial,
device->clock.devtime, device->clock.systime); device->clock.devtime, device->clock.systime);
} }
@ -191,7 +190,9 @@ dc_status_t
dc_parser_new2 (dc_parser_t **out, dc_context_t *context, dc_descriptor_t *descriptor, unsigned int devtime, dc_ticks_t systime) dc_parser_new2 (dc_parser_t **out, dc_context_t *context, dc_descriptor_t *descriptor, unsigned int devtime, dc_ticks_t systime)
{ {
return dc_parser_new_internal (out, context, return dc_parser_new_internal (out, context,
dc_descriptor_get_type (descriptor), dc_descriptor_get_model (descriptor), dc_descriptor_get_type (descriptor),
dc_descriptor_get_model (descriptor),
dc_descriptor_get_serial (descriptor),
devtime, systime); devtime, systime);
} }

View File

@ -23,119 +23,129 @@
#include <stdlib.h> // malloc, free #include <stdlib.h> // malloc, free
#include <string.h> // strncmp, strstr #include <string.h> // strncmp, strstr
#include "uwatec_g2.h" #include "scubapro_g2.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "usbhid.h" #include "usbhid.h"
#include "array.h" #include "array.h"
#include "platform.h" #include "platform.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &uwatec_g2_device_vtable) #define ISINSTANCE(device) dc_device_isinstance((device), &scubapro_g2_device_vtable)
#define RX_PACKET_SIZE 64 #define RX_PACKET_SIZE 64
#define TX_PACKET_SIZE 32 #define TX_PACKET_SIZE 32
#define ALADINSPORTMATRIX 0x17
#define ALADINSQUARE 0x22 #define ALADINSQUARE 0x22
#define G2 0x32
typedef struct uwatec_g2_device_t { typedef struct scubapro_g2_device_t {
dc_device_t base; dc_device_t base;
dc_iostream_t *iostream;
unsigned int timestamp; unsigned int timestamp;
unsigned int devtime; unsigned int devtime;
dc_ticks_t systime; dc_ticks_t systime;
} uwatec_g2_device_t; } scubapro_g2_device_t;
static dc_status_t uwatec_g2_device_set_fingerprint (dc_device_t *device, const unsigned char data[], unsigned int size); static dc_status_t scubapro_g2_device_set_fingerprint (dc_device_t *device, const unsigned char data[], unsigned int size);
static dc_status_t uwatec_g2_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t scubapro_g2_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t uwatec_g2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t scubapro_g2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t uwatec_g2_device_close (dc_device_t *abstract); static dc_status_t scubapro_g2_device_close (dc_device_t *abstract);
static const dc_device_vtable_t uwatec_g2_device_vtable = { static const dc_device_vtable_t scubapro_g2_device_vtable = {
sizeof(uwatec_g2_device_t), sizeof(scubapro_g2_device_t),
DC_FAMILY_UWATEC_G2, DC_FAMILY_UWATEC_G2,
uwatec_g2_device_set_fingerprint, /* set_fingerprint */ scubapro_g2_device_set_fingerprint, /* set_fingerprint */
NULL, /* read */ NULL, /* read */
NULL, /* write */ NULL, /* write */
uwatec_g2_device_dump, /* dump */ scubapro_g2_device_dump, /* dump */
uwatec_g2_device_foreach, /* foreach */ scubapro_g2_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
uwatec_g2_device_close /* close */ scubapro_g2_device_close /* close */
}; };
static dc_status_t static dc_status_t
uwatec_g2_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata); scubapro_g2_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
static dc_status_t static int receive_data(scubapro_g2_device_t *g2, unsigned char *buffer, int size, dc_event_progress_t *progress)
receive_data (uwatec_g2_device_t *device, dc_event_progress_t *progress, unsigned char *data, unsigned int size)
{ {
dc_custom_io_t *io = _dc_context_custom_io(g2->base.context);
while (size) { while (size) {
unsigned char buf[RX_PACKET_SIZE]; unsigned char buf[RX_PACKET_SIZE] = { 0 };
size_t transferred = 0; size_t transferred = 0;
dc_status_t rc = DC_STATUS_SUCCESS; dc_status_t rc;
unsigned int len = 0; int len;
rc = dc_iostream_read (device->iostream, buf, sizeof(buf), &transferred); rc = io->packet_read(io, buf, sizeof(buf), &transferred);
if (rc != DC_STATUS_SUCCESS) { if (rc != DC_STATUS_SUCCESS) {
ERROR (device->base.context, "read interrupt transfer failed"); ERROR(g2->base.context, "read interrupt transfer failed");
return rc; return -1;
} }
if (transferred != sizeof(buf)) { if (transferred < 1) {
ERROR (device->base.context, "incomplete read interrupt transfer (got " DC_PRINTF_SIZE ", expected " DC_PRINTF_SIZE ")", transferred, sizeof(buf)); ERROR(g2->base.context, "incomplete read interrupt transfer (got empty packet)");
return DC_STATUS_PROTOCOL; return -1;
} }
len = buf[0]; len = buf[0];
if (transferred < len + 1) {
ERROR(g2->base.context, "small packet read (got %zu, expected at least %d)", transferred, len + 1);
return -1;
}
if (len >= sizeof(buf)) { if (len >= sizeof(buf)) {
ERROR (device->base.context, "read interrupt transfer returns impossible packet size (%d)", len); ERROR(g2->base.context, "read interrupt transfer returns impossible packet size (%d)", len);
return DC_STATUS_PROTOCOL; return -1;
} }
HEXDUMP (device->base.context, DC_LOGLEVEL_DEBUG, "rcv", buf + 1, len); HEXDUMP (g2->base.context, DC_LOGLEVEL_DEBUG, "rcv", buf+1, len);
if (len > size) { if (len > size) {
ERROR (device->base.context, "receive result buffer too small"); ERROR(g2->base.context, "receive result buffer too small - truncating");
return DC_STATUS_PROTOCOL; len = size;
} }
memcpy(buffer, buf+1, len);
size -= len;
buffer += len;
// Update and emit a progress event. // Update and emit a progress event?
if (progress) { if (progress) {
progress->current += len; progress->current += len;
device_event_emit (&device->base, DC_EVENT_PROGRESS, progress); device_event_emit(&g2->base, DC_EVENT_PROGRESS, progress);
} }
memcpy(data, buf + 1, len);
size -= len;
data += len;
} }
return DC_STATUS_SUCCESS; return 0;
} }
static dc_status_t static dc_status_t
uwatec_g2_transfer (uwatec_g2_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize) scubapro_g2_transfer(scubapro_g2_device_t *g2, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize)
{ {
unsigned char buf[TX_PACKET_SIZE + 1]; dc_custom_io_t *io = _dc_context_custom_io(g2->base.context);
unsigned char buf[TX_PACKET_SIZE+1] = { 0 }; // the +1 is for the report type byte
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
size_t transferred = 0; size_t transferred = 0;
if (csize + 2 > sizeof(buf)) { if (csize > sizeof(buf)-2) {
ERROR (device->base.context, "command too big (%d)", csize); ERROR(g2->base.context, "command too big (%d)", csize);
return DC_STATUS_INVALIDARGS; return DC_STATUS_INVALIDARGS;
} }
HEXDUMP (device->base.context, DC_LOGLEVEL_DEBUG, "cmd", command, csize); HEXDUMP (g2->base.context, DC_LOGLEVEL_DEBUG, "cmd", command, csize);
buf[0] = 0; // USBHID report type
buf[1] = csize; // command size
memcpy(buf+2, command, csize); // command bytes
// BLE GATT protocol?
if (io->packet_size < 64) {
// No report type byte
status = io->packet_write(io, buf+1, csize+1, &transferred);
} else {
status = io->packet_write(io, buf, sizeof(buf), &transferred);
}
buf[0] = 0;
buf[1] = csize;
memcpy(buf + 2, command, csize);
memset(buf + 2 + csize, 0, sizeof(buf) - (csize + 2));
status = dc_iostream_write (device->iostream, buf, sizeof(buf), &transferred);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (device->base.context, "Failed to send the command."); ERROR(g2->base.context, "Failed to send the command.");
return status; return status;
} }
status = receive_data (device, NULL, answer, asize); if (receive_data(g2, answer, asize, NULL) < 0) {
if (status != DC_STATUS_SUCCESS) { ERROR(g2->base.context, "Failed to receive the answer.");
ERROR (device->base.context, "Failed to receive the answer."); return DC_STATUS_IO;
return status;
} }
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
@ -143,7 +153,7 @@ uwatec_g2_transfer (uwatec_g2_device_t *device, const unsigned char command[], u
static dc_status_t static dc_status_t
uwatec_g2_handshake (uwatec_g2_device_t *device) scubapro_g2_handshake (scubapro_g2_device_t *device, unsigned int model)
{ {
dc_device_t *abstract = (dc_device_t *) device; dc_device_t *abstract = (dc_device_t *) device;
@ -151,9 +161,14 @@ uwatec_g2_handshake (uwatec_g2_device_t *device)
unsigned char answer[1] = {0}; unsigned char answer[1] = {0};
unsigned char command[5] = {0x00, 0x10, 0x27, 0, 0}; unsigned char command[5] = {0x00, 0x10, 0x27, 0, 0};
// The vendor software does not do a handshake for the Aladin Sport Matrix,
// so let's not do any either.
if (model == ALADINSPORTMATRIX)
return DC_STATUS_SUCCESS;
// Handshake (stage 1). // Handshake (stage 1).
command[0] = 0x1B; command[0] = 0x1B;
dc_status_t rc = uwatec_g2_transfer (device, command, 1, answer, 1); dc_status_t rc = scubapro_g2_transfer (device, command, 1, answer, 1);
if (rc != DC_STATUS_SUCCESS) if (rc != DC_STATUS_SUCCESS)
return rc; return rc;
@ -165,7 +180,7 @@ uwatec_g2_handshake (uwatec_g2_device_t *device)
// Handshake (stage 2). // Handshake (stage 2).
command[0] = 0x1C; command[0] = 0x1C;
rc = uwatec_g2_transfer (device, command, 5, answer, 1); rc = scubapro_g2_transfer (device, command, 5, answer, 1);
if (rc != DC_STATUS_SUCCESS) if (rc != DC_STATUS_SUCCESS)
return rc; return rc;
@ -178,46 +193,70 @@ uwatec_g2_handshake (uwatec_g2_device_t *device)
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }
struct usb_id {
unsigned int model;
unsigned short vendor, device;
};
#define C_ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
static const struct usb_id *get_usb_id(unsigned int model)
{
int i;
static const struct usb_id model_to_usb[] = {
{ G2, 0x2e6c, 0x3201 }, // Scubapro G2
{ ALADINSQUARE, 0xc251, 0x2006 }, // Scubapro Aladin Square
};
for (i = 0; i < C_ARRAY_SIZE(model_to_usb); i++) {
const struct usb_id *id = model_to_usb+i;
if (id->model == model)
return id;
}
return NULL;
};
dc_status_t dc_status_t
uwatec_g2_device_open (dc_device_t **out, dc_context_t *context, unsigned int model) scubapro_g2_device_open(dc_device_t **out, dc_context_t *context, const char *name, unsigned int model)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
uwatec_g2_device_t *device = NULL; scubapro_g2_device_t *device = NULL;
if (out == NULL) if (out == NULL)
return DC_STATUS_INVALIDARGS; return DC_STATUS_INVALIDARGS;
// Allocate memory. // Allocate memory.
device = (uwatec_g2_device_t *) dc_device_allocate (context, &uwatec_g2_device_vtable); device = (scubapro_g2_device_t *) dc_device_allocate (context, &scubapro_g2_device_vtable);
if (device == NULL) { if (device == NULL) {
ERROR (context, "Failed to allocate memory."); ERROR(context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY; return DC_STATUS_NOMEMORY;
} }
// Set the default values. // Set the default values.
device->iostream = NULL;
device->timestamp = 0; device->timestamp = 0;
device->systime = (dc_ticks_t) -1; device->systime = (dc_ticks_t) -1;
device->devtime = 0; device->devtime = 0;
// Open the irda socket. dc_custom_io_t *io = _dc_context_custom_io(context);
unsigned int vid = 0, pid = 0; if (io && io->packet_open)
if (model == ALADINSQUARE) { status = io->packet_open(io, context, name);
vid = 0xc251; else {
pid = 0x2006; const struct usb_id *id = get_usb_id(model);
} else { if (!id) {
vid = 0x2e6c; ERROR(context, "Unknown USB ID for Scubapro model %#04x", model);
pid = 0x3201; return DC_STATUS_IO;
}
status = dc_usbhid_custom_io(context, id->vendor, id->device);
} }
status = dc_usbhid_open (&device->iostream, context, vid, pid);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open USB device"); ERROR (context, "Failed to open Scubapro G2 device");
goto error_free; goto error_free;
} }
// Perform the handshaking. // Perform the handshaking.
status = uwatec_g2_handshake (device); status = scubapro_g2_handshake(device, model);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to handshake with the device."); ERROR (context, "Failed to handshake with the device.");
goto error_close; goto error_close;
@ -228,7 +267,7 @@ uwatec_g2_device_open (dc_device_t **out, dc_context_t *context, unsigned int mo
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close: error_close:
dc_iostream_close (device->iostream); scubapro_g2_device_close((dc_device_t *) device);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
@ -236,26 +275,18 @@ error_free:
static dc_status_t static dc_status_t
uwatec_g2_device_close (dc_device_t *abstract) scubapro_g2_device_close (dc_device_t *abstract)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_custom_io_t *io = _dc_context_custom_io(abstract->context);
uwatec_g2_device_t *device = (uwatec_g2_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device. return io->packet_close(io);
rc = dc_iostream_close (device->iostream);
if (status != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
} }
static dc_status_t static dc_status_t
uwatec_g2_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) scubapro_g2_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size)
{ {
uwatec_g2_device_t *device = (uwatec_g2_device_t*) abstract; scubapro_g2_device_t *device = (scubapro_g2_device_t*) abstract;
if (size && size != 4) if (size && size != 4)
return DC_STATUS_INVALIDARGS; return DC_STATUS_INVALIDARGS;
@ -270,9 +301,9 @@ uwatec_g2_device_set_fingerprint (dc_device_t *abstract, const unsigned char dat
static dc_status_t static dc_status_t
uwatec_g2_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) scubapro_g2_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
{ {
uwatec_g2_device_t *device = (uwatec_g2_device_t*) abstract; scubapro_g2_device_t *device = (scubapro_g2_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS; dc_status_t rc = DC_STATUS_SUCCESS;
// Erase the current contents of the buffer. // Erase the current contents of the buffer.
@ -288,21 +319,21 @@ uwatec_g2_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Read the model number. // Read the model number.
unsigned char cmd_model[1] = {0x10}; unsigned char cmd_model[1] = {0x10};
unsigned char model[1] = {0}; unsigned char model[1] = {0};
rc = uwatec_g2_transfer (device, cmd_model, sizeof (cmd_model), model, sizeof (model)); rc = scubapro_g2_transfer (device, cmd_model, sizeof (cmd_model), model, sizeof (model));
if (rc != DC_STATUS_SUCCESS) if (rc != DC_STATUS_SUCCESS)
return rc; return rc;
// Read the serial number. // Read the serial number.
unsigned char cmd_serial[1] = {0x14}; unsigned char cmd_serial[1] = {0x14};
unsigned char serial[4] = {0}; unsigned char serial[4] = {0};
rc = uwatec_g2_transfer (device, cmd_serial, sizeof (cmd_serial), serial, sizeof (serial)); rc = scubapro_g2_transfer (device, cmd_serial, sizeof (cmd_serial), serial, sizeof (serial));
if (rc != DC_STATUS_SUCCESS) if (rc != DC_STATUS_SUCCESS)
return rc; return rc;
// Read the device clock. // Read the device clock.
unsigned char cmd_devtime[1] = {0x1A}; unsigned char cmd_devtime[1] = {0x1A};
unsigned char devtime[4] = {0}; unsigned char devtime[4] = {0};
rc = uwatec_g2_transfer (device, cmd_devtime, sizeof (cmd_devtime), devtime, sizeof (devtime)); rc = scubapro_g2_transfer (device, cmd_devtime, sizeof (cmd_devtime), devtime, sizeof (devtime));
if (rc != DC_STATUS_SUCCESS) if (rc != DC_STATUS_SUCCESS)
return rc; return rc;
@ -341,7 +372,7 @@ uwatec_g2_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Data Length. // Data Length.
command[0] = 0xC6; command[0] = 0xC6;
unsigned char answer[4] = {0}; unsigned char answer[4] = {0};
rc = uwatec_g2_transfer (device, command, sizeof (command), answer, sizeof (answer)); rc = scubapro_g2_transfer (device, command, sizeof (command), answer, sizeof (answer));
if (rc != DC_STATUS_SUCCESS) if (rc != DC_STATUS_SUCCESS)
return rc; return rc;
@ -365,7 +396,7 @@ uwatec_g2_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
// Data. // Data.
command[0] = 0xC4; command[0] = 0xC4;
rc = uwatec_g2_transfer (device, command, sizeof (command), answer, sizeof (answer)); rc = scubapro_g2_transfer (device, command, sizeof (command), answer, sizeof (answer));
if (rc != DC_STATUS_SUCCESS) if (rc != DC_STATUS_SUCCESS)
return rc; return rc;
@ -380,10 +411,9 @@ uwatec_g2_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
return DC_STATUS_PROTOCOL; return DC_STATUS_PROTOCOL;
} }
rc = receive_data (device, &progress, data, length); if (receive_data(device, data, length, &progress)) {
if (rc != DC_STATUS_SUCCESS) { ERROR (abstract->context, "Received an unexpected size.");
ERROR (abstract->context, "Failed to receive the answer."); return DC_STATUS_IO;
return rc;
} }
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
@ -391,19 +421,19 @@ uwatec_g2_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
static dc_status_t static dc_status_t
uwatec_g2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata) scubapro_g2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata)
{ {
dc_buffer_t *buffer = dc_buffer_new (0); dc_buffer_t *buffer = dc_buffer_new (0);
if (buffer == NULL) if (buffer == NULL)
return DC_STATUS_NOMEMORY; return DC_STATUS_NOMEMORY;
dc_status_t rc = uwatec_g2_device_dump (abstract, buffer); dc_status_t rc = scubapro_g2_device_dump (abstract, buffer);
if (rc != DC_STATUS_SUCCESS) { if (rc != DC_STATUS_SUCCESS) {
dc_buffer_free (buffer); dc_buffer_free (buffer);
return rc; return rc;
} }
rc = uwatec_g2_extract_dives (abstract, rc = scubapro_g2_extract_dives (abstract,
dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), callback, userdata); dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), callback, userdata);
dc_buffer_free (buffer); dc_buffer_free (buffer);
@ -413,7 +443,7 @@ uwatec_g2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, vo
static dc_status_t static dc_status_t
uwatec_g2_extract_dives (dc_device_t *abstract, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata) scubapro_g2_extract_dives (dc_device_t *abstract, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata)
{ {
if (abstract && !ISINSTANCE (abstract)) if (abstract && !ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS; return DC_STATUS_INVALIDARGS;

View File

@ -19,8 +19,8 @@
* MA 02110-1301 USA * MA 02110-1301 USA
*/ */
#ifndef UWATEC_G2_H #ifndef SCUBAPRO_G2_H
#define UWATEC_G2_H #define SCUBAPRO_G2_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
@ -31,9 +31,9 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
uwatec_g2_device_open (dc_device_t **device, dc_context_t *context, unsigned int model); scubapro_g2_device_open (dc_device_t **device, dc_context_t *context, const char *name, unsigned int model);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* UWATEC_G2_H */ #endif /* SCUBAPRO_G2_H */

View File

@ -184,6 +184,10 @@ dc_serial_open (dc_iostream_t **out, dc_context_t *context, const char *name)
if (out == NULL || name == NULL) if (out == NULL || name == NULL)
return DC_STATUS_INVALIDARGS; return DC_STATUS_INVALIDARGS;
// Are we using custom IO?
if (_dc_context_custom_io(context))
return dc_custom_io_serial_open(out, context, name);
INFO (context, "Open: name=%s", name); INFO (context, "Open: name=%s", name);
// Allocate memory. // Allocate memory.

View File

@ -164,6 +164,10 @@ dc_serial_open (dc_iostream_t **out, dc_context_t *context, const char *name)
if (out == NULL || name == NULL) if (out == NULL || name == NULL)
return DC_STATUS_INVALIDARGS; return DC_STATUS_INVALIDARGS;
// Are we using custom IO?
if (_dc_context_custom_io(context))
return dc_custom_io_serial_open(out, context, name);
INFO (context, "Open: name=%s", name); INFO (context, "Open: name=%s", name);
// Build the device name. // Build the device name.

View File

@ -58,6 +58,7 @@ shearwater_common_open (shearwater_common_device_t *device, dc_context_t *contex
status = dc_iostream_set_timeout (device->iostream, 3000); status = dc_iostream_set_timeout (device->iostream, 3000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
status = DC_STATUS_IO;
goto error_close; goto error_close;
} }

View File

@ -218,23 +218,35 @@ shearwater_petrel_device_foreach (dc_device_t *abstract, dc_dive_callback_t call
unsigned int hardware = array_uint_be (dc_buffer_get_data (buffer), dc_buffer_get_size (buffer)); unsigned int hardware = array_uint_be (dc_buffer_get_data (buffer), dc_buffer_get_size (buffer));
unsigned int model = 0; unsigned int model = 0;
switch (hardware) { switch (hardware) {
case 0x0808: // Petrel 2 case 0x0101:
case 0x0909: // Petrel 1 case 0x0202:
case 0x0B0B: // Petrel 1 (newer hardware) model = PREDATOR;
model = PETREL;
break; break;
case 0x0606:
case 0x0A0A: // Nerd 1 case 0x0A0A: // Nerd 1
case 0x0E0D: // Nerd 2 case 0x0E0D: // Nerd 2
model = NERD; model = NERD;
break; break;
case 0x0707: case 0x0404:
case 0x0909: // Petrel 1
case 0x0B0B: // Petrel 1 (newer hardware)
model = PETREL;
break;
case 0x0505:
case 0x0808: // Petrel 2
model = PETREL;
break;
case 0x0707: // documentation list 0C0D for both Perdix and Perdix AI :-(
model = PERDIX; model = PERDIX;
break; break;
case 0x0C0C:
case 0x0C0D: case 0x0C0D:
case 0x0D0D:
model = PERDIXAI; model = PERDIXAI;
break; break;
default: default:
WARNING (abstract->context, "Unknown hardware type %04x.", hardware); model = PETREL;
WARNING (abstract->context, "Unknown hardware type %04x. Assuming Petrel.", hardware);
} }
// Emit a device info event. // Emit a device info event.

View File

@ -34,7 +34,7 @@ dc_status_t
shearwater_petrel_device_open (dc_device_t **device, dc_context_t *context, const char *name); shearwater_petrel_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t dc_status_t
shearwater_petrel_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int serial);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -33,9 +33,6 @@ extern "C" {
dc_status_t dc_status_t
shearwater_predator_device_open (dc_device_t **device, dc_context_t *context, const char *name); shearwater_predator_device_open (dc_device_t **device, dc_context_t *context, const char *name);
dc_status_t
shearwater_predator_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -20,11 +20,19 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include <libdivecomputer/units.h> #include <libdivecomputer/units.h>
#include "shearwater_predator.h" #include "shearwater_predator.h"
#include "shearwater_petrel.h" #include "shearwater_petrel.h"
#include "shearwater_common.h"
#include "context-private.h" #include "context-private.h"
#include "parser-private.h" #include "parser-private.h"
#include "array.h" #include "array.h"
@ -47,16 +55,13 @@
#define IMPERIAL 1 #define IMPERIAL 1
#define NGASMIXES 10 #define NGASMIXES 10
#define MAXSTRINGS 32
#define PREDATOR 2
#define PETREL 3
typedef struct shearwater_predator_parser_t shearwater_predator_parser_t; typedef struct shearwater_predator_parser_t shearwater_predator_parser_t;
struct shearwater_predator_parser_t { struct shearwater_predator_parser_t {
dc_parser_t base; dc_parser_t base;
unsigned int model; unsigned int model;
unsigned int petrel;
unsigned int samplesize; unsigned int samplesize;
// Cached fields. // Cached fields.
unsigned int cached; unsigned int cached;
@ -67,7 +72,11 @@ struct shearwater_predator_parser_t {
unsigned int oxygen[NGASMIXES]; unsigned int oxygen[NGASMIXES];
unsigned int helium[NGASMIXES]; unsigned int helium[NGASMIXES];
double calibration[3]; double calibration[3];
unsigned int serial;
dc_divemode_t mode; dc_divemode_t mode;
/* String fields */
dc_field_string_t strings[MAXSTRINGS];
}; };
static dc_status_t shearwater_predator_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t shearwater_predator_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size);
@ -110,8 +119,8 @@ shearwater_predator_find_gasmix (shearwater_predator_parser_t *parser, unsigned
} }
static dc_status_t dc_status_t
shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int petrel) shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int serial)
{ {
shearwater_predator_parser_t *parser = NULL; shearwater_predator_parser_t *parser = NULL;
const dc_parser_vtable_t *vtable = NULL; const dc_parser_vtable_t *vtable = NULL;
@ -120,7 +129,7 @@ shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsig
if (out == NULL) if (out == NULL)
return DC_STATUS_INVALIDARGS; return DC_STATUS_INVALIDARGS;
if (petrel) { if (model != PREDATOR) {
vtable = &shearwater_petrel_parser_vtable; vtable = &shearwater_petrel_parser_vtable;
samplesize = SZ_SAMPLE_PETREL; samplesize = SZ_SAMPLE_PETREL;
} else { } else {
@ -137,8 +146,10 @@ shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsig
// Set the default values. // Set the default values.
parser->model = model; parser->model = model;
parser->petrel = petrel;
parser->samplesize = samplesize; parser->samplesize = samplesize;
parser->serial = serial;
// Set the default values.
parser->cached = 0; parser->cached = 0;
parser->logversion = 0; parser->logversion = 0;
parser->headersize = 0; parser->headersize = 0;
@ -156,20 +167,6 @@ shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsig
} }
dc_status_t
shearwater_predator_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
return shearwater_common_parser_create (out, context, model, 0);
}
dc_status_t
shearwater_petrel_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
return shearwater_common_parser_create (out, context, model, 1);
}
static dc_status_t static dc_status_t
shearwater_predator_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) shearwater_predator_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size)
{ {
@ -210,6 +207,146 @@ shearwater_predator_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *d
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }
/*
* These string cache interfaces should be some generic
* library rather than copied for all the dive computers.
*
* This is just copied from the EON Steel code.
*/
static void
add_string(shearwater_predator_parser_t *parser, const char *desc, const char *value)
{
int i;
for (i = 0; i < MAXSTRINGS; i++) {
dc_field_string_t *str = parser->strings+i;
if (str->desc)
continue;
str->desc = desc;
str->value = strdup(value);
break;
}
}
static void
add_string_fmt(shearwater_predator_parser_t *parser, const char *desc, const char *fmt, ...)
{
char buffer[256];
va_list ap;
/*
* We ignore the return value from vsnprintf, and we
* always NUL-terminate the destination buffer ourselves.
*
* That way we don't have to worry about random bad legacy
* implementations.
*/
va_start(ap, fmt);
buffer[sizeof(buffer)-1] = 0;
(void) vsnprintf(buffer, sizeof(buffer)-1, fmt, ap);
va_end(ap);
return add_string(parser, desc, buffer);
}
// The Battery state is a big-endian word:
//
// ffff = not paired / no comms for 90 s
// fffe = no comms for 30 s
//
// Otherwise:
// - top four bits are battery state (0 - normal, 1 - critical, 2 - warning)
// - bottom 12 bits are pressure in 2 psi increments (0..8k psi)
//
// This returns the state as a bitmask (so you can see all states it had
// during the dive). Note that we currently do not report pairing and
// communication lapses. Todo?
static unsigned int
battery_state(const unsigned char *data)
{
unsigned int pressure = array_uint16_be(data);
unsigned int state;
if ((pressure & 0xFFF0) == 0xFFF0)
return 0;
state = pressure >> 12;
if (state > 2)
return 0;
return 1u << state;
}
// Show the battery state
//
// NOTE! Right now it only shows the most serious bit
// but the code is set up so that we could perhaps
// indicate that the battery is on the edge (ie it
// reported both "normal" _and_ "warning" during the
// dive - maybe that would be a "starting to warn")
//
// We could also report unpaired and comm errors.
static void
add_battery_info(shearwater_predator_parser_t *parser, const char *desc, unsigned int state)
{
if (state >= 1 && state <= 7) {
static const char *states[8] = {
"", // 000 - No state bits, not used
"normal", // 001 - only normal
"critical", // 010 - only critical
"critical", // 011 - both normal and critical
"warning", // 100 - only warning
"warning", // 101 - normal and warning
"critical", // 110 - warning and critical
"critical", // 111 - normal, warning and critical
};
add_string(parser, desc, states[state]);
}
}
static void
add_deco_model(shearwater_predator_parser_t *parser, const unsigned char *data)
{
switch (data[67]) {
case 0:
add_string_fmt(parser, "Deco model", "GF %u/%u", data[4], data[5]);
break;
case 1:
add_string_fmt(parser, "Deco model", "VPM-B +%u", data[68]);
break;
case 2:
add_string_fmt(parser, "Deco model", "VPM-B/GFS +%u %u%%", data[68], data[85]);
break;
default:
add_string_fmt(parser, "Deco model", "Unknown model %d", data[67]);
}
}
static void
add_battery_type(shearwater_predator_parser_t *parser, const unsigned char *data)
{
if (parser->logversion < 7)
return;
switch (data[120]) {
case 1:
add_string(parser, "Battery type", "1.5V Alkaline");
break;
case 2:
add_string(parser, "Battery type", "1.5V Lithium");
break;
case 3:
add_string(parser, "Battery type", "1.2V NiMH");
break;
case 4:
add_string(parser, "Battery type", "3.6V Saft");
break;
case 5:
add_string(parser, "Battery type", "3.7V Li-Ion");
break;
default:
add_string_fmt(parser, "Battery type", "unknown type %d", data[120]);
break;
}
}
static dc_status_t static dc_status_t
shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
@ -234,9 +371,12 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
unsigned int logversion = 6; unsigned int logversion = 6;
if (data[127] > 6) if (data[127] > 6)
logversion = data[127]; logversion = data[127];
INFO(abstract->context, "Shearwater log version %u\n", logversion);
memset(parser->strings, 0, sizeof(parser->strings));
// Adjust the footersize for the final block. // Adjust the footersize for the final block.
if (parser->petrel || array_uint16_be (data + size - footersize) == 0xFFFD) { if (parser->model > PREDATOR || array_uint16_be (data + size - footersize) == 0xFFFD) {
footersize += SZ_BLOCK; footersize += SZ_BLOCK;
if (size < headersize + footersize) { if (size < headersize + footersize) {
ERROR (abstract->context, "Invalid data length."); ERROR (abstract->context, "Invalid data length.");
@ -253,6 +393,9 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
unsigned int helium[NGASMIXES] = {0}; unsigned int helium[NGASMIXES] = {0};
unsigned int o2_previous = 0, he_previous = 0; unsigned int o2_previous = 0, he_previous = 0;
// Transmitter battery levels
unsigned int t1_battery = 0, t2_battery = 0;
unsigned int offset = headersize; unsigned int offset = headersize;
unsigned int length = size - footersize; unsigned int length = size - footersize;
while (offset < length) { while (offset < length) {
@ -295,6 +438,13 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
he_previous = he; he_previous = he;
} }
// Transmitter battery levels
if (logversion >= 7) {
// T1 at offset 27, T2 at offset 19
t1_battery |= battery_state(data + offset + 27);
t2_battery |= battery_state(data + offset + 19);
}
offset += parser->samplesize; offset += parser->samplesize;
} }
@ -322,6 +472,13 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
parser->helium[i] = helium[i]; parser->helium[i] = helium[i];
} }
parser->mode = mode; parser->mode = mode;
add_string_fmt(parser, "Serial", "%08x", parser->serial);
add_string_fmt(parser, "FW Version", "%2x", data[19]);
add_deco_model(parser, data);
add_battery_type(parser, data);
add_string_fmt(parser, "Battery at end", "%.1f V", data[9] / 10.0);
add_battery_info(parser, "T1 battery", t1_battery);
add_battery_info(parser, "T2 battery", t2_battery);
parser->cached = 1; parser->cached = 1;
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
@ -348,6 +505,7 @@ shearwater_predator_parser_get_field (dc_parser_t *abstract, dc_field_type_t typ
dc_gasmix_t *gasmix = (dc_gasmix_t *) value; dc_gasmix_t *gasmix = (dc_gasmix_t *) value;
dc_salinity_t *water = (dc_salinity_t *) value; dc_salinity_t *water = (dc_salinity_t *) value;
dc_field_string_t *string = (dc_field_string_t *) value;
unsigned int density = 0; unsigned int density = 0;
if (value) { if (value) {
@ -383,6 +541,15 @@ shearwater_predator_parser_get_field (dc_parser_t *abstract, dc_field_type_t typ
case DC_FIELD_DIVEMODE: case DC_FIELD_DIVEMODE:
*((dc_divemode_t *) value) = parser->mode; *((dc_divemode_t *) value) = parser->mode;
break; break;
case DC_FIELD_STRING:
if (flags < MAXSTRINGS) {
dc_field_string_t *p = parser->strings + flags;
if (p->desc) {
*string = *p;
break;
}
}
return DC_STATUS_UNSUPPORTED;
default: default:
return DC_STATUS_UNSUPPORTED; return DC_STATUS_UNSUPPORTED;
} }
@ -414,6 +581,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal
unsigned int time = 0; unsigned int time = 0;
unsigned int offset = parser->headersize; unsigned int offset = parser->headersize;
unsigned int length = size - parser->footersize; unsigned int length = size - parser->footersize;
while (offset < length) { while (offset < length) {
dc_sample_value_t sample = {0}; dc_sample_value_t sample = {0};
@ -473,7 +641,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal
} }
// Setpoint // Setpoint
if (parser->petrel) { if (parser->model > PREDATOR) {
sample.setpoint = data[offset + 18] / 100.0; sample.setpoint = data[offset + 18] / 100.0;
} else { } else {
if (status & SETPOINT_HIGH) { if (status & SETPOINT_HIGH) {
@ -486,7 +654,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal
} }
// CNS // CNS
if (parser->petrel) { if (parser->model > PREDATOR) {
sample.cns = data[offset + 22] / 100.0; sample.cns = data[offset + 22] / 100.0;
if (callback) callback (DC_SAMPLE_CNS, sample, userdata); if (callback) callback (DC_SAMPLE_CNS, sample, userdata);
} }
@ -564,6 +732,5 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal
offset += parser->samplesize; offset += parser->samplesize;
} }
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }

View File

@ -35,7 +35,7 @@ dc_status_t
suunto_d9_device_open (dc_device_t **device, dc_context_t *context, const char *name, unsigned int model); suunto_d9_device_open (dc_device_t **device, dc_context_t *context, const char *name, unsigned int model);
dc_status_t dc_status_t
suunto_d9_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); suunto_d9_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model, unsigned int serial);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -20,7 +20,8 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h> // memcmp #include <string.h> // memcmp, strdup
#include <stdio.h> // snprintf
#include "suunto_d9.h" #include "suunto_d9.h"
#include "context-private.h" #include "context-private.h"
@ -72,6 +73,7 @@ typedef struct suunto_d9_parser_t suunto_d9_parser_t;
struct suunto_d9_parser_t { struct suunto_d9_parser_t {
dc_parser_t base; dc_parser_t base;
unsigned int model; unsigned int model;
unsigned int serial;
// Cached fields. // Cached fields.
unsigned int cached; unsigned int cached;
unsigned int mode; unsigned int mode;
@ -231,7 +233,7 @@ suunto_d9_parser_cache (suunto_d9_parser_t *parser)
} }
dc_status_t dc_status_t
suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int serial)
{ {
suunto_d9_parser_t *parser = NULL; suunto_d9_parser_t *parser = NULL;
@ -247,6 +249,7 @@ suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int
// Set the default values. // Set the default values.
parser->model = model; parser->model = model;
parser->serial = serial;
parser->cached = 0; parser->cached = 0;
parser->mode = AIR; parser->mode = AIR;
parser->ngasmixes = 0; parser->ngasmixes = 0;
@ -326,6 +329,7 @@ suunto_d9_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime)
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }
#define BUFLEN 16
static dc_status_t static dc_status_t
suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value) suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value)
@ -341,6 +345,9 @@ suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigne
return rc; return rc;
dc_gasmix_t *gasmix = (dc_gasmix_t *) value; dc_gasmix_t *gasmix = (dc_gasmix_t *) value;
dc_field_string_t *string = (dc_field_string_t *) value;
char buf[BUFLEN];
if (value) { if (value) {
switch (type) { switch (type) {
@ -388,6 +395,17 @@ suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigne
return DC_STATUS_DATAFORMAT; return DC_STATUS_DATAFORMAT;
} }
break; break;
case DC_FIELD_STRING:
switch (flags) {
case 0: /* serial */
string->desc = "Serial";
snprintf(buf, BUFLEN, "%08u", parser->serial);
break;
default:
return DC_STATUS_UNSUPPORTED;
}
string->value = strdup(buf);
break;
default: default:
return DC_STATUS_UNSUPPORTED; return DC_STATUS_UNSUPPORTED;
} }

View File

@ -22,6 +22,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <zlib.h> /* For crc32() */
#include "suunto_eonsteel.h" #include "suunto_eonsteel.h"
#include "context-private.h" #include "context-private.h"
@ -35,7 +36,6 @@
typedef struct suunto_eonsteel_device_t { typedef struct suunto_eonsteel_device_t {
dc_device_t base; dc_device_t base;
dc_iostream_t *iostream;
unsigned int model; unsigned int model;
unsigned int magic; unsigned int magic;
unsigned short seq; unsigned short seq;
@ -134,14 +134,14 @@ static void put_le32(unsigned int val, unsigned char *p)
* The maximum payload is 62 bytes. * The maximum payload is 62 bytes.
*/ */
#define PACKET_SIZE 64 #define PACKET_SIZE 64
static int receive_packet(suunto_eonsteel_device_t *eon, unsigned char *buffer, int size) static int receive_usbhid_packet(dc_custom_io_t *io, suunto_eonsteel_device_t *eon, unsigned char *buffer, int size)
{ {
unsigned char buf[64]; unsigned char buf[64];
dc_status_t rc = DC_STATUS_SUCCESS; dc_status_t rc = DC_STATUS_SUCCESS;
size_t transferred = 0; size_t transferred = 0;
int len; int len;
rc = dc_iostream_read(eon->iostream, buf, PACKET_SIZE, &transferred); rc = io->packet_read(io, buf, PACKET_SIZE, &transferred);
if (rc != DC_STATUS_SUCCESS) { if (rc != DC_STATUS_SUCCESS) {
ERROR(eon->base.context, "read interrupt transfer failed"); ERROR(eon->base.context, "read interrupt transfer failed");
return -1; return -1;
@ -168,6 +168,159 @@ static int receive_packet(suunto_eonsteel_device_t *eon, unsigned char *buffer,
return len; return len;
} }
static int fill_ble_buffer(dc_custom_io_t *io, suunto_eonsteel_device_t *eon, unsigned char *buffer, int size)
{
int state = 0;
int bytes = 0;
unsigned int crc;
for (;;) {
unsigned char packet[32];
dc_status_t rc = DC_STATUS_SUCCESS;
size_t transferred = 0;
int i;
rc = io->packet_read(io, packet, sizeof(packet), &transferred);
if (rc != DC_STATUS_SUCCESS) {
ERROR(eon->base.context, "BLE GATT read transfer failed");
return -1;
}
for (i = 0; i < transferred; i++) {
unsigned char c = packet[i];
if (c == 0x7e) {
if (state == 1)
goto done;
if (state == 2) {
ERROR(eon->base.context, "BLE GATT stream has escaped 7e character");
return -1;
}
/* Initial 7e character - good */
state = 1;
continue;
}
if (!state) {
ERROR(eon->base.context, "BLE GATT stream did not start with 7e");
return -1;
}
if (c == 0x7d) {
if (state == 2) {
ERROR(eon->base.context, "BLE GATT stream has escaped 7d character");
return -1;
}
state = 2;
continue;
}
if (state == 2) {
c ^= 0x20;
state = 1;
}
if (bytes < size)
buffer[bytes] = c;
bytes++;
}
}
done:
if (bytes < 4) {
ERROR(eon->base.context, "did not receive BLE CRC32 data");
return -1;
}
if (bytes > size) {
ERROR(eon->base.context, "BLE GATT stream too long (%d bytes, buffer is %d)", bytes, size);
return -1;
}
/* Remove and check CRC */
bytes -= 4;
crc = crc32(0, buffer, bytes);
if (crc != array_uint32_le(buffer + bytes)) {
ERROR(eon->base.context, "incorrect BLE CRC32 data");
return -1;
}
HEXDUMP (eon->base.context, DC_LOGLEVEL_DEBUG, "rcv", buffer, bytes);
return bytes;
}
#define HDRSIZE 12
#define MAXDATA 2048
#define CRCSIZE 4
static struct {
unsigned int len, offset;
unsigned char buffer[HDRSIZE + MAXDATA + CRCSIZE];
} ble_data;
static void fill_ble_data(dc_custom_io_t *io, suunto_eonsteel_device_t *eon)
{
int received;
received = fill_ble_buffer(io, eon, ble_data.buffer, sizeof(ble_data.buffer));
if (received < 0)
received = 0;
ble_data.offset = 0;
ble_data.len = received;
}
static int receive_ble_packet(dc_custom_io_t *io, suunto_eonsteel_device_t *eon, unsigned char *buffer, int size)
{
int maxsize;
if (ble_data.offset >= ble_data.len)
return 0;
maxsize = ble_data.len - ble_data.offset;
if (size > maxsize)
size = maxsize;
memcpy(buffer, ble_data.buffer + ble_data.offset, size);
ble_data.offset += size;
return size;
}
static int receive_packet(dc_custom_io_t *io, suunto_eonsteel_device_t *eon, unsigned char *buffer, int size)
{
if (io->packet_size < 64)
return receive_ble_packet(io, eon, buffer, size);
return receive_usbhid_packet(io, eon, buffer, size);
}
static int add_hdlc(unsigned char *dst, unsigned char val)
{
int chars = 1;
switch (val) {
case 0x7e: case 0x7d:
*dst++ = 0x7d;
val ^= 0x20;
chars++;
/* fallthrough */
default:
*dst = val;
}
return chars;
}
static int hdlc_reencode(unsigned char *dst, unsigned char *src, int len)
{
unsigned int crc = crc32(0, src, len);
int result = 0, i;
*dst++ = 0x7e; result++;
for (i = 0; i < len; i++) {
int chars = add_hdlc(dst, src[i]);
dst += chars;
result += chars;
}
for (i = 0; i < 4; i++) {
int chars = add_hdlc(dst, crc & 255);
dst += chars;
result += chars;
crc >>= 8;
}
*dst++ = 0x7e; result++;
return result;
}
static int send_cmd(suunto_eonsteel_device_t *eon, static int send_cmd(suunto_eonsteel_device_t *eon,
unsigned short cmd, unsigned short cmd,
unsigned int len, unsigned int len,
@ -176,6 +329,7 @@ static int send_cmd(suunto_eonsteel_device_t *eon,
unsigned char buf[64]; unsigned char buf[64];
unsigned short seq = eon->seq; unsigned short seq = eon->seq;
unsigned int magic = eon->magic; unsigned int magic = eon->magic;
dc_custom_io_t *io = _dc_context_custom_io(eon->base.context);
dc_status_t rc = DC_STATUS_SUCCESS; dc_status_t rc = DC_STATUS_SUCCESS;
size_t transferred = 0; size_t transferred = 0;
@ -207,7 +361,29 @@ static int send_cmd(suunto_eonsteel_device_t *eon,
memcpy(buf+14, buffer, len); memcpy(buf+14, buffer, len);
} }
rc = dc_iostream_write(eon->iostream, buf, sizeof(buf), &transferred); // BLE GATT protocol?
if (io->packet_size < 64) {
int hdlc_len;
unsigned char hdlc[2+2*(62+4)]; /* start/stop + escaping*(maxbuf+crc32) */
unsigned char *ptr;
hdlc_len = hdlc_reencode(hdlc, buf+2, buf[1]);
ptr = hdlc;
do {
int len = hdlc_len;
if (len > io->packet_size)
len = io->packet_size;
rc = io->packet_write(io, ptr, len, &transferred);
if (rc != DC_STATUS_SUCCESS)
break;
ptr += len;
hdlc_len -= len;
} while (hdlc_len);
} else {
rc = io->packet_write(io, buf, sizeof(buf), &transferred);
}
if (rc != DC_STATUS_SUCCESS) { if (rc != DC_STATUS_SUCCESS) {
ERROR(eon->base.context, "write interrupt transfer failed"); ERROR(eon->base.context, "write interrupt transfer failed");
return -1; return -1;
@ -229,8 +405,11 @@ static int receive_header(suunto_eonsteel_device_t *eon, struct eon_hdr *hdr, un
{ {
int ret; int ret;
unsigned char header[64]; unsigned char header[64];
dc_custom_io_t *io = _dc_context_custom_io(eon->base.context);
ret = receive_packet(eon, header, sizeof(header)); if (io->packet_size < 64)
fill_ble_data(io, eon);
ret = receive_packet(io, eon, header, sizeof(header));
if (ret < 0) if (ret < 0)
return -1; return -1;
if (ret < 12) { if (ret < 12) {
@ -256,11 +435,12 @@ static int receive_header(suunto_eonsteel_device_t *eon, struct eon_hdr *hdr, un
static int receive_data(suunto_eonsteel_device_t *eon, unsigned char *buffer, int size) static int receive_data(suunto_eonsteel_device_t *eon, unsigned char *buffer, int size)
{ {
int ret = 0; int ret = 0;
dc_custom_io_t *io = _dc_context_custom_io(eon->base.context);
while (size > 0) { while (size > 0) {
int len; int len;
len = receive_packet(eon, buffer + ret, size); len = receive_packet(io, eon, buffer + ret, size);
if (len < 0) if (len < 0)
return -1; return -1;
@ -294,8 +474,7 @@ static int send_receive(suunto_eonsteel_device_t *eon,
unsigned int len_out, const unsigned char *out, unsigned int len_out, const unsigned char *out,
unsigned int len_in, unsigned char *in) unsigned int len_in, unsigned char *in)
{ {
int len, actual, max; int len, actual;
unsigned char buf[2048];
struct eon_hdr hdr; struct eon_hdr hdr;
if (send_cmd(eon, cmd, len_out, out) < 0) if (send_cmd(eon, cmd, len_out, out) < 0)
@ -436,6 +615,20 @@ static int read_file(suunto_eonsteel_device_t *eon, const char *filename, dc_buf
* with the last dirent first. That's intentional: for dives, * with the last dirent first. That's intentional: for dives,
* we will want to look up the last dive first. * we will want to look up the last dive first.
*/ */
static struct directory_entry *add_dirent(struct directory_entry *new, struct directory_entry *list)
{
struct directory_entry **pp = &list, *p;
/* Skip any entries that are later than the new one */
while ((p = *pp) != NULL && strcmp(p->name, new->name) > 0)
pp = &p->next;
/* Add the new one to that location and return the new list pointer */
new->next = p;
*pp = new;
return list;
}
static struct directory_entry *parse_dirent(suunto_eonsteel_device_t *eon, int nr, const unsigned char *p, int len, struct directory_entry *old) static struct directory_entry *parse_dirent(suunto_eonsteel_device_t *eon, int nr, const unsigned char *p, int len, struct directory_entry *old)
{ {
while (len > 8) { while (len > 8) {
@ -445,7 +638,7 @@ static struct directory_entry *parse_dirent(suunto_eonsteel_device_t *eon, int n
struct directory_entry *entry; struct directory_entry *entry;
if (namelen + 8 + 1 > len || name[namelen] != 0) { if (namelen + 8 + 1 > len || name[namelen] != 0) {
ERROR(eon->base.context, "corrupt dirent entry"); ERROR(eon->base.context, "corrupt dirent entry: len=%d namelen=%d name='%s'", len, namelen, name);
break; break;
} }
HEXDUMP(eon->base.context, DC_LOGLEVEL_DEBUG, "dir entry", p, 8); HEXDUMP(eon->base.context, DC_LOGLEVEL_DEBUG, "dir entry", p, 8);
@ -457,8 +650,7 @@ static struct directory_entry *parse_dirent(suunto_eonsteel_device_t *eon, int n
ERROR(eon->base.context, "out of memory"); ERROR(eon->base.context, "out of memory");
break; break;
} }
entry->next = old; old = add_dirent(entry, old);
old = entry;
} }
return old; return old;
} }
@ -470,7 +662,6 @@ static int get_file_list(suunto_eonsteel_device_t *eon, struct directory_entry *
unsigned char result[2048]; unsigned char result[2048];
int rc, cmdlen; int rc, cmdlen;
*res = NULL; *res = NULL;
put_le32(0, cmd); put_le32(0, cmd);
memcpy(cmd + 4, dive_directory, sizeof(dive_directory)); memcpy(cmd + 4, dive_directory, sizeof(dive_directory));
@ -520,24 +711,8 @@ static int get_file_list(suunto_eonsteel_device_t *eon, struct directory_entry *
static int initialize_eonsteel(suunto_eonsteel_device_t *eon) static int initialize_eonsteel(suunto_eonsteel_device_t *eon)
{ {
const unsigned char init[] = {0x02, 0x00, 0x2a, 0x00}; const unsigned char init[] = {0x02, 0x00, 0x2a, 0x00};
unsigned char buf[64];
struct eon_hdr hdr; struct eon_hdr hdr;
dc_iostream_set_timeout(eon->iostream, 10);
/* Get rid of any pending stale input first */
for (;;) {
size_t transferred = 0;
dc_status_t rc = dc_iostream_read(eon->iostream, buf, sizeof(buf), &transferred);
if (rc != DC_STATUS_SUCCESS)
break;
if (!transferred)
break;
}
dc_iostream_set_timeout(eon->iostream, 5000);
if (send_cmd(eon, CMD_INIT, sizeof(init), init)) { if (send_cmd(eon, CMD_INIT, sizeof(init), init)) {
ERROR(eon->base.context, "Failed to send initialization command"); ERROR(eon->base.context, "Failed to send initialization command");
return -1; return -1;
@ -555,7 +730,7 @@ static int initialize_eonsteel(suunto_eonsteel_device_t *eon)
} }
dc_status_t dc_status_t
suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, unsigned int model) suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, const char *name, unsigned int model)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
suunto_eonsteel_device_t *eon = NULL; suunto_eonsteel_device_t *eon = NULL;
@ -574,13 +749,16 @@ suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, unsigned i
memset (eon->version, 0, sizeof (eon->version)); memset (eon->version, 0, sizeof (eon->version));
memset (eon->fingerprint, 0, sizeof (eon->fingerprint)); memset (eon->fingerprint, 0, sizeof (eon->fingerprint));
unsigned int vid = 0x1493, pid = 0; dc_custom_io_t *io = _dc_context_custom_io(eon->base.context);
if (model == EONCORE) { if (io && io->packet_open)
pid = 0x0033; status = io->packet_open(io, context, name);
} else { else {
pid = 0x0030; /* We really need some way to specify USB ID's in the descriptor */
unsigned int vendor_id = 0x1493;
unsigned int device_id = model ? 0x0033 : 0x0030;
status = dc_usbhid_custom_io(context, vendor_id, device_id);
} }
status = dc_usbhid_open(&eon->iostream, context, vid, pid);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR(context, "unable to open device"); ERROR(context, "unable to open device");
goto error_free; goto error_free;
@ -597,12 +775,22 @@ suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, unsigned i
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close: error_close:
dc_iostream_close(eon->iostream); suunto_eonsteel_device_close((dc_device_t *) eon);
error_free: error_free:
free(eon); free(eon);
return status; return status;
} }
static int count_dir_entries(struct directory_entry *de)
{
int count = 0;
while (de) {
count++;
de = de->next;
}
return count;
}
static dc_status_t static dc_status_t
suunto_eonsteel_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) suunto_eonsteel_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size)
{ {
@ -628,7 +816,6 @@ suunto_eonsteel_device_foreach(dc_device_t *abstract, dc_dive_callback_t callbac
dc_buffer_t *file; dc_buffer_t *file;
char pathname[64]; char pathname[64];
unsigned int time; unsigned int time;
unsigned int count = 0;
dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER; dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
// Emit a device info event. // Emit a device info event.
@ -645,40 +832,11 @@ suunto_eonsteel_device_foreach(dc_device_t *abstract, dc_dive_callback_t callbac
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }
// Locate the most recent dive.
// The filename represent the time of the dive, encoded as a hexadecimal
// number. Thus the most recent dive can be found by simply sorting the
// filenames alphabetically.
struct directory_entry *head = de, *tail = de, *latest = de;
while (de) {
if (strcmp (de->name, latest->name) > 0) {
latest = de;
}
tail = de;
count++;
de = de->next;
}
// Make the most recent dive the head of the list.
// The linked list is made circular, by attaching the head to the tail and
// then cut open again just before the most recent dive.
de = head;
while (de) {
if (de->next == latest) {
de->next = NULL;
tail->next = head;
break;
}
de = de->next;
}
file = dc_buffer_new(0); file = dc_buffer_new(0);
progress.maximum = count; progress.maximum = count_dir_entries(de);
progress.current = 0; progress.current = 0;
device_event_emit(abstract, DC_EVENT_PROGRESS, &progress); device_event_emit(abstract, DC_EVENT_PROGRESS, &progress);
de = latest;
while (de) { while (de) {
int len; int len;
struct directory_entry *next = de->next; struct directory_entry *next = de->next;
@ -769,9 +927,7 @@ static dc_status_t suunto_eonsteel_device_timesync(dc_device_t *abstract, const
static dc_status_t static dc_status_t
suunto_eonsteel_device_close(dc_device_t *abstract) suunto_eonsteel_device_close(dc_device_t *abstract)
{ {
suunto_eonsteel_device_t *eon = (suunto_eonsteel_device_t *) abstract; dc_custom_io_t *io = _dc_context_custom_io(abstract->context);
dc_iostream_close(eon->iostream); return io->packet_close(io);
return DC_STATUS_SUCCESS;
} }

View File

@ -31,7 +31,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
suunto_eonsteel_device_open(dc_device_t **device, dc_context_t *context, unsigned int model); suunto_eonsteel_device_open(dc_device_t **device, dc_context_t *context, const char *name, unsigned int model);
dc_status_t dc_status_t
suunto_eonsteel_parser_create(dc_parser_t **parser, dc_context_t *context, unsigned int model); suunto_eonsteel_parser_create(dc_parser_t **parser, dc_context_t *context, unsigned int model);

View File

@ -21,8 +21,16 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <math.h> #include <math.h>
#include <stdarg.h>
/* Wow. MSC is truly crap */
#ifdef _MSC_VER
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#endif
#include "suunto_eonsteel.h" #include "suunto_eonsteel.h"
#include "context-private.h" #include "context-private.h"
@ -71,6 +79,7 @@ struct type_desc {
#define MAXTYPE 512 #define MAXTYPE 512
#define MAXGASES 16 #define MAXGASES 16
#define MAXSTRINGS 32
typedef struct suunto_eonsteel_parser_t { typedef struct suunto_eonsteel_parser_t {
dc_parser_t base; dc_parser_t base;
@ -89,7 +98,8 @@ typedef struct suunto_eonsteel_parser_t {
double lowsetpoint; double lowsetpoint;
double highsetpoint; double highsetpoint;
double customsetpoint; double customsetpoint;
dc_tankvolume_t tankinfo[MAXGASES]; dc_field_string_t strings[MAXSTRINGS];
dc_tankinfo_t tankinfo[MAXGASES];
double tanksize[MAXGASES]; double tanksize[MAXGASES];
double tankworkingpressure[MAXGASES]; double tankworkingpressure[MAXGASES];
} cache; } cache;
@ -97,11 +107,6 @@ typedef struct suunto_eonsteel_parser_t {
typedef int (*eon_data_cb_t)(unsigned short type, const struct type_desc *desc, const unsigned char *data, int len, void *user); typedef int (*eon_data_cb_t)(unsigned short type, const struct type_desc *desc, const unsigned char *data, int len, void *user);
typedef struct eon_event_t {
const char *name;
parser_sample_event_t type;
} eon_event_t;
static const struct { static const struct {
const char *name; const char *name;
enum eon_sample type; enum eon_sample type;
@ -167,16 +172,6 @@ static enum eon_sample lookup_descriptor_type(suunto_eonsteel_parser_t *eon, str
return ES_none; return ES_none;
} }
static parser_sample_event_t lookup_event(const char *name, const eon_event_t events[], size_t n)
{
for (size_t i = 0; i < n; ++i) {
if (!strcasecmp(name, events[i].name))
return events[i].type;
}
return SAMPLE_EVENT_NONE;
}
static const char *desc_type_name(enum eon_sample type) static const char *desc_type_name(enum eon_sample type)
{ {
int i; int i;
@ -680,26 +675,17 @@ static void sample_event_state_type(const struct type_desc *desc, struct sample_
static void sample_event_state_value(const struct type_desc *desc, struct sample_data *info, unsigned char value) static void sample_event_state_value(const struct type_desc *desc, struct sample_data *info, unsigned char value)
{ {
dc_sample_value_t sample = {0}; dc_sample_value_t sample = {0};
static const eon_event_t states[] = {
{"Wet Outside", SAMPLE_EVENT_NONE},
{"Below Wet Activation Depth", SAMPLE_EVENT_NONE},
{"Below Surface", SAMPLE_EVENT_NONE},
{"Dive Active", SAMPLE_EVENT_NONE},
{"Surface Calculation", SAMPLE_EVENT_NONE},
{"Tank pressure available", SAMPLE_EVENT_NONE},
{"Closed Circuit Mode", SAMPLE_EVENT_NONE},
};
const char *name; const char *name;
name = info->state_type; name = info->state_type;
if (!name) if (!name)
return; return;
sample.event.type = lookup_event(name, states, C_ARRAY_SIZE(states)); sample.event.type = SAMPLE_EVENT_STRING;
if (sample.event.type == SAMPLE_EVENT_NONE) sample.event.name = name;
return;
sample.event.flags = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END; sample.event.flags = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END;
sample.event.flags |= 1 << SAMPLE_FLAGS_SEVERITY_SHIFT;
if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata);
} }
@ -710,25 +696,6 @@ static void sample_event_notify_type(const struct type_desc *desc, struct sample
static void sample_event_notify_value(const struct type_desc *desc, struct sample_data *info, unsigned char value) static void sample_event_notify_value(const struct type_desc *desc, struct sample_data *info, unsigned char value)
{ {
static const eon_event_t notifications[] = {
{"NoFly Time", SAMPLE_EVENT_NONE},
{"Depth", SAMPLE_EVENT_NONE},
{"Surface Time", SAMPLE_EVENT_NONE},
{"Tissue Level", SAMPLE_EVENT_TISSUELEVEL},
{"Deco", SAMPLE_EVENT_NONE},
{"Deco Window", SAMPLE_EVENT_NONE},
{"Safety Stop Ahead", SAMPLE_EVENT_NONE},
{"Safety Stop", SAMPLE_EVENT_SAFETYSTOP},
{"Safety Stop Broken", SAMPLE_EVENT_CEILING_SAFETYSTOP},
{"Deep Stop Ahead", SAMPLE_EVENT_NONE},
{"Deep Stop", SAMPLE_EVENT_DEEPSTOP},
{"Dive Time", SAMPLE_EVENT_DIVETIME},
{"Gas Available", SAMPLE_EVENT_NONE},
{"SetPoint Switch", SAMPLE_EVENT_NONE},
{"Diluent Hypoxia", SAMPLE_EVENT_NONE},
{"Air Time", SAMPLE_EVENT_NONE},
{"Tank Pressure", SAMPLE_EVENT_NONE},
};
dc_sample_value_t sample = {0}; dc_sample_value_t sample = {0};
const char *name; const char *name;
@ -736,11 +703,11 @@ static void sample_event_notify_value(const struct type_desc *desc, struct sampl
if (!name) if (!name)
return; return;
sample.event.type = lookup_event(name, notifications, C_ARRAY_SIZE(notifications)); sample.event.type = SAMPLE_EVENT_STRING;
if (sample.event.type == SAMPLE_EVENT_NONE) sample.event.name = name;
return;
sample.event.flags = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END; sample.event.flags = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END;
sample.event.flags |= 2 << SAMPLE_FLAGS_SEVERITY_SHIFT;
if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata);
} }
@ -752,22 +719,6 @@ static void sample_event_warning_type(const struct type_desc *desc, struct sampl
static void sample_event_warning_value(const struct type_desc *desc, struct sample_data *info, unsigned char value) static void sample_event_warning_value(const struct type_desc *desc, struct sample_data *info, unsigned char value)
{ {
static const eon_event_t warnings[] = {
{"ICD Penalty", SAMPLE_EVENT_NONE},
{"Deep Stop Penalty", SAMPLE_EVENT_VIOLATION},
{"Mandatory Safety Stop", SAMPLE_EVENT_SAFETYSTOP_MANDATORY},
{"OTU250", SAMPLE_EVENT_NONE},
{"OTU300", SAMPLE_EVENT_NONE},
{"CNS80%", SAMPLE_EVENT_NONE},
{"CNS100%", SAMPLE_EVENT_NONE},
{"Max.Depth", SAMPLE_EVENT_MAXDEPTH},
{"Air Time", SAMPLE_EVENT_AIRTIME},
{"Tank Pressure", SAMPLE_EVENT_NONE},
{"Safety Stop Broken", SAMPLE_EVENT_CEILING_SAFETYSTOP},
{"Deep Stop Broken", SAMPLE_EVENT_CEILING_SAFETYSTOP},
{"Ceiling Broken", SAMPLE_EVENT_CEILING},
{"PO2 High", SAMPLE_EVENT_PO2},
};
dc_sample_value_t sample = {0}; dc_sample_value_t sample = {0};
const char *name; const char *name;
@ -775,11 +726,11 @@ static void sample_event_warning_value(const struct type_desc *desc, struct samp
if (!name) if (!name)
return; return;
sample.event.type = lookup_event(name, warnings, C_ARRAY_SIZE(warnings)); sample.event.type = SAMPLE_EVENT_STRING;
if (sample.event.type == SAMPLE_EVENT_NONE) sample.event.name = name;
return;
sample.event.flags = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END; sample.event.flags = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END;
sample.event.flags |= 3 << SAMPLE_FLAGS_SEVERITY_SHIFT;
if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata);
} }
@ -791,27 +742,18 @@ static void sample_event_alarm_type(const struct type_desc *desc, struct sample_
static void sample_event_alarm_value(const struct type_desc *desc, struct sample_data *info, unsigned char value) static void sample_event_alarm_value(const struct type_desc *desc, struct sample_data *info, unsigned char value)
{ {
static const eon_event_t alarms[] = {
{"Mandatory Safety Stop Broken", SAMPLE_EVENT_CEILING_SAFETYSTOP},
{"Ascent Speed", SAMPLE_EVENT_ASCENT},
{"Diluent Hyperoxia", SAMPLE_EVENT_NONE},
{"Violated Deep Stop", SAMPLE_EVENT_VIOLATION},
{"Ceiling Broken", SAMPLE_EVENT_CEILING},
{"PO2 High", SAMPLE_EVENT_PO2},
{"PO2 Low", SAMPLE_EVENT_PO2},
};
dc_sample_value_t sample = {0};
const char *name; const char *name;
dc_sample_value_t sample = {0};
name = info->alarm_type; name = info->alarm_type;
if (!name) if (!name)
return; return;
sample.event.type = lookup_event(name, alarms, C_ARRAY_SIZE(alarms)); sample.event.type = SAMPLE_EVENT_STRING;
if (sample.event.type == SAMPLE_EVENT_NONE) sample.event.name = name;
return;
sample.event.flags = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END; sample.event.flags = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END;
sample.event.flags |= 4 << SAMPLE_FLAGS_SEVERITY_SHIFT;
if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata);
} }
@ -1014,6 +956,19 @@ suunto_eonsteel_parser_samples_foreach(dc_parser_t *abstract, dc_sample_callback
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }
static dc_status_t get_string_field(suunto_eonsteel_parser_t *eon, unsigned idx, dc_field_string_t *value)
{
if (idx < MAXSTRINGS) {
dc_field_string_t *res = eon->cache.strings+idx;
if (res->desc && res->value) {
*value = *res;
return DC_STATUS_SUCCESS;
}
}
return DC_STATUS_UNSUPPORTED;
}
// Ugly define thing makes the code much easier to read // Ugly define thing makes the code much easier to read
// I'd love to use __typeof__, but that's a gcc'ism // I'd love to use __typeof__, but that's a gcc'ism
#define field_value(p, set) \ #define field_value(p, set) \
@ -1082,11 +1037,13 @@ suunto_eonsteel_parser_get_field(dc_parser_t *parser, dc_field_type_t type, unsi
* We need to have workpressure and a valid tank. In that case, * We need to have workpressure and a valid tank. In that case,
* a fractional tank size implies imperial. * a fractional tank size implies imperial.
*/ */
if (tank->workpressure && (tank->type == DC_TANKVOLUME_METRIC)) { if (tank->workpressure && (tank->type & DC_TANKINFO_METRIC)) {
if (fabs(tank->volume - rint(tank->volume)) > 0.001) if (fabs(tank->volume - rint(tank->volume)) > 0.001)
tank->type = DC_TANKVOLUME_IMPERIAL; tank->type += DC_TANKINFO_IMPERIAL - DC_TANKINFO_METRIC;
} }
break; break;
case DC_FIELD_STRING:
return get_string_field(eon, flags, (dc_field_string_t *)value);
default: default:
return DC_STATUS_UNSUPPORTED; return DC_STATUS_UNSUPPORTED;
} }
@ -1137,7 +1094,7 @@ static void set_depth_field(suunto_eonsteel_parser_t *eon, unsigned short d)
// "enum:0=Off,1=Primary,2=?,3=Diluent" // "enum:0=Off,1=Primary,2=?,3=Diluent"
// "enum:0=Off,1=Primary,3=Diluent,4=Oxygen" // "enum:0=Off,1=Primary,3=Diluent,4=Oxygen"
// //
// We turn that into the DC_TANKVOLUME data here, but // We turn that into the DC_TANKINFO data here, but
// initially consider all non-off tanks to me METRIC. // initially consider all non-off tanks to me METRIC.
// //
// We may later turn the METRIC tank size into IMPERIAL if we // We may later turn the METRIC tank size into IMPERIAL if we
@ -1145,7 +1102,7 @@ static void set_depth_field(suunto_eonsteel_parser_t *eon, unsigned short d)
static int add_gas_type(suunto_eonsteel_parser_t *eon, const struct type_desc *desc, unsigned char type) static int add_gas_type(suunto_eonsteel_parser_t *eon, const struct type_desc *desc, unsigned char type)
{ {
int idx = eon->cache.ngases; int idx = eon->cache.ngases;
dc_tankvolume_t tankinfo = DC_TANKVOLUME_METRIC; dc_tankinfo_t tankinfo = DC_TANKINFO_METRIC;
const char *name; const char *name;
if (idx >= MAXGASES) if (idx >= MAXGASES)
@ -1156,9 +1113,9 @@ static int add_gas_type(suunto_eonsteel_parser_t *eon, const struct type_desc *d
if (!name) if (!name)
DEBUG(eon->base.context, "Unable to look up gas type %u in %s", type, desc->format); DEBUG(eon->base.context, "Unable to look up gas type %u in %s", type, desc->format);
else if (!strcasecmp(name, "Diluent")) else if (!strcasecmp(name, "Diluent"))
; tankinfo |= DC_TANKINFO_CC_DILUENT;
else if (!strcasecmp(name, "Oxygen")) else if (!strcasecmp(name, "Oxygen"))
; tankinfo |= DC_TANKINFO_CC_O2;
else if (!strcasecmp(name, "None")) else if (!strcasecmp(name, "None"))
tankinfo = DC_TANKVOLUME_NONE; tankinfo = DC_TANKVOLUME_NONE;
else if (strcasecmp(name, "Primary")) else if (strcasecmp(name, "Primary"))
@ -1210,6 +1167,42 @@ static int add_gas_workpressure(suunto_eonsteel_parser_t *eon, float wp)
return 0; return 0;
} }
static int add_string(suunto_eonsteel_parser_t *eon, const char *desc, const char *value)
{
int i;
eon->cache.initialized |= 1 << DC_FIELD_STRING;
for (i = 0; i < MAXSTRINGS; i++) {
dc_field_string_t *str = eon->cache.strings+i;
if (str->desc)
continue;
str->desc = desc;
str->value = strdup(value);
break;
}
return 0;
}
static int add_string_fmt(suunto_eonsteel_parser_t *eon, const char *desc, const char *fmt, ...)
{
char buffer[256];
va_list ap;
/*
* We ignore the return value from vsnprintf, and we
* always NUL-terminate the destination buffer ourselves.
*
* That way we don't have to worry about random bad legacy
* implementations.
*/
va_start(ap, fmt);
buffer[sizeof(buffer)-1] = 0;
(void) vsnprintf(buffer, sizeof(buffer)-1, fmt, ap);
va_end(ap);
return add_string(eon, desc, buffer);
}
static float get_le32_float(const unsigned char *src) static float get_le32_float(const unsigned char *src)
{ {
union { union {
@ -1233,7 +1226,16 @@ static int traverse_device_fields(suunto_eonsteel_parser_t *eon, const struct ty
const unsigned char *data, int len) const unsigned char *data, int len)
{ {
const char *name = desc->desc + strlen("sml.DeviceLog.Device."); const char *name = desc->desc + strlen("sml.DeviceLog.Device.");
if (!strcmp(name, "SerialNumber"))
return add_string(eon, "Serial", data);
if (!strcmp(name, "Info.HW"))
return add_string(eon, "HW Version", data);
if (!strcmp(name, "Info.SW"))
return add_string(eon, "FW Version", data);
if (!strcmp(name, "Info.BatteryAtStart"))
return add_string(eon, "Battery at start", data);
if (!strcmp(name, "Info.BatteryAtEnd"))
return add_string(eon, "Battery at end", data);
return 0; return 0;
} }
@ -1264,12 +1266,30 @@ static int traverse_gas_fields(suunto_eonsteel_parser_t *eon, const struct type_
if (!strcmp(name, ".Gas.Helium")) if (!strcmp(name, ".Gas.Helium"))
return add_gas_he(eon, data[0]); return add_gas_he(eon, data[0]);
if (!strcmp(name, ".Gas.TransmitterID"))
return add_string(eon, "Transmitter ID", data);
if (!strcmp(name, ".Gas.TankSize")) if (!strcmp(name, ".Gas.TankSize"))
return add_gas_size(eon, get_le32_float(data)); return add_gas_size(eon, get_le32_float(data));
if (!strcmp(name, ".Gas.TankFillPressure")) if (!strcmp(name, ".Gas.TankFillPressure"))
return add_gas_workpressure(eon, get_le32_float(data)); return add_gas_workpressure(eon, get_le32_float(data));
// There is a bug with older transmitters, where the transmitter
// battery charge returns zero. Rather than returning that bogus
// data, just don't return any battery charge information at all.
//
// Make sure to add all non-battery-charge field checks above this
// test, so that it doesn't trigger for anything else.
if (!data[0])
return 0;
if (!strcmp(name, ".Gas.TransmitterStartBatteryCharge"))
return add_string_fmt(eon, "Transmitter Battery at start", "%d %%", data[0]);
if (!strcmp(name, ".Gas.TransmitterEndBatteryCharge"))
return add_string_fmt(eon, "Transmitter Battery at end", "%d %%", data[0]);
return 0; return 0;
} }
@ -1326,12 +1346,22 @@ static int traverse_diving_fields(suunto_eonsteel_parser_t *eon, const struct ty
return 0; return 0;
} }
if (!strcmp(name, "Algorithm"))
return add_string(eon, "Deco algorithm", data);
if (!strcmp(name, "DiveMode")) { if (!strcmp(name, "DiveMode")) {
if (!strncmp((const char *)data, "CCR", 3)) { if (!strncmp((const char *)data, "CCR", 3)) {
eon->cache.divemode = DC_DIVEMODE_CCR; eon->cache.divemode = DC_DIVEMODE_CCR;
eon->cache.initialized |= 1 << DC_FIELD_DIVEMODE; eon->cache.initialized |= 1 << DC_FIELD_DIVEMODE;
} }
return 0; return add_string(eon, "Dive Mode", data);
}
/* Signed byte of conservatism (-2 .. +2) */
if (!strcmp(name, "Conservatism")) {
int val = *(signed char *)data;
return add_string_fmt(eon, "Personal Adjustment", "P%d", val);
} }
if (!strcmp(name, "LowSetPoint")) { if (!strcmp(name, "LowSetPoint")) {
@ -1346,6 +1376,18 @@ static int traverse_diving_fields(suunto_eonsteel_parser_t *eon, const struct ty
return 0; return 0;
} }
// Time recoded in seconds.
// Let's just agree to ignore seconds
if (!strcmp(name, "DesaturationTime")) {
unsigned int time = array_uint32_le(data) / 60;
return add_string_fmt(eon, "Desaturation Time", "%d:%02d", time / 60, time % 60);
}
if (!strcmp(name, "SurfaceTime")) {
unsigned int time = array_uint32_le(data) / 60;
return add_string_fmt(eon, "Surface Time", "%d:%02d", time / 60, time % 60);
}
return 0; return 0;
} }
@ -1372,6 +1414,8 @@ static int traverse_header_fields(suunto_eonsteel_parser_t *eon, const struct ty
eon->cache.maxdepth = d; eon->cache.maxdepth = d;
return 0; return 0;
} }
if (!strcmp(name, "DateTime"))
return add_string(eon, "Dive ID", data);
return 0; return 0;
} }

View File

@ -131,6 +131,81 @@ syserror(int errcode)
#endif #endif
#endif #endif
static dc_status_t
usbhid_packet_close(dc_custom_io_t *io)
{
dc_iostream_t *usbhid = (dc_iostream_t *)io->userdata;
return dc_usbhid_close(usbhid);
}
static dc_status_t
usbhid_packet_read(dc_custom_io_t *io, void* data, size_t size, size_t *actual)
{
dc_iostream_t *usbhid = (dc_iostream_t *)io->userdata;
return dc_usbhid_read(usbhid, data, size, actual);
}
/*
* FIXME! The USB HID "report type" is a disaster, and there's confusion
* between libusb and HIDAPI. The Scubapro G2 seems to need an explicit
* report type of 0 for HIDAPI, but not for libusb.
*
* See commit d251b37 ("Add a zero report ID to the commands") for the
* Scubapro G2 - but that doesn't actually work with the BLE case, so
* I really suspect that we need to do something _here_ in the packet
* IO layer, and have the USBHID registration set the report type to
* use (ie an extra new argument to dc_usbhid_custom_io() to set the
* report type, or something).
*
* The Suunto EON Steel just uses 0x3f and does that in the caller.
*/
static dc_status_t
usbhid_packet_write(dc_custom_io_t *io, const void* data, size_t size, size_t *actual)
{
dc_iostream_t *usbhid = (dc_iostream_t *)io->userdata;
return dc_usbhid_write(usbhid, data, size, actual);
}
dc_status_t
dc_usbhid_custom_io (dc_context_t *context, unsigned int vid, unsigned int pid)
{
dc_iostream_t *usbhid;
dc_status_t status;
static dc_custom_io_t custom = {
.packet_size = 64,
.packet_close = usbhid_packet_close,
.packet_read = usbhid_packet_read,
.packet_write = usbhid_packet_write,
};
status = dc_usbhid_open(&usbhid, context, vid, pid);
if (status != DC_STATUS_SUCCESS)
return status;
custom.userdata = (void *)usbhid;
dc_context_set_custom_io(context, &custom, NULL);
dc_usbhid_set_timeout(usbhid, 10);
/* Get rid of any pending stale input first */
/* NOTE! This will cause an annoying warning from dc_usbhid_read() */
for (;;) {
size_t transferred = 0;
unsigned char buf[64];
dc_status_t rc = dc_usbhid_read(usbhid, buf, sizeof(buf), &transferred);
if (rc != DC_STATUS_SUCCESS)
break;
if (!transferred)
break;
}
dc_usbhid_set_timeout(usbhid, 5000);
return DC_STATUS_SUCCESS;
}
#ifdef USBHID #ifdef USBHID
static dc_mutex_t g_usbhid_mutex = DC_MUTEX_INIT; static dc_mutex_t g_usbhid_mutex = DC_MUTEX_INIT;
static size_t g_usbhid_refcount = 0; static size_t g_usbhid_refcount = 0;
@ -271,7 +346,7 @@ dc_usbhid_open (dc_iostream_t **out, dc_context_t *context, unsigned int vid, un
} }
if (device == NULL) { if (device == NULL) {
ERROR (context, "No matching USB device found."); ERROR (context, "No matching USB device (%04x:%04x) found.", vid, pid);
status = DC_STATUS_NODEVICE; status = DC_STATUS_NODEVICE;
goto error_usb_free_list; goto error_usb_free_list;
} }

View File

@ -43,6 +43,10 @@ extern "C" {
dc_status_t dc_status_t
dc_usbhid_open (dc_iostream_t **iostream, dc_context_t *context, unsigned int vid, unsigned int pid); dc_usbhid_open (dc_iostream_t **iostream, dc_context_t *context, unsigned int vid, unsigned int pid);
/* Create a dc_custom_io_t that uses usbhid for packet transfer */
dc_status_t
dc_usbhid_custom_io(dc_context_t *context, unsigned int vid, unsigned int pid);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */