Compare commits

..

600 Commits

Author SHA1 Message Date
d5f9b352fc Bluetooth updates for DSX 2024-06-14 17:51:26 -04:00
311f8d05f4 Fix EOL to CRLF 2024-06-14 17:37:27 -04:00
deaaeee7a1 Fix undeclared variables 2024-06-14 17:31:24 -04:00
c281b04bfc Fix invalid files 2024-06-14 15:01:47 -04:00
132a3949fd Add support for the Aqualung i330R and Apeks DSX 2024-06-14 14:52:50 -04:00
27a37fc95a Revert "Add support for the Aqualung i330R and Apeks DSX"
This reverts commit d1106cb8babb993d97b816f8274e22ae4fa6a08d.
2024-06-14 14:04:43 -04:00
d1106cb8ba Add support for the Aqualung i330R and Apeks DSX 2024-06-14 13:50:39 -04:00
Michael Keller
9641883f2f
Merge pull request #64 from mikeller/fix_sensor_count 2024-06-02 16:30:57 +12:00
Michael Keller
c7e89eab11 Garmin: Fix Reporting of Sensor Count.
Report the number of tank sensors independently of the number of
gasmixes. This fixes an unintuitive error message popping up when
importing dives with more sensors than gasmixes.

Fixes https://github.com/subsurface/subsurface/issues/4221.

Reported-by: @bwong2132
Signed-off-by: Michael Keller <mikeller@042.ch>
2024-05-31 11:35:32 +12:00
Michael Keller
9b12e8e638
Merge pull request #63 from mikeller/cherry_pick_mares_fix 2024-05-25 08:50:41 +12:00
Jef Driesen
d9c230820f Fix the Mares usb-serial communication
The BLE changes in commit e83732e200620882b13804f1ca54c1ab90a38188 are
causing major problems for some of the usb-serial enabled models, like
the Puck Pro and Quad Air.

These models appear to require a small delay of a few milliseconds
between sending the two command bytes and the remainder of the command
payload. I suspect the device is still busy processing those first two
bytes, and thus not ready in time to receive the remaining data. Instead
of manually adding a fixed delay, restore the previous behaviour and
wait for the ack byte again. This has the advantage that the delay is
automatically proportional to the response time of the dive computer.

For the BLE communication nothing changes.
2024-05-19 18:49:20 +12:00
Michael Keller
5d321deb8a
Merge pull request #62 from mikeller/remove_garmin_filter 2024-05-08 12:29:29 +12:00
Michael Keller
9f2674ee7c
Merge pull request #61 from mikeller/add_shearwater_stack_status 2024-05-08 12:29:10 +12:00
Michael Keller
6bd1183c34
Merge pull request #59 from mikeller/fix_shearwater_sensor_calibration 2024-05-08 12:28:54 +12:00
Michael Keller
0c125489df
Merge pull request #57 from mikeller/remove_shearwater_predator_timesync 2024-05-08 12:27:55 +12:00
Michael Keller
fa224f5300 Shearwater: Add Stack Timer Information.
Add the configured stack run time and the remaining stack run time at
the start and end of the dive as extra information.

Signed-off-by: Michael Keller <github@ike.ch>
2024-05-07 19:40:48 +12:00
Michael Keller
8f686ce1d8 Shearwater: Remove timesync for Predator.
Remove the timesync function from the code for the Predator - testing
has shown that this function is not supported by this model.

Signed-off-by: Michael Keller <github@ike.ch>
2024-05-07 12:28:39 +12:00
Michael Keller
a7fb341fb0 Shearwater: Add Sensor Calibration Info.
Add the calibration values for ppO2 sonsors in CCR mode as extra info
fields.

Signed-off-by: Michael Keller <github@ike.ch>
2024-05-07 09:44:46 +12:00
=Michael Keller
ff0023b8b4 Garmin: Remove Unused Transport Filter.
Remove the unused transport filter for the file based Garmin importers,
as it is not used at all in the way that the USB storage transport is
implemented.

Signed-off-by: Michael Keller <github@ike.ch>
2024-05-05 20:36:22 +12:00
Michael Keller
6e65428fc8 Shearwater: Fix Sensor Calibration for DiveCAN Controllers.
Remove the code that forces hiding of O2 sensor readings despite the
sensors being reported as properly calibrated by the divecomputer.
This fixes the problem of no sensor readings showing on DiveCAN
controllers due to the fact that the sensor calibration values are
returned as defaults on these devices.
Also increase the timeout for data reads - this seems to improve the
reliability when reading logs of long dives.

Signed-off-by: Michael Keller <github@ike.ch>
2024-05-04 01:53:50 +12:00
Michael Keller
89221475cf
Merge pull request #60 from mikeller/fix_serial_setting
I verified that this bug is breaking the reporting of the serial number on my dive computers as well - they all report as `0`. Merging this as it is affecting a lot of users.
2024-05-04 01:40:03 +12:00
Michael Keller
bff6f7c140 Fix Setting of the Device Serial Number.
Fix setting of the serial number in `dc_parser_new()`.

Fixes https://github.com/subsurface/subsurface/issues/4155

Signed-off-by: Michael Keller <mikeller@042.ch>
2024-05-03 16:09:02 +12:00
Michael Keller
ca55a11ed5
Merge pull request #58 from mikeller/add_garmin_descent_mk3_support
Merging this - there is demand for this fix, so now is a good time to get it tested: https://groups.google.com/g/subsurface-divelog/c/7Uo7A9YTGhg/m/BlhlZ2NNBQAJ
2024-04-28 18:46:40 +12:00
Michael Keller
bb502c6d8b Garmin: Fixes to Add Support .fit format version 2.1.
Ignore timestamps on messages that we do not read any other fields from
- with the new (firmware >= 16.x) .fit file format these messages seem
to be sent out of order, causing other messages to be ignored if they
come after them in the file but are before them in the timeline.
Track the OC / CCR state at the beginning of the dive based on the
dive type - this avoids spurious 'switched to ...' messages caused by
new 'gas switch' messages at the beginning of dives.

See also https://forums.garmin.com/developer/fit-sdk/b/news-announcements/posts/important-fit-activity-file-message-change

Signed-off-by: Michael Keller <github@ike.ch>
2024-04-26 01:17:06 +12:00
Michael Keller
792090566e Garmin: Add Support for Descent Mk3(i).
Add support for the Garmin Descent Mk3(i) models.
This pretty much just updates the entry in the device list to cover Mk2
and Mk3 models.
It does nothing to add support for MTP when reading from an Mk3 model -
I have not been able to get MTP support on linux going reliably, and I
do not have an Mk2 / Mk3 to test with anyway.
I suspect that MTP support is incomplete anyway, as the
product IDs for models like the Mk2S and Mk2G are not detected.
This change also adds an extra info field for the Model (based on a
heuristic and incomplete list).
It also fixes the data type for the sensor_type field.

Signed-off-by: Michael Keller <mikeller@042.ch>
2024-04-22 00:56:44 +12:00
Michael Keller
62a29eea15
Merge pull request #56 from mikeller/update_libdivecomputer_202402 2024-02-26 13:00:50 +13:00
Michael Keller
4bbfe1659e Shearwater: Fix Up Timesynch Changes.
A few fixes for bugs introduced during merge conflict resolution.

Signed-off-by: Michael Keller <mikeller@042.ch>
2024-02-14 12:01:58 +13:00
Michael Keller
39bc2fe05c Import: Clean up gasmix / tank usage.
Separate the usage enums and remove the unneeded values from each.

Signed-off-by: Michael Keller <github@ike.ch>
2024-02-14 12:01:51 +13:00
Michael Keller
edfb1a9c67 Import: Update Garmin Descent Import for libdivecomputer Update.
Update the importer for Garmin Descent to work with the latest upstream
version of libdivecomputer.

Signed-off-by: Michael Keller <github@ike.ch>
2024-02-14 11:38:31 +13:00
Michael Keller
d37cb91734 Merge remote-tracking branch 'libdivecomputer/master' into update_libdivecomputer_202402 2024-02-02 17:40:41 +13:00
Michael Keller
78710ab2f1
Merge pull request #55 from subsurface/add_garmin_descent_mk3_parsing_support 2024-01-23 11:08:37 +13:00
Michael Keller
76170009b4 Garmin: Add Support for Parsing of Garmin Descent Mk3 FIT files.
Add support for FIT files generated by the Garmin Descent Mk3.
This just fixes a field number limitation, it has not yet been
verified that the Mk3 file format is properly interpreted by Subsurface.

Signed-off-by: Michael Keller <mikeller@042.ch>
2024-01-22 12:54:02 +13:00
Jef Driesen
1d0aeecf65 Fix the React Pro White memory layout 2024-01-18 10:53:08 +01:00
Jef Driesen
de6696bc7f Add support for the Shearwater Tern 2024-01-17 07:48:54 +01:00
Jef Driesen
cfe345aa8e Exclude O2 sensors without calibration data
O2 sensor for which no calibration data is available will always result
in a ppO2 value of zero for all samples, which isn't very useful.
2024-01-12 09:15:12 +01:00
Jef Driesen
d47e1ce02b Add support for the Scubapro G3 and Luna 2.0
The new models appear to be compatible with the previous G2, but with
new model numbers and bluetooth names. The USB VID/PID for the G3 is
still unknown.

Reported-by: Greg McLaughlin <support@moremobilesoftware.com>
2024-01-10 09:01:59 +01:00
Jef Driesen
08d8c3e132 Add support for parsing the compass bearings
When no compass bearing is set on the dive computer, the stored value is
initialized to zero. Since this can also be a valid value, those zero
values are only ignored untill another non-zero value is present.

In later firmware versions, the value will get initialized to 0xFFFF
instead.
2023-11-23 11:42:23 +01:00
Jef Driesen
2d9008aff7 Remove disabled gas mixes
Returning disabled gas mixes to the application mainly results in lots
of unnecessary information. Therefore, remove all disabled gas mixes,
unless they are actively used. Many other dive computers do not even
include disabled gas mixes in the data.

Unlike previously assumed, the on/off state of each gas mix is actually
available in the PNF data format (opening record 4). For the older
Predator data format, this info isn't available and all gas mixes are
manually marked as enabled.
2023-11-15 11:08:21 +01:00
Jef Driesen
e1762fc8bd Skip all non-sample records
The IX3M 2 with the APOS5 firmware supports a new info record containing
the GPS coordinates. To be able to identify this new record type, the
previously reserved field at byte offset 52 is now used to store the
record type: zero for the existing sample record and one for the new
info record.

This also fixes the underlying problem of the zero timestamp in commit
3c50e91a1096332df66b2d33d64e5a8dc9136ab9, because the zero timestamp was
the result of incorrectly interpreting the first info record as a sample
record.
2023-11-02 15:45:24 +01:00
Jef Driesen
3c50e91a10 Allow a zero timestamp for the first sample
Previously the timestamp of the first sample was always a non-zero
value, but the IX3M 2 with the APOS5 firmware now appears to record a
timestamp of zero. This was incorrectly detected as a backwards time
jump because the time is also initialized to zero.
2023-10-29 21:31:40 +01:00
Jef Driesen
cb0164150e Merge branch 'bluelinkpro' 2023-10-19 10:34:26 +02:00
Jef Driesen
e83732e200 Fix the Mares Bluelink Pro communication
Sending the two byte command header and then waiting for the ack byte
before sending the remainder of the command payload causes problems for
some (but not all) users. Most likely the extra roundtrip time due to
waiting for the ack byte results in a delay that sometimes exceeds a
timeout in the dive computer while it's waiting for the payload data.

On the other hand, sending both the command header and the payload data
in one single packet is also not an option, because it causes problems
for some models, like the Mares Matrix. See commit
59bfb0f3189b14ae858650b851539d59e3fefe86 for details.

As an alternative solution, send the packet payload immediately after
the header, without waiting for the ack byte. This eliminates the extra
roundtrip time, while still sending out two separate bluetooth packets.
2023-09-27 10:10:40 +02:00
Jef Driesen
a7e7439cab Setup the 2 byte command header internally
Instead of setting up the two byte command header in every function,
move this logic to a central place.
2023-09-15 09:23:58 +02:00
Jef Driesen
072f0d4242 Fix a potential buffer overflow 2023-09-08 16:10:45 +02:00
Jef Driesen
baa1c494c1 Use a symbolic constant for the header size 2023-09-08 16:10:45 +02:00
Jef Driesen
330cb88952 Use plain ascii text in the code comments 2023-09-08 16:10:38 +02:00
Jef Driesen
37421a1b9a Merge branch 'filter-function' 2023-08-24 17:18:46 +02:00
Jef Driesen
fe9b47f4bd Document the device descriptor functions 2023-08-24 17:18:24 +02:00
Jef Driesen
ed871137b1 Export the filter function in the public api
The functionality provided by the filter function is not only useful for
the built-in transports, but also for the applications. For example in
combination with a custom transport.
2023-08-24 17:18:24 +02:00
Jef Driesen
4a9be44afd Use separate data structures for USB and USB HID
Using separate data structures for the filtering allows to keep the USB
and USB HID backends completely independent from each other.
2023-08-24 17:18:24 +02:00
Jef Driesen
a985b11859 Replace the filter parameters with an alternative
The USB I/O backend needs some additional information (e.g. interface
number and in/out endpoints) to setup the USB connection. This info is
currently maintained inside the descriptor filter function and gets
passed to the USB backend by means of the filter parameters.

This approach is not only unnecessary complex, but also makes it very
difficult to expose the filter function in the public api because the
data structures for those parameters are private.

Therefore, this data exchange is replaced with a direct mapping between
the USB VID/PID and the configuration info in the USB backend itself.
2023-08-24 17:18:24 +02:00
Jef Driesen
b2310e62d6 Pass the descriptor to the filter function
Passing the descriptor for which the filter function is being called is
a good practice and will also allow to implement some more specific
filtering in the future.
2023-08-24 17:18:22 +02:00
Jef Driesen
301fdbe364 Remove support for the Tusa TC1
Apparantly the Tusa TC1 does not support downloading dives at all. The
bluetooth communication is probably disabled in the firmware.
2023-08-16 13:17:55 +02:00
Jef Driesen
beb348dbf6 Merge branch 'ostc-remove-disabled-gasmixes' 2023-08-14 10:23:55 +02:00
Jef Driesen
5d36cc0798 Remove disabled gas mixes
Returning disabled gas mixes to the application mainly results in lots
of unnecessary information. Therefore, remove all disabled gas mixes,
unless they are actively used. Many other dive computers do not even
include disabled gas mixes in the data.

The removal of the disabled gas mixes requires a two pass approach for
parsing the profile data. The first pass is only used to discover which
gas mixes are actively used during the dive. Next, all disabled and not
actively used gas mixes are removed from the list. Since removing one or
more gas mixes also invalidates the index of the remaining gas mixes,
the profile needs to be parsed again to report the new index in the gas
switch samples.

The original one based index is used as the stable gas mix id, used for
looking up the new gas mix index.
2023-08-11 12:39:39 +02:00
Jef Driesen
993283d1c8 Store the original one based gas mix index 2023-08-10 14:04:52 +02:00
Jef Driesen
323804d5e6 Keep track of the actively used gas mixes
The hwOS models support switching to a disabled gas mix. Therefore, the
disabled state is not always a good indication whether a gas mix is used
or not. Look for gas switches during the parsing step instead to keep
track of the actively used gas mixes.
2023-08-10 14:04:20 +02:00
Jef Driesen
ecc9e0b09b Limit the lookup function to the manual gas mixes
Looking up the gasmix by oxygen and helium content is only needed for
the manual gas mixes. For gas switches to a fixed gas mix, the index is
stored directly in the data.
2023-08-02 15:43:19 +02:00
Michael Keller
577b694087
Merge pull request #54 from mikeller/improve_cressi_leonardo_ascent_warnings 2023-08-01 21:43:41 +12:00
Michael Keller
58ea31e62e Cressi Leonardo: Turn ascent warnings into info events.
According to user feedback the ascent warnings on the Cressi Leonardo
are very sensitive. They come in 3 different levels.
This change turns levels 1 and 2 into info events, leaving only 3 as a
warning.
Fixes https://groups.google.com/g/subsurface-divelog/c/qBXF0wmyjKg/m/5qA0_KABCQAJ

Signed-off-by: Michael Keller <github@ike.ch>
2023-07-28 00:02:14 +12:00
Michael Keller
97b2c89aaa
Merge pull request #52 from mikeller/hw_ostc_mark_inactive_gases 2023-07-23 15:43:32 +12:00
Jef Driesen
8bfbb94087 Include the command byte in the hexdump
The hexdump only includes the command parameters, but not the main
command byte. Since there are many commands without parameters, that's
not very useful.
2023-07-20 23:40:02 +02:00
Jef Driesen
9cde393e5f Merge branch 'shearwater-tank-usage' 2023-07-18 00:30:22 +02:00
Jef Driesen
9bc742d3ac Use the HP CCR data for the oxygen/diluent usage
For dives in HP CCR mode, the oxygen and diluent tanks are stored at a
fixed index. This information is more reliable than using the tank name,
and also prevents the incorrect labeling of one of the other tanks as an
oxygen or diluent tank.
2023-07-18 00:30:06 +02:00
Jef Driesen
a4cd21b811 Use the GTR mode to detect sidemount tanks
Firmware v84 introduced support for sidemount diving. Users can now
configure the two sidemount tanks as the source for the GTR (Gas Time
Remaining) estimations. We can take advantage of this feature to detect
the sidemount tanks. This is more reliable than using the tank name.
2023-07-18 00:30:06 +02:00
Jef Driesen
f77e9c03fc Restrict the oxygen/diluent usage to CCR dives
For open-circuit dives, the oxygen and diluent usage doesn't make any
sense at all. But when an open-circuit diver uses the letter 'D' to
indicate a tank for decompression use, it will get incorrectly labeled
as a diluent tank.

Fixed by restricting the oxygen/diluent usage to CCR dives only.
2023-07-18 00:30:06 +02:00
Jef Driesen
f818a5a92a Add a function for detecting CCR dives 2023-07-18 00:30:06 +02:00
Linus Torvalds
3e39cb427a garmin: fix up some leftovers
When importing FIT files, we may not have serial numbers or firmware
versions in the result, so don't report them when they don't exist.

Also, add the product name to the FILE message field list, which can
contain relevant information.  Not that we report it right now, but now
we *could* do so.

This concludes the Suunto FIT file export saga.  It's not great, but it
looks like it should be usable.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-07-16 11:28:33 -07:00
Linus Torvalds
e81eca685a garmin: add a _third_ time offset field
So FIT files seem to have many many different ways to describe time
offsets.  And I'm not talking about the overall Garmin time offset of
631065600, which is the conversion from the "Unix Epoch" (Jan 1, 1970)
to the "Garmin Epoch" (Dec 31, 1989).

No, I'm talking just about "device time" to "local time" to "UTC"
conversions.

The DEVICE_SETTINGS message has two different fields for time offsets:
there's a "UTC offset" (presumably this is the timezone the device is
set to), and a "time offset" which we actually use to transform the
recorded time of the dive into the local time that we report.

But the Suunto FIT export doesn't seem to use either of those, and
instead Nick Clark points outthe Suunto FAQ:

 "Timestamp fields are deliberately defined as UTC time so that they may
  be conveniently displayed in the local time if so desired.

  In some instances it is useful to know the UTC offset when the file
  was generated (possibly different from when it is decoded). This can
  be accomplished by logging a single message containing both a
  local_timestamp and a timestamp field. This will establish the UTC
  offset of the file.

  Presently these fields are predefined for activity and monitoring
  messages"

so to get the actual local time, instead of getting it from the
DEVICE_SETTINGS message, we now have to parse the ACTIVITY message, and
take the difference between the regular timestamp and the
"local_timestamp" field.

The great thing about standards is that there are so many to choose
from.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-07-16 11:17:32 -07:00
Linus Torvalds
dc8f32609e garmin: add 'FIELD_DESCRIPTION' message definitions
We don't use them, but they seem to be trying to describe what the
developer fields are used for.  We may now parse the developer fields
enough to skip over them gracefully, but it looks like we migth some day
want to _really_ parse them, and while I haven't figured it out (at
all!) yet, this may some day help.

For example, we get things like this:

  FIELD_DESCRIPTION_name (STRING): "Depth"
  FIELD_DESCRIPTION_unit (STRING): "feet"
  FIELD_DESCRIPTION_original_mesg (UINT16): 20
  FIELD_DESCRIPTION_data_index (UINT8): 0
  FIELD_DESCRIPTION_field_definition (UINT8): 0
  FIELD_DESCRIPTION_base_type (UINT8): 136

which doesn't tell me anything at all right now, but looks like maybe it
should some day.

It looks like this is defining a developer field for depth in feet
(duh), and the data format may be the same as a RECORD message (20),
which does indeed normally contain the depth (but in mm as an UINT32,
and it's field number 92, so..)

End result: not useful right now, because I'm much too confused about
it.  But the debug printout looks interesting.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-07-16 11:01:00 -07:00
Linus Torvalds
196cfdf4df garmin: add names for a few RECORD message fields
Not because we use them, but because it makes it clearer from the debug
output that we know what they are and that they aren't interesting..

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-07-16 11:01:00 -07:00
Linus Torvalds
503afc1a5f garmin: improve on the debug formatting for field printouts
This also gets the passing of string values right, even if we don't
actually use this right now.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-07-16 11:00:52 -07:00
Linus Torvalds
e02df46a2b garmin: remove some left-over verbose hexdump debugging
This was part of me trying to figure out the compressed formats and the
developer fields, it's just noise now.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-07-16 09:56:12 -07:00
Linus Torvalds
2879bd69a5 Garmin: parse the ACTIVITY message record
The ACTIVITY message contains a "local timestamp" in addition to the
regular timestamp. That gives us the timezone information.

Or rather, it would give us the timezone info if we actually used it.
But now we at least parse it, so that we *could* use it.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-07-15 10:11:04 -07:00
Linus Torvalds
4a2dec531e garmin: relax file name length rules
We end up using the FIT file name as the "fingerprint" for the dive, and
include it at the beginning of the dive data as such.  And because of
how Garmin encoded the FIT files, we ended up having a fixed 24-byte
length for this, which is normally the date encoding:

    YYYY-MM-DD-HH-MM-SS.FIT

with the terminating NUL character.

Of course, then Garmin started using a short-form encoding too
(presumably due to FAT filesystem limits), and we have magic code to
sort the dates properly, using the name format

    YMDHMMSS.FIT

with the numbers encoded in a shorter format (eg "C4ND0302.fit" is
equivalent to "2022-04-23-13-03-02.fit").  See name_cmp() and
parse_short_name() for details.

Anyway, because we use the (zero-padded) 24 characters of the name as
the fingerprint, we used a fixed-size buffer for the filename that was
limited to that maximum size Garmin creates.

But then you download those things, and have multiple vendors, and
suddenly that 24-character limit on the filename is very annoying.

Instead of fixing this in some clean and generic way, let's just raise
the namelength limit to something bigger, and continue to use the first
24 characters of the name for the fingerprint.

Pretty it isn't, but it makes it slightly easier to import random FIT
files that don't conform exactly to the traditional Garmin format.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-07-14 12:31:33 -07:00
Linus Torvalds
67cd1cc0fd Expose FIT file parsing as its own "vendor"
Since we can now parse FIT files from other vendors than Garmin (ie the
Suunto FIT file export), let's expose this as a generic "FIT file
import" in the dive computer list.

It's all still very much using the Garmin parser, but uses a model ID
that is zero.  The only difference that makes is that it also tells the
parser to treat the result as a dive even if it cannot find the actual
dive markers that Garmin uses, since those won't exist in the limited
FIT file export.

This is still somewhat inconvenient, in that you cannot point to the
file itself, you can just point to the directory that contains FIT
files.  And right now we have an artifical length limitation on the
filenames, but I'll fix that next.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-07-14 12:07:30 -07:00
Linus Torvalds
929ce47155 garmin_parser: add support for developer fields
This was the _actual_ reason why the Suunto FIT file import fell flat on
its face: it adds records with developer fields in them, and I just had
no idea how to parse them.

It turns out that they aren't all *that* horrible to parse: they are
kind of like a special case of the regular FIT event fields.

And no, this does not really parse them: it only parses the layout, and
using that it can then skip the developer fields without causing the
decoder to go all wonky and lose stream synchronization.

At least it works for the specific case of the Suunto FIT files, and the
code makes some amount of sense.  The FIT format may be odd, but at the
same time it's most definitely designed for pretty simplistic devices,
so it's not some kind of crazy XML thing.

This gets us parsing those Suunto FIT files at least partially.

That said, it is all very rough indeed, since you have to lie and claim
you're downloading from a Garmin, and have to set up the whole magic
'Garmin/Activity/' directory structure and limit the file size to the 24
characters that Garmin uses.

So this is by no means the real solution.

Considering that Jef doesn't want the Garmin parser in libdivecomputer
anyway, the proper solution might be to move this all to subsurface, and
make it be a "FIT file import" thing instead.  Annoying, but on the
other hand it has also been a bit awkward to have it in libdivecomputer.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-07-13 14:01:58 -07:00
Linus Torvalds
147d3df635 garmin_parser: add support for compressed records and more debug output
This turns out to have been another false turn: mis-parsing the FIT file
caused us to think it had compressed records.

So I spent much too much time trying to figure out how those compressed
records actually work.  This is the result.

It looks like the only difference between a compressed record and a
regular one is that the compressed record has a single-byte "this is the
record type and the time offset" field at the start.  That basically
avoids the need of then having a full 4-byte absolute time for such a
record.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-07-13 13:58:44 -07:00
Linus Torvalds
4aa70c9e2a garmin_parser: add a HRM profile message stub
This is an empty stub for the HRM profile message, which isn't actually
used by anything I know of, but came up as a result of some mis-parsing
of odd FIT files generated by the Suunto mobile app.

Losing synchronization in the FIT file then caused the parser to think
it needed this message type, and not having it then caused an early
abort.

While it's not actually needed once parsing things correctly, since I
looked up the message number and name for this message type, let's just
keep it around.  It won't hurt, and maybe it avoids me having to look it
up in the future.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-07-13 13:53:15 -07:00
Linus Torvalds
571df62ce5 garmin_parser: be a little less abrupt about parsing errors
Instead of returning an error on unrecognized input when parsing, just
skip to the end of the buffer.  This makes at least partially parsed
data available, which can help figure out what ended up happening.

This was part of my "Suunto also does FIT files now, and does them very
differently from Garmin" series.  I think I parse the Suunto files right
now, but next time this happens, I'd rather get partial data than no
data at all.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-07-13 13:49:00 -07:00
Jef Driesen
ceaaba3e77 Add support for the new Ratio iX3M 2 models
Except for the new prefix in the bluetooth name, the new models are
backwards compatible with the previous models.
2023-07-12 13:11:19 +02:00
Michael Keller
1222041b46 HW OSTC3/4: Mark Inactive Gases as Such.
Return `DC_STATUS_UNSUPPORTED` for inactive gas mixes, while retaining
the configured gas information. This makes it possible to mark inactive
gases as such, or completely hide them, without affecting the gas
indices that are referenced in gas switches.

Signed-off-by: Michael Keller <github@ike.ch>
2023-07-09 14:46:44 +12:00
Linus Torvalds
3733b87ac9 Merge branches 'add_shearwater_teric_timesync' and 'add_ostc4_dump_error' of https://github.com/mikeller/libdc into Subsurface-DS9
Pull libdivecomputer updates from Michael Keller:

 - Add time synchronisation for the Shearwater Teric

 - Fix two OSTC4 buglets

* 'add_shearwater_teric_timesync' of https://github.com/mikeller/libdc:
  Add Time Synchronisation for the  Shearwater Teric.

* 'add_ostc4_dump_error' of https://github.com/mikeller/libdc:
  Fix bugs in OSTC4 support.
2023-07-08 16:50:45 -07:00
Michael Keller
0afd62d7af Return an error for the OSTC4 memory dump
The OSTC4 does not support downloading memory dumps.
2023-07-07 12:30:46 +02:00
Michael Keller
3a68af418e Fix the OSTC4 firmware upgrade
In commit 1c8cd096b57a876c4fb0afc5113aac05d75d924e the block size was
changed from 64 to 1024 bytes. For bluetooth classic communication, this
shouldn't matter, but for some reason it does cause the OSTC4 firmware
upgrade to fail. Maybe some buffering problem in the OSTC4 firmware or
bluetooth stack?

Change the block size back to 64 bytes.
2023-07-07 12:30:46 +02:00
Jef Driesen
ff0328537e Ignore the diluents for open-circuit dives
For open-circuit dives it makes no sense to also include the configured
diluents. Usually those diluents are only present because the diver uses
the same dive computer for both open and closed circuit dives.
2023-07-06 14:12:41 +02:00
Jef Driesen
3d82d6796f Merge branch 'shearwater-timesync' 2023-07-05 23:49:38 +02:00
Jef Driesen
25bd1f9853 Add support for time synchronization
Add time synchronisation for the Shearwater dive computers. All models
support setting the local time. Only the Teric has basic support for
time zones, and can set UTC time with a timezone offset.

Co-authored-by: Michael Keller <github@ike.ch>
2023-07-05 15:43:12 +02:00
Jef Driesen
c16530b8ab Detect negative response packets
When the dive computer receives an RDBI or WDBI command it doesn't
support, it sends a 3 byte NAK packet containing an error code. Detect
these NAK packets and use it to return a more appropriate error.
2023-07-05 15:43:12 +02:00
Jef Driesen
d4402aa296 Add support for the WDBI function
The RDBI (Read Data by Identifier) has a WDBI (Write Data by Identifier)
counterpart, which supports changing settings on the dive computer.
2023-07-05 15:43:12 +02:00
Jef Driesen
13705f2b2d Use a static buffer for the RDBI function
The RDBI (Read Data by Identifier) responses always have a fixed length.
Using a resizable buffer for the API only makes the memory management
more complex than necessary.

Also add some symbolic constants to improve readability.
2023-07-05 15:43:12 +02:00
Jef Driesen
ee147afceb Move the model number mapping to a function 2023-07-05 15:43:12 +02:00
Michael Keller
b13ad617ac Fix bugs in OSTC4 support.
Fix two bugs in the support for OSTC4:
- change block size for writes back to 64 bytes to prevent buffer
  overflow on the dive computer side;
- added 'unsupported' response for the dump command on OSTC4.

Signed-off-by: Michael Keller <github@ike.ch>
2023-06-14 12:37:11 +12:00
Michael Keller
838717dbae Add Time Synchronisation for the Shearwater Teric.
Add time synchronisation support for the Shearwater Teric. Unlike the
other Shearwater dive computers this model has basic support for time
zones, so we need to set the time in UTC and configure the time zone
offset.

Signed-off-by: Michael Keller <github@ike.ch>
2023-06-08 22:25:26 +12:00
Linus Torvalds
436063c74d Merge tag 'v0.8.0' into Subsurface-DS9
Merge upstream version 0.8.0 into our libdc fork.

Since we tracked the development branch, we already had merged all the
main changes, but it's been a couple of months since the last upstream
merge, and there were a few new changes upstream:

 - Divesoft Freedom and Liberty support

 - A couple of iostream abstraction layers: a new 'packet layer' and a
   HDLC layer, moving code from low-level dive computer downloaders to
   generic iostream layers.

 - misc minor updates

* tag 'v0.8.0': (25 commits)
  Release version 0.8.0
  Fix the date of the v0.7.0 release
  Add a missing filter for the Aqualung i750TC
  Reduce the BLE output packet size to 20 bytes again
  Integrate the new packet I/O in the backends
  Add a generic packet I/O implementation
  Fix a typo in the documentation
  Add support for the Divesoft Freedom and Liberty
  Integrate the HDLC stream in the eonsteel backend
  Add a generic HDLC I/O implementation
  Remove the local endianess functions
  Use the correct function to free resources
  Add the udev rules to the distribution tarball
  Add a README file to the contrib directory
  Include the revision in the Visual Studio and Android builds
  Don't generate the Windows version resource
  Move the Visual Studio project to the contrib directory
  Add a basic Android build system
  Disable the getopt argument permutation on Android
  Move the sign extension function to a common place
  ...
2023-05-27 16:18:41 -07:00
Michael Keller
763fc68741 Shearwater: Add time synchronisation.
Add time synchronisation for Shearwater dive computers.
This synchronises the local time, which is all that is supported by all
Shearwater models except for the Teric.
Time synchronisation including the time zone for the Teric still has to
be added.

Signed-off-by: Michael Keller <github@ike.ch>
2023-05-20 19:25:20 +12:00
Jef Driesen
9b7aa813e0 Change the salinity format in the xml output
Replace the numeric type with a name (fresh or salt) and change the
density value into an xml attribute. The type is the primary
information here, while the density value is optional.
2023-05-16 13:48:49 +02:00
Jef Driesen
63f5a4d652 Remove the dc_parser_set_data function
The dc_parser_set_data() function allows to re-use a parser object for
multiple dives. The advantages of this feature are actually very limited
in practice. The reduction in memory consumption is almost negligible,
because the amount of internal state in the parser is typically very
small. But the implementation requires some additional complexity
because each backend needs code to reset its internal state. Therefore,
the function is removed and the data and size needs to be passed
directly to the dc_parser_new() and dc_parser_new2() functions instead.

Because keeping a reference to the data has also caused issues in the
past, especially for applications implemented in a garbage collected
language, the data will now also get copied internally.
2023-05-15 22:19:37 +02:00
Jef Driesen
679db0bae6 Remove the clock parameters from the constructor
Only a few dive computer backends (reefnet, aladin and memomouse)
require the clock parameters for parsing the date/time. Therefore,
those parameters are removed from the constructor function and
applications should set the clock parameters with the
dc_parser_set_clock() function instead.
2023-05-15 22:19:36 +02:00
Jef Driesen
0a4f37770f Remove the backend specific calibration functions
The backend specific calibration function are deprecated. Applications
should use the new replacement functions introduced in commit
6ab140461a3a85fba3803283070427f3be413c79.
2023-05-15 22:19:36 +02:00
Jef Driesen
4e24b3a277 Pass the sample struct by reference
Because the sample struct is passed by value, the size of the structure
can't be changed without also changing the function signature and
breaking backwards compatibility. This prevents adding new fields in the
future, to support some new features.

When passing the sample struct by reference using a pointer, the size of
the pointer does always remains the same.
2023-05-15 22:19:36 +02:00
Jef Driesen
becb8bd36e Add a usage field to the tank and gas mix
For gas consumption calculations it's very convenient to know whether a
tank is used for example in a sidemount configuration, or as
oxygen/diluent tank on a rebreather.

For rebreather dives, it's convenient to know whether a gas mix is used
as a closed-circuit mix (oxygen/diluent) or as an open circuit mix
(bailout).
2023-05-15 22:19:36 +02:00
Jef Driesen
4b383a778e Add a TTS field to the deco sample
Some dive computers report the time of the next decompression stop,
while others report the Time To Surface (TTS). Some models can even
report both.

Add a TTS field to the deco sample to support both values.
2023-05-15 22:19:36 +02:00
Jef Driesen
b1ff2c6a8e Add the sensor index to the ppO2 sample
Rebreathers typically support multiple ppO2 sensors as a safety measure
in case a sensor fails during the dive. The current api can already
report multiple ppO2 values per sample, but it does not provide any
information about which sensor the measurement is from.

The new sensor index provides this info, and can also be used to
distinguish between the average/voted ppO2 value using the special value
DC_SENSOR_NONE.
2023-05-15 22:19:36 +02:00
Jef Driesen
bca8f9e2d2 Enable the millisecond resolution sample time
After the previous commit changed the resolution of the sample time to
milliseconds, the dive computers which actually support a higher
resoltion can now enable this feature and report all samples.
2023-05-15 22:19:36 +02:00
Jef Driesen
a34e909a84 Change the units for the sample time to milliseconds
Some dive computers, especially freediving computers, supports multiple
samples per second. Since our smallest unit of time is one second, we
can't represent this, and the extra samples are dropped. Therefore, the
units are changed to milliseconds to prepare supporting this extra
resolution.
2023-05-15 22:19:34 +02:00
Jef Driesen
db9371cf9f Release version 0.8.0 2023-05-11 18:56:37 +02:00
Jef Driesen
070de23b83 Post release version bump to 0.9.0 2023-05-11 18:56:37 +02:00
Jef Driesen
49aa12b172 Fix the date of the v0.7.0 release 2023-05-11 16:27:55 +02:00
Jef Driesen
2f1b99f2f9 Add a missing filter for the Aqualung i750TC
Commit 58d410b1a217bbc1f03d5c7a5a203c139a92616c accidentally omitted the
descriptor filter function.
2023-05-11 16:26:40 +02:00
Jef Driesen
6c3bbb2cc7 Reduce the BLE output packet size to 20 bytes again
The newer u-Blox Nina B2 bluetooth module supports larger packets up to
244 bytes, but the older Telit/Stollman bluetooth module does not.
Trying to send a packet larger than 20 bytes fails. For maximum
compatibility, limit the output packet size to 20 bytes.
2023-05-11 16:25:59 +02:00
Jef Driesen
1c8cd096b5 Integrate the new packet I/O in the backends
Replace the custom packet handling code in the iconhd and ostc3 backends
with the new layered packet I/O, and also integrate it into the idive
and extreme backends.
2023-05-11 16:25:59 +02:00
Jef Driesen
40c95ca02a Add a generic packet I/O implementation
The new packet I/O provides a layered I/O for reading and writing a byte
stream from the underlying packet oriented transport.
2023-05-11 16:25:59 +02:00
Jef Driesen
72ddd6a439 Fix a typo in the documentation 2023-04-24 00:02:17 +02:00
Jef Driesen
d4472b758f Add support for the Divesoft Freedom and Liberty
The latest versions of the Divesoft Freedom (HW 4.x) and Liberty (HW
2.x) dive computers support BLE communication. Previous generations did
support only a mass storage mode, where the dives are available as DLF
files. The BLE communication protocol uses HDLC framing for the data
packets. The dives downloaded over BLE have the same data format as the
DLF files.

Co-authored-by: Jan Matoušek <jan.matousek@rekomando.cz>
Tested-by: Jakub Hečko <jakub.hecko@divesoft.com>
2023-04-24 00:02:17 +02:00
Jef Driesen
b0e77fd05f Integrate the HDLC stream in the eonsteel backend 2023-04-24 00:02:17 +02:00
Jef Driesen
cee9a2e926 Add a generic HDLC I/O implementation
The new HDLC I/O provides a generic I/O stream for reading and writing
HDLC encoded frames on top of another base I/O stream.
2023-04-24 00:02:17 +02:00
Jef Driesen
9c38ae3e01 Remove the local endianess functions
Replace the local functions for writing 16 and 32 bit little endian
values with the corresponding common functions.
2023-04-17 16:28:19 +02:00
Jef Driesen
629d567381 Use the correct function to free resources
Currently this doesn't make any difference because the
dc_device_allocate() function simply calls free(), but this may change
in the future.
2023-04-12 11:47:25 +02:00
Jef Driesen
bec4a747ff Add the udev rules to the distribution tarball 2023-04-07 20:37:19 +02:00
Jef Driesen
43f48af418 Add a README file to the contrib directory 2023-04-07 20:37:19 +02:00
Jef Driesen
e45c62b028 Include the revision in the Visual Studio and Android builds
During troubleshooting it's very convenient to know the exact version
used in a bug report. With the git commit SHA1 added to the version
string in all builds, that becomes very easy.
2023-04-07 20:37:17 +02:00
Jef Driesen
767a2fad91 Don't generate the Windows version resource
The Windows version resource is compiled and can include the (generated)
version.h header file for the definition of the version macros. There is
no need to have it generated by autotools. Less generated files makes it
easier to use other build systems, like Visual Studio.
2023-04-07 20:35:05 +02:00
Jef Driesen
083b1eb8de Move the Visual Studio project to the contrib directory
With this change all the alternative build systems are now located in
the contrib directory.
2023-04-07 20:35:05 +02:00
Jef Driesen
118f6d79ba Add a basic Android build system
Add a basic Android.mk for building with the Android NDK. This can serve
as a good starting point for developers integrating libdivecomputer into
an Android application.

Co-authored-by: Sven Knoch <info@divinglog.de>
2023-04-07 20:35:02 +02:00
Jef Driesen
cf221de9b7 Disable the getopt argument permutation on Android
On Android operating systems, the getopt() function is posix compliant
and thus the option processing stops when the first non-option is found.
But the getopt_long() function permutes the argument vector, just like
the GNU implementation.

Using a leading '+' character in the option string disables the
permutation again.
2023-04-07 14:04:00 +02:00
Dirk Hohndel
3a2dc6cce4 Adapt dctool to recent API change
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2023-03-29 11:24:43 -07:00
Jef Driesen
86fd58c8c6 Move the sign extension function to a common place 2023-03-23 19:43:16 +01:00
Jef Driesen
1930b9eb59 Merge branch 'checksums' 2023-03-23 19:41:11 +01:00
Jef Driesen
554855cc7d Add the 16-bit CRC-ANSI functions
Yet another family of 16-bit CRC function. The only difference with the
already available CRC-CCITT algorithm is the choice of the polynomial.
2023-03-23 19:31:01 +01:00
Jef Driesen
27b471e76b Document the properties of the CRC functions 2023-03-23 19:30:23 +01:00
Jef Driesen
00033e4af0 Rename the 32-bit CRC functions
The new names make it easier to identify the normal and reflected
variant of the CRC function.
2023-03-23 19:30:23 +01:00
Jef Driesen
d327aea6ff Add a reflected variant of the 16-bit CRC-CCITT
The reflected variant of a CRC does reverse the bits of each input byte
and requires a different lookup table for an efficient implementation.
2023-03-23 19:28:37 +01:00
Jef Driesen
12f44f3410 Add an extra parameter for the xorout value
This change allows to calculate some more variants of the CRC-CCITT
algorithm with a single function.
2023-03-23 19:28:24 +01:00
Michael Keller
46d4bee8ab Add option to force overwrite firmware for OSTC4.
In order to support development of the open source firmware of the
OSTC4.
This is needed in order to be able to install firmware with the same
version number multiple times during development and testing.

Signed-off-by: Michael Keller <github@ike.ch>
2023-03-17 19:41:05 +13:00
Michael Keller
c288effa01 HW: Add gas type reporting through tank information.
Use tank information to report the type of gas used (open circuit /
diluent) for different gas mixes.

Signed-off-by: Michael Keller <github@ike.ch>
2023-03-17 10:23:48 +13:00
Michael Keller
d9dd30f327 HW: Add bailout events.
Add explicit events for OC bailout / switch back to closed
circuit on Heinrichs Weikamp dive computers.

Signed-off-by: Michael Keller <github@ike.ch>
2023-03-17 10:23:29 +13:00
Michael Keller
8b5b86fb4e HW: Apply the OSTC4 gas index offset to all HW computers.
Apply the gasmix index offset used by the OSTC4 on CCR dives to all
Heinrichs Weikamp computers and all dive types.

Signed-off-by: Michael Keller <github@ike.ch>
2023-03-17 10:21:54 +13:00
Michael Keller
4ddef92b80 HW OSTC4: Fix and improve CCR gas handling.
Fix a bug for the OSTC4 using the wrong gas after (diluent) gas
changes because the diluent gas index is offset by 5 when in CCR mode.
Also fix a bug adding manually entered gases on CCR dives as diluent
on OSTC4 - only OC gases can be manually entered on this dive computer.

Signed-off-by: Michael Keller <github@ike.ch>
2023-03-17 10:21:47 +13:00
Linus Torvalds
543bd58ddd Merge https://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge Jef's upstream fix for the OSTC4 CCR gas parsing issue reported by
Michael Keller.

This also effectively obviates (and undoes) the revert I did in commit
8d3271e586cd.

* https://github.com/libdivecomputer/libdivecomputer:
  Fix the OSTC4 diluent changes
2023-03-16 09:49:21 -07:00
Linus Torvalds
8d3271e586 Revert "Limit the index to the fixed gas mixes"
This reverts commit 328812e95bfe7c6c9d2a8d36c75144f05c7dc9dc.

This turns out to cause fatal parse failures for the cases where the gas
change refers to a manual or bailout gas.

As noted by Jef in that commit, we should likely report those
differently, but in the meantime, at least don't fail the download.

See the original report at [1], and a (at this point still contentious)
bigger change to gas switch reporting at [2].  This revert exists purely
as a "make it at least work for now".

Reported-by: Michael Keller <github@ike.ch>
Link: https://github.com/subsurface/libdc/pull/46#issuecomment-1438313959 [1]
Link: https://github.com/subsurface/libdc/pull/44 [2]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-03-06 12:02:45 -08:00
Jef Driesen
2ba9904757 Fix the OSTC4 diluent changes
The hwos devices support 5 gas mixes for open-circuit and 5 diluents for
CCR dives. Internally, both sets are stored separately, but depending on
the dive mode only one of both sets gets stored in the dive header. The
gas change event contains the index of the corresponding gas mix or
diluent, and should always be in the range 1 to 5.

The OSTC4 behaves a bit different from the other hwOS models and uses
index 6 to 10 for the diluents. That means the index needs to be
adjusted to refer to the correct mix in the dive header.

Reported-by: Michael Keller <github@ike.ch>
2023-02-23 23:46:13 +01:00
Michael Keller
648651e2d7 Heinrichs Weikamp: Increase parameter value buffer size.
Get rid of truncation warnings and possible string truncation by
increasing the size of the buffer used for parameter values. There is
enough space to display up to 64 characters.

Signed-off-by: Michael Keller <github@ike.ch>
2023-02-22 18:26:03 +13:00
Linus Torvalds
7efedfbb2b Merge branch 'master' of https://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge upstream updates from Jef Driesen:

 - Deepblu Cosmiq+ support has been merged upstream

 - Oceans S1 support has been merged upstream

 - Various new models supported: Cressi Donatello, Scubapro G2 TEK, new
   Excursion v6+ firmware.

 - misc core changes, most notably supporting a new annoying specialized
   binary format for "decomode", because Jef still can't deal with
   strings.

 - lots of small details

* https://github.com/libdivecomputer/libdivecomputer: (58 commits)
  Keep open-circuit and diluent gas mixes separately
  Parse some extra gas mix information
  Limit the index to the fixed gas mixes
  Handle dives without a valid gas mix more explicit
  Ignore all gas mixes for freedives
  Always include all gas mixes defined in the header
  Add support for the new Excursion v6+ firmware
  Add support for the HP CCR tank pressure
  Use the correct field for the setpoint sample
  Add support for the Oceans S1
  Add support for the Deepblu Cosmiq+
  Add missing functions for accessing big/little endian values
  Move the snprintf functions to the platform module
  Repeat the handshake every few packets
  Enable big page support
  Remove the model number from the vtpro struct
  Add the model number to the version table
  Move all model numbers to the common header
  Remove a duplicated include statement
  Add support for the 300bar pressure sensor
  ...
2023-02-19 17:10:25 -08:00
Jef Driesen
255a2dbb9a Keep open-circuit and diluent gas mixes separately
The OSTC stores either the OC gas mixes or the CCR diluents depending on
the dive mode. For CCR dives, there is also bailout to an OC gas
possible, and those gas mixes are added dynamically to the manual gas
mixes.

The Shearwater dive computers store both the configured OC gas mixes and
CCR diluents in the header.

In both cases, the gas change events should reference the correct type
of gas mix. This patch takes care of that.
2023-02-17 15:00:49 +01:00
Jef Driesen
ee78d6f65b Parse some extra gas mix information
Keep track of the gas mix type, and whether the gas mix is enabled or
not. Right now this extra information isn't really used for anything
yet, but it's available for future use.
2023-02-17 14:45:05 +01:00
Jef Driesen
328812e95b Limit the index to the fixed gas mixes
The index in the gas change event should refer to the one of the fixed
gas mixes. All gas mixes with a higher index are either manual or
bailout gas mixes, and are reported with different events containing an
O2 and He percentages instead.
2023-02-17 14:45:05 +01:00
Jef Driesen
98c7887e9c Handle dives without a valid gas mix more explicit
Dives without a valid gas mix in the sample data (e.g. both the O2 and
He set to zero) are currently ignored by accident. Because the
o2_previous and he_previous variables were initialized to zero, those
invalid gas mixes were not processed.

Add an explicit check for such gas mixes to make this more obvious.
2023-02-17 14:43:32 +01:00
Jef Driesen
5fd9317533 Ignore all gas mixes for freedives
For freedives it makes no sense to report any gas mixes. The freedives
also use a different sample format, which doesn't generate any gas
change events.
2023-02-17 14:41:01 +01:00
Jef Driesen
9787bb7ac9 Always include all gas mixes defined in the header
Especially among technical divers, it's not uncommon to carry spare
tanks that will only be used in emergency situations (for example a
rebreather with one or more bailout tanks). Since those gas mixes are
not used throughout the dive, they were also not reported to the
application.

Fixed by reporting all configured gas mixes. Applications can still
obtain the previous result after manually inspecting the gas switch
events in the samples and filtering out the unused gas mixes.

This partially reverts commit c8b166dadbf961e17a9bd1cc28db3d92832ddf72.
2023-02-16 14:05:53 +01:00
Linus Torvalds
1b9aea3213 garmin parser: avoid build warning about converting pointer types
DECLARE_FIELD() uses array_uint_endian() to turn an integer type into
the right endianness.  It's all conditional on being an integer type,
but the compiler still sees the assignment (with a cast) for other
types, and complains about casting the 'unsigned int' return value to a
pointer, even when that case is not actually dynamically ever taken.

Fix the compiler warning by just changing the return type of this
conversion function to 'unsigned long' instead, which will match the
size of pointers on all relevant architectures.

Don't look at that macro too closely, you'll go blind.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-02-09 11:23:03 -08:00
Michael Keller
9a3363dc7d Added detection for bailout to OC / switch back to CC for CCR dives.
As a CCR diver I would like to see the ability to properly track the 'on
loop' / 'bailed out to open circuit' status directly in Subsurface,
because this is an important (or even the most important) bit of status
information during a CCR dive.  This should extend to the use of the
correct ppO2 / gas mix in the deco ceiling / tissue model calculation.

My idea for how to do this would be to track the 'type' ('diluent' / 'OC
bailout') for every gasmix / tank that is reported by the dive computer.

Most CCR capable dive computers that I am familiar with require the user
to enter two different gas lists for diluent and bailout, so this should
work with the existing libdivecomputer API for these.  Unfortunately I
think making this change in Subsurface will require a bit of work, as
the libdivecomputer field capable of tracking the 'type' of a gas or
tank (`cache->tankinfo[]`) does not seem to be consumed at all in
Subsurface.

So this just provides a prerequisite for the change in Subsurface by
populating `tankinfo[]`.  In addition to this it also triggers a message
on every switch from CC to OC and back, at least giving a visual
indication of these diver triggered events.  The messages can probably
be removed from libdivecomputer again once 'loop status' tracking has
been added to Subsurface.

Also included is a fix of the tab expansion mess that I created in
commit 2129403 ("Added facility to detect and interpret manual setpoint
switches for Garmin Descent computers").  Apologies for this, I've
switched to using a custom `.vimrc` for this project now.

[ Edited up the commit message a bit further   - Linus ]

Signed-off-by: Michael Keller <github@ike.ch>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-02-09 11:20:34 -08:00
Michael Keller
f03f9b3bb3 refactoring: Push field cache access down into base class.
Push accesses to cached fields down into `field-cache.c` from parsers
that use the field cache.

As a result, all cached fields will be available to Subsurface in
computer models that use the field cache.

In particular this means that the proper use type (diluent / OC bailout)
of tanks will be shown for the Garmin Descent dive computers once that
is merged.

[ Edited commit message and massaged the deepblu and Eon Steel parsers
  to not complain about unhandled switch statement cases. - Linus ]

Signed-off-by: Michael Keller <github@ike.ch>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-02-09 11:05:49 -08:00
Jef Driesen
201be561d4 Add support for the new Excursion v6+ firmware
The new Excursion v6 firmware supports some new commands for accessing
the dive index, and also uses a completely new data format. To preserve
backwards compatibility in the download logic to some extent, some
critical fields such as the profile length, remain stored at identical
offsets.

The new data format now contains a version field to allow for future
modifications. This version field is located at byte offset 3, which
corresponds to the highest byte of the 32 bit dive number in the old
format. Thus, unless someone manages to reach 16M dives, this field will
always be zero for the old format.

Co-authored-by: Ryan Gardner <ryebrye@gmail.com>
2023-02-09 08:17:32 +01:00
Jef Driesen
78373d827b Add support for the HP CCR tank pressure
For the HP CCR mode, the O2 and diluent tank pressure was stored in the
T1 and T2 tank pressure fields. Starting from log version 14 they moved
to dedicated fields in the EXT sample, next to the T3 and T4 tank
pressure. Thus the maximum number of tanks increased from 4 to 6.
2023-02-03 07:56:47 +01:00
Jef Driesen
4e83b1642c Use the correct field for the setpoint sample
This only happened to work correctly because both the setpoint and ppO2
field have the same data type and are located at the same offset in the
union.
2023-01-27 09:25:58 +01:00
Jef Driesen
9eef8c50c0 Add support for the Oceans S1
The Oceans S1 uses a plaintext and line based communication protocol
over BLE. The larger payloads, which also contain plaintext data, are
transferred using the XMODEM-CRC protocol.

Based-on-code-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-01-25 14:17:29 +01:00
Jef Driesen
86e9cc3443 Add support for the Deepblu Cosmiq+
The Deepblu Cosmiq+ uses a plaintext and line based communication
protocol over BLE, where the binary payload data is encoded as
hexadecimal characters.

Based-on-code-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-01-25 13:32:14 +01:00
Jef Driesen
3ce34a0b6d Add missing functions for accessing big/little endian values
There are functions for reading 8, 16, 24 and 32-bit big and little
endian values, but the corresponding functions for writing such values
are not always available. The 64-bit variants are also missing.
2023-01-25 13:32:14 +01:00
Jef Driesen
187f8d625b Move the snprintf functions to the platform module
Moving the implementation of the snprintf wrapper functions to the
platform module allows to re-use the same implementation throughout the
entire codebase.
2023-01-25 13:32:14 +01:00
Jef Driesen
fca64faa3c Merge branch 'proplus4' 2023-01-25 12:15:50 +01:00
Jef Driesen
e0e3bc8994 Repeat the handshake every few packets
The Oceanic Pro Plus 4 appears to "disconnect" somehow after about 30
seconds. The BLE connection remains up, but the dive computer simply
stops responding to commands. The download fails with a timeout error,
and the end-user can only download a few dives at most.

The Android DiverLog+ application appears to keep the connection alive
by re-sending the version and handshake commands once in a while. Copy
this behaviour by repeating those two commands every 50 read requests.
During testing, that's approximately every 25 seconds.

Note that both commands are required, sending only one of them does not
fix the problem.
2023-01-25 12:13:08 +01:00
Jef Driesen
ceae89e149 Enable big page support
The Oceanic Pro Plus 4 appears to support the big page B4 and B8 read
commands, but with some strange twists:

 * When sending the B8 read command, a 256 byte packet is received. The
   checksums of the packet are valid, but the upper half of the payload
   data is always filled with zero bytes. That means we can't use this
   command.

 * The B4 read command appears to use a 2 byte checksum instead of the
   normal 1 byte checksum. That means we can use this command with a
   small model specific tweak.
2023-01-23 21:13:52 +01:00
Jef Driesen
3414f72f60 Remove the model number from the vtpro struct
The model number is now also available in the common struct. There is no
need to store it twice. The auto-detected model number from the version
table is also more reliable than the one passed by the caller.
2023-01-23 21:10:10 +01:00
Jef Driesen
d0857c49ec Add the model number to the version table
With the model number in the version table, the version string can be
mapped to the corresponding model number. This allows to implement some
model specific behaviour already before being able to read the model
number.

In most cases, there is a simple one to one relationship between the
version string and the model number, but there are also a few
exceptions:

 * For the Sherwood Wisdom 2 and 3, and the Beuchat Mundial 2 and 3,
   each variant has a different model number, but the first part of the
   version string is identical. The difference is in the firmware
   version part. Handling this correctly requires two entries in the
   table.

 * For the Oceanic OC1 there are 3 different model numbers, and only 2
   different version strings. That means there is no correct mapping
   possible.
2023-01-23 21:10:10 +01:00
Jef Driesen
f59cbf0fe5 Move all model numbers to the common header 2023-01-23 21:10:10 +01:00
Jef Driesen
45b9ee8376 Remove a duplicated include statement 2023-01-23 21:10:10 +01:00
Jef Driesen
cf81ac79b3 Add support for the 300bar pressure sensor
The new 300bar pressure transmitter records the pressure in units of
2bar, because otherwise the value doesn't fit into an 8-bit integer.
2023-01-19 16:18:42 +01:00
Jef Driesen
90bb40e5ea Fix the iX3M 2 decompression algorithms
The iX3M 2021 and iX3M 2 models use different values for the
decompression algorithm.
2023-01-19 14:50:00 +01:00
Jef Driesen
bf268d79b4 Fix parsing dives using dual Buhlmann and VPM algorithm
Some iX3M models support a dual mode Buhlmann and VPM decompression
algorithm. Currently libdivecomputer is only capable of reporting one of
those two algorithms, but that's still better than returning an error.
2023-01-17 08:19:58 +01:00
Nikolay Zhekov
989c992154 Add Shearwater Perdix AI hardware ID 2023-01-07 19:50:34 +01:00
Jef Driesen
b1f4ad94eb Fix the decoding of the CNS value
The CNS value is reported as a fraction instead of a percentage.
2023-01-06 17:16:29 +01:00
Jef Driesen
547b1cfd15 Parse the timezone setting
Since firmware version 5B and later, a timezone offset is available.
2023-01-06 17:16:29 +01:00
Linus Torvalds
064e198315 garmin: relax string parsing sanity checks
The garmin FIT file parser verified that a string entry fit in the field
size, but it turns out that the check is wrong: a FIT file string field
is not necessarily NUL-terminated at all, and it's ok to have a string
that fills the entire field.

We never actually then use the string length we just checked, so with
the checks being bogus, all of this code just goes away.  But let's
update the debug printout to follow these rules.

This makes parsing the example FIT file that Cédric sent us work just
fine (at least superficially, in that I don't see anything obviously
wrong with the result: I don't actually know what Cédric's dive was
supposed to look like to verify).

Reported-by: Cédric BAREYT <bareytcedric@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-01-02 14:23:27 -08:00
Jef Driesen
9019805f52 Validate the parameter before calling the vtable function
This removes the need to validate the date/time pointer in every single
backend.
2022-12-21 14:55:50 +01:00
Jef Driesen
f4fae1b9f6 Add some workarounds for the msvc compiler 2022-12-21 14:55:50 +01:00
Jef Driesen
094a225363 Detect the posix unistd.h header file
The getopt function is defined in the unistd.h header file. This header
file is only available on posix compatible systems. For example, on
Windows it's not available when building without mingw.
2022-12-21 14:55:12 +01:00
Jef Driesen
79c9c5b7f9 Add support for the Oceanic Geo Air
The Oceanic Geo Air appears to be compatible with the OC1.
2022-12-08 23:16:31 +01:00
Linus Torvalds
6200a7923f
Merge pull request from mikeller/added_garmin_ccr_setpoint_info
Added parsing of the CCR setpoint information for Garmin Descent computers.
2022-12-05 13:26:40 -08:00
Michael Keller
2129403c1e Added facility to detect and interpret manual setpoint switches for Garmin Descent computers.
Also improved the display of setpoint information - switch mode is shown, and auto switch depth is only shown in auto mode.
All of this has been tested.

Signed-off-by: Michael Keller <github@ike.ch>
2022-12-05 12:25:52 +13:00
Jef Driesen
59a0844ee6 Fix the progress events when no dives are present
When no dives are present, the maximum value for the progress events is
set to zero, which triggers an assert. Fixed by letting the progress
events reach 100% instead.
2022-12-03 13:29:10 +01:00
Jef Driesen
ed0b21beae Increase the BLE packet size
In the latest G2 firmware v2.0, the size of the BLE packets increased to
101 bytes (with a one byte header and 100 bytes of actual payload). This
caused the download to fail, because the internal buffer was suddenly
too small for those larger packets.

These larger packets are most likely due to an update in the BLE stack
of the dive computer. Originally, the maximum BLE packet size was just
20 bytes (excluding the 4 byte L2CAP header and 3 bytes GATT header),
but BLE 4.2 increased the maximum packet size to 244 bytes (or 251 bytes
with the headers).

The USB HID code path keeps using the same fixed size packets as before.
2022-12-02 13:45:50 +01:00
Jef Driesen
755f23fdfa Ignore the first byte of the BLE packets
The first byte of the BLE packets does no longer contain the size of the
payload. Since BLE supports variable sized packets, we can simply ignore
this byte and obtain the payload size from the BLE packet size.
2022-12-01 14:12:41 +01:00
Jef Driesen
db2540485e Link hidapi statically against libgcc
When compiling a 32bit dll with the mingw-w64 compiler, some 64bit
integer arithmetic operations are implemented using functions from
libgcc (e.g. __udivdi3 and __umoddi3 from libgcc_s_dw2-1.dll). This
unexpected dependency is inconvenient for applications.

The run-time dependency can be avoid by linking statically.
2022-11-25 21:54:34 +01:00
Jef Driesen
2577afed55 Update libusb and hidapi in the CI builds
The current hidapi version (v0.10.1) fails to build with newer autoconf
versions (v2.70) due to a duplicated AC_CONFIG_MACRO_DIR macro in the
configure.ac file. This is fixed in newer versions.
2022-11-25 21:52:23 +01:00
Jef Driesen
2c5ebef594 Add udev rules for hidraw devices
The hidapi-hidraw variant of the hidapi library needs access to the
specific /dev/hidraw* device nodes. The existing udev rules for the USB
devices don't apply to the hidraw device nodes.
2022-11-25 13:25:23 +01:00
Jef Driesen
913a65fde6 Allow to specify the hidapi library variant
On Linux, the hidapi library is usually available in two variants:
hidapi-libusb and hidapi-hidraw. By default, the autotools build system
won't be able to detect those variants (due to the difference in the
name) and will automatically fallback to the libusb implementation
instead.

If for some reason the hidapi library should be used, the preferred
hidapi variant can now be specified during configuation with a
parameter:

  ./configure --with-hidapi=hidapi-libusb|hidapi-hidraw

The default value for the parameter remains 'hidapi'.
2022-11-25 13:25:23 +01:00
Michael Keller
1e47f597fa Added parsing of the CCR setpoint information for Garmin Descent computers.
This is adding support for parsing the setpoint information in logfiles downloaded from Garmin Descent devices.

The Garmin devices do not have support for ppO2 sensor input, so they only work in 'fixed setpoint' mode for CCR dives, and dive data records do not contain actual ppO2 values.
The ppO2 values are retrofitted to the dive data based on 'setpoint change' events reported by the device. With this change CCR dives downloaded from a Garmin device are correctly classified as CCR dive, and the calculated ceiling / tissue loading graphs are accurate and match the deco stops reported by the device.
Before this change, CCR dives were classified as open circuit dives, often resulting in a massively overstated calculated ceiling.

This has been tested for logs with only automated setpoint changes - more test dives are needed to reverse engineer the log file format for manual setpoint changes, as the setpoint fields are not documented in Garmin's documentation for the FIT file format.

Signed-off-by: Michael Keller <github@ike.ch>
2022-11-24 11:20:04 +13:00
Jef Driesen
5218d3921a Read the software and hardware version 2022-11-23 08:37:25 +01:00
Jef Driesen
6874130743 Add the return type to the function definition
In commit 12c77a228e84f1ceed520b6afb53b4b64ea9def6, the return type of
the function was accidentally omitted.
2022-11-19 17:43:46 +01:00
Charlotte Koch
2f3a057969 Look for select(2) in a more reliable place 2022-11-14 13:29:28 +01:00
Greg McLaughlin
c2102f62d6 Add support for parsing bookmark events
The bookmark value is a bitfield indicating the type of bookmark:

  1 - Pressed the bookmark button during a dive
  2 - Reset the stopwatch
  4 - Unknown
  8 - Unknown
2022-11-10 14:09:05 +01:00
Jef Driesen
bf93040ab1 Receive only a single USB packet at a time
The hidapi based implementation returns as soon as the first packet is
received, while the libusb based implementation tries to read the
requested number of bytes. That fails with a timeout if the requested
number of bytes is larger than the size of a single packet and no
further packets are received.

Avoid this problem by limiting the size to the maximum packet size.
2022-11-10 14:03:46 +01:00
Jef Driesen
8a6abab1da Update the Github actions
The Github actions need an update due to upcoming deprecations:

 * The 'set-output' command is deprecated [1]. Update to write to the
   GITHUB_OUTPUT environment file instead.

 * All Github actions using Node.js 12 are deprecated [2]. Update the
   following actions to a newer version using Node.js 16:

    - actions/checkout
    - actions/upload-artifact
    - microsoft/setup-msbuild

 * The Github create-release and upload-release-asset actions are no
   longer maintained. Replace with an alternative solution using the
   Github CLI.

[1] https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
[2] https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/
2022-11-10 14:02:20 +01:00
Jef Driesen
005a2501b9 Merge branch 'hwos-empty-profile' 2022-11-10 12:38:00 +01:00
Jef Driesen
9508401971 Fix the download of dives without a profile
At the moment, trying to download an old dive for which the profile data
has already been overwritten with newer data fails. This used to work
fine, but around hwOS firmware v3.10, the behaviour described in commit
76187c550a806fe422920eb8795fa687244513f1 changed.

When downloading the compact/full headers, the firmware always sends the
headers without inspecting their content. Next, libdivecomputer uses the
length field in these headers to determine how many bytes to expect when
downloading the dive. However, when downloading the entire dive, the
hwOS firmware now checks whether the profile data of the dive is still
available. If that's no longer the case, the firmware sends a modified
dive header (with the begin/end pointer fields reset to zero, and the
length field reduced to 8 bytes), along with an empty dive profile.
Since libdivecomputer expects to receive the full profile as indicated
in the original header, the download fails with a timeout.

To workaround this problem, download the dive data in two steps. First,
download the 256 byte header and check whether it has been modified. If
that's the case, reduce the length to that of the 5 byte empty profile.

The header check is also updated to exclude the modified fields. For the
progress events, just pretend the full profile has been downloaded.
2022-11-10 11:28:38 +01:00
Jef Driesen
89ae8b94cf Fix the detection of empty dive profiles
Not only the two byte end-of-profile marker 0xFDFD is a valid empty dive
profile, but also a profile with the length field present and set to 8
bytes. In that case the actual length will be just 5 bytes.
2022-11-09 14:27:37 +01:00
Jef Driesen
a99d990117 Verify the fields of the compact header
When downloading the compact headers (which is the default for recent
hwOS firmware), it's not possible to compare the entire dive header, but
we can at least the check the fields that are available.

Also return an error if the verification fails.
2022-11-09 14:27:34 +01:00
Jef Driesen
c578e0a158 Use symbolic constants for the header offsets 2022-11-09 14:24:09 +01:00
Jef Driesen
34bc6b1613 Use the macro for encoding firmware versions
This makes it a bit easer to quickly locate the workarounds for specific
firmware versions.
2022-11-09 14:23:58 +01:00
Greg McLaughlin
59dd6a2a56 Increase the memory size for the Aqualung i770R
The Aqualung i770R appears to have 6M instead of 4M (high) memory.
Confirmed by trying to read past the 6M limit, which fails with a NAK
response. This amount also matches with the capacity stated in the
manual (6553 hours of profile data at a 60 second sample rate).
2022-11-02 22:56:53 +01:00
Linus Torvalds
28c27e2392 uwatec smart: allow bigger BLE packets
It looks like the Scubapro G2 firmware update to v2.0 ended up
increasing the BLE packet size, which broke our downloader.

The logic is shared with the USB HID code, and the way USB HID works is
that the packet is fixed at 64 bytes, and the first byte contains the
actual payload size.  So you could have up to 63 bytes of actual data
per packet, and that used to be the limit for the BLE side too.

However, now that the BLE side has bigger packets, using a 64-byte
packet buffer broke horribly, and caused the new 101-byte BLE packets
(one byte of odd data, and 100 bytes of actual payload) to be read as a
64-byte packet followed by a 37-byte one, and that just didn't work at
all.

At the same time, we cannot just increase the receive packet size,
because that makes src/usbhid.c very unhappy at least for the USE_LIBUSB
case, because using a bigger buffer for "libusb_interrupt_transfer()"
will then wait for more than one packet to arrive.  Which obviously
doesn't happen when you only get a small reply, and so it all goes
south.

Fixing src/usbhid.c to only ever ask for 64 bytes at a time is probably
the right thing to do, but this instead just makes the Uwatec downloader
look at what protocol it uses instead.  So if it's USB HID, we use a
64-bit buffer, and for BLE we use a maximum buffer size that then gets
filled in with whatever the actual packet size was.

Reported-by: <jmejul13@gmail.com>
Link: https://groups.google.com/d/msgid/subsurface-divelog/5d653bbd-5cad-4522-bb46-9e0319e465bbn%40googlegroups.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-11-02 10:16:02 -07:00
Jef Driesen
3d388a0a96 Don't pass a NULL pointer to memcpy
The memcpy and related functions expects a valid pointer, even if the
size is zero. Most libc implementations will handle a NULL pointer just
fine, but that's not guaranteed.

Simply skip the call when there is nothing to copy.
2022-11-02 13:23:14 +01:00
Jef Driesen
c5813d624a Add support for the Scubapro G2 TEK
The Scubapro G2 TEK is compatible with the G2, but with a new model
number.

Reported-by: Greg McLaughlin <support@moremobilesoftware.com>
2022-10-16 23:15:54 +02:00
Jef Driesen
3eedf4d24d Use the value stored in the dive header
The maximum depth value is stored in the dive header. There is no need
to parse the profile data to obtain it. This also avoids returning a
zero depth when the profile data is no longer available.

A few other fields (e.g. average depth, atmospheric pressure and
temperature) are also present in the dive header.
2022-10-13 20:56:59 +02:00
Jef Driesen
3e5282bf74 Add support for the Scorpena Alpha
The Scorpena Alpha uses the same communication protocol and data format
as the Deep Six Excursion.

Reported-by: Sven Knoch <info@divinglog.de>
2022-10-11 11:41:12 +02:00
Dirk Hohndel
43a503f6f0
Merge pull request #39 from subsurface/garminBigEndian
Garmin: attempt to parse big endian .FIT files
2022-10-06 13:39:16 -07:00
Dirk Hohndel
4d8cdaaf8e Garmin: attempt to parse big endian .FIT files
The only examples I have seen so far are small incomplete files that
don't contain the dive profile, so I'm unsure if this is sufficient (and
why there are big endian files in the first place).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-10-06 13:27:26 -07:00
Jef Driesen
ce578cafb9 Report the dive mode for Air and Nitrox dives
Currently the dive mode is only reported for rebreather dives.
2022-08-11 18:26:52 +02:00
Jef Driesen
12c77a228e Add a public api to configure the clock synchronization
For dive computers where the reference time (epoch) of the device is
unknown, libdivecomputer uses the current time of the device (devtime)
and the host system (systime) to synchronize both clocks.

Currently, both timestamps are passed directly to the constructor of the
parser. With the new public function, the application can adjust the
timestamps afterwards.
2022-08-11 17:36:26 +02:00
Jef Driesen
6ab140461a Add a public api to configure the depth calibration
Some dive computers store the depth as an absolute pressure value (in
bar). To convert to a depth value (in meters), the atmospheric pressure
and water density are required. For dive computers that do not have
those values available, libdivecomputer uses a default value. With the
new public api functions, applications can adjust those default values.

Some dive computers already provided a backend specific calibration
function. Those functions are now deprecated. They are kept around to
maintain backwards compatibility for now, but they will be removed in
the next version.
2022-08-11 17:36:15 +02:00
Jef Driesen
18f06ea585 Add a macro for the default density and atmospheric pressure
Replace the hardcoded default values with a macro defined in a central
location. This makes it much easier to adjust the values if necessary.
2022-08-11 17:36:15 +02:00
Jef Driesen
7fb943ae7f Add support for parsing the decompression model
Report the decompression algorithm (Buhlmann, VPM, RGBM or DCIEM), and
if available also the parameters. For now only the conservatism setting
is supported, and for the Buhlmann algorithm also the Gradient Factors
(GF).
2022-08-11 17:35:03 +02:00
Michael Andreen
565bb2af02 Garmin: Don't require sub directories for fit files
Start looking for fit files in the normal Garmin/Activity sub directory,
but if that doesn't exist look directly in the specified directory.

Signed-off-by: Michael Andreen <michael@andreen.dev>
2022-08-02 22:20:24 +02:00
Jef Driesen
95f309a1c9 Add support for the Cressi Donatello
The Cressi Donatello appears to be compatible with the Goa, with just a
different model number.
2022-08-02 09:03:33 +02:00
Linus Torvalds
107f5b14e3 Merge https://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge upstream changes from Jef Driesen:

 - New dive computer support:
    - Ratio iX3M 2
    - Sherwood Amphos Air 2.0

 - Cleanups and fixes

* https://github.com/libdivecomputer/libdivecomputer:
  Add support for the Ratio iX3M 2 models
  Add support for the Sherwood Amphos Air 2.0
  Replace switch statements with an array lookup
  Add Shearwater Perdix 2 and Petrel 3
  Update the Shearwater hardware IDs
  Fix the clock synchronization
  Remove unused time parameters
  Add support for a new Aqualung i200C variant
2022-07-30 17:18:51 -07:00
Jef Driesen
391d4db419 Add support for the Ratio iX3M 2 models
The protocol and data structures have not changed, so just adding the
new names and model numbers.
2022-07-22 00:27:30 +02:00
Jef Driesen
972beb52be Add support for the Sherwood Amphos Air 2.0
The Amphos Air 2.0 appears to be identical to the previous Amphos Air,
except for the new model number and version string.
2022-07-15 22:14:33 +02:00
Jef Driesen
80f22dce0b Replace switch statements with an array lookup
No functional change, just some more compact code.
2022-07-15 22:11:24 +02:00
Dirk Hohndel
26c43d6d8b Add Shearwater Perdix 2 and Petrel 3
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-06-27 15:08:35 +02:00
Dirk Hohndel
8451286c17 Update the Shearwater hardware IDs
Update and fix the hardware IDs based on the latest information from
Shearwater.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-06-27 15:02:51 +02:00
Jef Driesen
be5bb9e690 Fix the clock synchronization
For dives with a timestamp that is larger than the current device time
(e.g. in the future), the clock synchronization produces incorrect
values. In that case, the time difference suddenly becomes negative,
which corresponds to a large positive value as an unsigned integer.

Under normal circumstances, this scenario can't happen. But sometimes
actions such as battery replacements or firmware upgrades can cause the
internal clock to reset.

The Reefnet devices shouldn't need this fix, because their internal
clock can't be changed, but it doesn't hurt either.
2022-06-23 15:57:08 +02:00
Jef Driesen
e6f091909b Remove unused time parameters
Since the clock synchronization has been removed (see commit
a1962558412b8c89a79656992c8e7f4d001065c2 for the details), those
parameters serve no purpose anymore.
2022-06-23 15:56:10 +02:00
Jef Driesen
4616e2ed21 Add support for a new Aqualung i200C variant
There is a new variant of the i200C with a different model number
(0x4749) and double the amount of memory (128K).
2022-06-19 20:56:14 +02:00
Dirk Hohndel
a17e466bd1 Add Shearwater Perdix 2 and Petrel 3
Also update and fix the hardware IDs based on the latest information
from Shearwater.
Two of the hardware IDs that we supported before are not listed in the
current docs. In an abundance of caution I'll leave them in the code.
No harm done if they don't exist in real life.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-06-14 14:17:51 -07:00
Dirk Hohndel
643a6211b2 Simplistic attempt to support new Aqualung i200C
There appear to be newer models in the wild with a different model
number, but labeled as i200C.

To avoid confusion, this calls the new model i200Cv2.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-06-14 16:32:08 +00:00
Linus Torvalds
aff0c28d08 Merge https://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge Jef's upstream updates:

 - Add support for Seac Screen and Action

 - Add support for Cressi Michelangelo

 - misc small fixes

* https://github.com/libdivecomputer/libdivecomputer:
  Add support for the Seac Screen and Action
  Add an address parameter to the memory dump helper function
  Ignore invalid gas mixes
  Add support for the Cressi Michelangelo
  Move the C_ARRAY_SIZE macro to a common place
  Fix the timezone offset in the xml output
  Emit a devinfo event when downloading a memory dump
  Read the info and more info data during startup
  Use helper functions to decode multibyte values
  Fix changing the OSTC settings
2022-06-05 09:02:06 -07:00
Jef Driesen
4b4efb2c07 Add support for the Seac Screen and Action 2022-06-02 11:29:32 +02:00
Jef Driesen
2443d3ea47 Add an address parameter to the memory dump helper function
To support devices where not all memory is readable, the memory dump
helper function needs an extra parameter to specify the start address.
2022-06-01 13:27:13 +02:00
Jef Driesen
d0c7562c41 Ignore invalid gas mixes
The Cressi Michelangelo appears to store inactive gas mixes as a zero
oxygen percentage. Such invalid values shouldn't be reported.
2022-06-01 09:16:23 +02:00
Dirk Hohndel
7c3e92e391 move pointer test to generic helper
This should always be tested for - the only other user of the generic
helper currently didn't test for it, either.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-05-31 14:46:30 -07:00
Dirk Hohndel
0aad8cfd13 Garmin: replace get_field function
The generic function already handles all the cases (treating gasmix and
tank count as being the same and responding UNSUPPORTED to the same set
of types). The only thing missing is the check of the value parameter
and the extraction of the cache pointer from the context.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-05-31 14:46:28 -07:00
Dirk Hohndel
cd72516668 Garmin: decode divemode
The code used sub_sport to figure out if this was a dive in the first
place, but then never reported back the specific dive mode, leading to
all dives being interpreted as open circuit.

Reported-By: Anton van Rosmalen
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-05-31 10:59:45 -07:00
Jef Driesen
0064097c03 Add support for the Cressi Michelangelo
The Cressi Michelangelo appears to be compatible with the Goa, with just
a different model number.
2022-05-23 12:54:44 +02:00
Jef Driesen
8bfb965589 Move the C_ARRAY_SIZE macro to a common place 2022-05-23 12:14:00 +02:00
Jef Driesen
82c0134811 Fix the timezone offset in the xml output
For negative timezone offsets, only the hour part should have a sign.
The minute part must always be formatted as a positive number.
2022-05-23 12:13:49 +02:00
Jef Driesen
4512a0a5d7 Emit a devinfo event when downloading a memory dump
For diagnostics purposes it's often very useful to have the device
information available when downloading a memory dump.
2022-05-23 12:01:42 +02:00
Jef Driesen
52d2684479 Read the info and more info data during startup 2022-05-23 12:01:38 +02:00
Jef Driesen
7e3bf7eeb8 Use helper functions to decode multibyte values
Add and use some helper functions for decoding multibyte BCD and binary
encoded values, to remove some code duplication.
2022-05-23 12:00:35 +02:00
Michael Andreen
ea051578e6 Garmin: Handle file names in short format
When downloading heart rate data from a chest strap the Descent MK2i
uses a more compact format, like C4ND0302.fit. If any such dives have
been downloaded then newer dives in long format won't be detected and
requires downloading all dives and picking the right ones.

Instead parse this short format and ensure that these dives end up in
the correct order.

Format information found here:
https://gist.github.com/waywardone/fa8cb01462790aa8a26fab97477b80e1

Signed-off-by: Michael Andreen <michael@andreen.dev>
2022-04-24 23:54:04 +02:00
Linus Torvalds
77498afe5e Merge github.com:libdivecomputer/libdivecomputer into Subsurface-DS9
Pull upstream fix for Genesis React Pro serial number from Jef.

* github.com:libdivecomputer/libdivecomputer:
  Fix the Genesis React Pro serial number
2022-04-04 11:34:30 -07:00
Michael Andreen
5f3a0f0b8a OSTC: Use deco model instead of dive mode for deco model information
In the most recent merge deco model (byte 79) was swapped for divemode
(byte 82). This caused all OC dives to be classified as the older
algorithm without gradient factors.

Signed-off-by: Michael Andreen <michael@andreen.dev>
2022-04-03 23:49:07 +02:00
Jef Driesen
0753f10661 Fix changing the OSTC settings
The command to change the OSTC settings has a variable length payload (1
to 4 bytes). Therefore, the expected number of bytes is only know after
evaluating the first option index byte. Due to the limited UART buffer
in the OSTC, sending the remainder of the packet immediately after the
first byte, can cause the OSTC to get out of sync.

Introduce a small delay between sending the option index and the
remaining parameters to avoid this problem.
2022-03-31 13:20:13 +02:00
Nick Shore
0448ce686a Fix the Genesis React Pro serial number 2022-03-27 10:51:08 +02:00
Linus Torvalds
39dbb275cc Merge git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge Jef's upstream into the Subsurface branch:

 - support for new dive computers: Mares Pick Pro+, Deep Six Excursion,
   Crest CR-4, Genesis Centauri and Tusa TC1.

 - support freedive mode on Mares Smart Air

 - work with Oceanic dive computers regardless of whether they need the
   BLE handshake or not

 - OSTC updates: support bigger BLE packets in newer versions, fix
   setpoint in SCR mode

 - Shearwater updates: full dive mode parsing, correct timezone handling
   on Teric, support up to four transmitters on newer log versions.

* git://github.com/libdivecomputer/libdivecomputer: (26 commits)
  Read the extra tank information
  Add support for transmitter T3 and T4
  Limit the number of records for the Predator
  Report the timezone offset for the Teric
  Use the correct model number from the final block
  Use the dive mode stored in the header
  Report the correct dive mode for SCR dives
  Increase the size of the BLE packet cache
  Add support for the Genesis Centauri and Tusa TC1
  Read the hardware and software version
  Report the initial setpoint in SCR mode
  Add the divemode to the layout descriptor
  Re-order the fields in the layout descriptor
  Show the correct help message for the scan command
  Add support for the Crest CR-4
  Add udev rule for the Suunto EON Steel Black
  Ignore unsupported BLE handshake
  Detect NAK response packets
  Remove the initial gas switch
  Restore the original standard gravity factor
  ...
2022-02-27 12:20:09 -08:00
Jef Driesen
bedd6180f1 Merge branch 'shearwater' 2022-02-27 11:55:10 +01:00
Jef Driesen
c6640aa7d3 Read the extra tank information
The latest firmware does store some additional information for each
tank. Right now it's not really used for anything yet, but it's
available for future use.
2022-02-27 11:49:53 +01:00
Jef Driesen
7a650f940c Add support for transmitter T3 and T4
In recent firmware versions (log version 13), Shearwater added support
for two more tank transmittors: T3 and T4.
2022-02-27 11:48:41 +01:00
Jef Driesen
86e1d59a6a Limit the number of records for the Predator
In the older Predator-like data format, the 4th opening/closing record
is the last one. To avoid accidental use of the higher ones, leave them
undefined.
2022-02-27 11:47:13 +01:00
Jef Driesen
54fa676e75 Report the timezone offset for the Teric
The Shearwater Teric supports a UTC offset and DST setting.
2022-02-27 11:46:51 +01:00
Jef Driesen
d1242a28cf Use the correct model number from the final block
During the download, the model number is obtained from the hardware type
because the model number isn't available before downloading the first
dive. Since the list with available hardware types is incomplete, the
correct model number is not always available. However, during parsing
the correct model number is available in the final block.
2022-02-27 11:45:26 +01:00
Jef Driesen
ccd37d4fa3 Use the dive mode stored in the header
Starting with log version 8, the dive mode is stored in one of the
opening records. For backwards compatibility with older firmware
versions, the autodetection based on the status field in the sample data
is kept as a fallback mechanism.
2022-02-27 11:44:58 +01:00
Jef Driesen
811a9b4f89 Report the correct dive mode for SCR dives
The status field contains an extra bit for SCR dives, so there is no
reason to report them as CCR dives.
2022-02-18 13:54:22 +01:00
Jef Driesen
2794f96e47 Increase the size of the BLE packet cache
In the latest OSTC hardware, the Telit/Stollman bluetooth module has
been replaced with a u-Blox Nina B2 bluetooth module. This new module
supports BLE data packets of up to 244 bytes (corresponding to an ATT
MTU of 247 bytes and a LL PDU payload size of 251 bytes).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-02-14 12:39:40 -08:00
Jef Driesen
d960a37e12 Increase the size of the BLE packet cache
In the latest OSTC hardware, the Telit/Stollman bluetooth module has
been replaced with a u-Blox Nina B2 bluetooth module. This new module
supports BLE data packets of up to 244 bytes (corresponding to an ATT
MTU of 247 bytes and a LL PDU payload size of 251 bytes).
2022-01-31 14:06:17 +01:00
Jef Driesen
17bc0faa51 Restore the original standard gravity factor
The Uwatec/Scubapro dive computers are confirmed to internally use the
approximated standard gravity (10.0 m/s²) for the depth conversion.
Allthough this is technically wrong, users expect to get the same depth
values as their dive computer shows.

This partially reverts commit cfc9ddc380bdc5616893fc2af4e05204b5500ea2.
2022-01-10 13:40:13 -08:00
Jef Driesen
f6df075d51 Add support for the Genesis Centauri and Tusa TC1
Both models are compatible with the Deep Six Excursion.
2022-01-03 16:09:37 +01:00
Jef Driesen
c5dced237a Read the hardware and software version 2022-01-03 15:58:33 +01:00
Jef Driesen
c9c441b8bb Merge branch 'ostc' 2022-01-03 15:55:40 +01:00
Jef Driesen
5e2d376627 Report the initial setpoint in SCR mode 2022-01-03 15:54:49 +01:00
Jef Driesen
16e49eee6d Add the divemode to the layout descriptor 2022-01-03 15:54:49 +01:00
Jef Driesen
70411048e5 Re-order the fields in the layout descriptor
The new order of the fields matches the physical memory layout more
closely.
2022-01-03 15:54:39 +01:00
Jef Driesen
331bcbdaf7 Show the correct help message for the scan command 2021-12-13 08:46:09 +01:00
Jef Driesen
af03e39383 Add support for the Crest CR-4
The Crest CR-4 is compatible with the Deep Six Excursion.
2021-11-19 08:26:19 +01:00
Michael Andreen
93fe31eef5 Garmin: Fix gas change event parsing
The gas mixes are numbered from 0 and up and the gas change event uses
this number directly, so no need to subtract one.

Signed-off-by: Michael Andreen <michael@andreen.dev>
2021-11-17 11:58:14 +01:00
Jef Driesen
b2040d9adb Add udev rule for the Suunto EON Steel Black 2021-11-16 14:04:45 +01:00
Jef Driesen
cadbffe416 Merge branch 'oceanic-ble-handshake' 2021-10-20 15:04:26 +02:00
Jef Driesen
cd0f42804a Ignore unsupported BLE handshake
For some BLE enabled models, like the Oceanic Pro Plus X, Aqualung
i750TC, Sherwood Sage and Sherwood Beacon, the BLE handshake command
is not supported and therefore disabled.

However, based on a bug report by a user with two Aqualung i770R dive
computers, this detection mechanism based on the dive computer model
number isn't sufficient. Allthough the two devices have the exact same
firmware version (2A), the handshake command only works on the newest
unit, and fails with a NAK response on the oldest unit.

Remove the model based detection and always try to send the handshake
command and rely on the NAK response to ignore the failure instead. An
additional advantage is that we no longer have to (manually) maintain a
list with the model numbers where the handshaking is known to fail.
2021-10-20 15:02:57 +02:00
Jef Driesen
ba4a119a4f Detect NAK response packets
When the dive computer receives a command it doesn't support, it sends
back a single byte NAK (0xA5) packet instead of the expected ACK byte
(0x5A) at the start of the packet. Retrying is pointless in this case,
because the next attempt will also fail. Instead, return immediately
with an appropriate error code, and let the upper layers handle the
unsupported command.

Note that the detection is currently only enabled for BLE communication.
2021-10-20 15:02:34 +02:00
Jef Driesen
9ff6e5caad Remove the initial gas switch
The Cressi Drake is a freedive computer and does not support gas
switches.
2021-10-13 11:06:26 +02:00
Jef Driesen
a8bcfb998b Restore the original standard gravity factor
The Uwatec/Scubapro dive computers are confirmed to internally use the
approximated standard gravity (10.0 m/s²) for the depth conversion.
Allthough this is technically wrong, users expect to get the same depth
values as their dive computer shows.

This partially reverts commit cfc9ddc380bdc5616893fc2af4e05204b5500ea2.
2021-10-03 11:37:59 +02:00
Jef Driesen
1c39c68203 Add support for the Mares Puck Pro +
The Mares Puck Pro + is compatible with the previous Puck Pro. Both
models can't even be distinguished because they share the same model
number and use the same product name in the version packet.
2021-09-28 12:14:10 +02:00
Jef Driesen
0a9b8b1318 Merge branch 'smartair-freedives' 2021-09-14 21:34:01 +02:00
Jef Driesen
7e075eb959 Add support for Mares Smart Air freedives
The Mares Smart Air supports a freedive mode, which uses a different
data format compared to the scuba dives.
2021-09-14 21:33:47 +02:00
Jef Driesen
e52468e0c3 Use a layout descriptor
Replace hardcoded constants with a layout descriptor. This reduces the
amount of model specific conditions, and makes it easier to add support
for new models.
2021-09-14 21:32:48 +02:00
Jef Driesen
1a4798792e Use the divetime stored in the header
There is no need to calculate the total time from the pseudo profile,
because the dive time is also stored in the header.
2021-09-14 21:32:48 +02:00
Jef Driesen
c4b694fdb1 Fix the salinity parsing
The parser->mode field is only initialized at the end of the function.
The result is that the current code always used the default value
(zero). Inside the function itself, the local variable should be used
instead.
2021-09-14 21:32:31 +02:00
Linus Torvalds
b6df353752 Merge branch 'master' of git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge upstream libdivecomputer updates by Jef Driesen.

Minor fixups, and add ID for Cressi Neon.

* git://github.com/libdivecomputer/libdivecomputer:
  Add support for the Cressi Neon
  Use symbolic constant for invalid value
  Remove duplicate macro definition
  Add BLE support for the Aqualung i750TC
  Exclude the surface time from the dive time
2021-08-20 18:28:23 -07:00
Linus Torvalds
6e40a457f3 Remove MSVC build instructions from github workflows
MSVC isn't a supported target for subsurface - the Windows build is
cross-compiled, not native.  And MSVC is actively user-hostile, with
insane errors and warnings.

In particular, MSVC doesn't like "strdup()", and suggests you use the
nonstandard _strdup() instead.  Which is all kinds of wrong, and seems
to be a "let's use strict POSIX namespace rules as an excuse to make
people write less portable code".

There is probably some flag to make the MSVC compiler happy with sane
code, but it's easier to just disable the insanity entirely.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-08-20 18:20:18 -07:00
Linus Torvalds
a282ae0b29
Merge pull request #29 from subsurface/moreSerial
Add more serial numbers
2021-08-20 17:08:52 -07:00
Dirk Hohndel
3057ac79c2 Mares Icon HD protocol: add serial as string
I verified that the unsigned integer in the devinfo header actually matches the
serial number shown in the "About" dialog on the device - so let's add this as
extra data string and make it user visible (and also allow Mares Icon HD style
devices to be reliably distinguished in Subsurface).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-08-20 11:03:12 -07:00
Dirk Hohndel
f2cc4ab7ef Suunto Vyper protocol: add serial as string
I verified that the unsigned integer in the devinfo header actually matches the
serial number printed on the device - so let's add this as extra data string
and make it user visible (and also allow Suunto Vyper style devices to be
reliably distinguished in Subsurface).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-08-20 11:01:30 -07:00
Ryan Gardner
75f260a941 Add support for the Deep Six Excursion
Based on original work and code by Ryan Gardner, with some additional
improvements and integration into libdivecomputer by Jef Driesen.
2021-08-17 22:38:53 +02:00
Linus Torvalds
643b4271f6 EON Steel: support new gas change data from newer firmware
It seems that Suunto extended the gas change information in FW 2.5, and
added events and fields for when you create and delete gas mixes under
water.

The parses the relevant new information to get gas switches working
again, and to also add the information about gas creation and deletion
events.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-08-17 08:14:40 -10:00
Jef Driesen
e0409a9496 Add support for the Cressi Neon
The Cressi Neon appears to be compatible with the Goa and Cartesio, with
just a different model number.
2021-08-17 17:53:16 +02:00
Jef Driesen
70d3cdcc08 Use symbolic constant for invalid value 2021-08-16 15:26:45 +02:00
Linus Torvalds
e7da5acff3 Garmin: add extra-info for serial number and firmware version
In proper string format that matches what the Garmin reports on the
"About" screen.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-08-15 16:40:02 -10:00
Jef Driesen
03974481b0 Remove duplicate macro definition 2021-08-09 10:04:17 +02:00
Jef Driesen
58d410b1a2 Add BLE support for the Aqualung i750TC
The Aqualung i750TC supports BLE, but the BLE handshaking fails and
needs to be disabled.
2021-08-08 20:34:49 +02:00
Jef Driesen
38bd51e63a Exclude the surface time from the dive time
Like most dive commputers, the Mares Genius uses a surface timeout to
detect the end of the dive. But since there is no explicit dive time
field stored, the total dive time is based on the number of samples,
which includes this surface time at the end of the dive. However, the
dive time displayed by the dive computer (and also the Mares
DiveOrganizer application) does not include this surface time.

For older firmware versions the value is hardcoded to 3 minutes, but
starting with the newer v01.02.00 firmware the value is configurable and
stored in the settings. To detect whether the setting is available, we
need to check the profile version instead of the header version. That's
because the header appears to be generated on-the-fly during the
download, and thus the header version also changes for dives recorded
prior to the firmware update.

For all other models, also take into account a hardcoded timeout of 3
minutes.
2021-07-26 17:20:16 +02:00
Linus Torvalds
2ef285faf3 Merge branch 'crashFix' of https://github.com/subsurface/libdc into Subsurface-DS9
Merge mtp_device cleanup from Dirk Hohndel.

* 'crashFix' of https://github.com/subsurface/libdc:
  cleanup: ensure mtp_device field is 0
2021-07-19 14:37:46 -07:00
Linus Torvalds
3e87ed050c Merge branch 'master' of git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge upstream libdivecomputer updates by Jef Driesen:

 - fix HW Sport and Mares Genius firmware update

 - Windows Visual Studio build updates

 - Various parser updates:
    - sporasub depth, salinity and sample rate parsing
    - Atomics Cobalt atmospheric pressure parsing
    - unit cleanups (Uwatec, McLean Extreme)

* git://github.com/libdivecomputer/libdivecomputer:
  Some more fixes for the new Mares Genius firmware
  Implement the salinity field
  Fix the sample rate parsing
  Add support for the new Mares Genius firmware
  Use the correct standard gravity factor
  Use SI units internally
  Fix negative depth values
  Move the unit conversion to the last moment
  Implement the atmospheric pressure field
  Always use the stored atmospheric pressure
  Add a CI job to build with Visual Studio
  Migrate to Visual Studio 2013 (or newer)
  Emit events when downloading a memory dump
  Fix the depth decoding
  Add library dependencies in windows build
  Fix the hwOS Sport firmware upgrade
  Post release version bump to 0.8.0
2021-07-19 14:30:55 -07:00
Jef Driesen
927362354d Some more fixes for the new Mares Genius firmware
The changes in commit 5cb527d53ca88ac692beb55288172fc1003975fa to
support the new Mares Genius firmware v01.02.00 were incomplete.

For dives recorded prior to the firmware upgrade, only the header
version changed from 0.0 to 1.1, while the profile version remained the
same. But for dives recorded after the firmware upgrade, the profile
version also changed from 0.2 to 1.0.

The known header and profile object versions (indicated as
type.major.minor) are now:

  Model   | Firmware | Header | Profile
  ========|==========|========|=========
  Genius  | 1.0.x    | 1.0.0  | 0.0.2
  Genius  | 1.2.0    | 1.1.1  | 0.1.0
  Horizon | 1.7.28   | 1.0.1  | 1.0.2

To simplify the object version check, all versions below a certain upper
limit are now considered supported.
2021-07-13 22:45:40 +02:00
Jef Driesen
5bb6257acb Implement the salinity field
The 4th bit of the settings byte contains the salinity setting (salt or
fresh water).
2021-07-13 00:00:26 +02:00
Jef Driesen
060c0b7215 Fix the sample rate parsing
The byte at offset 0x1A appears to be some settings byte, containing not
only the sample rate index, but also some other values in the higher
bits. Except for the 4th bit, which contains the salinity setting, the
meaning of those higher bits remains unknown. Since the sample rate is
limited to only 4 possible values, 2 bits are sufficient for encoding
the sample rate index. The 3th bit might contain some other setting, or
be reserved for future sample rates.
2021-07-12 23:52:56 +02:00
Dirk Hohndel
eaeb5c5341 cleanup: ensure mtp_device field is 0
We explicitly check that field for 0 before dereferencing it. Let's make sure
that it always starts out being 0 - otherwise we'll get a potential crash here.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-07-12 14:49:13 -07:00
Jef Driesen
5cb527d53c Add support for the new Mares Genius firmware
The new Mares Genius firmware v01.02.00 has a header which is 10 bytes
larger. This difference is indicated with a change in the major version
from 0 to 1.
2021-07-06 17:43:41 +02:00
Jef Driesen
cfc9ddc380 Use the correct standard gravity factor
For manual depth calculations by divers, the standard gravity is
often approximated as 10.0 (e.g. 1 bar corresponds to 10 meter), but
libdivecomputer prefers to use the exact value of 9.80665 m/s².

For the McLean Extreme, it has been confirmed that the device also uses
the correct standard gravity internally for the conversion of the sample
depth.
2021-07-06 16:16:18 +02:00
Jef Driesen
cffda88ae8 Use SI units internally
Prefer SI units for internal constants (e.g. density) and calculations.
This results in more consistent conversion formulas across the different
backends.

For the Uwatec backend, this changes makes it also much more visible
that the unit for the depth is either 1 millibar (maximum depth) or 2
millibar (sample depth).
2021-07-06 16:16:18 +02:00
Jef Driesen
b186846a9e Fix negative depth values
The difference between two unsigned integers can be negative. To avoid
ending up with some very large positive values, an explicit cast to a
signed integer is required.

Depths are normally expected to be always positive, but near the surface
the pressure will be very close to the atmospheric pressure. Therefore
small negative values are not unusual.
2021-07-06 16:16:18 +02:00
Jef Driesen
da2446283a Move the unit conversion to the last moment
Processing the data in device units, and performing the unit conversion
only at the very last moment, avoids the need for intermediate floating
point math and thus possible rounding errors. In practice this is not
really an important issue, except for some case where a negative zero
value was returned.
2021-07-06 16:16:18 +02:00
Jef Driesen
6645b3f5e4 Implement the atmospheric pressure field 2021-07-06 16:16:18 +02:00
Jef Driesen
c8bd477c84 Always use the stored atmospheric pressure
The correct atmospheric pressure is measured and recorded by the dive
computer. There is no need to replace the correct value with some other
value.
2021-07-06 16:16:18 +02:00
Jef Driesen
c747dc7184 Add a CI job to build with Visual Studio
The migration to Visual Studio 2013 allows to build the Visual Studio
project in a Github Action.

Because some of the source files (e.g. the resource script and version
header) are normally auto-generated by the autotools build system, an
msys environment is setup to run the configure script. When building
from a distribution tarball, this extra step isn't necessary.
2021-07-02 17:30:58 +02:00
Jef Driesen
9307acbe4a Migrate to Visual Studio 2013 (or newer)
Starting with msvc 2013, the C compiler has much better C99 support. The
previous workaround to compile everything as C++ code is no longer
needed.

Some additional changes:

 - Add a 64bit build
 - Enable _CRT_SECURE_NO_WARNINGS to silence warnings
2021-07-02 17:29:27 +02:00
Jef Driesen
9106250a53 Emit events when downloading a memory dump 2021-06-25 17:17:20 +02:00
Jef Driesen
449b65cf1b Fix the depth decoding
With just 12 bits, the depth values are limited to at most 40.95m.
However for some deeper dives, this appears to be wrong. The next two
higher bits, which were previously unknown, are also part of the depth.
This increases the maximum depth to 163.83m.
2021-06-25 17:16:33 +02:00
Vincent Hagen
0bc7b195e5 Add library dependencies in windows build
Include libusb and hidapi when building for windows
these are also added to the artifact
2021-06-07 09:25:29 +02:00
Jef Driesen
fba5676b78 Fix the hwOS Sport firmware upgrade
Support for the S_BLOCK_WRITE2 command is only available since the hwOS
Tech firmware v3.09 and the hwOS Sport firmware v10.64. In commit
9e92381be48866f3f13a11e98d59962575bb5ad3 it was enabled for all firmware
versions newer than v3.09, causing the firmware upgrade to fail for
older hwOS Sport firmware versions.

Reported-by: Anton Lundin <glance@acc.umu.se>
2021-05-26 12:04:18 +02:00
Linus Torvalds
87d484e9a8 Merge tag 'v0.7.0' into Subsurface-DS9
Update to the v0.7.0 release.

Only a couple of trivial changes from the last development version we merged with:

 - add new product ID for the Sherwood Amphos 2.0

 - make the example app use the product name and not vendor name for the
   McLean Extrme

* tag 'v0.7.0':
  Release version 0.7.0
  Use the product name as the family name
  Add support for the Sherwood Amphos 2.0
2021-05-08 08:53:48 -07:00
Jef Driesen
14fd0296d4 Post release version bump to 0.8.0 2021-05-07 21:22:36 +02:00
Jef Driesen
47cbed5355 Release version 0.7.0 2021-05-07 21:22:36 +02:00
Jef Driesen
2ccdc46561 Use the product name as the family name
The standard practice for the human-readable family name is to use the
product name and not vendor name.
2021-05-07 20:46:56 +02:00
Nick Shore
37c4203537 Add support for the Sherwood Amphos 2.0 2021-05-02 16:08:10 +02:00
Linus Torvalds
9ab0800c00 Merge git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge upstream updates from Jef:

 - add suppoort for various new variants of existing dive computers:

    + Suunto Eon Steel Black, and new variant of Zoop Novo

    + Sherwood Beacon

    + new Shearwater Perdix AI model number

 - add new Sporasub SP2 support

 - various minor fixes and updates

* 'master' of git://github.com/libdivecomputer/libdivecomputer: (22 commits)
  Add support for a new Suunto Zoop Novo variant
  Add support for the EON Steel Black
  Add support for the Sporasub SP2
  Fix an overflow in the progress events
  Use a common sleep implementation
  Fix the clang compiler flag detection
  Add Github Actions CI builds and releases
  Show a summary after configuration
  Extend the OS detection to non Windows platforms
  Implement the ndl/deco sample
  Fix the maximum depth
  Mark the McLean Extreme as supporting BLE
  Fix -Wcast-qual compiler warning
  Mark the new iX3M 2021 models as supporting BLE
  Add support for the Sherwood Beacon
  Remove the infinite timeout
  Simplify the loop for reading the packet header
  Add a new Perdix AI hardware type
  Fix the McLean Extreme fingerprint feature
  Perform the check for the NULL key earlier
  ...
2021-04-22 08:40:35 -07:00
Nick Shore
d85d8811f0 Add support for a new Suunto Zoop Novo variant 2021-04-20 09:58:20 +02:00
Nick Shore
76d225dcfc Add support for the EON Steel Black 2021-04-20 09:30:01 +02:00
Jef Driesen
6ef72ab420 Add support for the Sporasub SP2
The Sporasub SP2 uses a very simple communication protocol and memory
layout, but with some unusual aspects:

Dives are artifically limited to a maximum of 6000 samples.

Unlike all other dive computers, the dives are not stored in some kind
of ringbuffer structure. Once the memory is full, no new dives can be
recorded. The existing dives need to be erased first, and the dive
computer will start recording again at te start of the memory area. The
Sporasub application has an "Auto-clear watch memory after data
transfer" feature for this purpose.

I didn't implement a more efficient download algorithm because
downloading a full memory dumps takes less than 10 seconds.
2021-04-15 16:47:59 +02:00
Jef Driesen
1418766a1a Fix an overflow in the progress events
The maximum value for the progress events is based on the amount of the
flash memory available for storing the dives. But the 8 byte serial
number is not stored inside the dive data, and is added dynamically
during the data transfer. This extra data needs to be taken into account
to avoid overflowing the progress events and trigger an assert in the
code.
2021-04-08 17:27:43 +02:00
Jef Driesen
752a064bb3 Use a common sleep implementation
Implement a common sleep function to eliminate some conditional
compilation in the rest of the code.
2021-03-24 17:17:57 +01:00
Jef Driesen
a4d771956a Fix the clang compiler flag detection
The clang compiler accepts *any* compiler flags, and just reports
an annoying warning instead:

  warning: unknown warning option '-Wsomething' [-Wunknown-warning-option]

Use -Werror=unknown-warning-option to change this warning into an error,
and detect the unsupported flag. Since this is a clang specific option,
it can't be used unconditionally with other compilers. The option is
also only used for checking the compiler flags, and not for compiling
the code.
2021-03-11 16:41:53 +01:00
Jef Driesen
007a2bc835 Add Github Actions CI builds and releases
The new Github Actions offers similar functionality as the Travis CI
integration, but with some interesting extra features:

The build action is almost equivalent to the existing Travis build
configuration. But as an extra feature, the build artifacts are now
available for download.

The release action does automatically build a distribution tarball and
create a Github release, whenever a new version is tagged and pushed.
2021-03-09 22:49:08 +01:00
Jef Driesen
6b576da5ef Show a summary after configuration 2021-03-07 21:24:15 +01:00
Jef Driesen
6bb13a564f Extend the OS detection to non Windows platforms
At the moment, only the Windows platform needs some special handling,
but this can easily be extended to detect and handle other platforms as
well.
2021-03-07 21:23:44 +01:00
Jef Driesen
bf482f6025 Merge branch 'vtpro' 2021-03-04 12:47:20 +01:00
Jef Driesen
d49a8a3e64 Implement the ndl/deco sample 2021-03-04 12:44:42 +01:00
Jef Driesen
95920af7b7 Fix the maximum depth
The upper bits appear to contain some other (currently unknown)
information. The Oceanic VT Pro specifications list a maximum depth of
399 ft (120 m), which requires only 9 bits. The Oceanic application also
ignores the higher bits.
2021-03-04 12:43:31 +01:00
Jef Driesen
3d3271abe1 Mark the McLean Extreme as supporting BLE
The McLean Extreme uses a dual stack Bluetooth module from Microchip
which supports both Bluetooth Classic and Low Energy.

Reported-by: David Carron <david_de_carron@hotmail.com>
2021-02-26 14:33:31 +01:00
Jef Driesen
b713136a00 Fix -Wcast-qual compiler warning
The CBC initialization vector is passed as a const pointer, and then
cast to a non-const pointer to store it in the aes state struct. This
cast can easily be avoided by changing the struct field into a const
pointer.
2021-02-24 12:00:05 +01:00
Jef Driesen
03ddc84384 Mark the new iX3M 2021 models as supporting BLE
The new iX3M 2021 models with bluetooth do support BLE communication.
Bluetooth Classic (rfcomm), which was the only supported bluetooth
variant in the previous models, is not available.
2021-02-16 11:43:53 +01:00
Jef Driesen
580e1d5fc5 Add support for the Sherwood Beacon
The Sherwood Beacon appears to be compatible with the Sherwood Sage. For
the BLE communication the handshake also fails and is disabled.
2021-02-16 09:54:52 +01:00
Jef Driesen
f42df2d846 Remove the infinite timeout
When an Uwatec Aladin is connected, but the transfer hasn't been started
yet, we receive a continuous stream of zero bytes. Approximately every
7-8ms a new zero byte is received. But when the dive computer is
(temporary) disconnected, the stream of zero bytes also ends.

The consequence is that due to the use of blocking read call with an
infinite timeout, the application becomes unresponsive, without any
chance to abort the communication. This can eaily be avoided by using a
timeout instead. Receiving the main 2048 byte packet takes about 1050ms.
Thus a 3000ms timeout should be long enough to not cause the main data
transfer to timeout, but still short enough to cancel reasonable fast.
2021-02-12 13:54:40 +01:00
Jef Driesen
ecc23a5a76 Simplify the loop for reading the packet header
The for loop construct without an increment statement is a bit unusual
and thus easy to miss. With an equivalent while loop, the intent becomes
a bit more obvious.
2021-02-12 13:54:40 +01:00
Jef Driesen
d63c6cd04e Add a new Perdix AI hardware type 2021-02-12 13:52:52 +01:00
Jef Driesen
034819cd2d Fix the McLean Extreme fingerprint feature
Currently the fingerprint feature uses the first 7 bytes of the computer
configuration data. Since this information does not uniquely identify a
dive, and is actually often identical for several dives, no new dives
are detected anymore. Fixed by using the date/time timestamp at the
start of the dive configuration data instead.

Reported-by: David Carron <david_de_carron@hotmail.com>
2021-02-08 11:01:24 +01:00
Jef Driesen
0f677fcaac Perform the check for the NULL key earlier
The previous commit added a check for a NULL key inside the filter
functions, but it's more efficient to handle it early on, before even
calling the filter function.
2021-02-05 14:25:53 +01:00
Jef Driesen
efc9236fbc Fix the return value for a NULL key
An example where the filter functions can be called with a NULL key is
when a bluetooth discovery fails to retrieve the name of the remote
device. In such case, we have no information to detect whether the
bluetooth device matches a known dive computer or not, and thus it
shouldn't be filtered out.
2021-01-25 16:51:04 +01:00
Jef Driesen
b9a99de158 Fix the oceanic filter function
The matching functions expect a pointer to the value as argument, and
not the value itself. Since a C string is already a pointer (to a NULL
terminated character array), an extra pointer indirection is required.
2021-01-25 09:39:05 +01:00
Linus Torvalds
81f95d3880 Mark the Aqualung i750TC as BLE-capable
Dirk got a log from Amin that shows

  Discovered new device: "EZ001945" "LE:{cb0ff33a-40d3-63eb-2764-11e63896534f}"
  Not recognized as dive computer

and that's the i750TC device model name.  It's not recognized as a dive
computer because subsurface don't have that EZ as a model version, but
even if it did, it would not try to use BLE to download because
libdivecomputer doesn't mark it as BLE capable.

But it appears that it is, so add the protocol marker (even if the log
Dirk has then shows a failure to connect, so not all is well).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-01-23 11:11:53 -08:00
Linus Torvalds
38ebb81536 Merge branch 'master' of git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge with Jef's upstream libdivecomputer updates:

 - support new Ratio iX3M 2021 model IDs

 - support Mares Horizon, and fix the Mares Genius layout

 - add support for Shearwood Sage

 - various warning fixes, other minor details

* 'master' of git://github.com/libdivecomputer/libdivecomputer: (23 commits)
  Wait before sending the firmware data
  Add support for the new iX3M 2021 models
  Avoid generating the SIGPIPE signal
  Use an unsigned value to represent the undefined state
  Use an unsigned integer for the number of dives
  Use the cross-platform socket file descriptor type
  Limit the size to INT_MAX
  Define DC_TIMEZONE_NONE as a signed integer
  Use an unsigned integer for the length
  Fix -Wsign-compare compiler warnings
  Fix -Wshadow compiler warnings
  Fix -Wcast-qual compiler warning
  Fix -Wswitch compiler warning
  Remove unused variables
  Implement the rbt sample
  Use some more descriptive variable names
  Verify the oxygen and helium percentage
  Add support for the Mares Horizon
  Swap the object major and minor version
  Fix the Mares Genius memory layout
  ...
2021-01-23 11:00:50 -08:00
Jef Driesen
939470df52 Wait before sending the firmware data
Without the small delay, sending the first frame often fails. Trying to
read the ACK response byte just fails with a timeout, and no data is
received at all. The bootloader is probably not ready to receive data
yet.
2021-01-15 09:33:28 +01:00
Jef Driesen
0239329f06 Add support for the new iX3M 2021 models
The new iX3M 2021 models (refered to as 'iX3M with Sequared Buttons' in
the Ratio support section) identify as iX5M in the Bluetooth name.

Reported-by: Damian Zaremba <damian@damianzaremba.co.uk>
2021-01-15 08:59:46 +01:00
Jef Driesen
d5dffb70be Avoid generating the SIGPIPE signal
Handling the SIGPIPE signal in a library is tricky, because installing a
signal handler does affects the entire application. But we can at least
try to avoid generating the SIGPIPE signal ourselves. On Linux, that
requires the use of the MSG_NOSIGNAL flag, and on Mac and BSD setting
the SO_NOSIGPIPE socket option.
2021-01-07 21:39:47 +01:00
Jef Driesen
4ffd45c126 Merge branch 'warnings' 2021-01-05 13:01:48 +01:00
Jef Driesen
ba6a8a43f7 Use an unsigned value to represent the undefined state
This fixes some more -Wsign-compare compiler warnings.
2021-01-05 09:32:45 +01:00
Jef Driesen
5eddaeade6 Use an unsigned integer for the number of dives
Because the dive_count variable is decremented, it doesn't contain the
total number of dives, but the index of the last dive. A negative number
indicates no dives. The same result can be obtained by using the total
number of dives directly. That's not only more intuitive, but also fixes
a -Wsign-compare compiler warning.
2021-01-05 09:32:45 +01:00
Jef Driesen
fc76b4a258 Use the cross-platform socket file descriptor type
Windows and unix use a diferent data type for representing socket file
descriptors (SOCKET vs int). This mismatch results in a compiler warning
when comparing to S_INVALID.
2021-01-05 09:32:45 +01:00
Jef Driesen
b0cce363f1 Limit the size to INT_MAX
Allthough the input buffer size has type 'size_t', the return value of
the function has only type 'int'. Hence the function can't support input
buffers larger than INT_MAX.

This allows to fix a -Wsign-compare compiler warning: operand of ?:
changes signedness from ‘int’ to ‘size_t’ due to unsignedness of other
operand.
2021-01-05 09:32:45 +01:00
Jef Driesen
10a4ec0b08 Define DC_TIMEZONE_NONE as a signed integer
The hexadecimal value 0x80000000 is too large to be represented as a
signed 32bit integer. Therefore the default type for the constant is an
unsigned 32bit integer. This is a bit annoying because the timezone
field is actually defined as a signed integer, and thus comparisions
produce -Wsign-compare compiler warnings.

Fixed by switching to INT_MIN, which is the same underlying value but
interpreted as a signed integer.
2021-01-05 09:32:45 +01:00
Jef Driesen
0688b74099 Use an unsigned integer for the length
This avoids -Wsign-compare compiler warnings due to comparison of
integer expressions of different signedness.
2021-01-05 09:32:45 +01:00
Jef Driesen
1130b7eade Fix -Wsign-compare compiler warnings
Comparing signed and unsigned integer expressions can have unexpected
results because the signed integer will get promoted to an unsigned
integer. To avoid the warning, add an explicit cast to the unsigned
type, along with a check to catch negative values.
2021-01-05 09:32:45 +01:00
Jef Driesen
8f383ac531 Fix -Wshadow compiler warnings
Rename a few variables, parameters and functions to avoid shadowing
others.
2021-01-05 09:32:45 +01:00
Jef Driesen
7c9726da64 Fix -Wcast-qual compiler warning
String literals have the type 'char[N]' by default. Allthough they are
not really 'const', modifying a string literal is undefined behaviour.
Therefore, to avoid mistakes, libdivecomputer uses the -Wwrite-strings
compiler option to change the default type to 'const char[N]'.

The cast that triggers the -Wcast-qual warning can be avoided by using a
character array instead of string literal.
2021-01-04 20:20:52 +01:00
Jef Driesen
548fce69f8 Fix -Wswitch compiler warning
Add a default label to prevent warnings for all enum values not handled
in the switch statement. It's intentional in this piece of code.
2021-01-04 20:20:52 +01:00
Jef Driesen
b97acabb01 Remove unused variables 2021-01-04 20:20:52 +01:00
Jef Driesen
6c9a758648 Implement the rbt sample
The name of the RBT (Remaining Bottom Time) sample was taken from the
Uwatec dive computers. The actual definition depends on the dive
computer, but it usually corresponds to the air time remaining (with or
without some additional factors taken into account).
2021-01-04 20:20:03 +01:00
Jef Driesen
e592c7e7b7 Use some more descriptive variable names 2021-01-04 20:20:03 +01:00
Jef Driesen
cebf4089cc Verify the oxygen and helium percentage
The oxygen and helium percentage in the gas change event should
correspond to the percentages indicated in the dive header.
2021-01-04 20:20:03 +01:00
Jef Driesen
099fda0d2b Merge branch 'horizon' 2020-12-24 14:06:03 +01:00
Jef Driesen
8b06f2c31d Add support for the Mares Horizon
The Mares Horizon is a variant of the Mares Genius, with a few changes
to support SCR dives:

The dive header is slightly modified. There is an extra 8 byte field at
offset 0x18, which causes all later fields to have moved up with the
same amount. This difference is indicated in both the object minor
version (with a change from v0.0 to v0.1), and the logformat.

For the profile data, there is a new SDPT sample type which contains a
bit more information compared to the existing DPRS sample type. This
difference is indicated with a change in the object type (from 0 to 1).

The current implementation assumes a fixed order for the record types (a
DSTR record, a TISS record, zero or more DPRS/SDPT records with an AIRS
record every 4 sample, and finally a DEND record), and either only DPRS
or SDPT records but never a mixture of the two. If these assumptions
turns out to be incorrect, the implementation will need to be changed
significantly. Note that the assumption of the fixed order was already
present for the Genius.

Bluetooth support is currently disabled in the Horizon firmware, but
might be re-enabled in the future.
2020-12-24 13:52:47 +01:00
Jef Driesen
484e9dcdc3 Swap the object major and minor version 2020-12-24 11:33:18 +01:00
Jef Driesen
9438064afc Fix the Mares Genius memory layout
The Mares Genius appears to have 16M of flash memory, and it also
supports 4K packets.
2020-12-24 11:28:03 +01:00
Jef Driesen
6ab4ac7f7f Merge branch 'oceanic-ringbuffer-pointers' 2020-12-24 11:16:09 +01:00
Jef Driesen
9eddbe88be Skip logbook entries with invalid pointers
Since logbook entries with invalid ringbuffer pointers are considered a
fatal error, the download is aborted. The result is that any remaining
entries, located after the invalid entry, can't be downloaded at all.

This can be avoided by skipping the problematic entry instead of
aborting the download.
2020-12-01 11:05:37 +01:00
Jef Driesen
e53e7cf961 Re-use the common error handling code
There is no need to duplicate the error cleanup code everywhere. Break
out of the while loop and cleanup at the end of the function.
2020-12-01 11:04:56 +01:00
Jef Driesen
90a08ad845 Add support for the Sherwood Sage
The Sherwood Sage appears to be very similar to the Aeris A300CS. For
the BLE communication the handshake fails and is disabled.

Reported-By: Nick Shore <support@mac-dive.com>
2020-11-26 14:13:57 +01:00
Linus Torvalds
e58a5866bb Merge git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge upstream libdivecomputer from Jef:

 - support the Scubapro Aladin A2

 - improve Cressi Goa support

 - parse and report Oceanic firmware versions

* 'master' of git://github.com/libdivecomputer/libdivecomputer:
  Report the firmware version in the devinfo event
  Refactor the version string matching to use one table
  Parse the firmware version
  Add support for Cressi Goa gauge and freedives
  Add the extra 5 bytes containing the divemode
  Add a function to insert data anywhere in the buffer
  Add support for the Scubapro Aladin A2
2020-11-08 16:04:40 -08:00
Dirk Hohndel
4fc85409da bugfix: only sort non-NULL array
Unclear if this is needed.

This might address CID 363698

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-31 15:10:25 -07:00
Dirk Hohndel
47be86eb79 fix incorrect comparison
Operator precedence gets me every time. Equally binds stronger
than bitwise logical operation.

Fixes CID 363699

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-31 15:09:04 -07:00
Linus Torvalds
1712b99f79 Merge branch 'Garmin-Mk2i' into Subsurface-DS9
This merges the FIT file parsing extensions to actually parse the
pressure data from the new Garmin Descent Mk2i.

There is more data there about cylinder sizing etc that we can parse,
but this is enough to make things useful.  At least for the test cases I
have access to so far.

* Garmin-Mk2i:
  Garmin Descent Mk2i: add support for parsing cylinder pressure data
  Garmin: add skeleton for the new fields for the Descent Mk2/Mk2i
2020-10-30 12:40:53 -07:00
Linus Torvalds
89b1cc4f28 Garmin Descent Mk2i: add support for parsing cylinder pressure data
Very early trial at parsing the pressure data from the Garmin tank pods.
It seems to work for the test-cases I have.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-10-30 12:37:19 -07:00
Dirk Hohndel
3a300a6a8f
Merge pull request #25 from subsurface/mtp
Garmin Descent Mk2/Mk2i MTP support
2020-10-30 10:53:17 -07:00
Linus Torvalds
c4a3db4ac1 Garmin: add skeleton for the new fields for the Descent Mk2/Mk2i
This adds the field definitions, but doesn't actually report the data
yet.  But just having the definitions makes the debug output a lot
easier to read through.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-10-30 10:50:00 -07:00
Dirk Hohndel
9554e87431 Garmin: support .FIT files from filesystem even for MTP devices
If the caller provides us with a path name, we should not try to connect to the
dive computer via MTP, but instead read the .FIT files from the path provided.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-30 10:01:29 -07:00
Dirk Hohndel
ea3e542450 Garmin: add MTP support
Create parallel helper functions that use libmtp to walk the file tree on the
device and to then read a specific file from the device into our dc_buffer.
MTP is not a file system, it's an object storage, that just happens to allow
object names and parent/child relationships between objects. As a result we
need to remember those file ids for MTP downloads.

The mtp_get_file_list function is rather complex as it includes both the
initial communication with the device and the code to walk the object tree and
then create the list of file.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-29 13:48:01 -07:00
Dirk Hohndel
05e066b2ff Garmin: refactor the code to prepare for MTP support
Breaking things into helper function makes it much easier to then support both
regular file operations and MTP.

This includes some mild whitespace cleanups for consistency.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-29 13:21:10 -07:00
Dirk Hohndel
8df5c15db9 Garmin: add the Descent Mk2/Mk2i
Just like for the Descent Mk1 this uses the internal Garmin model number (as
indicated in the FIT format) as model, not the USB product ID.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-29 13:21:10 -07:00
Dirk Hohndel
e1bbdd5e65 Garmin: pass the model to the device_open function
We do this for a few other device where we need slightly different behavior,
depending on the specific model.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-27 15:26:20 -07:00
Jef Driesen
7f553c1276 Merge branch 'oceanic-firmware-version' 2020-10-27 11:14:29 +01:00
Jef Driesen
b7850e9cbf Report the firmware version in the devinfo event 2020-10-27 10:54:40 +01:00
Jef Driesen
50f3ba3189 Refactor the version string matching to use one table
With just a single table, the version string matching not only becomes
simpler, but adding new layouts also requires no code changes anymore.

For devices that need different layouts depending on the firmware
version (e.g. Oceanic Atom 2.0 and Aeris Manta), the table may contain
multiple entries with the different firmware versions. The only
requirement is that the entry with the highest firmware version must be
listed first.
2020-10-27 10:54:40 +01:00
Jef Driesen
014a15ba62 Parse the firmware version
The patterns used for the version string have the firmware version
masked out because it varies. We can re-use those masks to extract the
firmware version.
2020-10-27 09:43:25 +01:00
Jef Driesen
5b133233f7 Merge branch 'goa-freedive' 2020-10-20 13:58:54 +02:00
Jef Driesen
c77a311a89 Add support for Cressi Goa gauge and freedives
The gauge and freedives have a slightly different data format compared
to scuba dives. The main difference is the size of the header and two
new sample types.
2020-10-20 13:56:20 +02:00
Jef Driesen
57cd11fffe Add the extra 5 bytes containing the divemode
The logbook header has 5 bytes extra, which are not present in the dive
header. Those 5 extra bytes contain the dive mode, which is required for
parsing the dive data. Therefore, insert all 5 bytes again and update
the parser.

The remaining 4 bytes appear to be some 32 bit address. They are not
used for anything right now, but are preserved as well in case they are
needed in the future.
2020-10-20 13:56:20 +02:00
Jef Driesen
fe9a3d9a10 Add a function to insert data anywhere in the buffer
The memory buffer already supported appending and prepending data, but
not inserting data anywhere in the buffer. That's exactly what the new
function does. The free space is still maintained at either the start or
the end of the buffer.
2020-10-20 13:56:20 +02:00
Nick Shore
625f56b494 Add support for the Scubapro Aladin A2 2020-10-13 09:04:32 +02:00
Linus Torvalds
0ebd5d3879 Garmin Descent: clear dive data in between dives
This actually got broken long ago (and before the new "Subsurface-DS9"
branch: when I converted the Garmin parser to use the generic field
cache, I missed the fact that the parser now cleared _only_ that generic
part of the per-dive cache in between different dives.

The GPS information, and the general dive information would be left
alone in between dives, and could leak from one dive to the next.

Most of the time you don't notice, because dives tend to all have the
same information, so the stale data would get overwritten when parsing
the next dive.  But that isn't _always_ true - particularly for the GPS
information, not all the data necessarily always exists.

So clear all the per-dive data when starting to parse a new dive.

This puts the non-gps data all in one sub-structure, so that it's easy
to clear that too in one go - even though that part of the data probably
always does get opverwritten by the new dive data.

Reported-by: @brysconsulting
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-09-29 16:54:48 -07:00
Linus Torvalds
d52dfb002d Merge git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge updates from Jef's upstream branch.

Fix Mares Genius salinity parsing, and a possible buffer overflow in the
Liquivision Lynx parser.

This also has Jef's copy of Dirk's Shearwater PNF parsing fix that we
already had in our tree.

* 'master' of git://github.com/libdivecomputer/libdivecomputer:
  Fix a buffer overflow
  fix Shearwater PNF parsing for Petrel / Petrel 2
  Fix a bug in the salt and fresh water parsing
2020-09-21 12:22:30 -07:00
Linus Torvalds
1801023c68 Merge branch 'cleanup' of https://github.com/subsurface/libdc into Subsurface-DS9
Pull coverity fixes from Dirk Hohndel.

* 'cleanup' of https://github.com/subsurface/libdc:
  fix some coverity errors
2020-09-21 12:21:36 -07:00
Dirk Hohndel
a004fdffed fix some coverity errors
CID 350142: Resource leak
CID 350154: Resource leak
CID 360641: Resource leak
CID 350147: Possibly not null-terminated strings

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-21 12:05:57 -07:00
Jef Driesen
c6ea7afb76 Fix a buffer overflow
The existing check accepts the number of array elements as a valid
index. That's clearly wrong for zero based indexing, and would result in
a buffer overflow.
2020-09-21 11:49:35 +02:00
Dirk Hohndel
469d3ee177 fix Shearwater PNF parsing for Petrel / Petrel 2
At some point (possibly around v71 of their firmware), Shearwater implemented
PNF for the Petrel and Petrel 2. Those are of course not air integrated, and
apparently don't support adjustable sample rate, so the log data doesn't include
opening and closing record 5. Instead of failing when those aren't found, we
should simply only access those when they actually exist.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-21 09:39:12 +02:00
Linus Torvalds
8cfd2aacaf Merge branch 'shearwaterPNFfix' of github.com:Subsurface-divelog/libdc into Subsurface-DS9
Pull Shearwater PNF parsing fix from Dirk:
 "The parser assumed that all opening/closing records were required.

  But it seems that for the Petrel / Petrel 2 they actually aren't,
  specifically record 5 is missing.

  Which makes sense, as that one only contains air integration stuff
  plus the sample interval (which isn't configurable on the older dive
  computers)"

* 'shearwaterPNFfix' of github.com:Subsurface-divelog/libdc:
  fix Shearwater PNF parsing for Petrel / Petrel 2
2020-09-19 12:01:02 -07:00
Dirk Hohndel
8e1335e372 fix Shearwater PNF parsing for Petrel / Petrel 2
At some point (possibly around v71 of their firmware), Shearwater implemented
PNF for the Petrel and Petrel 2. Those are of course not air integrated, and
apparently don't support adjustable sample rate, so the log data doesn't include
opening and closing record 5. Instead of failing when those aren't found, we
should simply only access those when they actually exist.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-19 10:29:55 -07:00
Jef Driesen
8a10e545d4 Fix a bug in the salt and fresh water parsing
The original Mares Genius support was based on Mares Dive Organizer
2.25, which has a bug in the salinity parsing. The latest version 2.26
has this bug fixed.

Reported-by: Greg McLaughlin <gregm@somemore.com>
2020-09-18 17:29:52 +02:00
Dirk Hohndel
7d26fb6a13 Add BLE transport for McLean Extreme
As suggested by Linus.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-15 13:37:18 -07:00
Linus Torvalds
2e63eaec16 Merge git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Pull McLean Extreme fix from Jef Driesen.

The McLean Extreme sample interval was wrong, causing imported dives to
appear twice as long as long as they should.

* git://github.com/libdivecomputer/libdivecomputer:
  Fix the sample interval
2020-09-15 10:39:06 -07:00
Jef Driesen
2909863573 Fix the sample interval
The McLean Extreme records a sample every 10 seconds instead of every 20
seconds. This resulted in dive durations that were twice as long as
expected.

Reported-by: David Carron <david_de_carron@hotmail.com>
2020-09-15 15:06:12 +02:00
Linus Torvalds
39dc77d669 Shearwater Teric: remove our local support for the TAG INFO_EVENT
This mostly reverts commit cb7f47b ("Shearwater Teric: add support for
the TAG INFO_EVENT") because upstream libdivecomputer now does this
natively as of commit 3e89e1b ("Add support for parsing info events").

Also, the way this had been done, it looks like it had basically
disabled the support for LOG_RECORD_FREEDIVE_SAMPLE, although nobody
seems to have ever complained, so presumably there aren't a lot of
freedivers using Shearwater dive computers and subsurface.

With this, our main differences with Jef are just the string interface
code, and the fact that we still stop parsing at LOG_RECORD_FINAL.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-09-12 12:22:50 -07:00
Linus Torvalds
d6153a5a07 Merge branch 'Subsurface-DS9' of github.com:Subsurface-divelog/libdc into Subsurface-DS9
Merge Dirk's Peregrine support with Jef's.

Jef had some extra logic, and otherwise the same, so this is just a
history merge with no content difference.

* 'Subsurface-DS9' of github.com:Subsurface-divelog/libdc:
  Add basic detection for Shearwater Peregrine
2020-09-12 12:00:37 -07:00
Linus Torvalds
f33814c13c Merge git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge upstrean libdivecomputer updates from Jef Driesen:

 - a different way to work around the windows 'instance' craziness

 - minor updates to the Shearwater parser

* git://github.com/libdivecomputer/libdivecomputer:
  Add support for parsing info events
  Add support for the Shearwater Peregrine
  Fix a conflict with the Windows header files
  Add a missing parameter for the USB HID filter
2020-09-12 11:55:52 -07:00
Dirk Hohndel
ad566ab04f Add basic detection for Shearwater Peregrine
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-08-21 16:11:53 -07:00
Jef Driesen
3e89e1b871 Add support for parsing info events 2020-08-22 00:27:11 +02:00
Jef Driesen
e2ecd96daa Add support for the Shearwater Peregrine 2020-08-22 00:05:32 +02:00
Jef Driesen
7a4c5e919f Fix a conflict with the Windows header files
In one of the Windows system header files, an "interface" macro is
defined as:

  #define interface struct

This results in some very strange build errors when also including the
descriptor-private.h header file. That's because the dc_usb_params_t
struct has a member field named "interface":

  typedef struct dc_usb_params_t {
      unsigned int interface;
      unsigned char endpoint_in;
      unsigned char endpoint_out;
  } dc_usb_params_t;

As a workaround, define the WIN32_LEAN_AND_MEAN macro before including
the windows.h header file. This excludes some less common Windows API
declarations, including the above one.
2020-08-21 23:56:52 +02:00
Jef Driesen
51b1ae925c Add a missing parameter for the USB HID filter
In commit 57f0ce6d7902117cfc4d0d6b401b516fc93ca488, an extra parameter
was added to the dc_descriptor_filter() function. But I only updated the
libusb code path and forgot to do the same for the hidapi variant.
2020-08-21 17:57:47 +02:00
Linus Torvalds
1df0e13cc4 Fix for absolutely wonderful Windows feature
It turns out that Windows is more of a PoC than I ever imagined.  The
system headers will have something like this in it:

  #define __STRUCT__ struct
  #define interface __STRUCT__

which means that using the identifier "interface" will result in
completely indecipherable error messages from a Windows compiler.

That's some truly broken stinking garbage.  It's not like "interface" is
even a bad identifier.

Let's just #undef this crazy feature.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-08-20 14:06:46 -07:00
Linus Torvalds
378b9c1aec Fix HIDAPI breakage
When Jef added a filter parameter in commit 57f0ce6 ("Add support for
filter parameters") he didn't do the HIDAPI case, because who uses
HIDAPI?

Windows and OS X, it would seem.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-08-20 13:28:28 -07:00
Linus Torvalds
3c1e763a47 Merge git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge upstream changes by Jef Driesen:

 - add support for Liquivision dive computers

 - add support for the Aqualung i470TC

 - extract out Atomic Aquatics Cobalt USB support as a iostream

 - misc fixes

* git://github.com/libdivecomputer/libdivecomputer:
  Fix the OSTC4 firmware upgrade
  Handle a negative number of bytes as an error
  Update the example application
  Use the new USB transport for the Atomic Aquatics Cobalt
  Add an I/O implementation for USB communication
  Add support for filter parameters
  Disable direct access to the filter function
  Increase the receive timeout to 5 seconds
  Fix the McLean Extreme bluetooth name
  Add support for Liquivision dive computers
  Add support for the Aqualung i470TC
2020-08-20 12:36:38 -07:00
Jef Driesen
9dace57814 Fix the OSTC4 firmware upgrade
Commit d1b865d192afc9efde337b5cff8a239366f15565 breaks the OSTC4
firmware upgrade because the OSTC4 expects to receive the service init
command and the service key all at once, before sending any response.

The hwOS firmware still reads the service init command one byte at a
time, and sends the echo immediately after each byte. But in the
meantime, the hwos firmware has also been optimized. The processing time
for an incoming byte is now always faster then the time it takes for the
next byte to physically arrive via the serial line between the USB/BT
chip and the processor. Thus, even without any buffering, sending all
bytes at once should no longer be a problem.

This partially reverts commit d1b865d192afc9efde337b5cff8a239366f15565.

Reported-by: Anton Lundin <glance@acc.umu.se>
Suggested-by: Ralph Lembcke <mail@ralph-lembcke.de>
2020-08-20 15:29:15 +02:00
Jef Driesen
c77551b366 Handle a negative number of bytes as an error
There is no reason for libusb to ever return a negative number of bytes,
but due to the use of a signed integer, it's technically possible. And
because libdivecomputer returns an unsigned integer, such a negative
number would be reported as a very large size.
2020-08-11 15:22:31 +02:00
Jef Driesen
33a20bd2b8 Merge branch 'iostream-usb' 2020-08-11 15:22:07 +02:00
Jef Driesen
5380b247af Update the example application
The application is now responsible for setting up the USB based I/O
stream.
2020-08-11 15:16:36 +02:00
Jef Driesen
c72dc4aa73 Use the new USB transport for the Atomic Aquatics Cobalt
Replace the hardcoded libusb based code with the new USB I/O transport.
This enables the use of a custom I/O on platforms where libusb is not
available.
2020-08-11 15:16:36 +02:00
Jef Driesen
c84bbd93a3 Add an I/O implementation for USB communication
The USB communication is now also implemented as an I/O stream
transport. Unlike most I/O devices, USB communication supports multiple
interfaces and endpoints. This requires some some special care:

In the general case, autodetection isn't really possible without
additional knowledge. Hence the need for the filter parameters to pass
this kind of information.

The implementation assumes two bulk endpoints for the standard
read/write interface. Communication with the control endpoint is
supported through the new DC_IOCTL_USB_CONTROL_{READ,WRITE} ioctl's.
2020-08-11 15:16:36 +02:00
Jef Driesen
57f0ce6d79 Add support for filter parameters
The filter parameter provides a mechanism to pass some additional
information, needed to configure the I/O stream, back to the caller.
2020-08-03 11:51:59 +02:00
Jef Driesen
edacbb2f13 Disable direct access to the filter function
Replace the small helper function to retrieve the function pointer and
then call the function, with another helper function to call the filter
function directly. This way the function pointer doesn't need to be
exposed at all.
2020-08-03 11:51:59 +02:00
Jef Driesen
6986840c0d Increase the receive timeout to 5 seconds
When the fingerprint feature isn't used (or with a timestamp of zero),
the response to the SIZE (0xC6) and DATA (0xC4) commands is received
almost instantly:

    [0.302704] W: C60000000010270000
    [0.366727] R: DCF90F00
    [0.367829] W: C40000000010270000
    [0.394812] R: E0F90F00

But when the fingerprint feature is used (with a non-zero timestamp),
there is a noticable delay:

    [0.341218] W: C64CEB204D10270000
    [1.927905] R: FE0B0000
    [1.931610] W: C44CEB204D10270000
    [5.092081] R: 020C0000

In this particular case, the total amount of dive data was close to 1M
bytes, which pushed the delay over the 3 second timeout, and caused the
download to fail. Increasing the timeout to 5 seconds fixed the problem.

The most likely explanation is that the dive computer needs to scan its
internal logbook to determine which dives and how many bytes to send.
Because that involves reading relative slow flash memory, this can take
up to a few seconds, especially if there are many dives present.

The duration of the delay also depends on the value of the fingerprint
timestamp: the less dives we try to download, the longer the delay! I
suspect that's because the most recent dives are located near the end of
the logbook. Hence, the less dives we request, the more dives the dive
computer needs to skip.

Below are some timings for downloading espectively 792410, 531856 and
270850 bytes from the same dive computer, but with a different
fingerprint value:

    [0.216305] W: C6F8D5C84510270000
    [0.373511] R: 56170C00
    [0.378929] W: C4F8D5C84510270000
    [0.661388] R: 5A170C00

    [0.236246] W: C620D80F4810270000
    [0.559608] R: 8C1D0800
    [0.563755] W: C420D80F4810270000
    [1.171631] R: 901D0800

    [0.246193] W: C654E6434A10270000
    [0.826365] R: FE210400
    [0.831760] W: C454E6434A10270000
    [1.974351] R: 02220400
2020-08-03 11:48:33 +02:00
Jef Driesen
cdd618e683 Fix the McLean Extreme bluetooth name 2020-07-26 17:27:49 +02:00
Jef Driesen
71a149d776 Add support for Liquivision dive computers 2020-07-09 17:02:32 +02:00
Linus Torvalds
6935fe717a Merge branch 'Oceans-S1' into Subsurface-DS9
Add initial support for the Oceans S1.

This expands a bit on the generic functions for the field-cache code,
and uses that to then add a fairly minimal Oceans S1 downloader.

And while it's minimal, it downloads about everything the S1 offers,
which is mainly just depth and temperature.

There are a few fields that it currently doesn't use, notably the
events and NDL information that the dive computer presumably reports in
the auxiliary data that comes in the sample, but without documentation
and more testing I'm not comfortable parsing that.

There's also some "current dive computer state" that isn't imported,
like the battery status.  I know how to read it, but it's not per-dive
data that could be added as extra fields: it's literally just the
current dive computer battery state at the time of the download.

The Oceans team said they'll provide more information about the
download, so this might be expanded in the future, but it seems fairly
usable even in this form.

Thanks to Dhaval Giani for sending me his Oceans S1 as a loaner, and to
Seth Garrison for doing the initial BLE packet dumps that made me think
it was fairly easily doable.

* Oceans-S1:
  Oceans S1: polish up the downloading logic for usability
  Oceans S1: actually download all dives and parse them
  Oceans S1: fill out core download protocol details
  Oceans S1: start filling in protocol details
  Oceans S1: start documenting the download format and first packets
  Add skeleton for Oceans S1 downloader
  Add generic dc_field_get() helper
2020-06-25 11:33:12 -07:00
Linus Torvalds
6b22340ddc Merge git://github.com/libdivecomputer/libdivecomputer into Subsurface-DS9
Merge upstream libdivecomputer updates from Jef Driesen:

 - Jef merged the EON Steel dive sorting fix we had in our branch: one
   less difference to upstream

 - Jef merged the McLean Extreme support with some updates and cleanups,
   this just takes all his changes.

 - manual pages for iostream

 - various minor fixes and updates from Jef

* git://github.com/libdivecomputer/libdivecomputer:
  Update the gitignore file
  Update the man pages for the new iostream functions
  Purge the serial port buffer during initialization
  Add support for the McLean Extreme
  Suunto Eon Steel: sort the dive list properly
  Remove the salinity compensation
  Fix the hwOS ppO2 bug for firmware v3.08
2020-06-25 11:24:00 -07:00
Linus Torvalds
8d17c3c01c Oceans S1: polish up the downloading logic for usability
This adds a few finishing touches to actually download dives in the
expected order (newest first), which fixes the handling of already
downloaded dives.

It also adds the fingerprinting code to optimize the downloading a bit.

Finally, it handles cancellation in the middle.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-25 10:40:41 -07:00
Linus Torvalds
da8ae52b50 Oceans S1: actually download all dives and parse them
This isn't perfect - we don't do the whole dive fingerprint etc, so
right now it always downloads all dives.

To make matters worse, it downloads dives oldest first, which then
confuses the subsurface downloader that expects newest first.

So there's stuff to clean up, but the basic profile data is all there.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-24 17:09:34 -07:00
Linus Torvalds
91658dd167 Oceans S1: fill out core download protocol details
All of the Oceans S1 protocol seems to be basically ASCII data, but the
bigger chunks of data (the dive list, and the actual dive profiles) are
chunked in 512-byte pieces with sequence numbers and what looks like
some checksum.

This doesn't check the checksum yet, but the basic "download data" seems
to work.

Note that the code doesn't actually _parse_ said data yet, nor create an
actual dive list.  So this is very much only very incremental progress,
but this seems to have been the nastiest part of the actual protocol.

Knock wood.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-24 14:18:57 -07:00
Linus Torvalds
ae58a66d9a Oceans S1: start filling in protocol details
This does the time sync command, which is particularly simple.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-23 15:45:27 -07:00
Linus Torvalds
7018206f56 Oceans S1: start documenting the download format and first packets
The communication seems to be mainly ASCII strings, with the main
complexity probably being that the Nordic Semi UART has some side
channel for switching between line-buffered and "bulk data" modes.

That part might end up being painful and needing more interfaces to the
Subsurface BLE code.

We'll likely need to add more special BLE code.  The Bluetooth SIG
really is a horrible disgrace.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-23 14:28:44 -07:00
Linus Torvalds
d58b8f6928 Add skeleton for Oceans S1 downloader
This does nothing, but fills in all the basic boiler plate code and data
structures.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-23 13:28:10 -07:00
Linus Torvalds
e9129ff45a Add generic dc_field_get() helper
This generic helper just gets everything from the field cache.

Dive computers can do their own things for any field they handle
differently, and then at the end fall back to this for all of the common
cases that are purely described by the field cache structure.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-22 14:56:55 -07:00
Jef Driesen
91acd9bb2d Add support for the Aqualung i470TC 2020-06-19 11:47:46 +02:00
Vincent Hagen
c065a78402 Update the gitignore file 2020-06-15 11:42:22 +02:00
Vincent Hagen
21742bd2ec Update the man pages for the new iostream functions
- Added missing man pages for the new functions.
 - Updated the main libdivecomputer man page to reflect the new flow.
 - Fixed minor typos in the dc_parser_get_field and
   dc_parser_samples_foreach functions.
2020-06-15 11:36:26 +02:00
Jef Driesen
85074dba40 Purge the serial port buffer during initialization 2020-06-08 13:45:43 +02:00
David Carron
8d35ee6978 Add support for the McLean Extreme 2020-06-08 13:45:43 +02:00
Linus Torvalds
9e6035f98a Suunto Eon Steel: sort the dive list properly
Instead of assuming that the dive list is presented in a sorted circular
list, sort it properly alphabetically (which also ends up being a
numerical sort for the HEX ascii dive names).

The "search for most recent dive, then splice the list around" case
doesn't work in the general case.  It happens to work if you don't
delete any dives, and dives only disappear as they are being overwritten
by new dives when the storage overflows.

But if you delete dives and then create new ones, the dive list will not
be sorted at all, and we should sort it properly when downloading.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-06-08 13:38:45 +02:00
Jef Driesen
cac0eb7d81 Remove the salinity compensation
In recent hwos firmware versions, the depth is no longer stored as
pressure (in millibar), but directly as depth (in meters) with the
salinity and gravity factor already applied.
2020-06-03 14:08:02 +02:00
David Carron
ee84202b2b Add support for the McLean Extreme dive computer
Initial support for McLean Extreme

Signed-off by: David McLean Carron <david_de_carron@hotmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-18 09:52:17 -07:00
Jef Driesen
9525bc8047 Fix the hwOS ppO2 bug for firmware v3.08
The hwOS ppO2 firmware bug is also present in firmware 3.08. See commit
b9a3606f379c3c9f57bbf561bdcb52fb76b711db for more details.
2020-05-13 16:45:53 +02:00
Linus Torvalds
48e46cf777 Shearwater: add extended information parsing
This adds the string field interface to the Shearwater family of dive
computers.

That includes proper serial number formatting, but it also has a lot of
new fields for battery information (both the dive computer itself and
the transmitter) but also deco model information.

Much of the deco model cases come from Anton Lundin in the original
subsurface branch, and Dirk Hohndel added the battery type and serial
number and firmware version data.  And I ended up massaging it even in
that original branch, so it blamed me for all these lines even back
there.

The sign-offs from Dirk and Anton are from the original commits.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:14:10 -07:00
Linus Torvalds
53f82e4ac9 Shearwater: fix (again) per-cell ppO2 reporting
This re-applied commit 902dbf4d6d24 ("shearwater: Fallback to
average/voted ppo2") which got lost in the last merge with upstream when
I synced with Jef's rewrite of the PNF parser.

Reported-by: Martin Long <martin@longhome.co.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:12:43 -07:00
Dirk Hohndel
cb7f47b60b Shearwater Teric: add support for the TAG INFO_EVENT
This logs every INFO_EVENT record and provides a SAMPLE_EVENT_BOOKMARK
event for the only INFO_EVENT we can parse so far, the TAG event.

Three bits in the flag value in that event structure are now used to
hold the tag type, and if a non-zero type has been set, then the value
is the heading in degress.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:10:54 -07:00
Linus Torvalds
cdfbe4092d Shearwater Petrel: make the hardware ID decoding a bit easier to read
Dirk seems to have some documentation about the different ID's, plus it
just makes sense to order the switch statement by number.

This is partly based on Dirk's original commit to do the different model
numbers, with various changes over time due to merge conflict
resolution.  Dirk's sign-off comes from Dirks commit in the original
subsurface branch.

As of firmware 11, Teric identifies as 0x1F0A.

Also, just like libdivecomputer upstream, don't assume that an unknown
model is a Petrel - that was a stupid thing to do and caused downloads
with the Teric to break.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Shearwater parser: add new harware model nr for Teric

As of firmware 11 at least my Teric identifies as 0x1F0A.
Also, just like libdivecomputer upstream, don't assume that an unknown
model is a Petrel - that was a stupid thing to do and caused downloads
with the Teric to break.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Linus Torvalds
cf6c0d6640 Cressi: mark Cartesio and Goa as supporting BLE
They don't actually have any native BLE capabilities, but there's a "HAL
9000" docking station with bluetooth capability (and a USB cable for
wired connectivity).

This will need more work, the BLE communication is packetized
differently from the regular serial one.  But I'm keeping this
difference from Jef's upstream for posterity.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Dirk Hohndel
6042aa8875 Mark Aqualung i750TC as Bluetooth capable
There is also an i300C that is Bluetooth capable, but I don't know if
that's the same model as the i300 or a different variation.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-05-07 15:05:37 -07:00
Linus Torvalds
680752bc0f i770R: parse tank pressure and water salinity like the i750tc
This needs to be checked.  I'm not sure why Jef has different code here,
but I'm keeping our Subsurface branch differences around.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Linus Torvalds
93597f1ed9 Oceanic: when encountering an unknown device, report the version string
This is purely to make things easier to debug when new devices show up.

The version string technically ends up being visible in the HEX dump of
the download too, but that's just not very convenient.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Dirk Hohndel
6b0cf9a9f3 Oceanic Atom2: add extended string information parsing
This adds the string field interface to the Oceanic Atom2 family,
including the proper serial number handling.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Dirk Hohndel
c5405cc0c2 Suunto D9 family: add extended information parsing
This adds the string field interface to the Suunto D9 family.

It's really just the proper serial number handling.  From Dirk's
original commit:

 "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"

so thus just serial number.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Dirk Hohndel
fb6cde0d17 Heinrichs Weikamp OSTC: add extended information parsing
This adds the string field interface to the HW OSTC family, including
the proper serial number handling.

The deco model information was done by Anton Lundin in the original
subsurface branch, and the salinity, serial number, battery voltage and
desat information was added by Dirk Hohndel.  Jan Mulder added the
battery percentage.

[ The sign-offs have been taken from the original commits in that old
  subsurface branch, and I'm marking Dirk as the main author because on
  the whole most of the lines come from him  - Linus ]

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Linus Torvalds
025fb5ed1a Add serial number to parser creation for ostc, atom2, shearwater and suunto d9
These backends want the serial number for reporting, and can't get it
any other way.

We really should re-organize this.  It's a nasty source of pointless
changes wrt upstream libdivecomputer, and I'm not convinced it's worth
the pain.

We also don't even have a consistent ordering for the arguments. Oh well.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Linus Torvalds
704ed3f1e4 Add back Mares BlueLink Pro bluetooth support tweaks
The Mares BlueLink Pro BLE dongle is the beast from hell, and introduces
lots of extra slowdowns into the Mares communication protocol.

In particular, it turns out that we really can't send the command bytes,
then wait for the ACK byte, and then send the command argument data as a
separate packet.  Because of the delays that the dongle adds, the dive
computer will have given up on the command arguments by the time it sees
them.

At the same time we don't want to always pass the command and arguments
as one single packet in all situations, because at least the Mares
Matrix really seems to want that "wait for ACK before sending
arguments".  See commit 59bfb0f3189b ("Add support for the Mares
Matrix") for details.

So introduce a new "splitcommand" flag, which is set by default, but
gets disabled for the BLE transport case.

Also, because bluetooth is slow, we don't want to ask for big packets of
data.  It seems to cause a buffer overflow on the BlueLink Pro when the
serial data from the dive computer arrives faster than the bluetooth
data can be sent to the downloading side.

So when using the BLE transport, we also limit the packet size to 128
bytes in addition to disabling the command splitting.

With this, I can download hundreds of kB of data from the Mares Quad Air
successfully over BLE.  It's *slow*, but it works.

This is a re-application of commit 5be8c17ea1 ("Mares bluetooth support
tweaks"), with small changes for how the libdivecomputer IO interfaces
have changed in the meantime.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Linus Torvalds
a1c408e8f4 Make custom iostream read/write wrapper more rebust
The dc_iostream_{read,write}() implementation had multiple issues:

 - it would return DC_STATUS_SUCCESS even if no iostream implementation
   existed.

   Yes, it would also return a zero "actual" bytes, but most backends
   don't even pass an "actual" pointer, so returning success was still
   completely insane.

   This one probably didn't matter, because all iostreams should have
   read and write members, but the return value was completely wrong if
   that ever were to happen.

 - If the user passed in a NULL 'actual' pointer, the wrapper would
   ignore that, and pass in its own pointer instead, in order to know
   how many bytes to print for the debug message.

   But that means that the low-level read/write functions cannot know
   whether the user actually is able to handle a partial read or not.

   This one _definitely_ matters, because some protocols need to have a
   buffer for the whole incoming packet, but packerts may not always be
   full-size. The low-level protocol needs to know whether to wait for
   further packets (in order to fill the buffer) or to just return the
   partial data.

This fixes these issues.  If the user passes in a NULL actual pointer
(indicating that it needs all-or-nothing and is not ready to handle a
partial success), just loop over the IO until the buffer is fully
exhausted.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Dirk Hohndel
b9657e4545 Atomics Cobalt: use the new DC string fields
Not a lot of fields, but give the serial number in the proper format,
and other version information (Software version and bootloader version).
And the Nofly time that the dive computer reports.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Linus Torvalds
62057c90bd Use the extended parsing facilities for the Suunto EON Steel backend
This takes advantage of the field cache and string interfaces, and
reports TTS with the new TTS sample.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Linus Torvalds
41f89f415e Suunto Eon Steel: sort the dive list properly
Instead of assuming that the dive list is presented in a sorted circular
list, sort it properly alphabetically (which also ends up being a
numerical sort for the HEX ascii dive names).

The "search for most recent dive, then splice the list around" case
doesn't work in the general case.  It happens to work if you don't
delete any dives, and dives only disappear as they are being overwritten
by new dives when the storage overflows.

But if you delete dives and then create new ones, the dive list will not
be sorted at all, and we should sort it properly when downloading.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Linus Torvalds
8594445088 Add support for the Deepblu Cosmiq+ dive computer
Somewhat basic support, but the data the Deepblu Cosmiq+ reports is
pretty basic.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Linus Torvalds
4e9e94d9f8 Add backend for Garmin Descent Mk1
This uses pretty much all of our new infrastructure: the USB storage
iostream for the actual IO, the field-cache for the divecomputer fields,
and the string interface for the events.

It's also a very fast downloader.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Linus Torvalds
99c2ca7205 Add 'usbstorage' iostream
This ends up being just a file interface for dive computers that expose
their data as a filesystem that can be mounted.

Right now that's only the Garmin Descent Mk1, although technically the
Uemis Zurich also did that (but oddly, and the backend was never merged
into libdivecomputer).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Linus Torvalds
cf104bb8de Extend on the event flag type with severity and types
The libdivecomputer sample flag field for events is fairly useless,
traditionally just having a "begin/end" bit.

This extends the flags field with a severity marker ("state", "info",
"warning", "alarm") so that subsurface can report the event with the
proper kind of notice (ie big red error marker for an alarm, but not
show divecomputer state changes by default, for example).

For Shearwater events we can also add the type of event ("interest",
"navpoint", "danger", "animal", "injury").

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Linus Torvalds
dc4b2e0592 Add string event sample type
A lot of dive computers have fairly arbitrary events that are not really
amenable to the simplistic static enumerated values that libdivecomputer
traditionally uses.

In fact, some dive computers (particularly the newer Suunto ones) very
explicitly report strings natively, with events literally being
described with a string like "Below Wet Activation Depth".

So instead of trying to turn these strings into one of the enumerated
values (and have the dive log software try to turn them back into some
random string when showing the user), just report the string itself.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Linus Torvalds
15c23eb7f6 Add time-to-surface sample type
This adds the ability to report time to surface (TTS) as a sample, which
a number of backends will want.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:37 -07:00
Linus Torvalds
af2249a7c5 Add generic field cache and string field infrastructure
This adds the infrastructure for the "field cache", which is just
various helpers for the dc_get_field() interface.

This includes the 'dc_field_cache_t' structure that a libdivecomputer
backend can just add to its parser data structure, and a few macros to
make it very easy to initialize the fields and then return them in the
'get_field()' callback.

And part of it is the infrastructure support for the 'dc_field_string_t'
type, which adds the support for string fields.  That will be used to
return various string-formatted data from the dive computer, like deco
models, serial numbers, etc.

And no, a serial number is most definitely not a "number". It's a string.

Right now there are no users of this yet, that comes next.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 15:05:30 -07:00
Linus Torvalds
086b0a799e Clean up 'dc_tankvolume_t' type and make it 'dc_tankinfo_t'
The dc_tankvolume_t type had information about metric vs imperial
volume, but we actually want other things too, like the actual usage of
the cylinder.

So rename it to 'dc_tankinfo_t' and extend the semantics from an
enumeration of volume units, to be a bitmap of information flags.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 12:36:23 -07:00
Linus Torvalds
06ca08ed2b Fix up .gitignore file
Add the build directory, and the dctool binary to the list of files to
be ignored.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 12:36:23 -07:00
Linus Torvalds
8ea51ad16e Update compiler flags and dc version suffic for Subsurface-NG
We have a slightly different set of flags for mthe subsurface build, and
we want the version to also say that this is our Subsurface-specific
branch of libdc, not the upstream one.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-05-07 11:49:34 -07:00
Jef Driesen
82f298febd Merge branch 'ostc3-fwupdate-improvements' 2020-03-24 18:48:56 +01:00
Jef Driesen
9e92381be4 Use a more robust command to write flash memory
The S_BLOCK_WRITE (0x30) command sends a stream of bytes to the dive
computer. Because the payload has no fixed length and there is no length
field included, the hwOS firmware detects the end of the stream by means
of a 400ms timeout. The main disadvantage of this approach is that a
short hiccup in the communication will be incorrectly detected as the
end of the stream.  Hence only a part of the data will get written to
the flash memory, and the remainder of the data will get interpreted as
the next commands.

To avoid this problem, the hwOS firmware v3.09 and later supports a new
S_BLOCK_WRITE2 (0x31) command, which uses a fixed size payload of 256
bytes.

Reported-by: Ralph Lembcke <mail@ralph-lembcke.de>
2020-03-24 18:32:13 +01:00
Jef Driesen
dff6d0c514 Read and cache the firmware version information
By reading the firmware version information immediately after entering
download or service mode, we can identify the specific firmware version
and adapt to minor differences in the communication protocol.
2020-03-24 18:32:13 +01:00
Jef Driesen
da4a8a90c7 Add an extra delay after writing to the flash memory
The S_BLOCK_WRITE (0x30) command sends a stream of bytes to the dive
computer. Because the payload has no fixed length and there is no length
field included, the hwOS firmware detects the end of the stream by means
of a 400ms timeout. Therefore the ready byte is always delayed by this
400ms timeout.

The same remark applies to the DISPLAY (0x6E) and CUSTOMTEXT (0x63)
commands. But because libdivecomputer always pad the text with zeros and
sends the maximum payload size, we won't hit the timeout.

Reported-by: Ralph Lembcke <mail@ralph-lembcke.de>
2020-03-24 18:32:13 +01:00
Jef Driesen
7b9b6b4005 Add an extra delay after erasing a flash memory page
Erasing a flash memory page is a relative slow operation and takes a
significant amount of time. Therefore, the ready byte is delayed, and
the standard timeout is no longer sufficient. Estimate the required
delay and wait.

Reported-by: Ralph Lembcke <mail@ralph-lembcke.de>
2020-03-24 18:32:13 +01:00
Jef Driesen
d1b865d192 Send the service init command one byte at a time
The hwOS firmware reads the service init command one byte at a time, and
sends the echo immediately after each byte.

Reported-by: Ralph Lembcke <mail@ralph-lembcke.de>
2020-03-24 18:32:13 +01:00
Ralph Lembcke
94cd864dba Fix some typos in the comments 2020-03-24 18:32:13 +01:00
Jef Driesen
ffa9e0aa3c Ignore excess bytes in the BLE version packet
For the Oceanic Pro Plus X and the Aqualung i770R, downloading over BLE
often fails because the version packet contains one or more unexpected
bytes.

For a successful download, the correct structure for the version packet
is as follows:

    5A 4F4345414E4F43582031432030303032 C6

That's the start byte, the payload "OCEANOCX 1C 0002" and the checksum.
For all the failed packets, there are one or more bytes extra present
between the payload and the checksum:

    5A 4F4345414E4F43582031432030303032 9F02 67
    5A 4F4345414E4F43582031432030303032 3603 FF
    5A 4F4345414E4F43582031432030303032 64   2A
    5A 4F4345414E4F43582031432030303032 9202 5A
    5A 4F4345414E4F43582031432030303032 08   CE
    5A 4F4345414E4F43582031432030303032 2C01 F3

The amount of extra bytes, and their content appears to be pretty
random. The strangest part is that the checksum of the packet is
actually correct and includes those extra bytes!

As workaround, accept extra bytes in the BLE packet, verify the checksum
as usual, and finally strip the excess bytes and only pass the actual
content to the next layer. To avoid false positives, the workaround is
limited to packets with a payload and checksum, and only enabled for the
two affected models.
2020-03-17 14:33:56 +01:00
Jef Driesen
8a1d32d319 Pass infinite NDL values to the application
When the last deco stop is cleared, the dive computer switches to NDL
mode with an infinite time (0x7FFF for APOS4 and 0xFFFF for APOS3). But
because libdivecomputer does not report those infinite values to the
application, detecting the end of the deco phase is not very intuitive.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

The change to uppercase is purely cosmetic. The string comparisions are
not case-sensitive. But for documentation purposes it's good practice to
list the exact name as reported by the device.
2019-09-11 08:51:00 +02:00
Jef Driesen
f801b512c3 Check condition before entering the loop
The condition doesn't change inside the loop, so there is no need to
check it every iteration.
2019-09-11 08:50:16 +02:00
Jef Driesen
912eb37ac3 Discard the cached BLE packet
When using a BLE connection, it's not sufficient to purge the buffers of
the underlying I/O stream. The locally cached BLE packet needs to be
discarded also.
2019-09-06 09:04:23 +02:00
Linus Torvalds
d62674a803 Add support for Aqualung i200c
It's exactly the same as the regular i200, but has a new version number
and string.

Tested-by: Tiago Thedim Dias <tiagotsoc@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-09-03 08:40:10 +02:00
Jef Driesen
d21070ad1a Merge branch 'ix3m-transmitter' 2019-09-02 08:27:21 +02:00
Jef Driesen
8829619473 Take the tank transmitter flags into account
Suppress the tank pressure sample when there is no active transmitter
available, or the connection with the transmitter is (temporary) lost.
In the latter case, the pressure is recorded as zero.
2019-09-02 08:26:38 +02:00
Jef Driesen
dc508c30f9 Add support for multiple tank transmitters
The Ratio dive computers support up to 10 tank pressure sensors. The ID
of the active tank sensor is stored in the sample data, and gets mapped
to the corresponding tank index.
2019-09-02 08:25:17 +02:00
Jef Driesen
1cd285a4d8 Use a struct for the gasmix and tank data
This small refactoring is mainly a preparation to support multiple
tanks. There is no functional change.
2019-08-27 14:01:50 +02:00
Janice McLaughlin
d5aa15c1c5 Add support for the Aqualung i550C 2019-07-08 08:49:14 +02:00
Jef Driesen
07dff48a3b Enable bluetooth support for the Ratio iX3M GPS 2019-07-05 11:39:06 +02:00
Jef Driesen
01d89add2f Update the naming of the Ratio iX3M GPS range 2019-07-05 11:39:06 +02:00
Jef Driesen
708fbb02de Mark the string tables as constant
Not only the strings in the table are constant, but also the table
itself. This allows the compiler to place the table in a read-only data
section.
2019-07-05 11:39:06 +02:00
Jef Driesen
209890daeb Refactor the filter functions
Replace all the different internal filter functions with one generic
function and a set of callback functions.
2019-07-05 11:37:13 +02:00
Janice McLaughlin
c70046bccf Fix the tank pressure reporting
A small typo introduced with the Tusa Talis support in commit
b188c414206daaa5b6de464ced98d78f6da7cde1 accidentally disabled the tank
pressure reporting for all models.
2019-06-27 08:55:45 +02:00
Jef Driesen
e80e320b8b Return the correct error code 2019-06-26 15:43:58 +02:00
Jef Driesen
334105322c Merge branch 'genius' 2019-06-26 15:43:36 +02:00
Jef Driesen
feec939a29 Add support for the Mares Genius
The Mares Genius supports a new command to download different types of
objects (e.g. dive header, dive profiles, etc) directly, without needing
to manually read and parse the contents of the flash memory.

The data structure also changed significantly. The profile data is now
organized into different records. Each record starts and ends with a 4
byte ascii marker:

  DSTR: Dive start record
  TISS: Tissue record
  DPRS: Sample record
  AIRS: Air integration record
  DEND: Dive end record

and contains a CRC checksum. The contents of the records remains very
similar to the existing iconhd data format.

Based-on-code-by: Janice McLaughlin <janice@moremobilesoftware.com>
2019-06-26 15:29:56 +02:00
Jef Driesen
a74d4ca14d Simplify the detection of air integrated models 2019-06-26 12:52:07 +02:00
Jef Driesen
7b29651d1e Refactor the gas mix and tank parsing 2019-06-26 12:51:53 +02:00
Jef Driesen
732c607c22 Refactor the date/time parsing
Split the offset calculation in two steps: first the offset to the
header data, and then the date/time field. The main advantage is that
the resulting code now follows the same logic as in the other functions.
2019-06-26 12:51:26 +02:00
Jef Driesen
e4c88a9309 Replace the header offset with the header size
The Mares Genius dive header is no longer located at the end of the data
(after the dive profile), but at the start. Therefore we don't need the
offset to the dive header anymore. Replace with the size of the header
instead.
2019-06-21 16:15:40 +02:00
Jef Driesen
6fb09e05a4 Use symbolic constants for the commands
The two byte commands are in fact a single byte command. The second byte
is some kind of checksum, containing the command byte xor'ed with the
value 0xA5.
2019-06-21 16:15:40 +02:00
Kristaps Dz
ca784be4e2 Add license information to the AES code
The license of the original source is stipulated in
https://github.com/kokke/tiny-AES-c/blob/master/unlicense.txt.
2019-06-21 16:13:27 +02:00
Jef Driesen
ddf086271c Update the udev rules 2019-06-18 09:24:43 +02:00
Jef Driesen
0dc10062ce Add support for the Suunto D5
The Suunto D5 is fully compatible with the Eon Steel, except for the
different USB PID.

Reported-By: Nick Shore <support@mac-dive.com>
2019-05-27 09:06:13 +02:00
Jef Driesen
b188c41420 Add support for the Tusa Talis
Reported-By: Nick Shore <support@mac-dive.com>
2019-05-27 09:06:13 +02:00
Jef Driesen
629e33432f Add the G2 HUD bluetooth device name 2019-05-27 09:06:13 +02:00
Jef Driesen
7b29c5d43d Detect Mares Quad with more flash memory
The latest variant of the Mares Quad has 4 times more flash memory
compared to the original variant (1M vs 256K). Therefore this variant
supports a new command to read the size of the flash memory.

At the moment, it's unknown whether the previous variant also supports
this new command or not. Probably not, because none of the other
compatible models seems to support it either. Hence we only attempt to
read the flash memory size for the Quad, and a failure is not considered
a fatal error. The disadvantage of this approach is that a temporary
communication problem can result in a misdetection of the flash memory
size.

Reported-by: Janice McLaughlin <janice@moremobilesoftware.com>
2019-05-27 08:54:27 +02:00
Janice McLaughlin
5c55760fd5 Fix the limit for an invalid sample temperature
In the EON Steel descriptor for the temperature field, the "nillable"
value is -3000:

   int16,precision=2,nillable=-3000

So the missing equals sign is just a small oversight.
2019-05-24 11:14:13 +02:00
Jef Driesen
05a21bc8ee Fix a buffer overflow
The length field in the data is checked for the maximum size (e.g. the
size of the buffer), but there is no such check on the minimum size
(e.g. the size of the header). If the length is smaller, the code
accessed data before the start of the buffer.
2019-05-10 16:02:01 +02:00
Jef Driesen
f37c3d3c86 Fix the ndl/deco sample for the Aqualung i450T 2019-04-24 16:23:11 +02:00
Jef Driesen
74957542bb Add support for the Scubapro G2 HUD
The G2 HUD is compatible with the G2, except for the new USB PID.
2019-04-23 10:00:08 +02:00
Jef Driesen
7d48587ed8 Add support for the Scubapro Aladin H Matrix
The Aladin H Matrix appears to be identical to the Aladin Sport Matrix.
2019-04-23 09:59:24 +02:00
Jef Driesen
019a98f80c Add support for the Mares Bluelink Pro interface
The main difference with the serial communication is that the BLE
communication uses data packets (with a maximum size of 20 bytes)
instead of a continuous data stream.

Occasionally, the device responds with an empty packet (with just the
ACK and EOF byte) or with a short packet where one or more payload bytes
are missing. The empty packet is most likely caused because the device
didn't receive the second part of the command (with the parameters) in
time. The missing bytes might be caused by a buffer overflow on the
Bluelink Pro, when the data from the dive computer arrives faster over
the serial link than the device can forward it over the slower bluetooth
link to the host system.

One way to address this problem is to lower the packet size from 256 bytes
to only 128 bytes. The main disadvantage is that this also impacts the
download speed considerably. In one particular example, the total
download time increased from about 135 to 210 seconds (which is already
slow compared to the 62 seconds the same download takes over usb)!

An alternative solution is to simply retry the failed command. That way
there is only a performance penalty for the few bad packets, and not for
every single packet. In the above example, only two packets needed a
retransmission.

Note that the iconhd communication protocol uses no checksums. Hence
it's not possible to detect corrupt data packets. Only short packets can
be detected, because they result in a timeout.
2019-04-14 19:55:14 +02:00
Jef Driesen
88a814a616 Check the correct vtable pointer 2019-04-14 11:25:12 +02:00
Jef Driesen
01ec0c0970 Merge branch 'suunto-dx' 2019-04-13 11:37:33 +02:00
Jef Driesen
6ee786c31a Report the setpoint data 2019-04-13 11:37:15 +02:00
Jef Driesen
8a70885f89 Take the CCR diluents into account
The Suunto DX supports 3 CCR diluents and 8 OC gas mixes. Since the gas
mix index in the data is relative to either the set of CCR diluents or
OC gas mixes (depending on the dive mode) and libdivecomputer reports
both sets, the index needs to be adjusted.
2019-04-13 11:37:06 +02:00
Jef Driesen
6867ffb143 Implement the initial gas mix
Initialize the initial gas mix correctly from the data in the dive
header, instead of always using the first gas mix.
2019-04-13 11:23:36 +02:00
Jef Driesen
5116ee8f2d Get the gas mix index directly from the event data
There is no need to lookup the gas mix index, because the number is
stored directly in the event data, right next to the oxygen and helium
values. This actually removes an ambiguity in cases where the user has
configured two or more identical gas mixes. In that case, the lookup
would always find the first gas mix.
2019-04-13 11:15:53 +02:00
Jef Driesen
530b28bf6f Ignore zero tank pressure values
When the connection with the transmitter is lost, the OSTC records a
zero value for the tank pressure.
2019-03-06 11:05:27 +01:00
Jef Driesen
2ea24cf043 Add filters for BLE communication
This is mainly for future use and reference, because there is still no
built-in support for BLE communication available.
2019-03-06 11:05:27 +01:00
Jef Driesen
f05f60c4ad Skip empty logbook entries
On certain devices, for example the Aeris Elite T3, the logbook
ringbuffer can sometimes contain an empty logbook entry in between the
valid entries. Because the presence of such an empty entry is currently
being interpreted as having reached the last valid entry, the download
is aborted. The result is that all remaining valid entries, located
after the empty entry, can't be downloaded.

This can be avoided by skipping the empty entry instead of aborting the
download.
2019-03-06 11:04:53 +01:00
Jef Driesen
81bca1ff7c Merge branch 'ratio' 2019-02-22 14:23:33 +01:00
Jef Driesen
4bbebe7c32 Add clock synchronization support
The Ratio dive computers support synchronizing the internal clock. One
complication is that recent firmware versions (4.0.56 or 4.1.10) support
two timezones (home and abroad), while the libdivecomputer api only
supports one timezone. To deal with this, the most recent firmware
versions (4.0.58 or 4.1.12) will interprete an invalid timezone index
(0xFF) as leaving the timezone unchanged.

If the firmware doesn't support the dual timezone command, or if the
firmware doesn't have the invalid timezone index modification yet, then
a fallback to the single timezone command is provided. Note that in the
latter case the side effect is that both timezones will be changed!
2019-02-22 14:21:51 +01:00
Jef Driesen
ec14ee2b77 Use symbolic constants for the commands 2019-02-22 14:21:51 +01:00
Jef Driesen
d876542d39 Don't pass a NULL pointer to memcpy
The memcpy and related functions expects a valid pointer, even if the
size is zero. Most libc implementations will handle a NULL pointer just
fine, but that's not guaranteed.

Simply skip the call when there is nothing to copy.
2019-02-22 14:21:51 +01:00
Jef Driesen
3287e3bd5d Update the list of the Ratio dive computers
There were quite a few models missing in the list. And because the
lowest iX3M model number has changed, the iX3M detection needed to be
updated as well.
2019-02-22 14:21:51 +01:00
Jef Driesen
2b96b2f52c Use the timezone setting of the dive computer
The Ratio dive computers with the latest APOS4 firmware support a
timezone setting. Take this timezone into account instead of using the
timezone of the host system.
2019-01-18 14:44:46 +01:00
Jef Driesen
e363e5b1fd Add support for the Cressi Goa and Cartesio 2019-01-14 21:14:30 +01:00
Jef Driesen
da2582237f Add an extra parameter for the initial CRC value
This allows to calculate different variants of the CRC-CCITT algorithm
with a single function.
2019-01-08 15:20:05 +01:00
Jef Driesen
4c93e14b0e Add support for the Ratio iDive Color series
The new iDive Color series uses the same communication protocol and data
format as the previous models.
2019-01-08 08:22:23 +01:00
Jef Driesen
179ec4688f Merge branch 'shearwater' 2018-12-21 10:44:50 +01:00
Jef Driesen
47bb08bbfd Shearwater Petrel Native Format parsing
This will allow parsing dives from the Shearwater Teric, but depending on the
firmware could also be used on older models.

Based on ideas and code from Dirk Hohndel
2018-12-20 13:45:32 +01:00
Dirk Hohndel
ae503626ae Shearwater: detect which logbook format is support
The Log Upload RDBI (Read Data by Identifier) response tells us which
format the dive computer supports.

Shearwater recommends to use the 'Petrel Native Format' for all dive
computers which support it, even those pre-Teric models which (depending
on firmware) might support both PNF and the older 'Predator-Like
Format'.

They also recommend to ignore the 0x90000000 format which is very
similar to PNF but without the final record and to use the older
Predator Like Format in that case.

The 0xDD000000 format is never an option by the time you got here, but
in the old code (prior to the PNF addition) we would have fallen back to
0xC0000000, so let's do the same here.

Any other value is actually an unknown format and should be treated as
such.

Which format we use is determined by the base address used to download
the logbook entries.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-12-20 13:45:32 +01:00
Dirk Hohndel
472e73118d Shearwater: add Teric to list of supported dive computers
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-12-20 13:45:32 +01:00
Dirk Hohndel
864b40cb3d Shearwater: skip deleted dives
Without this change a deleted dive on device is treated like the end of the
dive list.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-12-20 13:45:32 +01:00
Jef Driesen
0b2959d8c7 Fix a potential buffer overflow
Check whether there is space available for a complete sample, and not
just a single byte!
2018-12-18 08:57:54 +01:00
Jef Driesen
c622998fb1 Fix the Cobalt 2 memory size
The Cobalt 2 has a bit more flash memory available for storing dives
compared to the original Cobalt 1. This larger amount of memory can
cause the progress events to exceed past 100% if there are many dives
present. This will trigger the assert in the event code and crash the
application.
2018-12-17 16:44:48 +01:00
Jef Driesen
0d3d34a5c9 Use the travis homebrew plugin to install packages 2018-12-06 11:42:47 +01:00
Jef Driesen
ab522a4a52 Increase the internal log buffer
The Atomic Aquatics Cobalt backend uses 8K data packets. Since a hexdump
of such a data packet needs at least twice the size of the binary data,
the internal log buffer should be increased to 16K bytes.
2018-12-06 08:34:29 +01:00
Jef Driesen
ed21d776dd Fix undefined behaviour in left shifts
Due to the integer promotion rules of the C language, the unsigned char
values are promoted to a signed integer (and not an unsigned integer)
before being shifted. But the result of a left shift on a signed type is
undefined if the resulting value can't be represented in the signed
type.

GCC's Undefined Behavior Sanitizer (ubsan), enabled with the option
-fsanitize=undefined, detects this type of problem at runtime with the
following warning: "left shift of X by Y places cannot be represented in
type 'int'".

Fixed with an explicit cast to unsigned integer.
2018-12-05 10:21:09 +01:00
Jef Driesen
43303eadf6 Add support for the Aqualung i300C 2018-11-28 16:34:50 +01:00
Janice McLaughlin
52388efe59 Add support for the Aqualung i770R
It appears that the Aqualung i770R looks almost the same as the Pro Plus
X, but has an additional pO2 field for each gas by the O2 field, which
impacts the offset calculations.
2018-11-28 16:34:50 +01:00
Janice McLaughlin
f5d636d12e Fix the Pro Plus X gas mixes 2018-11-28 16:34:50 +01:00
Janice McLaughlin
04c367fd06 Oceanic: fix up dive truncation issues
This fixes the dive truncation that happened with long dives due to the
removal of extra padding (commit a2100843b9cf: "Remove extra padding
from the end of the profile").  It turns out the rest of the profile was
in bits 13-15 (with bit 12 being something else).
2018-11-28 16:34:50 +01:00
Linus Torvalds
e04a7fb33d Scubapro G2: update BLE downloading for new 1.4 firmware version
The packetization format for the BLE communication used to be that the
first byte of the BLE GATT payload was the size of the payload (1-19
bytes).

That seems to no longer be true as of fw version 1.4.  It is still the
size of the payload for the simple small reply packets, but for the long
data stream it ends up being an odd sequence of 13 different values that
are almost - but not quite - 19 apart.

Whatever.  Modify our strict "length byte must make sense" rule to be
more of a guidline than a hard rule.  This makes the download succeed
again.

Very weird.

Reported-by: Adric Norris <landstander668@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-11-28 16:34:19 +01:00
Jef Driesen
24f800d185 Add a workaround for invalid ringbuffer begin pointers
Unfortunately there are several devices with an invalid ringbuffer begin
pointer. In such cases, the strict validation of the pointer causes the
download to fail, without being able to download any dives at all.

Since the begin pointer is only needed to detect the start of the oldest
dive, we can fall back to downloading the entire profile ringbuffer.
Usually we can still detect the start of the oldest dive in some other
(indirect) way. For example when reaching past the end of the
ringbuffer, or the presence of invalid pointers in the linked list
structure. The result is that, we'll be able to download at least some
dives before hitting some other error.
2018-11-11 20:55:38 +01:00
Jef Driesen
6e87c1d7b7 Fix the RTS signal handling for Pelagic interface
The RTS signal needs to be low before it is raised, and not just set.
This ensures that the PIC inside the Pelagic PC interface is reset and
the initialization sequence always starts cleanly, regardless of the
previous state of the signal.

Reported-By: Bill Perry <bperrybap@opensource.billsworld.billandterrie.com>
2018-10-02 20:40:27 +02:00
Jef Driesen
96949627aa Fix a memory leak in the error handling 2018-10-02 20:40:27 +02:00
Janice McLaughlin
a2100843b9 Remove extra padding from the end of the profile
Even after removing the pages padded with 0xFF bytes, there are still
some invalid sample pages present at the end of the profile. But it
turns out the number of valid profile pages is stored in the logbook
entry.

The only caveat is that the number of pages appears to be stored as a 12
bit number, which limits the total profile size to only 64Kb. We don't
known what happens for larger dives.
2018-09-30 09:54:18 +02:00
Jef Driesen
e968f84999 Add support for the Aqualung i100 2018-09-24 10:11:42 +02:00
Jef Driesen
884f66a115 Fix the Mares Smart Apnea min/max temperature
The minimum and maximum temperature were mixed up.

Reported-By: Peter Balck <pbalck@gmail.com>
2018-09-07 10:23:17 +02:00
Jef Driesen
b1d434f0ea Fix the libusb and hidapi includes
The libusb and hidapi pkg-config files already add the subdirectory to
the header search path with:

   -I/usr/include/libusb-1.0
   -I/usr/include/hidapi

Therefore, using the subdirectory in the include statement is wrong. In
practice, this usualy works fine by accident, because the base directory
(/usr/include) is typically listed in the default search path of the
compiler. But that's not always true. For example when cross-compiling
or when using the PKG_CONFIG_LIBDIR environment variable.
2018-08-31 15:05:37 +02:00
246 changed files with 25098 additions and 5304 deletions

173
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,173 @@
name: Build
on: [push, pull_request]
jobs:
linux:
name: Linux
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
compiler: [gcc, clang]
env:
CC: ${{ matrix.compiler }}
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: sudo apt-get install libbluetooth-dev libusb-1.0-0-dev
- run: autoreconf --install --force
- run: ./configure --prefix=/usr
- run: make
- run: make distcheck
- name: Package artifacts
run: |
make install DESTDIR=$PWD/artifacts
tar -czf ${{ github.job }}-${{ matrix.compiler }}.tar.gz -C artifacts usr
- uses: actions/upload-artifact@v3
with:
name: ${{ github.job }}-${{ matrix.compiler }}
path: ${{ github.job }}-${{ matrix.compiler }}.tar.gz
mac:
name: Mac
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
compiler: [gcc, clang]
env:
CC: ${{ matrix.compiler }}
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: brew install autoconf automake libtool hidapi libusb
- run: autoreconf --install --force
- run: ./configure --prefix=/usr
- run: make
- run: make distcheck
- name: Package artifacts
run: |
make install DESTDIR=$PWD/artifacts
tar -czf ${{ github.job }}-${{ matrix.compiler }}.tar.gz -C artifacts usr
- uses: actions/upload-artifact@v3
with:
name: ${{ github.job }}-${{ matrix.compiler }}
path: ${{ github.job }}-${{ matrix.compiler }}.tar.gz
windows:
name: Windows
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
arch: [i686, x86_64]
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: sudo apt-get install gcc-mingw-w64 binutils-mingw-w64 mingw-w64-tools
- name: Install libusb
env:
LIBUSB_VERSION: 1.0.26
run: |
wget -c https://github.com/libusb/libusb/archive/refs/tags/v${LIBUSB_VERSION}.tar.gz
tar xzf v${LIBUSB_VERSION}.tar.gz
pushd libusb-${LIBUSB_VERSION}
autoreconf --install --force
./configure --host=${{ matrix.arch }}-w64-mingw32 --prefix=/usr
make
make install DESTDIR=$PWD/../artifacts
popd
- name: Install hidapi
env:
HIDAPI_VERSION: 0.12.0
run: |
wget -c https://github.com/libusb/hidapi/archive/refs/tags/hidapi-${HIDAPI_VERSION}.tar.gz
tar xzf hidapi-${HIDAPI_VERSION}.tar.gz
pushd hidapi-hidapi-${HIDAPI_VERSION}
autoreconf --install --force
./configure --host=${{ matrix.arch }}-w64-mingw32 --prefix=/usr LDFLAGS='-static-libgcc'
make
make install DESTDIR=$PWD/../artifacts
popd
- run: autoreconf --install --force
- run: ./configure --host=${{ matrix.arch }}-w64-mingw32 --prefix=/usr
env:
PKG_CONFIG_LIBDIR: ${{ github.workspace }}/artifacts/usr/lib/pkgconfig
PKG_CONFIG_SYSROOT_DIR: ${{ github.workspace }}/artifacts
PKG_CONFIG_ALLOW_SYSTEM_CFLAGS: 1
PKG_CONFIG_ALLOW_SYSTEM_LIBS: 1
- run: make
- run: make distcheck
- name: Package artifacts
run: |
make install DESTDIR=$PWD/artifacts
tar -czf ${{ github.job }}-${{ matrix.arch }}.tar.gz -C artifacts usr
- uses: actions/upload-artifact@v3
with:
name: ${{ github.job }}-${{ matrix.arch }}
path: ${{ github.job }}-${{ matrix.arch }}.tar.gz
# msvc:
#
# name: Visual Studio
#
# runs-on: windows-latest
#
# strategy:
# fail-fast: false
# matrix:
# platform: [x86, x64]
#
# env:
# CONFIGURATION: Release
#
# steps:
# - uses: actions/checkout@v3
# - uses: msys2/setup-msys2@v2
# with:
# install: autoconf automake libtool pkg-config make gcc
# - run: |
# autoreconf --install --force
# ./configure --prefix=/usr
# make -C src revision.h
# shell: msys2 {0}
# - uses: microsoft/setup-msbuild@v1
# - run: msbuild -m -p:Platform=${{ matrix.platform }} -p:Configuration=${{ env.CONFIGURATION }} contrib/msvc/libdivecomputer.vcxproj
# - uses: actions/upload-artifact@v3
# with:
# name: ${{ github.job }}-${{ matrix.platform }}
# path: contrib/msvc/${{ matrix.platform }}/${{ env.CONFIGURATION }}/bin
android:
name: Android
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: |
autoreconf --install --force
./configure --prefix=/usr
make -C src revision.h
- run: $ANDROID_NDK/ndk-build -C contrib/android NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk
- uses: actions/upload-artifact@v3
with:
name: ${{ github.job }}
path: contrib/android/libs

47
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,47 @@
name: Release
on:
push:
tags: 'v*'
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Version number
id: version
run: |
VERSION="${GITHUB_REF/refs\/tags\/v/}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Build distribution tarball
id: build
run: |
sudo apt-get install libbluetooth-dev libusb-1.0-0-dev
autoreconf --install --force
./configure
make
make distcheck
- name: Check tarball version number
id: check
run: |
FILENAME="libdivecomputer-${{ steps.version.outputs.version }}.tar.gz"
if [ ! -f "${FILENAME}" ]; then
echo ::error ::Tarball \'${FILENAME}\' not found!
exit 1
fi
- name: Create Github release
id: release
run: |
VERSION="${{ steps.version.outputs.version }}"
if [ "${VERSION}" != "${VERSION%%-*}" ]; then
PRERELEASE="-p"
fi
gh release create ${PRERELEASE} "${{ github.ref }}" "libdivecomputer-${VERSION}.tar.gz"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

32
.gitignore vendored
View File

@ -37,32 +37,7 @@ Makefile.in
/doc/html/ /doc/html/
/doc/latex/ /doc/latex/
/examples/aladin /examples/dctool
/examples/atom2
/examples/d9
/examples/darwin
/examples/edy
/examples/eon
/examples/frog
/examples/iconhd
/examples/leonardo
/examples/memomouse
/examples/n2ition3
/examples/nemo
/examples/ostc
/examples/ostc-fwupdate
/examples/predator
/examples/puck
/examples/sensus
/examples/sensuspro
/examples/sensusultra
/examples/smart
/examples/solution
/examples/universal
/examples/veo250
/examples/vtpro
/examples/vyper
/examples/vyper2
/include/libdivecomputer/version.h /include/libdivecomputer/version.h
@ -72,11 +47,10 @@ Makefile.in
/m4/ltsugar.m4 /m4/ltsugar.m4
/m4/ltversion.m4 /m4/ltversion.m4
/msvc/Debug/ /msvc/x64/
/msvc/Release/ /msvc/x86/
/msvc/*.ncb /msvc/*.ncb
/msvc/*.suo /msvc/*.suo
/msvc/*.vcproj.*.user
/src/libdivecomputer.exp /src/libdivecomputer.exp
/src/libdivecomputer.la /src/libdivecomputer.la

View File

@ -37,11 +37,10 @@ addons:
packages: packages:
- libbluetooth-dev - libbluetooth-dev
- libusb-1.0-0-dev - libusb-1.0-0-dev
homebrew:
install: packages:
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then - hidapi
brew install hidapi libusb; - libusb
fi
script: script:
- case $CC in - case $CC in

View File

@ -16,4 +16,8 @@ pkgconfig_DATA = libdivecomputer.pc
EXTRA_DIST = \ EXTRA_DIST = \
libdivecomputer.pc.in \ libdivecomputer.pc.in \
msvc/libdivecomputer.vcproj contrib/README \
contrib/android/Android.mk \
contrib/msvc/libdivecomputer.vcxproj \
contrib/msvc/libdivecomputer.vcxproj.filters \
contrib/udev/libdivecomputer.rules

74
NEWS
View File

@ -1,3 +1,77 @@
Version 0.8.0 (2023-05-11)
==========================
The v0.8.0 release is mainly a bugfix release, and brings in support for a
number of new devices. This release is fully backwards compatible with the
previous one.
New features:
* Add support for new backends:
- excursion: Deep Six Excursion, Crest CR-4, Genesis Centauri, Tusa TC1, Scorpena Alpha
- screen: Seac Screen and Action
- cosmiq: Deepblu Cosmiq+
- s1: Oceans S1
- freedom: Divesoft Freedom and Liberty
* Add support for some new devices:
- Aqualung: i200C
- Cressi: Donatello, Michelangelo, Neon
- Mares: Puck Pro +
- Oceanic: Geo Air
- Ratio: iX3M 2
- Scubapro: G2 TEK
- Shearwater: Petrel 3, Perdix 2
- Sherwood: Amphos Air 2.0
* Add support for parsing the decompression model
* Add a public api to configure the depth calibration
* Add a public api to configure the clock synchronization
* Add a basic Android build system
Removed/changed features:
* Migrate to Visual Studio 2013 (or newer)
* Move the Visual Studio project to the contrib directory
Version 0.7.0 (2021-05-07)
==========================
The main highlight of the v0.7.0 release is the introduction of the new
I/O interface. With this common interface, the dive computer backends
can more easily use different I/O implementations at runtime, including
an application defined one. This is needed to support Bluetooth Low
Energy (BLE), for which there is no built-in implementation available.
Due to the fundamental changes to the I/O layer, this release is not
backwards compatible.
New features:
* A new I/O interface
* Add support for new backends:
- goa: Cressi Goa and Cartesio
- divecomputereu: Tecdiving DiveComputer.eu
- extreme: McLean Extreme
- lynx: Liquivision Xen, Xeo, Lynx and Kaon
- sp2: Sporasub SP2
* Add support for many new devices:
- Aqualung: i100, i200C, i300C, i470TC, i550C, i770R
- Heinrichs Weikamp: OSTC 2 TR
- Mares: Genius, Horizon, Quad Air, Smart Air
- Oceanic: Geo 4.0, Pro Plus 4, Pro Plus X, Veo 4.0
- Ratio: iDive Color, iX3M GPS, iX3M 2021
- Scubapro: A1, A2, Aladin H Matrix, G2 Console, G2 HUD
- Seac: Guru, Jack
- Shearwater: Peregrine, Teric
- Sherwood: Amphos 2.0, Beacon, Sage, Wisdom 4
- Suunto: D5, EON Steel Black
- Tusa: Talis
* Firmware upgrade support for the Ratio computers
* Support for semi-closed circuit diving
Removed/changed features:
* Unify the Uwatec Smart, Meridian and G2 backends
Version 0.6.0 (2017-11-24) Version 0.6.0 (2017-11-24)
========================== ==========================

View File

@ -1,6 +1,6 @@
# Versioning. # Versioning.
m4_define([dc_version_major],[0]) m4_define([dc_version_major],[0])
m4_define([dc_version_minor],[7]) m4_define([dc_version_minor],[9])
m4_define([dc_version_micro],[0]) m4_define([dc_version_micro],[0])
m4_define([dc_version_suffix],[devel-Subsurface-NG]) m4_define([dc_version_suffix],[devel-Subsurface-NG])
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]))
@ -72,18 +72,21 @@ AM_CONDITIONAL([HAVE_MANDOC],[test -n "$MANDOC"])
# Enable automake silent build rules. # Enable automake silent build rules.
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
# Checks for native Windows. # Checks for operating system.
AC_MSG_CHECKING([for native Win32]) AC_MSG_CHECKING([for operating system])
case "$host" in case "$host" in
*-*-mingw*) *-*-mingw*)
os_win32=yes platform=windows
;;
*-*-darwin*)
platform=mac
;; ;;
*) *)
os_win32=no platform=default
;; ;;
esac esac
AC_MSG_RESULT([$os_win32]) AC_MSG_RESULT([$platform])
AM_CONDITIONAL([OS_WIN32], [test "$os_win32" = "yes"]) AM_CONDITIONAL([OS_WIN32], [test "$platform" = "windows"])
DEPENDENCIES="" DEPENDENCIES=""
@ -100,16 +103,29 @@ AS_IF([test "x$with_libusb" != "xno"], [
]) ])
]) ])
# Checks for MTP support.
AC_ARG_WITH([libmtp],
[AS_HELP_STRING([--without-libmtp],
[Build without the libmtp library])],
[], [with_libmtp=auto])
AS_IF([test "x$with_libmtp" != "xno"], [
PKG_CHECK_MODULES([LIBMTP], [libmtp], [have_libmtp=yes], [have_libmtp=no])
AS_IF([test "x$have_libmtp" = "xyes"], [
AC_DEFINE([HAVE_LIBMTP], [1], [libmtp library])
DEPENDENCIES="$DEPENDENCIES libmtp"
])
])
# Checks for HIDAPI support. # Checks for HIDAPI support.
AC_ARG_WITH([hidapi], AC_ARG_WITH([hidapi],
[AS_HELP_STRING([--without-hidapi], [AS_HELP_STRING([--without-hidapi],
[Build without the hidapi library])], [Build without the hidapi library])],
[], [with_hidapi=auto]) [], [with_hidapi=hidapi])
AS_IF([test "x$with_hidapi" != "xno"], [ AS_IF([test "x$with_hidapi" != "xno"], [
PKG_CHECK_MODULES([HIDAPI], [hidapi], [have_hidapi=yes], [have_hidapi=no]) PKG_CHECK_MODULES([HIDAPI], [$with_hidapi], [have_hidapi=yes], [have_hidapi=no])
AS_IF([test "x$have_hidapi" = "xyes"], [ AS_IF([test "x$have_hidapi" = "xyes"], [
AC_DEFINE([HAVE_HIDAPI], [1], [hidapi library]) AC_DEFINE([HAVE_HIDAPI], [1], [hidapi library])
DEPENDENCIES="$DEPENDENCIES hidapi" DEPENDENCIES="$DEPENDENCIES $with_hidapi"
]) ])
]) ])
@ -154,7 +170,7 @@ AC_CHECK_HEADERS([sys/socket.h linux/types.h linux/irda.h], , , [
# Checks for header files. # Checks for header files.
AC_CHECK_HEADERS([linux/serial.h]) AC_CHECK_HEADERS([linux/serial.h])
AC_CHECK_HEADERS([IOKit/serial/ioss.h]) AC_CHECK_HEADERS([IOKit/serial/ioss.h])
AC_CHECK_HEADERS([getopt.h]) AC_CHECK_HEADERS([unistd.h getopt.h])
AC_CHECK_HEADERS([sys/param.h]) AC_CHECK_HEADERS([sys/param.h])
AC_CHECK_HEADERS([pthread.h]) AC_CHECK_HEADERS([pthread.h])
AC_CHECK_HEADERS([mach/mach_time.h]) AC_CHECK_HEADERS([mach/mach_time.h])
@ -174,6 +190,7 @@ AC_CHECK_FUNCS([clock_gettime mach_absolute_time])
AC_CHECK_FUNCS([getopt_long]) AC_CHECK_FUNCS([getopt_long])
# Checks for supported compiler options. # Checks for supported compiler options.
AX_APPEND_COMPILE_FLAGS([-Werror=unknown-warning-option],[ERROR_CFLAGS])
AX_APPEND_COMPILE_FLAGS([ \ AX_APPEND_COMPILE_FLAGS([ \
-Wall \ -Wall \
-Wshadow \ -Wshadow \
@ -190,10 +207,13 @@ AX_APPEND_COMPILE_FLAGS([ \
-Wno-unused-but-set-variable \ -Wno-unused-but-set-variable \
-Wno-pointer-sign \ -Wno-pointer-sign \
-Wno-shadow \ -Wno-shadow \
]) -Wenum-conversion \
-Werror=enum-conversion \
-fmacro-prefix-map='$(top_srcdir)/'= \
],,[$ERROR_CFLAGS])
# Windows specific compiler options. # Windows specific compiler options.
AS_IF([test "$os_win32" = "yes"], [ AS_IF([test "$platform" = "windows"], [
AX_APPEND_COMPILE_FLAGS([-Wno-pedantic-ms-format]) AX_APPEND_COMPILE_FLAGS([-Wno-pedantic-ms-format])
]) ])
@ -209,6 +229,25 @@ m4_ifset([dc_version_suffix],[
AC_DEFINE(HAVE_VERSION_SUFFIX, [1], [Define if a version suffix is present.]) AC_DEFINE(HAVE_VERSION_SUFFIX, [1], [Define if a version suffix is present.])
]) ])
# Supported transports
transport_serial="yes"
transport_usb="${have_libusb-no}"
if test "$have_hidapi" = "yes"; then
transport_usbhid="yes"
elif test "$have_libusb" = "yes" && test "$platform" != "mac"; then
transport_usbhid="yes"
else
transport_usbhid="no"
fi
if test "$platform" = "windows"; then
transport_irda="$ac_cv_header_af_irda_h"
transport_bluetooth="$ac_cv_header_ws2bth_h"
else
transport_irda="$ac_cv_header_linux_irda_h"
transport_bluetooth="${have_bluez-no}"
fi
transport_ble="no"
AC_CONFIG_FILES([ AC_CONFIG_FILES([
libdivecomputer.pc libdivecomputer.pc
Makefile Makefile
@ -216,10 +255,41 @@ AC_CONFIG_FILES([
include/libdivecomputer/Makefile include/libdivecomputer/Makefile
include/libdivecomputer/version.h include/libdivecomputer/version.h
src/Makefile src/Makefile
src/libdivecomputer.rc
doc/Makefile doc/Makefile
doc/doxygen.cfg doc/doxygen.cfg
doc/man/Makefile doc/man/Makefile
examples/Makefile examples/Makefile
]) ])
AC_OUTPUT AC_OUTPUT
AC_MSG_NOTICE([
$PACKAGE $VERSION
===============
Compiler:
CC : $CC
CFLAGS : $CFLAGS
LDFLAGS : $LDFLAGS
Features:
Logging : $enable_logging
Pseudo terminal : $enable_pty
Example applications : $enable_examples
Documentation : $enable_doc
Transports:
Serial : $transport_serial
USB : $transport_usb
USBHID : $transport_usbhid
IrDA : $transport_irda
Bluetooth : $transport_bluetooth
BLE : $transport_ble
Building:
Type 'make' to compile $PACKAGE.
Type 'make install' to install $PACKAGE.
])

56
contrib/README Normal file
View File

@ -0,0 +1,56 @@
Alternative build systems
=========================
The autotools based build system is the official build system for the
libdivecomputer project. But for convenience, a few alternative build systems
are available as well. Unfortunately, these builds systems require a few extra
steps to generate some header files.
If you have access to a UNIX build system (for example a Linux virtual machine,
MinGW, Cygwin or the Windows Subsystem for Linux), you can use the autotools
build system to generate those files:
$ autoreconf --install --force
$ ./configure
$ make -C src revision.h
Alternative, you can generate those files manually. First, create the version.h
file from the version.h.in template:
$ cp include/libdivecomputer/version.h.in include/libdivecomputer/version.h
and replace all the @DC_VERSION@ placeholders with the values defined in the
configure.ac file.
Next, generate the revision.h file:
$ echo "#define DC_VERSION_REVISION \"$(git rev-parse --verify HEAD)\"" > src/revision.h
The alternative build systems are ready to use now.
Visual Studio
-------------
The Visual Studio project file can be opened in the IDE, or build directly from
the command-line:
msbuild -m -p:Platform=x86|x64 -p:Configuration=Debug|Release contrib/msvc/libdivecomputer.vcxproj
Android NDK
-----------
$ANDROID_NDK/ndk-build -C contrib/android NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=Android.mk
Linux udev rules
================
For dive computers using USB or USB HID communication, regular users typically
don't have the necessary permissions to access the device nodes. This can be
fixed with some udev rules.
Install the udev rules, and reload them:
$ sudo cp contrib/udev/libdivecomputer.rules /etc/udev/rules.d/
$ sudo udevadm control --reload
Note: the provided udev rules assume the user is in the plugdev group.

148
contrib/android/Android.mk Normal file
View File

@ -0,0 +1,148 @@
LOCAL_PATH := $(call my-dir)/../..
include $(CLEAR_VARS)
LOCAL_MODULE := libdivecomputer
LOCAL_CFLAGS := -DENABLE_LOGGING -DHAVE_VERSION_SUFFIX -DHAVE_PTHREAD_H -DHAVE_STRERROR_R -DHAVE_CLOCK_GETTIME -DHAVE_LOCALTIME_R -DHAVE_GMTIME_R -DHAVE_TIMEGM -DHAVE_STRUCT_TM_TM_GMTOFF
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_SRC_FILES := \
src/aes.c \
src/array.c \
src/atomics_cobalt.c \
src/atomics_cobalt_parser.c \
src/bluetooth.c \
src/buffer.c \
src/checksum.c \
src/citizen_aqualand.c \
src/citizen_aqualand_parser.c \
src/cochran_commander.c \
src/cochran_commander_parser.c \
src/common.c \
src/context.c \
src/cressi_edy.c \
src/cressi_edy_parser.c \
src/cressi_goa.c \
src/cressi_goa_parser.c \
src/cressi_leonardo.c \
src/cressi_leonardo_parser.c \
src/custom.c \
src/datetime.c \
src/deepblu_cosmiq.c \
src/deepblu_cosmiq_parser.c \
src/deepsix_excursion.c \
src/deepsix_excursion_parser.c \
src/descriptor.c \
src/device.c \
src/diverite_nitekq.c \
src/diverite_nitekq_parser.c \
src/divesoft_freedom.c \
src/divesoft_freedom_parser.c \
src/divesystem_idive.c \
src/divesystem_idive_parser.c \
src/hdlc.c \
src/hw_frog.c \
src/hw_ostc3.c \
src/hw_ostc.c \
src/hw_ostc_parser.c \
src/ihex.c \
src/iostream.c \
src/irda.c \
src/iterator.c \
src/liquivision_lynx.c \
src/liquivision_lynx_parser.c \
src/mares_common.c \
src/mares_darwin.c \
src/mares_darwin_parser.c \
src/mares_iconhd.c \
src/mares_iconhd_parser.c \
src/mares_nemo.c \
src/mares_nemo_parser.c \
src/mares_puck.c \
src/mclean_extreme.c \
src/mclean_extreme_parser.c \
src/oceanic_atom2.c \
src/oceanic_atom2_parser.c \
src/oceanic_common.c \
src/oceanic_veo250.c \
src/oceanic_veo250_parser.c \
src/oceanic_vtpro.c \
src/oceanic_vtpro_parser.c \
src/oceans_s1.c \
src/oceans_s1_common.c \
src/oceans_s1_parser.c \
src/packet.c \
src/parser.c \
src/pelagic_i330r.c \
src/platform.c \
src/rbstream.c \
src/reefnet_sensus.c \
src/reefnet_sensus_parser.c \
src/reefnet_sensuspro.c \
src/reefnet_sensuspro_parser.c \
src/reefnet_sensusultra.c \
src/reefnet_sensusultra_parser.c \
src/ringbuffer.c \
src/seac_screen.c \
src/seac_screen_parser.c \
src/serial_posix.c \
src/shearwater_common.c \
src/shearwater_petrel.c \
src/shearwater_predator.c \
src/shearwater_predator_parser.c \
src/socket.c \
src/sporasub_sp2.c \
src/sporasub_sp2_parser.c \
src/suunto_common2.c \
src/suunto_common.c \
src/suunto_d9.c \
src/suunto_d9_parser.c \
src/suunto_eon.c \
src/suunto_eon_parser.c \
src/suunto_eonsteel.c \
src/suunto_eonsteel_parser.c \
src/suunto_solution.c \
src/suunto_solution_parser.c \
src/suunto_vyper2.c \
src/suunto_vyper.c \
src/suunto_vyper_parser.c \
src/tecdiving_divecomputereu.c \
src/tecdiving_divecomputereu_parser.c \
src/timer.c \
src/usb.c \
src/usbhid.c \
src/uwatec_aladin.c \
src/uwatec_memomouse.c \
src/uwatec_memomouse_parser.c \
src/uwatec_smart.c \
src/uwatec_smart_parser.c \
src/version.c \
src/zeagle_n2ition3.c \
src/field-cache.c \
src/usb_storage.c \
src/garmin.c \
src/garmin_parser.c
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := dctool
LOCAL_SHARED_LIBRARIES := libdivecomputer
LOCAL_CFLAGS := -DHAVE_UNISTD_H -DHAVE_GETOPT_H -DHAVE_GETOPT_LONG -DHAVE_DECL_OPTRESET=1
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_SRC_FILES := \
examples/common.c \
examples/dctool.c \
examples/dctool_download.c \
examples/dctool_dump.c \
examples/dctool_fwupdate.c \
examples/dctool_help.c \
examples/dctool_list.c \
examples/dctool_parse.c \
examples/dctool_read.c \
examples/dctool_scan.c \
examples/dctool_timesync.c \
examples/dctool_version.c \
examples/dctool_write.c \
examples/output.c \
examples/output_raw.c \
examples/output_xml.c \
examples/utils.c
include $(BUILD_EXECUTABLE)

View File

@ -0,0 +1,408 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{CEA7215A-D6B5-4840-8086-3C854F371997}</ProjectGuid>
<RootNamespace>libdivecomputer</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)$(PlatformTarget)\$(Configuration)\bin\</OutDir>
<IntDir>$(PlatformTarget)\$(Configuration)\obj\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)$(PlatformTarget)\$(Configuration)\bin\</OutDir>
<IntDir>$(PlatformTarget)\$(Configuration)\obj\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)$(PlatformTarget)\$(Configuration)\bin\</OutDir>
<IntDir>$(PlatformTarget)\$(Configuration)\obj\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)$(PlatformTarget)\$(Configuration)\bin\</OutDir>
<IntDir>$(PlatformTarget)\$(Configuration)\obj\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBDIVECOMPUTER_EXPORTS;ENABLE_LOGGING;HAVE_VERSION_SUFFIX;HAVE_AF_IRDA_H;HAVE_WS2BTH_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>$(OutDir)libdivecomputer.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
</Link>
<ResourceCompile>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBDIVECOMPUTER_EXPORTS;ENABLE_LOGGING;HAVE_VERSION_SUFFIX;HAVE_AF_IRDA_H;HAVE_WS2BTH_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>$(OutDir)libdivecomputer.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
</Link>
<ResourceCompile>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBDIVECOMPUTER_EXPORTS;ENABLE_LOGGING;HAVE_VERSION_SUFFIX;HAVE_AF_IRDA_H;HAVE_WS2BTH_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>$(OutDir)libdivecomputer.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
</Link>
<ResourceCompile>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBDIVECOMPUTER_EXPORTS;ENABLE_LOGGING;HAVE_VERSION_SUFFIX;HAVE_AF_IRDA_H;HAVE_WS2BTH_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>$(OutDir)libdivecomputer.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
</Link>
<ResourceCompile>
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\src\aes.c" />
<ClCompile Include="..\..\src\array.c" />
<ClCompile Include="..\..\src\atomics_cobalt.c" />
<ClCompile Include="..\..\src\atomics_cobalt_parser.c" />
<ClCompile Include="..\..\src\bluetooth.c" />
<ClCompile Include="..\..\src\buffer.c" />
<ClCompile Include="..\..\src\checksum.c" />
<ClCompile Include="..\..\src\citizen_aqualand.c" />
<ClCompile Include="..\..\src\citizen_aqualand_parser.c" />
<ClCompile Include="..\..\src\cochran_commander.c" />
<ClCompile Include="..\..\src\cochran_commander_parser.c" />
<ClCompile Include="..\..\src\common.c" />
<ClCompile Include="..\..\src\context.c" />
<ClCompile Include="..\..\src\cressi_edy.c" />
<ClCompile Include="..\..\src\cressi_edy_parser.c" />
<ClCompile Include="..\..\src\cressi_goa.c" />
<ClCompile Include="..\..\src\cressi_goa_parser.c" />
<ClCompile Include="..\..\src\cressi_leonardo.c" />
<ClCompile Include="..\..\src\cressi_leonardo_parser.c" />
<ClCompile Include="..\..\src\custom.c" />
<ClCompile Include="..\..\src\datetime.c" />
<ClCompile Include="..\..\src\deepblu_cosmiq.c" />
<ClCompile Include="..\..\src\deepblu_cosmiq_parser.c" />
<ClCompile Include="..\..\src\deepsix_excursion.c" />
<ClCompile Include="..\..\src\deepsix_excursion_parser.c" />
<ClCompile Include="..\..\src\descriptor.c" />
<ClCompile Include="..\..\src\device.c" />
<ClCompile Include="..\..\src\diverite_nitekq.c" />
<ClCompile Include="..\..\src\diverite_nitekq_parser.c" />
<ClCompile Include="..\..\src\divesoft_freedom.c" />
<ClCompile Include="..\..\src\divesoft_freedom_parser.c" />
<ClCompile Include="..\..\src\divesystem_idive.c" />
<ClCompile Include="..\..\src\divesystem_idive_parser.c" />
<ClCompile Include="..\..\src\hdlc.c" />
<ClCompile Include="..\..\src\hw_frog.c" />
<ClCompile Include="..\..\src\hw_ostc.c" />
<ClCompile Include="..\..\src\hw_ostc3.c" />
<ClCompile Include="..\..\src\hw_ostc_parser.c" />
<ClCompile Include="..\..\src\ihex.c" />
<ClCompile Include="..\..\src\iostream.c" />
<ClCompile Include="..\..\src\irda.c" />
<ClCompile Include="..\..\src\iterator.c" />
<ClCompile Include="..\..\src\liquivision_lynx.c" />
<ClCompile Include="..\..\src\liquivision_lynx_parser.c" />
<ClCompile Include="..\..\src\mares_common.c" />
<ClCompile Include="..\..\src\mares_darwin.c" />
<ClCompile Include="..\..\src\mares_darwin_parser.c" />
<ClCompile Include="..\..\src\mares_iconhd.c" />
<ClCompile Include="..\..\src\mares_iconhd_parser.c" />
<ClCompile Include="..\..\src\mares_nemo.c" />
<ClCompile Include="..\..\src\mares_nemo_parser.c" />
<ClCompile Include="..\..\src\mares_puck.c" />
<ClCompile Include="..\..\src\mclean_extreme.c" />
<ClCompile Include="..\..\src\mclean_extreme_parser.c" />
<ClCompile Include="..\..\src\oceanic_atom2.c" />
<ClCompile Include="..\..\src\oceanic_atom2_parser.c" />
<ClCompile Include="..\..\src\oceanic_common.c" />
<ClCompile Include="..\..\src\oceanic_veo250.c" />
<ClCompile Include="..\..\src\oceanic_veo250_parser.c" />
<ClCompile Include="..\..\src\oceanic_vtpro.c" />
<ClCompile Include="..\..\src\oceanic_vtpro_parser.c" />
<ClCompile Include="..\..\src\oceans_s1.c" />
<ClCompile Include="..\..\src\oceans_s1_common.c" />
<ClCompile Include="..\..\src\oceans_s1_parser.c" />
<ClCompile Include="..\..\src\packet.c" />
<ClCompile Include="..\..\src\parser.c" />
<ClCompile Include="..\..\src\pelagic_i330r.c" />
<ClCompile Include="..\..\src\platform.c" />
<ClCompile Include="..\..\src\rbstream.c" />
<ClCompile Include="..\..\src\reefnet_sensus.c" />
<ClCompile Include="..\..\src\reefnet_sensuspro.c" />
<ClCompile Include="..\..\src\reefnet_sensuspro_parser.c" />
<ClCompile Include="..\..\src\reefnet_sensusultra.c" />
<ClCompile Include="..\..\src\reefnet_sensusultra_parser.c" />
<ClCompile Include="..\..\src\reefnet_sensus_parser.c" />
<ClCompile Include="..\..\src\ringbuffer.c" />
<ClCompile Include="..\..\src\seac_screen.c" />
<ClCompile Include="..\..\src\seac_screen_parser.c" />
<ClCompile Include="..\..\src\serial_win32.c" />
<ClCompile Include="..\..\src\shearwater_common.c" />
<ClCompile Include="..\..\src\shearwater_petrel.c" />
<ClCompile Include="..\..\src\shearwater_predator.c" />
<ClCompile Include="..\..\src\shearwater_predator_parser.c" />
<ClCompile Include="..\..\src\socket.c" />
<ClCompile Include="..\..\src\sporasub_sp2.c" />
<ClCompile Include="..\..\src\sporasub_sp2_parser.c" />
<ClCompile Include="..\..\src\suunto_common.c" />
<ClCompile Include="..\..\src\suunto_common2.c" />
<ClCompile Include="..\..\src\suunto_d9.c" />
<ClCompile Include="..\..\src\suunto_d9_parser.c" />
<ClCompile Include="..\..\src\suunto_eon.c" />
<ClCompile Include="..\..\src\suunto_eonsteel.c" />
<ClCompile Include="..\..\src\suunto_eonsteel_parser.c" />
<ClCompile Include="..\..\src\suunto_eon_parser.c" />
<ClCompile Include="..\..\src\suunto_solution.c" />
<ClCompile Include="..\..\src\suunto_solution_parser.c" />
<ClCompile Include="..\..\src\suunto_vyper.c" />
<ClCompile Include="..\..\src\suunto_vyper2.c" />
<ClCompile Include="..\..\src\suunto_vyper_parser.c" />
<ClCompile Include="..\..\src\tecdiving_divecomputereu.c" />
<ClCompile Include="..\..\src\tecdiving_divecomputereu_parser.c" />
<ClCompile Include="..\..\src\timer.c" />
<ClCompile Include="..\..\src\usb.c" />
<ClCompile Include="..\..\src\usbhid.c" />
<ClCompile Include="..\..\src\uwatec_aladin.c" />
<ClCompile Include="..\..\src\uwatec_memomouse.c" />
<ClCompile Include="..\..\src\uwatec_memomouse_parser.c" />
<ClCompile Include="..\..\src\uwatec_smart.c" />
<ClCompile Include="..\..\src\uwatec_smart_parser.c" />
<ClCompile Include="..\..\src\version.c" />
<ClCompile Include="..\..\src\zeagle_n2ition3.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\libdivecomputer\atomics_cobalt.h" />
<ClInclude Include="..\..\include\libdivecomputer\ble.h" />
<ClInclude Include="..\..\include\libdivecomputer\bluetooth.h" />
<ClInclude Include="..\..\include\libdivecomputer\buffer.h" />
<ClInclude Include="..\..\include\libdivecomputer\common.h" />
<ClInclude Include="..\..\include\libdivecomputer\context.h" />
<ClInclude Include="..\..\include\libdivecomputer\custom.h" />
<ClInclude Include="..\..\include\libdivecomputer\datetime.h" />
<ClInclude Include="..\..\include\libdivecomputer\descriptor.h" />
<ClInclude Include="..\..\include\libdivecomputer\device.h" />
<ClInclude Include="..\..\include\libdivecomputer\divesystem_idive.h" />
<ClInclude Include="..\..\include\libdivecomputer\hw_frog.h" />
<ClInclude Include="..\..\include\libdivecomputer\hw_ostc.h" />
<ClInclude Include="..\..\include\libdivecomputer\hw_ostc3.h" />
<ClInclude Include="..\..\include\libdivecomputer\ioctl.h" />
<ClInclude Include="..\..\include\libdivecomputer\iostream.h" />
<ClInclude Include="..\..\include\libdivecomputer\irda.h" />
<ClInclude Include="..\..\include\libdivecomputer\iterator.h" />
<ClInclude Include="..\..\include\libdivecomputer\oceanic_atom2.h" />
<ClInclude Include="..\..\include\libdivecomputer\oceanic_veo250.h" />
<ClInclude Include="..\..\include\libdivecomputer\oceanic_vtpro.h" />
<ClInclude Include="..\..\include\libdivecomputer\parser.h" />
<ClInclude Include="..\..\include\libdivecomputer\reefnet_sensus.h" />
<ClInclude Include="..\..\include\libdivecomputer\reefnet_sensuspro.h" />
<ClInclude Include="..\..\include\libdivecomputer\reefnet_sensusultra.h" />
<ClInclude Include="..\..\include\libdivecomputer\serial.h" />
<ClInclude Include="..\..\include\libdivecomputer\suunto_d9.h" />
<ClInclude Include="..\..\include\libdivecomputer\suunto_eon.h" />
<ClInclude Include="..\..\include\libdivecomputer\suunto_vyper2.h" />
<ClInclude Include="..\..\include\libdivecomputer\units.h" />
<ClInclude Include="..\..\include\libdivecomputer\usb.h" />
<ClInclude Include="..\..\include\libdivecomputer\usbhid.h" />
<ClInclude Include="..\..\include\libdivecomputer\version.h" />
<ClInclude Include="..\..\src\aes.h" />
<ClInclude Include="..\..\src\array.h" />
<ClInclude Include="..\..\src\atomics_cobalt.h" />
<ClInclude Include="..\..\src\checksum.h" />
<ClInclude Include="..\..\src\citizen_aqualand.h" />
<ClInclude Include="..\..\src\cochran_commander.h" />
<ClInclude Include="..\..\src\common-private.h" />
<ClInclude Include="..\..\src\context-private.h" />
<ClInclude Include="..\..\src\cressi_edy.h" />
<ClInclude Include="..\..\src\cressi_goa.h" />
<ClInclude Include="..\..\src\cressi_leonardo.h" />
<ClInclude Include="..\..\src\deepblu_cosmiq.h" />
<ClInclude Include="..\..\src\deepsix_excursion.h" />
<ClInclude Include="..\..\src\device-private.h" />
<ClInclude Include="..\..\src\diverite_nitekq.h" />
<ClInclude Include="..\..\src\divesoft_freedom.h" />
<ClInclude Include="..\..\src\divesystem_idive.h" />
<ClInclude Include="..\..\src\hdlc.h" />
<ClInclude Include="..\..\src\hw_frog.h" />
<ClInclude Include="..\..\src\hw_ostc.h" />
<ClInclude Include="..\..\src\hw_ostc3.h" />
<ClInclude Include="..\..\src\ihex.h" />
<ClInclude Include="..\..\src\iostream-private.h" />
<ClInclude Include="..\..\src\iterator-private.h" />
<ClInclude Include="..\..\src\liquivision_lynx.h" />
<ClInclude Include="..\..\src\mares_common.h" />
<ClInclude Include="..\..\src\mares_darwin.h" />
<ClInclude Include="..\..\src\mares_iconhd.h" />
<ClInclude Include="..\..\src\mares_nemo.h" />
<ClInclude Include="..\..\src\mares_puck.h" />
<ClInclude Include="..\..\src\mclean_extreme.h" />
<ClInclude Include="..\..\src\oceanic_atom2.h" />
<ClInclude Include="..\..\src\oceanic_common.h" />
<ClInclude Include="..\..\src\oceanic_veo250.h" />
<ClInclude Include="..\..\src\oceanic_vtpro.h" />
<ClInclude Include="..\..\src\oceans_s1.h" />
<ClInclude Include="..\..\src\oceans_s1_common.h" />
<ClInclude Include="..\..\src\packet.h" />
<ClInclude Include="..\..\src\parser-private.h" />
<ClInclude Include="..\..\src\pelagic_i330r.h" />
<ClInclude Include="..\..\src\platform.h" />
<ClInclude Include="..\..\src\rbstream.h" />
<ClInclude Include="..\..\src\reefnet_sensus.h" />
<ClInclude Include="..\..\src\reefnet_sensuspro.h" />
<ClInclude Include="..\..\src\reefnet_sensusultra.h" />
<ClInclude Include="..\..\src\revision.h" />
<ClInclude Include="..\..\src\ringbuffer.h" />
<ClInclude Include="..\..\src\seac_screen.h" />
<ClInclude Include="..\..\src\shearwater_common.h" />
<ClInclude Include="..\..\src\shearwater_petrel.h" />
<ClInclude Include="..\..\src\shearwater_predator.h" />
<ClInclude Include="..\..\src\socket.h" />
<ClInclude Include="..\..\src\sporasub_sp2.h" />
<ClInclude Include="..\..\src\suunto_common.h" />
<ClInclude Include="..\..\src\suunto_common2.h" />
<ClInclude Include="..\..\src\suunto_d9.h" />
<ClInclude Include="..\..\src\suunto_eon.h" />
<ClInclude Include="..\..\src\suunto_eonsteel.h" />
<ClInclude Include="..\..\src\suunto_solution.h" />
<ClInclude Include="..\..\src\suunto_vyper.h" />
<ClInclude Include="..\..\src\suunto_vyper2.h" />
<ClInclude Include="..\..\src\tecdiving_divecomputereu.h" />
<ClInclude Include="..\..\src\timer.h" />
<ClInclude Include="..\..\src\uwatec_aladin.h" />
<ClInclude Include="..\..\src\uwatec_memomouse.h" />
<ClInclude Include="..\..\src\uwatec_smart.h" />
<ClInclude Include="..\..\src\zeagle_n2ition3.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\src\libdivecomputer.rc" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\..\src\libdivecomputer.symbols">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">echo EXPORTS &gt; "$(OutDir)libdivecomputer.def" &amp;&amp; type "%(FullPath)" &gt;&gt; "$(OutDir)libdivecomputer.def"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">echo EXPORTS &gt; "$(OutDir)libdivecomputer.def" &amp;&amp; type "%(FullPath)" &gt;&gt; "$(OutDir)libdivecomputer.def"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)libdivecomputer.def;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)libdivecomputer.def;%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">echo EXPORTS &gt; "$(OutDir)libdivecomputer.def" &amp;&amp; type "%(FullPath)" &gt;&gt; "$(OutDir)libdivecomputer.def"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">echo EXPORTS &gt; "$(OutDir)libdivecomputer.def" &amp;&amp; type "%(FullPath)" &gt;&gt; "$(OutDir)libdivecomputer.def"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)libdivecomputer.def;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)libdivecomputer.def;%(Outputs)</Outputs>
</CustomBuild>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
</Project>

View File

@ -1,17 +1,35 @@
# Atomic Aquatics Cobalt # Atomic Aquatics Cobalt
SUBSYSTEM=="usb", ATTR{idVendor}=="0471", ATTR{idProduct}=="0888", GROUP="plugdev" SUBSYSTEM=="usb", ATTR{idVendor}=="0471", ATTR{idProduct}=="0888", GROUP="plugdev"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="0471", ATTRS{idProduct}=="0888", GROUP="plugdev"
# Suunto EON Steel # Suunto EON Steel
SUBSYSTEM=="usb", ATTR{idVendor}=="1493", ATTR{idProduct}=="0030", GROUP="plugdev" SUBSYSTEM=="usb", ATTR{idVendor}=="1493", ATTR{idProduct}=="0030", GROUP="plugdev"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="1493", ATTRS{idProduct}=="0030", GROUP="plugdev"
# Suunto EON Core # Suunto EON Core
SUBSYSTEM=="usb", ATTR{idVendor}=="1493", ATTR{idProduct}=="0033", GROUP="plugdev" SUBSYSTEM=="usb", ATTR{idVendor}=="1493", ATTR{idProduct}=="0033", GROUP="plugdev"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="1493", ATTRS{idProduct}=="0033", GROUP="plugdev"
# Suunto D5
SUBSYSTEM=="usb", ATTR{idVendor}=="1493", ATTR{idProduct}=="0035", GROUP="plugdev"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="1493", ATTRS{idProduct}=="0035", GROUP="plugdev"
# Suunto EON Steel Black
SUBSYSTEM=="usb", ATTR{idVendor}=="1493", ATTR{idProduct}=="0036", GROUP="plugdev"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="1493", ATTRS{idProduct}=="0036", GROUP="plugdev"
# Scubapro G2 # Scubapro G2
SUBSYSTEM=="usb", ATTR{idVendor}=="2e6c", ATTR{idProduct}=="3201", GROUP="plugdev" SUBSYSTEM=="usb", ATTR{idVendor}=="2e6c", ATTR{idProduct}=="3201", GROUP="plugdev"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="2e6c", ATTRS{idProduct}=="3201", GROUP="plugdev"
# Scubapro G2 Console # Scubapro G2 Console
SUBSYSTEM=="usb", ATTR{idVendor}=="2e6c", ATTR{idProduct}=="3211", GROUP="plugdev" SUBSYSTEM=="usb", ATTR{idVendor}=="2e6c", ATTR{idProduct}=="3211", GROUP="plugdev"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="2e6c", ATTRS{idProduct}=="3211", GROUP="plugdev"
# Scubapro G2 HUD
SUBSYSTEM=="usb", ATTR{idVendor}=="2e6c", ATTR{idProduct}=="4201", GROUP="plugdev"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="2e6c", ATTRS{idProduct}=="4201", GROUP="plugdev"
# Scubapro Aladin Square # Scubapro Aladin Square
SUBSYSTEM=="usb", ATTR{idVendor}=="c251", ATTR{idProduct}=="2006", GROUP="plugdev" SUBSYSTEM=="usb", ATTR{idVendor}=="c251", ATTR{idProduct}=="2006", GROUP="plugdev"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="c251", ATTRS{idProduct}=="2006", GROUP="plugdev"

View File

@ -0,0 +1,102 @@
COMPUTER CONFIGURATION
----------------------
The computer configuration (including gradient factors, gasses etc) is read and written as a single, fixed size block.
Config section
--------------
Computer configuration and individual dive configurations both start with identical generic configuration sections of length 0x002d bytes
0x0000 uint8_t format ZERO
0x0001 uint8_t gas[0]_pO2 oxygen content [0, 100] (percent)
0x0002 uint8_t gas[0]_pHe helium content [0, 100] (percent)
0x0003 uint8_t gas[1]_pO2 oxygen content [0, 100] (percent)
0x0004 uint8_t gas[1]_pHe helium content [0, 100] (percent)
0x0005 uint8_t gas[2]_pO2 oxygen content [0, 100] (percent)
0x0006 uint8_t gas[2]_pHe helium content [0, 100] (percent)
0x0007 uint8_t gas[3]_pO2 oxygen content [0, 100] (percent)
0x0008 uint8_t gas[3]_pHe helium content [0, 100] (percent)
0x0009 uint8_t gas[4]_pO2 oxygen content [0, 100] (percent)
0x000a uint8_t gas[4]_pHe helium content [0, 100] (percent)
0x000b uint8_t gas[5]_pO2 oxygen content [0, 100] (percent)
0x000c uint8_t gas[5]_pHe helium content [0, 100] (percent)
0x000d uint8_t gas[6]_pO2 oxygen content [0, 100] (percent)
0x000e uint8_t gas[6]_pHe helium content [0, 100] (percent)
0x000f uint8_t gas[7]_pO2 oxygen content [0, 100] (percent)
0x0010 uint8_t gas[7]_pHe helium content [0, 100] (percent)
0x0011 uint8_t gas_mask bitwise mask of enabled gasses
0x0012 uint8_t gas_active current gas index
0x0013 uint8_t setpoint[0] (centibar)
0x0014 uint8_t setpoint[1] (centibar)
0x0015 uint8_t setpoint[2] (centibar)
0x0016 uint8_t setpoint_mask bitwise mask of enabled setpoints
0x0017 uint8_t setpoint_active current setpoint index
0x0018 bool metric display units [true: metric, false: imperial]
0x0019 uint16_t name dive number
0x001b uint8_t laststop_index last stop depth enumeration [0, 3] (metric: 3m, 4m, 5m, 6m imperial: 10ft, 13ft, 16ft, 18ft)
0x001c uint16_t Vasc ascent speed limit (millibar/minute)
0x001e uint16_t Psurf surface pressure (millibar)
0x0020 uint8_t gfs_index predefined gf enumeration [0, 5] (only used in rec mode)
0x0021 uint8_t gf lo custom gf low [0, 255] (ignored in rec mode)
0x0022 uint8_t gf hi custom gf high [0, 255] (ignored in rec mode)
0x0023 uint8_t density_index predefined water density enumeration [0: 1.000, 1: 1.020, 2: 1.030]
0x0024 uint16_t ppN2_limit nitrogen partial pressure alert (millibars)
0x0026 uint16_t ppO2_limit oxygen partial pressure alert (millibars)
0x0028 uint16_t ppO2_bottomlimit oxygen partial pressure alert (millibars)
0x002a uint16_t density_limit (units ??)
0x002c uint8_t operatingmode operating mode enumeration [0: OC rec, 1: OC tec, 2: CC, 3: Gauge]
Computer configuration
----------------------
The computer configuration is read and written as a single block of 0x006a bytes formatted thusly:
<config section as above>
0x002d +
0x0000 int64_t epoch internal adjustment used to set computer time
0x0008 uint16_t inactive_timeout number of seconds of inactivity before the computer turns itself off
0x000a uint16_t dive_timeout number of seconds on surface before declaring dive finished
0x000c uint16_t log_period number of seconds between dive samples
0x000e uint16_t log_timeout not used
0x0010 uint16_t brightness_timeout number of seconds of inactivity before the computer dims the screen
0x0012 uint8_t brightness dimmed screen brightness [0, 10]
0x0013 uint8_t colorscheme computer color scheme enumeration [0, 12]
0x0014 uint8_t language computer display language enumeration [0, 1]
0x0015 uint8_t batterytype user-defined battery type enumeration [0, 4]
0x0016 uint16_t batterytime computer up time since last battery change
0x0018 <48 bytes> compass calibration data (cannot be written)
0x0048 uint8_t button_sensitivity piezo button sensitivity [0, 9]
0x0049 uint8_t orientation screen and button orientation
0x004a char[32] diver_name diver name (guaranteed at least one nul terminator)
0x006a
Dive configuration
------------------
Individual dives are read as a single block of 0x002d bytes formatted thusly:
<config section as above>
0x002d +
0x0000 uint32_t log_start log start (seconds since midnight 1 jan 2000)
0x0004 uint32_t dive_start dive start (seconds since midnight 1 jan 2000)
0x0008 uint32_t dive_end dive end (seconds since midnight 1 jan 2000)
0x000c uint32_t log_end log end (seconds since midnight 1 jan 2000)
0x0010 uint8_t temp_min minimum ambient temperature (degrees centigrade)
0x0011 uint8_t temp_max maximum ambient temperature (degrees centigrade)
0x0012 uint16_t pO2_min minimum inspired oxygen partial pressure during the dive (millibars)
0x0014 uint16_t pO2_max maximum inspired oxygen partial pressure during the dive (millibars)
0x0016 uint16_t Pmax maximum ambient pressure during the dive (millibars)
0x0018 uint16_t Pav average ambient pressure during the dive (millibars)
0x001a uint32_t ISS integral supersaturation of dive mbar*minutes
0x001e uint16_t CNS_start CNS at start of dive (percent)
0x0020 uint16_t CNS_max maximum CNS encountered during the dive (percent)
0x0022 uint16_t OTU OTU dive
0x0024 uint16_t tndl shortest NDL calculated during dive (seconds)
0x0026 uint32_t tdeco longest decompression time calculated during dive (seconds)
0x002a uint8_t ndeco deepest decompression stop index calculated during dive (seconds)
0x002b uint16_t tdesat desaturation time calculated at end of dive (seconds)
0x002d

View File

@ -17,6 +17,7 @@ MANPAGES = \
dc_descriptor_get_model.3 \ dc_descriptor_get_model.3 \
dc_descriptor_get_product.3 \ dc_descriptor_get_product.3 \
dc_descriptor_get_vendor.3 \ dc_descriptor_get_vendor.3 \
dc_descriptor_get_transports.3 \
dc_descriptor_iterator.3 \ dc_descriptor_iterator.3 \
dc_device_close.3 \ dc_device_close.3 \
dc_device_foreach.3 \ dc_device_foreach.3 \
@ -31,8 +32,29 @@ MANPAGES = \
dc_parser_get_field.3 \ dc_parser_get_field.3 \
dc_parser_new.3 \ dc_parser_new.3 \
dc_parser_samples_foreach.3 \ dc_parser_samples_foreach.3 \
dc_parser_set_data.3 \ dc_bluetooth_open.3 \
libdivecomputer.3 dc_bluetooth_iterator_new.3 \
dc_bluetooth_device_get_address.3 \
dc_bluetooth_device_get_name.3 \
dc_bluetooth_addr2str.3 \
dc_bluetooth_str2addr.3 \
dc_bluetooth_device_free.3 \
dc_usbhid_open.3 \
dc_usbhid_device_get_pid.3 \
dc_usbhid_device_get_vid.3 \
dc_usbhid_iterator_new.3 \
dc_usbhid_device_free.3 \
dc_serial_open.3 \
dc_serial_device_get_name.3 \
dc_serial_iterator_new.3 \
dc_serial_device_free.3 \
dc_irda_open.3 \
dc_irda_device_get_name.3 \
dc_irda_device_get_address.3 \
dc_irda_iterator_new.3 \
dc_irda_device_free.3 \
dc_iostream_close.3 \
libdivecomputer.3
HTMLPAGES = $(MANPAGES:%=%.html) HTMLPAGES = $(MANPAGES:%=%.html)

View File

@ -0,0 +1,61 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_BLUETOOTH_ADDR2STR 3
.Os
.Sh NAME
.Nm dc_bluetooth_addr2str
.Nd Convert a bluetooth address to a string.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/bluetooth.h
.Ft "const char*"
.Fo dc_bluetooth_addr2str
.Fa "dc_bluetooth_address_t address"
.Fa "char *str"
.Fa "size_t size"
.Fc
.Sh DESCRIPTION
Convert a bluetooth address to a string.
.Pp
The bluetooth address is formatted as XX:XX:XX:XX:XX:XX, where each XX is a
hexadecimal number specifying an octet of the 48-bit address.
The minimum size for the buffer is
.Dv DC_BLUETOOTH_SIZE
bytes.
.Pp
The reverse can be done with
.Xr dc_bluetooth_str2addr 3 .
.Sh RETURN VALUES
Returns the bluetooth address represented as a string.
.Sh SEE ALSO
.Xr dc_bluetooth_str2addr 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -0,0 +1,52 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_BLUETOOTH_DEVICE_FREE 3
.Os
.Sh NAME
.Nm dc_bluetooth_device_free
.Nd Destroy the bluetooth device and free all resources.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/bluetooth.h
.Ft void
.Fo dc_bluetooth_device_free
.Fa "dc_bluetooth_device_t *device"
.Fc
.Sh DESCRIPTION
Destroy the bluetooth device and free all resources.
The bluetooth
.Fa device
usually found by searching through
.Xr dc_bluetooth_iterator_new 3 .
.Sh SEE ALSO
.Xr dc_bluetooth_iterator_new 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -0,0 +1,69 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_BLUETOOTH_DEVICE_GET_ADDRESS 3
.Os
.Sh NAME
.Nm dc_bluetooth_device_get_address
.Nd Get the address of a bluetooth device.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/bluetooth.h
.Ft "dc_bluetooth_address_t"
.Fo dc_bluetooth_device_get_address
.Fa "dc_bluetooth_device_t *device"
.Fc
.Sh DESCRIPTION
Get the bluetooth device address of given bluetooth
.Fa device .
Required when opening transport communication with
.Xr dc_bluetooth_open 3 .
Requires a valid
.Fa device
of type
.Ft dc_bluetooth_device_t
which can be retrieved using
.Xr dc_bluetooth_iterator_new 3 .
.Sh RETURN VALUES
Returns the bluetooth address of
.Fa device
as
.Ft dc_bluetooth_address_t
which is a 64bit integer holding the bluetooth address.
The address can be formatted as a string by using
.Xr dc_bluetooth_addr2str 3 .
.Sh SEE ALSO
.Xr dc_bluetooth_open 3 ,
.Xr dc_bluetooth_iterator_new 3 ,
.Xr dc_bluetooth_device_get_name 3 ,
.Xr dc_bluetooth_addr2str 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -0,0 +1,61 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_BLUETOOTH_DEVICE_GET_NAME 3
.Os
.Sh NAME
.Nm dc_bluetooth_device_get_name
.Nd Get the name of a bluetooth device.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/bluetooth.h
.Ft "const char *"
.Fo dc_bluetooth_device_get_name
.Fa "dc_bluetooth_device_t *device"
.Fc
.Sh DESCRIPTION
Get the name of given bluetooth
.Fa device .
Used for displaying.
Requires a valid
.Fa bluetooth_device
of type
.Ft dc_bluetooth_device_t
which can be retrieved using
.Xr dc_bluetooth_iterator_new 3 .
.Sh RETURN VALUES
Returns the bluetooth device of
.Fa device .
.Sh SEE ALSO
.Xr dc_bluetooth_open 3 ,
.Xr dc_bluetooth_iterator_new 3 ,
.Xr dc_bluetooth_device_get_address 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -0,0 +1,102 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_BLUETOOTH_ITERATOR_NEW 3
.Os
.Sh NAME
.Nm dc_bluetooth_iterator_new
.Nd Create an iterator to enumerate the bluetooth devices.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/bluetooth.h
.Ft dc_status_t
.Fo dc_bluetooth_iterator_new
.Fa "dc_iterator_t **iterator"
.Fa "dc_context_t *context"
.Fa "dc_descriptor_t *descriptor"
.Fc
.Sh DESCRIPTION
Iterates through the available bluetooth devices which matches the given
.Fa descriptor .
Accepts a
.Fa context
opened with
.Xr dc_context_new 3
and a
.Fa descriptor
usually found by searching through
.Xr dc_descriptor_iterator 3 .
.Pp
On returning
.Dv DC_STATUS_SUCCESS
the
.Fa iterator
will be set to an
.Ft dc_iterator_t
which can be used to iterate the available bluetooth devices using
.Xr dc_iterator_next 3 .
.Pp
The value type of the iterator is of type
.Ft dc_bluetooth_device_t .
This value can be used in functions to extract information about this specific bluetooth device, namely
.Xr dc_bluetooth_device_get_name 3
and
.Xr dc_bluetooth_device_get_address 3 .
When done the bluetooth device needs to be freed with
.Xr dc_bluetooth_device_free 3 .
.Pp
After iterating the
.Fa iterator
needs to be freed using
.Xr dc_iterator_free 3 .
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_SUCCESS
on success, or another
.Ft dc_status_t
code on failure.
On
.Dv DC_STATUS_SUCCESS
the returned
.Fa iterator
needs to be freed when done using
.Xr dc_iterator_free 3 .
.Sh SEE ALSO
.Xr dc_context_new 3 ,
.Xr dc_usbhid_iterator_new 3 ,
.Xr dc_serial_iterator_new 3 ,
.Xr dc_irda_iterator_new 3 ,
.Xr dc_bluetooth_device_get_name 3 ,
.Xr dc_bluetooth_device_get_address 3 ,
.Xr dc_bluetooth_device_free 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -0,0 +1,87 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_BLUETOOTH_OPEN 3
.Os
.Sh NAME
.Nm dc_bluetooth_open
.Nd Opens an iostream for a bluetooth device
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/bluetooth.h
.Ft dc_status_t
.Fo dc_bluetooth_open
.Fa "dc_iostream_t **iostream"
.Fa "dc_context_t *context"
.Fa "dc_bluetooth_address_t address"
.Fa "unsigned int port"
.Fc
.Sh DESCRIPTION
Opens an iostream for a bluetooth device.
Accepts a
.Fa context
opened with
.Xr dc_context_new 3 ,
a 48-bit bluetooth
.Fa address
given by
.Xr dc_bluetooth_iterator_new 3
together with
.Xr dc_bluetooth_device_get_address 3
or
.Xr dc_bluetooth_str2addr 3
and a bluetooth rfcomm
.Fa port
number (use 0 for autodetection).
.Pp
Upon returning
.Dv DC_STATUS_SUCCESS ,
the
.Fa iostream
pointer must be freed with
.Xr dc_iostream_close 3 .
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_SUCCESS
on success or one of several error values on error.
On success, the
.Fa iostream
pointer is filled in with an open handle.
.Sh SEE ALSO
.Xr dc_context_new 3 ,
.Xr dc_iostream_close 3 ,
.Xr dc_serial_open 3 ,
.Xr dc_irda_open 3 ,
.Xr dc_usbhid_open 3 ,
.Xr dc_bluetooth_iterator_new 3 ,
.Xr dc_bluetooth_device_get_address 3 ,
.Xr dc_bluetooth_str2addr 3 ,
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -0,0 +1,58 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_BLUETOOTH_STR2ADDR 3
.Os
.Sh NAME
.Nm dc_bluetooth_str2addr
.Nd Convert a string to a bluetooth address.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/bluetooth.h
.Ft "dc_bluetooth_address_t"
.Fo dc_bluetooth_addr2str
.Fa "const char *address"
.Fc
.Sh DESCRIPTION
Convert a string to a bluetooth address.
.Pp
The string
.Fa address
is expected to be in the format XX:XX:XX:XX:XX:XX,
where each XX is a hexadecimal number specifying an octet of the 48-bit address.
.Pp
The reverse can be done with
.Xr dc_bluetooth_addr2str 3 .
.Sh RETURN VALUES
Returns the bluetooth address represented as a 48-bit number.
.Sh SEE ALSO
.Xr dc_bluetooth_addr2str 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -82,7 +82,7 @@ is
.Sh SEE ALSO .Sh SEE ALSO
.Xr dc_datetime_localtime 3 , .Xr dc_datetime_localtime 3 ,
.Xr dc_datetime_mktime 3 , .Xr dc_datetime_mktime 3 ,
.Xr dc_datetime_new 3 .Xr dc_datetime_now 3
.Sh AUTHORS .Sh AUTHORS
The The
.Lb libdivecomputer .Lb libdivecomputer

View File

@ -82,7 +82,7 @@ is
.Sh SEE ALSO .Sh SEE ALSO
.Xr dc_datetime_gmtime 3 , .Xr dc_datetime_gmtime 3 ,
.Xr dc_datetime_mktime 3 , .Xr dc_datetime_mktime 3 ,
.Xr dc_datetime_new 3 .Xr dc_datetime_now 3
.Sh AUTHORS .Sh AUTHORS
The The
.Lb libdivecomputer .Lb libdivecomputer

View File

@ -47,7 +47,7 @@ may not sanely be converted.
.Sh SEE ALSO .Sh SEE ALSO
.Xr dc_datetime_gmtime 3 , .Xr dc_datetime_gmtime 3 ,
.Xr dc_datetime_localtime 3 , .Xr dc_datetime_localtime 3 ,
.Xr dc_datetime_new 3 .Xr dc_datetime_now 3
.Sh AUTHORS .Sh AUTHORS
The The
.Lb libdivecomputer .Lb libdivecomputer

View File

@ -0,0 +1,72 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_DESCRIPTOR_GET_TRANSPORTS 3
.Os
.Sh NAME
.Nm dc_descriptor_get_transports
.Nd Gets the transports supported by the given descriptor.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/descriptor.h
.Ft "unsigned int"
.Fo dc_descriptor_get_transports
.Fa "dc_descriptor_t *descriptor"
.Fc
.Sh DESCRIPTION
Gets the transports supported by the given
.Fa descriptor .
The
.Fa descriptor
usually found by searching through
.Xr dc_descriptor_iterator 3 .
.Sh RETURN VALUES
Returns a union (bitwise OR) of the transports supported by the given
.Fa descriptor .
.Pp
The result is combination of
.Dv DC_TRANSPORT_USB ,
.Dv DC_TRANSPORT_USBHID ,
.Dv DC_TRANSPORT_BLE ,
.Dv DC_TRANSPORT_BLUETOOTH ,
.Dv DC_TRANSPORT_SERIAL ,
.Dv DC_TRANSPORT_IRDA
.Pp
To determine if a specific transport is supported use the following code
.Bd -literal -offset indent
unsigned int transports = dc_descriptor_get_transports(descriptor);
if(transports & DC_TRANSPORT_USBHID) {
// Device supports USB HID as transport
}
.Ed
.Sh SEE ALSO
.Xr dc_descriptor_iterator 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -53,7 +53,7 @@ with
Each dive invokes Each dive invokes
.Fa callback .Fa callback
with the dive data, which should be parsed with with the dive data, which should be parsed with
.Xr dc_parser_set_data 3 , .Xr dc_parser_new 3 ,
and the binary fingerprint of the dive. and the binary fingerprint of the dive.
The fingerprint can be used to record the newest dive and stop The fingerprint can be used to record the newest dive and stop
processing (on subsequent invocations) when the same dive fingerprint is processing (on subsequent invocations) when the same dive fingerprint is
@ -72,7 +72,7 @@ If
returns zero, this will not be reflected in the return value (usually returns zero, this will not be reflected in the return value (usually
.Dv DC_STATUS_SUCCESS ) . .Dv DC_STATUS_SUCCESS ) .
.Sh SEE ALSO .Sh SEE ALSO
.Xr dc_parser_set_data 3 .Xr dc_parser_new 3
.Sh AUTHORS .Sh AUTHORS
The The
.Lb libdivecomputer .Lb libdivecomputer

View File

@ -18,7 +18,7 @@
.\" Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, .\" Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
.\" MA 02110-1301 USA .\" MA 02110-1301 USA
.\" .\"
.Dd January 5, 2017 .Dd June 5, 2020
.Dt DC_DEVICE_OPEN 3 .Dt DC_DEVICE_OPEN 3
.Os .Os
.Sh NAME .Sh NAME
@ -33,7 +33,7 @@
.Fa "dc_device_t **device" .Fa "dc_device_t **device"
.Fa "dc_context_t *context" .Fa "dc_context_t *context"
.Fa "dc_descriptor_t *descriptor" .Fa "dc_descriptor_t *descriptor"
.Fa "const char *name" .Fa "dc_iostream_t *iostream"
.Fc .Fc
.Sh DESCRIPTION .Sh DESCRIPTION
Open a dive computer device for processing. Open a dive computer device for processing.
@ -45,19 +45,14 @@ a dive computer
.Fa descriptor .Fa descriptor
usually found by searching through usually found by searching through
.Xr dc_descriptor_iterator 3 , .Xr dc_descriptor_iterator 3 ,
and a platform-specific device and a
.Fa name .Fa iostream
.Po opened with a transport specific open function like
such as .Xr dc_usbhid_open 3 ,
.Pa /dev/ttyUSBx .Xr dc_irda_open 3 ,
on Linux, .Xr dc_serial_open 3 ,
.Pa /dev/tty.xxx
on Mac OS X,
.Pa /dev/ttyUx
on the BSDs,
or or
.Pa COMx .Xr dc_bluetooth_open 3
on Microsoft Windows
.Pc . .Pc .
.Pp .Pp
Upon returning Upon returning
@ -83,6 +78,10 @@ The
library was written by library was written by
.An Jef Driesen , .An Jef Driesen ,
.Mt jef@libdivecomputer.org . .Mt jef@libdivecomputer.org .
.br
The manpages were written by The manpages were written by
.An Kristaps Dzonsons , .An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv . .Mt kristaps@bsd.lv .
and
.An Vincent Hagen ,
.Mt vinnie@script4web.nl

View File

@ -1,7 +1,7 @@
.\" .\"
.\" libdivecomputer .\" libdivecomputer
.\" .\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv> .\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\" .\"
.\" This library is free software; you can redistribute it and/or .\" This library is free software; you can redistribute it and/or
.\" modify it under the terms of the GNU Lesser General Public .\" modify it under the terms of the GNU Lesser General Public
@ -18,48 +18,43 @@
.\" Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, .\" Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
.\" MA 02110-1301 USA .\" MA 02110-1301 USA
.\" .\"
.Dd January 5, 2017 .Dd June 5, 2020
.Dt DC_PARSER_SET_DATA 3 .Dt DC_IOSTREAM_CLOSE 3
.Os .Os
.Sh NAME .Sh NAME
.Nm dc_parser_set_data .Nm dc_iostream_close
.Nd assigns parse data to a dive parser .Nd Close the I/O stream and free all resources.
.Sh LIBRARY .Sh LIBRARY
.Lb libdivecomputer .Lb libdivecomputer
.Sh SYNOPSIS .Sh SYNOPSIS
.In libdivecomputer/parser.h .In libdivecomputer/iostream.h
.Ft dc_status_t .Ft dc_status_t
.Fo dc_parser_set_data .Fo dc_iostream_close
.Fa "dc_parser_t *parser" .Fa "dc_iostream_t *iostream"
.Fa "const unsigned char *data"
.Fa "unsigned int size"
.Fc .Fc
.Sh DESCRIPTION .Sh DESCRIPTION
Assigns the binary sequence Close the I/O stream and free all resources.
.Fa data Accepts the
of length .Fa iostream
.Fa size to close and free.
bytes to
.Fa parser ,
which was created with
.Xr dc_parser_new 3 .
How the data is parsed depends upon the values provided to
.Xr dc_parser_new 3 .
The data usually comes from the callback assigned to
.Xr dc_device_foreach 3 .
.Sh RETURN VALUES .Sh RETURN VALUES
Returns Returns
.Dv DC_STATUS_OK .Dv DC_STATUS_SUCCESS
on success and another code on failure. on success, or another
.Ft dc_status_t
code on failure.
.Sh SEE ALSO .Sh SEE ALSO
.Xr dc_device_foreach 3 , .Xr dc_usbhid_open 3 ,
.Xr dc_parser_new 3 .Xr dc_serial_open 3 ,
.Xr dc_irda_open 3 ,
.Xr dc_bluetooth_open 3 .
.Sh AUTHORS .Sh AUTHORS
The The
.Lb libdivecomputer .Lb libdivecomputer
library was written by library was written by
.An Jef Driesen , .An Jef Driesen ,
.Mt jef@libdivecomputer.org . .Mt jef@libdivecomputer.org .
The manpages were written by .br
.An Kristaps Dzonsons , This manpage is written by
.Mt kristaps@bsd.lv . .An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -0,0 +1,52 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_IRDA_DEVICE_FREE 3
.Os
.Sh NAME
.Nm dc_irda_device_free
.Nd Destroy the irda device and free all resources.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/irda.h
.Ft void
.Fo dc_irda_device_free
.Fa "dc_irda_device_t *device"
.Fc
.Sh DESCRIPTION
Destroy the irda device and free all resources.
The irda
.Fa device
usually found by searching through
.Xr dc_irda_iterator_new 3 .
.Sh SEE ALSO
.Xr dc_irda_iterator_new 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -0,0 +1,59 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_IRDA_DEVICE_GET_ADDRESS 3
.Os
.Sh NAME
.Nm dc_irda_device_get_address
.Nd Get the address of the IrDA device.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/irda.h
.Ft "unsigned int"
.Fo dc_irda_device_get_address
.Fa "dc_irda_device_t *device"
.Fc
.Sh DESCRIPTION
Get the address of the IrDA device. Return value used for opening a IrDA device using
.Xr dc_irda_open 3 .
Requires a valid irda
.Fa device
of type
.Ft dc_irda_device_t
which can be retrieved using
.Xr dc_irda_iterator_new 3 .
.Sh RETURN VALUES
Returns the IrDA address of given IrDA
.Fa device
.Sh SEE ALSO
.Xr dc_irda_open 3 ,
.Xr dc_irda_device_get_name 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -0,0 +1,58 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_IRDA_DEVICE_GET_NAME 3
.Os
.Sh NAME
.Nm dc_irda_device_get_name
.Nd Get the address of the IrDA device.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/irda.h
.Ft "const char *"
.Fo dc_irda_device_get_name
.Fa "dc_irda_device_t *device"
.Fc
.Sh DESCRIPTION
Get the name of the IrDA device. Used for displaying.
Requires a valid irda
.Fa device
of type
.Ft dc_irda_device_t
which can be retrieved using
.Xr dc_irda_iterator_new 3 .
.Sh RETURN VALUES
Returns the IrDA name of given
.Fa irda_device
.Sh SEE ALSO
.Xr dc_irda_device_get_address 3 .
.Xr dc_irda_iterator_new 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -0,0 +1,102 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_IRDA_ITERATOR_NEW 3
.Os
.Sh NAME
.Nm dc_irda_iterator_new
.Nd Create an iterator to enumerate the IrDA devices.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/irda.h
.Ft dc_status_t
.Fo dc_irda_iterator_new
.Fa "dc_iterator_t **iterator"
.Fa "dc_context_t *context"
.Fa "dc_descriptor_t *descriptor"
.Fc
.Sh DESCRIPTION
Iterates through the available IrDA devices which matches the given
.Fa descriptor .
Accepts a
.Fa context
opened with
.Xr dc_context_new 3
and a
.Fa descriptor
usually found by searching through
.Xr dc_descriptor_iterator 3 .
.Pp
On returning
.Dv DC_STATUS_SUCCESS
the
.Fa iterator
will be set to an
.Ft dc_iterator_t
which can be used to iterate the available IrDA devices using
.Xr dc_iterator_next 3 .
.Pp
The value type of the iterator is of type
.Ft dc_irda_device_t .
This value can be used in functions to extract information about this specific IrDA device, namely
.Xr dc_irda_device_get_name 3
and
.Xr dc_irda_device_get_address 3 .
When done the IrDA device needs to be freed with
.Xr dc_irda_device_free 3 .
.Pp
After iterating the
.Fa iterator
needs to be freed using
.Xr dc_iterator_free 3 .
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_SUCCESS
on success, or another
.Ft dc_status_t
code on failure.
On
.Dv DC_STATUS_SUCCESS
the returned
.Fa iterator
needs to be freed when done using
.Xr dc_iterator_free 3 .
.Sh SEE ALSO
.Xr dc_context_new 3 ,
.Xr dc_usbhid_iterator_new 3 ,
.Xr dc_serial_iterator_new 3 ,
.Xr dc_bluetooth_iterator_new 3 ,
.Xr dc_irda_device_get_name 3 ,
.Xr dc_irda_device_get_address 3 ,
.Xr dc_irda_device_free 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

85
doc/man/dc_irda_open.3 Normal file
View File

@ -0,0 +1,85 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_IRDA_OPEN 3
.Os
.Sh NAME
.Nm dc_irda_open
.Nd Opens an iostream for a IrDA device
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/irda.h
.Ft dc_status_t
.Fo dc_irda_open
.Fa "dc_iostream_t **iostream"
.Fa "dc_context_t *context"
.Fa "unsigned int address"
.Fa "unsigned int lsap"
.Fc
.Sh DESCRIPTION
Opens an iostream for a IrDA (Infra Red) device.
Accepts a
.Fa context
opened with
.Xr dc_context_new 3 ,
.Fa address
given through
.Xr dc_irda_iterator_new 3
together with
.Xr dc_irda_device_get_address 3
, the last argument
.Fa lsap
is a port number used during the communication. Currently only Uwatec computers use IrDA comminication and for those the
.Fa lsap
can be hardcoded to 1
.Pp
Upon returning
.Dv DC_STATUS_SUCCESS ,
the
.Fa iostream
pointer must be freed with
.Xr dc_iostream_close 3 .
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_SUCCESS
on success or one of several error values on error.
On success, the
.Fa iostream
pointer is filled in with an open handle.
.Sh SEE ALSO
.Xr dc_context_new 3 ,
.Xr dc_iostream_close 3 ,
.Xr dc_serial_open 3 ,
.Xr dc_usbhid_open 3 ,
.Xr dc_bluetooth_open 3 ,
.Xr dc_irda_iterator_new 3 ,
.Xr dc_irda_device_get_address 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -37,7 +37,7 @@
Extract the date and time of a dive, Extract the date and time of a dive,
.Fa parser , .Fa parser ,
previously initialised with previously initialised with
.Xr dc_parser_set_data 3 . .Xr dc_parser_new 3 .
This returns the broken-down time-stamp of the dive in the local time of This returns the broken-down time-stamp of the dive in the local time of
the dive. the dive.
.Pp .Pp
@ -57,7 +57,7 @@ messages on further failure.
.Sh SEE ALSO .Sh SEE ALSO
.Xr dc_datetime_gmtime 3 , .Xr dc_datetime_gmtime 3 ,
.Xr dc_datetime_localtime 3 , .Xr dc_datetime_localtime 3 ,
.Xr dc_parser_set_data 3 .Xr dc_parser_new 3
.Sh AUTHORS .Sh AUTHORS
The The
.Lb libdivecomputer .Lb libdivecomputer

View File

@ -39,7 +39,7 @@
Extract a field from a dive, Extract a field from a dive,
.Fa parser , .Fa parser ,
previously initialised with previously initialised with
.Xr dc_parser_set_data 3 . .Xr dc_parser_new 3 .
The The
.Fa value .Fa value
field type depends upon the field type depends upon the
@ -149,7 +149,7 @@ the tank volume units as
or or
.Dv DC_TANKVOLUME_METRIC ; .Dv DC_TANKVOLUME_METRIC ;
.Va volume , .Va volume ,
the tank volume in bar or zero if the tank is the tank volume in litres or zero if the tank is
.Dv DC_TANKVOLUME_NONE ; .Dv DC_TANKVOLUME_NONE ;
.Va workpressure , .Va workpressure ,
the work pressure in bar or zero if the work pressure in bar or zero if
@ -187,7 +187,7 @@ if the field was retrieved,
if the field is not supported by the device, or other error messages on if the field is not supported by the device, or other error messages on
further failure. further failure.
.Sh SEE ALSO .Sh SEE ALSO
.Xr dc_parser_set_data 3 .Xr dc_parser_new 3
.Sh AUTHORS .Sh AUTHORS
The The
.Lb libdivecomputer .Lb libdivecomputer

View File

@ -39,8 +39,6 @@
.Fa "dc_parser_t **parser" .Fa "dc_parser_t **parser"
.Fa "dc_context_t *context" .Fa "dc_context_t *context"
.Fa "dc_descriptor_t *descriptor" .Fa "dc_descriptor_t *descriptor"
.Fa "unsigned int devtime"
.Fa "dc_ticks_t systime"
.Fc .Fc
.Sh DESCRIPTION .Sh DESCRIPTION
Creates a parser for a single dive extracted from the dive computer with Creates a parser for a single dive extracted from the dive computer with
@ -55,10 +53,6 @@ parameter; and
.Nm dc_parser_new2 , .Nm dc_parser_new2 ,
which is given device values (model, etc.) directly. which is given device values (model, etc.) directly.
.Pp .Pp
After filling in the
.Fa parser
parameter, one usually sets parser data with
.Xr dc_parser_set_data 3 .
The pointer must later be freed with The pointer must later be freed with
.Xr dc_parser_destroy 3 . .Xr dc_parser_destroy 3 .
.Sh RETURN VALUES .Sh RETURN VALUES

View File

@ -31,7 +31,7 @@
.Ft "typedef void" .Ft "typedef void"
.Fo "(*dc_sample_callback_t)" .Fo "(*dc_sample_callback_t)"
.Fa "dc_sample_type_t type" .Fa "dc_sample_type_t type"
.Fa "dc_sample_value_t value" .Fa "const dc_sample_value_t *value"
.Fa "void *userdata" .Fa "void *userdata"
.Fc .Fc
.Ft dc_status_t .Ft dc_status_t
@ -42,7 +42,7 @@
.Fc .Fc
.Sh DESCRIPTION .Sh DESCRIPTION
Extract the samples taken during a dive as previously initialised with Extract the samples taken during a dive as previously initialised with
.Xr dc_parser_set_data 3 . .Xr dc_parser_new 3 .
Each sample is passed to Each sample is passed to
.Fa callback .Fa callback
with the with the
@ -63,7 +63,7 @@ closed.
The following sample types may be raised: The following sample types may be raised:
.Bl -tag -width Ds .Bl -tag -width Ds
.It Dv DC_SAMPLE_TIME .It Dv DC_SAMPLE_TIME
The time of the sample taken in seconds after the dive began. The time of the sample taken in milliseconds after the dive began.
Set in the Set in the
.Fa time .Fa time
field. field.
@ -126,7 +126,7 @@ Sets the
.Fa rbt .Fa rbt
field. field.
.It Dv DC_SAMPLE_HEARTBEAT .It Dv DC_SAMPLE_HEARTBEAT
The diver's heartbeet in beats per minute. The diver's heartbeat in beats per minute.
Sets the Sets the
.Fa heartbeat .Fa heartbeat
field. field.
@ -184,7 +184,7 @@ Returns
.Dv DC_STATUS_OK .Dv DC_STATUS_OK
on success and another code on failure. on success and another code on failure.
.Sh SEE ALSO .Sh SEE ALSO
.Xr dc_parser_set_data 3 .Xr dc_parser_new 3
.Sh AUTHORS .Sh AUTHORS
The The
.Lb libdivecomputer .Lb libdivecomputer

View File

@ -0,0 +1,52 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_SERIAL_DEVICE_FREE 3
.Os
.Sh NAME
.Nm dc_serial_device_free
.Nd Destroy the serial device and free all resources.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/serial.h
.Ft void
.Fo dc_serial_device_free
.Fa "dc_serial_device_t *device"
.Fc
.Sh DESCRIPTION
Destroy the serial device and free all resources.
The serial
.Fa device
usually found by searching through
.Xr dc_serial_iterator_new 3 .
.Sh SEE ALSO
.Xr dc_serial_iterator_new 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -0,0 +1,59 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_SERIAL_DEVICE_GET_NAME 3
.Os
.Sh NAME
.Nm dc_serial_device_get_name
.Nd Get the device name of the serial device.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/serial.h
.Ft "const char *"
.Fo dc_serial_device_get_name
.Fa "dc_serial_device_t *device"
.Fc
.Sh DESCRIPTION
Get the device node of the serial device. Used when opening serial transport with
.Xr dc_serial_open 3 .
Requires a valid serial
.Fa device
of type
.Ft dc_serial_device_t
which can be retrieved using
.Xr dc_serial_iterator_new 3 .
.Sh RETURN VALUES
Returns the device name of given serial
.Fa device
.Sh SEE ALSO
.Xr dc_serial_open 3 ,
.Xr dc_serial_iterator_new 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -0,0 +1,99 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_SERIAL_ITERATOR_NEW 3
.Os
.Sh NAME
.Nm dc_serial_iterator_new
.Nd Create an iterator to enumerate the serial devices.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/serial.h
.Ft dc_status_t
.Fo dc_serial_iterator_new
.Fa "dc_iterator_t **iterator"
.Fa "dc_context_t *context"
.Fa "dc_descriptor_t *descriptor"
.Fc
.Sh DESCRIPTION
Iterates through the available serial devices matching the given
.Fa descriptor .
Accepts a
.Fa context
opened with
.Xr dc_context_new 3
and a
.Fa descriptor
usually found by searching through
.Xr dc_descriptor_iterator 3 .
.Pp
On returning
.Dv DC_STATUS_SUCCESS
the
.Fa iterator
will be set to an
.Ft dc_iterator_t
which can be used to iterate the available serial devices using
.Xr dc_iterator_next 3 .
.Pp
The value type of the iterator is of type
.Ft dc_serial_device_t .
This value can be used in functions to extract information about this specific serial device, namely
.Xr dc_serial_device_get_name 3
When done the serial device needs to be freed with
.Xr dc_serial_device_free 3 .
.Pp
After iterating the
.Fa iterator
needs to be freed using
.Xr dc_iterator_free 3 .
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_SUCCESS
on success, or another
.Ft dc_status_t
code on failure.
On
.Dv DC_STATUS_SUCCESS
the returned
.Fa iterator
needs to be freed when done using
.Xr dc_iterator_free 3 .
.Sh SEE ALSO
.Xr dc_context_new 3 ,
.Xr dc_usbhid_iterator_new 3 ,
.Xr dc_irda_iterator_new 3 ,
.Xr dc_bluetooth_iterator_new 3 ,
.Xr dc_serial_device_get_name 3 ,
.Xr dc_serial_device_free 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

80
doc/man/dc_serial_open.3 Normal file
View File

@ -0,0 +1,80 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_SERIAL_OPEN 3
.Os
.Sh NAME
.Nm dc_serial_open
.Nd Opens an iostream for a serial device
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/serial.h
.Ft dc_status_t
.Fo dc_serial_open
.Fa "dc_iostream_t **iostream"
.Fa "dc_context_t *context"
.Fa "const char *name"
.Fc
.Sh DESCRIPTION
Opens an iostream for a serial device.
Accepts a
.Fa context
opened with
.Xr dc_context_new 3
and a
.Fa name
device name, usually found through
.Xr dc_serial_iterator_new 3
with
.Xr dc_serial_device_get_name 3 .
.Pp
Upon returning
.Dv DC_STATUS_SUCCESS ,
the
.Fa iostream
pointer must be freed with
.Xr dc_iostream_close 3 .
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_SUCCESS
on success or one of several error values on error.
On success, the
.Fa iostream
pointer is filled in with an open handle.
.Sh SEE ALSO
.Xr dc_context_new 3 ,
.Xr dc_iostream_close 3 ,
.Xr dc_usbhid_open 3 ,
.Xr dc_irda_open 3 ,
.Xr dc_bluetooth_open 3 ,
.Xr dc_serial_iterator_new 3 ,
.Xr dc_serial_device_get_name 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -0,0 +1,52 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_USBHID_DEVICE_FREE 3
.Os
.Sh NAME
.Nm dc_usbhid_device_free
.Nd Destroy the USB HID device and free all resources.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/usbhid.h
.Ft void
.Fo dc_usbhid_device_free
.Fa "dc_usbhid_device_t *device"
.Fc
.Sh DESCRIPTION
Destroy the USB HID device and free all resources.
The usbhid
.Fa device
usually found by searching through
.Xr dc_usbhid_iterator_new 3 .
.Sh SEE ALSO
.Xr dc_usbhid_iterator_new 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -0,0 +1,58 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_USBHID_DEVICE_GET_PID 3
.Os
.Sh NAME
.Nm dc_usbhid_device_get_pid
.Nd Get the product id (PID) of the USB HID device.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/usbhid.h
.Ft "unsigned int"
.Fo dc_usbhid_device_get_pid
.Fa "dc_usbhid_device_t *device"
.Fc
.Sh DESCRIPTION
Get the product id (PID) of the USB HID device. Used for displaying.
Requires a valid usbhid
.Fa device
of type
.Ft dc_usbhid_device_t
which can be retrieved using
.Xr dc_usbhid_iterator_new 3 .
.Sh RETURN VALUES
Returns the product id (PID) of given
.Fa usbhid_device
.Sh SEE ALSO
.Xr dc_usbhid_device_get_vid 3 ,
.Xr dc_usbhid_iterator_new 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -0,0 +1,58 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_USBHID_DEVICE_GET_VID 3
.Os
.Sh NAME
.Nm dc_usbhid_device_get_vid
.Nd Get the vendor id (VID) of the USB HID device.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/usbhid.h
.Ft "unsigned int"
.Fo dc_usbhid_device_get_vid
.Fa "dc_usbhid_device_t *device"
.Fc
.Sh DESCRIPTION
Get the vendor id (VID) of the USB HID device. Used for displaying.
Requires a valid usbhid
.Fa device
of type
.Ft dc_usbhid_device_t
which can be retrieved using
.Xr dc_usbhid_iterator_new 3 .
.Sh RETURN VALUES
Returns the vendor id (VID) of given usbhid
.Fa device
.Sh SEE ALSO
.Xr dc_usbhid_device_get_vid 3 ,
.Xr dc_usbhid_iterator_new 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -0,0 +1,101 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_USBHID_ITERATOR_NEW 3
.Os
.Sh NAME
.Nm dc_usbhid_iterator_new
.Nd Create an iterator to enumerate the USB HID devices.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/usbhid.h
.Ft dc_status_t
.Fo dc_usbhid_iterator_new
.Fa "dc_iterator_t **iterator"
.Fa "dc_context_t *context"
.Fa "dc_descriptor_t *descriptor"
.Fc
.Sh DESCRIPTION
Iterates through the available USB HID devices matching the given
.Fa descriptor .
Accepts a
.Fa context
opened with
.Xr dc_context_new 3
and a
.Fa descriptor
usually found by searching through
.Xr dc_descriptor_iterator 3 .
.Pp
On returning
.Dv DC_STATUS_SUCCESS
the
.Fa iterator
will be set to an
.Ft dc_iterator_t
which can be used to iterate the available USB HID devices using
.Xr dc_iterator_next 3 .
.Pp
The value type of the iterator is of type
.Ft dc_usbhid_device_t .
This value can be used in functions to extract information about this specific USB HID device, namely
.Xr dc_usbhid_device_get_pid 3
and
.Xr dc_usbhid_device_get_vid 3 .
When done the USB HID device needs to be freed with
.Xr dc_usbhid_device_free 3 .
.Pp
After iterating the
.Fa iterator
needs to be freed using
.Xr dc_iterator_free 3 .
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_SUCCESS
on success, or another
.Ft dc_status_t
code on failure.
On
.Dv DC_STATUS_SUCCESS
the returned
.Fa iterator
needs to be freed when done using
.Xr dc_iterator_free 3 .
.Sh SEE ALSO
.Xr dc_context_new 3 ,
.Xr dc_bluetooth_iterator_new 3 ,
.Xr dc_serial_iterator_new 3 ,
.Xr dc_irda_iterator_new 3 ,
.Xr dc_usbhid_device_get_pid 3 ,
.Xr dc_usbhid_device_get_vid 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

77
doc/man/dc_usbhid_open.3 Normal file
View File

@ -0,0 +1,77 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2020 Vincent Hagen <vinnie@script4web.nl>
.\"
.\" 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
.\"
.Dd June 5, 2020
.Dt DC_USBHID_OPEN 3
.Os
.Sh NAME
.Nm dc_usbhid_open
.Nd Opens an iostream for a USB HID device
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/usbhid.h
.Ft dc_status_t
.Fo dc_usbhid_open
.Fa "dc_iostream_t **iostream"
.Fa "dc_context_t *context"
.Fa "dc_usbhid_device_t *device"
.Fc
.Sh DESCRIPTION
Opens an iostream for a USB HID device.
Accepts a
.Fa context
opened with
.Xr dc_context_new 3
and a
.Fa device
usually found by searching through
.Xr dc_usbhid_iterator_new 3 .
.Pp
Upon returning
.Dv DC_STATUS_SUCCESS ,
the
.Fa iostream
pointer must be freed with
.Xr dc_iostream_close 3 .
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_SUCCESS
on success or one of several error values on error.
On success, the
.Fa iostream
pointer is filled in with an open handle.
.Sh SEE ALSO
.Xr dc_context_new 3 ,
.Xr dc_usbhid_iterator_new 3 ,
.Xr dc_iostream_close 3 ,
.Xr dc_serial_open 3 ,
.Xr dc_irda_open 3 ,
.Xr dc_bluetooth_open 3 .
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
This manpage is written by
.An Vincent Hagen ,
.Mt vinnie@script4web.nl .

View File

@ -41,9 +41,8 @@ these steps:
.Bl -enum .Bl -enum
.It .It
Create a new context with Create a new context with
.Xr dc_context_new 3 . .Xr dc_context_new 3
This supplies a parse context: logging, error handling, etc. to initialize the library. Logging can be controlled with
Override the values with
.Xr dc_context_set_logfunc 3 .Xr dc_context_set_logfunc 3
and and
.Xr dc_context_set_loglevel 3 . .Xr dc_context_set_loglevel 3 .
@ -52,11 +51,28 @@ Find a descriptor for their dive computer by iterating through
.Xr dc_descriptor_iterator 3 .Xr dc_descriptor_iterator 3
and searching by name, vendor, or product family. and searching by name, vendor, or product family.
.It .It
Open the hardware device to which the dive computer is connected with Find the transport to use for the communication. To determine the supported transports use
.Xr dc_device_open 3 , .Xr dc_descriptor_get_transports 3 .
then invoke .It
Find the hardware device corresponding to the connected dive computer by iterating through
.Xr dc_usbhid_iterator_new 3 ,
.Xr dc_serial_iterator_new 3 ,
.Xr dc_irda_iterator_new 3
or
.Xr dc_bluetooth_iterator_new 3 .
.It
Open the transport communcations with
.Xr dc_usbhid_open 3 ,
.Xr dc_serial_open 3 ,
.Xr dc_irda_open 3
or
.Xr dc_bluetooth_open 3 .
.It
Open a connection to the dive computer with
.Xr dc_device_open 3 .
Optionally use
.Xr dc_device_set_events 3 , .Xr dc_device_set_events 3 ,
.Xr dc_device_set_fingerprint 3 , .Xr dc_device_set_fingerprint 3
and and
.Xr dc_device_set_cancel 3 .Xr dc_device_set_cancel 3
to set the logging events, last-seen fingerprint, and cancel routine, to set the logging events, last-seen fingerprint, and cancel routine,
@ -66,13 +82,12 @@ Iterate over all dives with
.Xr dc_device_foreach 3 . .Xr dc_device_foreach 3 .
.It .It
For each iterated dive, create a new parser with For each iterated dive, create a new parser with
.Xr dc_parser_new 3 .Xr dc_parser_new 3 .
and set the parsed data with
.Xr dc_parser_set_data 3 .
.It .It
Get attributes of the parsed dive with Get attributes of the parsed dive with
.Xr dc_parser_get_field 3 , .Xr dc_parser_get_field 3 .
then iterate through the dive's samples (recorded data) with .It
Iterate through the dive's samples (recorded data) with
.Xr dc_parser_samples_foreach 3 . .Xr dc_parser_samples_foreach 3 .
.El .El
.Sh RETURN VALUES .Sh RETURN VALUES
@ -129,7 +144,10 @@ return
.Dv DC_STATUS_SUCCESS . .Dv DC_STATUS_SUCCESS .
.El .El
.Sh SEE ALSO .Sh SEE ALSO
.Xr dc_buffer_new 3 .Xr dc_context_new 3 ,
.Xr dc_descriptor_iterator 3
.Xr dc_device_open 3
.Xr dc_parser_new 3
.Sh AUTHORS .Sh AUTHORS
The The
.Lb libdivecomputer .Lb libdivecomputer

View File

@ -31,6 +31,7 @@
#include <libdivecomputer/serial.h> #include <libdivecomputer/serial.h>
#include <libdivecomputer/bluetooth.h> #include <libdivecomputer/bluetooth.h>
#include <libdivecomputer/irda.h> #include <libdivecomputer/irda.h>
#include <libdivecomputer/usb.h>
#include <libdivecomputer/usbhid.h> #include <libdivecomputer/usbhid.h>
#include "common.h" #include "common.h"
@ -71,6 +72,7 @@ static const backend_table_t g_backends[] = {
{"vtpro", DC_FAMILY_OCEANIC_VTPRO, 0x4245}, {"vtpro", DC_FAMILY_OCEANIC_VTPRO, 0x4245},
{"veo250", DC_FAMILY_OCEANIC_VEO250, 0x424C}, {"veo250", DC_FAMILY_OCEANIC_VEO250, 0x424C},
{"atom2", DC_FAMILY_OCEANIC_ATOM2, 0x4342}, {"atom2", DC_FAMILY_OCEANIC_ATOM2, 0x4342},
{"i330r", DC_FAMILY_PELAGIC_I330R, 0x4744},
{"nemo", DC_FAMILY_MARES_NEMO, 0}, {"nemo", DC_FAMILY_MARES_NEMO, 0},
{"puck", DC_FAMILY_MARES_PUCK, 7}, {"puck", DC_FAMILY_MARES_PUCK, 7},
{"darwin", DC_FAMILY_MARES_DARWIN, 0}, {"darwin", DC_FAMILY_MARES_DARWIN, 0},
@ -80,6 +82,7 @@ static const backend_table_t g_backends[] = {
{"ostc3", DC_FAMILY_HW_OSTC3, 0x0A}, {"ostc3", DC_FAMILY_HW_OSTC3, 0x0A},
{"edy", DC_FAMILY_CRESSI_EDY, 0x08}, {"edy", DC_FAMILY_CRESSI_EDY, 0x08},
{"leonardo", DC_FAMILY_CRESSI_LEONARDO, 1}, {"leonardo", DC_FAMILY_CRESSI_LEONARDO, 1},
{"goa", DC_FAMILY_CRESSI_GOA, 2},
{"n2ition3", DC_FAMILY_ZEAGLE_N2ITION3, 0}, {"n2ition3", DC_FAMILY_ZEAGLE_N2ITION3, 0},
{"cobalt", DC_FAMILY_ATOMICS_COBALT, 0}, {"cobalt", DC_FAMILY_ATOMICS_COBALT, 0},
{"predator", DC_FAMILY_SHEARWATER_PREDATOR, 2}, {"predator", DC_FAMILY_SHEARWATER_PREDATOR, 2},
@ -89,7 +92,17 @@ static const backend_table_t g_backends[] = {
{"idive", DC_FAMILY_DIVESYSTEM_IDIVE, 0x03}, {"idive", DC_FAMILY_DIVESYSTEM_IDIVE, 0x03},
{"cochran", DC_FAMILY_COCHRAN_COMMANDER, 0}, {"cochran", DC_FAMILY_COCHRAN_COMMANDER, 0},
{"divecomputereu", DC_FAMILY_TECDIVING_DIVECOMPUTEREU, 0}, {"divecomputereu", DC_FAMILY_TECDIVING_DIVECOMPUTEREU, 0},
{"descentmk1", DC_FAMILY_GARMIN, 0}, {"extreme", DC_FAMILY_MCLEAN_EXTREME, 0},
{"lynx", DC_FAMILY_LIQUIVISION_LYNX, 0},
{"sp2", DC_FAMILY_SPORASUB_SP2, 0},
{"excursion", DC_FAMILY_DEEPSIX_EXCURSION, 0},
{"screen", DC_FAMILY_SEAC_SCREEN, 0},
{"cosmiq", DC_FAMILY_DEEPBLU_COSMIQ, 0},
{"s1", DC_FAMILY_OCEANS_S1, 0},
{"freedom", DC_FAMILY_DIVESOFT_FREEDOM, 19},
// Not merged upstream yet
{"descentmk1", DC_FAMILY_GARMIN, 0},
}; };
static const transport_table_t g_transports[] = { static const transport_table_t g_transports[] = {
@ -99,6 +112,8 @@ static const transport_table_t g_transports[] = {
{"irda", DC_TRANSPORT_IRDA}, {"irda", DC_TRANSPORT_IRDA},
{"bluetooth", DC_TRANSPORT_BLUETOOTH}, {"bluetooth", DC_TRANSPORT_BLUETOOTH},
{"ble", DC_TRANSPORT_BLE}, {"ble", DC_TRANSPORT_BLE},
// Not merged upstream yet
{"usbstorage",DC_TRANSPORT_USBSTORAGE}, {"usbstorage",DC_TRANSPORT_USBSTORAGE},
}; };
@ -397,6 +412,41 @@ dctool_file_read (const char *filename)
return buffer; return buffer;
} }
static dc_status_t
dctool_usb_open (dc_iostream_t **out, dc_context_t *context, dc_descriptor_t *descriptor)
{
dc_status_t status = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
// Discover the usb device.
dc_iterator_t *iterator = NULL;
dc_usb_device_t *device = NULL;
dc_usb_iterator_new (&iterator, context, descriptor);
while (dc_iterator_next (iterator, &device) == DC_STATUS_SUCCESS) {
break;
}
dc_iterator_free (iterator);
if (device == NULL) {
ERROR ("No dive computer found.");
status = DC_STATUS_NODEVICE;
goto cleanup;
}
// Open the usb device.
status = dc_usb_open (&iostream, context, device);
if (status != DC_STATUS_SUCCESS) {
ERROR ("Failed to open the usb device.");
goto cleanup;
}
*out = iostream;
cleanup:
dc_usb_device_free (device);
return status;
}
static dc_status_t static dc_status_t
dctool_usbhid_open (dc_iostream_t **out, dc_context_t *context, dc_descriptor_t *descriptor) dctool_usbhid_open (dc_iostream_t **out, dc_context_t *context, dc_descriptor_t *descriptor)
{ {
@ -531,16 +581,18 @@ dctool_iostream_open (dc_iostream_t **iostream, dc_context_t *context, dc_descri
case DC_TRANSPORT_SERIAL: case DC_TRANSPORT_SERIAL:
return dc_serial_open (iostream, context, devname); return dc_serial_open (iostream, context, devname);
case DC_TRANSPORT_USB: case DC_TRANSPORT_USB:
return DC_STATUS_SUCCESS; return dctool_usb_open(iostream, context, descriptor);
case DC_TRANSPORT_USBHID: case DC_TRANSPORT_USBHID:
return dctool_usbhid_open(iostream, context, descriptor); return dctool_usbhid_open(iostream, context, descriptor);
case DC_TRANSPORT_IRDA: case DC_TRANSPORT_IRDA:
return dctool_irda_open (iostream, context, descriptor, devname); return dctool_irda_open (iostream, context, descriptor, devname);
case DC_TRANSPORT_BLUETOOTH: case DC_TRANSPORT_BLUETOOTH:
return dctool_bluetooth_open (iostream, context, descriptor, devname); return dctool_bluetooth_open (iostream, context, descriptor, devname);
case DC_TRANSPORT_USBSTORAGE:
return dc_usb_storage_open (iostream, context, devname);
default: default:
return DC_STATUS_UNSUPPORTED; return DC_STATUS_UNSUPPORTED;
// Not merged upstream yet
case DC_TRANSPORT_USBSTORAGE:
return dc_usb_storage_open (iostream, context, devname);
} }
} }

View File

@ -24,10 +24,12 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <signal.h> #include <signal.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H #ifdef HAVE_GETOPT_H
#include <getopt.h> #include <getopt.h>
#endif #endif
@ -48,7 +50,7 @@
#define RESET 1 #define RESET 1
#endif #endif
#if defined(__GLIBC__) || defined(__MINGW32__) || defined(BSD) #if defined(__GLIBC__) || defined(__MINGW32__) || defined(BSD) || defined(__ANDROID__)
#define NOPERMUTATION "+" #define NOPERMUTATION "+"
#else #else
#define NOPERMUTATION "" #define NOPERMUTATION ""
@ -240,7 +242,8 @@ main (int argc, char *argv[])
} }
// Translate the help option into a command. // Translate the help option into a command.
char *argv_help[] = {(char *) "help", NULL, NULL}; char helpcmd[] = "help";
char *argv_help[] = {helpcmd, NULL, NULL};
if (help || argv[0] == NULL) { if (help || argv[0] == NULL) {
if (argv[0]) { if (argv[0]) {
argv_help[1] = argv[0]; argv_help[1] = argv[0];

View File

@ -24,9 +24,11 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H #ifdef HAVE_GETOPT_H
#include <getopt.h> #include <getopt.h>
#endif #endif
@ -78,20 +80,12 @@ dive_cb (const unsigned char *data, unsigned int size, const unsigned char *fing
// Create the parser. // Create the parser.
message ("Creating the parser.\n"); message ("Creating the parser.\n");
rc = dc_parser_new (&parser, divedata->device); rc = dc_parser_new (&parser, divedata->device, data, size);
if (rc != DC_STATUS_SUCCESS) { if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error creating the parser."); ERROR ("Error creating the parser.");
goto cleanup; goto cleanup;
} }
// Register the data.
message ("Registering the data.\n");
rc = dc_parser_set_data (parser, data, size);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error registering the data.");
goto cleanup;
}
// Parse the dive data. // Parse the dive data.
message ("Parsing the dive data.\n"); message ("Parsing the dive data.\n");
rc = dctool_output_write (divedata->output, parser, data, size, fingerprint, fsize); rc = dctool_output_write (divedata->output, parser, data, size, fingerprint, fsize);

View File

@ -24,9 +24,11 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H #ifdef HAVE_GETOPT_H
#include <getopt.h> #include <getopt.h>
#endif #endif

View File

@ -24,8 +24,10 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H #ifdef HAVE_GETOPT_H
#include <getopt.h> #include <getopt.h>
#endif #endif
@ -35,6 +37,7 @@
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/hw_ostc.h> #include <libdivecomputer/hw_ostc.h>
#include <libdivecomputer/hw_ostc3.h> #include <libdivecomputer/hw_ostc3.h>
#include <libdivecomputer/divesystem_idive.h>
#include "dctool.h" #include "dctool.h"
#include "common.h" #include "common.h"
@ -91,7 +94,10 @@ fwupdate (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t tra
rc = hw_ostc_device_fwupdate (device, hexfile); rc = hw_ostc_device_fwupdate (device, hexfile);
break; break;
case DC_FAMILY_HW_OSTC3: case DC_FAMILY_HW_OSTC3:
rc = hw_ostc3_device_fwupdate (device, hexfile); rc = hw_ostc3_device_fwupdate (device, hexfile, false);
break;
case DC_FAMILY_DIVESYSTEM_IDIVE:
rc = divesystem_idive_device_fwupdate (device, hexfile);
break; break;
default: default:
rc = DC_STATUS_UNSUPPORTED; rc = DC_STATUS_UNSUPPORTED;

View File

@ -24,8 +24,10 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H #ifdef HAVE_GETOPT_H
#include <getopt.h> #include <getopt.h>
#endif #endif

View File

@ -24,8 +24,10 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H #ifdef HAVE_GETOPT_H
#include <getopt.h> #include <getopt.h>
#endif #endif

View File

@ -24,9 +24,11 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H #ifdef HAVE_GETOPT_H
#include <getopt.h> #include <getopt.h>
#endif #endif
@ -52,17 +54,17 @@ parse (dc_buffer_t *buffer, dc_context_t *context, dc_descriptor_t *descriptor,
// Create the parser. // Create the parser.
message ("Creating the parser.\n"); message ("Creating the parser.\n");
rc = dc_parser_new2 (&parser, context, descriptor, devtime, systime); rc = dc_parser_new2 (&parser, context, descriptor, data, size);
if (rc != DC_STATUS_SUCCESS) { if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error creating the parser."); ERROR ("Error creating the parser.");
goto cleanup; goto cleanup;
} }
// Register the data. // Set the clock.
message ("Registering the data.\n"); message ("Setting the clock.\n");
rc = dc_parser_set_data (parser, data, size); rc = dc_parser_set_clock (parser, devtime, systime);
if (rc != DC_STATUS_SUCCESS) { if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) {
ERROR ("Error registering the data."); ERROR ("Error setting the clock.");
goto cleanup; goto cleanup;
} }
@ -152,7 +154,7 @@ dctool_parse_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
goto cleanup; goto cleanup;
} }
for (unsigned int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {
// Read the input file. // Read the input file.
buffer = dctool_file_read (argv[i]); buffer = dctool_file_read (argv[i]);
if (buffer == NULL) { if (buffer == NULL) {

View File

@ -24,8 +24,10 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H #ifdef HAVE_GETOPT_H
#include <getopt.h> #include <getopt.h>
#endif #endif

View File

@ -24,8 +24,10 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H #ifdef HAVE_GETOPT_H
#include <getopt.h> #include <getopt.h>
#endif #endif
@ -36,6 +38,7 @@
#include <libdivecomputer/serial.h> #include <libdivecomputer/serial.h>
#include <libdivecomputer/irda.h> #include <libdivecomputer/irda.h>
#include <libdivecomputer/bluetooth.h> #include <libdivecomputer/bluetooth.h>
#include <libdivecomputer/usb.h>
#include <libdivecomputer/usbhid.h> #include <libdivecomputer/usbhid.h>
#include "dctool.h" #include "dctool.h"
@ -59,6 +62,9 @@ scan (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transpo
case DC_TRANSPORT_BLUETOOTH: case DC_TRANSPORT_BLUETOOTH:
status = dc_bluetooth_iterator_new (&iterator, context, descriptor); status = dc_bluetooth_iterator_new (&iterator, context, descriptor);
break; break;
case DC_TRANSPORT_USB:
status = dc_usb_iterator_new (&iterator, context, descriptor);
break;
case DC_TRANSPORT_USBHID: case DC_TRANSPORT_USBHID:
status = dc_usbhid_iterator_new (&iterator, context, descriptor); status = dc_usbhid_iterator_new (&iterator, context, descriptor);
break; break;
@ -90,6 +96,10 @@ scan (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transpo
dc_bluetooth_device_get_name (device)); dc_bluetooth_device_get_name (device));
dc_bluetooth_device_free (device); dc_bluetooth_device_free (device);
break; break;
case DC_TRANSPORT_USB:
printf ("%04x:%04x\n", dc_usb_device_get_vid (device), dc_usb_device_get_pid (device));
dc_usb_device_free (device);
break;
case DC_TRANSPORT_USBHID: case DC_TRANSPORT_USBHID:
printf ("%04x:%04x\n", dc_usbhid_device_get_vid (device), dc_usbhid_device_get_pid (device)); printf ("%04x:%04x\n", dc_usbhid_device_get_vid (device), dc_usbhid_device_get_pid (device));
dc_usbhid_device_free (device); dc_usbhid_device_free (device);
@ -150,7 +160,7 @@ dctool_scan_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
// Show help message. // Show help message.
if (help) { if (help) {
dctool_command_showhelp (&dctool_list); dctool_command_showhelp (&dctool_scan);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -24,8 +24,10 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H #ifdef HAVE_GETOPT_H
#include <getopt.h> #include <getopt.h>
#endif #endif

View File

@ -24,8 +24,10 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H #ifdef HAVE_GETOPT_H
#include <getopt.h> #include <getopt.h>
#endif #endif

View File

@ -24,8 +24,10 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H #ifdef HAVE_GETOPT_H
#include <getopt.h> #include <getopt.h>
#endif #endif

View File

@ -80,7 +80,7 @@ mktemplate_datetime (char *buffer, size_t size, dc_parser_t *parser)
n = snprintf (buffer, size, "%04i%02i%02iT%02i%02i%02i", n = snprintf (buffer, size, "%04i%02i%02iT%02i%02i%02i",
datetime.year, datetime.month, datetime.day, datetime.year, datetime.month, datetime.day,
datetime.hour, datetime.minute, datetime.second); datetime.hour, datetime.minute, datetime.second);
if (n < 0 || n >= size) if (n < 0 || (size_t) n >= size)
return -1; return -1;
return n; return n;
@ -92,7 +92,7 @@ mktemplate_number (char *buffer, size_t size, unsigned int number)
int n = 0; int n = 0;
n = snprintf (buffer, size, "%04u", number); n = snprintf (buffer, size, "%04u", number);
if (n < 0 || n >= size) if (n < 0 || (size_t) n >= size)
return -1; return -1;
return n; return n;

View File

@ -90,7 +90,7 @@ convert_volume (double value, dctool_units_t units)
} }
static void static void
sample_cb (dc_sample_type_t type, dc_sample_value_t value, void *userdata) sample_cb (dc_sample_type_t type, const dc_sample_value_t *value, void *userdata)
{ {
static const char *events[] = { static const char *events[] = {
"none", "deco", "rbt", "ascent", "ceiling", "workload", "transmitter", "none", "deco", "rbt", "ascent", "ceiling", "workload", "transmitter",
@ -104,64 +104,80 @@ sample_cb (dc_sample_type_t type, dc_sample_value_t value, void *userdata)
sample_data_t *sampledata = (sample_data_t *) userdata; sample_data_t *sampledata = (sample_data_t *) userdata;
unsigned int seconds = 0, milliseconds = 0;
switch (type) { switch (type) {
case DC_SAMPLE_TIME: case DC_SAMPLE_TIME:
seconds = value->time / 1000;
milliseconds = value->time % 1000;
if (sampledata->nsamples++) if (sampledata->nsamples++)
fprintf (sampledata->ostream, "</sample>\n"); fprintf (sampledata->ostream, "</sample>\n");
fprintf (sampledata->ostream, "<sample>\n"); fprintf (sampledata->ostream, "<sample>\n");
fprintf (sampledata->ostream, " <time>%02u:%02u</time>\n", value.time / 60, value.time % 60); if (milliseconds) {
fprintf (sampledata->ostream, " <time>%02u:%02u.%03u</time>\n", seconds / 60, seconds % 60, milliseconds);
} else {
fprintf (sampledata->ostream, " <time>%02u:%02u</time>\n", seconds / 60, seconds % 60);
}
break; break;
case DC_SAMPLE_DEPTH: case DC_SAMPLE_DEPTH:
fprintf (sampledata->ostream, " <depth>%.2f</depth>\n", fprintf (sampledata->ostream, " <depth>%.2f</depth>\n",
convert_depth(value.depth, sampledata->units)); convert_depth(value->depth, sampledata->units));
break; break;
case DC_SAMPLE_PRESSURE: case DC_SAMPLE_PRESSURE:
fprintf (sampledata->ostream, " <pressure tank=\"%u\">%.2f</pressure>\n", fprintf (sampledata->ostream, " <pressure tank=\"%u\">%.2f</pressure>\n",
value.pressure.tank, value->pressure.tank,
convert_pressure(value.pressure.value, sampledata->units)); convert_pressure(value->pressure.value, sampledata->units));
break; break;
case DC_SAMPLE_TEMPERATURE: case DC_SAMPLE_TEMPERATURE:
fprintf (sampledata->ostream, " <temperature>%.2f</temperature>\n", fprintf (sampledata->ostream, " <temperature>%.2f</temperature>\n",
convert_temperature(value.temperature, sampledata->units)); convert_temperature(value->temperature, sampledata->units));
break; break;
case DC_SAMPLE_EVENT: case DC_SAMPLE_EVENT:
if (value.event.type != SAMPLE_EVENT_GASCHANGE && value.event.type != SAMPLE_EVENT_GASCHANGE2) { if (value->event.type != SAMPLE_EVENT_GASCHANGE && value->event.type != SAMPLE_EVENT_GASCHANGE2) {
fprintf (sampledata->ostream, " <event type=\"%u\" time=\"%u\" flags=\"%u\" value=\"%u\">%s</event>\n", fprintf (sampledata->ostream, " <event type=\"%u\" time=\"%u\" flags=\"%u\" value=\"%u\">%s</event>\n",
value.event.type, value.event.time, value.event.flags, value.event.value, events[value.event.type]); value->event.type, value->event.time, value->event.flags, value->event.value, events[value->event.type]);
} }
break; break;
case DC_SAMPLE_RBT: case DC_SAMPLE_RBT:
fprintf (sampledata->ostream, " <rbt>%u</rbt>\n", value.rbt); fprintf (sampledata->ostream, " <rbt>%u</rbt>\n", value->rbt);
break; break;
case DC_SAMPLE_HEARTBEAT: case DC_SAMPLE_HEARTBEAT:
fprintf (sampledata->ostream, " <heartbeat>%u</heartbeat>\n", value.heartbeat); fprintf (sampledata->ostream, " <heartbeat>%u</heartbeat>\n", value->heartbeat);
break; break;
case DC_SAMPLE_BEARING: case DC_SAMPLE_BEARING:
fprintf (sampledata->ostream, " <bearing>%u</bearing>\n", value.bearing); fprintf (sampledata->ostream, " <bearing>%u</bearing>\n", value->bearing);
break; break;
case DC_SAMPLE_VENDOR: case DC_SAMPLE_VENDOR:
fprintf (sampledata->ostream, " <vendor type=\"%u\" size=\"%u\">", value.vendor.type, value.vendor.size); fprintf (sampledata->ostream, " <vendor type=\"%u\" size=\"%u\">", value->vendor.type, value->vendor.size);
for (unsigned int i = 0; i < value.vendor.size; ++i) for (unsigned int i = 0; i < value->vendor.size; ++i)
fprintf (sampledata->ostream, "%02X", ((const unsigned char *) value.vendor.data)[i]); fprintf (sampledata->ostream, "%02X", ((const unsigned char *) value->vendor.data)[i]);
fprintf (sampledata->ostream, "</vendor>\n"); fprintf (sampledata->ostream, "</vendor>\n");
break; break;
case DC_SAMPLE_SETPOINT: case DC_SAMPLE_SETPOINT:
fprintf (sampledata->ostream, " <setpoint>%.2f</setpoint>\n", value.setpoint); fprintf (sampledata->ostream, " <setpoint>%.2f</setpoint>\n", value->setpoint);
break; break;
case DC_SAMPLE_PPO2: case DC_SAMPLE_PPO2:
fprintf (sampledata->ostream, " <ppo2>%.2f</ppo2>\n", value.ppo2); if (value->ppo2.sensor != DC_SENSOR_NONE) {
fprintf (sampledata->ostream, " <ppo2 sensor=\"%u\">%.2f</ppo2>\n", value->ppo2.sensor, value->ppo2.value);
} else {
fprintf (sampledata->ostream, " <ppo2>%.2f</ppo2>\n", value->ppo2.value);
}
break; break;
case DC_SAMPLE_CNS: case DC_SAMPLE_CNS:
fprintf (sampledata->ostream, " <cns>%.1f</cns>\n", value.cns * 100.0); fprintf (sampledata->ostream, " <cns>%.1f</cns>\n", value->cns * 100.0);
break; break;
case DC_SAMPLE_DECO: case DC_SAMPLE_DECO:
fprintf (sampledata->ostream, " <deco time=\"%u\" depth=\"%.2f\">%s</deco>\n", fprintf (sampledata->ostream, " <deco time=\"%u\" depth=\"%.2f\">%s</deco>\n",
value.deco.time, value->deco.time,
convert_depth(value.deco.depth, sampledata->units), convert_depth(value->deco.depth, sampledata->units),
decostop[value.deco.type]); decostop[value->deco.type]);
if (value->deco.tts) {
fprintf (sampledata->ostream, " <tts>%u</tts>\n",
value->deco.tts);
}
break; break;
case DC_SAMPLE_GASMIX: case DC_SAMPLE_GASMIX:
fprintf (sampledata->ostream, " <gasmix>%u</gasmix>\n", value.gasmix); fprintf (sampledata->ostream, " <gasmix>%u</gasmix>\n", value->gasmix);
break; break;
default: default:
break; break;
@ -238,7 +254,7 @@ dctool_xml_output_write (dctool_output_t *abstract, dc_parser_t *parser, const u
fprintf (output->ostream, "<datetime>%04i-%02i-%02i %02i:%02i:%02i %+03i:%02i</datetime>\n", fprintf (output->ostream, "<datetime>%04i-%02i-%02i %02i:%02i:%02i %+03i:%02i</datetime>\n",
dt.year, dt.month, dt.day, dt.year, dt.month, dt.day,
dt.hour, dt.minute, dt.second, dt.hour, dt.minute, dt.second,
dt.timezone / 3600, (dt.timezone % 3600) / 60); dt.timezone / 3600, (abs(dt.timezone) % 3600) / 60);
} }
// Parse the divetime. // Parse the divetime.
@ -322,11 +338,19 @@ dctool_xml_output_write (dctool_output_t *abstract, dc_parser_t *parser, const u
"<gasmix>\n" "<gasmix>\n"
" <he>%.1f</he>\n" " <he>%.1f</he>\n"
" <o2>%.1f</o2>\n" " <o2>%.1f</o2>\n"
" <n2>%.1f</n2>\n" " <n2>%.1f</n2>\n",
"</gasmix>\n",
gasmix.helium * 100.0, gasmix.helium * 100.0,
gasmix.oxygen * 100.0, gasmix.oxygen * 100.0,
gasmix.nitrogen * 100.0); gasmix.nitrogen * 100.0);
if (gasmix.usage) {
const char *usage[] = {"none", "oxygen", "diluent", "sidemount"};
fprintf (output->ostream,
" <usage>%s</usage>\n",
usage[gasmix.usage]);
}
fprintf (output->ostream,
"</gasmix>\n");
} }
// Parse the tanks. // Parse the tanks.
@ -354,6 +378,12 @@ dctool_xml_output_write (dctool_output_t *abstract, dc_parser_t *parser, const u
" <gasmix>%u</gasmix>\n", " <gasmix>%u</gasmix>\n",
tank.gasmix); tank.gasmix);
} }
if (tank.usage) {
const char *usage[] = {"none", "oxygen", "diluent", "sidemount"};
fprintf (output->ostream,
" <usage>%s</usage>\n",
usage[tank.usage]);
}
if (tank.type != DC_TANKVOLUME_NONE) { if (tank.type != DC_TANKVOLUME_NONE) {
fprintf (output->ostream, fprintf (output->ostream,
" <type>%s</type>\n" " <type>%s</type>\n"
@ -386,6 +416,30 @@ dctool_xml_output_write (dctool_output_t *abstract, dc_parser_t *parser, const u
names[divemode]); names[divemode]);
} }
// Parse the deco model.
message ("Parsing the deco model.\n");
dc_decomodel_t decomodel = {DC_DECOMODEL_NONE};
status = dc_parser_get_field (parser, DC_FIELD_DECOMODEL, 0, &decomodel);
if (status != DC_STATUS_SUCCESS && status != DC_STATUS_UNSUPPORTED) {
ERROR ("Error parsing the deco model.");
goto cleanup;
}
if (status != DC_STATUS_UNSUPPORTED) {
const char *names[] = {"none", "buhlmann", "vpm", "rgbm", "dciem"};
fprintf (output->ostream, "<decomodel>%s</decomodel>\n",
names[decomodel.type]);
if (decomodel.type == DC_DECOMODEL_BUHLMANN &&
(decomodel.params.gf.low != 0 || decomodel.params.gf.high != 0)) {
fprintf (output->ostream, "<gf>%u/%u</gf>\n",
decomodel.params.gf.low, decomodel.params.gf.high);
}
if (decomodel.conservatism) {
fprintf (output->ostream, "<conservatism>%d</conservatism>\n",
decomodel.conservatism);
}
}
// Parse the salinity. // Parse the salinity.
message ("Parsing the salinity.\n"); message ("Parsing the salinity.\n");
dc_salinity_t salinity = {DC_WATER_FRESH, 0.0}; dc_salinity_t salinity = {DC_WATER_FRESH, 0.0};
@ -396,8 +450,14 @@ dctool_xml_output_write (dctool_output_t *abstract, dc_parser_t *parser, const u
} }
if (status != DC_STATUS_UNSUPPORTED) { if (status != DC_STATUS_UNSUPPORTED) {
fprintf (output->ostream, "<salinity type=\"%u\">%.1f</salinity>\n", const char *names[] = {"fresh", "salt"};
salinity.type, salinity.density); if (salinity.density) {
fprintf (output->ostream, "<salinity density=\"%.1f\">%s</salinity>\n",
salinity.density, names[salinity.type]);
} else {
fprintf (output->ostream, "<salinity>%s</salinity>\n",
names[salinity.type]);
}
} }
// Parse the atmospheric pressure. // Parse the atmospheric pressure.

View File

@ -26,6 +26,12 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#ifdef _MSC_VER
#define snprintf _snprintf
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#endif
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
#define FUNCTION __func__ #define FUNCTION __func__
#else #else

View File

@ -7,9 +7,12 @@ libdivecomputer_HEADERS = \
descriptor.h \ descriptor.h \
iterator.h \ iterator.h \
iostream.h \ iostream.h \
ioctl.h \
serial.h \ serial.h \
bluetooth.h \ bluetooth.h \
ble.h \
irda.h \ irda.h \
usb.h \
usbhid.h \ usbhid.h \
custom.h \ custom.h \
device.h \ device.h \
@ -28,4 +31,5 @@ libdivecomputer_HEADERS = \
hw_ostc.h \ hw_ostc.h \
hw_frog.h \ hw_frog.h \
hw_ostc3.h \ hw_ostc3.h \
atomics_cobalt.h atomics_cobalt.h \
divesystem_idive.h

View File

@ -36,9 +36,6 @@ atomics_cobalt_device_version (dc_device_t *device, unsigned char data[], unsign
dc_status_t dc_status_t
atomics_cobalt_device_set_simulation (dc_device_t *device, unsigned int simulation); atomics_cobalt_device_set_simulation (dc_device_t *device, unsigned int simulation);
dc_status_t
atomics_cobalt_parser_set_calibration (dc_parser_t *parser, double atmospheric, double hydrostatic);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -0,0 +1,54 @@
/*
* libdivecomputer
*
* Copyright (C) 2019 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
*/
#ifndef DC_BLE_H
#define DC_BLE_H
#include "ioctl.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
* Get the remote device name.
*/
#define DC_IOCTL_BLE_GET_NAME DC_IOCTL_IOR('b', 0, DC_IOCTL_SIZE_VARIABLE)
/**
* Get the bluetooth authentication PIN code.
*
* The data format is a NULL terminated string.
*/
#define DC_IOCTL_BLE_GET_PINCODE DC_IOCTL_IOR('b', 1, DC_IOCTL_SIZE_VARIABLE)
/**
* Get/set the bluetooth authentication access code.
*
* The data format is a variable sized byte array.
*/
#define DC_IOCTL_BLE_GET_ACCESSCODE DC_IOCTL_IOR('b', 2, DC_IOCTL_SIZE_VARIABLE)
#define DC_IOCTL_BLE_SET_ACCESSCODE DC_IOCTL_IOW('b', 2, DC_IOCTL_SIZE_VARIABLE)
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* DC_BLE_H */

View File

@ -51,6 +51,9 @@ dc_buffer_append (dc_buffer_t *buffer, const unsigned char data[], size_t size);
int int
dc_buffer_prepend (dc_buffer_t *buffer, const unsigned char data[], size_t size); dc_buffer_prepend (dc_buffer_t *buffer, const unsigned char data[], size_t size);
int
dc_buffer_insert (dc_buffer_t *buffer, size_t offset, const unsigned char data[], size_t size);
int int
dc_buffer_slice (dc_buffer_t *buffer, size_t offset, size_t size); dc_buffer_slice (dc_buffer_t *buffer, size_t offset, size_t size);

View File

@ -78,6 +78,7 @@ typedef enum dc_family_t {
DC_FAMILY_OCEANIC_VTPRO = (4 << 16), DC_FAMILY_OCEANIC_VTPRO = (4 << 16),
DC_FAMILY_OCEANIC_VEO250, DC_FAMILY_OCEANIC_VEO250,
DC_FAMILY_OCEANIC_ATOM2, DC_FAMILY_OCEANIC_ATOM2,
DC_FAMILY_PELAGIC_I330R,
/* Mares */ /* Mares */
DC_FAMILY_MARES_NEMO = (5 << 16), DC_FAMILY_MARES_NEMO = (5 << 16),
DC_FAMILY_MARES_PUCK, DC_FAMILY_MARES_PUCK,
@ -90,6 +91,7 @@ typedef enum dc_family_t {
/* Cressi */ /* Cressi */
DC_FAMILY_CRESSI_EDY = (7 << 16), DC_FAMILY_CRESSI_EDY = (7 << 16),
DC_FAMILY_CRESSI_LEONARDO, DC_FAMILY_CRESSI_LEONARDO,
DC_FAMILY_CRESSI_GOA,
/* Zeagle */ /* Zeagle */
DC_FAMILY_ZEAGLE_N2ITION3 = (8 << 16), DC_FAMILY_ZEAGLE_N2ITION3 = (8 << 16),
/* Atomic Aquatics */ /* Atomic Aquatics */
@ -107,8 +109,26 @@ typedef enum dc_family_t {
DC_FAMILY_COCHRAN_COMMANDER = (14 << 16), DC_FAMILY_COCHRAN_COMMANDER = (14 << 16),
/* Tecdiving */ /* Tecdiving */
DC_FAMILY_TECDIVING_DIVECOMPUTEREU = (15 << 16), DC_FAMILY_TECDIVING_DIVECOMPUTEREU = (15 << 16),
/* McLean */
DC_FAMILY_MCLEAN_EXTREME = (16 << 16),
/* Liquivision */
DC_FAMILY_LIQUIVISION_LYNX = (17 << 16),
/* Sporasub */
DC_FAMILY_SPORASUB_SP2 = (18 << 16),
/* Deep Six */
DC_FAMILY_DEEPSIX_EXCURSION = (19 << 16),
/* Seac Screen */
DC_FAMILY_SEAC_SCREEN = (20 << 16),
/* Deepblu Cosmiq */
DC_FAMILY_DEEPBLU_COSMIQ = (21 << 16),
/* Oceans S1 */
DC_FAMILY_OCEANS_S1 = (22 << 16),
/* Divesoft Freedom */
DC_FAMILY_DIVESOFT_FREEDOM = (23 << 16),
// Not merged upstream yet
/* Garmin */ /* Garmin */
DC_FAMILY_GARMIN = (16 << 16), DC_FAMILY_GARMIN = (100 << 16),
} dc_family_t; } dc_family_t;
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -32,15 +32,16 @@ extern "C" {
typedef struct dc_custom_cbs_t { typedef struct dc_custom_cbs_t {
dc_status_t (*set_timeout) (void *userdata, int timeout); dc_status_t (*set_timeout) (void *userdata, int timeout);
dc_status_t (*set_latency) (void *userdata, unsigned int value);
dc_status_t (*set_break) (void *userdata, unsigned int value); dc_status_t (*set_break) (void *userdata, unsigned int value);
dc_status_t (*set_dtr) (void *userdata, unsigned int value); dc_status_t (*set_dtr) (void *userdata, unsigned int value);
dc_status_t (*set_rts) (void *userdata, unsigned int value); dc_status_t (*set_rts) (void *userdata, unsigned int value);
dc_status_t (*get_lines) (void *userdata, unsigned int *value); dc_status_t (*get_lines) (void *userdata, unsigned int *value);
dc_status_t (*get_available) (void *userdata, size_t *value); dc_status_t (*get_available) (void *userdata, size_t *value);
dc_status_t (*configure) (void *userdata, unsigned int baudrate, unsigned int databits, dc_parity_t parity, dc_stopbits_t stopbits, dc_flowcontrol_t flowcontrol); dc_status_t (*configure) (void *userdata, unsigned int baudrate, unsigned int databits, dc_parity_t parity, dc_stopbits_t stopbits, dc_flowcontrol_t flowcontrol);
dc_status_t (*poll) (void *userdata, int timeout);
dc_status_t (*read) (void *userdata, void *data, size_t size, size_t *actual); dc_status_t (*read) (void *userdata, void *data, size_t size, size_t *actual);
dc_status_t (*write) (void *userdata, const void *data, size_t size, size_t *actual); dc_status_t (*write) (void *userdata, const void *data, size_t size, size_t *actual);
dc_status_t (*ioctl) (void *userdata, unsigned int request, void *data, size_t size);
dc_status_t (*flush) (void *userdata); dc_status_t (*flush) (void *userdata);
dc_status_t (*purge) (void *userdata, dc_direction_t direction); dc_status_t (*purge) (void *userdata, dc_direction_t direction);
dc_status_t (*sleep) (void *userdata, unsigned int milliseconds); dc_status_t (*sleep) (void *userdata, unsigned int milliseconds);

View File

@ -22,11 +22,13 @@
#ifndef DC_DATETIME_H #ifndef DC_DATETIME_H
#define DC_DATETIME_H #define DC_DATETIME_H
#include <limits.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#define DC_TIMEZONE_NONE 0x80000000 #define DC_TIMEZONE_NONE INT_MIN
#if defined (_WIN32) && !defined (__GNUC__) #if defined (_WIN32) && !defined (__GNUC__)
typedef __int64 dc_ticks_t; typedef __int64 dc_ticks_t;

View File

@ -29,29 +29,96 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/**
* Opaque object representing a supported dive computer.
*/
typedef struct dc_descriptor_t dc_descriptor_t; typedef struct dc_descriptor_t dc_descriptor_t;
/**
* Create an iterator to enumerate the supported dive computers.
*
* @param[out] iterator A location to store the iterator.
* @returns #DC_STATUS_SUCCESS on success, or another #dc_status_t code
* on failure.
*/
dc_status_t dc_status_t
dc_descriptor_iterator (dc_iterator_t **iterator); dc_descriptor_iterator (dc_iterator_t **iterator);
/**
* Free the device descriptor.
*
* @param[in] descriptor A valid device descriptor.
*/
void void
dc_descriptor_free (dc_descriptor_t *descriptor); dc_descriptor_free (dc_descriptor_t *descriptor);
/**
* Get the vendor name of the dive computer.
*
* @param[in] descriptor A valid device descriptor.
* @returns The vendor name of the dive computer on success, or NULL on failure.
*/
const char * const char *
dc_descriptor_get_vendor (dc_descriptor_t *descriptor); dc_descriptor_get_vendor (dc_descriptor_t *descriptor);
/**
* Get the product name of the dive computer.
*
* @param[in] descriptor A valid device descriptor.
* @returns The product name of the dive computer on success, or NULL on
* failure.
*/
const char * const char *
dc_descriptor_get_product (dc_descriptor_t *descriptor); dc_descriptor_get_product (dc_descriptor_t *descriptor);
/**
* Get the family type of the dive computer.
*
* @param[in] descriptor A valid device descriptor.
* @returns The family type of the dive computer on success, or DC_FAMILY_NULL
* on failure.
*/
dc_family_t dc_family_t
dc_descriptor_get_type (dc_descriptor_t *descriptor); dc_descriptor_get_type (dc_descriptor_t *descriptor);
/**
* Get the model number of the dive computer.
*
* @param[in] descriptor A valid device descriptor.
* @returns The model number of the dive computer on success, or zero on
* failure.
*/
unsigned int unsigned int
dc_descriptor_get_model (dc_descriptor_t *descriptor); dc_descriptor_get_model (dc_descriptor_t *descriptor);
/**
* Get all transports supported by the dive computer.
*
* @param[in] descriptor A valid device descriptor.
* @returns A bitmask with all the transports supported by the dive computer on
* success, or DC_TRANSPORT_NONE on failure.
*/
unsigned int unsigned int
dc_descriptor_get_transports (dc_descriptor_t *descriptor); dc_descriptor_get_transports (dc_descriptor_t *descriptor);
/**
* Check if a low-level I/O device matches a supported dive computer.
*
* @param[in] descriptor A valid device descriptor.
* @param[in] transport The transport type of the I/O device.
* @param[in] userdata A pointer to a transport specific data structure:
* - DC_TRANSPORT_SERIAL: Name of the device node (string)
* - DC_TRANSPORT_USB: USB VID/PID (#dc_usb_desc_t)
* - DC_TRANSPORT_USBHID: USB VID/PID (#dc_usbhid_desc_t)
* - DC_TRANSPORT_IRDA: IrDA device name (string)
* - DC_TRANSPORT_BLUETOOTH: Bluetooth device name (string)
* - DC_TRANSPORT_BLE: Bluetooth device name (string)
* @returns Non-zero if the device matches a supported dive computer, or zero if
* there is no match.
*/
int
dc_descriptor_filter (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -1,7 +1,7 @@
/* /*
* libdivecomputer * libdivecomputer
* *
* Copyright (C) 2017 Jef Driesen * Copyright (C) 2019 Jef Driesen
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -19,26 +19,20 @@
* MA 02110-1301 USA * MA 02110-1301 USA
*/ */
#ifndef DC_DESCRIPTOR_PRIVATE_H #ifndef DC_DIVESYSTEM_IDIVE_H
#define DC_DESCRIPTOR_PRIVATE_H #define DC_DIVESYSTEM_IDIVE_H
#include <libdivecomputer/descriptor.h> #include "common.h"
#include "device.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
typedef struct dc_usb_desc_t { dc_status_t
unsigned short vid; divesystem_idive_device_fwupdate (dc_device_t *abstract, const char *filename);
unsigned short pid;
} dc_usb_desc_t;
typedef int (*dc_filter_t) (dc_transport_t transport, const void *userdata);
dc_filter_t
dc_descriptor_get_filter (dc_descriptor_t *descriptor);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* DC_DESCRIPTOR_PRIVATE_H */ #endif /* DC_DIVESYSTEM_IDIVE_H */

View File

@ -22,6 +22,8 @@
#ifndef DC_HW_OSTC3_H #ifndef DC_HW_OSTC3_H
#define DC_HW_OSTC3_H #define DC_HW_OSTC3_H
#include <stdbool.h>
#include "common.h" #include "common.h"
#include "device.h" #include "device.h"
#include "datetime.h" #include "datetime.h"
@ -55,7 +57,7 @@ dc_status_t
hw_ostc3_device_config_reset (dc_device_t *abstract); hw_ostc3_device_config_reset (dc_device_t *abstract);
dc_status_t dc_status_t
hw_ostc3_device_fwupdate (dc_device_t *abstract, const char *filename); hw_ostc3_device_fwupdate (dc_device_t *abstract, const char *filename, bool forceUpdate);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -0,0 +1,73 @@
/*
* libdivecomputer
*
* Copyright (C) 2019 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
*/
#ifndef DC_IOCTL_H
#define DC_IOCTL_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/*
* Ioctl direction bits.
*
* Note: WRITE means the application is writing and the driver is
* reading. READ means the application is reading and the driver is
* writing.
*/
#define DC_IOCTL_DIR_NONE 0u
#define DC_IOCTL_DIR_READ 1u
#define DC_IOCTL_DIR_WRITE 2u
/*
* Ioctl variable size bits.
*/
#define DC_IOCTL_SIZE_VARIABLE 0
/*
* Helper macro to encode ioctl numbers.
*/
#define DC_IOCTL_BASE(dir,type,nr,size) \
(((dir) << 30) | \
((size) << 16) | \
((type) << 8) | \
((nr) << 0))
/*
* Macros to encode ioctl numbers.
*/
#define DC_IOCTL_IO(type,nr) DC_IOCTL_BASE(DC_IOCTL_DIR_NONE, (type), (nr), 0)
#define DC_IOCTL_IOR(type,nr,size) DC_IOCTL_BASE(DC_IOCTL_DIR_READ, (type), (nr), (size))
#define DC_IOCTL_IOW(type,nr,size) DC_IOCTL_BASE(DC_IOCTL_DIR_WRITE, (type), (nr), (size))
#define DC_IOCTL_IORW(type,nr,size) DC_IOCTL_BASE(DC_IOCTL_DIR_READ | DC_IOCTL_DIR_WRITE, (type), (nr), (size))
/*
* Macros to decode ioctl numbers.
*/
#define DC_IOCTL_DIR(request) (((request) >> 30) & 0x0003)
#define DC_IOCTL_SIZE(request) (((request) >> 16) & 0x3FFF)
#define DC_IOCTL_TYPE(request) (((request) >> 8) & 0x00FF)
#define DC_IOCTL_NR(request) (((request) >> 0) & 0x00FF)
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* DC_IOCTL_H */

View File

@ -123,22 +123,6 @@ dc_iostream_get_transport (dc_iostream_t *iostream);
dc_status_t dc_status_t
dc_iostream_set_timeout (dc_iostream_t *iostream, int timeout); dc_iostream_set_timeout (dc_iostream_t *iostream, int timeout);
/**
* Set the receive latency.
*
* The effect of this setting is highly platform and driver specific. On
* Windows it does nothing at all, on Linux it controls the low latency
* flag (e.g. only zero vs non-zero latency), and on Mac OS X it sets
* the receive latency as requested.
*
* @param[in] iostream A valid I/O stream.
* @param[in] value The latency in milliseconds.
* @returns #DC_STATUS_SUCCESS on success, or another #dc_status_t code
* on failure.
*/
dc_status_t
dc_iostream_set_latency (dc_iostream_t *iostream, unsigned int value);
/** /**
* Set the state of the break condition. * Set the state of the break condition.
* *
@ -211,6 +195,36 @@ dc_iostream_get_available (dc_iostream_t *iostream, size_t *value);
dc_status_t dc_status_t
dc_iostream_configure (dc_iostream_t *iostream, unsigned int baudrate, unsigned int databits, dc_parity_t parity, dc_stopbits_t stopbits, dc_flowcontrol_t flowcontrol); dc_iostream_configure (dc_iostream_t *iostream, unsigned int baudrate, unsigned int databits, dc_parity_t parity, dc_stopbits_t stopbits, dc_flowcontrol_t flowcontrol);
/**
* Poll the I/O stream for available data.
*
* There are three distinct modes available:
*
* 1. Blocking (timeout < 0):
*
* The poll operation is blocked until one or more bytes have been
* received. If no bytes are received, the operation will block
* forever.
*
* 2. Non-blocking (timeout == 0):
*
* The poll operation returns immediately, even if no bytes have
* been received.
*
* 3. Timeout (timeout > 0):
*
* The poll operation is blocked until one or more bytes have been
* received. If no bytes are received within the specified amount of
* time, the operation will return with a timeout.
*
* @param[in] iostream A valid I/O stream.
* @param[in] timeout The timeout in milliseconds.
* @returns #DC_STATUS_SUCCESS on success, #DC_STATUS_TIMEOUT on
* timeout, or another #dc_status_t code on failure.
*/
dc_status_t
dc_iostream_poll (dc_iostream_t *iostream, int timeout);
/** /**
* Read data from the I/O stream. * Read data from the I/O stream.
* *
@ -239,6 +253,19 @@ dc_iostream_read (dc_iostream_t *iostream, void *data, size_t size, size_t *actu
dc_status_t dc_status_t
dc_iostream_write (dc_iostream_t *iostream, const void *data, size_t size, size_t *actual); dc_iostream_write (dc_iostream_t *iostream, const void *data, size_t size, size_t *actual);
/**
* Perform an I/O stream specific request.
*
* @param[in] iostream A valid I/O stream.
* @param[in] request The request to perform.
* @param[in,out] data The request specific data.
* @param[in] size The size of the request specific data.
* @returns #DC_STATUS_SUCCESS on success, or another #dc_status_t code
* on failure.
*/
dc_status_t
dc_iostream_ioctl (dc_iostream_t *iostream, unsigned int request, void *data, size_t size);
/** /**
* Flush the internal output buffer and wait until the data has been * Flush the internal output buffer and wait until the data has been
* transmitted. * transmitted.

View File

@ -67,6 +67,7 @@ typedef enum dc_field_type_t {
DC_FIELD_TANK_COUNT, DC_FIELD_TANK_COUNT,
DC_FIELD_TANK, DC_FIELD_TANK,
DC_FIELD_DIVEMODE, DC_FIELD_DIVEMODE,
DC_FIELD_DECOMODEL,
DC_FIELD_STRING, DC_FIELD_STRING,
} dc_field_type_t; } dc_field_type_t;
@ -124,6 +125,17 @@ typedef enum parser_sample_flags_t {
#define SAMPLE_FLAGS_SEVERITY_WARN (3 << SAMPLE_FLAGS_SEVERITY_SHIFT) #define SAMPLE_FLAGS_SEVERITY_WARN (3 << SAMPLE_FLAGS_SEVERITY_SHIFT)
#define SAMPLE_FLAGS_SEVERITY_ALARM (4 << SAMPLE_FLAGS_SEVERITY_SHIFT) #define SAMPLE_FLAGS_SEVERITY_ALARM (4 << SAMPLE_FLAGS_SEVERITY_SHIFT)
/* these are used for the types of TAGs in Shearwater PNF info events */
#define SAMPLE_FLAGS_TYPE_SHIFT 5
#define SAMPLE_FLAGS_TYPE_MASK (7 << SAMPLE_FLAGS_TYPE_SHIFT)
#define SAMPLE_FLAGS_TYPE_NONE (0 << SAMPLE_FLAGS_TYPE_SHIFT)
#define SAMPLE_FLAGS_TYPE_INTEREST (1 << SAMPLE_FLAGS_TYPE_SHIFT)
#define SAMPLE_FLAGS_TYPE_NAVPOINT (2 << SAMPLE_FLAGS_TYPE_SHIFT)
#define SAMPLE_FLAGS_TYPE_DANGER (3 << SAMPLE_FLAGS_TYPE_SHIFT)
#define SAMPLE_FLAGS_TYPE_ANIMAL (4 << SAMPLE_FLAGS_TYPE_SHIFT)
#define SAMPLE_FLAGS_TYPE_ISSUE (5 << SAMPLE_FLAGS_TYPE_SHIFT)
#define SAMPLE_FLAGS_TYPE_INJURY (6 << SAMPLE_FLAGS_TYPE_SHIFT)
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,
@ -161,19 +173,26 @@ typedef struct dc_salinity_t {
double density; double density;
} dc_salinity_t; } dc_salinity_t;
typedef enum dc_usage_t {
DC_USAGE_NONE, // Usage not specified
DC_USAGE_OXYGEN,
DC_USAGE_DILUENT,
DC_USAGE_OPEN_CIRCUIT,
} dc_usage_t;
typedef struct dc_gasmix_t { typedef struct dc_gasmix_t {
double helium; double helium;
double oxygen; double oxygen;
double nitrogen; double nitrogen;
dc_usage_t usage;
} dc_gasmix_t; } dc_gasmix_t;
#define DC_SENSOR_NONE 0xFFFFFFFF
#define DC_GASMIX_UNKNOWN 0xFFFFFFFF #define DC_GASMIX_UNKNOWN 0xFFFFFFFF
typedef unsigned int dc_tankinfo_t; typedef unsigned int dc_tankinfo_t;
#define DC_TANKINFO_METRIC 1 #define DC_TANKINFO_METRIC 1
#define DC_TANKINFO_IMPERIAL 2 #define DC_TANKINFO_IMPERIAL 2
#define DC_TANKINFO_CC_DILUENT 4
#define DC_TANKINFO_CC_O2 8
// For backwards compatibility // For backwards compatibility
#define DC_TANKVOLUME_NONE 0 #define DC_TANKVOLUME_NONE 0
@ -203,6 +222,11 @@ typedef unsigned int dc_tankinfo_t;
* divide by 1 ATM (Vair = Vwater * Pwork / Patm). * divide by 1 ATM (Vair = Vwater * Pwork / Patm).
*/ */
typedef enum dc_tank_usage_t {
DC_TANK_USAGE_NONE,
DC_TANK_USAGE_SIDEMOUNT,
} dc_tank_usage_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_tankinfo_t type; /* Tank type - metric/imperial and oc/cc */ dc_tankinfo_t type; /* Tank type - metric/imperial and oc/cc */
@ -210,15 +234,53 @@ typedef struct dc_tank_t {
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_usage_t usage;
} dc_tank_t; } dc_tank_t;
typedef enum dc_decomodel_type_t {
DC_DECOMODEL_NONE,
DC_DECOMODEL_BUHLMANN,
DC_DECOMODEL_VPM,
DC_DECOMODEL_RGBM,
DC_DECOMODEL_DCIEM,
} dc_decomodel_type_t;
/*
* Decompression model
*
* The type field contains the decompression algorithm.
*
* The (optional) conservatism field contains the personal adjustment
* setting of the algorithm. The exact interpretation depends on the
* dive computer, but the default value (zero) will typically correspond
* to the neutral setting, while a positive value is more conservative
* and a negative value more aggressive.
*
* The (optional) params field contains the parameters of the algorithm:
*
* DC_DECOMODEL_BUHLMANN: The Gradient Factor (GF) parameters low and
* high. For a pure Buhlmann algorithm (e.g. without GF enabled), both
* values are 100. If GF are enabled, but the actual parameter values
* are not available from the dive computer, both values are zero.
*/
typedef struct dc_decomodel_t {
dc_decomodel_type_t type;
int conservatism;
union {
struct {
unsigned int high;
unsigned int low;
} gf;
} params;
} dc_decomodel_t;
typedef struct dc_field_string_t { typedef struct dc_field_string_t {
const char *desc; const char *desc;
const char *value; const char *value;
} dc_field_string_t; } dc_field_string_t;
typedef union dc_sample_value_t { typedef union dc_sample_value_t {
unsigned int time; unsigned int time; /* Milliseconds */
double depth; double depth;
struct { struct {
unsigned int tank; unsigned int tank;
@ -241,31 +303,41 @@ typedef union dc_sample_value_t {
const void *data; const void *data;
} vendor; } vendor;
double setpoint; double setpoint;
double ppo2; struct {
unsigned int sensor;
double value;
} ppo2;
double cns; double cns;
struct { struct {
unsigned int type; unsigned int type;
unsigned int time; unsigned int time;
double depth; double depth;
unsigned int tts;
} deco; } deco;
unsigned int gasmix; /* Gas mix index */ unsigned int gasmix; /* Gas mix index */
} dc_sample_value_t; } dc_sample_value_t;
typedef struct dc_parser_t dc_parser_t; typedef struct dc_parser_t dc_parser_t;
typedef void (*dc_sample_callback_t) (dc_sample_type_t type, dc_sample_value_t value, void *userdata); typedef void (*dc_sample_callback_t) (dc_sample_type_t type, const dc_sample_value_t *value, void *userdata);
dc_status_t dc_status_t
dc_parser_new (dc_parser_t **parser, dc_device_t *device); dc_parser_new (dc_parser_t **parser, dc_device_t *device, const unsigned char data[], size_t size);
dc_status_t dc_status_t
dc_parser_new2 (dc_parser_t **parser, dc_context_t *context, dc_descriptor_t *descriptor, unsigned int devtime, dc_ticks_t systime); dc_parser_new2 (dc_parser_t **parser, dc_context_t *context, dc_descriptor_t *descriptor, const unsigned char data[], size_t size);
dc_family_t dc_family_t
dc_parser_get_type (dc_parser_t *parser); dc_parser_get_type (dc_parser_t *parser);
dc_status_t dc_status_t
dc_parser_set_data (dc_parser_t *parser, const unsigned char *data, unsigned int size); dc_parser_set_clock (dc_parser_t *parser, unsigned int devtime, dc_ticks_t systime);
dc_status_t
dc_parser_set_atmospheric (dc_parser_t *parser, double atmospheric);
dc_status_t
dc_parser_set_density (dc_parser_t *parser, double density);
dc_status_t dc_status_t
dc_parser_get_datetime (dc_parser_t *parser, dc_datetime_t *datetime); dc_parser_get_datetime (dc_parser_t *parser, dc_datetime_t *datetime);

View File

@ -35,9 +35,6 @@ extern "C" {
dc_status_t dc_status_t
reefnet_sensus_device_get_handshake (dc_device_t *device, unsigned char data[], unsigned int size); reefnet_sensus_device_get_handshake (dc_device_t *device, unsigned char data[], unsigned int size);
dc_status_t
reefnet_sensus_parser_set_calibration (dc_parser_t *parser, double atmospheric, double hydrostatic);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -38,9 +38,6 @@ reefnet_sensuspro_device_get_handshake (dc_device_t *device, unsigned char data[
dc_status_t dc_status_t
reefnet_sensuspro_device_write_interval (dc_device_t *device, unsigned char interval); reefnet_sensuspro_device_write_interval (dc_device_t *device, unsigned char interval);
dc_status_t
reefnet_sensuspro_parser_set_calibration (dc_parser_t *parser, double atmospheric, double hydrostatic);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -56,9 +56,6 @@ reefnet_sensusultra_device_write_parameter (dc_device_t *device, reefnet_sensusu
dc_status_t dc_status_t
reefnet_sensusultra_device_sense (dc_device_t *device, unsigned char data[], unsigned int size); reefnet_sensusultra_device_sense (dc_device_t *device, unsigned char data[], unsigned int size);
dc_status_t
reefnet_sensusultra_parser_set_calibration (dc_parser_t *parser, double atmospheric, double hydrostatic);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -27,6 +27,7 @@
#include "iostream.h" #include "iostream.h"
#include "iterator.h" #include "iterator.h"
#include "descriptor.h" #include "descriptor.h"
#include "ioctl.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -77,6 +78,16 @@ dc_serial_iterator_new (dc_iterator_t **iterator, dc_context_t *context, dc_desc
dc_status_t dc_status_t
dc_serial_open (dc_iostream_t **iostream, dc_context_t *context, const char *name); dc_serial_open (dc_iostream_t **iostream, dc_context_t *context, const char *name);
/**
* Set the receive latency in milliseconds.
*
* The effect of this setting is highly platform and driver specific. On
* Windows it does nothing at all, on Linux it controls the low latency
* flag (e.g. only zero vs non-zero latency), and on Mac OS X it sets
* the receive latency as requested.
*/
#define DC_IOCTL_SERIAL_SET_LATENCY DC_IOCTL_IOW('s', 0, sizeof(unsigned int))
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -0,0 +1,153 @@
/*
* libdivecomputer
*
* Copyright (C) 2020 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
*/
#ifndef DC_USB_H
#define DC_USB_H
#include "common.h"
#include "context.h"
#include "iostream.h"
#include "iterator.h"
#include "descriptor.h"
#include "ioctl.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
* Perform a USB control transfer.
*
* The parameters for the control transfer are specified in the
* #dc_usb_control_t data structure. If the control transfer requires
* additional data as in- or output, the buffer must be located
* immediately after the #dc_usb_control_t data structure, and the
* length of the buffer must be indicated in the #wLength field. The
* size of the ioctl request is the total size, including the size of
* the #dc_usb_control_t structure.
*/
#define DC_IOCTL_USB_CONTROL_READ DC_IOCTL_IOR('u', 0, DC_IOCTL_SIZE_VARIABLE)
#define DC_IOCTL_USB_CONTROL_WRITE DC_IOCTL_IOW('u', 0, DC_IOCTL_SIZE_VARIABLE)
/**
* USB control transfer.
*/
typedef struct dc_usb_control_t {
unsigned char bmRequestType;
unsigned char bRequest;
unsigned short wValue;
unsigned short wIndex;
unsigned short wLength;
} dc_usb_control_t;
/**
* Endpoint direction bits of the USB control transfer.
*/
typedef enum dc_usb_endpoint_t {
DC_USB_ENDPOINT_OUT = 0x00,
DC_USB_ENDPOINT_IN = 0x80
} dc_usb_endpoint_t;
/**
* Request type bits of the USB control transfer.
*/
typedef enum dc_usb_request_t {
DC_USB_REQUEST_STANDARD = 0x00,
DC_USB_REQUEST_CLASS = 0x20,
DC_USB_REQUEST_VENDOR = 0x40,
DC_USB_REQUEST_RESERVED = 0x60
} dc_usb_request_t;
/**
* Recipient bits of the USB control transfer.
*/
typedef enum dc_usb_recipient_t {
DC_USB_RECIPIENT_DEVICE = 0x00,
DC_USB_RECIPIENT_INTERFACE = 0x01,
DC_USB_RECIPIENT_ENDPOINT = 0x02,
DC_USB_RECIPIENT_OTHER = 0x03,
} dc_usb_recipient_t;
/**
* USB device descriptor.
*/
typedef struct dc_usb_desc_t {
unsigned short vid;
unsigned short pid;
} dc_usb_desc_t;
/**
* Opaque object representing a USB device.
*/
typedef struct dc_usb_device_t dc_usb_device_t;
/**
* Get the vendor id (VID) of the USB device.
*
* @param[in] device A valid USB device.
*/
unsigned int
dc_usb_device_get_vid (dc_usb_device_t *device);
/**
* Get the product id (PID) of the USB device.
*
* @param[in] device A valid USB device.
*/
unsigned int
dc_usb_device_get_pid (dc_usb_device_t *device);
/**
* Destroy the USB device and free all resources.
*
* @param[in] device A valid USB device.
*/
void
dc_usb_device_free(dc_usb_device_t *device);
/**
* Create an iterator to enumerate the USB devices.
*
* @param[out] iterator A location to store the iterator.
* @param[in] context A valid context object.
* @param[in] descriptor A valid device descriptor or NULL.
* @returns #DC_STATUS_SUCCESS on success, or another #dc_status_t code
* on failure.
*/
dc_status_t
dc_usb_iterator_new (dc_iterator_t **iterator, dc_context_t *context, dc_descriptor_t *descriptor);
/**
* Open a USB connection.
*
* @param[out] iostream A location to store the USB connection.
* @param[in] context A valid context object.
* @param[in] device A valid USB device.
* @returns #DC_STATUS_SUCCESS on success, or another #dc_status_t code
* on failure.
*/
dc_status_t
dc_usb_open (dc_iostream_t **iostream, dc_context_t *context, dc_usb_device_t *device);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* DC_USB_H */

View File

@ -32,6 +32,14 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/**
* USB HID device descriptor.
*/
typedef struct dc_usbhid_desc_t {
unsigned short vid;
unsigned short pid;
} dc_usbhid_desc_t;
/** /**
* Opaque object representing a USB HID device. * Opaque object representing a USB HID device.
*/ */

View File

@ -1,911 +0,0 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="libdivecomputer"
ProjectGUID="{CEA7215A-D6B5-4840-8086-3C854F371997}"
RootNamespace="libdivecomputer"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBDIVECOMPUTER_EXPORTS;ENABLE_LOGGING;HAVE_AF_IRDA_H;HAVE_WS2BTH_H"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
CompileAs="2"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib"
LinkIncremental="2"
ModuleDefinitionFile="$(OutDir)/libdivecomputer.def"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBDIVECOMPUTER_EXPORTS;ENABLE_LOGGING;HAVE_AF_IRDA_H;HAVE_WS2BTH_H"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
CompileAs="2"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib"
LinkIncremental="1"
ModuleDefinitionFile="$(OutDir)/libdivecomputer.def"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath="..\src\aes.c"
>
</File>
<File
RelativePath="..\src\array.c"
>
</File>
<File
RelativePath="..\src\atomics_cobalt.c"
>
</File>
<File
RelativePath="..\src\atomics_cobalt_parser.c"
>
</File>
<File
RelativePath="..\src\bluetooth.c"
>
</File>
<File
RelativePath="..\src\buffer.c"
>
</File>
<File
RelativePath="..\src\checksum.c"
>
</File>
<File
RelativePath="..\src\citizen_aqualand.c"
>
</File>
<File
RelativePath="..\src\citizen_aqualand_parser.c"
>
</File>
<File
RelativePath="..\src\cochran_commander.c"
>
</File>
<File
RelativePath="..\src\cochran_commander_parser.c"
>
</File>
<File
RelativePath="..\src\common.c"
>
</File>
<File
RelativePath="..\src\context.c"
>
</File>
<File
RelativePath="..\src\cressi_edy.c"
>
</File>
<File
RelativePath="..\src\cressi_edy_parser.c"
>
</File>
<File
RelativePath="..\src\cressi_leonardo.c"
>
</File>
<File
RelativePath="..\src\cressi_leonardo_parser.c"
>
</File>
<File
RelativePath="..\src\custom.c"
>
</File>
<File
RelativePath="..\src\datetime.c"
>
</File>
<File
RelativePath="..\src\descriptor.c"
>
</File>
<File
RelativePath="..\src\device.c"
>
</File>
<File
RelativePath="..\src\diverite_nitekq.c"
>
</File>
<File
RelativePath="..\src\diverite_nitekq_parser.c"
>
</File>
<File
RelativePath="..\src\divesystem_idive.c"
>
</File>
<File
RelativePath="..\src\divesystem_idive_parser.c"
>
</File>
<File
RelativePath="..\src\hw_frog.c"
>
</File>
<File
RelativePath="..\src\hw_ostc.c"
>
</File>
<File
RelativePath="..\src\hw_ostc3.c"
>
</File>
<File
RelativePath="..\src\hw_ostc_parser.c"
>
</File>
<File
RelativePath="..\src\ihex.c"
>
</File>
<File
RelativePath="..\src\iostream.c"
>
</File>
<File
RelativePath="..\src\irda.c"
>
</File>
<File
RelativePath="..\src\iterator.c"
>
</File>
<File
RelativePath="..\src\mares_common.c"
>
</File>
<File
RelativePath="..\src\mares_darwin.c"
>
</File>
<File
RelativePath="..\src\mares_darwin_parser.c"
>
</File>
<File
RelativePath="..\src\mares_iconhd.c"
>
</File>
<File
RelativePath="..\src\mares_iconhd_parser.c"
>
</File>
<File
RelativePath="..\src\mares_nemo.c"
>
</File>
<File
RelativePath="..\src\mares_nemo_parser.c"
>
</File>
<File
RelativePath="..\src\mares_puck.c"
>
</File>
<File
RelativePath="..\src\oceanic_atom2.c"
>
</File>
<File
RelativePath="..\src\oceanic_atom2_parser.c"
>
</File>
<File
RelativePath="..\src\oceanic_common.c"
>
</File>
<File
RelativePath="..\src\oceanic_veo250.c"
>
</File>
<File
RelativePath="..\src\oceanic_veo250_parser.c"
>
</File>
<File
RelativePath="..\src\oceanic_vtpro.c"
>
</File>
<File
RelativePath="..\src\oceanic_vtpro_parser.c"
>
</File>
<File
RelativePath="..\src\parser.c"
>
</File>
<File
RelativePath="..\src\rbstream.c"
>
</File>
<File
RelativePath="..\src\reefnet_sensus.c"
>
</File>
<File
RelativePath="..\src\reefnet_sensus_parser.c"
>
</File>
<File
RelativePath="..\src\reefnet_sensuspro.c"
>
</File>
<File
RelativePath="..\src\reefnet_sensuspro_parser.c"
>
</File>
<File
RelativePath="..\src\reefnet_sensusultra.c"
>
</File>
<File
RelativePath="..\src\reefnet_sensusultra_parser.c"
>
</File>
<File
RelativePath="..\src\ringbuffer.c"
>
</File>
<File
RelativePath="..\src\serial_win32.c"
>
</File>
<File
RelativePath="..\src\shearwater_common.c"
>
</File>
<File
RelativePath="..\src\shearwater_petrel.c"
>
</File>
<File
RelativePath="..\src\shearwater_predator.c"
>
</File>
<File
RelativePath="..\src\shearwater_predator_parser.c"
>
</File>
<File
RelativePath="..\src\socket.c"
>
</File>
<File
RelativePath="..\src\suunto_common.c"
>
</File>
<File
RelativePath="..\src\suunto_common2.c"
>
</File>
<File
RelativePath="..\src\suunto_d9.c"
>
</File>
<File
RelativePath="..\src\suunto_d9_parser.c"
>
</File>
<File
RelativePath="..\src\suunto_eon.c"
>
</File>
<File
RelativePath="..\src\suunto_eon_parser.c"
>
</File>
<File
RelativePath="..\src\suunto_eonsteel.c"
>
</File>
<File
RelativePath="..\src\suunto_eonsteel_parser.c"
>
</File>
<File
RelativePath="..\src\suunto_solution.c"
>
</File>
<File
RelativePath="..\src\suunto_solution_parser.c"
>
</File>
<File
RelativePath="..\src\suunto_vyper.c"
>
</File>
<File
RelativePath="..\src\suunto_vyper2.c"
>
</File>
<File
RelativePath="..\src\suunto_vyper_parser.c"
>
</File>
<File
RelativePath="..\src\tecdiving_divecomputereu.c"
>
</File>
<File
RelativePath="..\src\tecdiving_divecomputereu_parser.c"
>
</File>
<File
RelativePath="..\src\garmin.c"
>
</File>
<File
RelativePath="..\src\garmin_parser.c"
>
</File>
<File
RelativePath="..\src\timer.c"
>
</File>
<File
RelativePath="..\src\usbhid.c"
>
</File>
<File
RelativePath="..\src\uwatec_aladin.c"
>
</File>
<File
RelativePath="..\src\uwatec_memomouse.c"
>
</File>
<File
RelativePath="..\src\uwatec_memomouse_parser.c"
>
</File>
<File
RelativePath="..\src\uwatec_smart.c"
>
</File>
<File
RelativePath="..\src\uwatec_smart_parser.c"
>
</File>
<File
RelativePath="..\src\version.c"
>
</File>
<File
RelativePath="..\src\zeagle_n2ition3.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath="..\src\aes.h"
>
</File>
<File
RelativePath="..\src\array.h"
>
</File>
<File
RelativePath="..\src\atomics_cobalt.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\atomics_cobalt.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\bluetooth.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\buffer.h"
>
</File>
<File
RelativePath="..\src\checksum.h"
>
</File>
<File
RelativePath="..\src\citizen_aqualand.h"
>
</File>
<File
RelativePath="..\src\cochran_commander.h"
>
</File>
<File
RelativePath="..\src\common-private.h"
>
</File>
<File
RelativePath="..\src\context-private.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\context.h"
>
</File>
<File
RelativePath="..\src\cressi_edy.h"
>
</File>
<File
RelativePath="..\src\cressi_leonardo.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\custom.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\datetime.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\descriptor.h"
>
</File>
<File
RelativePath="..\src\device-private.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\device.h"
>
</File>
<File
RelativePath="..\src\diverite_nitekq.h"
>
</File>
<File
RelativePath="..\src\divesystem_idive.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\hw_frog.h"
>
</File>
<File
RelativePath="..\src\hw_frog.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\hw_ostc.h"
>
</File>
<File
RelativePath="..\src\hw_ostc.h"
>
</File>
<File
RelativePath="..\src\hw_ostc3.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\hw_ostc3.h"
>
</File>
<File
RelativePath="..\src\ihex.h"
>
</File>
<File
RelativePath="..\src\iostream-private.h"
>
</File>
<File
RelativePath="..\src\iostream.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\irda.h"
>
</File>
<File
RelativePath="..\src\iterator-private.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\iterator.h"
>
</File>
<File
RelativePath="..\src\mares_common.h"
>
</File>
<File
RelativePath="..\src\mares_darwin.h"
>
</File>
<File
RelativePath="..\src\mares_iconhd.h"
>
</File>
<File
RelativePath="..\src\mares_nemo.h"
>
</File>
<File
RelativePath="..\src\mares_puck.h"
>
</File>
<File
RelativePath="..\src\oceanic_atom2.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\oceanic_atom2.h"
>
</File>
<File
RelativePath="..\src\oceanic_common.h"
>
</File>
<File
RelativePath="..\src\oceanic_veo250.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\oceanic_veo250.h"
>
</File>
<File
RelativePath="..\src\oceanic_vtpro.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\oceanic_vtpro.h"
>
</File>
<File
RelativePath="..\src\parser-private.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\parser.h"
>
</File>
<File
RelativePath="..\src\platform.h"
>
</File>
<File
RelativePath="..\src\rbstream.h"
>
</File>
<File
RelativePath="..\src\reefnet_sensus.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\reefnet_sensus.h"
>
</File>
<File
RelativePath="..\src\reefnet_sensuspro.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\reefnet_sensuspro.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\reefnet_sensusultra.h"
>
</File>
<File
RelativePath="..\src\reefnet_sensusultra.h"
>
</File>
<File
RelativePath="..\src\revision.h"
>
</File>
<File
RelativePath="..\src\ringbuffer.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\serial.h"
>
</File>
<File
RelativePath="..\src\shearwater_common.h"
>
</File>
<File
RelativePath="..\src\shearwater_petrel.h"
>
</File>
<File
RelativePath="..\src\shearwater_predator.h"
>
</File>
<File
RelativePath="..\src\socket.h"
>
</File>
<File
RelativePath="..\src\suunto_common.h"
>
</File>
<File
RelativePath="..\src\suunto_common2.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\suunto_d9.h"
>
</File>
<File
RelativePath="..\src\suunto_d9.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\suunto_eon.h"
>
</File>
<File
RelativePath="..\src\suunto_eon.h"
>
</File>
<File
RelativePath="..\src\suunto_eonsteel.h"
>
</File>
<File
RelativePath="..\src\suunto_solution.h"
>
</File>
<File
RelativePath="..\src\suunto_vyper.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\suunto_vyper2.h"
>
</File>
<File
RelativePath="..\src\suunto_vyper2.h"
>
</File>
<File
RelativePath="..\src\tecdiving_divecomputereu.h"
>
</File>
<File
RelativePath="..\src\garmin.h"
>
</File>
<File
RelativePath="..\src\timer.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\units.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\usbhid.h"
>
</File>
<File
RelativePath="..\src\uwatec_aladin.h"
>
</File>
<File
RelativePath="..\src\uwatec_memomouse.h"
>
</File>
<File
RelativePath="..\src\uwatec_smart.h"
>
</File>
<File
RelativePath="..\include\libdivecomputer\version.h"
>
</File>
<File
RelativePath="..\src\zeagle_n2ition3.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
<File
RelativePath="..\src\libdivecomputer.rc"
>
</File>
<File
RelativePath="..\src\libdivecomputer.symbols"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="echo EXPORTS &gt; &quot;$(OutDir)/libdivecomputer.def&quot; &amp;&amp; type &quot;$(InputPath)&quot; &gt;&gt; &quot;$(OutDir)/libdivecomputer.def&quot;"
Outputs="$(OutDir)/libdivecomputer.def"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="echo EXPORTS &gt; &quot;$(OutDir)/libdivecomputer.def&quot; &amp;&amp; type &quot;$(InputPath)&quot; &gt;&gt; &quot;$(OutDir)/libdivecomputer.def&quot;"
Outputs="$(OutDir)/libdivecomputer.def"
/>
</FileConfiguration>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -1,9 +1,9 @@
AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
AM_CFLAGS = $(LIBUSB_CFLAGS) $(HIDAPI_CFLAGS) $(BLUEZ_CFLAGS) AM_CFLAGS = $(LIBUSB_CFLAGS) $(LIBMTP_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) $(LIBMTP_LIBS) $(HIDAPI_LIBS) $(BLUEZ_LIBS) -lm
libdivecomputer_la_LDFLAGS = \ libdivecomputer_la_LDFLAGS = \
-version-info $(DC_VERSION_LIBTOOL) \ -version-info $(DC_VERSION_LIBTOOL) \
-no-undefined \ -no-undefined \
@ -16,7 +16,7 @@ endif
libdivecomputer_la_SOURCES = \ libdivecomputer_la_SOURCES = \
version.c \ version.c \
descriptor-private.h descriptor.c \ descriptor.c \
iostream-private.h iostream.c \ iostream-private.h iostream.c \
iterator-private.h iterator.c \ iterator-private.h iterator.c \
common-private.h common.c \ common-private.h common.c \
@ -43,6 +43,7 @@ libdivecomputer_la_SOURCES = \
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 \
oceanic_vtpro.h oceanic_vtpro.c oceanic_vtpro_parser.c \ oceanic_vtpro.h oceanic_vtpro.c oceanic_vtpro_parser.c \
pelagic_i330r.h pelagic_i330r.c \
mares_common.h mares_common.c \ mares_common.h mares_common.c \
mares_nemo.h mares_nemo.c mares_nemo_parser.c \ mares_nemo.h mares_nemo.c mares_nemo_parser.c \
mares_puck.h mares_puck.c \ mares_puck.h mares_puck.c \
@ -55,6 +56,7 @@ libdivecomputer_la_SOURCES = \
aes.h aes.c \ aes.h aes.c \
cressi_edy.h cressi_edy.c cressi_edy_parser.c \ cressi_edy.h cressi_edy.c cressi_edy_parser.c \
cressi_leonardo.h cressi_leonardo.c cressi_leonardo_parser.c \ cressi_leonardo.h cressi_leonardo.c cressi_leonardo_parser.c \
cressi_goa.h cressi_goa.c cressi_goa_parser.c \
zeagle_n2ition3.h zeagle_n2ition3.c \ zeagle_n2ition3.h zeagle_n2ition3.c \
atomics_cobalt.h atomics_cobalt.c atomics_cobalt_parser.c \ atomics_cobalt.h atomics_cobalt.c atomics_cobalt_parser.c \
shearwater_common.h shearwater_common.c \ shearwater_common.h shearwater_common.c \
@ -63,7 +65,7 @@ libdivecomputer_la_SOURCES = \
diverite_nitekq.h diverite_nitekq.c diverite_nitekq_parser.c \ diverite_nitekq.h diverite_nitekq.c diverite_nitekq_parser.c \
citizen_aqualand.h citizen_aqualand.c citizen_aqualand_parser.c \ citizen_aqualand.h citizen_aqualand.c citizen_aqualand_parser.c \
divesystem_idive.h divesystem_idive.c divesystem_idive_parser.c \ divesystem_idive.h divesystem_idive.c divesystem_idive_parser.c \
platform.h \ platform.h platform.c \
ringbuffer.h ringbuffer.c \ ringbuffer.h ringbuffer.c \
rbstream.h rbstream.c \ rbstream.h rbstream.c \
checksum.h checksum.c \ checksum.h checksum.c \
@ -71,14 +73,30 @@ libdivecomputer_la_SOURCES = \
buffer.c \ buffer.c \
cochran_commander.h cochran_commander.c cochran_commander_parser.c \ cochran_commander.h cochran_commander.c cochran_commander_parser.c \
tecdiving_divecomputereu.h tecdiving_divecomputereu.c tecdiving_divecomputereu_parser.c \ tecdiving_divecomputereu.h tecdiving_divecomputereu.c tecdiving_divecomputereu_parser.c \
garmin.h garmin.c garmin_parser.c \ mclean_extreme.h mclean_extreme.c mclean_extreme_parser.c \
liquivision_lynx.h liquivision_lynx.c liquivision_lynx_parser.c \
sporasub_sp2.h sporasub_sp2.c sporasub_sp2_parser.c \
deepsix_excursion.h deepsix_excursion.c deepsix_excursion_parser.c \
seac_screen.h seac_screen.c seac_screen_parser.c \
deepblu_cosmiq.h deepblu_cosmiq.c deepblu_cosmiq_parser.c \
oceans_s1_common.h oceans_s1_common.c \
oceans_s1.h oceans_s1.c oceans_s1_parser.c \
divesoft_freedom.h divesoft_freedom.c divesoft_freedom_parser.c \
hdlc.h hdlc.c \
packet.h packet.c \
socket.h socket.c \ socket.h socket.c \
irda.c \ irda.c \
usb.c \
usbhid.c \ usbhid.c \
bluetooth.c \ bluetooth.c \
usb_storage.c \
custom.c custom.c
# Not merged upstream yet
libdivecomputer_la_SOURCES += \
usb_storage.c \
field-cache.h field-cache.c \
garmin.h garmin.c garmin_parser.c
if OS_WIN32 if OS_WIN32
libdivecomputer_la_SOURCES += serial_win32.c libdivecomputer_la_SOURCES += serial_win32.c
else else
@ -95,7 +113,7 @@ libdivecomputer.exp: libdivecomputer.symbols
$(AM_V_GEN) sed -e '/^$$/d' $< > $@ $(AM_V_GEN) sed -e '/^$$/d' $< > $@
.rc.lo: .rc.lo:
$(AM_V_GEN) $(LIBTOOL) --silent --tag=CC --mode=compile $(RC) $(DEFS) $(DEFAULT_INCLUDES) $< -o $@ $(AM_V_GEN) $(LIBTOOL) --silent --tag=CC --mode=compile $(RC) $(DEFS) $(DEFAULT_INCLUDES) $(AM_CPPFLAGS) $< -o $@
libdivecomputer.lo: revision.h libdivecomputer.lo: revision.h

View File

@ -1,4 +1,28 @@
/* /*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
This is an implementation of the AES128 algorithm, specifically ECB and CBC mode. This is an implementation of the AES128 algorithm, specifically ECB and CBC mode.
@ -74,7 +98,7 @@ typedef struct aes_state_t {
#if defined(CBC) && CBC #if defined(CBC) && CBC
// Initial Vector used only for CBC mode // Initial Vector used only for CBC mode
uint8_t* Iv; const uint8_t* Iv;
#endif #endif
} aes_state_t; } aes_state_t;
@ -518,7 +542,7 @@ void AES128_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length,
if(iv != 0) if(iv != 0)
{ {
state.Iv = (uint8_t*)iv; state.Iv = iv;
} }
for(i = 0; i < length; i += KEYLEN) for(i = 0; i < length; i += KEYLEN)
@ -560,7 +584,7 @@ void AES128_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length,
// If iv is passed as 0, we continue to encrypt without re-setting the Iv // If iv is passed as 0, we continue to encrypt without re-setting the Iv
if(iv != 0) if(iv != 0)
{ {
state.Iv = (uint8_t*)iv; state.Iv = iv;
} }
for(i = 0; i < length; i += KEYLEN) for(i = 0; i < length; i += KEYLEN)

View File

@ -1,3 +1,29 @@
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
*/
#ifndef _AES_H_ #ifndef _AES_H_
#define _AES_H_ #define _AES_H_

View File

@ -160,6 +160,30 @@ array_convert_str2num (const unsigned char data[], unsigned int size)
return value; return value;
} }
unsigned int
array_convert_bin2dec (const unsigned char data[], unsigned int size)
{
unsigned int value = 0;
for (unsigned int i = 0; i < size; ++i) {
value *= 100;
value += data[i];
}
return value;
}
unsigned int
array_convert_bcd2dec (const unsigned char data[], unsigned int size)
{
unsigned int value = 0;
for (unsigned int i = 0; i < size; ++i) {
value *= 100;
value += bcd2dec(data[i]);
}
return value;
}
unsigned int unsigned int
array_uint_be (const unsigned char data[], unsigned int n) array_uint_be (const unsigned char data[], unsigned int n)
{ {
@ -167,7 +191,7 @@ array_uint_be (const unsigned char data[], unsigned int n)
unsigned int value = 0; unsigned int value = 0;
for (unsigned int i = 0; i < n; ++i) { for (unsigned int i = 0; i < n; ++i) {
shift -= 8; shift -= 8;
value |= data[i] << shift; value |= (unsigned int) data[i] << shift;
} }
return value; return value;
} }
@ -178,76 +202,170 @@ array_uint_le (const unsigned char data[], unsigned int n)
unsigned int shift = 0; unsigned int shift = 0;
unsigned int value = 0; unsigned int value = 0;
for (unsigned int i = 0; i < n; ++i) { for (unsigned int i = 0; i < n; ++i) {
value |= data[i] << shift; value |= (unsigned int) data[i] << shift;
shift += 8; shift += 8;
} }
return value; return value;
} }
unsigned long long
array_uint64_be (const unsigned char data[])
{
return ((unsigned long long) data[0] << 56) |
((unsigned long long) data[1] << 48) |
((unsigned long long) data[2] << 40) |
((unsigned long long) data[3] << 32) |
((unsigned long long) data[4] << 24) |
((unsigned long long) data[5] << 16) |
((unsigned long long) data[6] << 8) |
((unsigned long long) data[7] << 0);
}
unsigned long long
array_uint64_le (const unsigned char data[])
{
return ((unsigned long long) data[0] << 0) |
((unsigned long long) data[1] << 8) |
((unsigned long long) data[2] << 16) |
((unsigned long long) data[3] << 24) |
((unsigned long long) data[4] << 32) |
((unsigned long long) data[5] << 40) |
((unsigned long long) data[6] << 48) |
((unsigned long long) data[7] << 56);
}
unsigned int unsigned int
array_uint32_be (const unsigned char data[]) array_uint32_be (const unsigned char data[])
{ {
return (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]; return ((unsigned int) data[0] << 24) |
((unsigned int) data[1] << 16) |
((unsigned int) data[2] << 8) |
((unsigned int) data[3] << 0);
} }
unsigned int unsigned int
array_uint32_le (const unsigned char data[]) array_uint32_le (const unsigned char data[])
{ {
return data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24); return ((unsigned int) data[0] << 0) |
((unsigned int) data[1] << 8) |
((unsigned int) data[2] << 16) |
((unsigned int) data[3] << 24);
} }
unsigned int unsigned int
array_uint32_word_be (const unsigned char data[]) array_uint32_word_be (const unsigned char data[])
{ {
return data[1] + (data[0] << 8) + (data[3] << 16) + (data[2] << 24); return ((unsigned int) data[0] << 8) |
((unsigned int) data[1] << 0) |
((unsigned int) data[2] << 24) |
((unsigned int) data[3] << 16);
} }
void
array_uint32_le_set (unsigned char data[], const unsigned int input)
{
data[0] = input & 0xFF;
data[1] = (input >> 8) & 0xFF;
data[2] = (input >> 16) & 0xFF;
data[3] = (input >> 24) & 0xFF;
}
unsigned int unsigned int
array_uint24_be (const unsigned char data[]) array_uint24_be (const unsigned char data[])
{ {
return (data[0] << 16) + (data[1] << 8) + data[2]; return ((unsigned int) data[0] << 16) |
((unsigned int) data[1] << 8) |
((unsigned int) data[2] << 0);
} }
void
array_uint24_be_set (unsigned char data[], const unsigned int input)
{
data[0] = (input >> 16) & 0xFF;
data[1] = (input >> 8) & 0xFF;
data[2] = input & 0xFF;
}
unsigned int unsigned int
array_uint24_le (const unsigned char data[]) array_uint24_le (const unsigned char data[])
{ {
return data[0] + (data[1] << 8) + (data[2] << 16); return ((unsigned int) data[0] << 0) |
((unsigned int) data[1] << 8) |
((unsigned int) data[2] << 16);
} }
unsigned short unsigned short
array_uint16_be (const unsigned char data[]) array_uint16_be (const unsigned char data[])
{ {
return (data[0] << 8) + data[1]; return ((unsigned int) data[0] << 8) |
((unsigned int) data[1] << 0);
} }
unsigned short unsigned short
array_uint16_le (const unsigned char data[]) array_uint16_le (const unsigned char data[])
{ {
return data[0] + (data[1] << 8); return ((unsigned int) data[0] << 0) |
((unsigned int) data[1] << 8);
}
void
array_uint64_be_set (unsigned char data[], const unsigned long long input)
{
data[0] = (input >> 56) & 0xFF;
data[1] = (input >> 48) & 0xFF;
data[2] = (input >> 40) & 0xFF;
data[3] = (input >> 32) & 0xFF;
data[4] = (input >> 24) & 0xFF;
data[5] = (input >> 16) & 0xFF;
data[6] = (input >> 8) & 0xFF;
data[7] = (input ) & 0xFF;
}
void
array_uint64_le_set (unsigned char data[], const unsigned long long input)
{
data[0] = (input ) & 0xFF;
data[1] = (input >> 8) & 0xFF;
data[2] = (input >> 16) & 0xFF;
data[3] = (input >> 24) & 0xFF;
data[4] = (input >> 32) & 0xFF;
data[5] = (input >> 40) & 0xFF;
data[6] = (input >> 48) & 0xFF;
data[7] = (input >> 56) & 0xFF;
}
void
array_uint32_be_set (unsigned char data[], const unsigned int input)
{
data[0] = (input >> 24) & 0xFF;
data[1] = (input >> 16) & 0xFF;
data[2] = (input >> 8) & 0xFF;
data[3] = (input ) & 0xFF;
}
void
array_uint32_le_set (unsigned char data[], const unsigned int input)
{
data[0] = (input ) & 0xFF;
data[1] = (input >> 8) & 0xFF;
data[2] = (input >> 16) & 0xFF;
data[3] = (input >> 24) & 0xFF;
}
void
array_uint24_be_set (unsigned char data[], const unsigned int input)
{
data[0] = (input >> 16) & 0xFF;
data[1] = (input >> 8) & 0xFF;
data[2] = (input ) & 0xFF;
}
void
array_uint24_le_set (unsigned char data[], const unsigned int input)
{
data[0] = (input ) & 0xFF;
data[1] = (input >> 8) & 0xFF;
data[2] = (input >> 16) & 0xFF;
}
void
array_uint16_be_set (unsigned char data[], const unsigned short input)
{
data[0] = (input >> 8) & 0xFF;
data[1] = (input ) & 0xFF;
}
void
array_uint16_le_set (unsigned char data[], const unsigned short input)
{
data[0] = (input ) & 0xFF;
data[1] = (input >> 8) & 0xFF;
} }
unsigned char unsigned char
@ -255,3 +373,45 @@ bcd2dec (unsigned char value)
{ {
return ((value >> 4) & 0x0f) * 10 + (value & 0x0f); return ((value >> 4) & 0x0f) * 10 + (value & 0x0f);
} }
unsigned char
dec2bcd (unsigned char value)
{
if (value >= 100)
return 0;
unsigned char hi = value / 10;
unsigned char lo = value % 10;
return (hi << 4) | lo;
}
/*
* When turning a two's-complement number with a certain number
* of bits into one with more bits, the sign bit must be repeated
* in all the extra bits.
*/
unsigned int
signextend (unsigned int value, unsigned int nbits)
{
if (nbits <= 0 || nbits > 32)
return 0;
unsigned int signbit = 1U << (nbits - 1);
unsigned int mask = signbit - 1;
if ((value & signbit) == signbit)
return value | ~mask;
else
return value & mask;
}
unsigned int
popcount (unsigned int value)
{
unsigned int count = 0;
while (value) {
value &= value - 1;
count++;
}
return count;
}

View File

@ -22,6 +22,8 @@
#ifndef ARRAY_H #ifndef ARRAY_H
#define ARRAY_H #define ARRAY_H
#define C_ARRAY_SIZE(a) (sizeof (a) / sizeof *(a))
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
@ -52,12 +54,24 @@ array_convert_hex2bin (const unsigned char input[], unsigned int isize, unsigned
unsigned int unsigned int
array_convert_str2num (const unsigned char data[], unsigned int size); array_convert_str2num (const unsigned char data[], unsigned int size);
unsigned int
array_convert_bin2dec (const unsigned char data[], unsigned int size);
unsigned int
array_convert_bcd2dec (const unsigned char data[], unsigned int size);
unsigned int unsigned int
array_uint_be (const unsigned char data[], unsigned int n); array_uint_be (const unsigned char data[], unsigned int n);
unsigned int unsigned int
array_uint_le (const unsigned char data[], unsigned int n); array_uint_le (const unsigned char data[], unsigned int n);
unsigned long long
array_uint64_be (const unsigned char data[]);
unsigned long long
array_uint64_le (const unsigned char data[]);
unsigned int unsigned int
array_uint32_be (const unsigned char data[]); array_uint32_be (const unsigned char data[]);
@ -67,15 +81,9 @@ array_uint32_le (const unsigned char data[]);
unsigned int unsigned int
array_uint32_word_be (const unsigned char data[]); array_uint32_word_be (const unsigned char data[]);
void
array_uint32_le_set (unsigned char data[], const unsigned int input);
unsigned int unsigned int
array_uint24_be (const unsigned char data[]); array_uint24_be (const unsigned char data[]);
void
array_uint24_be_set (unsigned char data[], const unsigned int input);
unsigned int unsigned int
array_uint24_le (const unsigned char data[]); array_uint24_le (const unsigned char data[]);
@ -85,9 +93,42 @@ array_uint16_be (const unsigned char data[]);
unsigned short unsigned short
array_uint16_le (const unsigned char data[]); array_uint16_le (const unsigned char data[]);
void
array_uint64_be_set (unsigned char data[], const unsigned long long input);
void
array_uint64_le_set (unsigned char data[], const unsigned long long input);
void
array_uint32_be_set (unsigned char data[], const unsigned int input);
void
array_uint32_le_set (unsigned char data[], const unsigned int input);
void
array_uint24_be_set (unsigned char data[], const unsigned int input);
void
array_uint24_le_set (unsigned char data[], const unsigned int input);
void
array_uint16_be_set (unsigned char data[], const unsigned short input);
void
array_uint16_le_set (unsigned char data[], const unsigned short input);
unsigned char unsigned char
bcd2dec (unsigned char value); bcd2dec (unsigned char value);
unsigned char
dec2bcd (unsigned char value);
unsigned int
signextend (unsigned int value, unsigned int nbits);
unsigned int
popcount (unsigned int value);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -19,19 +19,10 @@
* MA 02110-1301 USA * MA 02110-1301 USA
*/ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h> // memcmp, memcpy #include <string.h> // memcmp, memcpy
#include <stdlib.h> // malloc, free #include <stdlib.h> // malloc, free
#ifdef HAVE_LIBUSB #include <libdivecomputer/usb.h>
#ifdef _WIN32
#define NOGDI
#endif
#include <libusb-1.0/libusb.h>
#endif
#include "atomics_cobalt.h" #include "atomics_cobalt.h"
#include "context-private.h" #include "context-private.h"
@ -41,7 +32,8 @@
#define ISINSTANCE(device) dc_device_isinstance((device), &atomics_cobalt_device_vtable) #define ISINSTANCE(device) dc_device_isinstance((device), &atomics_cobalt_device_vtable)
#define EXITCODE(rc) (rc == LIBUSB_ERROR_TIMEOUT ? DC_STATUS_TIMEOUT : DC_STATUS_IO) #define COBALT1 0
#define COBALT2 2
#define VID 0x0471 #define VID 0x0471
#define PID 0x0888 #define PID 0x0888
@ -49,15 +41,15 @@
#define FP_OFFSET 20 #define FP_OFFSET 20
#define SZ_MEMORY (29 * 64 * 1024) #define SZ_HEADER 228
#define SZ_MEMORY1 (29 * 64 * 1024) // Cobalt 1
#define SZ_MEMORY2 (41 * 64 * 1024) // Cobalt 2
#define SZ_VERSION 14 #define SZ_VERSION 14
typedef struct atomics_cobalt_device_t { typedef struct atomics_cobalt_device_t {
dc_device_t base; dc_device_t base;
#ifdef HAVE_LIBUSB dc_iostream_t *iostream;
libusb_context *context;
libusb_device_handle *handle;
#endif
unsigned int simulation; unsigned int simulation;
unsigned char fingerprint[6]; unsigned char fingerprint[6];
unsigned char version[SZ_VERSION]; unsigned char version[SZ_VERSION];
@ -65,7 +57,6 @@ typedef struct atomics_cobalt_device_t {
static dc_status_t atomics_cobalt_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size); static dc_status_t atomics_cobalt_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size);
static dc_status_t atomics_cobalt_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t atomics_cobalt_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t atomics_cobalt_device_close (dc_device_t *abstract);
static const dc_device_vtable_t atomics_cobalt_device_vtable = { static const dc_device_vtable_t atomics_cobalt_device_vtable = {
sizeof(atomics_cobalt_device_t), sizeof(atomics_cobalt_device_t),
@ -76,22 +67,19 @@ static const dc_device_vtable_t atomics_cobalt_device_vtable = {
NULL, /* dump */ NULL, /* dump */
atomics_cobalt_device_foreach, /* foreach */ atomics_cobalt_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
atomics_cobalt_device_close /* close */ NULL /* close */
}; };
dc_status_t dc_status_t
atomics_cobalt_device_open (dc_device_t **out, dc_context_t *context) atomics_cobalt_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
#ifdef HAVE_LIBUSB
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
atomics_cobalt_device_t *device = NULL; atomics_cobalt_device_t *device = NULL;
#endif
if (out == NULL) if (out == NULL)
return DC_STATUS_INVALIDARGS; return DC_STATUS_INVALIDARGS;
#ifdef HAVE_LIBUSB
// Allocate memory. // Allocate memory.
device = (atomics_cobalt_device_t *) dc_device_allocate (context, &atomics_cobalt_device_vtable); device = (atomics_cobalt_device_t *) dc_device_allocate (context, &atomics_cobalt_device_vtable);
if (device == NULL) { if (device == NULL) {
@ -100,67 +88,30 @@ atomics_cobalt_device_open (dc_device_t **out, dc_context_t *context)
} }
// Set the default values. // Set the default values.
device->context = NULL; device->iostream = iostream;
device->handle = NULL;
device->simulation = 0; device->simulation = 0;
memset (device->fingerprint, 0, sizeof (device->fingerprint)); memset (device->fingerprint, 0, sizeof (device->fingerprint));
int rc = libusb_init (&device->context); // Set the timeout for receiving data (2000 ms).
if (rc < 0) { status = dc_iostream_set_timeout (device->iostream, TIMEOUT);
ERROR (context, "Failed to initialize usb support."); if (status != DC_STATUS_SUCCESS) {
status = DC_STATUS_IO; ERROR (context, "Failed to set the timeout.");
goto error_free; goto error_free;
} }
device->handle = libusb_open_device_with_vid_pid (device->context, VID, PID);
if (device->handle == NULL) {
ERROR (context, "Failed to open the usb device.");
status = DC_STATUS_IO;
goto error_usb_exit;
}
rc = libusb_claim_interface (device->handle, 0);
if (rc < 0) {
ERROR (context, "Failed to claim the usb interface.");
status = DC_STATUS_IO;
goto error_usb_close;
}
status = atomics_cobalt_device_version ((dc_device_t *) device, device->version, sizeof (device->version)); status = atomics_cobalt_device_version ((dc_device_t *) device, device->version, sizeof (device->version));
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to identify the dive computer."); ERROR (context, "Failed to identify the dive computer.");
goto error_usb_close; goto error_free;
} }
*out = (dc_device_t*) device; *out = (dc_device_t*) device;
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_usb_close:
libusb_close (device->handle);
error_usb_exit:
libusb_exit (device->context);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
#else
return DC_STATUS_UNSUPPORTED;
#endif
}
static dc_status_t
atomics_cobalt_device_close (dc_device_t *abstract)
{
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract;
#ifdef HAVE_LIBUSB
libusb_release_interface(device->handle, 0);
libusb_close (device->handle);
libusb_exit (device->context);
#endif
return DC_STATUS_SUCCESS;
} }
@ -198,6 +149,7 @@ atomics_cobalt_device_set_simulation (dc_device_t *abstract, unsigned int simula
dc_status_t dc_status_t
atomics_cobalt_device_version (dc_device_t *abstract, unsigned char data[], unsigned int size) atomics_cobalt_device_version (dc_device_t *abstract, unsigned char data[], unsigned int size)
{ {
dc_status_t status = DC_STATUS_SUCCESS;
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract; atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract;
if (!ISINSTANCE (abstract)) if (!ISINSTANCE (abstract))
@ -206,31 +158,31 @@ atomics_cobalt_device_version (dc_device_t *abstract, unsigned char data[], unsi
if (size < SZ_VERSION) if (size < SZ_VERSION)
return DC_STATUS_INVALIDARGS; return DC_STATUS_INVALIDARGS;
#ifdef HAVE_LIBUSB
// Send the command to the dive computer. // Send the command to the dive computer.
uint8_t bRequest = 0x01; unsigned char bRequest = 0x01;
int rc = libusb_control_transfer (device->handle, dc_usb_control_t control = {
LIBUSB_RECIPIENT_DEVICE | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT, DC_USB_REQUEST_VENDOR | DC_USB_RECIPIENT_DEVICE | DC_USB_ENDPOINT_OUT, /* bmRequestType */
bRequest, 0, 0, NULL, 0, TIMEOUT); bRequest, /* bRequest */
if (rc != LIBUSB_SUCCESS) { 0, /* wValue */
ERROR (abstract->context, "Failed to send the command."); 0, /* wIndex */
return EXITCODE(rc); 0, /* wLength */
} };
HEXDUMP (abstract->context, DC_LOGLEVEL_INFO, "Write", &bRequest, 1); status = dc_iostream_ioctl (device->iostream, DC_IOCTL_USB_CONTROL_WRITE, &control, sizeof(control));
if (status != DC_STATUS_SUCCESS) {
ERROR (abstract->context, "Failed to send the command.");
return status;
}
// Receive the answer from the dive computer. // Receive the answer from the dive computer.
int length = 0; size_t length = 0;
unsigned char packet[SZ_VERSION + 2] = {0}; unsigned char packet[SZ_VERSION + 2] = {0};
rc = libusb_bulk_transfer (device->handle, 0x82, status = dc_iostream_read (device->iostream, packet, sizeof(packet), &length);
packet, sizeof (packet), &length, TIMEOUT); if (status != DC_STATUS_SUCCESS || length != sizeof (packet)) {
if (rc != LIBUSB_SUCCESS || length != sizeof (packet)) {
ERROR (abstract->context, "Failed to receive the answer."); ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE(rc); return status;
} }
HEXDUMP (abstract->context, DC_LOGLEVEL_INFO, "Read", packet, length);
// Verify the checksum of the packet. // Verify the checksum of the packet.
unsigned short crc = array_uint16_le (packet + SZ_VERSION); unsigned short crc = array_uint16_le (packet + SZ_VERSION);
unsigned short ccrc = checksum_add_uint16 (packet, SZ_VERSION, 0x0); unsigned short ccrc = checksum_add_uint16 (packet, SZ_VERSION, 0x0);
@ -242,16 +194,13 @@ atomics_cobalt_device_version (dc_device_t *abstract, unsigned char data[], unsi
memcpy (data, packet, SZ_VERSION); memcpy (data, packet, SZ_VERSION);
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
#else
return DC_STATUS_UNSUPPORTED;
#endif
} }
static dc_status_t static dc_status_t
atomics_cobalt_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init, dc_event_progress_t *progress) atomics_cobalt_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init, dc_event_progress_t *progress)
{ {
#ifdef HAVE_LIBUSB dc_status_t status = DC_STATUS_SUCCESS;
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract; atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract;
if (device_is_cancelled (abstract)) if (device_is_cancelled (abstract))
@ -263,36 +212,47 @@ atomics_cobalt_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init,
return DC_STATUS_NOMEMORY; return DC_STATUS_NOMEMORY;
} }
// Adjust the maximum value to take into account the two byte checksum and
// the 8 byte serial number. Those extra bytes are not stored inside the
// dive header and are added dynamically during the data transfer. Since we
// don't know the total number of dives in advance, we can't calculate the
// total number of extra bytes and adjust the maximum on the fly.
if (progress) {
progress->maximum += 2 + 8;
}
// Send the command to the dive computer. // Send the command to the dive computer.
uint8_t bRequest = 0; unsigned char bRequest = 0;
if (device->simulation) if (device->simulation)
bRequest = init ? 0x02 : 0x03; bRequest = init ? 0x02 : 0x03;
else else
bRequest = init ? 0x09 : 0x0A; bRequest = init ? 0x09 : 0x0A;
int rc = libusb_control_transfer (device->handle,
LIBUSB_RECIPIENT_DEVICE | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT,
bRequest, 0, 0, NULL, 0, TIMEOUT);
if (rc != LIBUSB_SUCCESS) {
ERROR (abstract->context, "Failed to send the command.");
return EXITCODE(rc);
}
HEXDUMP (abstract->context, DC_LOGLEVEL_INFO, "Write", &bRequest, 1); dc_usb_control_t control = {
DC_USB_REQUEST_VENDOR | DC_USB_RECIPIENT_DEVICE | DC_USB_ENDPOINT_OUT, /* bmRequestType */
bRequest, /* bRequest */
0, /* wValue */
0, /* wIndex */
0, /* wLength */
};
status = dc_iostream_ioctl (device->iostream, DC_IOCTL_USB_CONTROL_WRITE, &control, sizeof(control));
if (status != DC_STATUS_SUCCESS) {
ERROR (abstract->context, "Failed to send the command.");
return status;
}
unsigned int nbytes = 0; unsigned int nbytes = 0;
while (1) { while (1) {
// Receive the answer from the dive computer. // Receive the answer from the dive computer.
int length = 0; size_t length = 0;
unsigned char packet[8 * 1024] = {0}; unsigned char packet[8 * 1024] = {0};
rc = libusb_bulk_transfer (device->handle, 0x82, status = dc_iostream_read (device->iostream, packet, sizeof(packet), &length);
packet, sizeof (packet), &length, TIMEOUT); if (status != DC_STATUS_SUCCESS && status != DC_STATUS_TIMEOUT) {
if (rc != LIBUSB_SUCCESS && rc != LIBUSB_ERROR_TIMEOUT) {
ERROR (abstract->context, "Failed to receive the answer."); ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE(rc); return status;
} }
HEXDUMP (abstract->context, DC_LOGLEVEL_INFO, "Read", packet, length);
// Update and emit a progress event. // Update and emit a progress event.
if (progress) { if (progress) {
progress->current += length; progress->current += length;
@ -339,9 +299,6 @@ atomics_cobalt_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init,
dc_buffer_slice (buffer, 0, nbytes - 2); dc_buffer_slice (buffer, 0, nbytes - 2);
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
#else
return DC_STATUS_UNSUPPORTED;
#endif
} }
@ -350,9 +307,12 @@ atomics_cobalt_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
{ {
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract; atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract;
// Get the model number.
unsigned int model = array_uint16_le (device->version + 12);
// Enable progress notifications. // Enable progress notifications.
dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER; dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
progress.maximum = SZ_MEMORY + 2; progress.maximum = (model == COBALT2 ? SZ_MEMORY2 : SZ_MEMORY1) + 2;
device_event_emit (abstract, DC_EVENT_PROGRESS, &progress); device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
// Emit a vendor event. // Emit a vendor event.
@ -389,6 +349,12 @@ atomics_cobalt_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }
if (size < SZ_HEADER) {
ERROR (abstract->context, "Dive header is too small (%u).", size);
dc_buffer_free (buffer);
return DC_STATUS_DATAFORMAT;
}
if (memcmp (data + FP_OFFSET, device->fingerprint, sizeof (device->fingerprint)) == 0) { if (memcmp (data + FP_OFFSET, device->fingerprint, sizeof (device->fingerprint)) == 0) {
dc_buffer_free (buffer); dc_buffer_free (buffer);
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
@ -399,12 +365,6 @@ atomics_cobalt_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }
// Adjust the maximum value to take into account the two checksum bytes
// for the next dive. Since we don't know the total number of dives in
// advance, we can't calculate the total number of checksum bytes and
// adjust the maximum on the fly.
progress.maximum += 2;
ndives++; ndives++;
} }

View File

@ -23,6 +23,7 @@
#define ATOMICS_COBALT_H #define ATOMICS_COBALT_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
#include <libdivecomputer/atomics_cobalt.h> #include <libdivecomputer/atomics_cobalt.h>
@ -32,10 +33,10 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
atomics_cobalt_device_open (dc_device_t **device, dc_context_t *context); atomics_cobalt_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
atomics_cobalt_parser_create (dc_parser_t **parser, dc_context_t *context); atomics_cobalt_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -46,11 +46,10 @@ typedef struct atomics_cobalt_parser_t atomics_cobalt_parser_t;
struct atomics_cobalt_parser_t { struct atomics_cobalt_parser_t {
dc_parser_t base; dc_parser_t base;
// Depth calibration. // Depth calibration.
double atmospheric;
double hydrostatic; double hydrostatic;
}; };
static dc_status_t atomics_cobalt_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t atomics_cobalt_parser_set_density (dc_parser_t *abstract, double density);
static dc_status_t atomics_cobalt_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t atomics_cobalt_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime);
static dc_status_t atomics_cobalt_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t atomics_cobalt_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value);
static dc_status_t atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); static dc_status_t atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
@ -58,7 +57,9 @@ static dc_status_t atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract,
static const dc_parser_vtable_t atomics_cobalt_parser_vtable = { static const dc_parser_vtable_t atomics_cobalt_parser_vtable = {
sizeof(atomics_cobalt_parser_t), sizeof(atomics_cobalt_parser_t),
DC_FAMILY_ATOMICS_COBALT, DC_FAMILY_ATOMICS_COBALT,
atomics_cobalt_parser_set_data, /* set_data */ NULL, /* set_clock */
NULL, /* set_atmospheric */
atomics_cobalt_parser_set_density, /* set_density */
atomics_cobalt_parser_get_datetime, /* datetime */ atomics_cobalt_parser_get_datetime, /* datetime */
atomics_cobalt_parser_get_field, /* fields */ atomics_cobalt_parser_get_field, /* fields */
atomics_cobalt_parser_samples_foreach, /* samples_foreach */ atomics_cobalt_parser_samples_foreach, /* samples_foreach */
@ -67,7 +68,7 @@ static const dc_parser_vtable_t atomics_cobalt_parser_vtable = {
dc_status_t dc_status_t
atomics_cobalt_parser_create (dc_parser_t **out, dc_context_t *context) atomics_cobalt_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size)
{ {
atomics_cobalt_parser_t *parser = NULL; atomics_cobalt_parser_t *parser = NULL;
@ -75,15 +76,14 @@ atomics_cobalt_parser_create (dc_parser_t **out, dc_context_t *context)
return DC_STATUS_INVALIDARGS; return DC_STATUS_INVALIDARGS;
// Allocate memory. // Allocate memory.
parser = (atomics_cobalt_parser_t *) dc_parser_allocate (context, &atomics_cobalt_parser_vtable); parser = (atomics_cobalt_parser_t *) dc_parser_allocate (context, &atomics_cobalt_parser_vtable, data, size);
if (parser == NULL) { if (parser == 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.
parser->atmospheric = 0.0; parser->hydrostatic = DEF_DENSITY_SALT * GRAVITY;
parser->hydrostatic = 1025.0 * GRAVITY;
*out = (dc_parser_t*) parser; *out = (dc_parser_t*) parser;
@ -92,22 +92,11 @@ atomics_cobalt_parser_create (dc_parser_t **out, dc_context_t *context)
static dc_status_t static dc_status_t
atomics_cobalt_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) atomics_cobalt_parser_set_density (dc_parser_t *abstract, double density)
{ {
return DC_STATUS_SUCCESS; atomics_cobalt_parser_t *parser = (atomics_cobalt_parser_t *) abstract;
}
parser->hydrostatic = density * GRAVITY;
dc_status_t
atomics_cobalt_parser_set_calibration (dc_parser_t *abstract, double atmospheric, double hydrostatic)
{
atomics_cobalt_parser_t *parser = (atomics_cobalt_parser_t*) abstract;
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
parser->atmospheric = atmospheric;
parser->hydrostatic = hydrostatic;
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }
@ -151,15 +140,10 @@ atomics_cobalt_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, un
dc_gasmix_t *gasmix = (dc_gasmix_t *) value; dc_gasmix_t *gasmix = (dc_gasmix_t *) value;
dc_tank_t *tank = (dc_tank_t *) value; dc_tank_t *tank = (dc_tank_t *) value;
double atmospheric = 0.0; unsigned int atmospheric = array_uint16_le (p + 0x26);
char buf[BUFLEN]; char buf[BUFLEN];
dc_field_string_t *string = (dc_field_string_t *) value; dc_field_string_t *string = (dc_field_string_t *) value;
if (parser->atmospheric)
atmospheric = parser->atmospheric;
else
atmospheric = array_uint16_le (p + 0x26) * BAR / 1000.0;
unsigned int workpressure = 0; unsigned int workpressure = 0;
if (value) { if (value) {
@ -168,13 +152,14 @@ atomics_cobalt_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, un
*((unsigned int *) value) = array_uint16_le (p + 0x58) * 60; *((unsigned int *) value) = array_uint16_le (p + 0x58) * 60;
break; break;
case DC_FIELD_MAXDEPTH: case DC_FIELD_MAXDEPTH:
*((double *) value) = (array_uint16_le (p + 0x56) * BAR / 1000.0 - atmospheric) / parser->hydrostatic; *((double *) value) = (signed int)(array_uint16_le (p + 0x56) - atmospheric) * (BAR / 1000.0) / parser->hydrostatic;
break; break;
case DC_FIELD_GASMIX_COUNT: case DC_FIELD_GASMIX_COUNT:
case DC_FIELD_TANK_COUNT: case DC_FIELD_TANK_COUNT:
*((unsigned int *) value) = p[0x2a]; *((unsigned int *) value) = p[0x2a];
break; break;
case DC_FIELD_GASMIX: case DC_FIELD_GASMIX:
gasmix->usage = DC_USAGE_NONE;
gasmix->helium = p[SZ_HEADER + SZ_GASMIX * flags + 5] / 100.0; gasmix->helium = p[SZ_HEADER + SZ_GASMIX * flags + 5] / 100.0;
gasmix->oxygen = p[SZ_HEADER + SZ_GASMIX * flags + 4] / 100.0; gasmix->oxygen = p[SZ_HEADER + SZ_GASMIX * flags + 4] / 100.0;
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
@ -206,6 +191,7 @@ atomics_cobalt_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, un
tank->gasmix = flags; tank->gasmix = flags;
tank->beginpressure = array_uint16_le(p + 6) * PSI / BAR; tank->beginpressure = array_uint16_le(p + 6) * PSI / BAR;
tank->endpressure = array_uint16_le(p + 14) * PSI / BAR; tank->endpressure = array_uint16_le(p + 14) * PSI / BAR;
tank->usage = DC_TANK_USAGE_NONE;
break; break;
case DC_FIELD_DIVEMODE: case DC_FIELD_DIVEMODE:
switch(p[0x24]) { switch(p[0x24]) {
@ -220,6 +206,9 @@ 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_ATMOSPHERIC:
*((double *) value) = atmospheric / 1000.0;
break;
case DC_FIELD_STRING: case DC_FIELD_STRING:
switch(flags) { switch(flags) {
case 0: // Serialnr case 0: // Serialnr
@ -274,11 +263,7 @@ atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback
if (size < header + SZ_SEGMENT * nsegments) if (size < header + SZ_SEGMENT * nsegments)
return DC_STATUS_DATAFORMAT; return DC_STATUS_DATAFORMAT;
double atmospheric = 0.0; unsigned int atmospheric = array_uint16_le (data + 0x26);
if (parser->atmospheric)
atmospheric = parser->atmospheric;
else
atmospheric = array_uint16_le (data + 0x26) * BAR / 1000.0;
// Previous gas mix - initialize with impossible value // Previous gas mix - initialize with impossible value
unsigned int gasmix_previous = 0xFFFFFFFF; unsigned int gasmix_previous = 0xFFFFFFFF;
@ -304,19 +289,19 @@ atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback
// Time (seconds). // Time (seconds).
time += interval; time += interval;
sample.time = time; sample.time = time * 1000;
if (callback) callback (DC_SAMPLE_TIME, sample, userdata); if (callback) callback (DC_SAMPLE_TIME, &sample, userdata);
// Depth (1/1000 bar). // Depth (1/1000 bar).
unsigned int depth = array_uint16_le (data + offset + 0); unsigned int depth = array_uint16_le (data + offset + 0);
sample.depth = (depth * BAR / 1000.0 - atmospheric) / parser->hydrostatic; sample.depth = (signed int)(depth - atmospheric) * (BAR / 1000.0) / parser->hydrostatic;
if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata);
// Pressure (1 psi). // Pressure (1 psi).
unsigned int pressure = array_uint16_le (data + offset + 2); unsigned int pressure = array_uint16_le (data + offset + 2);
sample.pressure.tank = tank; sample.pressure.tank = tank;
sample.pressure.value = pressure * PSI / BAR; sample.pressure.value = pressure * PSI / BAR;
if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); if (callback) callback (DC_SAMPLE_PRESSURE, &sample, userdata);
// Current gas mix // Current gas mix
unsigned int gasmix = data[offset + 4]; unsigned int gasmix = data[offset + 4];
@ -332,14 +317,14 @@ atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback
return DC_STATUS_DATAFORMAT; return DC_STATUS_DATAFORMAT;
} }
sample.gasmix = idx; sample.gasmix = idx;
if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata);
gasmix_previous = gasmix; gasmix_previous = gasmix;
} }
// Temperature (1 °F). // Temperature (1 °F).
unsigned int temperature = data[offset + 8]; unsigned int temperature = data[offset + 8];
sample.temperature = (temperature - 32.0) * (5.0 / 9.0); sample.temperature = (temperature - 32.0) * (5.0 / 9.0);
if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata);
// violation status // violation status
sample.event.type = 0; sample.event.type = 0;
@ -349,15 +334,15 @@ atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback
unsigned int violation = data[offset + 11]; unsigned int violation = data[offset + 11];
if (violation & 0x01) { if (violation & 0x01) {
sample.event.type = SAMPLE_EVENT_ASCENT; sample.event.type = SAMPLE_EVENT_ASCENT;
if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata);
} }
if (violation & 0x04) { if (violation & 0x04) {
sample.event.type = SAMPLE_EVENT_CEILING; sample.event.type = SAMPLE_EVENT_CEILING;
if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata);
} }
if (violation & 0x08) { if (violation & 0x08) {
sample.event.type = SAMPLE_EVENT_PO2; sample.event.type = SAMPLE_EVENT_PO2;
if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata);
} }
// NDL & deco // NDL & deco
@ -372,7 +357,8 @@ atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback
sample.deco.type = DC_DECO_NDL; sample.deco.type = DC_DECO_NDL;
sample.deco.time = ndl; sample.deco.time = ndl;
sample.deco.depth = 0.0; sample.deco.depth = 0.0;
if (callback) callback (DC_SAMPLE_DECO, sample, userdata); sample.deco.tts = 0;
if (callback) callback (DC_SAMPLE_DECO, &sample, userdata);
offset += SZ_SEGMENT; offset += SZ_SEGMENT;
} }

View File

@ -24,7 +24,6 @@
#endif #endif
#include <stdlib.h> // malloc, free #include <stdlib.h> // malloc, free
#include <stdio.h>
#include "socket.h" #include "socket.h"
@ -52,7 +51,6 @@
#include "context-private.h" #include "context-private.h"
#include "iostream-private.h" #include "iostream-private.h"
#include "iterator-private.h" #include "iterator-private.h"
#include "descriptor-private.h"
#include "platform.h" #include "platform.h"
#ifdef _WIN32 #ifdef _WIN32
@ -79,7 +77,7 @@ static dc_status_t dc_bluetooth_iterator_free (dc_iterator_t *iterator);
typedef struct dc_bluetooth_iterator_t { typedef struct dc_bluetooth_iterator_t {
dc_iterator_t base; dc_iterator_t base;
dc_filter_t filter; dc_descriptor_t *descriptor;
#ifdef _WIN32 #ifdef _WIN32
HANDLE hLookup; HANDLE hLookup;
#else #else
@ -99,15 +97,16 @@ static const dc_iterator_vtable_t dc_bluetooth_iterator_vtable = {
static const dc_iostream_vtable_t dc_bluetooth_vtable = { static const dc_iostream_vtable_t dc_bluetooth_vtable = {
sizeof(dc_socket_t), sizeof(dc_socket_t),
dc_socket_set_timeout, /* set_timeout */ dc_socket_set_timeout, /* set_timeout */
NULL, /* set_latency */
NULL, /* set_break */ NULL, /* set_break */
NULL, /* set_dtr */ NULL, /* set_dtr */
NULL, /* set_rts */ NULL, /* set_rts */
NULL, /* get_lines */ NULL, /* get_lines */
dc_socket_get_available, /* get_available */ dc_socket_get_available, /* get_available */
NULL, /* configure */ NULL, /* configure */
dc_socket_poll, /* poll */
dc_socket_read, /* read */ dc_socket_read, /* read */
dc_socket_write, /* write */ dc_socket_write, /* write */
dc_socket_ioctl, /* ioctl */
NULL, /* flush */ NULL, /* flush */
NULL, /* purge */ NULL, /* purge */
dc_socket_sleep, /* sleep */ dc_socket_sleep, /* sleep */
@ -230,7 +229,7 @@ dc_bluetooth_addr2str(dc_bluetooth_address_t address, char *str, size_t size)
if (str == NULL || size < DC_BLUETOOTH_SIZE) if (str == NULL || size < DC_BLUETOOTH_SIZE)
return NULL; return NULL;
int n = snprintf(str, size, "%02X:%02X:%02X:%02X:%02X:%02X", int n = dc_platform_snprintf(str, size, "%02X:%02X:%02X:%02X:%02X:%02X",
(unsigned char)((address >> 40) & 0xFF), (unsigned char)((address >> 40) & 0xFF),
(unsigned char)((address >> 32) & 0xFF), (unsigned char)((address >> 32) & 0xFF),
(unsigned char)((address >> 24) & 0xFF), (unsigned char)((address >> 24) & 0xFF),
@ -375,7 +374,7 @@ dc_bluetooth_iterator_new (dc_iterator_t **out, dc_context_t *context, dc_descri
iterator->count = ndevices; iterator->count = ndevices;
iterator->current = 0; iterator->current = 0;
#endif #endif
iterator->filter = dc_descriptor_get_filter (descriptor); iterator->descriptor = descriptor;
*out = (dc_iterator_t *) iterator; *out = (dc_iterator_t *) iterator;
@ -455,7 +454,7 @@ dc_bluetooth_iterator_next (dc_iterator_t *abstract, void *out)
INFO (abstract->context, "Discover: address=" DC_ADDRESS_FORMAT ", name=%s", INFO (abstract->context, "Discover: address=" DC_ADDRESS_FORMAT ", name=%s",
address, name ? name : ""); address, name ? name : "");
if (iterator->filter && !iterator->filter (DC_TRANSPORT_BLUETOOTH, name)) { if (!dc_descriptor_filter (iterator->descriptor, DC_TRANSPORT_BLUETOOTH, name)) {
continue; continue;
} }

View File

@ -231,6 +231,72 @@ dc_buffer_prepend (dc_buffer_t *buffer, const unsigned char data[], size_t size)
} }
int
dc_buffer_insert (dc_buffer_t *buffer, size_t offset, const unsigned char data[], size_t size)
{
if (buffer == NULL)
return 0;
if (offset > buffer->size)
return 0;
size_t head = buffer->offset;
size_t tail = buffer->capacity - (buffer->offset + buffer->size);
unsigned char *ptr = buffer->data + buffer->offset;
if (size <= head) {
if (buffer->size)
memmove (ptr - size, ptr, offset);
buffer->offset -= size;
} else if (size <= tail) {
if (buffer->size)
memmove (ptr + offset + size, ptr + offset, buffer->size - offset);
} else if (size <= tail + head) {
size_t n = buffer->size + size;
size_t available = buffer->capacity - n;
size_t tmp_offset = head > tail ? available : 0;
unsigned char *tmp = buffer->data;
if (buffer->size) {
memmove (tmp + tmp_offset, ptr, offset);
memmove (tmp + tmp_offset + offset + size, ptr + offset, buffer->size - offset);
}
buffer->offset = tmp_offset;
} else {
size_t n = buffer->size + size;
size_t capacity = dc_buffer_expand_calc (buffer, n);
size_t available = capacity - n;
size_t tmp_offset = head > tail ? available : 0;
unsigned char *tmp = (unsigned char *) malloc (capacity);
if (tmp == NULL)
return 0;
if (buffer->size) {
memcpy (tmp + tmp_offset, ptr, offset);
memcpy (tmp + tmp_offset + offset + size, ptr + offset, buffer->size - offset);
}
free (buffer->data);
buffer->data = tmp;
buffer->capacity = capacity;
buffer->offset = tmp_offset;
}
if (size)
memcpy (buffer->data + buffer->offset + offset, data, size);
buffer->size += size;
return 1;
}
int int
dc_buffer_slice (dc_buffer_t *buffer, size_t offset, size_t size) dc_buffer_slice (dc_buffer_t *buffer, size_t offset, size_t size)
{ {

View File

@ -68,8 +68,13 @@ checksum_xor_uint8 (const unsigned char data[], unsigned int size, unsigned char
} }
/*
* Polynomial: 0x1021
* RefIn: False
* RefOut: False
*/
unsigned short unsigned short
checksum_crc_ccitt_uint16 (const unsigned char data[], unsigned int size) checksum_crc16_ccitt (const unsigned char data[], unsigned int size, unsigned short init, unsigned short xorout)
{ {
static const unsigned short crc_ccitt_table[] = { static const unsigned short crc_ccitt_table[] = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
@ -106,15 +111,174 @@ checksum_crc_ccitt_uint16 (const unsigned char data[], unsigned int size)
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
}; };
unsigned short crc = 0xffff; unsigned short crc = init;
for (unsigned int i = 0; i < size; ++i) for (unsigned int i = 0; i < size; ++i)
crc = (crc << 8) ^ crc_ccitt_table[(crc >> 8) ^ data[i]]; crc = (crc << 8) ^ crc_ccitt_table[(crc >> 8) ^ data[i]];
return crc; return crc ^ xorout;
} }
/*
* Polynomial: 0x1021
* RefIn: True
* RefOut: True
*/
unsigned short
checksum_crc16r_ccitt (const unsigned char data[], unsigned int size, unsigned short init, unsigned short xorout)
{
static const unsigned short crc_ccitt_table[] = {
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
};
unsigned short crc = init;
for (unsigned int i = 0; i < size; ++i)
crc = (crc >> 8) ^ crc_ccitt_table[(crc ^ data[i]) & 0xff];
return crc ^ xorout;
}
/*
* Polynomial: 0x8005
* RefIn: False
* RefOut: False
*/
unsigned short
checksum_crc16_ansi (const unsigned char data[], unsigned int size, unsigned short init, unsigned short xorout)
{
static const unsigned short crc_ccitt_table[] = {
0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
};
unsigned short crc = init;
for (unsigned int i = 0; i < size; ++i)
crc = (crc << 8) ^ crc_ccitt_table[(crc >> 8) ^ data[i]];
return crc ^ xorout;
}
/*
* Polynomial: 0x8005
* RefIn: True
* RefOut: True
*/
unsigned short
checksum_crc16r_ansi (const unsigned char data[], unsigned int size, unsigned short init, unsigned short xorout)
{
static const unsigned short crc_ccitt_table[] = {
0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
};
unsigned short crc = init;
for (unsigned int i = 0; i < size; ++i)
crc = (crc >> 8) ^ crc_ccitt_table[(crc ^ data[i]) & 0xff];
return crc ^ xorout;
}
/*
* Polynomial: 0x04C11DB7
* Init: 0xffffffff
* XorOut: 0xffffffff
* RefIn: True
* RefOut: True
*/
unsigned int unsigned int
checksum_crc32 (const unsigned char data[], unsigned int size) checksum_crc32r (const unsigned char data[], unsigned int size)
{ {
static const unsigned int crc_table[] = { static const unsigned int crc_table[] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
@ -157,3 +321,56 @@ checksum_crc32 (const unsigned char data[], unsigned int size)
return crc ^ 0xffffffff; return crc ^ 0xffffffff;
} }
/*
* Polynomial: 0x04C11DB7
* Init: 0xffffffff
* XorOut: 0xffffffff
* RefIn: False
* RefOut: False
*/
unsigned int
checksum_crc32 (const unsigned char data[], unsigned int size)
{
static const unsigned int crc_table[] = {
0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B, 0x1A864DB2, 0x1E475005,
0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61, 0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD,
0x4C11DB70, 0x48D0C6C7, 0x4593E01E, 0x4152FDA9, 0x5F15ADAC, 0x5BD4B01B, 0x569796C2, 0x52568B75,
0x6A1936C8, 0x6ED82B7F, 0x639B0DA6, 0x675A1011, 0x791D4014, 0x7DDC5DA3, 0x709F7B7A, 0x745E66CD,
0x9823B6E0, 0x9CE2AB57, 0x91A18D8E, 0x95609039, 0x8B27C03C, 0x8FE6DD8B, 0x82A5FB52, 0x8664E6E5,
0xBE2B5B58, 0xBAEA46EF, 0xB7A96036, 0xB3687D81, 0xAD2F2D84, 0xA9EE3033, 0xA4AD16EA, 0xA06C0B5D,
0xD4326D90, 0xD0F37027, 0xDDB056FE, 0xD9714B49, 0xC7361B4C, 0xC3F706FB, 0xCEB42022, 0xCA753D95,
0xF23A8028, 0xF6FB9D9F, 0xFBB8BB46, 0xFF79A6F1, 0xE13EF6F4, 0xE5FFEB43, 0xE8BCCD9A, 0xEC7DD02D,
0x34867077, 0x30476DC0, 0x3D044B19, 0x39C556AE, 0x278206AB, 0x23431B1C, 0x2E003DC5, 0x2AC12072,
0x128E9DCF, 0x164F8078, 0x1B0CA6A1, 0x1FCDBB16, 0x018AEB13, 0x054BF6A4, 0x0808D07D, 0x0CC9CDCA,
0x7897AB07, 0x7C56B6B0, 0x71159069, 0x75D48DDE, 0x6B93DDDB, 0x6F52C06C, 0x6211E6B5, 0x66D0FB02,
0x5E9F46BF, 0x5A5E5B08, 0x571D7DD1, 0x53DC6066, 0x4D9B3063, 0x495A2DD4, 0x44190B0D, 0x40D816BA,
0xACA5C697, 0xA864DB20, 0xA527FDF9, 0xA1E6E04E, 0xBFA1B04B, 0xBB60ADFC, 0xB6238B25, 0xB2E29692,
0x8AAD2B2F, 0x8E6C3698, 0x832F1041, 0x87EE0DF6, 0x99A95DF3, 0x9D684044, 0x902B669D, 0x94EA7B2A,
0xE0B41DE7, 0xE4750050, 0xE9362689, 0xEDF73B3E, 0xF3B06B3B, 0xF771768C, 0xFA325055, 0xFEF34DE2,
0xC6BCF05F, 0xC27DEDE8, 0xCF3ECB31, 0xCBFFD686, 0xD5B88683, 0xD1799B34, 0xDC3ABDED, 0xD8FBA05A,
0x690CE0EE, 0x6DCDFD59, 0x608EDB80, 0x644FC637, 0x7A089632, 0x7EC98B85, 0x738AAD5C, 0x774BB0EB,
0x4F040D56, 0x4BC510E1, 0x46863638, 0x42472B8F, 0x5C007B8A, 0x58C1663D, 0x558240E4, 0x51435D53,
0x251D3B9E, 0x21DC2629, 0x2C9F00F0, 0x285E1D47, 0x36194D42, 0x32D850F5, 0x3F9B762C, 0x3B5A6B9B,
0x0315D626, 0x07D4CB91, 0x0A97ED48, 0x0E56F0FF, 0x1011A0FA, 0x14D0BD4D, 0x19939B94, 0x1D528623,
0xF12F560E, 0xF5EE4BB9, 0xF8AD6D60, 0xFC6C70D7, 0xE22B20D2, 0xE6EA3D65, 0xEBA91BBC, 0xEF68060B,
0xD727BBB6, 0xD3E6A601, 0xDEA580D8, 0xDA649D6F, 0xC423CD6A, 0xC0E2D0DD, 0xCDA1F604, 0xC960EBB3,
0xBD3E8D7E, 0xB9FF90C9, 0xB4BCB610, 0xB07DABA7, 0xAE3AFBA2, 0xAAFBE615, 0xA7B8C0CC, 0xA379DD7B,
0x9B3660C6, 0x9FF77D71, 0x92B45BA8, 0x9675461F, 0x8832161A, 0x8CF30BAD, 0x81B02D74, 0x857130C3,
0x5D8A9099, 0x594B8D2E, 0x5408ABF7, 0x50C9B640, 0x4E8EE645, 0x4A4FFBF2, 0x470CDD2B, 0x43CDC09C,
0x7B827D21, 0x7F436096, 0x7200464F, 0x76C15BF8, 0x68860BFD, 0x6C47164A, 0x61043093, 0x65C52D24,
0x119B4BE9, 0x155A565E, 0x18197087, 0x1CD86D30, 0x029F3D35, 0x065E2082, 0x0B1D065B, 0x0FDC1BEC,
0x3793A651, 0x3352BBE6, 0x3E119D3F, 0x3AD08088, 0x2497D08D, 0x2056CD3A, 0x2D15EBE3, 0x29D4F654,
0xC5A92679, 0xC1683BCE, 0xCC2B1D17, 0xC8EA00A0, 0xD6AD50A5, 0xD26C4D12, 0xDF2F6BCB, 0xDBEE767C,
0xE3A1CBC1, 0xE760D676, 0xEA23F0AF, 0xEEE2ED18, 0xF0A5BD1D, 0xF464A0AA, 0xF9278673, 0xFDE69BC4,
0x89B8FD09, 0x8D79E0BE, 0x803AC667, 0x84FBDBD0, 0x9ABC8BD5, 0x9E7D9662, 0x933EB0BB, 0x97FFAD0C,
0xAFB010B1, 0xAB710D06, 0xA6322BDF, 0xA2F33668, 0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4,
};
unsigned int crc = 0xffffffff;
for (unsigned int i = 0; i < size; ++i)
crc = crc_table[((crc >> 24) ^ data[i]) & 0xFF] ^ (crc << 8);
return crc ^ 0xffffffff;
}

View File

@ -39,7 +39,19 @@ unsigned char
checksum_xor_uint8 (const unsigned char data[], unsigned int size, unsigned char init); checksum_xor_uint8 (const unsigned char data[], unsigned int size, unsigned char init);
unsigned short unsigned short
checksum_crc_ccitt_uint16 (const unsigned char data[], unsigned int size); checksum_crc16_ccitt (const unsigned char data[], unsigned int size, unsigned short init, unsigned short xorout);
unsigned short
checksum_crc16r_ccitt (const unsigned char data[], unsigned int size, unsigned short init, unsigned short xorout);
unsigned short
checksum_crc16_ansi (const unsigned char data[], unsigned int size, unsigned short init, unsigned short xorout);
unsigned short
checksum_crc16r_ansi (const unsigned char data[], unsigned int size, unsigned short init, unsigned short xorout);
unsigned int
checksum_crc32r (const unsigned char data[], unsigned int size);
unsigned int unsigned int
checksum_crc32 (const unsigned char data[], unsigned int size); checksum_crc32 (const unsigned char data[], unsigned int size);

View File

@ -31,6 +31,8 @@
#define ISINSTANCE(device) dc_device_isinstance((device), &citizen_aqualand_device_vtable) #define ISINSTANCE(device) dc_device_isinstance((device), &citizen_aqualand_device_vtable)
#define SZ_HEADER 32
typedef struct citizen_aqualand_device_t { typedef struct citizen_aqualand_device_t {
dc_device_t base; dc_device_t base;
dc_iostream_t *iostream; dc_iostream_t *iostream;
@ -200,6 +202,12 @@ citizen_aqualand_device_foreach (dc_device_t *abstract, dc_dive_callback_t callb
unsigned char *data = dc_buffer_get_data (buffer); unsigned char *data = dc_buffer_get_data (buffer);
unsigned int size = dc_buffer_get_size (buffer); unsigned int size = dc_buffer_get_size (buffer);
if (size < SZ_HEADER) {
ERROR (abstract->context, "Dive header is too small (%u).", size);
dc_buffer_free (buffer);
return DC_STATUS_DATAFORMAT;
}
if (callback && memcmp (data + 0x05, device->fingerprint, sizeof (device->fingerprint)) != 0) { if (callback && memcmp (data + 0x05, device->fingerprint, sizeof (device->fingerprint)) != 0) {
callback (data, size, data + 0x05, sizeof (device->fingerprint), userdata); callback (data, size, data + 0x05, sizeof (device->fingerprint), userdata);
} }

View File

@ -35,7 +35,7 @@ dc_status_t
citizen_aqualand_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); citizen_aqualand_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
citizen_aqualand_parser_create (dc_parser_t **parser, dc_context_t *context); citizen_aqualand_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -36,7 +36,6 @@ typedef struct citizen_aqualand_parser_t {
dc_parser_t base; dc_parser_t base;
} citizen_aqualand_parser_t; } citizen_aqualand_parser_t;
static dc_status_t citizen_aqualand_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size);
static dc_status_t citizen_aqualand_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t citizen_aqualand_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime);
static dc_status_t citizen_aqualand_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t citizen_aqualand_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value);
static dc_status_t citizen_aqualand_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); static dc_status_t citizen_aqualand_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
@ -44,7 +43,9 @@ static dc_status_t citizen_aqualand_parser_samples_foreach (dc_parser_t *abstrac
static const dc_parser_vtable_t citizen_aqualand_parser_vtable = { static const dc_parser_vtable_t citizen_aqualand_parser_vtable = {
sizeof(citizen_aqualand_parser_t), sizeof(citizen_aqualand_parser_t),
DC_FAMILY_CITIZEN_AQUALAND, DC_FAMILY_CITIZEN_AQUALAND,
citizen_aqualand_parser_set_data, /* set_data */ NULL, /* set_clock */
NULL, /* set_atmospheric */
NULL, /* set_density */
citizen_aqualand_parser_get_datetime, /* datetime */ citizen_aqualand_parser_get_datetime, /* datetime */
citizen_aqualand_parser_get_field, /* fields */ citizen_aqualand_parser_get_field, /* fields */
citizen_aqualand_parser_samples_foreach, /* samples_foreach */ citizen_aqualand_parser_samples_foreach, /* samples_foreach */
@ -53,7 +54,7 @@ static const dc_parser_vtable_t citizen_aqualand_parser_vtable = {
dc_status_t dc_status_t
citizen_aqualand_parser_create (dc_parser_t **out, dc_context_t *context) citizen_aqualand_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size)
{ {
citizen_aqualand_parser_t *parser = NULL; citizen_aqualand_parser_t *parser = NULL;
@ -61,7 +62,7 @@ citizen_aqualand_parser_create (dc_parser_t **out, dc_context_t *context)
return DC_STATUS_INVALIDARGS; return DC_STATUS_INVALIDARGS;
// Allocate memory. // Allocate memory.
parser = (citizen_aqualand_parser_t *) dc_parser_allocate (context, &citizen_aqualand_parser_vtable); parser = (citizen_aqualand_parser_t *) dc_parser_allocate (context, &citizen_aqualand_parser_vtable, data, size);
if (parser == NULL) { if (parser == NULL) {
ERROR (context, "Failed to allocate memory."); ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY; return DC_STATUS_NOMEMORY;
@ -73,13 +74,6 @@ citizen_aqualand_parser_create (dc_parser_t **out, dc_context_t *context)
} }
static dc_status_t
citizen_aqualand_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size)
{
return DC_STATUS_SUCCESS;
}
static dc_status_t static dc_status_t
citizen_aqualand_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) citizen_aqualand_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime)
{ {
@ -238,15 +232,15 @@ citizen_aqualand_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba
// Time // Time
time += interval; time += interval;
sample.time = time; sample.time = time * 1000;
if (callback) callback (DC_SAMPLE_TIME, sample, userdata); if (callback) callback (DC_SAMPLE_TIME, &sample, userdata);
// Depth // Depth
if (metric) if (metric)
sample.depth = depth / 10.0; sample.depth = depth / 10.0;
else else
sample.depth = depth * FEET; sample.depth = depth * FEET;
if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata);
// Temperature // Temperature
if (time % 300 == 0) { if (time % 300 == 0) {
@ -257,7 +251,7 @@ citizen_aqualand_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba
sample.temperature = temperature / 10.0; sample.temperature = temperature / 10.0;
else else
sample.temperature = (temperature - 32.0) * (5.0 / 9.0); sample.temperature = (temperature - 32.0) * (5.0 / 9.0);
if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata);
} }
} }
} }

View File

@ -30,8 +30,6 @@
#include "ringbuffer.h" #include "ringbuffer.h"
#include "rbstream.h" #include "rbstream.h"
#define C_ARRAY_SIZE(array) (sizeof (array) / sizeof *(array))
#define MAXRETRIES 2 #define MAXRETRIES 2
#define COCHRAN_MODEL_COMMANDER_TM 0 #define COCHRAN_MODEL_COMMANDER_TM 0
@ -41,6 +39,8 @@
#define COCHRAN_MODEL_EMC_16 4 #define COCHRAN_MODEL_EMC_16 4
#define COCHRAN_MODEL_EMC_20 5 #define COCHRAN_MODEL_EMC_20 5
#define UNDEFINED 0xFFFFFFFF
typedef enum cochran_endian_t { typedef enum cochran_endian_t {
ENDIAN_LE, ENDIAN_LE,
ENDIAN_BE, ENDIAN_BE,
@ -57,8 +57,8 @@ typedef struct cochran_data_t {
unsigned char *logbook; unsigned char *logbook;
unsigned short int dive_count; unsigned short int dive_count;
int fp_dive_num; unsigned int fp_dive_num;
int invalid_profile_dive_num; unsigned int invalid_profile_dive_num;
unsigned int logbook_size; unsigned int logbook_size;
} cochran_data_t; } cochran_data_t;
@ -621,18 +621,17 @@ cochran_commander_find_fingerprint(cochran_commander_device_t *device, cochran_d
// We track profile ringbuffer usage to determine which dives have profile data // We track profile ringbuffer usage to determine which dives have profile data
int profile_capacity_remaining = device->layout->rb_profile_end - device->layout->rb_profile_begin; int profile_capacity_remaining = device->layout->rb_profile_end - device->layout->rb_profile_begin;
int dive_count = -1; unsigned int dive_count = 0;
data->fp_dive_num = -1; data->fp_dive_num = UNDEFINED;
// Start at end of log // Start at end of log
if (data->dive_count < device->layout->rb_logbook_entry_count) if (data->dive_count < device->layout->rb_logbook_entry_count)
dive_count = data->dive_count; dive_count = data->dive_count;
else else
dive_count = device->layout->rb_logbook_entry_count; dive_count = device->layout->rb_logbook_entry_count;
dive_count--;
unsigned int sample_read_size = 0; unsigned int sample_read_size = 0;
data->invalid_profile_dive_num = -1; data->invalid_profile_dive_num = UNDEFINED;
// Remove the pre-dive events that occur after the last dive // Remove the pre-dive events that occur after the last dive
unsigned int rb_head_ptr = 0; unsigned int rb_head_ptr = 0;
@ -676,7 +675,7 @@ cochran_commander_find_fingerprint(cochran_commander_device_t *device, cochran_d
// Loop through dives to find FP, Accumulate profile data size, // Loop through dives to find FP, Accumulate profile data size,
// and find the last dive with invalid profile // and find the last dive with invalid profile
for (unsigned int i = 0; i <= dive_count; ++i) { for (unsigned int i = 0; i < dive_count; ++i) {
unsigned int idx = (device->layout->rb_logbook_entry_count + head_dive - (i + 1)) % device->layout->rb_logbook_entry_count; unsigned int idx = (device->layout->rb_logbook_entry_count + head_dive - (i + 1)) % device->layout->rb_logbook_entry_count;
unsigned char *log_entry = data->logbook + idx * device->layout->rb_logbook_entry_size; unsigned char *log_entry = data->logbook + idx * device->layout->rb_logbook_entry_size;
@ -953,7 +952,7 @@ cochran_commander_device_foreach (dc_device_t *abstract, dc_dive_callback_t call
} }
// Change tail to dive following the fingerprint dive. // Change tail to dive following the fingerprint dive.
if (data.fp_dive_num > -1) if (data.fp_dive_num != UNDEFINED)
tail_dive = (data.fp_dive_num + 1) % layout->rb_logbook_entry_count; tail_dive = (data.fp_dive_num + 1) % layout->rb_logbook_entry_count;
// Number of dives to read // Number of dives to read

View File

@ -35,7 +35,7 @@ dc_status_t
cochran_commander_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); cochran_commander_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
cochran_commander_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); cochran_commander_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model);
#ifdef __cplusplus #ifdef __cplusplus
} }

Some files were not shown because too many files have changed in this diff Show More