Compare commits

...

1286 Commits

Author SHA1 Message Date
Jef Driesen
72a88b18d9 Fix the date/time with timezone offset
When using the dc_datetime_gmtime() function for a timestamp with a
timezone offset, the timezone offset needs to be added to the timestamp
prior to the call.
2024-05-20 20:59:03 +02:00
Jef Driesen
eb4b082b1b Use a different buffer size for Rx and Tx
The BLE (and USBHID) protocol stores the size of the payload as a single
byte in the packet header. Hence the size of the payload is limited to a
maximum of 255 bytes. For sending packets, there is an additional
command byte present, which reduces the maximum payload size to 254
bytes. For receiving packets, there is no command byte present and thus
the maximum payload size is 255 bytes.

The Scubapro G3 sends BLE packets of 256 bytes, and that caused the
download to fail because the receive buffer was one byte too small.
2024-05-16 16:41:57 +02:00
Jef Driesen
8fe598e1b0 Merge branch 'sirius' 2024-05-03 17:27:39 +02:00
Jef Driesen
1663997111 Add support for the Mares Sirius (and compatible models)
The Mares Sirius uses the same communication protocol as the Genius,
except for the fact that it uses a newer BLE version which supports
larger data packets. The actual MTU is likely negotiated because we see
different sizes like 244 and 182 bytes. We don't have access to this MTU
size because not all BLE implementations can expose this information.

Unfortunately not only the BLE packet size is variable, but also the
size of the higher level data frames (used for downloading the content
of the objects) is no longer fixed. The frame size appears to adapt to
the BLE MTU size. This is most likely done to reduce the overhead and
maximize the throughput.

Although each frame ends with an OxEA byte, we can't rely on this
knowledge to detect the end of the frame. The END byte is not escaped in
the payload, and thus can also appear anywhere in the frame. As a
workaround, we rely on the fact that each frame appears to be send as a
single BLE packet. The only exception is the ACK byte, which gets send
as a separate BLE packet if the command requires parameter data.

Compatible models: Quad Ci, Puck 4 and Puck Air 2
2024-05-03 17:27:25 +02:00
Jef Driesen
f20d9cb972 Refactor the Mares Genius and Horizon parser
The current implementation assumes a fixed order for the different
record types to share some code with the older models. See commits [1]
and [2] for more details. The main disadvantages of this approach are
the extra complexity and the limited flexibility to adapt to future
changes to the data format.

To make the parsing code more future proof, split the code into separate
functions for the Genius/Horizon and the older models.

[1] Commit 8b06f2c31d437d6e067c21e7263b5ccc33539537 (Horizon)
[2] Commit feec939a2924095f07e030aa98d839b40d4cb6cc (Genius)
2024-05-03 17:27:25 +02:00
Jef Driesen
4516842a5a Use a new command to read the serial number
The Mares Genius (and compatible models) uses a new command to download
different types of objects, instead of manually reading and parsing the
flash memory. This command also supports reading device properties like
the serial number.

This change is necessary because newer models like the Sirius no longer
support reading directly from the flash memory.
2024-05-03 17:27:25 +02:00
Jef Driesen
9a603fa8cf Use macros to detect the device type
The macros make the code a bit more compact, and adding support for new
models becomes easier too.
2024-05-03 17:27:25 +02:00
Jef Driesen
89a28427d6 Increase the BLE packet size
Devices supporting BLE 4.2 (or higher) can use data packets with a
payload size of up to 244 bytes. None of the current Mares models
support this at the moment, but increasing the size on the receiving
side already prepares the code for future models and remains fully
backwards compatible.
2024-05-03 17:27:22 +02:00
Jef Driesen
4914f6bff3 Fix the memory layout of the Oceanic Geo
For devices with a newer firmware version (2B) the profile ringbuffer
ends already at 0xFE00, while for devices with an older firmware version
(1D) it runs to the end of the memory.
2024-04-21 22:50:57 +02:00
Jef Driesen
dcf842cd9d Fix the Apeks DSX tank number
Since commit f5f855d4284a84d5249462c46a9c4f6107a12b09, the tank number
should remain one based instead of zero based.
2024-04-01 23:37:37 +02:00
Jef Driesen
8745a3b95a 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-03-26 22:32:48 +01:00
Jef Driesen
a86cb92ed8 Add some more details to the error messages 2024-03-26 22:19:02 +01:00
Jef Driesen
b8c3a09c6f Fix a macro redefinition warning
The C library stdio.h header file already defines the EOF macro. Rename
our macro to avoid the conflict.
2024-03-21 19:18:04 +01:00
Jef Driesen
6903a66cc5 Update the Github actions
All Github actions using Node.js 16 are deprecated [1]. Update the
following actions to a newer version using Node.js 20:

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

[1] https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/
2024-03-20 17:31:15 +01:00
Janice McLaughlin
9070da3570 Add support for the Aqualung i330R and Apeks DSX
The Aqualung i330R and Apeks DSX use a completely new communication
protocol. The main (and most problematic) difference is the use of a
proprietary bluetooth pairing mechanism instead of the standard
bluetooth pairing. The data format remains more or less compatible with
the previous models, with only the usual changes to the parser.

The initial code and reverse engineering work was contributed by Janice,
with further improvements and modifications for integration in
libdivecomputer by Jef.

Co-authored-by: Jef Driesen <jef@libdivecomputer.org>
2024-03-20 17:24:59 +01:00
Jef Driesen
8e349d4046 Add ioctl's for the bluetooth authentication
For dive computers which are using an application specific proprietary
pairing mechanism instead of the standard bluetooth pairing, we need to
be able to exchange some additional information with the application.
Therefore, 3 new BLE specific ioctl's are added:

When a device has not been paired yet, libdivecomputer will request the
PIN code from the application with DC_IOCTL_BLE_GET_PINCODE. Once the
device has been paired successfully, the access code is passed back to
the application with DC_IOCTL_BLE_SET_ACCESSCODE. On the next download,
libdivecomputer will request this access code again from the application
with DC_IOCTL_BLE_GET_ACCESSCODE. If no access code is available, the
pairing procedure will start again by requesting the PIN.
2024-03-20 17:24:59 +01:00
Jef Driesen
47f6949db1 Merge branch 'pelagic-refactor' 2024-03-20 17:24:25 +01:00
Jef Driesen
9070b7d035 Log the ringbuffer pointers
Logging the ringbuffer pointers is very useful while investigating
problems and adding support for new models.
2024-03-20 17:23:46 +01:00
Jef Driesen
4cc0bc25ae Support reading the logbook in forward direction
To prepare the code to support reading the logbook ringbuffer in the
forward direction, a new field is added to the layout data structure to
indicate the direction of the ringbuffer, the workaround for handling an
invalid pointer is extended to support both directions, and finally the
correct parameters are passed to the rbstream reader.
2024-03-20 17:23:46 +01:00
Jef Driesen
f49af5208c Separate the error handling from the size calculation 2024-03-20 17:23:46 +01:00
Jef Driesen
b9d7684552 Refactor the code to read the ringbuffer pointers
Move the code to read the ringbuffer pointers into a separate function
that deals with all the quirks internally and simply returns two
begin/end pairs.

To obtain the logbook end pointer, the page size is now added to the
value of the last pointer without taking into account the ringbuffer
boundaries. Therefore the boundary checks in the caller need to be
relaxed to accept the end pointer as a valid value.

The profile begin/end pointers are not used anywhere and are only
retrieved for diagnostics purposes.
2024-03-20 17:23:46 +01:00
Jef Driesen
ae292253ba Refactor the code to read the device info
Move the code to read and emit the device info into a separate function
to reduce some code duplication.

As a side effect, the check for devices without a logbook and profile
ringbuffer needs to be performed earlier now, in order to prevent a
division by zero in the progress events.
2024-03-20 17:23:46 +01:00
Jef Driesen
a91a7dbc38 Refactor the function to get the profile pointers
Refactor the code to retrieve the profile pointers from the logbook
entry into a single function that deals with all the quirks internally
and simply returns a begin/end pair.

To obtain the end pointer, the page size is now added to the value of
the last pointer without taking into account the ringbuffer boundaries.
The consequence are:

 - The boundary checks in the caller need to be relaxed to accept the
   end pointer as a valid value.
 - The check for the gap between the profiles can no longer compare the
   pointer values directly because the begin/end values are equivalent,
   but not equal.
2024-03-20 17:23:46 +01:00
Jef Driesen
121c7c12fb Swap values 2 and 3 of the pointer mode
Swapping values 2 and 3 of the pointer mode has the advantage that only
the mode with the largest value uses bytes as its unit, while all others
use the page size as their unit.
2024-03-20 17:23:43 +01:00
Jef Driesen
f42449b101 Fix the Aeris 500AI logbook read command
The two bytes in the command to read the logbook index are most likely
not a single 16 bit number, but two 8 bit numbers specifiying a range.
The same pattern can be found in the logbook pointers.
2024-03-15 14:26:25 +01:00
Jef Driesen
aa2dbac509 Log the number of skipped bytes 2024-03-15 14:26:25 +01:00
Jef Driesen
60a9b889de Merge branch 'ringbuffer' 2024-03-14 12:26:52 +01:00
Jef Driesen
4139509238 Use symbolic constants for empty/full ringbuffer 2024-03-14 12:26:24 +01:00
Jef Driesen
1ba7e5cad0 Fix errors in the ringbuffer operations
The ringbuffer calculations contained several flaws:

The ringbuffer_normalize() function doesn't shift the result from the
internal normalize call back to the range [begin,end-1]. The only reason
why this bug didn't cause any issues yet, is because this function isn't
used anywhere.

The ringbuffer_distance() function can return a wrong result whenever
the difference between the two values is an exact multiple of the
ringbuffer size. For example:

  distance(x,x,n)   == 0 or n (depending on the empty/full mode)
  distance(x,x+n,n) == 0
  distance(x+n,x,n) == n

So far this bug didn't cause any problems yet, because in practice this
function is always used with values inside the safe range [begin,end-1].

For input values outside the safe range [begin,end-1], only larger
values are accepted, while smaller values will trigger an assert.

A zero-length ringbuffer (e.g. begin == end) results in a division by
zero.
2024-03-14 12:26:24 +01:00
Jef Driesen
04fe252625 Merge branch 'rbstream' 2024-03-14 12:26:07 +01:00
Jef Driesen
9090f713b4 Add support for reading a ringbuffer forwards
A dive computer typically writes its ringbuffer in the forward
direction. Thus, when downloading the dives in reverse order (newest
first), the ringbuffer needs to be read in the backward direction.

However, some dive computers already re-arrange the data in the correct
order, which means the data needs to be read in the opposite direction.
To support this case without drastic changes in the logic, the rbstream
implementation is extended to also support reading in the forward
direction.
2024-03-14 12:25:37 +01:00
Jef Driesen
00b0169578 Update the internal state in-place
Some of the internal state is cached in local variables at the start of
the function, and is updated only at the end of the function. But the
contents of the packet buffer is never cached. As a result, the two can
go out of sync when an error occurs and the function returns early.
Trying to restore the original state is pointless if the corresponding
data in the packet buffer is no longer available.

Fixed by removing the local variables and always updating the internal
state in-place to reflect the current state.
2024-03-14 12:24:58 +01:00
Jef Driesen
e0cf41a14e Add some extra parameter validation
The ringbuffer boundary addresses (begin/end) should be ordered
correctly, and the packet size should be smaller than the ringbuffer
size, otherwise the code won't work as expected.
2024-03-14 12:24:45 +01:00
Jef Driesen
f5f855d428 Discard pressure samples from invalid tanks
Keeping the one based tank number interally allows to easily discard the
pressure samples from invalid tanks. This avoid returning a huge tank
number (e.g. 0xFFFFFFFF) when the internal tank number happens to be
zero.
2024-03-13 16:52:05 +01:00
Janice McLaughlin
811ae7de82 Add the deco and rbt samples
Add the deco and rbt samples for the Oceanic Pro Plus 4 and Aeris Atmos
AI 2.
2024-03-13 16:51:55 +01: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
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
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
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
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
070de23b83 Post release version bump to 0.9.0 2023-05-11 18:56:37 +02:00
Jef Driesen
db9371cf9f Release version 0.8.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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Jef Driesen
631cfd8c45 Add Travis CI integration 2018-08-30 08:11:18 +02:00
Jef Driesen
a4d9f72cf0 Fix the transport command-line parameter 2018-08-27 10:29:23 +02:00
Kristaps Dz
e4f04128be Document dc_descriptor_get_model 2018-08-27 10:28:02 +02:00
Calle Gunnarsson
4da94a7285 Include stddef.h in iostream.h
This header need to be included to successfully generate Go-bindings.
2018-08-20 07:55:54 +02:00
Jef Driesen
ff1ee12770 Add support for the Mares Smart Air
The Smart Air uses almost the same data format as the Quad Air. Only the
4 bytes containing the dive mode and number of samples moved from the
beginning of the header to the end. This is a change adopted from the
regular Smart.
2018-08-16 08:33:44 +02:00
Jef Driesen
17b3e07398 Fix the average depth for older OSTC dives
For older OSTC dives, using logbook format version 0x20, the average
depth is not available in the dive header. It's only available since
version 0x21, which increased the header size from 47 to 57 bytes.
2018-08-10 12:57:20 +02:00
Jef Driesen
aee70d1ec7 Add support for the Oceanic Pro Plus X
The Oceanic Pro Plus X is quite different from the previous models. The
profile data is now stored in a dedicated memory area, and hence there
are a few important differences:

Reading data from the new profile memory area is done with a new F6
command. This new command is very similar to the existing B8 command,
but accesses a completely different memory area. In order to integrate
those two memory areas as transparantly as possible into the existing
infrastructure, a virtual memory space is introduced. The lower part of
the virtual memory is mapped onto the main memory area, while the upper
part is mapped onto the new profile memory area.

The page size of the new profile memory area also increased from 16 to
256 bytes. If the profile size is not an exact multiple of 256 bytes,
the dive computer pads the profile data with 0xFF bytes.

The other changes are the usual Oceanic device specific changes.
2018-07-20 10:18:49 +02:00
Jef Driesen
b3144ac26b 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.
2018-06-28 16:35:36 +02:00
Jef Driesen
564958f927 Fix an uninitialized variable
In the error handling code, the dc_buffer_free() function can be called
with an unitialized "buffer" variable as parameter. Fixed by adding an
extra label.

Reported-By: Linus Torvalds <torvalds@linux-foundation.org>
2018-06-28 16:35:36 +02:00
Jef Driesen
0d73a38900 Initialize the socket library for the bluetooth discovery
On Windows, the WSAStartup() function needs to be called, to initialize
the socket library, before using any of the other WSA socket functions.
This includes the functions used for the bluetooth device discovery.
2018-06-27 15:51:44 +02:00
Jef Driesen
41f50534aa Fix the length of the Suunto D6i gas change event
The latest Suunto D6i firmware uses 5 bytes for the 0x06 gas change
event.

Reported-By: Nick Shore <support@mac-dive.com>
2018-06-27 09:35:44 +02:00
Jef Driesen
472e9e984c Add support for the Tecdiving DiveComputer.eu 2018-06-22 23:24:30 +02:00
Jef Driesen
2985616532 Fix the Mac OS X timer implementation
The Mac OS X timer implementation returned timestamps with nanoseconds
as unit instead of microseconds.

Reported-by: Rick Balsano <rick.balsano@gmail.com>
2018-06-22 23:21:51 +02:00
Jef Driesen
6085a11b1f Add the average depth to the xml output 2018-06-22 23:14:15 +02:00
Jef Driesen
51d6a40132 Merge branch 'uwatec' 2018-06-22 23:13:54 +02:00
Jef Driesen
b3ebfa0e6e Skip the handshake for BLE communication
The Scubapro LogTrak application doesn't send the handshake commands for
BLE communication. Also the Aladin Sport Matrix, which supports only
BLE, responds with a 0x01 byte instead of the expected 0x01 byte and
that causes the handshaking to fail. Thus simply omit the handshaking
for BLE communication.

Reported-by: Berthold Stöger <berthold.stoeger@tuwien.ac.at>
2018-06-22 23:13:44 +02:00
Jef Driesen
8aef4a49a0 Unify the Uwatec Smart, Meridian and G2 backends
The Uwatec Smart, Meridian and G2 backends are almost identical, except
for the low-level packet sending and receiving code. With the new I/O
layer, those three backends can easily be unified in a single backend.

The Meridian and G2 are completely removed, only the family types are
kept for backwards compatibility.
2018-06-22 23:13:44 +02:00
Jef Driesen
1a0909ac92 Re-organize the packet send/receive code
Add separate send and receive helper functions. This is mainly a
preparation step for a larger re-organization of the Uwatec code.
2018-06-22 23:13:44 +02:00
Jef Driesen
c2fc0cdd1c Use symbolic constants for the commands 2018-06-22 23:13:44 +02:00
Jef Driesen
6ed9c3c64c Implement an rfcomm filter function 2018-06-22 08:22:31 +02:00
Jef Driesen
0fde62050d Remove the filter for HW OSTC's without bluetooth
The HW OSTC models without bluetooth support don't need the filter
function.
2018-06-21 22:53:19 +02:00
Jef Driesen
680f233690 Implement the sleep function for IrDA and bluetooth 2018-06-21 22:23:53 +02:00
Jef Driesen
ab37d94ee9 Add a missing event descriptor
The Aladin Tec (and Tec 2G) sample descriptor table supports up to two
event bytes, but there is only a single event descriptor. This missing
descriptor causes a fatal error during parsing. Add a dummy descriptor
to avoid the error.
2018-06-11 12:54:50 +02:00
Jef Driesen
cecf8c5d6f Add support for the Seac Guru
The Seac Guru is compatible with the DiveSystem/Ratio dive computers.
2018-04-21 08:28:13 +02:00
Thomas E. Horner
4879174164 Fix building without logging enabled 2018-04-20 07:57:31 +02:00
Jef Driesen
26f4cae47c Fix a critical mistake in the OSTC3 code
Instead of reading data packets, the code is actually sending some
random data to the dive computer! A small typo with bad consequences!

This is a critical bug because it not only causes the download to fail,
but also appears to change random settings on the dive computer. I
suspect that the garbage data that gets send to the dive computer
happens to contain some valid write settings commands.
2018-04-19 15:05:21 +02:00
Jef Driesen
8a3fd3b136 Add udev rules for some dive computers 2018-04-19 15:03:39 +02:00
Jef Driesen
62d54cf3f3 Merge branch 'iostream' 2018-04-17 08:40:31 +02:00
Jef Driesen
29f781f803 Fix a typo in the comments 2018-04-17 08:36:26 +02:00
Jef Driesen
56d194d377 Use a NULL pointer for the no-op implementation
For most I/O stream implementations the serial communication specific
functions are meaningless. Implementing them as no-ops allows the dive
computer backends the call the I/O stream functions unconditionally.

However, implementing the no-op with a dummy function returning
DC_STATUS_SUCCESS, does not only add some (small) overhead at runtime,
but also requires many such functions. This is inconvenient and the same
result can easily be obtained by using a NULL pointer instead.

The consequence is that the logic is reversed now. To obtain the
previous behaviour of returning the DC_STATUS_UNSUPPORTED error code
again, you'll need to implement a dummy function. But that's fine
because it's the less common case.
2018-04-17 08:18:35 +02:00
Jef Driesen
1908394af4 Add some extra logging 2018-04-12 10:07:53 +02:00
Jef Driesen
945898f8fd Always initialize the output parameters
I/O functions with output parameters, should always initialize those
output parameters, even when an error is returned. This prevents the
(accidental) use of uninitialized variables, whenever the caller forgets
to check the return code.

As a nice side effect, the use of a local variable guarantees that the
underlying I/O implementation will always receive a valid pointer.
2018-04-12 10:07:30 +02:00
Jef Driesen
8957d61f4e Add support for the Scubapro G2 Console
The G2 Console is identical to the G2, except for the new USB PID.
2018-04-06 13:15:11 +02:00
Jef Driesen
c5504b5437 Merge branch 'usbhid' 2018-04-03 22:06:18 +02:00
Jef Driesen
3d394c9262 Don't use the USB VID/PID for opening the device
When two or more identical (or very similar) dive computers are
connected, the USB VID/PID can be ambiguous. That's because the VID/PID
identifies the type of the USB device, and not the individual device.
But each USB HID device descriptor returned by the device discovery
represents a single connected device, and thus guarantees to open the
correct USB device.

To obtain the same behaviour as before, an application can simply open
the first discovered device.
2018-04-03 22:02:15 +02:00
Jef Driesen
9477791bfe Use a reference counted USB session
Replace the global USB library context with a reference counted session
to manage the lifetime of the USB library context. For the libusb based
implementation, this is actually a much better match for the underlying
libusb api, and allows to eliminate the global state. For the hidapi
based implementation, the global state is unavoidable because the hidapi
doesn't support multiple sessions. Therefore we use a singleton session.
2018-04-03 21:58:26 +02:00
Jef Driesen
5bec560673 Merge branch 'ble' 2018-04-03 21:52:58 +02:00
Jef Driesen
8f7abc5a2d Add BLE support for the Shearwater devices
The main difference with the serial communication is that the BLE
communication transmits each SLIP encoded data packet as one or more BLE
data packets. The BLE packets have an extra two byte header with the
total number of packets and the current packet number.
2018-04-03 21:52:20 +02:00
Jef Driesen
0978f8c0fa Add BLE support for the HW OSTC3 devices
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.
2018-04-03 21:52:20 +02:00
Jef Driesen
3dcf93e26e Add BLE support for the Scubapro G2 devices
The main difference with the USB HID communication is that the BLE data
packets have a variable size and are no longer padded to the full 32
(Tx) or 64 (Rx) bytes.
2018-04-03 21:52:20 +02:00
Jef Driesen
afff8b450f Add BLE support for the Suunto Eon Steel devices
The main difference with the USB HID communication is that the BLE data
stream is encoded using HDLC framing with a 32 bit CRC checksum. Due to
this encoding, the data packets can no longer be processed one by one
(as is done for the USB HID packets). The entire HDLC encoded stream
needs to be received before it can be processed. This requires some
additional buffering.
2018-04-03 21:52:20 +02:00
Jef Driesen
a7d0033bae Add a Bluetooth Low Energy (BLE) transport type
Libdivecomputer doesn't have built-in support for BLE communication yet,
so this is mainly for future use and custom I/O implementations.
2018-04-03 21:52:20 +02:00
Jef Driesen
0c5cf94b10 Merge branch 'iostream' 2018-04-03 21:44:49 +02:00
Jef Driesen
6b50e7f959 Set a default transport in the examples
Setting a default transport type avoids the need to explicitely set a
transport using the the new --transport command-line option. This also
preserves backwards compatibility with previous versions where the
option didn't exist yet.
2018-04-03 21:44:08 +02:00
Jef Driesen
630b5e7c3c Add support for the scan command 2018-04-03 21:44:08 +02:00
Jef Driesen
c50958495d Update the example application
The dctool example application is updated to the latest changes:

 - The I/O stream is opened and closed by the application.

 - A new (mandatory) option is added to select the desired transport
   type. This is nessecary because several dive computers support
   multiple transport types now.
2018-04-03 21:44:08 +02:00
Jef Driesen
44eba5515c Move the I/O implementations to the public api
The I/O implementations need to be exposed in the public api, otherwise
applications won't be able to use them!
2018-04-03 21:44:08 +02:00
Jef Driesen
ef2402eff5 Integrate the new I/O interface in the public api
Currently the dive computer backends are responsible for opening (and
closing) the underlying I/O stream internally. The consequence is that
each backend is hardwired to a specific transport type (e.g. serial,
irda or usbhid). In order to remove this dependency and support more
than one transport type in the same backend, the opening (and closing)
of the I/O stream is moved to the application.

The dc_device_open() function is modified to accept a pointer to the I/O
stream, instead of a string with the device node (which only makes sense
for serial communication). The dive computer backends only depend on the
common I/O interface.
2018-04-03 21:11:06 +02:00
Jef Driesen
30ea13b36b Remove the obsolete transport function
With the support for multiple transports per device, the
dc_descriptor_get_transport() function became obsolete because it does
support only a single transport type. Applications should use the new
dc_descriptor_get_transports() function instead.
2018-04-03 21:11:06 +02:00
Jef Driesen
46608ce898 Always enable all device descriptors
With the support for multiple transports per device and the possibility
to use custom I/O implementations, libdivecomputer no longer knows which
devices are actually supported. Hence libdivecomputer needs to always
report all the devices it knows about, and it's up to the application to
filter out entries for which there is no suitable transport available
(either built-in or custom).
2018-04-03 21:11:06 +02:00
Jef Driesen
aee59a33be Add support for querying the available built-in transports
Because the list of supported built-in transports depends on the
availability of external libraries (libusb, hidapi) and the operating
system, the application needs some mechanism to retrieve this
information at runtime. Therefore, a new dc_context_get_transports()
function is added, which returns a bitmask with all the available
built-in transports.
2018-04-03 21:11:06 +02:00
Jef Driesen
eed993fd16 Add support for multiple transports per device
Several dive computers support multiple transports. For example the
Suunto Eon Steel supports both USB HID and BLE. All devices using
bluetooth classic communication support both the native bluetooth
transport and the legacy serial port emulation.

To support this feature, the values of the dc_transport_t type are
changed into bitmasks, and the dc_descriptor_t struct is extended with a
bitfield with all the supported transports.
2018-04-03 21:11:06 +02:00
Jef Driesen
3230387fff Add the transport type to the I/O stream
Add a function to query the underlying transport type. This allows the
dive computer backends to implement transport specific behaviour where
necessary.

For the built-in I/O implementations, the transport type is obviously
always hardcoded, but for a custom I/O implementation the application
needs to provide the correct type. Hence the transport type can't be
hardcoded in the vtable and needs to be passed as a parameter.
2018-04-03 21:11:06 +02:00
Jef Driesen
7c95581826 Merge branch 'eonsteel' 2018-04-03 21:10:24 +02:00
Jef Driesen
7d48cffc0d Simplify the packet send/receive code
Re-organize the packet sending and receiving code to eliminate the need
for different code paths for the init command and all other commands.
2018-04-03 21:10:04 +02:00
Jef Driesen
43f196b804 Remove the code to purge the input buffer
Trying to purge the input buffer by reading and discarding data packets,
results in an annoying and confusing error message if no data packet is
received. To avoid this error, the functionality should be integrated in
the USB HID code, either automatically during initialization or by
implementing the purge function.

But since there seems to be no evidence that this is actually necessary,
let's remove this code.
2018-04-03 21:10:04 +02:00
Jef Driesen
5344f3926a Abort with an error if the buffer is too small
Silently truncating the data packet if the buffer is too small will
result in a corrupt data stream.
2018-04-03 21:10:04 +02:00
Jef Driesen
38c3f289b5 Improve the error reporting
The error codes from the I/O layer are now correctly returned to the
upper layers.
2018-04-03 21:10:04 +02:00
Jef Driesen
755b52febc Improve the fingerprint matching
Check the fingerprint before downloading the dive. If a match is found,
this avoids some unnecessary communication and thus makes the download a
little bit faster.
2018-04-03 21:10:04 +02:00
Jef Driesen
01ccb7ce4b Fix a few memory leaks
The file list isn't freed when an error occurs, and the strings returned
from the lookup_enum function are dynamically allocated and thus should
be freed as well.
2018-04-03 21:10:04 +02:00
Jef Driesen
96bac1de13 Fix some compiler warnings
The descriptor strings are dynamically allocated and owned by the
struct. The const qualifiers are a bit misleading here, and result in
warnings when trying to free the pointers again.
2018-04-03 21:10:04 +02:00
Jef Driesen
ea2272d4b0 Fix a build error for msvc
The msvc build needs the platform header for the non-standard _snprintf
function.
2018-04-03 21:06:48 +02:00
Jef Driesen
2c7d1fe39f Use 64bit arithmetic to avoid overflow
The multiplication is evaluated using 32bit arithmetic, and then stored
in a 64bit integer. The 32bit integer overflow can be avoided by casting
to a 64bit type first.
2018-04-03 21:06:48 +02:00
Jef Driesen
54fef8e093 Add support for using an optional device descriptor
The device descriptor is either mandatory for a certain command (with
DCTOOL_CONFIG_DESCRIPTOR) or always NULL. But for some commands it will
be useful to support an optional descriptor as well. To support this, we
always try to lookup the device descriptor whenever the corresponding
command-line options are set.
2018-04-03 21:06:48 +02:00
Jef Driesen
0026fbd289 Re-write the slip encoding and decoding
The write function is modified to always fill the buffer completely
before sending out the data. For escaped characters, the previous
implementation needed to append two bytes at once. Thus, if there was
only space left for a single byte, the buffer got flushed early with one
byte still unused. This can be avoid by appending one byte at a time.

The read function is modified to use a simple state machine with only a
single read call. This is mainly preparation to support reading and
processing larger data packets instead of just single bytes.
2018-04-03 21:06:48 +02:00
Jef Driesen
b62f160dd5 Workaround for an OSTC4 issue
I received a bug report complaining that the most recent dives did not
get downloaded. It turns out that the internal dive number in the
logbook entries got reset back to zero somehow:

Logbook   0: empty
...
Logbook 209: empty
Logbook 210: 1
Logbook 211: 2
...
Logbook 235: 26
Logbook 236: 27
Logbook 237: 0
Logbook 238: 1
...
Logbook 254: 17
Logbook 255: 18

This confuses the logic to locate the most recent dive. Because that
logic assumes that the entry with the highest internal dive number is
always the most recent dive, it finds logbook entry #236 instead of the
correct entry #255. Now, when processing the logbook entries backwards,
it stops at those empty entries, and thus never reaches then newest
entries #237 to #255.

The workaround is based on the fact that the OSTC4, unlike the other
hwos based models, already re-orders the logbook entries and always
sends the most recent logbook entry last. So we can ignore the dive
number and simply use the last non-empty entry.
2018-04-03 21:06:48 +02:00
Linus Torvalds
c15d422f75 Suunto EON Steel: set date too when doing device timesync
I'd never noticed this before, since my date had always been already set
correctly, but the timesync with the EON Steel only set the time, not
the date.

The fix is trivial, since the code already filled in the datetime data,
it just didn't do the SET_DATE command.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-04-03 21:01:39 +02:00
Jef Driesen
5207fcd86b Add support for the dive mode
The Dive Rite NiTek Q supports OC and CC samples. For reporting the dive
mode, any dive containing at least one CC sample is considered to be a
CCR dive.
2018-03-09 21:35:51 +01:00
Jef Driesen
38ff1f75dd Remove the half-duplex emulation from the I/O api
Now that the half-duplex emulation code isn't used anymore, it can be
removed from the I/O stream api.
2018-03-05 09:08:21 +01:00
Jef Driesen
4897a8351b Handle the half-duplex emulation in the vyper2 backend
The half-duplex emulation is basically a workaround for a timing problem
in the vyper2 backend. Since no other dive computer backend uses or
needs this feature, it makes no sense to support this at the I/O layer.
It can be implemented directly in the vyper2 backend instead.
2018-03-05 09:08:21 +01:00
Jef Driesen
ee31f24cfb Use the new timer for the timestamps in the logging
Replace the platform specific code with the new timers.
2018-03-05 09:08:21 +01:00
Jef Driesen
eb4c150024 Use the new timer for the timeout calculations
Replace the gettimeofday() based implementation with the new monotonic
timers. This makes the implementation more robust against unexpected
adjustments of the clock.
2018-03-05 09:08:21 +01:00
Jef Driesen
a8adb16c0d Add a high resolution timer module
The new timer module provides an cross-platform interface for a high
resolution monotonic clock. The timestamps are always relative to the
creation of the timer and their unit is one microseconds.

The timers can be used for logging, measuring elapsed time and
implementing timeouts.
2018-03-05 08:44:14 +01:00
Jef Driesen
becaf02ab6 Add functions for converting bluetooth addresses 2018-03-04 20:49:49 +01:00
Jef Driesen
efd47cd9a1 Add support for the OSTC 2 TR
The OSTC 2 TR add supports for one or more tank pressure transmitters,
and the active transmitter is linked to the active gas mix.
2018-02-17 10:22:44 +01:00
Jef Driesen
0ac15dffd3 Add a workaround for invalid logbook begin pointers
Unfortunately there are several devices where an invalid logbook begin
pointer occurs relative frequently. Typical examples are the Oceanic VT
4.1 and the Sherwood Wisdom 2. 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 oldest logbook
entry, we can fall back to downloading the entire logbook ringbuffer. If
we're lucky (and we usually are), we can detect the oldest entry by
inspecting the logbook entries once they are downloaded (e.g. presence
of uninitialized entries) and then the download will finish succesfully.
In the worst case scenario, we'll be able to download at least some
dives before hitting another error.
2018-02-06 13:00:57 +01:00
Jef Driesen
05f5522210 Let the ringbuffer function handle a full ringbuffer
The ringbuffer_distance() function has a parameter to specify whether a
ringbuffer with identical begin/end pointers should be considered an
empty or a full ringbuffer. Hence there is no need to handle the case of
a full ringbuffer manually.
2018-02-06 13:00:34 +01:00
Jef Driesen
9117b593fc Suppress the warning if no O2 sensors are present
The warning about disabling the O2 sensors due to factory default
calibration values, applies only if there is at least one calibrated O2
sensor present.

This has no effect on the calibration bits, because those are already
zero if there are no calibrated O2 sensors present.
2018-02-05 19:58:22 +01:00
Jef Driesen
85eef19f8f Integrate the connect step into the open function
There is no need to expose the two step connection setup of the
underlying socket interface in the public api. Doing so may complicate
the implementation on platforms where the native api is not based on the
socket interface (e.g. Mac OS X).

Note that the function to connect based on the IrDA service name is
removed. It's not used anywhere in libdivecomputer and since IrDA is an
outdated technology nowadays, it's unlikely we'll need it in the future.
2018-02-04 21:21:42 +01:00
Jef Driesen
695212ddf8 Merge branch 'discovery' 2018-02-04 21:21:42 +01:00
Jef Driesen
0ce3bd3e6d Implement some filter functions 2018-02-04 21:21:42 +01:00
Jef Driesen
30e4060817 Add suport for applying a filter function
The device descriptors are extended with a filter function. During the
device discovery, this filter function is used to return only devices
that match a known dive computer.

The filtering is optional, and can be disabled by passing a NULL pointer
for the device descriptor when creating the iterator with one of the
dc_xxx_iterator_new() functions.
2018-02-04 21:21:42 +01:00
Jef Driesen
ca91500ed5 Re-write the device discovery using the iterator api
Replacing the callback based interface with an iterator based interface,
results in a more extensible abstraction with a common interface for
each of the built-in I/O implementations (serial, usbhid, irda and
bluetooth).
2018-02-04 21:21:16 +01:00
Jef Driesen
296fad2d9d Cleanup the iterator internals 2018-01-30 22:00:41 +01:00
Jef Driesen
f992d201ad Simplify the conditional compilation
Move the global variables inside an existing conditionally compiled
block, to remove some of the #ifdef's.
2018-01-30 21:21:21 +01:00
Jef Driesen
931d1857ce Disable some Windows specific compiler warnings
The -Wno-pedantic-ms-format option is only needed for the MinGW target.
But for some reason, the AX_APPEND_COMPILE_FLAGS macro enables the
option for all other GCC targets too. But during compilation GCC outputs
the warning "unrecognized command line option".
2018-01-30 21:21:21 +01:00
Jef Driesen
90eed3c790 Use SDP to auto-detect the rfcomm port number
When the port number is set to zero (which is an invalid value), detect
the port number automatically. On Windows, we can simply supply the UUID
of the serial port service, and the Windows api will take care of the
discovery. On Linux (bluez), the SDP discovery needs to be performed
manually to retrieve the port number.
2018-01-30 21:21:21 +01:00
Jef Driesen
6d5ac37f99 Use the actual IrDA device names 2018-01-30 21:21:21 +01:00
Jef Driesen
9e169c9a3f Use the correct data type for the temperature
Temperatures are reported as a floating point values and not as
(unsigned) integers.
2018-01-30 21:20:53 +01:00
Jef Driesen
3e36cad5ee Disable O2 sensors with default calibration values
If all (calibrated) sensors still have their factory default calibration
values (2100), they are probably not calibrated properly. To avoid
returning incorrect ppO2 values to the application, they are manually
disabled (e.g. marked as uncalibrated).
2018-01-30 19:56:49 +01:00
Jef Driesen
9ca91ca584 Add support for the Seac Jack
The Seac Jack is compatible with the DiveSystem/Ratio dive computers.
2018-01-30 19:52:27 +01:00
Jef Driesen
0ae9e355f8 Check for memory allocation errors
Appending data to the buffer may fail if a memory allocation is
necessary to enlarge the buffer. Hence the return value of the
dc_buffer_append() call should always be checked, unless the memory was
already pre-allocated or the check is deferred after the last operation.
2018-01-29 15:06:58 +01:00
Jef Driesen
c194f559d8 Erase the buffer before calling the vtable function
This guarantees that the backend will always receive an empty buffer,
and eliminates the need to clear the buffer manually in every single
backend.
2018-01-09 15:54:44 +01:00
Jef Driesen
d23bc6e089 Replace hardcoded size with the sizeof operator 2018-01-09 15:54:44 +01:00
Jef Driesen
c3556d81c9 Use the correct model number for the Shearwater Nerd 2
Unlike the Shearwater Petrel, the Shearwater Nerd 2 appears to have a
distinct model number from the Nerd.

Reported-by: Janice McLaughlin <janice@moremobilesoftware.com>
2018-01-09 15:53:52 +01:00
Jef Driesen
21b0f01852 Merge branch 'coverity' 2018-01-04 20:23:50 +01:00
Dirk Hohndel
4335c9b9eb Cleanup: remove confusing NULL check
device has already been dereferenced before we ever get here

Coverity CID 207713
Coverity CID 207780

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01:00
Dirk Hohndel
4144e0c7ff Cleanup: bail on error
Coverity CID 207809

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01:00
Dirk Hohndel
2f097e54fe Cleanup: consistently check return value of iostream functions
Coverity CID 215197
Coverity CID 215200

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01:00
Dirk Hohndel
4e93b9a8f8 Cleanup: check return value of ioctl()
It's checked for all the other invocations...

Coverity CID 207796

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01:00
Dirk Hohndel
e22adbb3f9 Cleanup: remove dead code and return the correct return code
Coverity CID 207700

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01:00
Dirk Hohndel
88cc5e1413 Cleanup: avoid undefined shift operation
Shifting a 32bit value by 32 is undefined.

Instead of using shifts to create the mask, explicitly create it by
subtracting 1 from the signbit value (and using bitwise NOT to fill all
the higher bits).

This commit looks confusing because Jef wanted me to not have two places
where I use the bitwise not. So instead of creating an equivalent mask
variable and not having to change the return statements we end up with a
mask that is the bitwise invert of what was there before this commit and
therefore the return statements need to change as well.

Coverity CID 207769

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01:00
Dirk Hohndel
71f76819c0 Cleanup: ensure string is 0 terminated
The Linux kernel uses the sir_name as a standard C string (in one
instance copying it into a 60 char buffer using kstrncpy with a length
limit of 60), we therefore need to ensure that it is 0 terminated.

Since the existing code didn't notify the caller if we were truncating
the string at 25 characters, I didn't add such a warning/error for
truncating at 24 characters.

I was not able to find documentation on how Windows uses irdaServiceName
but since this is implementing the same standard, the same change was
made to the Windows code.

In both cases I replaced the hardcoded length of 25 with a sizeof()
argument (but both Linux and Windows hard code that length in their
headers, so it seems unlikely this would ever change).

Coverity CID 207790

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01:00
Dirk Hohndel
5997caf45f Cleanup: avoid memory leak
Coverity CID 207731

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01:00
Dirk Hohndel
681720e96a Cleanup: avoid memory leak
Coverity CID 207773

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:46:54 +01:00
Dirk Hohndel
96e6bf5848 Cleanup: avoid memory leaks
Coverity CID 207730
Coverity CID 207747

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:45:40 +01:00
Dirk Hohndel
bd00ddea17 Cleanup: correctly handle upper bound of array
Coverity CID 207684
Coverity CID 207724
Coverity CID 207728

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-04 19:45:40 +01:00
Jef Driesen
81f3fdd854 Fix a mistake in the error checking
This is a small bug that was introduced long time ago, with commit
84563c6303a4ab263ea19c973d3f0bbfe6fc0955.
2017-12-13 09:54:55 +01:00
Janice
a833992ed6 Add support for the Mares Quad Air 2017-12-13 09:50:52 +01:00
Dirk Hohndel
ca1efdcecd Correctly determine git SHA if libdivecomputer is a git submodule
In the case of a submodule, the .git file is a text file pointing to the
correct module in the parent's .git folder. The git rev-parse works
correctly in both cases.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-07 15:54:48 +01:00
Jef Driesen
42f8e012b7 Don't accept a NULL pointer as parameter
Immediately return an error instead of trying to pass the NULL pointer
to the underlying open system call.
2017-12-01 15:03:17 +01:00
Jef Driesen
f87720dff9 Add support for semi-closed circuit diving
Add a new type to distinguish between closed circuit (CCR) and
semi-closed circuit (SCR) diving. Some dive computers from HW and
DiveSystem/Ratio support this.

Because the CCR/SCR abbreviations are more commonly used, let's take the
opportunity to also rename the existing DC_DIVEMODE_CC. To preserve
backwards compatibility, a macro is added to map the old name to the new
one.

Reported-by: Jan Mulder <jlmulder@xs4all.nl>
2017-11-30 09:03:46 +01:00
Jef Driesen
76187c550a Detect dives with invalid profile data
The OSTC3 stores the dive headers and profile data in two separate
memory areas. There is a header area with fixed positions and a profile
area which is used as a ring buffer. Each dive header stores the
position of the profile data in the ring buffer.

Now, once there are more dive headers then room for the profiles, the
oldest profiles (but not the headers) are overwritten with new data.
Because the dive headers are not updated when their profile data gets
overwritten, they will now point to data that is no longer available.
The internal logbook detects this situation and does not display the
profile. But during the download, there is no such check, and the OSTC
will send invalid profile data.

This invalid profile data should be dropped on the receiver side.
Unfortunately implementing the exact same check as is done by the OSTC
itself isn't possible, because the OSTC doesn't send the 6 byte internal
header on which the check is based. As a workaround, the two byte
end-of-profile marker and the length field in the profile header is used
to detect overwritten profiles.
2017-11-30 09:03:46 +01:00
Jef Driesen
f98f5eba5f Merge branch 'iostream' 2017-11-26 23:07:57 +01:00
Jef Driesen
e22ba69819 Implement the serial communication functions as no-ops
For the socket based I/O stream implementations (IrDA and bluetooth) the
serial communication specific functions are meaningless. Implementing
them as no-ops allows the dive computer backends the call the I/O stream
functions unconditionally.

This is important for the bluetooth implementation, because bluetooth
enabled dive computers will be able to use both the native bluetooth
communication and the legacy bluetooth serial port emulation.
2017-11-26 23:00:33 +01:00
Jef Driesen
823303980e Move the socket code to a common file
A large part of the irda and bluetooth code is the Windows and BSD
socket code. Moving this code to a common file reduces code duplication.
2017-11-26 23:00:33 +01:00
Jef Driesen
283eaa1ca6 Add support for a custom I/O implementation
Wih the custom I/O implementation, an application can use its own
low-level I/O layer instead of using one of the built-in ones. The
application only needs to provide a set of callback functions, and
libdivecomputer will wrap them into a I/O stream.
2017-11-26 10:40:34 +01:00
Jef Driesen
cf9626efc3 Port the USB HID code to the new I/O interface 2017-11-25 10:26:49 +01:00
Jef Driesen
300ef5257b Port the bluetooth code to the new I/O interface 2017-11-25 10:26:49 +01:00
Jef Driesen
8f17055ec4 Port the IrDA code to the new I/O interface 2017-11-25 10:26:49 +01:00
Jef Driesen
7cd1656d1d Port the serial code to the new I/O interface 2017-11-25 10:26:49 +01:00
Jef Driesen
3ca27995e1 Add a new abstract I/O interface
The purpose of the new I/O interface is to provide a common interface
for all existing I/O implementations (serial, IrDA, bluetooth and USB
HID). With a common interface the dive computer backends can more easily
use different I/O implementations at runtime, without needing
significant code changes. For example bluetooth enabled devices can
easily switch between native bluetooth communication and serial port
emulation mode.

The new interface is modelled after the existing serial communication
api. Implementations where some of those functions are meaningless (e.g.
IrDA, bluetooth and USB), can just leave those functions unimplemented
(causing the call to fail with DC_STATUS_UNSUPPORTED), or implement it
as a no-op (always return DC_STATUS_SUCCESS).
2017-11-25 10:26:49 +01:00
Jef Driesen
b75095cefa Post release version bump to 0.7.0 2017-11-24 23:48:55 +01:00
Jef Driesen
1195abc2f4 Release version 0.6.0 2017-11-24 23:47:58 +01:00
Jef Driesen
350893fb27 Fix some potential buffer overflows
Verify the buffer size before accessing its content!
2017-11-24 23:46:08 +01:00
Jef Driesen
68380b2ec0 Fix some casts with constant pointers
Casting away the const qualifier generates a compiler warning which can
easily be avoided by preserving the const qualifier.
2017-11-24 23:45:11 +01:00
Jef Driesen
91f5b34ae5 Enable some useful compiler warnings by default
Because some of those compiler warnings are GCC specific, they should
only be enabled if the compiler actually supports them. This is take
care of with some macros from the autoconf-archive.

To avoid breaking the build on systems that don't have those macros
installed (e.g. Mac OS X), they are included in the project.
2017-11-24 23:45:11 +01:00
Jef Driesen
cbaebc777d Generate html documentation from the manpages 2017-11-23 10:33:31 +01:00
Jef Driesen
4ccfa51faf Fix the decoding of the ndl/deco information
With the new APOS4 firmware, both the tts and the duration of the first
deco stop are recorded while in deco. But compared with the older
firmware, the tts field has moved to a slightly different offset. And
contrary to the new documentation, it seems that the value for invalid
or infinite has also changed from 0xFFFF to 0x7FFF,

Note that for dives recorded with an older firmware version, the
duration of the first deco stop isn't available, and libdivecomputer
reports the tts instead. This is the same behaviour as before.

Reported-by: Janice McLaughlin <janice@moremobilesoftware.com>
2017-11-19 23:07:38 +01:00
Jef Driesen
93fc2f1c79 Decode the firmware version for the iDive series
For the older iDive series, the firmware is stored at a slightly
different offset.
2017-11-19 23:07:38 +01:00
Jef Driesen
4ffd514f76 Add support for the Suunto Eon Core
The Suunto Eon Core uses a different USB PID, but otherwise it's
compatible with the Eon Steel. It's probably an Eon Steel internally,
but with a smaller form factor.

To be able to distinguish between the two models and use the correct USB
PID, each model is assigned a different (artificial) model number.

Reported-by: Nick Shore <support@mac-dive.com>
2017-11-19 23:05:23 +01:00
Jef Driesen
812db650d4 Locate the most recent dive
The Suunto Eon Steel seems to have a limit of maximum 400 dives. Once
that limit is reached, the oldest dives get overwritten with newer
dives. But the order in which the dive entries are downloaded isn't
changed, and thus the most recent dive is no longer the last entry.

For the first 400 dives, the order is always straightforward:

   D001 D002  ... D399 D400

The most recent dive is always the last entry, and no special processing
is necessary. But once the limit is reached, the next few dives will
start to overwrite the oldest dives, but the order remains unchanged:

   D401 D402 ... D399 D400

Thus in order to return the dives in the correct order (newest first),
we can no longer assume the most recent dive is the last entry, and thus
we need to locate it manually.

The new algorithm is based on the assumption that the most recent dive
will have the hightest timestamp. And to be able to walk backwards
through all the entries, the list is assumed to be a circular list.
2017-11-19 23:05:23 +01:00
Linus Torvalds
f5df265300 Add EON Steel time sync capability
The EON Steel can use the new 'timesync' interface to set the time
automatically from the computer it is connected to.

This also regularizes the EON Steel command names a bit, and adds a few
new commands (you can also read the time etc, which this doesn't
actually use).

[Jef Driesen: Modified to follow the existing naming conventions, return
the correct error code and avoid arithmetic operations with signed
integers.]

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-11-19 23:05:23 +01:00
Jef Driesen
2ced18870d Improve the progress events
At the moment the progress events are reported for each download
operation separately. Combined with the fact that the size of the dives
isn't known in advance, and thus the progress events are based on a
worst case value, the user experience is far from optimal. In practice,
the progress goes from 0 to 100% for every manifest, and it stays close
to zero while downloading the dives.

This is improved by combining the individual progress events into a
single progress for the entire download. This global progress simply
counts the number of individual download operations. Since each
operation is now subdivided into a fixed number of steps, regardless of
the size of the transfer, the perceived speed is no longer constant.
2017-11-19 19:51:59 +01:00
Jef Driesen
2d7d5152b4 Detect the model number using the hardware type
The model number is stored in the final block of each dive. But for an
efficient implementation of the fingerprint feature, the devinfo event
should be emitted before downloading the manifests or the dives. Thus
reporting the correct model number is problematic.

Currently the model number is simply hardcoded to the value of the
Petrel. This is sufficient for the parser, because there the model
number is only used to distinguish the Predator from all the other
models. Now, because the petrel backend doesn't support the Predator,
and the predator backend (which supports both the Predator and Petrel)
can obtain the correct model number from the final block, the hardcoded
value works fine. Except of course for identifying the actual model!

Allthough there doesn't seems to be a command to retrieve the model
number directly, we can retrieve the hardware type and map that to the
model number.
2017-11-19 19:48:55 +01:00
Dirk Hohndel
63d6af8c41 Shearwater: add support for remaining gas time
[Jef Driesen: Update to the latest documentation.]

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-11-19 18:04:21 +01:00
Dirk Hohndel
7f22f4ac86 Shearwater: extract tank sensor data for log version 7
The first dive computer to support this is the Perdix AI. Interestingly,
this keeps track of two sensors at all times. I haven't seen data with
two sensors active, yet.

[Jef Driesen: Update to the latest documentation.]

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-11-19 18:04:21 +01:00
Dirk Hohndel
9f754dc563 Shearwater: extract log version from header
The earliest document I have references log version 6. There are
apparently older versions, but I don't know what the differences
are. Before version 7, the log version wasn't always reliably
stored, so we assume 6 is the minimum and use 7 (or later) if we
find it.

[Jef Driesen: Initialize and reset the cache correctly.]

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-11-19 18:04:21 +01:00
Jef Driesen
428704b538 Add support for the Scubapro Aladin Square
The communication protocol is identical to the G2 protocol, but with a
different USB VID/PID (c251:2006).

Note that unlike the G2, the Aladin Square seems to support only 33 byte
USB HID packets (1 byte report id and 32 bytes payload), even when the
actual command is much smaller. Without padding the commands, the dive
computer doesn't reply at all. Because the padding is already there, to
support the Windows api, no further changes are necessary.
2017-11-16 16:33:11 +01:00
Jan Mulder
20d7d03a0d OSTC: initialize initial CNS from header
As the OSTC does not report a CNS value on the first sample, we need to
initialize it differently. This can be solved by using the initial CNS
value form the dive header, and storing that value in the first sample.
The resulting patch is very similar to 44f629f03a91a3b3.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-11-14 13:51:04 +01:00
Jef Driesen
e786b0b0b6 Use an out-of-range value as undefined
The main purpose of the magic value UNDEFINED, is to indicate that a
value isn't present in the data. But since the value 0xFF can actually
be stored in the data, we can't distinguish between those two cases.
This ambiguity can be avoided by using a magic value that lies outside
the valid range for 8 and 16 bit fields.

Note that an initial gas mix value of 0xFF remains interpreted as
UNDEFINED, but this is now made explicit.
2017-11-14 13:21:21 +01:00
Berthold Stoeger
d0d4c7b994 Support for the Scubapro Aladin Sport Matrix.
The protocol is identical to the G2 protocol, with the exception of a
missing handshake.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-11-01 20:53:48 +01:00
Jef Driesen
a196255841 Replace the clock calibration with a fixed epoch
Currently the date/time parsing assumes the reference time (epoch) of
the device clock is unknown. Hence we retrieve the current time of the
device (devtime) and the host system (systime) during the download.
Since both timestamps represent the same instant in time, but with a
different reference time, we can calibrate the device clock as follows:

    ticks = parser->systime - (parser->devtime - timestamp) / 2

But this produces wrong results once the device clock has been adjusted
manually. Adjusting the device clock will suddenly increase (or
decrease) the devtime, while the systime continues ticking forwards
normally. Hence all dives recorded before the time adjustment will get
an incorrect date/time value.

Fortunately all devices appear to use a fixed epoch (2000-01-01 00:00:00
UTC) and we can simply replace the calibration with a hardcoded value.

Reported-By: Linus Torvalds <torvalds@linux-foundation.org>
2017-10-23 15:02:38 +02:00
Jef Driesen
7f2384d665 Merge branch 'usbhid' 2017-10-09 16:27:44 +02:00
Jef Driesen
f708eadcfd Make the initialization thread-safe
Perform the initialization inside a critical section.

Unfortunately Windows critical sections, which are the simplest
synchronization mechanism available on Windows, do not support static
initialization. A call to InitializeCriticalSection is required.
Therefore a simple spinlock, with an implementation based on atomic
operations, is used as a workaround.
2017-10-09 14:35:36 +02:00
Jef Driesen
7b920f5c42 Initialize the usb library only once
Initializing the hidapi library more than once is tricky. The hid_init()
function can be called multiple times, but the the hid_exit() function
will free the resources unconditionally, regardless of how many times
the hid_init() function has been called. The consequence is a premature
termination of the library.

To avoid this problem, the calls are reference counted. Note that this
workaround can't protect against calls made outside the libdivecomputer
code!

The libusb library doesn't suffer from this problem, because each
initialization returns a new context pointer. But for consistency, we
now also use a single reference counted libusb context.
2017-10-09 14:35:36 +02:00
Jef Driesen
efe2edd83c Merge branch 'g2' 2017-09-28 22:22:16 +02:00
Jef Driesen
bcb64b3297 Workaround for a Windows libusb issue
When libusb uses the Windows HID api internally, it does automatically
prepend a zero report ID to the data for devices which support only a
single report. But apparently it also returns a size of one byte extra!
As a workaround, the number of bytes is limited to the actual size.

See commit c9ed92d3f55c259931527a27d018eb5791a176dd for a similar issue
in the hidapi library.
2017-09-28 22:19:11 +02:00
Jef Driesen
ddb7276bf0 Use a fixed size packet for sending
The Windows HID api always expects to receive a fixed size buffer
(corresponding to the largest report supported by the device). But
unlike the hidapi library, the libusb library doesn't automatically pad
the buffer to the expected size when trying to send less bytes. Thus
when trying to submit the transfer, the underlying Windows api call
immediately fails with ERROR_INVALID_PARAMETER.

To workaround this problem, pad the data packet with zeros manually and
always send the entire packet (1 byte report ID and 32 bytes payload).
2017-09-28 22:06:21 +02:00
Jef Driesen
a28d2feb4f Replace the size macro with the sizeof operator 2017-09-28 22:06:14 +02:00
Jef Driesen
94f739ab52 Merge branch 'platform' 2017-09-28 22:04:47 +02:00
Jef Driesen
5a00224c93 Use the correct printf format for the size_t type 2017-09-28 22:02:53 +02:00
Jef Driesen
52e03944c0 Move platform specific macros to a common header file 2017-09-28 22:02:53 +02:00
Jef Driesen
b683eca5c8 Use the correct data type for the return value 2017-09-28 22:01:58 +02:00
Jef Driesen
87adab39d7 Rename the DiveSystem vendor to Ratio
At the time support for the Orca and iDive series was implemented, they
were being sold under the "DiveSystem" brand. But nowadays, the newer
iDive and iX3M series are being sold under the "Ratio" brand. Since this
frequently confuses end-users, let's rename the libdivecomputer vendor
name as well.

The Orca and the original iDive series remain under the DiveSystem
brand.
2017-09-28 22:00:09 +02:00
Jef Driesen
fa53d1351b Fix the Sherwood Insight temperature 2017-09-12 22:34:55 +02:00
Jef Driesen
50c4f18cf6 Implement the ndl/deco sample 2017-09-12 22:34:55 +02:00
Jef Driesen
38366ef8ed Merge branch 'cochran' 2017-09-12 19:59:56 +02:00
John Van Ostrand
0220782aa8 Change communication parameter to work better with FTDI
The parameters used with the FTDI USB serial port drivers didn't work
well with directly with libftdi1. The new baud rate results in the same
effective baud rates for both.

The rbstream block size was reduced to help with the unreliability of
the libftdi communications.
2017-09-12 11:08:54 +02:00
John Van Ostrand
ca4c261f6e Retry read operations on failure
Using FTDI for custom I/O resulted in very unrealible reads. This patch
allows more reliable use of FTDI custom I/O, like what might be needed
when used on a mobile device like Android.

[Jef Driesen: Modified to retry only for non-fatal errors. This simply
restores the code from commit b3d2c603ddec9758fb36706bbde46ce23ca9f0ed,
which was removed in commit 55e8f83eb5d934e65fbf587d427de267f174c651.]
2017-09-12 11:06:38 +02:00
Jef Driesen
c839134130 Add support for the Suunto D4f 2017-09-11 08:25:51 +02:00
Jef Driesen
be8b95fdf9 Implement the tank pressure
With the new APOS4 firmware, the latest ix3m and idive models support a
wireless tank sensor. For dives without a tank pressure sensor, the
pressure field in the sample is zero. Thus the first non-zero value
indicates the presence of a tank sensor.
2017-09-07 10:26:07 +02:00
Jef Driesen
45af27734e Merge branch 'uwatec' 2017-09-05 19:04:43 +02:00
Jef Driesen
cb2a4f4a72 Use more descriptive names
Those two samples are no longer unknown. The first one contains some
freedive related data, and the second one contains some additional data
with several sub types. At the moment only the tank and gas mix info is
used.
2017-09-02 10:34:23 +02:00
Jef Driesen
ce590b5bc9 Use two passes to parse the profile data
In the trimix data format, the tank and gas mix information is no longer
stored in the header, but in a special sample. Because this sample is
usually located at the end of the profile, the info isn't available yet
during the first pass. Hence the need for a second pass.

Without this change, the tank and gas mix samples will be missing unless
the caller calls the dc_parser_get_field() function before calling the
dc_parser_samples_foreach() function.
2017-09-02 10:12:44 +02:00
Jef Driesen
6b88bc1b8b Fix the Uwatec trimix data format
The trimix dive header is only 84 bytes large, instead of 0xB1 bytes.
The difference is quite hard to notice, because compared to the normal
Galileo data format, the majority of the fields are located at exactly
the same offset. But there are also some subtle differences, like the
settings field containing the freedive and gauge bits.

To fix this bug, a new header table is added. The rest of the code is
updated to use this new table instead of the old trimix flag. The only
place where the old flag is still used is for the decoding of the tank
and pressure sample.
2017-09-01 15:00:10 +02:00
Jef Driesen
26f5925c05 Implement the ndl/deco, rbt and bookmark samples 2017-08-25 21:25:21 +02:00
Jef Driesen
d954a500f6 Implement the setpoint sample for the iDive and iX3M 2017-08-22 08:40:55 +02:00
Jef Driesen
abab44a74c Implement the ndl/deco sample for the Aqualung i300 2017-08-20 21:29:18 +02:00
Jef Driesen
4aac63ea00 Update the msvc project file 2017-08-19 22:32:48 +02:00
Jef Driesen
156f54302d Add basic timezone support
Allthough most dive computers always use local time and don't support
timezones at all, there are a few exceptions. There are two different
sources of timezone information:

 - Some of the newer Uwatec/Scubapro devices use UTC internally and also
   support a timezone setting. This UTC offset is currently taken into
   account to obtain the dive date/time, but the UTC offset itself is
   lost.

 - Uwatec/Scubapro and Reefnet devices rely on the clock of the host
   system to synchronize the internal device clock and calculate the
   dive date/time. The consequence is that the resulting date/time is
   always in the timezone of the host system.

In order to preserve this timezone information, the dc_datetime_t
structure is extended with a new "timezone" field, containing the UTC
offset in seconds. Devices without timezone support will set the field
to the special value DC_TIMEZONE_NONE.

The dc_datetime_localtime() and dc_datetime_gmtime() functions will
automatically populate the new field with respectively the local
timezone offset and zero. The dc_datetime_mktime() function will take
into account the new timezone field for the conversion to UTC. The
special value DC_TIMEZONE_NONE is interpreted as zero.
2017-08-18 23:26:45 +02:00
Jef Driesen
838f730fb2 Merge branch 'timesync' 2017-08-18 23:23:36 +02:00
Jef Driesen
215d1155f8 Add time synchronization to the example application 2017-08-18 23:17:33 +02:00
Jef Driesen
22e0ab3d2b Implement the new api for the HW devices
The Heinrichs-Weikamp devices already supported clock synchronization by
means of a device specific function. This is now replaced with the new
api.
2017-08-18 23:17:33 +02:00
Jef Driesen
acb4a187fb Add support for synchronizing the device clock
Being able to synchronize the dive computer clock with the host system
is a very useful feature. Add the infrastructure to support this feature
through the public api.
2017-08-18 23:17:33 +02:00
Jef Driesen
db0e1691cc Merge branch 'hidapi' 2017-08-18 23:16:26 +02:00
Jef Driesen
eea02126a4 Use hidapi as the default USB HID library
On Windows, the hidapi library uses the standard Microsoft USB HID
driver, while libusb requires the installation of a different driver
(WinUSB or libusbK). But installing one of the libusb drivers breaks
compatibility with other applications using hidapi (Scubapro LogTRAK and
Suunto DM5) because only one driver can be active. Switching
libdivecomputer to hidapi avoids this problem.

On Linux, the hidapi library doesn't seem to offer any advantages over
libusb. Most distributions don't even have the hidapi library installed
by default. Because there are usually two variants of the hidapi library
available on Linux (hidapi-libusb and hidapi-hidraw), the autotools
build system won't be able to detect it out-of-the-box, and will
automatically fallback to the libusb implementation.

On Mac OS X, hidapi is already the default (and also the only option).
2017-08-18 23:15:55 +02:00
Jef Driesen
c9ed92d3f5 Workaround for a Windows hidapi issue
The Windows HID api always expects to receive a fixed size buffer
(corresponding to the largest report supported by the device). Therefore
the hidapi library internally pads the buffer with zeros to the expected
size, but apparently it also returns the size of the padded buffer! As a
workaround the number of bytes is limited to the actual size.
2017-08-18 23:15:55 +02:00
Jef Driesen
b82d5fcfff Reset the number of bytes to zero on error
The hidapi read and write functions return a negative value if an error
occurs. Those negative values should not be returned to the caller as
the actual number of bytes (or used in the logging). The value is reset
to zero instead.
2017-08-18 23:15:55 +02:00
Jef Driesen
d251b373be Add a zero report ID to the commands
The zero report ID byte is required when using the hidapi library. We
just never noticed this problem before, because we use libusb by
default, and libusb doesn't need the extra zero byte.
2017-08-18 23:15:55 +02:00
Jef Driesen
05c858bf96 Fix compatibility issue with hidapi
The hidapi library requires that the first byte contains the report ID.
For devices which support only a single report, the report ID byte
should be zero. The remaining bytes contain the actual report data.

Now, when hidapi uses libusb internally, it strips the zero report ID
byte again before passing the data to libusb. Thus in order to remain
compatible with the hidapi based implementation, our libusb based
implementation should do the same.
2017-08-18 23:15:55 +02:00
Jef Driesen
854ad13f16 Implement the salinity field 2017-08-17 08:49:38 +02:00
Jef Driesen
722160cd48 Fix the atmospheric pressure for the iX3M
The iX3M appears to store the atmosperic pressure in units of 1/10
millibar instead of 1 millibar.
2017-08-17 08:49:32 +02:00
Jef Driesen
133b7394c2 Rename the OSTC 3+ to OSTC Plus
The correct name for the OSTC 3+ is OSTC Plus nowadays. Allthough the
exact name doesn't really matter because all OSTC3 based models are
compatible, using the correct name should reduce confusing for
end-users.
2017-08-17 08:46:35 +02:00
Jef Driesen
2813d61f65 Locate the most recent dive using the logbook pointers
I received a bug report from a device which failed to download new dives
after a reset (probably caused by an empty battery). This reset appears
to reset the internal dive counter back to zero, and also resets the
write pointer back to the begin of the logbook ringbuffer, but leaves
the existing logbook entries in place. The result is that the logic to
find the most recent dive based on the highest internal dive counter,
will be wrong because it finds those old entries.

The discovery of the logbook (and profile) write pointers eliminates the
need to search for the most recent logbook entry.
2017-08-15 23:29:30 +02:00
Jef Driesen
f7bcbb5828 Add support for the Aqualung i200 2017-08-15 11:47:05 +02:00
Jef Driesen
813400ec54 Merge branch 'cochran' 2017-08-15 11:39:32 +02:00
John Van Ostrand
cdf7e8e635 Add event handling to TM model
For some reason I had never added event processing to this model.
2017-08-15 11:30:13 +02:00
John Van Ostrand
3f1131f80f Fix profile buffer size and address size
I dived the model enough to wrap the profile buffer and I was wrong
about where the end was. Also, the buffer starts 3 bytes after where it
could. We were treating profile pointers as 4 bytes when they are two
bytes. This worked most of the time when short tissues were clear
(tissue load follows the pointer).
2017-08-15 11:30:09 +02:00
John Van Ostrand
adef3f67fc Add three event codes
I found three previously undiscovered event codes.
2017-08-15 11:30:04 +02:00
John Van Ostrand
fb65726a55 Add support for the Commander TM
The Cochran Commander TM appears to be a first generation Commander with
limited storage and function compared to later models.

The main differences are:

 - The TM doesn't support high-speed transfer so use the 0x05 read
   command and don't change to a higher baud rate. Still reset to 9600
   to wait for the heartbeat.
 - The TM has a different config command (one byte).
 - The TM has only one config page.
2017-08-15 11:29:58 +02:00
John Van Ostrand
1d8f25ba9b Dump function no longer assumes reads begin at byte 0
For previously supported Cochran computers high-speed read of log and
profile data started at byte 0. Older models that lack the high-speed
transfer function use the standard speed read commands and so the log
and profile data are read at higher addresses.
2017-08-15 11:29:40 +02:00
John Van Ostrand
8b41e72cf7 Remove unneeded function
Since moving to per-dive download of profile data (and now rbstream
download) the data->sample_data_offset and data->sample_size variables
aren't used so calculating them doesn't make sense.
2017-08-15 11:29:05 +02:00
Jef Driesen
88b6e36e04 Use only a single read operation
The profile and throw-away data can be read all at once. This avoids the
need for an extra memory allocation and fixes a memory leak.
2017-08-15 11:28:57 +02:00
John Van Ostrand
cd5eb61e90 Make rbstream pagesize smaller and device specific
The progress bar was taking 18 seconds between updates on a Commander II
when using a 128K pagesize. Since devices differ in their baud rates, it
makes sense to use smaller pages on slower devices. This change reduces
it to 32K on a Commander II and to 64K on EMC devices.
2017-08-15 11:28:19 +02:00
John Van Ostrand
55e8f83eb5 Use rbstream for reading profile data
Per-dive reading of the DC takes too long because of latency on read
commands. The rbstream solves this by reading ahead in large blocks.
2017-08-15 11:28:09 +02:00
Jef Driesen
4e0c2e4650 Remove non-existing function from header
The dc_device_version() function has been removed from the public api
long time ago.
2017-08-11 08:22:53 +02:00
Jef Driesen
535d612a93 Use the correct type in the leonardo vtable 2017-08-02 09:19:03 +02:00
Jef Driesen
b8b94c46fc Merge branch 'cochran' 2017-07-05 13:12:27 +02:00
John Van Ostrand
fd1557f634 Removed unused code 2017-07-05 13:11:33 +02:00
John Van Ostrand
2c5e787b77 Fixed duplicate gasmix event reports
Newer cochran DCs record a gas change event at the begining of a
dive. The code creates a gas change before processing samples so
with newer DCs this resulted in duplicate events.
2017-07-05 13:11:33 +02:00
John Van Ostrand
094b635f87 Added decompression event handling for the Commander
I finally found an example of decompression on a Commander II computer
and it seems to be identical to the EMC.
2017-07-05 13:11:33 +02:00
John Van Ostrand
e1b679912a Fix bad profiles when profile ringbuffer wraps around
The method used to calculate the data used by dives (to determine when
we run out of ringbuffer) incorrectly didn't include surface sample
data. Ten to twenty minute of sample data is recorded at the surface in
case the diver re-descends, continuing the dive. The code then thought
that older dive profiles were not yet overwritten. The improper data was
returned to the user.
2017-07-05 13:11:33 +02:00
John Van Ostrand
9c795e6e4e Changed cochran_comander_profile_size function parameters
This function is much more useful if it works like a
ringbuffer_distance() function. It assumed the wrong values when
calculating profile size and it didn't have easy access to values it
needed to properly calculate profile sizes.

It makes sense to keep since it validates pointers.
2017-07-05 13:11:33 +02:00
John Van Ostrand
48d93e9404 Fixed location and encoding of Commander II pointers
Commander II pointers to profile ringbuffer data was wrong. After seeing
the Commander I encoding I realized the Commander II encoding of RB
pointers was in a flipped word big endian format. It only appeared to be
in normal big endian format because of an adjacent pointer that usually
shared the same first two bytes.
2017-07-05 13:11:33 +02:00
John Van Ostrand
3545bf158a Use a local variable for the layout pointer 2017-07-05 13:11:33 +02:00
John Van Ostrand
3a2f2ff0c3 Add new EMC device model string 2017-07-05 13:11:33 +02:00
John Van Ostrand
216e393f43 Add support for Pre-21000 s/n Commander dive computers
This adds support for older Cochran Commander dive computers,
specifically Commanders with serial numbers prior to 21000.

This also renames "Commander" model to "Commander II" and
adds "Commander I" to refer to pre-21000 models.
2017-07-05 13:11:33 +02:00
John Van Ostrand
45f0605678 Fix problems with wrapped logbook ringbuffer 2017-07-05 13:11:33 +02:00
John Van Ostrand
b3d2c603dd Retry read operations on failure
[Jef Driesen: Modified to retry only for non-fatal errors.]
2017-07-05 13:07:36 +02:00
John Van Ostrand
346391ae2c Change profile download to be incremental
It will result in a 30 minute download for full computers but it
significantly reduces the time to download partial dives.
2017-07-05 09:15:05 +02:00
Jef Driesen
c26755624d Fix the id string offset
Since commit 344bfab229a17c7227b9bec02f616505a8d9e998 only a subset of
the id string is used to detect the model. But because the offset was
never updated, the model detection always fails now.
2017-07-05 09:15:05 +02:00
Jef Driesen
7ce057d2ba Fix the progress events
I accidentally passed the address of the progress pointer to the
device_event_emit() function, instead of the pointer itself. Oops.
2017-07-04 14:58:52 +02:00
Jef Driesen
cdcfef6c1a Merge branch 'g2' 2017-06-28 15:33:57 +02:00
Jef Driesen
3a05e0ecf0 Use the trimix data format 2017-06-28 15:32:39 +02:00
Jef Driesen
0a5623a949 Use the correct model number
The model number reported by the Scubapro G2 is 0x32.
2017-06-28 15:32:39 +02:00
Jef Driesen
7ee210f83f Enable more fine grained progress events
At the moment, the progress reporting will jump straight from about 0%
at the start of the download to 100% at the end of the download, without
any updates in between. This is improved by updating after every packet.
2017-06-28 15:32:39 +02:00
Jef Driesen
06259fed19 Abort with an error if the buffer is too small
Silently truncating the data packet if the buffer is too small will
result in a corrupt data stream.
2017-06-28 15:32:39 +02:00
Jef Driesen
eae071c97d Use the standard libdivecomputer error codes
The error code returned by the dc_usbhid_read() function should be
returned as-is, instead of being replaced with some generic error, which
gets translated again to DC_STATUS_IO in the caller.
2017-06-28 15:32:39 +02:00
Linus Torvalds
fcfee82cc8 Scubapro G2: add missed command packet logging
I did the packet logging for the received data side, but forgot to do
the same thing on the command transfer side, which makes the debug logs
a bit less useful.

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-06-28 15:32:39 +02:00
Jef Driesen
434e765128 Merge branch 'ix3m' 2017-06-16 09:00:26 +02:00
Jef Driesen
24621ed519 Improve the handling of unreadable dives
Dives that are reported by the dive computer as unreadable (for example
due to a power loss during the dive) are now skipped instead of being
reported as a fatal error. Those dives can't be retrieved, so there is
no good reason to abort the download.
2017-06-16 08:57:02 +02:00
Jef Driesen
3b967f9eb1 Improve the handling of devices without any dives
Don't return an error if the dive computer reports there are no dives
available!
2017-06-16 08:57:00 +02:00
Jef Driesen
5178c0f755 Add extra NAK error codes 2017-06-16 08:56:02 +02:00
Jef Driesen
35d1e6ff14 Propagate the error code to the caller 2017-06-16 08:09:32 +02:00
Jef Driesen
31c68ba338 Automatically re-transmit corrupt data packets
Originally packets are only retried when a valid NAK packet with the
busy error code is received. The retrying is now enabled for other types
of errors also, such as data packets with checksum errors.
2017-06-14 16:36:40 +02:00
Jef Driesen
37392a03f2 Add a separate transport type for USB HID 2017-06-02 12:11:39 +02:00
Jef Driesen
58eebf4ece Add a bluetooth transport type 2017-06-02 12:11:39 +02:00
Jef Driesen
3c7bd525bb Add support for native bluetooth communication
For the time being, the bluetooth communication code is of very limited
use. It's not used anywhere in the library, and as an internal api it's
also not available to applications. It serves mainly as a reference
implementation for future use.

The implementation supports Windows and Linux.
2017-06-02 12:11:39 +02:00
Jef Driesen
404cea7417 Move the dummy IrDA implementation
The dummy IrDA implementation is integrated in the main file. The
appropriate implementation is selected using conditional compilation
based on the features detect by the autotools build system.
2017-06-02 12:11:39 +02:00
Kristaps Dzonsons
0b22a2ba33 Fix the Oceanic OCS freedive mode 2017-06-02 11:24:00 +02:00
Jef Driesen
4545730776 Report the average ppO2 in external O2 sensor mode only
Just like the ppO2 values from the O2 sensors, the average ppO2 should
be reported in external O2 sensor mode only.
2017-05-27 22:33:22 +02:00
John Van Ostrand
344bfab229 Altered model detection after seeing some bytes change after a firmware update. 2017-05-27 21:37:15 +02:00
Jef Driesen
e2d623fc65 Merge branch 'ix3m' 2017-05-24 07:18:19 +02:00
Jef Driesen
28947876a2 Add support for the new models 2017-05-24 07:18:02 +02:00
Jef Driesen
55b9307e19 Add support for the new iX3M APOS4 firmware
The new APOS4 firmware changed the data format and communication
protocol. The size of the samples changed from 54 to 64 bytes, and in
order to speedup the download, a single data packet contains 3 samples
at once. If the number of samples is not an exact multiple of three, the
last packet appears to contain garbage data.

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

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

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

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

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

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2017-05-11 07:58:03 +02:00
Dirk Hohndel
588e7e7ab4 Predator: don't report PPO2 unless in CC mode
Sending this in OC mode is redundant and might confuse applications that
assume they only get PPO2 data in CC mode.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-10 11:30:53 +02:00
Jef Driesen
415d7f2214 Fix the Sherwood Wisdom 3 memory layout
The logbook ringbuffer starts at 0x03D0 instead of 0x0240.
2017-05-10 11:16:57 +02:00
Jef Driesen
21c7c9c009 Implement the read and write functions for the OSTC3
The existing infrastructure for upgrading the firmware can also be used
to support reading and writing directly to the internal flash memory.
2017-05-04 08:49:24 +02:00
Jef Driesen
3daba977e0 Don't ignore handshaking errors 2017-05-04 08:34:04 +02:00
Jef Driesen
6e9278ff24 Add support for the Mares Quad 2017-04-30 09:49:15 +02:00
Jan Mulder
44f629f03a OSTC3: set initial setpoint in profile data
In CCR fixed setpoint mode of the OSTC3, the initial setpoint at the start
of the dive was not set. This fix adds the initial setpoint based on
the data in the fixed setpoint table (ie, the first fixed setpoint is
the initial one).

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-04-29 10:17:14 +02:00
Jef Driesen
39a7920083 Merge branch 'cleanup' 2017-04-24 13:06:49 +02:00
Jef Driesen
bdf69ce1ec Remove unused parameters 2017-04-24 13:05:20 +02:00
Jef Driesen
468418193b Cleanup the extract dives functions
After being removed from the public api, these functions can be changed
into local, static functions. And in a few cases, they are no longer
necessary and can be removed completely.
2017-04-22 09:11:41 +02:00
Jef Driesen
c5f089b4a6 Remove unnecessary helper functions
The second variant of the open or create functions were introduced to
maintain backwards compatibility. But after being removed from the
public api, these functions serve no purpose anymore, and can be removed
completely.
2017-04-19 11:33:17 +02:00
Jef Driesen
d1a06e784c Remove deprecated functions from the public api
The vendor_product_parser_create() and vendor_product_device_open()
functions should be called indirectly, through the generic
dc_device_open() and dc_parser_new() functions. And the
vendor_product_extract_dives() functions are internal functions that
should never have been part of the public api in the first place.
2017-04-18 08:41:10 +02:00
Jef Driesen
8952ad0c29 Remove unnecessary include statements 2017-04-13 08:02:11 +02:00
Jef Driesen
97a6023bb6 Fix the firmware version and serial number
When downloading a Shearwater Petrel using the predator backend, the
firmware version and serial number are different compared to those
reported by the petrel backend.

This is caused by a difference in the encoding of the data. In the
predator data format, the firmware version appears to be BCD encoded,
and the serial number is stored as a big endian integer.
2017-04-12 08:44:10 +02:00
Jef Driesen
9fb7a1f228 Add support for the Uwatec Aladin Tec 3G 2017-04-12 08:35:31 +02:00
Jef Driesen
d021bb98ef Disable the deco events
These deco events have already been converted to a deco sample.
2017-04-08 08:56:15 +02:00
Jef Driesen
bfd7301945 Replace the deco events with a deco sample 2017-04-08 08:56:15 +02:00
Jef Driesen
e2c020d4c7 Report errors from the close function 2017-04-08 08:46:07 +02:00
Jef Driesen
0609a4c80a Mark the private function as static 2017-03-30 15:09:40 +02:00
Jef Driesen
c5d5220e28 Fix a bug in the tank pressure samples
The number of tank pressure sensors is not necessary equal to the number
of gas mixes. Take for example a dive with two gas mixes, but only a
single tank pressure sensor attached to one of the two tanks. Because
the tank index is shared with the gas mix index, it will refer to a
non-existing sensor when switching to a tank without a pressure sensor
attached.

The invalid tank index should not be considered a fatal error. The tank
pressure values should be ignored instead. The device appears to record
zero values anyway, except for the first value immediately after the gas
switch. I suspect that's caused by the fact that the pressure is only
recorded every 4 samples, and therefore the last pressure value is
reported with a small delay.
2017-03-28 13:12:19 +02:00
Jef Driesen
640308c076 Disable freedive mode for the Uwatec Aladin Tec 2G
The Uwatec Aladin Tec 2G doesn't support freedive mode. This appears to
be a bug in SmartTrak and LogTrak. They both report gauge and air/nitrox
dives as apnea dives.
2017-03-27 21:36:11 +02:00
Jef Driesen
b1ba3fa0c6 Mark the private function as static 2017-03-27 16:23:23 +02:00
Jef Driesen
c5fac27bc8 Fix some compiler warnings 2017-03-08 08:54:42 +01:00
Jef Driesen
57ffb2ba7a Fix some more null pointer dereferences 2017-03-08 08:47:04 +01:00
Jef Driesen
8735071fac Use a more efficient download algorithm
The current algorithm always downloads a full memory dump, and extracts
the dives afterwards. For the typical scenario where only a few dives
are being downloaded, this is inefficient because most of the data isn't
needed. This can easily be avoided by downloading the data on the fly.
2017-02-27 08:20:49 +01:00
Jef Driesen
2646e4df86 Use the new ringbuffer stream
All dive computer backends are updated to use the new ringbuffer stream.
2017-02-16 21:04:59 +01:00
Jef Driesen
3f82a553bd Add a common ringbuffer reading algorithm
Reading a ringbuffer backwards in order to process the most recent data
first, is a very common operation. Nearly every dive computer backend
has its own implementation. Thus with a common implementation, the
amount of code duplication and complexity in the dive computer backends
can be greatly reduced.

The common algorithm is implemented as a simple ringbuffer stream, which
takes care of all the technical details like the ringbuffer boundaries,
alignment to the page size, using the optimal packet size and caching
the remaining data.
2017-02-16 20:34:09 +01:00
Jef Driesen
f83d156fdb Improve the robustness of the IrDA I/O code
The select system call modifies the file descriptor set, and depending
on the underlying implementation also the timeout. Therefore these
parameters should be re-initialized before every call.

The existing code also didn't handle EINTR and EAGAIN correct.
2017-02-16 13:11:14 +01:00
Jef Driesen
24cbff9a9f Fix a few null pointer dereferences 2017-02-16 12:00:41 +01:00
Jef Driesen
e96611cccd Fix the number of gas mixes
The Tusa Zen supports a maximum of only 2 gas mixes.
2017-02-10 19:42:02 +01:00
Jef Driesen
3f9133def9 Always use the sample timestamp as the base value
With a time based sample interval, the number of samples for a single
timestamp should be constant. However in practice some devices
occasionally store fewer samples. Since our sample time is based purely
on the sample interval, it goes completely out of sync with the sample
timestamp. To avoid this problem, the sample timestamp is used as the
base value.

For the Oceanic Pro Plus 2, this problem is very noticable. After about
115 minutes into a dive, the sample interval appears to increase to 60
seconds. Thus, without this fix, the resulting dive time for long dives
is suddenly much shorter than it should be.
2017-02-08 07:43:44 +01:00
Jef Driesen
0832f97492 Fix the name of the Aqualung i550
The Aqualung i550 doesn't have a "T" (which probably stands for
transmitter) in its name.
2017-02-01 08:32:01 +01:00
Jef Driesen
9cb6856bfb Fix the ndl/deco and rbt samples
The Air Time Remaining (ATR) and Dive Time Remaining (DTR) fields have
been swapped.
2017-01-30 20:54:59 +01:00
Jef Driesen
ae954af768 Parse the sample interval correctly
The Cressi Drake supports a sample interval of 1, 2, 3 and 4 seconds.
2017-01-23 08:40:00 +01:00
Jef Driesen
7b589cab9d Merge branch 'i450t' 2017-01-19 22:12:17 +01:00
Jef Driesen
e5805f3f7d Fix the Aqualung i450T time samples
The Aqualung i450T appears to ignore the fixed sample rate and instead
store a timestamp in each sample.

The presence of the surface samples in combination with this timestamp
based format is odd. Even the official Diverlog software is confused:
the Windows versions seems to ignore them, but the Mac version takes
them into account.
2017-01-19 22:11:48 +01:00
Jef Driesen
8a4c1f1ef7 Split the raw data into multiple vendor samples
After the previous commit, the raw data is now reported with one large
vendor sample. Because that makes the data more difficult to interpret
(for example during debugging), a small helper function is added to
split the data again in multiple vendor samples.
2017-01-19 22:11:48 +01:00
Jef Driesen
7c0f8f9b9d Output samples only once all raw data is available
Originally, the time and vendor sample values are emitted immediately
after the previous sample is complete. This is now postponed until all
raw samples are available.

This will be required for the Aqualung i450t. That model appears to
ignore the fixed sample rate and instead store a timestamp in each
sample. That means the timestamp is only available once the last raw
sample data has been reached.
2017-01-19 22:06:52 +01:00
Jef Driesen
0429ea146e Fix the length check 2017-01-19 22:06:31 +01:00
Jef Driesen
ef47084e05 Skip the extra samples one by one
Skipping the extra samples by increasing the length is not always
reliable. If there are empty samples present, they will get skipped
instead of the real samples. And if the number of samples isn't an exact
multiple of the samplerate, we're accessing data beyond the end of the
dive profile.
2017-01-19 22:06:31 +01:00
Jef Driesen
ef1e64ac03 Fix the memory layout for the Hollis DG03
The profile ringbuffer ends at 0xFE00 instead of 0x10000.
2017-01-19 22:05:20 +01:00
Jef Driesen
3c17132a55 Implement ndl/deco for the Hollis DG03 2017-01-19 22:05:20 +01:00
Kristaps Dzonsons
6c356604ec Document the date/time functions 2017-01-12 19:03:28 +01:00
Kristaps Dzonsons
77b0cebb35 Document the public api with man pages 2017-01-07 13:41:07 +01:00
Jef Driesen
07dcc8998b Add support for the Cressi Drake
The Cressi Drake is a mainly a freedive computer. The data format is
almost identical to the Leonardo. The main difference is that a single
dive now contains an entire freedive session. Each freedive in the
session is delimited with a 4 byte header containing the surface
interval and a special marker.
2016-12-30 22:25:14 +01:00
Jef Driesen
3dbfe9d66d Detect overwritten dive profiles
The logbook entries are stored separately from the profile data. If the
profile ringbuffer is filled faster than the logbook ringbuffer, then
the oldest logbook entries can still point to profile data that has
already been overwritten with newer data.

To detect such overwritten profile data, we keep track of the remaining
space in the profile ringbuffer.
2016-12-30 10:01:39 +01:00
Jef Driesen
8c71aebe45 Merge branch 'iconhd' 2016-12-23 20:38:49 +01:00
Jef Driesen
7c7c62dab2 Ignore tank pressure if no sensor is attached
If no tank pressure sensor is attached, the extra 8 bytes with the tank
info are still present, but the recorded tank pressure value is always
zero.
2016-12-23 20:00:05 +01:00
Jef Driesen
f74e354d68 Add support for the tank field 2016-12-23 19:50:13 +01:00
Jef Driesen
9d95870f78 Add support for the salinity field 2016-12-21 10:20:11 +01:00
Jef Driesen
8c95180578 Use the sample interval from the settings
The sample interval is stored in the settings, and thus there is no need
to use a hardcoded value. In practice all dives appear to be using the
default value (5 seconds), so this is more about being future proof.
2016-12-21 10:08:04 +01:00
Jef Driesen
296b13947f Update the Aqualung i750TC parser
The Aqualung i750TC data format appears identical to the Oceanic VTX
format. Therefore the i750TC parser is updated to match with the VTX
parser.
2016-12-06 08:47:11 +01:00
Jef Driesen
7778533bdf Toggle the DTR line during setup
On linux, several users are reporting download problems, while on
windows everything works fine. Simply toggling the DTR line appears to
fix the problem.

A possible explanation is that on windows, the SetCommState() function
not only configures the serial protocol parameters, but also initializes
the DTR and RTS lines. In the libdivecomputer implementation the default
state is enabled (DTR_CONTROL_ENABLE and RTS_CONTROL_ENABLE). The result
is that the DTR line gets automatically initialized to enabled, and then
manually disabled again.

On linux, the DTR and RTS lines are not automatically initialized during
configuration, and need to be controlled explicitely. The result is that
the DTR line ends up disabled without being toggled.
2016-11-29 10:14:28 +01:00
Jef Driesen
c3dc368163 Implement the read function
The read command appears to be limited to the range 0x1000-0x1100. That
range seems to correspond with the first 256 bytes of the full memory
dump. The packet size of 32 bytes is an arbitrary choice.
2016-11-29 08:54:30 +01:00
Ryan McLean
39aa859d19 Add doxygen documentation to the build system 2016-11-22 20:25:50 +01:00
Jef Driesen
61f3031364 Add support for the Aqualung i750TC 2016-11-12 16:05:50 +01:00
Jef Driesen
4d5bc22242 Fix the Windows version resource build
When building the Windows version resource, the -DHAVE_CONFIG_H option
isn't passed to resource compiler automatically. The result is that
development builds don't have their git revision embedded in the DLL.
2016-11-07 10:15:52 +01:00
Jef Driesen
18995e83a8 Force the dive mode to gauge
The Citizen Hyper Aqualand supports gauge mode only.
2016-11-04 19:53:30 +01:00
Jef Driesen
385c1850cb Add support for the dive mode
The dive mode is stored in each sample, and can change during the dive.
In order to report a single value for the entire dive, we assume the
value of the first sample is representive for the entire dive. For
example a dive started as a CC dive but with a bailout to OC during the
dive, is still considered to be a CC dive.

A warning is generated if the dive mode changes.
2016-11-04 19:53:30 +01:00
Jef Driesen
390b5fe553 Report the initial gas mix on the first sample
For dives with multiple gas mixes, an application doesn't have enough
info to figure out which one is the initial gas mix. Usually it's the
first gas mix, but that's not guaranteed. Reporting the intial gas mix
on the first sample avoids this problem.
2016-11-04 19:26:21 +01:00
Jef Driesen
d0dbd1f6fd Remove the deprecated gas change events
The new gas mix sample has been around for a while now, and we're not
going to maintain the deprecated events forever.
2016-11-04 19:24:54 +01:00
Jef Driesen
590882cd1d Add support for the Hollis DG02. 2016-10-04 08:21:11 +02:00
Jef Driesen
8ad3e6322e Add support for the Oceanic F10.
This appears to be an Oceanic branded version of the Aeris F10.
2016-10-01 10:49:02 +02:00
Jef Driesen
8aa8bbebd5 Post release version bump to 0.6.0. 2016-09-30 21:20:06 +02:00
Jef Driesen
ba0e7224b0 Release version 0.5.0. 2016-09-30 21:17:08 +02:00
Jef Driesen
1d94d3504f Merge branch 'msvc' 2016-09-29 22:41:12 +02:00
Jef Driesen
81c1944604 Include the public header in the implementation file.
In the public header files, all symbols are marked extern C. When using
a C compiler, there is usually no problem if the header isn't included
in the C file. But the msvc build system uses the C++ compiler (due to
the use of some C99 features not supported by the msvc C compiler).
2016-09-28 15:17:54 +02:00
Jef Driesen
e7ceb96627 Add explicit casts for the msvc C++ compiler. 2016-09-28 15:17:54 +02:00
Jef Driesen
53c75860a7 Add some workarounds for the msvc compiler. 2016-09-28 15:17:54 +02:00
Jef Driesen
995cfd4bbd Update the msvc project file. 2016-09-28 14:50:56 +02:00
Jef Driesen
7714a57c44 Add missing header files to the Makefiles.
To be able to generate a distribution tarball, all files need to be
listed explicitely.
2016-09-28 14:49:52 +02:00
Janice
3cb29abfaa Add support for the Subgear XP-Air 2016-09-24 10:07:15 +02:00
Jef Driesen
03c252335b Fix the firmware version for the HW Frog.
The firmware version in the dive header is stored at byte offset 32
instead of 34.
2016-09-19 15:15:52 +02:00
Jef Driesen
c3039b4aab Merge branch 'usbhid' 2016-09-19 15:15:36 +02:00
Jef Driesen
417ee6e619 Use the new USB HID backend for the Eon Steel. 2016-09-19 15:04:48 +02:00
Jef Driesen
6c6b144fe0 Add a dummy backend for systems without USB HID support.
This dummy implemantion is used when building without libusb and hidapi.
2016-09-19 15:04:48 +02:00
Jef Driesen
ed2a7c91fe Use the hidapi library on Mac OS X.
On Mac OS X, libusb doesn't work for USB HID devices. We can use the
hidapi library instead. Although the hidapi library supports Linux and
Windows too, we keep using libusb there to avoid the extra dependency.
2016-09-19 15:04:48 +02:00
Jef Driesen
bae6cb856e Add a new USB HID communication backend. 2016-09-19 15:04:48 +02:00
Jef Driesen
f30e048afc Add a configure option to build without libusb. 2016-09-19 08:48:04 +02:00
Jef Driesen
5bc52bc5a2 Merge branch 'eonsteel' 2016-09-17 23:49:37 +02:00
Jef Driesen
ec473feabf Restore the sample events.
In commit 864b46603963ea2f70f5166bb7a738a12fc280fc, the sample events
have been removed because we need to parse the enum string descriptor
instead of the numeric value.
2016-09-17 23:37:45 +02:00
Linus Torvalds
5e8b4dd6dc Suunto EON Steel: initialize the tank 'gasmix' index
The gasmix query interface considers cylinders and gas mixes independent
things, so the tank data structure has a pointer to the gasmix index.

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

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

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-17 14:47:23 +02:00
Linus Torvalds
40bc67d8ff Suunto EON Steel: do the proper enum lookup for a few more cases
Instead of hardcoding the enum values for setpoint type and gas type,
use "lookup_enum()" to actually parse the enum data and use that.

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

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-17 14:47:23 +02:00
Linus Torvalds
6352b90a34 Suunto EON Steel: fix the event begin/end flag
This fixes a bug where the begin/end marker was mistakenly added as the
value instead of as flag.

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

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

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

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-16 16:27:47 +02:00
Linus Torvalds
a1947f3fb0 EON Steel: pass in the type descriptor to samples that need it
The samples that take 'enum' types need the type descriptor to parse
what the enum type means.

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

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

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

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

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

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

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

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-16 16:26:49 +02:00
Linus Torvalds
84111fe606 Suunto EON Steel: add descriptor debugging output
.. every time I look for a new feature I add debug code to print out all
the descriptors.  So let's just do it once and for all.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-16 16:26:49 +02:00
Dirk Hohndel
eb61dc4c75 Add tank size reporting for Suunto EON Steel
Sadly the data we get from the EON Steel is a bit of a mess.
It doesn't really tell us if the data is metric or imperial (it always sends
both wet volume and working pressure). And in imperial mode the Suunto
engineers seem a bit confused. The pressure given (entered on the dive computer
in psi) is sent to us not in bar, not in atm... it's "something". As far as I
can tell it's a constant factor of 1.00069182389937 different from bar.
And the wet sizes are a bit to small to get the cuft size the user entered.
But instead of trying to guess and fix the mess, we just pass it through...

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

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

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-09-16 16:26:49 +02:00
Jef Driesen
decfa24f92 Fix the gas mix parsing for the Aladin Tec 2G.
Unlike the other models, the Aladin Tec 2G uses only a single byte to
store the oxygen percentage, and there is no need to manually re-map the
deco mix.

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

  ID: 0 0 1 1

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

  ID: 0 0 2 2

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

  ID: 0 X 2 X

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

  ID: 0 1 2 3

We can take advantage of this knowledge to avoid having to re-map the
deco mix id.
2016-09-02 16:34:06 +02:00
Jef Driesen
3b179e7058 Add support for the Sherwood Vision. 2016-08-25 09:10:06 +02:00
Jef Driesen
c506be93f9 Fix the decoding of the maximum depth.
Several devices (e.g. Oceanic Geo, Oceanic Veo 2.0 and Tusa Zen) report
a maximum depth that is clearly too large. The problem is easily fixed
by ignoring the higher bits. The exact bit mask is an educated guess. A
12 bit value is plausible because it's also used for the sample depths.
2016-08-23 07:58:25 +02:00
Jef Driesen
3b18d4a448 Improve the default layout detection.
Select the default memory layout for unsupported devices based on the
amount of memory indicated in the version string. This allows to
download a full memory dump.
2016-08-21 13:27:39 +02:00
Jef Driesen
6d3fbb7e6d Add a warning for unsupported devices. 2016-08-21 13:27:06 +02:00
Jef Driesen
dfa191c9bc Fix the temperature for the Tusa Zen Air. 2016-08-20 21:22:19 +02:00
Jef Driesen
f666cb8cb3 Add support for the Aqualung i550T. 2016-08-20 21:20:01 +02:00
Jef Driesen
2e40d35da4 Merge branch 'uwatec' 2016-08-18 23:32:41 +02:00
Jef Driesen
0ab2d8ccda Use the new settings field for the salinity.
Since the salinity bit is stored in the settings, there is no need for a
separate salinity entry in the header tables.
2016-08-17 14:09:52 +02:00
Jef Driesen
bfcd707889 Fix the parsing of freedives.
In freedive mode the sample rate is only 1 second instead of 4 seconds.
The tank pressure fields appear to be re-used for some other (unknown)
purposes, and should be ignored.
2016-08-17 14:08:50 +02:00
Jef Driesen
8b0a048175 Detect the gauge and freedive mode correctly.
The gauge and freedive mode bits are stored in the settings field. The
location of the gauge bit appears to be the same for all models. For the
freedive bit it depends on the model, and also not all models support
it.
2016-08-17 08:10:36 +02:00
Jef Driesen
1226b47c6d Add the salinity field for the Aladin Tec. 2016-08-17 08:10:11 +02:00
Jef Driesen
769d90aca2 Add support for the Scubapro Mantis 2. 2016-08-14 10:07:45 +02:00
Jef Driesen
af7e7aed19 Fix the decoding of the dive time.
The dive time is stored in two separate bytes: one for the number of
minutes, and another one for the hours. Since we only took into account
the first byte containing the minutes, the divetime for dives longer
than one hour was always too short.
2016-08-12 11:47:41 +02:00
Jef Driesen
ae93a6ab08 Add support for the Scubapro Mantis.
The Scubapro Mantis uses the same model number as the Meridian, and
works out of the box.
2016-08-11 08:57:47 +02:00
Jef Driesen
9e585a9525 Fix the Aeris 500AI serial number.
The Aeris 500AI serial number appears to be located at a slightly
different offset, and with an unusual encoding. It's a BCD encoded
number, but with the digits of each byte swapped.
2016-08-08 09:20:55 +02:00
Jef Driesen
00c2705786 Add the serial number encoding to the layout.
At the moment, the encoding of the serial number is tied to the global
pointer mode. To support devices where this is no longer the case, a new
entry for the serial number encoding is added.
2016-08-08 08:38:23 +02:00
Thomas Gschwind
0a769cdd57 Add salinity and timezone fields to Aladin Tec 2G 2016-08-07 09:31:21 +02:00
Janice
e99b8ac837 Add NDL and RBT for the ATOM31 and I450T 2016-08-05 10:26:07 +02:00
Jef Driesen
b4dc2532e8 Add support for the new extended hardware descriptor.
The latest v2.09 (hwOS) and v1.1.0 (hwOS4) firmware introduced a new
variant of the hardware descriptor command. This extended command
returns:

 - a 16 bit hardware descriptor
 - a 16 bit feature descriptor
 - an 8 bit model descriptor

The hardware descriptor is backwards compatible with the existing one
(upper bits are all zero for now). For the OSTC4, the feature descriptor
is currently used to indicated the Bonex scooter version (0x01), and the
model descriptor is 0x43. For all other models, the feature and model
descriptors are always zero for now.

For older firmware versions, which do not support the new extended
descriptor yet, there is an automatic fallback to the previous
descriptor.
2016-08-02 10:44:34 +02:00
Jef Driesen
9ef840fc96 Update the OSTC device descriptors.
There are a few new hardware variants since the last update.
2016-07-30 21:40:56 +02:00
Jef Driesen
f94aab3c8e Merge branch 'ostc4' 2016-07-30 21:39:56 +02:00
Jef Driesen
b896847e14 Add a workaround for an OSTC4 firmware bug.
Due to a firmware bug, the deco/ndl info is incorrect for all OSTC4
dives with a firmware older than version 1.0.8. Since it's not possible
to correct the info again, it's ignored and not returned to the
application.
2016-07-30 21:36:55 +02:00
Jef Driesen
ff15b865b2 Fix the decoding of the OSTC4 firmware version.
The OSTC4 firmware version uses four digits for the firmware version
(X.Y.Z.Beta), while all other hwOS models use two digits (X.Y). To
preserve backwards compatibility with the existing two byte data format,
the OSTC4 firmware version is packed into a 16 bit integer as follows:

   XXXX XYYY YYZZ ZZZB

and stored with little endian byte order.
2016-07-30 21:36:55 +02:00
Jef Driesen
2829f7ebf9 Add an ostc3 specific function with the model number.
To be able to pass the OSTC 3 model number to the parser, and preserve
backwards compatibility, we need a new function. The new function should
also be used for the Frog, by passing zero as the model number.

Using the hw_ostc_parser_create() function with the hwos parameter set
to one, is now deprecated but will remain supported for backwards
compatibility.
2016-07-23 23:14:13 +02:00
Jef Driesen
29caab0673 Rename the frog parameter and field to hwos.
The frog parameter and field are not only used for the Frog, but also
for all hwOS based models. Therefore, using the more generic hwos as the
name is more meaningful.
2016-07-23 23:11:30 +02:00
Jef Driesen
ad2257569c Add a new dc_parser_new2 convenience function.
For applications supporting offline parsing (like libdivecomputer's own
dctool application), some device specific knowledge is still required in
order to map a particular model to the corresponding backend. The new
convenience function will take care of that internally.

The already existing dc_parser_new() function does the same, but
requires an open device handle, which makes it unsuitable for offline
parsing.
2016-07-22 21:14:33 +02:00
Jef Driesen
c8b2d89354 Set the default model number.
When the device family is provided without an explicit model number, we
simply choose the first available model. But since new models are being
added all the time, this default model is not guaranteed to remain the
same. That's not desirable because it can alter the behaviour of the
application.

The introduction of the Aeris 500AI is an example of this problem. The
default model in the vtpro family used to be the Oceanic Versa Pro. But
because the Aeris 500AI has a lower model number, it automatically
became the new default model. Since both use a different protocol
variant (MOD vs INTR) they are not interchangable.

The default model is now hardcoded. The best option is of course to
provide the model number explicitly!
2016-07-11 21:49:16 +02:00
Jef Driesen
335539f179 Merge branch 'aeris500ai' 2016-07-11 21:48:58 +02:00
Jef Driesen
92f84b5945 Refactor the oceanic download function.
The large and complex oceanic_common_device_foreach() function is
refactored into two independent helper functions. One for reading the
entries in the logbook ringbuffer, and another for reading the profile
data.
2016-07-11 21:47:29 +02:00
Jef Driesen
aaa7fbe08d Add support for the Aeris 500AI.
The Aeris 500AI is quite different from the other vtpro compatible
models. First, it uses the INTR protocol variant. Next, it doesn't
appear to have a logbook ringbuffer. Instead it supports a new read
logbook index command (0x52) that returns the logbook entries. This
requires a custom implementation of the logbook function.
2016-07-11 21:47:29 +02:00
Jef Driesen
9c251b6814 Ignore samples with all 0xFF bytes. 2016-07-11 21:47:29 +02:00
Jef Driesen
5824254cf5 Add support for the INTR protocol variant.
There are two variants of the vtpro communication protocol: the existing
MOD variant and the new INTR variant. The main difference is in the
initialization sequence, with two completely different response packets:

   MOD--OK_V2.00
   INTR-OK_V1.11

The INTR variant does not appear to return useful information in the
version packet.
2016-07-11 21:47:29 +02:00
Jef Driesen
b41ecd0c15 Add a parameter with the model number. 2016-07-11 21:47:29 +02:00
Jef Driesen
9bae07551f Allow custom logbook and profile functions.
By adding the logbook and profile functions to the vtable, a dive
computer backend can now easily replace the default implementation with
a custom one, without having to duplicate the common code.
2016-07-11 21:47:29 +02:00
Jef Driesen
4ba92e24ef Fix a crash when no dives are present.
To guard applications from divisions by zero, the progress event code
asserts the maximum value should always be non-zero. The eonsteel does
trigger this assert when there are no dives present.
2016-07-11 13:14:15 +02:00
Jef Driesen
1e22760f91 Fix the memory layout for the Aqualung i300.
The profile ringbuffer ends at 0xFE00 instead of 0x10000.
2016-06-23 08:48:45 +02:00
Jef Driesen
47037286a2 Fix the sample rate for the Aqualung i450t. 2016-06-13 15:17:58 +02:00
Jef Driesen
375fe2f6a7 Fix the nitrox gas mix parsing.
Mares Darwin compatible devices support a nitrox mode. The nitrogen
percentage should only be taken into account when the dive mode is set
to nitrox, because the last used value remains in place for air dives.
2016-06-03 08:19:42 +02:00
Jef Driesen
cb3b372b5b Add support for the dive mode field. 2016-06-03 08:13:55 +02:00
Jef Driesen
73a06407b8 Fix the length of the Vyper Novo gas change event.
Just like the Suunto DX, the Vyper Novo uses 5 bytes for the 0x06 gas
change event.
2016-06-02 08:27:24 +02:00
Jef Driesen
8f776cc55e Add support for the Aqualung i300. 2016-05-16 09:06:57 +02:00
Jef Driesen
d1aa9478a4 Merge branch 'refactor' 2016-05-10 20:22:07 +02:00
Jef Driesen
f8417037c6 Convert operating system errors.
Errors reported by system calls are now converted to the corresponding
libdivecomputer status code. This results in a more descriptive and
meaningfull return value.
2016-05-10 11:52:32 +02:00
Jef Driesen
4fd0118d4e Add support for 1.5 stopbits. 2016-05-10 11:35:03 +02:00
Jef Driesen
72bd82f0a3 Add support for space and mark parity. 2016-05-10 11:35:03 +02:00
Jef Driesen
84563c6303 Refactor the internal serial and IrDA api.
The low level serial and IrDA functions are modified to:

 - Use the libdivecomputer namespace prefix.

 - Return a more detailed status code instead of the zero on success and
   negative on error return value. This will allow to return more
   fine-grained error codes.

 - The read and write functions have an additional output parameter to
   return the actual number of bytes transferred. Since these functions
   are not atomic, some data might still be transferred successfully if
   an error occurs.

The dive computer backends are updated to use the new api.
2016-05-10 11:34:57 +02:00
Jef Driesen
dbba7f3272 Fix the date for the Sherwood Insight 2. 2016-04-27 16:20:04 +02:00
Jef Driesen
33f5206f79 Add support for the Beuchat Mundial 2 and 3.
These two models use the same memory layout and data format as the
Oceanic F10.

Reported-By: Nick Shore <support@mac-dive.com>
2016-04-27 09:09:06 +02:00
Jef Driesen
3978dea153 Merge branch 'eonsteel' 2016-04-26 21:04:32 +02:00
Jef Driesen
d40cdb4755 Add the devinfo event.
The devinfo event with the device serial number is required for the
fingerprint feature. Without this event, applications won't be able to
load (or save) the correct fingerprint. All necessary information is
already available in the initial handshake packet.
2016-04-26 10:59:02 +02:00
Jef Driesen
76c52b582a Add support for the fingerprint feature. 2016-04-26 10:56:52 +02:00
Jef Driesen
ce82829284 Fix a memory leak.
A new buffer is allocated for each dive, but only the last one is freed.
Since the code is already prepared to simply re-use the same buffer,
there is no need to allocate those extra buffers.
2016-04-26 10:56:48 +02:00
Jef Driesen
0899486378 Add support for the new DX data format.
Just like the D4i and D6i, the new header is a few bytes larger. The
correct variant can again be detected by means of the logbook id tag at
the start of the header.
2016-04-19 09:02:52 +02:00
Jef Driesen
018c27d7b3 Add support for the Aqualung i450T. 2016-03-31 13:26:34 +02:00
Jef Driesen
f3fb2391f9 Add support for the Cressi Newton.
The Cressi Newton appears to be compatible with the Leonardo and Giotto.
2016-03-29 16:34:59 +02:00
Jef Driesen
469717a2a1 Add support for imperial units in the xml output.
Libdivecomputer always uses metric units internally. But when reverse
engineering a device that stores everything using imperial units, it's
very convenient to be able to switch the output to imperial units too.
2016-03-29 16:34:27 +02:00
Jef Driesen
8ab3fb0542 Always close the xml tags.
The dive and sample xml tags were not closed properly if an error
occurred during parsing.
2016-03-27 22:02:52 +02:00
Jef Driesen
c8b166dadb Get the gas mixes from the sample data.
The Shearwater devices support adding, removing or editing gas mixes
during the dive. The pre-defined gas mixes available in the opening and
closing block are only a snapshot of the configuration at the start and
at the end of the dive. Thus by editing the gas mixes during the dive
it's possible to switch to a gas mix that is not present in the opening
(or even the closing block). The parser doesn't support that.

To avoid this problem, we now collect the available gas mixes from the
sample data. As a side effect we only return those gas mixes that are
effectively used during the dive.
2016-03-23 10:50:21 +01:00
Jef Driesen
c964fa5ad9 Cache the dive mode internally.
This simply moves the code to the get the dive mode from its own
function into the existing caching function.
2016-03-23 10:50:21 +01:00
Jef Driesen
0bb3f7ebd1 Add support for the Shearwater Perdix. 2016-03-23 10:48:59 +01:00
John Van Ostrand
9a4e2b75a5 Add support for the Cochran Commander and EMC. 2016-03-22 20:09:45 +01:00
Jef Driesen
280f1871f0 Add support for the Uwatec Aladin Sport.
The Aladin Sport appears to be compatible with the Aladin 2G.
2016-03-17 08:22:39 +01:00
Jef Driesen
50ba063a46 Add support for the Suunto Zoop/Vyper Novo.
The Zoop Novo and Vyper Novo are compatible with respectively the D4i
and D6i.
2016-03-11 10:36:05 +01:00
Jef Driesen
63dcee9eaa The new D6i data format support 3 gas mixes. 2016-03-11 10:35:46 +01:00
Jef Driesen
2e64d47dff Add support for the new D4i and D6i data format.
One of the newer D4i and D6i firmware versions (for example v1.5.9),
introduces a new variant of the data format. The new dive header is 8
bytes larger. The correct variant can be detected by means of the
logbook id tag at the start of the header.
2016-03-09 14:14:10 +01:00
Jef Driesen
42e234a0f9 Merge branch 'ostc4' 2016-03-07 13:10:48 +01:00
Jef Driesen
dbd604abb0 Add support for the HW OSTC 4.
Except for the firmware update and a few other minor differences, the
new OSTC4 is backwards compatible with the OSTC3.
2016-03-01 21:26:43 +01:00
Jef Driesen
f0c442751d Read and cache the hardware descriptor.
By reading the hardware descriptor immediately after entering download
or service mode, we can identify the specific model and adapt to minor
differences in the communication protocol.
2016-03-01 21:26:43 +01:00
Jef Driesen
6ce83347f0 Pass an array to the checksum function. 2016-03-01 21:26:43 +01:00
Jef Driesen
90cf480c25 Fix the OSTC3 missing initial gas mix detection.
For the OSTC3 compatible devices, a missing initial gas mix (e.g. no gas
marked as the first gas) leaves the initial gas mix index at its default
value of zero. This is different from the OSTC2 compatible devices,
where a missing initial gas is stored as the value 0xFF.

By initializing the index with the value 0xFF, the existing detection
works for both variants.
2016-02-26 08:25:55 +01:00
Jef Driesen
5629bdd87a Merge branch 'dctool' 2016-02-26 08:25:05 +01:00
Jef Driesen
83e54d84a2 Add support for the parse command. 2016-02-26 08:24:11 +01:00
Jef Driesen
e8b9e88171 Integrate the new output formats.
The existing output code is removed and replaced with the new XML and
RAW output formats. The desired output format can be selected with a new
command-line option. The XML format remains the default output format.
2016-02-26 08:24:11 +01:00
Jef Driesen
5d9ddafc41 Add support for the raw output format.
The RAW output format exports each dive to a raw (binary) file. To
output multiple files, the filename is interpreted as a template and
should contain one or more placeholders.
2016-02-26 08:23:55 +01:00
Jef Driesen
e35f0a3ff4 Add support for the xml output format.
The XML output format exports all dives to a single xml file.
2016-02-26 08:23:45 +01:00
Jef Driesen
195702046c Add a new abstract output interface.
The new output interface provides the necessary infrastructure to add
support for multiple output formats. Due to the abstract interface, each
new format will require only minimal changes in the application itself.
2016-02-26 07:55:40 +01:00
Janice
4765f7bc50 Fix year decoding for Sherwood Amphos Air 2016-02-19 19:47:29 +01:00
Jef Driesen
aafdbe8baa Fix the date for the Oceanic Datamask. 2016-02-16 20:38:03 +01:00
Jef Driesen
d2e150319b Fix the decoding of negative temperatures.
Due to a firmware bug, negative temperatures are stored incorrectly and
a workaround is necessary to recover the correct value.
2016-02-04 20:44:30 +01:00
Jef Driesen
67a3697a4d Disable the getopt argument permutation on BSD systems.
On BSD based operating systems (which includes Mac OS X), 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.
2016-01-30 23:00:17 +01:00
Jef Driesen
5add68b2d5 Use the optreset variable on BSD systems.
On BSD based operating systems the optreset variable should be used to
reset the internal getopt state. Setting optind to zero is a GNU
extension.
2016-01-30 23:00:17 +01:00
Jef Driesen
ade8619ea6 Don't assume malloc sets errno to ENOMEM.
Although many implementations (including glibc) set errno on failure,
this is not required by the C standard.
2016-01-26 20:32:22 +01:00
Jef Driesen
4228899f59 Reduce the conditional compilation for Windows.
With a few compatibility macros and helper variables, the amount of
conditional compilation can be greatly reduced.
2016-01-26 20:32:22 +01:00
Jef Driesen
4475d69814 Use the error code returned by the WSAStartup function.
Unlike the other socket functions, the WSAStartup() function returns the
extended error code directly. A call to the WSAGetLastError() function
is not needed and should not be used.
2016-01-21 20:11:36 +01:00
Jef Driesen
0acdee08a1 Merge branch 'f11' 2016-01-18 13:04:07 +01:00
Jef Driesen
6b3874121d Don't ignore zero depth samples in freedive mode.
In freedive mode, samples are only 2 or 4 bytes large, thus a sample
containing all 0x00 bytes represents a zero depth value and not some
invalid data that should be ignored.
2016-01-18 13:03:48 +01:00
Jef Driesen
789fdb4d9a Remove the footer sample for the F10 and F11.
The F10 and F11 don't seem to have a special footer sample after the
profile data. Those 8 bytes appear to be valid sample data.
2016-01-18 13:03:47 +01:00
Jef Driesen
ca032783a2 Fix the decoding of the dive time.
I originally assumed the second byte contains the hour, but that turns
out to be wrong. At least some of the bits have a different meaning.
With only seconds and minutes, the maximum divetime is limited to at
most 99 minutes and 59 seconds. That shouldn't be a problem for
freedives.
2016-01-18 13:03:47 +01:00
Jef Driesen
49af321bc5 Use the correct sample rate from the header.
The Oceanic and Aeris F11 have a configurable sample rate. The possible
sample intervals are 2, 1, 0.5 and 0.25 seconds. Since our smallest unit
of time is one second, we can't represent the last two, and the extra
samples will get dropped for now.
2016-01-18 13:03:47 +01:00
Jef Driesen
9d856e5a36 Fix the memory layout for the Oceanic F11. 2016-01-18 13:03:47 +01:00
Jef Driesen
9520ecddbc Add support for the Oceanic F11.
This appears to be an Oceanic branded version of the Aeris F11.
2016-01-18 13:03:47 +01:00
Jef Driesen
0afa60bd97 Return a more appropriate error code.
The DC_STATUS_IO code is intended for reporting low-level I/O errors.
That's not the case here, and there are more appropriate error codes
available.
2016-01-18 12:56:49 +01:00
Jef Driesen
ff29d218bb Use helper functions to allocate and free objects.
Both the allocation and initialization of the object data structure is
now moved to a single function. The corresponding deallocation function
is intended to free objects that have been allocated, but are not fully
initialized yet. The public cleanup function shouldn't be used in such
case, because it may try to release resources that haven't been
initialized yet.
2016-01-05 20:40:21 +01:00
Jef Driesen
9bc14dca10 Remove some boilerplate code from the cleanup functions.
Instead of freeing the object data structure in the backend specific
cleanup function, the memory is now freed automatically in the base
class function. This reduces the amount of boilerplate code in the
backends. Backends that don't allocate any additional resources, do no
longer require a cleanup function at all.
2016-01-05 20:40:21 +01:00
Jef Driesen
f1c0249053 Simplify the error handling in the close function.
When the close function returns, all resources should be freed,
regardless of whether an error has occured or not. The error code is
purely informative.

However, in order to return the first error code, which is usually the
most interesting one, the current implementation is unnecessary
complicated. If an error occurs, there is no need to exit immediately.
Simply store the error code unless there is already a previous one, and
then continue.
2016-01-05 20:40:21 +01:00
Jef Driesen
18d4d5dcc0 Switch to goto style error handling.
With the goto error handling, all cleanup code can be moved to a central
location and no longer needs to be duplicated multiple times.
2016-01-05 20:40:21 +01:00
Jef Driesen
0fb6f5a7fa Merge branch 'dctool' 2016-01-05 20:39:52 +01:00
Jef Driesen
013882f3f2 Add the fwupdate command. 2016-01-05 20:38:47 +01:00
Jef Driesen
ce472ffa19 Add the read and write commands. 2016-01-05 20:38:47 +01:00
Jef Driesen
195c4c7a7e Add the download command. 2016-01-05 20:38:47 +01:00
Jef Driesen
bfbb56c781 Add the dump command. 2016-01-04 19:50:51 +01:00
Jef Driesen
ff7c3f6901 Add the list command. 2016-01-04 19:50:51 +01:00
Jef Driesen
4dee95d352 Add the version command. 2016-01-04 19:50:51 +01:00
Jef Driesen
38c9ebc74e Add the help command. 2016-01-04 19:50:51 +01:00
Jef Driesen
57a54f824c Add helper functions for converting hexadecimal data. 2016-01-04 19:50:51 +01:00
Jef Driesen
8f61648a39 Add helper functions for reading/writing binary files. 2016-01-04 19:50:51 +01:00
Jef Driesen
5188f5c25f Add a helper function for translating status codes. 2016-01-04 19:50:51 +01:00
Jef Driesen
655e9ad312 Add a default event handler. 2016-01-04 19:50:51 +01:00
Jef Driesen
28d8759294 Setup the cancel signal handler. 2016-01-04 19:50:51 +01:00
Jef Driesen
f0e5edc50b Setup the device descriptor. 2016-01-04 19:50:51 +01:00
Jef Driesen
3c57060d95 Setup the library context. 2016-01-04 19:50:51 +01:00
Jef Driesen
689e1f1f55 Change the format for error and warning messages.
Use the same format as used for printing the error and warning messages
from libdivecomputer itself.
2016-01-04 19:50:51 +01:00
Jef Driesen
b5503e53fd Add a more modular example application.
The universal application works well, but is quite difficult to extend
with more functionality. Therefore a new and more modular application is
needed. The new dctool application will support multiple sub-commands,
to carry out specific actions. Extending the application will be as easy
as adding new commands.
2016-01-04 19:50:51 +01:00
Jef Driesen
dd779d531a Fix the date parsing for several models.
To store the day (range 1 to 31) as a binary encoded value, only 5 bits
are required. The extra 6th bit is part of the year. The year is also
not BCD encoded. This happened to work by accident, because for a single
nibble, the current implementation of the bcd2dec() function returns the
binary value.
2016-01-04 19:30:40 +01:00
Jef Driesen
06e0de6712 Add a new sample with the active gas mix.
The new gasmix sample contains the index of the active gas mix.

This new sample is intended as a replacement for the existing gas change
events (SAMPLE_EVENT_GASCHANGE and SAMPLE_EVENT_GASCHANGE2). To maintain
backwards compatibility, the legacy events are marked as deprecated but
not removed yet.
2015-12-21 14:03:39 +01:00
Jef Driesen
d839852953 Parse the profile to retrieve the bailout gas mixes.
In CC mode, only the diluents are stored in the header. The list with
the OC gas mixes, which are used for bailout, are not stored in the
header. In order to retrieve the bailout mixes too, we need to parse the
profile and add them to the manual gas mixes.
2015-12-21 12:58:02 +01:00
Jef Driesen
5c6c4cccc7 Add support for the DiveSystem iX3M series.
The protocol of the iX3M series is almost identical to the protocol of
the iDive series. The main difference is that the command bytes and the
size of the response packets have been changed. In order to be able to
communicate with the correct set of commands, the user needs to supply
the correct number now. To maintain backwards compatibility, a new
variant of the open function is added.
2015-12-14 12:23:31 +01:00
Jef Driesen
d516376ce7 Improve the support for pseudo terminals.
Apparantly Fedora applies a custom patch to glibc's tcsetattr()
function, which adds an extra check to verify the PARENB/CREAD/CSIZE
bits in the termios c_cflag field.

However, in commit 197b9f09421111e03588c94d55a72aa6ec624c63 we already
discovered that for pty's, some of the termios settings make no sense at
all, and therefore the Linux kernel always does:

    tty->termios.c_cflag &= ~(CSIZE | PARENB);
    tty->termios.c_cflag |= (CS8 | CREAD);

Thus, instead of ignoring such nonsense termios settings, the kernel
changes the termios structure to reflect what pty's actually do. The
consequence is that these settings will not stick, and cause the extra
check in the Fedora specific patch to fail.

To workaround this problem, we ignore the error when building
libdivecomputer with pty support enabled.
2015-12-10 19:41:41 +01:00
Gilbert J. M. Forkel
07c9cf8950 Correctly detect a device without any dives.
If the dive computer has not recorded any dives yet, the profile pointer
isn't valid and contains the default value 0xFFFFFFFF. There is no need
to return an error in this case.
2015-12-10 14:53:45 +01:00
Jef Driesen
a4838e7cfc Fix the layout for the Oceanic Atom 1.0.
The profile ringbuffer starts already at address 0x0440 instead of
0x0A40. The logbook ringbuffer is therefore a bit smaller too.
2015-12-06 17:40:41 +01:00
Jef Driesen
a155fb717b Add extra debug information to the error messages.
With the extra debug information it's easier to investigate the
underlying problem, without needing a debugger.
2015-12-06 17:40:02 +01:00
Jef Driesen
9ee3a10390 Add a workaround for a missing initial gas mix.
In some rare cases, the initial gas mix contains the value 0xFF. This
value is obviously outside the expected range (1-5), and therefore
causes the parsing to fail. It's not really clear how this can happen.

As a workaround for the fatal error, we now ignore the invalid value and
simply proceed without a gas mix.
2015-12-06 17:38:03 +01:00
Jef Driesen
842c4ca466 Fix the salt water conversion.
The dive computer records the raw absolute pressure. To convert this
pressure value into a depth, we need to divide by the salinity factor,
not multiply!
2015-11-10 10:42:36 +01:00
Jef Driesen
4552558e87 Use an output parameter for the number of bytes.
With the number of bytes returned separately from the error code, we can
immediately return the correct error code.
2015-11-10 08:24:15 +01:00
Jef Driesen
fb5f7ad971 Use the GCC printf format attribute.
This enables the compiler to check the arguments against a printf style
format string in all calls to the logging functions.
2015-11-06 07:52:27 +01:00
Jef Driesen
0a20eae342 Prefer the C99 identifier for the function name.
The GCC 5 compiler with -Wpedantic enabled generates warnings for the
non-standard predefined identifier __FUNCTION___. These warnings can be
avoided by using the C99 identifier __func__ instead.
2015-11-06 07:51:42 +01:00
Jef Driesen
84d67c5544 Add support for the new OSTC logbook format.
With the new logbook format version 0x24, the OSTC no longer stores the
date/time at the end of the dive, but at the start of the dive.
2015-10-29 09:50:37 +01:00
Jef Driesen
ae70d1efba Fix the dive mode for the Galileo Trimix.
Parsing the gas mixes has been implemented a while ago, so this check is
no longer neccessary.
2015-10-29 09:28:56 +01:00
Jef Driesen
8ac9778c9e Merge branch 'atom2' 2015-10-28 08:56:23 +01:00
Jef Driesen
aa2499ef0f Implement gas switches for the Hollis TX1. 2015-10-28 08:27:24 +01:00
Jef Driesen
99300d4e37 Implement ndl/deco support for the Hollis TX1. 2015-10-28 08:27:24 +01:00
Jef Driesen
3b0e36ccbf Implement ndl/deco support for the Tusa Zen. 2015-10-28 08:27:24 +01:00
Jef Driesen
7341403f73 Fix the temperature for the Tusa Zen. 2015-10-28 08:27:24 +01:00
Jef Driesen
95aa477129 Cache the parser data internally. 2015-10-28 08:27:24 +01:00
Jef Driesen
6f89e445e3 Convert the internal tank id to an index.
The internal Uwatec tank id should be converted to the libdivecomputer
tank index. If there is no corresponding tank, the tank pressure samples
are dropped for the following reasons:

Some models appear to record an absolute tank pressure sample, even if
there is no pressure sensor attached to the corresponding tank. In this
case only the tank index changes. The sample value simply retains the
last pressure of the previous tank. Since we don't have any real
pressure data, dropping those samples is fine.
2015-10-28 08:26:58 +01:00
Jef Driesen
a21f60e0bc Handle a libusb timeout as a non fatal error.
Dives are downloaded using bulk transfers with an 8K buffer. Normally
the 2 second timeout is more than sufficient, and the timeout should
never expire, unless there is some serious communcation problem. But
nevertheless, users are reporting timeouts for dives having a length
that is an exact multiple of the USB packet size (64 bytes). In that
case, libusb reports a timeout with an non-zero amount of bytes
received. Despite the timeout, the received data contains a complete
dive.

I suspect libusb is somehow unable to determine whether the transfer is
complete and therefore waits until the timeout expires. For transfers
that are not a multiple of the USB packet size, the end of the transfer
is indicated by the last incomplete packet. This is not the case if the
length is an exact multiple of the USB packet size. This problem is
usually solved by sending a zero-length packet. Maybe the USB stack of
the Cobalt is not sending such a zero-length packet?

Atomics will address the problem with a Coblat 2 firmware upgrade, that
will simply append two zero bytes if the length is a multiple of 64
bytes. As a workaround for older firmware versions, we ignore the
timeout and process all received data. This shouldn't have any
disadvantages. An incomplete dive, for example due to a real timeout,
will now be detected by means of the minimum length and/or the checksum.
2015-10-28 08:08:17 +01:00
Robert C. Helling
00e0cfa0ab Mention Shearwater Nerd alongside with Petrel 2
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2015-10-16 19:55:57 +02:00
Janice
0efa420b71 Convert ndl/deco time to seconds. 2015-10-14 09:11:47 +02:00
Giorgio Marzano
95bdea93cd Use the correct memory layout and packet size. 2015-10-05 15:11:34 +02:00
Giorgio Marzano
cb06adef35 Add support for the Mares Smart Apnea.
The Mares Smart Apnea uses a different data format than the regular
Smart, because it records not only a summary of each freedive in the
session, but also a full depth profile.

Because both the regular Smart and the Smart Apnea have the same model
number (0x10), another way to distinguish the two variants is needed.
Therefore, the Smart Apnea gets a modified model number, with one of the
higher bit set. The actual type is detected from the contents of the
version packet.

The new Smart Apnea is also capable of recording multiple samples per
second (e.g. 2, 4 or 8). But since our smallest unit of time is one
second, we can't represent this, and the extra samples will get dropped
for now.
2015-09-30 08:19:59 +02:00
Jef Driesen
3fa606a8a2 Fix the gas switches for Galileo Trimix.
The Galileo Trimix supports up to 10 tanks and gas mixes. However, the
existing alarm based gas switch events have only 2 bits available, and
can support at most 4 gas mixes. Therefore, the trimix variant stores
another 4 bit value in the second alarm byte.

For the first three gas mixes (and possibly also the fourth), both alarm
bytes appear to be always set to the same value. For the higher mixes,
the value in the first alarm byte is always zero. This doesn't cause any
problems, because in the data stream the second alarm byte is stored
after the first one, and our final value is always the last one.

The non-trimix variant also has the second alarm byte, but the gas mix
bits appear to be always zero. In order to avoid taking this zero as the
final value, a separate table is used for the trimix variant.
2015-09-17 11:24:16 +02:00
Jef Driesen
52453f080d Add support for the tank field.
The air integrated uwatec aladin models do record the total consumption,
and not the begin/end pressure. Returning the total consumption as the
begin pressure, combined with a zero end pressure is strictly speaking
not correct, but it still provides useful information.
2015-09-11 22:41:46 +02:00
Jef Driesen
ddbcdeecbb Ignore disconnected O2 sensors.
Even if there are no O2 sensors connected (for example in auto or fixed
setpoint mode), the device records a ppO2 sample with all three values
set to zero. Such samples are now ignored, as if there was no ppO2
sample present.

Reported-by: Anton Lundin <glance@acc.umu.se>
2015-09-10 09:25:06 +02:00
Jef Driesen
c72bdfe4e4 Add support for logging I/O operations.
The Atomics Cobalt backend uses libusb directly, without going through
an internal I/O layer that support logging. Therefore the logging needs
to be done in the backend itself.
2015-09-07 22:51:44 +02:00
Jef Driesen
55afe711f7 Fix the layout for the Oceanic Pro Plus 3.
The logbook ringbuffer starts at address 0x03E0 instead of 0x240. Since
none of the other models uses the same address, a completely new layout
structure is necessary.
2015-08-29 09:16:49 +02:00
Jef Driesen
3ff890b3e2 Improve the detection of unused tanks.
The begin/end pressure for unused tanks is normally zero. But I noticed
that in some cases both pressure values are stored as 0xFFFF. Since that
corresponds to a pressure of 511.99 bar, this is most likely some
special magic value, and not a valid pressure.

Tanks where either the begin or end pressure is 0xFFFF are now ignored
too.
2015-08-28 07:28:26 +02:00
Jef Driesen
5381714d08 Fix a bug in the tank id.
Due to a bitshift with the wrong number of bits, the tank id was always
zero for the Uwatec trimix firmware.
2015-08-20 09:08:56 +02:00
Jef Driesen
922d219bdc Add support for the tank field. 2015-08-10 13:10:44 +02:00
Jef Driesen
2fafcc7ae2 Disable all gas mixes in gauge/freedive mode. 2015-08-06 12:00:10 +02:00
Jef Driesen
04ffc894c9 Add support for ppO2 samples.
When the PPO2 sample was introduced, we didn't take into account the
fact that rebreathers usually support multiple O2 sensors. The HW OSTC
supports for example three sensors. In order to support multiple values,
without having to introduce a new data structure with an additional
sensor id field, we simply relax the assumption of allowing only one
DC_SAMPLE_PPO2 value per sample. Applications that are not prepared for
multiple values, will automatically use only one of them (probably the
last one).
2015-08-06 08:50:14 +02:00
Jef Driesen
a8f06c5c3c Add support for the new compact logbook headers.
With firmware version 1.84 (beta), a more compact logbook header is
introduced. Due to their smaller size (16 vs 256 bytes), the total
amount of data that needs to be transferred is much smaller (4K vs 64K).
Therefore, downloading these compact headers is roughly 16 times faster
then downloading the full headers.

For backwards compatibility with older firmware versions, there is an
automatic fallback to the full logbook headers.
2015-08-02 21:22:32 +02:00
Jef Driesen
98a7b86dcf Merge branch 'petrel' 2015-07-15 14:36:55 +02:00
Jef Driesen
0d04ad58a3 Add support for setpoint samples.
The setpoint samples are only enabled for closed circuit dives.
2015-07-15 14:36:30 +02:00
Jef Driesen
1a8e757daf Add support for the dive mode.
The Shearwaters store the current dive mode for each sample, and not one
single value for each dive. Therfore we need to process all samples. If
there is at least one sample marked as closed circuit, we classify the
dive as a closed circuit dive. Otherwise we default to open circuit.
2015-07-15 14:36:30 +02:00
Jef Driesen
af3b38d6f4 Cache the sample and header/footer size. 2015-07-15 14:36:30 +02:00
Jef Driesen
73ae03a4c0 Merge branch 'atom2' 2015-07-14 22:46:47 +02:00
Jef Driesen
4795e1b6ce Prevent a zero length memory allocation.
In theory this shouldn't be possible, but it doesn't hurt to check the
length explicitely.
2015-07-14 22:46:32 +02:00
Jef Driesen
76bd9783d4 Add an exception for devices without a logbook ringbuffer.
For devices without a logbook ringbuffer, such as the Oceanic Veo 1.0
and the Aeris XR-1 NX, the ringbuffer begin and end are identical. In
this case, the changes in the previous commit will always result in a
fatal error due to an invalid ringbuffer pointer. To avoid the error, we
exit before trying to use the pointers.
2015-07-14 22:46:32 +02:00
Jef Driesen
cfc1a68b0d Handle invalid logbook pointers as a fatal error.
Until now, an invalid logbook pointer was silently ignored and handled
as an empty ringbuffer. But this hides real errors, which is worse than
failing if no dives are present. Trying to download dives from an empty
device should be a rather uncommon scenario anyway.
2015-07-14 22:46:31 +02:00
Jef Driesen
55eaadac0c Merge branch 'uwatec' 2015-07-14 22:01:20 +02:00
Jef Driesen
f8d25fc49f Remove the event bytes from the vendor sample.
Now that we are able to parse the event bytes properly, there is no need
to pass the raw event bytes to the application.

In the current implementation, the vendor event was broken for devices
with multiple event bytes anyway. Because we deliver all event bytes at
once, the application doesn't know which bytes contain a valid value
(originating from the profile data) or just a dummy zero value.
2015-07-11 09:12:43 +02:00
Jef Driesen
efe7e52bbe Add support for parsing the event bytes.
Right now only gas switch and bookmark events are supported, because
none of the other uwatec events can easily be mapped onto the existing
libdivecomputer events. But the basic infrastructure for supporting more
events is in place now.
2015-07-10 10:58:05 +02:00
Jef Driesen
0158739bcf Use the static libgcc option only for Windows.
For obvious reasons, the -static-libgcc linker option is not supported
by non gcc compilers, like clang. Since we only need this option when
building Windows DLL's, we can easily avoid the problem with a
conditional on the mingw compiler.
2015-07-10 09:01:37 +02:00
Jef Driesen
b7c3582604 Fix the temperature for the Aeris Manta.
The Aeris Manta does not store the temperature as a delta value, but as
an absolute value (at offset 6).
2015-07-06 15:00:22 +02:00
Jef Driesen
37c00ce4f7 Add support for the Shearwater Petrel 2.
The Shearwater Petrel 2 uses exactly the same communication protocol as
the original Petrel. Therefore the new model has always been supported
out, and we only need to add the new model to the list of supported
devices.
2015-07-06 11:27:06 +02:00
Jef Driesen
73c6d03071 Merge branch 'uwatec' 2015-07-05 15:21:54 +02:00
Jef Driesen
701b93d865 Add support for the Galileo Trimix.
For the trimix version, the gasmix and tank information is no longer
stored in the header. It's now stored in a special sample at the end of
the dive.
2015-07-05 15:21:37 +02:00
Jef Driesen
7f3cea691d Use a fixed id for the uwatec deco mix.
The id of the uwatec deco mix is always 2, even for devices which
support maximum two gas mixes. Strictly speaking, this change is more
correct than commit 4fd825cdac341a2d4a1366c6deb7d4a71bbdf94d, allthough
in practice they are equivalent.
2015-07-05 15:21:37 +02:00
Jef Driesen
82c1a55a13 Fix the gas switches for galileo devices.
The bitmask for the gas mix bits was wrong. With the new mask we also no
longer have to disable the alarm based gas switches for the Meridian and
Chromis.
2015-07-05 15:21:37 +02:00
Jef Driesen
b17f432635 Fix the logic to skip disabled gas mixes.
Originally I assumed it's not possible to enable a gas mix if the
previous gas mix has already been disabled. However, this assumption
turns out to be wrong.  For devices with support for 3 gas mixes, it's
possible to enable only the first and the third gas mix, and leave the
second gas mix disabled.

This is fixed by checking all gas mixes, instead of aborting once the
first disabled gas mix has been found. Due to this change the uwatec gas
mix id's are no longer sequential and need to remapped to the
corresponding internal array index.
2015-07-05 15:21:37 +02:00
Jef Driesen
5629efad94 Merge branch 'eonsteel' 2015-07-05 11:37:52 +02:00
Linus Torvalds
90a19dd154 EON Steel: don't report airtime remaining as a libdivecomputer event
It looks like the SAMPLE_EVENT_AIRTIME is actually meant for just
airtime warnings (as in the dive computer warning about low air).

If we ever care, I think we'd need to add a new interface for this.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-05 11:33:49 +02:00
Linus Torvalds
a16f8ec470 EON Steel: fix up missing gastime/ventilation parsing
Now that I actually have dives with the new format and with air
integration, I could test it all out and noticed some missing pieces.

This adds parsing for gastime and ventilation events (although we don't
*do* anything with the ventilation data, I have no idea what the number
means).

Also, this fixes an annoying warning message problem, which caused these
missing events to cause a SIGSEGV rather than just a bening warning.
Stupid bug, and only went unnoticed because libdivecomputer isn't built
with format string warnings.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-05 11:33:49 +02:00
Linus Torvalds
edbdea0472 EON Steel: convert to dynamic sample parsing
This gets rid of the fixed sample indexes and the hardcoded grouping
code, and replaces them with proper parsing of the type descriptions.

This should mean that the new Suunto firmware v1.1.15 is now fully
supported by libdivecomputer.

There are still parts of the event description that we should really
parse better, notably the 'enum' descriptions of what the different
enumerated types mean, because it looks like those will change too.  But
that is not nearly as important as getting the basic infrastructure done
for the core sample types.

Almost accidentally, this also ends up now parsing the compass heading
event.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-07-05 11:33:49 +02:00
Linus Torvalds
af3e099c55 EON Steel: start moving away from "fixed" fields
I was initially fooled into thinking that the field type numbers have
some meaning: the types didn't change if the upper byte of the type
number was zero.  So I assumed that meant "fixed".

But the most recent firmware update made clear that no, they aren't
fixed, and the upper byte of the type must be some other thing.

This moves some more of the parsing over to comparing the strings,
rather than looking at the type index.  It still leaves the sample data
alone, and I really want to do something more efficient than comparing
the type descriptor string for that, but at least the dive header fields
are now just comparing strings.

The actual marshalling that Suunto uses also describes the encoding, and
it's all ignoring that for now.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-07-05 11:33:35 +02:00
Linus Torvalds
a701cc9309 EON Steel: empty descriptor lines are ok
Suunto's new v1.1.15 firmware ends up terminating some final descriptor
lines with a newline, rather than just using newlines as separators.  So
the last newline may not be followed by further data, but simple be the
end of the string.  Accept that case.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-07-04 08:44:54 +02:00
Linus Torvalds
bdae428639 Suunto EON Steel: populate dive surface pressure
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-04 08:44:54 +02:00
Linus Torvalds
9eef4d6cec suunto eon steel: clean up size limits and error reporting
This is some small cleanup after the whole reply size rewrite.  It
further improves on the error log reporting a bit, and it undoes the
"read exact size" thing introduced in "suunto eon steel: fix file
reading special case", because it is no longer necessary.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-04 08:44:54 +02:00
Linus Torvalds
e73dcdacae suunto eon steel: be more explicit about transfer sizes
When reading data from the EON Steel, we'd generally continue reading
until we saw that a response was done by seeing a packet that wasn't
full.

That broke for the case of the data boundary matching the packet
boundary, fixed by the commit "suunto eon steel: fix file reading
special case".

However, that commit only fixed it for the case of reading a file, where
the result has a size that is known up-front.  And most other situations
really don't matter, because the result size is fixed and fits in a
single packet, so it all works.

However, there are still a few cases that could trigger the problem,
notably reading the directory contents.

So change the send_receive() logic to actually read the expected size
from the receive header in the first packet of the reply.  This means
that we need to re-organize the packet reception code a bit, but the end
result is that we are much more careful about data sizes,

This also changes the packet logging to be much more readable, by
logging just the actual data, and not the (uninteresting) per-packet
header, or the stale data at the end of the packet.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-04 08:44:54 +02:00
Linus Torvalds
8e3cb0542f suunto eon steel: fix file reading special case
The "receive_data()" function would continue to try to read packets as
long as the previous packet was full-sized, but with just the right size
of file and the right chunking, the file might end at a packet boundary.
Then receive_data() would try to read more data, which fails - there are
no more packets, despite the last packet being full.

This never triggered for me, but Robert Helling forwarded a data dump of
a filure to read a dive due to this.

Since I don't trigger this case, I can't really test it, but I did check
that the new "stop early" logic works for me (ie never triggers ;).

Reported-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-04 08:44:54 +02:00
Jef Driesen
58f7235bb9 Update the symbols file. 2015-07-03 22:37:13 +02:00
Jef Driesen
98bd0d2d21 Update the msvc project file. 2015-07-03 22:37:13 +02:00
Jef Driesen
bd2b132d7f Avoid a run-time dependency on the libgcc dlls.
When compiling a 32bit dll with the mingw-w64 compiler, some 64bit
integer arithmetic operations are implemented using functions from
libgcc (e.g. __divdi3 and __moddi3 from libgcc_s_sjlj-1.dll). This
unexpected dependency is inconvenient for applications.

The run-time dependency can be avoid by linking statically.
2015-07-03 22:36:06 +02:00
Anton Lundin
ab92043dc3 Remove removed function from public header
reefnet_sensusultra_device_set_maxretries was killed off back in v0.3,
but was still lying around in the public header.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2015-06-26 09:59:24 +02:00
Jef Driesen
a72c03188d Use the correct layout for the Oceanic Geo.
At least one Oceanic Geo is unable to download the last memory page.
However, another device with an older firmware version (version 1D
instead of 2B), does not have this problem. So in theory the correct
layout depends on the firmware version.

But since the profile ringbuffer also appears to end at the address
0xFE00 instead of 0x10000, we'll never need to download that last page
in practice. Thus we can be lazy and simply use a single layout for all
firmware versions. The only drawback is that the last page might be
missing when downloading a full memory dump.
2015-06-16 23:00:07 +02:00
Jef Driesen
e7d142e5eb Fix the ringbuffer start address for the Aeris F10. 2015-06-16 23:00:07 +02:00
Jef Driesen
c647a27c27 Implement tank pressure samples for the Nemo Air.
The tank pressure is stored every third sample as a delta value.
2015-06-13 12:18:46 +02:00
Jef Driesen
bfd91a733c Implement the tank field for the Nemo and Puck Air. 2015-06-13 12:08:09 +02:00
Jef Driesen
e6f51ea302 Emit the devinfo event before using the fingerprint.
Applications are supposed to lookup the fingerprint when the devinfo
event is emitted. For the Uwatec Smart devices, the fingerprint is the
raw device timestamp. But because this timestamp was already used to
initialize the command before emitting the event, an outdated value
(typically the default value of zero) was used instead of the correct
one set by the application.
2015-06-02 09:46:08 +02:00
Jef Driesen
4dc727d507 Merge branch 'uwatec' 2015-05-21 16:28:24 +02:00
Jef Driesen
f720aa2fc8 Use the UTC offset of the device.
For devices with timezone support, use the UTC offset stored by the
device, instead of the current timezone of the host system.
2015-05-19 12:05:40 +02:00
Jef Driesen
74fcd11d2b Add support for the salinity field. 2015-05-19 12:05:40 +02:00
Jef Driesen
5ca1ef40c1 Adjust the depth for salt water dives.
The Uwatec dive computers report the depth based on fresh water. Salt
water dives need a correction to take into account the salinity. There
is only a fresh/salt water flag present in the data, but Uwatec appears
to assume a salinity factor of 1.025.
2015-05-19 12:05:40 +02:00
Jef Driesen
f59bad5260 Add support for the new tank fields. 2015-05-19 12:05:40 +02:00
Jef Driesen
50c8b46c96 Fix the size of the dive header.
The size of the dive header is one byte smaller: 0x32 instead of 0x33
bytes. Because we were expecting a larger packet, this bug caused the
downloading of the dive headers to fail. I'm surprised no one noticed
this mistake before.
2015-05-13 08:14:12 +02:00
Jef Driesen
568365397d Fix the CNS sample value.
The CNS value in the public api is reported as a fraction, and not a
percentage.
2015-05-13 08:13:59 +02:00
Jef Driesen
e810232a6d Add support for CNS samples. 2015-05-13 08:13:39 +02:00
Jef Driesen
d5eaa979d0 Convert the CNS value to a percentage. 2015-05-12 19:54:15 +02:00
Jef Driesen
4094f379ae Merge branch 'suunto' 2015-05-08 08:29:13 +02:00
Jef Driesen
106abe2dba Remove the temperature and pressure samples.
With the new temperature and pressure field, artificially injecting the
temperature and pressure info from the header into the samples is no
longer necessary. Applications will typically expect a real temperature
or pressure profile, and not a few discrete points.

The two surface samples (with zero depth) at the begin and end of the
dive are kept for now, to support events that occur at the surface.
2015-05-08 08:17:18 +02:00
Jef Driesen
7278a70afe Implement the tank and temperature fields. 2015-05-08 08:15:09 +02:00
Jef Driesen
5a61ffcc2f Use a variable for gauge mode.
This makes the code a little bit more readable, without needing any
comments.
2015-05-08 08:14:06 +02:00
Jef Driesen
e1f939c131 Move all caching code to a common function. 2015-05-05 21:15:51 +02:00
Jef Driesen
02e812f88b Apply the ghost event fix for the Suunto Solution.
I forgot to include the Suunto Solution part in the previous commit.

In theory the Suunto Solution (and Eon) can't be affected by the ghost
event bug. All possible events bytes are already exhausted, and
therefore unknown events are impossible. But applying the fix anyway
doesn't hurt and keeps the code consistent with the other backends.
2015-05-05 20:31:03 +02:00
Jef Driesen
23acddbe08 Eliminate ghost events caused by unknown events.
The newest Suunto models (e.g. D4i, D6i, D9tx and DX) support a few
additional events (type 0x15 and higher), which are not supported yet
because their interpretation isn't known.

Due to a nasty bug, these unkown events result in "ghost" events. When
such an unknown event is encountered, the sample type field isn't set
explicitely. Therefore it simply retains the value from the previous
sample, whatever that might be. If the previous sample happens to be an
event as well, then the unknown event will show up as a duplicate event.
But if the previous sample is not an event, then the resulting event
type is undefined.

This is fixed by always resetting the event type explicitely. Those
unknown events are also suppressed now and no longer delivered to the
application.

Allthough I haven't observed this bug with the Suunto Eon and Vyper,
they could be affected too.
2015-05-04 15:50:53 +02:00
Jef Driesen
ecd20ffb4c Merge branch 'ostc' 2015-05-01 11:31:07 +02:00
Jef Driesen
f24b93cd82 Parse the profile to retrieve the manual gas mixes.
The DC_FIELD_GASMIX api doesn't support the 6th manual gas very well.
Manual gas mixes are either not taken into account at all (OSTC3), or
only the last value is returned (OSTC2).

We now parse the profile data in order to retrieve all the manual gas
mixes too. Note that manual gas mixes are only included when they are
actively used during the dive. This is a small change in behaviour for
the OSTC2.

To simplify the implementation, there is an upper limit of 10 manual gas
mixes (or 15 gas mixes in total). This is an arbitrary choice, which
should be more than sufficient in practice. If it turns out to be too
small, we can always increase the number, or even make it truely
unlimited.
2015-05-01 11:29:35 +02:00
Jef Driesen
ac48210f4a Cache the fixed gas mixes too. 2015-05-01 11:29:35 +02:00
Jef Driesen
391de65d16 Cache the header data internally. 2015-05-01 11:29:35 +02:00
Jef Driesen
b832f4cf1b Cache the header and footer size internally. 2015-05-01 11:28:55 +02:00
Jef Driesen
8eba3cae3a Cache the gas mixes internally. 2015-05-01 11:28:20 +02:00
Anton Lundin
ad1c17b39d Dump function for the OSTC3
This adds a dump function for the ostc3 series computers. This function
dumps the whole external eprom, that contains the dive-headers and the
dive data.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2015-05-01 10:55:53 +02:00
Jef Driesen
c03c592a27 Merge branch 'iq700' 2015-04-29 23:06:12 +02:00
Jef Driesen
d7c89bbc39 Add support for the temperature field. 2015-04-22 08:27:41 +02:00
Jef Driesen
47874037ea Disable gas change events except for the intial mix.
For the IQ-700, the existing code for the active gas mix always results
in an out-of-range gas mix index. The index of the active gas mix is
probably stored in another bit. As a temporary workaround, we simply
assume the active gas mix is always the first gas mix. This should
already produce correct results for dives with only single gas mix.
2015-04-22 08:27:41 +02:00
Jef Driesen
311bc85645 Add support for the Tusa IQ-700.
The Tusa IQ-700 is very similar to the other Seiko based models. The
most important change is that due the smaller amount of memory (8K vs
32K), the logbook entries are only 1 byte large instead of two bytes.
2015-04-22 08:25:03 +02:00
Jef Driesen
f0974ed6bc Replace hardcoded constants with a layout descriptor. 2015-04-21 19:45:31 +02:00
Jef Driesen
9ae985a499 Fix the ringbuffer start address.
Currently the profile ringbuffer starts at the base address 0x4000, but
I believe the real start is one 0x20 byte page earlier, at 0x3FE0. I
have two reasons for this:

1. To locate the start of a dive, we always have to substract one page
from the pointers in the logbook ringbuffer. With the new base address,
they would point directly to the start of the dive, which makes a lot
more sense.

2. When comparing the divetime as stored in the header with the one
obtained by counting the number of samples, they always match except for
dives that span the ringbuffer wrap point. If those extra 0x20 bytes are
included, the counts do match again.

Unfortunately, this change breaks the assumption that the ringbuffer is
aligned to packet boundaries. As a workaround, we define a virtual
ringbuffer that is slightly larger than the actual ringbuffer, but
properly aligned. Data outside the real ringbuffer is downloaded and
then immediately dropped.
2015-04-21 19:45:31 +02:00
Jef Driesen
ad6ec1e7f5 Align all read operations to packet boundaries.
Packets have a fixed size of 0x80 bytes, while a single page is only
0x20 bytes long. Thus each read operation always returns 4 pages at
once. Now, if the end-of-profile pointer is not nicely aligned on a
packet boundary, then the download algorithm won't arrive exactly at the
start address of the ringbuffer, because the ringbuffer is properly
aligned. The consequence is that we won't even notice we reached the
ringbuffer boundary and happily continue reading outside the ringbuffer.
Oops!

This is fixed by aligning the end-of-profile pointer, which guarantees
that all read operations are now nicely aligned to packet boundaries.
2015-04-21 19:45:31 +02:00
Jef Driesen
c4233c091d Send the command and read the echo byte by byte.
When trying to send a command, the first attempt always fails. We
receive the echo, but no data packet. A second attempt usually works,
but we always get back the same data packet. That's cleary wrong.

Now, when comparing the data packets with those of the Tusa application,
I noticed something very interesting. When we request the first packet
(page 0x0000), we get:

  W: 520000
  R: 520000
  R: 00880124056202000250002890470824...19202720002000200020002000204145

The Tusa application also request this page, but the response is
completely different:

  W: 520000
  R: 520000
  R: 22182224222322092203220522112210...0000000000f021fc0000000000000045

The response we get is identical to the response that the Tusa
application gets for page 0x0052:

  W: 520052
  R: 520052
  R: 00880124056202000250002890470824...19202720002000200020002000204145

The only difference here is the echo of the command. But the echo should
be ignored, because it's generated by the pc interface, and not send by
the dive computer. This is easily verified by the fact that we always
receive an echo, even without a dive computer connected (e.g. only the
pc interface).

Notice how the command type (first byte) and page number (last byte) are
identical (0x52) for this request! I suspect that somehow the command
type ends up being interpreted as the page number. That would explain
why we're always getting the same response: as far as the device is
concerned we're always requesting page 0x52. This is probably also
related to the fact that the device doesn't respond after the first
request. It's not impossible that if the first command wasn't received
correctly and we resend the command, the device receives something that
contains parts of both attempts.

By sending the command and reading the echo byte by byte instead of all
at once, the above problem disappears.
2015-04-21 19:45:31 +02:00
Jef Driesen
edd777dbd3 Wait after changing the serial line settings.
Without the delay, the communication immediately fails. We receive the
command echo, but not the actual data packet. I suspect the device is
still be busy with the initialization and needs a bit more time before
it's ready to accept a request.
2015-04-21 19:44:01 +02:00
Jef Driesen
c4cbd19d5b Resend the command on failures. 2015-04-21 19:43:58 +02:00
Jef Driesen
327e39ed52 Merge branch 'mares' 2015-04-18 21:37:05 +02:00
Jef Driesen
3a6206e72c Relax the detection of the last dive.
We received data from a Mares Smart where the existing heuristics to
detect the last dive are not sufficient. The very last check, where the
calculated and stored are compared results in a fatal error.
2015-04-10 22:31:29 +02:00
Jef Driesen
4797ad8d9e Add support for the Mares Smart.
The Mares Smart supports not only scuba diving, but also freediving.
Because the freedive data format is fundamentally different from the
regular dives, being able to detect the type of dive in advance is very
important. For that reason, Mares moved the 4 bytes containing the dive
mode and number of samples from the beginning of the header to the end.
Except for this 4 byte shift, there are no changes for regular dives.

For the freedives, there is no real profile available, only a summary of
the entire freedive session. In an attempt to workaround this
limitation, we generate a pseudo profile in exactly the same (but ugly)
way as is done in the Mares Nemo backend.
2015-04-10 22:15:53 +02:00
Jef Driesen
e838aebc87 Add some additional DiveSystem iDive models.
These are all the models listed in the official documentation from
DiveSystem. They all share the same communication protocol and data
format.
2015-03-20 13:29:51 +01:00
Jef Driesen
a67e21dc2f Add support for two new OSTC3 variants.
The new OSTC3 (model 0x1A) is identical to the existing OSTC3, except
that the usb interface has been replaced with a bluetooth interface.

The new OSTC2 (model 0x1A) will retain the look and feel of the OSTC 2C
(e.g. plastic housing, piezo buttons and rechargable battery), but under
the hood it will use the same firmware as the OSTC3. It will also have a
bluetooth interface.
2015-03-18 13:30:35 +01:00
Jef Driesen
42808873e4 Disable alarm based gas switches for the Meridian.
The gas mix index stored in the alarm bytes is occasionally out of range
(larger than the number of available gas mixes). The index refers to one
of the disabled gas mixes. Since those are excluded now, this results in
a fatal error instead of a switch to a nonsense gas mix.

To workaround this problem, the alarm based gas switches are disabled
until we figure out how to parse them correctly.

The Chromis is almost identical to the Meridian, and will probably need
the same workaround. Although I don't have any data to confirm this,
let's just keep the two in sync.
2015-03-18 08:46:49 +01:00
Jef Driesen
c01ff9f9c6 Merge branch 'uwatec' 2015-03-12 14:13:59 +01:00
Jef Driesen
c135eb75de Implement the dive mode field.
Dives with all gas mixes disabled are flagged as gauge dives in the
Uwatec application.
2015-03-12 14:13:43 +01:00
Jef Driesen
76f93d3fe5 Ignore disabled gas mixes.
Gas mixes are disabled by setting their oxygen percentage byte to 0x00.
This is clearly an invalid gas mix, and it makes no sense to return it
back to the application.

It seems the device doesn't allow you to enable a gas mix if the
previous gas mix has already been disabled. Therefore we can simply stop
parsing the gas mixes once the first disabled gas mix has been found.
2015-03-12 14:13:43 +01:00
Jef Driesen
4fd825cdac Uwatec Aladin Tec 2G supports maximum 2 gas mixes.
According to the technical specifications, the Uwatec Aladin Tec 2G
supports maximum two gas mixes. The data appears to confirm this,
because the extra third gas mix always contains unrealistic oxygen
percentages.

However, I came across some data containing gas switches to the third
gas mix. The interesting part is that according to the Uwatec
application, this is actually a switch to the second gas mix in the
header. One possible explanation is that for models with up to 3 gas
mixes, they are labelled respectively "bottom", "travel" and "deco" mix.
But the documentation for the Aladin Tec 2G only refers to the bottom
and deco mix. So it might be that internally the index of the deco mix
is always the 3th mix, regardless of whether a travel mix is supported
or not.

If the only allowed values for the gas mix index are 0 (for the bottom
mix) or 2 (for the deco mix), then manually remapping the deco mix is
equivalent with ignoring the lowest bit. This has the advantage that the
required bitmasks and shifts are no longer different from those for the
other models.
2015-03-12 14:13:18 +01:00
Jef Driesen
8b64ce0edc Cache the parser data internally. 2015-03-12 14:13:18 +01:00
Jef Driesen
fb417ee5b5 No gas mix support for the Galileo Trimix yet.
For the Galileo Trimix we don't know yet where and how the gas mixes are
stored. Right now, we just pretend there are no gas mixes available,
which is misleading.
2015-03-12 14:13:17 +01:00
Jef Driesen
bcb2925a25 Fix the Galileo trimix detection.
Originally, I assumed that the trimix firmware update changed the model
number from 0x11 (Galileo) to 0x19 (Galileo Trimix). But that assumption
appears to be wrong because I received data from a Galileo with model
number 0x11, but with the trimix data format. Another explanation might
be that the trimix data format is not specific to the trimix firmware.

Anyway, this is easily fixed by treating both models identically.
2015-03-12 14:12:53 +01:00
Jef Driesen
5a1f1293d2 Disable tank pressure samples for the Aeris Manta.
The Aeris Manta is yet another non-air integrated model that doesn't set
the initial tank pressure to the magic value 10000.
2015-03-06 22:33:10 +01:00
Jef Driesen
90ba491c6d Merge branch 'ostc' 2015-03-06 21:45:39 +01:00
Jef Driesen
3b264d9cfd Add support for the new hardware descriptor.
The latest firmware v1.75 introduced a new hardware descriptor byte to
identify the different models based on their hardware features. This new
hardware descriptor is now used as the libdivecomputer model number. For
older firmware versions, which do not support the descriptor yet, there
is an automatic fallback to the previous method based on the serial
number.
2015-03-06 21:45:02 +01:00
Jef Driesen
bdbe95f221 Detect and report unsupported commands.
When trying to send an unsupported command, the ostc will simply ignore
the command. Instead of echoing the command byte back, the ostc will
immediately send the ready byte, to indicate it's ready to receive the
next command. We can use this to detect unsupported commands, because
the ready byte is a reserved value and guaranteed to never be a valid
command byte.

Normally we don't send invalid commands. But newer firmware version can
always introduce new commands to support new features. To maintain
backwards compatibility with older firmware versions, it's important to
be able to detect unsupported commands and provide a fallback.
2015-03-06 21:45:02 +01:00
Jef Driesen
c7d2bfc9a0 Add support for the Sherwood Amphos Air. 2015-03-04 08:13:53 +01:00
Jef Driesen
da96f0211a Fix the freedive mode for the DG03 and VT3.
The freedive/gauge bits for the Hollis DG03 and Oceanic VT3 are stored
at another location than our initial assumption.
2015-03-04 08:06:39 +01:00
Jef Driesen
f205ef736c Merge branch 'veo' 2015-02-27 10:31:17 +01:00
Jef Driesen
41834a31c7 Fix the freedive mode for the Oceanic Veo 2 and 3.
In freedive mode, the Oceanic Veo 2.0 and 3.0 have samples that are only
4 bytes long, instead of the normal 8 bytes.

The Oceanic VT3 and Hollis DG03 use the same logbook layout, and
although I haven't been able to confirm this with real data, it's very
likely they need the same fix.
2015-02-27 10:18:09 +01:00
Jef Driesen
488c396656 Fix the hour for the Oceanic Veo 2 and 3.
For BCD encoding the hour in a 12 hour clock system, only 5 bits are
required. The extra two bits are used for storing the freedive/gauge
mode.
2015-02-27 10:17:19 +01:00
Jef Driesen
678e75a05a Merge branch 'vtx' 2015-02-21 14:38:28 +01:00
Jef Driesen
bad4dd4342 Add support for the Oceanic VTX.
The Oceanic VTX is very similar to the Aeris A300 CS. The main
difference is the higher baudrate (115200 vs 38400). This is annoying
because without the correct baudrate, no communication is possible and
thus the existing autodetection based on the version packet doesn't
work. As a workaround, we now rely on the model number from the device
descriptor. The consequence is that the user must select the correct
model now (or at least a model with the same baudrate).
2015-02-19 13:47:48 +01:00
Jef Driesen
4dfca21a2b Pass the model number to the open function.
This change will be necessary for the Oceanic VTX, because it uses a
higher baudrate.

To maintain backwards compatibility, the existing function remains
unchanged and a new function is introduced instead.
2015-02-19 13:47:25 +01:00
Jef Driesen
f5d96a081c Extend the retry logic to corrupt data packets.
At the moment, there is only retry logic for the ACK/NAK byte. Corrupt
data packets (e.g. wrong checksum, unexpected length, etc) are treated
as a fatal error. By reading the entire packet inside the retry loop,
all non-fatal errors are automatically taken care off.

This change is necessary for the Oceanic VTX. For some unknown reason,
the device always responds with an invalid data packet when sending the
version command for the first time:

  W: 84 00
  R: 5A 4F ?? 45 41 4E 56 54 58 20 31 42 20 32 30 34 38 E9

There is always one byte missing (marked with question marks), resulting
in a timeout. However, when re-sending the command again, we receive a
valid data packet:

  W: 84 00
  R: 5A 4F 43 45 41 4E 56 54 58 20 31 42 20 32 30 34 38 E9

This might be a firmware bug, because we're observing the exact same
behaviour with the official Oceanlog application.
2015-02-19 13:47:25 +01:00
Jef Driesen
11d9256e43 Use symbolic constants for the commands. 2015-02-19 13:45:13 +01:00
Jef Driesen
5906c113af Merge branch 'freedive' 2015-02-15 19:25:58 +01:00
Jef Driesen
4671a31853 Disable gas mixes in freedive mode. 2015-02-14 21:44:58 +01:00
Jef Driesen
d2fce4ac3b Implement the dive mode field. 2015-02-14 21:44:58 +01:00
Jef Driesen
6f14e996d7 Fix the freedive mode for the Aeris Elite T3.
In freedive mode, the Aeris Elite T3 has samples that are only 2 bytes
long, instead of the normal 8 bytes.

Since there are many other models which support a freedive mode, the new
implemention provides the necessary infrastructure to easily integrate
those other models too.
2015-02-14 21:44:58 +01:00
Jef Driesen
6f23ab9ed7 Fix the depth for the Aeris F11.
Since the size of a sample is only 2 bytes, we were actually reading the
depth value from the next sample.
2015-02-10 21:18:23 +01:00
Jef Driesen
b781fcf73d Add support for the HW OSTC cR.
The OSTC cR is new model for closed circuit (CCR) diving. Under the hood
it's identical to the OSTC 3, but with an S8 connector to interface with
an external oxygen sensor. Since the data format already supports oxygen
sensors, the OSTC cR can be added to the list of supported devices
without any further changes.
2015-02-09 19:47:55 +01:00
Anton Lundin
1d5863d827 Add average depth from OSTC/OSTC3 logbook
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2015-02-09 19:45:30 +01:00
Jef Driesen
b6a3c9b237 Add support for the Scubapro Chromis. 2015-02-09 19:45:17 +01:00
Jef Driesen
6ad341d0c7 Disable tank pressure samples for the Oceanic Geo 2.0.
The Oceanic Geo 2.0 is a non-air integrated model that doesn't seem to
set the initial tank pressure to the magic value 10000.
2015-02-02 09:05:33 +01:00
Anton Lundin
cfd4f4ce17 Have make be more silent by default
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2015-01-21 09:09:02 +01:00
Jef Driesen
d50c9e8d63 Merge branch 'eonsteel' 2015-01-08 16:35:15 +01:00
Linus Torvalds
97a8d41089 Add EON Steel bookmarks, warnings and alarm events
I'd missed these because I'm blind. But mostly because they aren't as
common.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-01-08 08:49:36 +01:00
Linus Torvalds
92371935fc Parse EON Steel notification and state changes
The EON Steel notifications and states match the libdivecomputer ones
very badly, but this tries to make sense of the ones that match.  And
puts the infrastructure in to do others in the future.

Signed-off-by: Linus Torvalds <torvalds@linux-fouindation.org>
2015-01-08 08:49:36 +01:00
Linus Torvalds
7a7418421c Add EON Steel gas change event parsing
The really sad part is that the EON Steel handles gas change events
correctly, by actually saying which cylinder it switches to.  But the
libdivecomputer interfaces are broken, and only contain the gas *mix*
you switch to, which is ambiguous since you could have the same mix in
multiple cylinders.

Maybe we could put the one-based cylinder index into the "flags" field?
With zero meaning "unknown". That would be a straightforward extension.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-01-08 08:49:36 +01:00
Jef Driesen
87e6940572 Add support for the DiveSystem iDive and Orca. 2014-12-29 10:09:34 +01:00
Jef Driesen
f941af8d25 Merge branch 'ostc3-firmware' 2014-12-21 15:48:02 +01:00
Jef Driesen
396b867119 Reserve one byte extra for the null character.
The OSTC3 can display a status message of up to 16 characters large.
Since this does not include the terminating null character, the buffer
needs to be one byte larger.
2014-12-21 15:02:48 +01:00
Jef Driesen
e2589c0756 Replace the code for handling line endings.
The new implementation is similar to the already existing code for
reading Intel HEX files. It can handle arbitrary line endings, and not
just CRLF or LF.
2014-12-21 15:02:08 +01:00
Anton Lundin
2d4f76ab51 Simplify state switching and checking for OSTC3
This simplifies the code to check and handle state switching for the
OSTC3.

Suggested-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-12-21 15:02:08 +01:00
Anton Lundin
7c447c5c16 Remove unused imports
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-12-21 15:02:08 +01:00
Anton Lundin
57701ba0b0 Add Anton to copyright notice.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-12-21 15:02:08 +01:00
Anton Lundin
c6486444d3 Teach examples/ostc-fwupdate about OSTC3
This teaches the example firmware upgrader about how to upgrade the
OSTC3's.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-12-21 15:02:08 +01:00
Anton Lundin
02d8c0f04a Firmware upgrade for OSTC3
This connects the bits and implements firmware upgrade for the OSTC3.

This code is inspired by JeanDo ostc-companion.

Reviewed-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-12-21 15:02:08 +01:00
Anton Lundin
2733a9dc53 Add code to send upgrade firmware command to OSTC3
This function triggers a reboot into the bootloader which flashes the
new firmware to Prom.

This code is inspired by JeanDo ostc-companion.

Reviewed-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-12-21 15:00:02 +01:00
Anton Lundin
543ddca8a2 Add code to write rom of the OSTC3
This is how you transfer a new firmware to the OSTC3.

This code is inspired by JeanDo ostc-companion.

Reviewed-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-12-21 15:00:02 +01:00
Anton Lundin
6322e96268 Add function to read the rom from the OSTC3
This is necessary to verify that the memory written got transfered
correctly.

This code is inspired by JeanDo ostc-companion.

Reviewed-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-12-21 15:00:02 +01:00
Anton Lundin
5c71ff34c4 Add a function to erase the memory of the OSTC3
This is the fist step in the firmware upgrade process.

This code is inspired by JeanDo ostc-companion.

Reviewed-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-12-21 15:00:02 +01:00
Anton Lundin
08dda98c29 Add utility functions to convert uints to bytes
Reviewed-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-12-21 15:00:02 +01:00
Anton Lundin
1d8337c570 Add a helper to put the OSTC3 into servicemode
This code is inspired by JeanDo ostc-companion.

Reviewed-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-12-21 15:00:02 +01:00
Anton Lundin
d8f11810e1 Lift the OSTC3 INIT out of open
This lifts the OSTC3 INIT command out from the open function and does
that separately. This is refactoring to be able to enter service mode so
we can access service mode commands.

Reviewed-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-12-21 15:00:02 +01:00
Anton Lundin
b1c12b597b Add code to read and decrypt OSTC3 firmware files
This code is inspired by JeanDo ostc-companion.

Reviewed-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-12-21 14:52:12 +01:00
Anton Lundin
954cae1a0e Workaround msvc lack of a stdint.h
Suggested-by: Jef Driesen <jef@libdivecomputer.org>
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-12-21 14:52:12 +01:00
Anton Lundin
5820ac01e3 Port TinyAES-128 to be thread safe.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-12-21 14:52:12 +01:00
Anton Lundin
52bc5ab7a0 Import Tiny AES128
This imports Tiny AES128 from https://github.com/kokke/tiny-AES128-C for
use in the decoding of OSTC3 firmwares.

This aes-code is released into the public domain.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-12-21 14:52:12 +01:00
Jef Driesen
e453837c88 Merge branch 'vyper' 2014-12-18 21:50:07 +01:00
Janice
4b61434587 Also cache the number of mixes and the mix values
At least one dive computer in the Suunto Vyper family, the Vytec DS, is
capable of recording gas mix switches, and therefore supports more than
one mix. When going through the dive profile caching process, also look
for gas changes and record how many mixes were used in the dive. Mix 1
is always the main tank and it’s O2 value can be found in the dive
header, but the other tank O2 values are not available ahead of time. By
reviewing the dive profile ahead of time, the entire list of mixes can
be returned to the application at the beginning of the dive as per
usual.
2014-12-04 23:24:54 +01:00
Jef Driesen
3bf73253bc Cache the parser data internally.
The code to calculate parameters like maximum depth and divetime is
duplicated in multiple places. Move this code to a single place, and
cache the data in the parser instead.
2014-12-03 19:35:50 +01:00
Jef Driesen
134da18190 Fix the temperature for the Sherwood Amphos.
The sign bit is stored at a different offset.
2014-11-30 21:02:13 +01:00
Jef Driesen
598377ec44 Add support for the Citizen Hyper Aqualand. 2014-11-30 15:30:16 +01:00
Jef Driesen
d68cf82432 Merge branch 'eonsteel' 2014-11-24 14:10:45 +01:00
Jef Driesen
21f3dbcb04 Add a default case to the switch statement.
This is only the silence the "enumeration value not handled in switch"
compiler warning. There is already a check earlier on to take care of
unsupported fields, but the default case is a good practice anyway.
2014-11-24 11:57:23 +01:00
Jef Driesen
0ed5e6d653 Fix another memory leak.
The array with type descriptors is populated with dynamically allocated
strings, but they are never freed anywhere. To be able to free those
strings easily, they are now initialized with NULL pointers instead of
zero length strings.
2014-11-24 11:57:23 +01:00
Jef Driesen
d1121d174c Fix a few memory leaks. 2014-11-24 11:37:24 +01:00
Jef Driesen
6df4f00822 Fix a NULL pointer dereference. 2014-11-24 11:37:24 +01:00
Jef Driesen
0b0acf7336 Use the non-standard _snprintf() function for msvc. 2014-11-24 11:37:24 +01:00
Jef Driesen
dbcaa6946a Add explicit casts for the msvc C++ compiler. 2014-11-24 11:37:24 +01:00
Jef Driesen
f228a5f9fc Replace string literals with arrays.
This avoids some more compiler warnings regarding incompatible pointer
types (e.g. signed vs unsigned char pointers). Arrays have the
additional advantage of the sizeof operator. This eliminates an
unnecessary strlen() call, and the strcpy() call can be replaced with
memcpy().
2014-11-24 11:37:24 +01:00
Jef Driesen
d5933d59fb Replace zero length strings with NULL pointers.
This avoids some compiler warnings. The type of the string literal is a
const char pointer, while the send_cmd() function expects an unsigned
char pointer.
2014-11-24 11:37:24 +01:00
Jef Driesen
4120b2f0e9 Replace void pointers with unsigned char pointers.
Since we're dealing with byte arrays, there's no need to use void
pointers. Using unsigned char pointers also eliminates some compiler
warnings for pointer arithmetic on void pointers.
2014-11-24 11:37:24 +01:00
Jef Driesen
e8c2e87919 Remove the custom logging functions.
There is no need for custom logging functions, because libdivecomputer
already has an extensive logging infrastructure, featuring conditional
compilation, multiple loglevels, customization by the application, etc.
2014-11-24 11:37:24 +01:00
Jef Driesen
3368294018 Don't terminate the application on error.
Terminating the application on error, by calling exit, is not
appropriate in a library. An error code should be returned instead.
2014-11-24 11:37:24 +01:00
Jef Driesen
1fa054b409 Use the libusb autodetach functionality only if available.
The libusb autodetach kernel driver functionality is only available in
recent versions.
2014-11-24 11:37:24 +01:00
Jef Driesen
6bc6e58d3b Fix a redefinition warning for the ERROR macro.
See commit 113d2e4706698f7086e5499282ec958aa2de044f for more details.
2014-11-24 11:37:24 +01:00
Jef Driesen
686500d51b Follow the libdivecomputer naming conventions.
All entry point functions (e.g. public functions or functions called
through the vtable) use the backend name as the prefix. The same applies
to the main device and parser structures.
2014-11-24 11:37:24 +01:00
Linus Torvalds
5c967f3382 Suunto EON Steel: support downloading of core dive profile data
Basic Suunto EON Steel downloading copied from my test application.
This parses all the core dive data, including sample data (time, depth,
cylinder pressure, deco information etc).

The deco information returns ceiling and TTS rather than ceiling and
"time at ceiling", because that's what the dive computer has, and I
don't see any other way to return the information.

We don't report any events yet, though.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-11-24 11:37:23 +01:00
Jef Driesen
b2bc231cb4 Convert imperial tank volume to the metric system.
There are two different ways to specify the volume of a tank. In the
metric system, the tank volume is specified as the water capacity, while
in the imperial system the tank volume is specified as the air capacity
at the surface (1 ATM) when the tank is filled at its working pressure.

To avoid mistakes, the tank volume is now always returned as the metric
volume. For imperial tanks, the tank volume is converted to the metric
representation.
2014-11-13 13:13:07 +01:00
Janice
71fe683922 Don't look for tank pressure information from a GEO 2014-11-10 13:05:33 +01:00
Dirk Hohndel
5e88cf7494 Add missing break in Cobalt support for divemode
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-09 09:59:20 +01:00
Jef Driesen
4a16327322 Fix the tank working pressure for the Cobalt.
The difference between CUFT@PSI and CUFT@BAR is only for the Cobalt user
interface, to allow the user to enter the tank volume independent of the
units configured in the main preferences. Internally the working
pressure is always stored in psi.
2014-11-09 09:20:16 +01:00
Jef Driesen
52a9dc3947 Add support for the Mares Airlab.
The Mares Airlab is actually the same device as the Darwin Air.
2014-11-07 22:12:59 +01:00
Jef Driesen
14a29decd0 Merge branch 'divemode' 2014-11-07 22:12:23 +01:00
Jef Driesen
88159c6fe4 Implement the dive mode for several devices.
The new dive mode field is now supported by devices from these
manufacturers:

 * Atomic Aquatics
 * Heinrichs Weikamp
 * Mares
 * Reefnet
 * Suunto
2014-11-07 22:12:05 +01:00
Jef Driesen
c95ab19e6a Use symbolic constants for the dive mode. 2014-11-07 22:04:16 +01:00
Jef Driesen
651123de53 Add support for parsing the dive mode. 2014-11-07 22:04:16 +01:00
Jef Driesen
7a3d921725 Merge branch 'tanks' 2014-11-07 22:00:25 +01:00
Jef Driesen
25411672dc Implement tank support for the Mares Darwin Air. 2014-11-07 22:00:07 +01:00
Jef Driesen
11cafbaf5f Implement tank support for the Atomic Cobalt. 2014-11-07 22:00:07 +01:00
Jef Driesen
8f9878a1c0 Add support for parsing tank data in the dive header. 2014-11-07 22:00:07 +01:00
Jef Driesen
ed0cbf818d Merge branch 'temperature' 2014-11-07 21:59:31 +01:00
Jef Driesen
52cac91b18 Implement the temperature support for several devices.
The new temperature fields are now supported by devices from these
manufacturers:

 * Atomic Aquatics
 * Heinrichs Weikamp
 * Mares
 * Suunto
 * Uwatec
2014-11-07 21:58:49 +01:00
Jef Driesen
693a452250 Extend temperature with surface, min and max values. 2014-11-07 21:58:49 +01:00
Calle Gunnarsson
a4e5d4234c Cressi Leonardo now reports temperature from dive header
Signed-off-by: Calle Gunnarsson <calle.gunnarsson@gmail.com>
2014-11-07 21:58:49 +01:00
Calle Gunnarsson
cdbc0cd9bd Added support for parsing temperature in the dive header
Devices that only reports a single temperature in the header
will now be able to report it as well when they implement this.

Signed-off-by: Calle Gunnarsson <calle.gunnarsson@gmail.com>
2014-11-07 21:58:49 +01:00
Jef Driesen
60665ec633 Disable exclusive access mode during close.
When closing the slave side of a pseudo terminal, the exclusive access
mode will persists on the master side. The result is that re-opening the
slave side will fail with EBUSY, unless the process has root priviliges.
To workaround this problem, we already introduced an option that enables
better compatibility with pseudo terminals. See commmit
fab606b00a44ea2114a4029ad09b70c66c3049f7 for details.

In my development environment, I always have this option enabled. But
occasionally I also need to test release builds. And then I usually end
up with inaccessible pty's again, because the pty support is disabled by
default for release build.

This problem can easily be avoided by disabling the exclusive access
mode, just before closing the file descriptor.
2014-11-07 09:07:41 +01:00
Dirk Hohndel
d2eacc5c01 Fix temperature parsing for Sherwood Wisdom 3
Adds the new model and treats it like a Wisdom 2 (and many other, similar
versions of the Oceanic Atom2 style dive computers).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-30 10:03:11 +01:00
Janice McLaughlin
69fec57ed7 Fix the gas mixes for the Aeris A300AI.
The Aeris A300AI supports 4 instead of 3 gas mixes. The offset where the
gas mixes are stored was wrong too.
2014-10-28 09:14:25 +01:00
Jef Driesen
1d2ebd7af1 Fix the header size for the Oceanic VT4 and VT4.1.
This change was already present in the oceanic_atom2_parser_get_field()
function, but not in the oceanic_atom2_parser_samples_foreach()
function. These two should always be kept in sync.

This fixes a bug in the tank pressure detection.
2014-10-28 09:07:18 +01:00
Jef Driesen
853477b3b1 Add support for the Aeris F11.
Most of the changes needed for the F11 are the standard model specific
tweaks. But the F11 also has another interesting "feature". If you try
to download a full memory dump using the standard B1 read command, then
the data starts to repeat after the first 64K. It seems that somehow,
the B1 command can only address the first 64K of the memory. To avoid
this problem, the newer B4 read command needs to be used instead.

This might be a firmware bug, or maybe internally they store the address
in a 12bit variable, which causes the upper bits to get lost? That would
explain the repeating data.
2014-10-27 22:02:04 +01:00
Jef Driesen
af43c80d78 Merge branch 'a300cs' 2014-10-27 21:16:31 +01:00
Jef Driesen
a1ff11e08e Cache the last page to reduce the number of I/O operations.
In bigpage mode, we always read large pages, regardless of the amount of
bytes requested by the caller. Excess bytes are simply discarded. This
is inefficient because the same large page will be downloaded multiple
times, when requesting more than one 16 byte page from the same large
page. By caching the pages internally, we can greatly reduce the amount
of I/O operations.

In practice, applications and also libdivecomputer's internal algorithm
for downloading the dives will typically request contiguous pages, so we
only need to cache the last page.

This implementation is based on ideas and code contributed by Dirk
Hohndel.
2014-10-27 12:24:18 +01:00
Dirk Hohndel
0bcee519e0 Aeris A300CS: detect the number of cylinders used
The A300CS actually tells us how many of the cylinders it considers "in
use".

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-27 12:24:18 +01:00
Dirk Hohndel
7a108f555b Aeris A300CS: add reporting of water type (fresh/salt)
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-27 12:24:18 +01:00
Dirk Hohndel
16fb1c1869 Aeris A300CS: add support for NDL / deco data
Encoded in every sample. The depth is in multiples of 10 feet which gives
somewhat odd metric stop depth - but rounding to full meters would take
care of that.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-27 12:24:18 +01:00
Dirk Hohndel
d89dd952c9 Add initial support for the Aeris A300CS
This is ignoring a ton of data that the dive computer provides. But it
gives profile, tank pressure and temperatures - so it's a start.

This patch adds a set_dtr and set_rts call to the serial interface prior
to interacting with the device. This change is required for the A300CS to
talk to the computer.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-27 12:24:18 +01:00
Dirk Hohndel
4fa0f4cc59 Prepare Oceanic infrastructure for multi page reads
Some new Oceanic dive computers like the Aeris A300CS support a new read
command that always reads 256 byte pages instead of 16 byte pages, other
versions support reading 128 byte pages.

This patch adds a field to the oceanic_atom2_device_t structure to
indicate which type of device this is. If bigpage mode is enabled, the
algorithm will always request larger, aligned reads and fall back to
standard 16 byte reads otherwise.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-27 12:24:18 +01:00
Jef Driesen
abe2eab976 Fix the date/time for the Oceanic Pro Plus 3.
The day is stored as a binary value, not a BCD encoded value.
2014-10-25 21:21:43 +02:00
Jef Driesen
8853a1ccd4 Associate the pressure samples with the primary tank.
The primary tank, which is the tank connected to the hose and thus the
tank pressure sensor, it not necessary the first tank. The correct tank
index can be found by searching the array for a gas mix with a sensor id
equal to one.
2014-10-10 21:28:24 +02:00
Jef Driesen
9db9e970cf Convert the gasmix id into an array index.
The gasmix value in the sample data is the id of the gasmix. Depending
how the user manipulated the gasmix settings, this id is not necessary
identical to the index into the gasmix array.  The array index can be
found by searching the array for a mix with the correct id.
2014-10-10 21:28:24 +02:00
Jef Driesen
8edc765e6b Add some more error messages. 2014-10-10 21:27:15 +02:00
Jef Driesen
693bfa3916 Fix the Tusa Zen header size and pressure.
For the Tusa Zen, the header is 16 bytes smaller. With this change, the
gasmixes and the intial temperature are now parsed correctly.

The tank pressure samples have also been disabled manually, because this
is a non-air integrated model that doesn't seem to set the initial tank
pressure to the magic value 10000.
2014-09-14 22:09:48 +02:00
Jef Driesen
5f765f9143 Add support for the Subgear XP-3G. 2014-08-26 22:09:47 +02:00
Jef Driesen
e79bd02f0a Fix a buffer overflow.
The 6 byte logbook entry gets prepended to the profile data. We need to
take this into account when allocating the memory buffer. Under normal
circumstances this shouldn't be a problem, because a single dive is
usually much smaller than the profile ringbuffer. But it's better to be
on the safe side.
2014-08-26 22:08:41 +02:00
Jef Driesen
cde70334b0 Initialize the fingerprint before use.
The fingerprint is used unconditionally, regardless of whether it's
explicitly set by the application or not. Therefore it needs to be
initialized properly.
2014-08-26 22:07:59 +02:00
Jef Driesen
6845d9b77c Fix the Mares Puck 2 memory layout descriptor.
The Mares Puck 2 uses the same memory layout as the Nemo Wide 2. See
commit 322227df7f65da8b4a962f3513e0a10b89cbe29d for more details.
2014-08-21 23:41:20 +02:00
Jef Driesen
84d997fac6 Fix a build error.
Commit 7a851ccb1b9ed9b8906721cb1872b96b35185883 accidentally broke the
build due to a missing line.
2014-08-16 22:46:53 +02:00
Jef Driesen
549207a48b Add suport for the OSTC Sport variant.
Although the OSTC Sport uses bluetooth communication, the new model
remains fully compatible with the OSTC3, because it provides a virtual
serial port interface. As usual, the new model can be detected based on
the serial number.
2014-08-16 17:39:12 +02:00
Jef Driesen
b12d5acb86 Merge branch 'iconhd' 2014-08-14 12:00:03 +02:00
Jef Driesen
7a851ccb1b Add some extra error messages. 2014-08-14 10:20:23 +02:00
Jef Driesen
b0874ea4d9 Disable gas mixes and events in gauge mode.
For a dive in gauge mode, the gas mixes defined in the header should be
ignored, and no gas change event should be emitted. This is done by
hardcoding the number of gas mixes to zero.
2014-08-14 09:52:57 +02:00
Jef Driesen
4f2d71ce49 Cache the parser data internally.
The code to find the offset to the footer and parse the gas mix data is
duplicated in multiple places. Move this code to a single place, and
cache the data in the parser instead.
2014-08-13 16:23:22 +02:00
Jef Driesen
c2f86a7806 Ignore disabled gas mixes.
Gas mixes that have been disabled are stored as a mix with 0% oxygen and
0% helium. This is clearly an invalid gas mix, and it makes no sense to
return it back to the application.
2014-08-09 17:19:36 +02:00
Jef Driesen
ed2b9d34d5 Fix the dive mode detection for the Mares Nemo Air.
For the Nemo Air, a dive mode with the value 2 indicates gauge mode
instead of freedive mode. With this change, all models from the puck
family now use the same values.
2014-08-03 15:49:16 +02:00
Jef Driesen
5826257a79 Use symbolic constants for the model numbers. 2014-08-03 15:03:08 +02:00
Jef Driesen
eb036357a6 Ignore excess samples with the same timestamp.
With a time based sample interval, the maximum number of samples for a
single timestamp should be constant. However in practice some devices
occasionally store one or more additional samples with the same
timestamp.

Ignoring those excess samples, allows the parser to proceed, while still
preserving the strict time based interval for the application.
2014-07-10 12:40:10 +02:00
Jef Driesen
77d53813bd Remove the device specific example applications.
These device specific applications became obsolete long time ago with
the introduction of the universal application.
2014-07-02 17:06:27 +02:00
Venkatesh Shukla
33710423ac Add an option to disable the example applications.
The example applications may not always be needed. An option to disable
them might be useful.

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
2014-07-02 16:26:39 +02:00
Jef Driesen
6433a45bbc Fix the date/time for the Aeris Elite T3.
Commit d414da70a42afca0096e0402a426c4ac8d2a2881 added support for a
second Aeris Elite T3 variant. But the parser wasn't updated to take
into account this second model number.
2014-06-25 08:44:36 +02:00
Jef Driesen
368c138858 Fix the gas mixes for a few models.
For the Aeris Manta and Sherwood Insight, the header size should be 16
bytes smaller. Due to this mistake not only two samples were missing,
but also the byte offset for the gas mixes were wrong. This resulted in
invalid gas mixes, with oxygen percentages exceeding 100%.
2014-06-25 08:44:27 +02:00
Jef Driesen
48e73babd6 Fix the temperature for the Sherwood Wisdom 2.
The sign bit should be reversed for this model.
2014-06-20 22:22:41 +02:00
Jef Driesen
f8081f1e1f Merge branch 'gasmix' 2014-06-19 09:01:14 +02:00
Jef Driesen
f20f28e9d0 Ignore disabled gas mixes.
For the older models, gas mixes are disabled by setting their oxygen
percentage byte to 0x00 or 0xFF. Trying to parse such a byte as a valid
percentage results in an invalid gas mix.

Because the device doesn't allow you to enable a gas mix if the previous
gas mix has already been disabled, we can simply stop parsing the gas
mixes once the first disabled gas mix has been found.
2014-06-19 08:58:51 +02:00
Jef Driesen
86e9c3dfd3 Cache the initial gas mix.
The gas mode should not only be taken into account for parsing the gas
mix definitions, but also for the initial gas mix. Because the logic
needs to be kept in sync, it's convenient to have all related code in a
single place, and cache the value.
2014-06-17 21:05:23 +02:00
Jef Driesen
28135bc57a Apply the gas mode immediately.
Because the gas mode takes precedence over the individual gas mix
definitions, we can simplify the code by taking the gas mode into
account immediately when parsing the gas mixes.
2014-06-17 21:05:23 +02:00
Jef Driesen
e0e6460372 Merge branch 'dx' 2014-06-17 21:04:50 +02:00
Jef Driesen
bb2b64f5d7 Fix the length of the Suunto DX gas change event.
The Suunto DX uses 5 bytes for the 0x06 gas change event.
2014-06-17 21:03:55 +02:00
Jef Driesen
8a5bfc390d Remove the percentage variable.
There is already another variable for the O2 percentage, so re-use that
one instead.
2014-06-17 21:03:55 +02:00
Jef Driesen
e263a1c336 Improve the warning and error messages. 2014-06-17 21:03:55 +02:00
Jef Driesen
ffd1d1c8b6 Disable the gas mixes in gauge mode. 2014-06-12 08:31:19 +02:00
Cristian Ionescu-Idbohrn
1d6c933415 Another gitignore update.
Signed-off-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
2014-06-11 15:25:24 +02:00
Jef Driesen
8eebc0abd8 Add support for the Beuchat Voyager 2G. 2014-06-07 10:08:04 +02:00
Jef Driesen
20c874b267 Use higher resolution timestamps on Windows.
In commit 886884ab606def1183d99eca7dec8affefee635e, the custom log
function in the example applications has already been modified to use
high resolution timestamps. But I forgot about the built-in default log
function. So this is basically the same change, but now applied to the
built-in log function.
2014-05-28 15:41:21 +02:00
Jef Driesen
2e71075c5b Merge branch 'termios' 2014-05-28 15:40:41 +02:00
Jef Driesen
197b9f0942 Remove the extra check of the termios structure.
The extra memcmp check after the tcsetattr call is intended to verify
whether all the changes to the termios structure have been applied
correctly.

But for pty's, some of the termios settings make no sense at all, and
therefore the Linux kernel always does:

    tty->termios.c_cflag &= ~(CSIZE | PARENB);
    tty->termios.c_cflag |= (CS8 | CREAD);

Thus, instead of ignoring such nonsense termios settings, the kernel
changes the termios structure to reflect what pty's actually do. The
consequence is that these settings will not stick, and cause the memcmp
check to fail.

An example where this affects libdivecomputer, are the two backends that
require odd or even parity (e.g. vyper and iconhd). Here, the kernel
will clear the PARENB flag, and thus cause the memcmp check to fail.

Since this check appears to causes more trouble than it solves, let's
just remove it completely!
2014-05-28 11:11:35 +02:00
Jef Driesen
5f1a18653d Initialize the termios structure.
The previous commit exposed another issue. The termios structure may
contain padding bytes. Because the content of those padding bytes is
unspecified, they may contain some random data, which causes the memcmp
to fail.

Explicitly initializing the termios structure with memset, will also set
the padding bytes to zero.
2014-05-28 11:10:23 +02:00
Venkatesh Shukla
3001dda198 Minor error in serial_configure
Due to a minor mistake, only the first byte was being checked for
equality. Fixed it by changing position of parenthesis.

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
2014-05-20 21:48:57 +02:00
Jef Driesen
48924123a6 Fix a typo in the profile ringbuffer start address.
The profile ringbuffer is supposed to be located after the logbook
ringbuffer, but due a silly typo they did overlap with 256 bytes.
2014-05-19 22:57:49 +02:00
Jef Driesen
654a909936 Fix the Mares Puck Pro memory layout descriptor.
The Mares Puck Pro uses the same memory layout as the Nemo Wide 2. See
commit 322227df7f65da8b4a962f3513e0a10b89cbe29d for more details.
2014-05-19 08:40:10 +02:00
Jef Driesen
1872b71dad Add support for ascent rate warnings.
The Cressi Leonardo does store an indicator for the ascent rate (e.g.
the number of arrows) in the upper two bits. This results in 4 possible
values, ranging from 0 to 3, with the following interpretation:

    0.0 -  3.9 m/min  No signal
    4.0 -  7.9 m/min  1 Arrow
    8.0 - 11.9 m/min  2 Arrows
   12.0+       m/min  3 Arrows (with STOP icon)

Reported-By: Nick Shore <support@mac-dive.com>
2014-05-13 10:35:06 +02:00
Jef Driesen
61e9847196 Merge branch 'ostc' 2014-05-06 22:16:59 +02:00
Jef Driesen
b7a5394e73 Add support for the new OSTC3 bailout event.
With the exception of the different event mask (single byte 0x80 vs two
byte 0x0100), the OSTC3 bailout event is identical to the OSTC2 variant.
Just as before, the new bailout event is reported to the application as
a normal gas change event.
2014-05-06 11:25:46 +02:00
Jef Driesen
4db8535e39 Use the extended sample length stored in the data.
Currently, the buffer overflow checks take into account the size of the
entire dive. But since the length of the extended sample is stored in
the data, we can actually check for overflows in each sample. The main
benefit is that errors will be caught much earlier now.

An additional advantage is that we can now easily skip any remaining
sample bytes. Normally such bytes are not present, unless a firmware
update introduces a new feature which our parser doesn't support yet.
2014-05-06 11:25:46 +02:00
Jef Driesen
5abad6e568 Add more error messages.
This makes debugging easier, because the error messages immediately
reveal where the problem is located, without needing a debugger.
2014-05-06 09:07:13 +02:00
Jef Driesen
466fb0ff6b Add more buffer overflow checks.
There are a few places left, where the contents of the buffer is
accessed without first inspecting the available length.
2014-05-06 09:03:26 +02:00
Jef Driesen
322227df7f Fix the Mares Nemo Wide 2 memory layout descriptor.
The Mares Nemo Wide 2 appears to have a slightly larger profile
ringbuffer, which extends to the end of the internal memory. It remains
to be seen whether this is also true for some of the other models. The
Mares Matrix is currently the only model where this is definitely not
the case.
2014-04-22 14:29:58 +02:00
Jef Driesen
b4cc491aee Add support for the Aeris A300. 2014-04-22 14:29:58 +02:00
Jef Driesen
80d34414a2 Merge branch 'hollistx1' 2014-04-22 14:29:01 +02:00
Jef Driesen
148f059bcb Add support for the Hollis TX1.
The Hollis TX1 has several new features compared to the other models. It
supports trimix and up to 6 different gas mixes can be configured. It
also has twice the amount of memory, which requires an extra bit for the
ringbuffer pointers.
2014-04-22 14:28:27 +02:00
Jef Driesen
3c99f55b6f Add support for trimix gas mixes. 2014-04-22 11:33:53 +02:00
Jef Driesen
c74118a922 Fix the initial gas mix for the D4i, D6i and D9tx.
The initial gas mix index has been confirmed for the D6i only. For the
other two models, it's an educated guess that the byte offset will be
identical.
2014-04-15 13:57:43 +02:00
Jef Driesen
6b912f4f7b Fix the detection of the last valid dive.
Normally, the last valid dive is followed by an empty entry with all
0xFF bytes. However, we received data from a device where a few of those
bytes are not equal to 0xFF. This causes the entry to be processed
incorrectly as a valid dive.

As a workaround, we now check the internal dive number for 0xFFFF.
2014-04-07 11:05:14 +02:00
Jef Driesen
eb12a0aa20 Remove an infinite loop.
If an unknown type byte is encountered, the offset isn't incremented,
resulting in an infinite loop. We now return an error instead.
2014-03-31 11:26:51 +02:00
Jef Driesen
1d7c79b635 Add support for the Atomic Aquatics Cobalt 2. 2014-03-30 23:09:45 +02:00
Anton Lundin
6d4893a146 Fix building for Android
This makes libdivecomputer build via Android NDK. Its currently unusable
due to the fact that Android usually doesn't provide any kernel serial
drivers.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-03-28 12:38:24 +01:00
Jef Driesen
5086b1781c Reduce the timeout to one second.
A packet usually takes only a few milliseconds to transfer, so one
second is still plenty of margin.
2014-03-28 10:08:22 +01:00
Jef Driesen
f0faebb3a1 Introduce an adaptive inter packet delay.
On some systems a small delay is required between receiving the response
of a packet and sending the request for the next packet. Without this
delay, almost every request fails with either a NAK or a timeout.
Retrying usually works, but also causes the download to slow down
considerable.

The root of the problem appears to be related to the FTDI low latency
setting. On Windows and Mac OS X systems, the default setting for the
latency is 16ms, while Linux defaults to a low latency setting of only
1ms. This higher latency on Windows and Mac automatically introduces a
small delay while reading the packet, and that probably happens to be
just enough to make the transfer succeed without any problems. But on
Linux, due to the low latency setting, the next request is send almost
immediately, and that causes the transfer to fail. I suspect the dive
computer may still be busy with the previous request and needs a bit
more time before it's ready to accept a new request.

To mitigate this problem, we introduce a adaptive inter packet delay.
Initially this adaptive delay is set to zero. This is to make sure we
don't affect those systems that don't need a delay at all. Now, every
time a packet fails, that's an indication the inter packet delay is too
small, and we slightly increase the value. After a few attempts we'll
automatically reach the minimal required value. To avoid that the delay
grows out of control in the case of serious trouble, it's limited at
16ms.

Note that the fixed 100ms delay before retrying a failed packet remains
in place. That's on purpose, to make sure the next attempt will always
be successful, regardless of whether the adaptive delay has already
reached its minimal value or not.
2014-03-28 10:08:13 +01:00
Jef Driesen
bfeab10515 Add support for modifying the receive latency.
Currently this isn't used or needed anywhere, but the research has been
done, and it would be silly to drop the knowledge. We may need it in the
future.
2014-03-28 09:39:26 +01:00
Jef Driesen
fa90009c29 Merge branch 'suunto' 2014-03-22 10:22:15 +01:00
Jef Driesen
ede9469316 Report the initial gas mix.
The Suunto dive computers record gas change events in the profile data.
But because there is no gas change event stored on the first sample, the
application doesn't know which gas mix is in use, until the very first
gas change event occurs.

For the Suunto HelO2, the index of the initial gas mix is stored in the
dive header. This is most likely also the case for the other models, but
I haven't found yet where exactly it is stored. As a temporary solution,
we simply assume the initial gas mix is the first gas in the list with
available gas mixes. This should be a reasonable assumption for most
dives.

Fixes ticket #2
2014-03-22 10:21:25 +01:00
Jef Driesen
d8ccfd928b Cache the gas mix data internally.
The gas mix data is used from multiple functions, and the code to parse
that data is duplicated in each function. Because this is error prone,
the code is moved to a single place, and the data cached in the parser.
2014-03-22 10:21:07 +01:00
Florian Klink
fc008312b5 Remove trailing whitespaces
Most of them appear in the disclaimers, but some are in the code as
well.
2014-03-19 09:16:07 +01:00
Janice McLaughlin
f923ec3889 Fix the gas mixes for the Oceanic OCi.
The Oceanic OCi supports 4 gas mixes instead of just 3, and they are
stored at a different offset.
2014-03-14 09:48:35 +01:00
Jef Driesen
db79a63c0d Fix a typo in the format string. 2014-03-14 09:44:10 +01:00
Jef Driesen
886884ab60 Use higher resolution timestamps on Windows.
The resolution of the GetTickCount function is limited to the resolution
of the system timer, which is typically in the range of 10 to 16
milliseconds. This is unsufficient for measuring very short time
intervals in the milliseconds range. The QueryPerformanceCounter
function provides much higher resolution timestamps. We already use it
for the half-duplex workaround.
2014-03-13 15:49:15 +01:00
Jef Driesen
c9202454bb Merge branch 'uwatec' 2014-03-09 23:05:22 +01:00
Jef Driesen
861b5652e0 Add support for parsing gas changes.
Parsing the gas switch events is somewhat complicated, because depending
on the actual model, they can be stored in different ways.

The table below lists the number of gas mixes (G), tanks (T) and alarm
bytes (A) supported by each model. Note that only the representative
model in each group is listed.

  Model         | G | T | A
  ==============|===|===|===
  Pro           | 1 | 0 | 1
  Com           | 1 | 1 | 1
  Tec           | 3 | 3 | 1
  Aladin Tec    | 1 | 0 | 2
  Aladin Tec 2G | 3 | 0 | 2
  Galileo       | 3 | 3 | 3

Models without support for multiple gasmixes only need to set the
initial gas mix correctly. Models with support for one or more tank
pressure sensors can link the gas switches to the tank switches. Models
with at least two alarm bytes can store a gas switch event in the second
alarm byte.

As can be observed from the table, some models can use several different
methods to store the gas switches. The current implementation supports
all of them. In the case of a conflict, the last used method always
takes precedence. That's simply due to the fact that each method just
sets the gasmix index, and only the final value is used. If this
approach turns out to produce wrong results, it can always be fixed
later.

The initial gasmix is always assumed to be the first configured gasmix.
2014-03-09 12:57:52 +01:00
Jef Driesen
68f97e907a Use only one byte for the oxygen percentage.
One byte is already more than sufficient to store an oxygen percentage.
Using two bytes doesn't cause any problems for some models, because the
upper byte is always zero, but for other models that's not the case.
Most likely this upper byte is used to store something else.
2014-03-09 12:57:52 +01:00
Jef Driesen
48661ce7a8 Fix the gasmix offset for the Aladin Tec 2G. 2014-03-09 12:57:52 +01:00
Jef Driesen
b9e8fdcb52 Use the same tables for the Uwatec Smart Tec and Z.
Internal, these two models use exactly the same data format. For those
features which are only available on one of the models, the
corresponding data fields are set to their unused values. For example,
the Smart Tec supports up to three gasmixes, while the Smart Z supports
only one gasmix. But although the Smart Z has storage reserved for up to
three gas mixes, only the first one is ever used.
2014-03-09 12:57:52 +01:00
Jef Driesen
3536086015 Check the buffer size before using the data.
For the Galileo Trimix, the header length isn't fixed. The actual length
depends on whether the dive has the trimix setting enabled or not.
Because at this point we're still trying to determine the length of the
header, it hasn't been checked yet and an extra check is necessary.
2014-03-09 12:57:52 +01:00
Jef Driesen
8da80ea0a2 Store the pointers to the tables in the device handle.
Because for selecting the correct header and sample tables (and
associated data) only the model number is necessary, they can easily be
stored inside the device handle. The main benefit is less duplicated
code.
2014-03-09 12:57:52 +01:00
Anton Lundin
575f2e9016 Ignore ostc-fwupdate binary
Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-03-06 10:43:41 +01:00
Jef Driesen
3927be9ced Fix the decoding of the serial number.
The serial number is stored as a plain 32bit integer, and the device
shows the hexadecimal representation. Because a BCD encoding can only
represent the lower digits (0-9) of a hexadecimal number, the upper
digits (A-F) got mangled.

Reported-By: Nick Shore <support@mac-dive.com>
2014-03-06 09:34:53 +01:00
Jef Driesen
0e11bad6c0 Use relative instead of absolute offests.
Although the settings sample will most likely always be located at the
start, it's better to be on the safe side and use an offset relative to
the start of the settings sample.

Reported-By: Nick Shore <support@mac-dive.com>
2014-03-06 08:25:15 +01:00
Jef Driesen
56e2dec726 Add support for configuring the OSTC3 settings.
Starting with firmware v1.23, the OSTC3 settings can be configured
through the USB interface. There are new commands for reading, writing
and restoring the settings to their default values.
2014-03-04 20:10:43 +01:00
Jef Driesen
23658b55c8 Fix a subtle bug in the previous commit.
The workaround in the previous commit has a bug. If after a reset, the
first entry happens to be located near the end of the TOC, then after a
few dives, the TOC will overflow and new entries will be written at the
start of the TOC. But the current algorithm starts scanning the TOC from
the start and abort the scan as soon as an empty entry is found. Thus if
there are less than 256 dives present, those entries near the end will
never be reached.

We now ignore all uninitialized entries, when searching for the most
recent dive. An explicit safety check is added in case dives are
unexpectedly interleaved with empty entries.
2014-03-04 20:10:42 +01:00
Jef Driesen
5d6408ed2f Ignore uninitialized header entries
Normally, the OSTC3 will always start writing dives at the first entry
in the TOC (Table of Contents). Therefore, uninitialized entries can
only be present after the last dive. However due to a minor firmware
bug, resetting the logbook erases the TOC but leaves the internal dive
counter unchanged. The consequence is that the next dive will still be
stored at the corresponding next TOC entry, while all previous TOC
entries have been erased.

As a workaround, we simply ignore uninitialized entries, unless we have
already found at least one dive.
2014-02-27 10:30:47 +01:00
Jef Driesen
db4d35cd3d Increase the internal log buffer.
With the switch to 4K data packets in the Icon HD backend, the internal
log buffer is no longer large enough for hexdumps of these data packets.
A hexdump needs twice the size of the binary data, plus some extra bytes
for the header and the terminating null byte.
2014-02-27 09:56:40 +01:00
Jef Driesen
d395a31378 Merge branch 'mares' 2014-02-21 21:28:19 +01:00
Jef Driesen
9394773cd2 Increase the packet size again for the Icon HD.
The switch from downloading the entire data with a single large packet
to multiple smaller 256 byte packets, resulted in a considerable
performance regression. In one particular case, the difference was a
factor 6.7 slower!

I performed a small tests (using an Icon HD Net Ready) with 256, 1024
and 4096 byte packets, and the total time was respectively 21.0, 11.3
and 6.5 seconds. For a single large packet, the total time is only 5.9
seconds. Thus the difference with a 4096 byte packet is negligible.
2014-02-21 21:22:53 +01:00
Jef Driesen
991d0180d8 Autodetect the model using the version packet.
The model number stored in the main memory isn't always the most
reliable source of information, because there are devices where the
model number has not been filled in properly. Instead, we check the
product name in the version packet against the list with valid names,
and return the corresponding model number.

As an additional advantage, we no longer depend on the model number
supplied by the application for selecting the correct memory layout.
Nevertheless, the model parameter is kept for backwards compatibility.
2014-02-21 21:22:53 +01:00
Jef Driesen
2049bdb836 Remove an unnecessary function. 2014-02-21 21:22:53 +01:00
Jef Driesen
c718abbe06 Use the same packet size for all models.
The recommended packet size is 256 bytes, which matches the maximal
amount of data that can be read back from the internal memory chip.
Larger requests are split by the firmware into multiple blocks of
maximum 256 bytes.

Note that initially, we already used 256 byte packets for the newer
models, but it seems this was accidentally changed to only 64 bytes in
commit ad0e187c0c932121efa50763afc02771633cbd61.

The main benefit of this change is a simplification of the code, because
now there is no longer a difference between the Icon HD and Matrix
variant of the protocol.
2014-02-21 21:22:52 +01:00
Jef Driesen
c93314026c Use the same standard baudrate for all models.
The Mares Icon HD use a processor with integrated USB circuit, which
presents itself to the host system as a CDC-ACM device. Since there is
no external usb-serial chip involved, the baudrate and other serial
line parameters are irrelevant. By choosing the same settings as the
later models, which do use an usb-serial chip, we can completely avoid
the problem of unresponsive devices due to using the wrong baudrate.
2014-02-21 21:22:52 +01:00
Jef Driesen
fcc75e5a37 Merge branch 'leonardo' 2014-02-21 21:22:21 +01:00
Jef Driesen
2064c3d410 Fix the parsing of the serial number.
The serial number appears to be either a 24 or a 16 bit number, but
certainly not a 32bit number. Whether it's 24 or 16 bit is hard to
tell because the data we have available always contains a zero value
in the third byte.
2014-02-19 14:24:52 +01:00
Jef Driesen
f836e6a025 Add support for the Cressi Giotto.
The communication protocol and memory layout of the Cressi Giotto
appears to be identical to that of the Leonardo. The first byte seems
to be the model number, with 0x01 for the Leonardo and 0x04 for the
Giotto.
2014-02-19 14:22:31 +01:00
Jef Driesen
1f086a0f90 Merge branch 'nitektrio' 2014-02-18 19:34:49 +01:00
Jef Driesen
ba77b0ed24 Add support for gas switches. 2014-02-15 16:41:08 +01:00
Jef Driesen
d30b5c65fe Ignore invalid gas mixes.
Gas mixes that have been marked as disabled are stored as the value 0xF0.
When interpreted as an oxygen percentage, this results in an out of range
value. Therefore, these gas mixes should simply be ignored.
2014-02-15 16:41:07 +01:00
Jef Driesen
56aa3b6669 Merge branch 'release-0.4'
Integrate the bugfixes from the stable branch.
2014-02-06 20:31:27 +01:00
Jef Driesen
9f42f6b87d Release version 0.4.2. 2014-02-06 20:22:19 +01:00
Jef Driesen
7b739814d1 Merge branch 'diverite' 2014-02-06 09:48:27 +01:00
Jef Driesen
5ddca0b4f7 Fix a small spelling mistake. 2014-02-06 09:42:06 +01:00
Jef Driesen
3f7af8c349 Add support for the Dive Rite NiTek Q. 2014-02-06 09:42:06 +01:00
Jef Driesen
35003ced81 Add support for the OSTC 2C variant. 2014-01-26 21:51:33 +01:00
Jef Driesen
040679f76a Improve the progress events.
Reading the data packet in multiple smaller chunks greatly improves the
progress events. Instead of just two events, before and after the
download, there are now many intermediate events. This change also
allows to significantly reduce the timeout, from 30 seconds to just one
second, which avoids blocking for too long in case the device doesn't
respond at all.
2014-01-23 09:48:56 +01:00
Jef Driesen
4ae3a4f3ab Remove the infinite timeout.
An infinite timeout causes major problems, because if the device doesn't
respond at all, the read call will block forever. With the eon serial
line settings (1200 8N2), the total time to read the 2305 byte packet is
about 21.129 seconds. A timeout of 30 seconds should be plenty of time.
2014-01-23 09:48:56 +01:00
Jef Driesen
f219de5a55 Merge branch 'msvc' 2014-01-22 20:10:21 +01:00
Jef Driesen
13db9dc8c0 Update the msvc project file. 2014-01-22 20:09:14 +01:00
Jef Driesen
3f9f722219 Always use the ANSI variant of the Windows functions. 2014-01-22 20:02:58 +01:00
Jef Driesen
7b9bd1880c Add explicit casts for the msvc C++ compiler. 2014-01-22 20:02:58 +01:00
Jef Driesen
914e740087 Fix the memory layout for the VT4.x.
The VT4.x memory layout appears to be slightly different from the Atom
3.x memory layout. The logbook ringbuffer does start at offset 0x420
instead of 0x400.
2013-12-23 21:05:52 +01:00
Tim Wootton
459b1574b8 Add iconhd gas change event
Signed-off-by: Tim Wootton <tim@tee-jay.demon.co.uk>
2013-10-27 06:57:18 +01:00
Stephane Bensoussan
4c94460831 Use only 11 bits for the depth.
When using up to 14 bits for the depth, the resulting values are too
large in some cases. Most likely the upper bits are used to store
something else. Even with only 11 bits, the resulting depth range
(0-204.7m) should still be more than sufficient.
2013-10-21 11:41:19 +02:00
Jef Driesen
c524986175 Add support for the Scubapro/Uwatec Meridian.
The Uwatec Meridian protocol is identical to the Uwatec Smart/Galileo
protocol, except for some additional framing around each data packet,
and the switch from IrDA to usb-serial communication. For parsing, the
data format appears to be identical to the Galileo data format.
2013-10-19 10:11:15 +02:00
Jef Driesen
938839e694 Add support for the Scubapro XTender 5.
The XTender 5 is identical to the other models in the Zeagle N2iTiON3
family, and can be added to the list of supported devices without any
further changes.
2013-10-18 20:10:28 +02:00
Tim Wootton
734533e4d1 Fix units for atmospheric pressure for iconhd type
Was returning mbar, should have been bar.

Signed-off-by: Tim Wootton <tim@tee-jay.demon.co.uk>
2013-10-15 11:49:46 +02:00
Tim Wootton
2af365cfb7 Adds support for DC_FIELD_ATMOSPHERIC to the iconhd parser
Signed-off-by: Tim Wootton <tim@tee-jay.demon.co.uk>
2013-10-12 20:33:52 +02:00
Patrick Valsecchi
8edbceaa4d Use the correct vtable for the Shearwater Petrel.
That was an harmless copy&paste error.

Signed-off-by: Patrick Valsecchi <patrick@thus.ch>
2013-10-11 15:41:57 +02:00
Jef Driesen
8e0355c354 Buffer the slip packet before sending.
On Mac OS X, sending the slip packet byte by byte results in an abysmal
performance. The first byte takes up to 160ms to send, and each next
byte approximately 250ms. The packet to request a data block is
typically 7 bytes large, and therefore takes about 1660ms to send.
Because a dive is transmitted as multiple smaller packets (typically
144 bytes without protocol overhead), downloading a single dive can
easily take several seconds.

However, when sending the entire slip packet at once, the time remains
roughly identical to sending just the first byte. The result is that
the time for sending a packet reduces significantly, proportional to
the length of the packet.

Under the hood, the slip packet is now internally buffered, and the
buffer is send only when the entire packet is complete, or whenever the
buffer gets full. But in practice, the buffer is large enough to always
store an entire packet.

In the original bug report, downloading 57 dives took about 40 minutes.
After applying the patch, that time reduced to only 5 minutes!
2013-09-21 11:30:39 +02:00
Jef Driesen
6f7495dd3e Add support for a new Uwatec Aladin 2G variant.
This new variant has a different model number and has switched to the
Uwatec Galileo data format.
2013-09-19 08:56:40 +02:00
Jef Driesen
043fc4166c Add support for the Oceanic OCi.
The new Oceanic OCi appears to be almost identical to the already
supported Oceanic OC1. The most important change is the different
location for the logbook ringbuffer.
2013-09-17 13:06:56 +02:00
Jef Driesen
b96780ce75 Add support for the Sherwood Amphos. 2013-09-16 09:57:34 +02:00
Jef Driesen
85fd0c524f Fix the memory layout descriptors.
The profile ringbuffer appears to be slightly smaller than expected for
some models. For the Mares Matrix (and all compatible devices) it ends
earlier, while for the Icon HD Net Ready it starts later.

This bug resulted in missing dives, because all remaining dives were
getting dropped once a dive that crossed the ringbuffer boundary was
reached.
2013-09-09 15:05:58 +02:00
Jef Driesen
1bfcb8c3c1 Mark the Oceanic Veo 2.0 as a non air integrated model. 2013-09-05 20:41:46 +02:00
Jef Driesen
1331db75cb Fix the memory layout for the Atom 3.x and VT4.x.
The logbook ringbuffer appears to start at offset 0x400 instead of
0x240. Since these ringbuffer boundaries have to be taken taken into
account only once the ringbuffer has been filled completely, this bug
affects users with more than 200 dives only. Thus, no surprise it didn't
get noticed earlier.
2013-09-05 08:21:25 +02:00
Jef Driesen
b35e07b71b Add cancellation support to several backends.
Some backends are technically capable of supporting cancellation, but
still lacked the necessary code to enable it.
2013-09-03 20:13:49 +02:00
Jef Driesen
888b6ab03f Disable the cancellation callback during shutdown.
Several backends require a shutdown command to be send before closing
the connection. If such a command gets cancelled, that might result in
an unclean shutdown. Backends where this is problematic can always
ignore cancellation requests internally, but it's less error-prone (and
much easier) to simply disable the cancellation callback for all
backends, before closing the connection.
2013-09-03 20:09:31 +02:00
Jef Driesen
eb8e615999 Merge branch 'ostc-fwupdate' 2013-08-23 13:44:19 +02:00
Jef Driesen
22a8bc70ea Add a warning to the firmware update code. 2013-08-23 13:42:55 +02:00
Jef Driesen
8e1a8c14a3 Add a small example application. 2013-08-23 13:42:55 +02:00
Jef Driesen
bc89e0a3de Autodetect the bootloader protocol variant.
When updating the firmware while the OSTC is running in normal mode, the
V2 protocol should be used. However, the OSTC can also be rebooted from
the menu or reset using the magnetic switch, and then the V1 protocol
should be used. The only difference with the V2 protocol is the slower
baudrate (19200 vs 115200).

True autodetection of the protocol variant is difficult, because the
bootloader will abort the firmware update when not receiving a 0xC1
byte. But we can still take advantage of the fact that the normal
firmware does ignore any 0xC1 bytes sent at the wrong baudrate, and
probe with the V1 protocol first. If the bootloader is already running,
it will respond immediately and we're done. If the normal firmware is
still running, it won't respond and the probing with the V1 protocol
will fail. If we then switch to the V2 protocol, the firmware update
will continue as before.

The result is a firmware updater which supports both bootloader
protocols without requiring any manual configuration.
2013-08-22 09:15:55 +02:00
Jef Driesen
14286e8236 Add support for updating the HW OSTC firmware.
Only the bootloader V2 protocol is supported for now.
2013-08-22 09:15:55 +02:00
Jef Driesen
222ba81157 Add a parser for Intel HEX files. 2013-08-22 09:15:55 +02:00
Alexander Neumann
37cb54c376 Add Mares Puck 2 dive computer
This dive computer has the same enclosure as the Mares Puck, but the
wire protocol is that of the Puck Pro. The original software identifies
it as a "Mares Puck 2", and the handshake string also contains the
sequence "PUCK 2", so this string is used to identify the device.
2013-08-12 13:11:07 +02:00
Michael Andreen
5f8da384e6 Identify event 0x07 on Suunto d9-style computers as Below Floor.
This event is on when accumulating deco time. Once you reach the floor
deco time will start decreasing and the event will stop. Going below the
floor again will re-activate the event.

Signed-off-by: Michael Andreen <harv@ruin.nu>
2013-08-05 23:02:19 +02:00
Jef Driesen
456365366c Decode the IrDA device address as little endian.
This is only a cosmetic change, to make the IrDA device address on
Windows consistent with the address Linux. There is no functional
difference because the address is always serialized and deserialized
internally, and applications shouldn't care about the actual number.

Anyway, the difference in endianness is easy to notice because the
Uwatec Smart family of devices use the serial number as the IrDA device
address. On Linux, the address was identical to the serial number, while
on Windows the byte order was reversed.
2013-08-05 22:45:48 +02:00
Jef Driesen
3d82c5f9cd Add logging to the IrDA communication. 2013-08-05 22:45:48 +02:00
Jef Driesen
9ce8888e37 Log the device name of the serial port. 2013-08-05 22:42:24 +02:00
Jef Driesen
d44053a994 Add internal support for enumerating serial ports.
For the time being, the serial port enumeration code is of very limited
use. It's not used anywhere in the library, and as an internal api it's
also not available to applications. It serves mainly as a reference
implementation for future use.
2013-08-05 22:40:07 +02:00
Jef Driesen
622363dca8 Add partial support for the Aeris XR-1 NX.
The Aeris XR-1 NX has very limited memory and doesn't have a
logbook and profile ringbuffer. Hence downloading dives isn't
really supported, but even this limited amount of data might be
useful for someone.
2013-07-19 18:20:14 +02:00
Jef Driesen
5c16b28fb9 Use only 12 bits for the temperature.
When using all 16 bits for the temperature, the resulting values are
clearly wrong in some cases. Most likely the upper 4 bits are used to
store something else. Even with only 12 bits, the resulting temperature
range (0-409.5°C) should still be more than sufficient.
2013-07-16 08:46:49 +02:00
Jef Driesen
b4250ef74d Post release version bump to 0.4.2. 2013-07-01 21:44:05 +02:00
Jef Driesen
2d3e707839 Release version 0.4.1. 2013-07-01 21:35:38 +02:00
Jef Driesen
bed4d19aca Add support for the new bailout event.
The new bailout event is reported to the application as a normal gas
change event.
2013-06-19 10:39:10 +02:00
Jef Driesen
b1574848b2 Interpret the 7th bit of the event byte correctly.
In the OSTC3 data format, the 7th bit of the event byte is used to
indicate whether another event byte is present or not. For the OSTC2,
this 7th bit remained unused, and I assumed it would eventually get used
in the same way as the OSTC3 does. But that assumption turns out to be
wrong. Starting with firmware v2.66 the 7th bit is used for a new
bailout event.

This patch leaves the existing logic intact, but except for the OSTC3
format (version 0x23), the maximum number of events bytes is now limited
to just one byte.
2013-06-19 10:34:02 +02:00
Jef Driesen
6ad8d61253 Fix the date/time for the Oceanic Geo 2.0. 2013-06-15 07:58:59 +02:00
Jef Driesen
d7c59dff58 Adjust the length based on the firmware version.
The OSTC 3 dataformat does contain the profile length twice: once in the
main 256 byte header, and again in the small profile header. However due
to a firmware bug, both values are not identical. The value in the main
header is wrong and 3 bytes larger than the value in the small profile
header. This bug was fixed in firmware version 0.93.

Unfortunately we rely on the length in the main header to calculate the
number of bytes to read when downloading the dive. The consequence is
that for all dives recorded with firmware 0.93 or later, the length is
calculated incorrectly, and the download fails. Luckily the firmware
version is stored in the main header too, and we can adjust the length
calculation accordingly.
2013-05-30 20:52:57 +02:00
Jef Driesen
9b65159a57 Mark the dc_datetime_mktime parameter as const.
Unlike the corresponding mktime C library function, the libdivecomputer
function will never modify its argument. By marking the parameter as
const this is made more explicit.
2013-05-23 14:17:41 +02:00
Jef Driesen
890f5f0b5b Fix the temperature for the Aeris Atmos AI 2.
The temperature sign bit is reversed for this model.
2013-05-16 20:16:03 +02:00
Jef Driesen
d8bc4910b7 Post release version bump to 0.4.1. 2013-05-16 19:39:24 +02:00
Jef Driesen
3c8ea2c33c Post release version bump to 0.5.0. 2013-05-13 23:54:14 +02:00
344 changed files with 56680 additions and 13042 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@v4
- 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@v4
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@v4
- 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@v4
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@v4
- 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@v4
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@v4
- 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@v2
- run: msbuild -m -p:Platform=${{ matrix.platform }} -p:Configuration=${{ env.CONFIGURATION }} contrib/msvc/libdivecomputer.vcxproj
- uses: actions/upload-artifact@v4
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@v4
- 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@v4
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@v4
- 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 }}

37
.gitignore vendored
View File

@ -8,6 +8,7 @@
.*.swp
.deps/
.libs/
compile
Makefile
Makefile.in
@ -31,31 +32,12 @@ Makefile.in
/stamp-h1
/tags
/examples/aladin
/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/predator
/examples/puck
/examples/sensus
/examples/sensuspro
/examples/sensusultra
/examples/smart
/examples/solution
/examples/universal
/examples/veo250
/examples/vtpro
/examples/vyper
/examples/vyper2
/doc/doxygen
/doc/doxygen.cfg
/doc/html/
/doc/latex/
/examples/dctool
/include/libdivecomputer/version.h
@ -65,11 +47,10 @@ Makefile.in
/m4/ltsugar.m4
/m4/ltversion.m4
/msvc/Debug/
/msvc/Release/
/msvc/x64/
/msvc/x86/
/msvc/*.ncb
/msvc/*.suo
/msvc/*.vcproj.*.user
/src/libdivecomputer.exp
/src/libdivecomputer.la

55
.travis.yml Normal file
View File

@ -0,0 +1,55 @@
language: c
matrix:
include:
- os: linux
compiler: gcc
- os: linux
compiler: clang
- os: osx
compiler: gcc
- os: osx
compiler: clang
- os: linux
compiler: i686-w64-mingw32-gcc
addons:
apt:
packages:
- gcc-mingw-w64
- binutils-mingw-w64
- mingw-w64-tools
- os: linux
compiler: x86_64-w64-mingw32-gcc
addons:
apt:
packages:
- gcc-mingw-w64
- binutils-mingw-w64
- mingw-w64-tools
addons:
apt:
packages:
- libbluetooth-dev
- libusb-1.0-0-dev
homebrew:
packages:
- hidapi
- libusb
script:
- case $CC in
*-gcc) TARGET="${CC%-gcc}" ;;
esac
- if [ -n "$TARGET" ]; then
TARGETOPTS="--host=${TARGET}";
unset CC;
fi
- autoreconf --install --force
- ./configure $TARGETOPTS --disable-doc
- make

View File

@ -146,7 +146,7 @@ such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an

View File

@ -1,5 +1,14 @@
SUBDIRS = include src examples
SUBDIRS = include src
if ENABLE_EXAMPLES
SUBDIRS += examples
endif
if ENABLE_DOC
SUBDIRS += doc
endif
AM_MAKEFLAGS = -s
ACLOCAL_AMFLAGS = -I m4
pkgconfigdir = $(libdir)/pkgconfig
@ -7,4 +16,8 @@ pkgconfig_DATA = libdivecomputer.pc
EXTRA_DIST = \
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

162
NEWS
View File

@ -1,3 +1,165 @@
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)
==========================
The v0.6.0 release adds support for several new devices, introduces two
new features and fixes a couple of bugs. There are a few minor backwards
incompatible changes, but most applications won't be affected by those.
New features:
* Add support for new backends:
- g2: Scubapro G2, Aladin Sport Matrix, Aladin Square
* Add support for many new devices:
- Aqualung: i200, i750TC
- Cochran: Commander I, II and TM
- Cressi: Drake
- Hollis: DG02
- Mares: Quad
- Oceanic: F10
- Ratio: iX3M and iDive series
- Suunto: D4f, Eon Core
- Uwatec: Aladin Tec 3G
* Add basic timezone support
* Add support for synchronizing the device clock
* Document the public api with man pages
Removed/changed features:
* Remove the deprecated gas change events
* Remove the deprecated vendor_product_parser_create(),
vendor_product_device_open() and vendor_product_extract_dives()
functions from the public api
* Remove the hw_{frog,ostc,ostc3}_device_clock() functions
Bug fixes:
* Many small improvements
Version 0.5.0 (2016-09-30)
==========================
After more than three years of development, the v0.5.0 release is long
overdue. The main highlights are the support for many new devices, a few
new features and lots of bug fixes. This release is fully backwards
compatible with the previous one.
New features:
* Add support for new backends:
- aqualand: Citizen Hyper Aqualand
- commander: Cochran Commander and EMC
- eonsteel: Suunto EON Steel
- idive: DiveSystem iDive and iX3M
- meridian: Scubapro Meridian, Mantis and Chromis
- nitekq: Dive Rite NiTek Q
* Add support for many new devices:
- Aeris: 500 AI, A300, A300CS, F11, XR-1 NX
- Aqualung: i300, i450T, i550T
- Beuchat: Mundial 2, Mundial 3, Voyager 2G
- Cressi: Giotto, Newton
- Dive Rite: NiTek Trio
- Heinrichs Weikamp: OSTC 2, 3+, 4, cR and Sport
- Hollis: TX1
- Mares: Airlab, Smart, Smart Apnea, Puck 2
- Oceanic: F11, OCi, VTX
- Scubapro: XTender 5
- Shearwater: Nerd, Perdix, Petrel 2
- Sherwood: Amphos, Amphos Air, Vision
- Subgear: XP-3G, XP-Air
- Suunto: Vyper Novo, Zoop Novo
- Tusa: IQ-700
- Uwatec: Aladin 2G, Aladin Sport
* Add a new sample with the active gas mix.
* Add the temperature, tank and divemode fields.
* Add support for updating the OSTC and OSTC3 firmware.
* Add support for configuring the OSTC3 settings.
* Add a new dc_parser_new2 convenience function.
Removed/changed features:
* The gas change events (SAMPLE_EVENT_GASCHANGE and
SAMPLE_EVENT_GASCHANGE2) have been replaced with the new gasmix
sample (DC_SAMPLE_GASMIX). The legacy events are considered
deprecated, but kept for backwards compatibility.
Bug fixes:
* Many small improvements
Version 0.4.0 (2013-05-13)
==========================

View File

@ -1,8 +1,8 @@
# Versioning.
m4_define([dc_version_major],[0])
m4_define([dc_version_minor],[4])
m4_define([dc_version_minor],[9])
m4_define([dc_version_micro],[0])
m4_define([dc_version_suffix],[])
m4_define([dc_version_suffix],[devel])
m4_define([dc_version],dc_version_major.dc_version_minor.dc_version_micro[]m4_ifset([dc_version_suffix],-[dc_version_suffix]))
# Libtool versioning.
@ -46,41 +46,106 @@ AS_IF([test "x$enable_pty" = "xyes"], [
AC_DEFINE(ENABLE_PTY, [1], [Enable pseudo terminal support.])
])
# Example applications.
AC_ARG_ENABLE([examples],
[AS_HELP_STRING([--enable-examples=@<:@yes/no@:>@],
[Build example applications @<:@default=yes@:>@])],
[], [enable_examples=yes])
AM_CONDITIONAL([ENABLE_EXAMPLES], [test "x$enable_examples" = "xyes"])
# Documentation.
AC_ARG_ENABLE([doc],
[AS_HELP_STRING([--enable-doc=@<:@yes/no@:>@],
[Build documentation @<:@default=yes@:>@])],
[], [enable_doc=yes])
AM_CONDITIONAL([ENABLE_DOC], [test "x$enable_doc" = "xyes"])
# Checks for programs.
AC_PROG_CC
AC_PROG_CC_C99
AC_CHECK_PROGS([DOXYGEN], [doxygen])
AC_CHECK_PROGS([MANDOC], [mandoc])
AM_CONDITIONAL([HAVE_DOXYGEN],[test -n "$DOXYGEN"])
AM_CONDITIONAL([HAVE_MANDOC],[test -n "$MANDOC"])
# Enable automake silent build rules.
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
# Checks for native Windows.
AC_MSG_CHECKING([for native Win32])
# Checks for operating system.
AC_MSG_CHECKING([for operating system])
case "$host" in
*-*-mingw*)
os_win32=yes
platform=windows
;;
*-*-darwin*)
platform=mac
;;
*)
os_win32=no
platform=default
;;
esac
AC_MSG_RESULT([$os_win32])
AM_CONDITIONAL([OS_WIN32], [test "$os_win32" = "yes"])
AC_MSG_RESULT([$platform])
AM_CONDITIONAL([OS_WIN32], [test "$platform" = "windows"])
DEPENDENCIES=""
# Checks for USB support.
PKG_CHECK_MODULES([LIBUSB], [libusb-1.0], [have_libusb=yes], [have_libusb=no])
if test "$have_libusb" = "yes"; then
AC_DEFINE([HAVE_LIBUSB], [1], [libusb support])
AC_SUBST([DEPENDENCIES], [libusb-1.0])
fi
AC_ARG_WITH([libusb],
[AS_HELP_STRING([--without-libusb],
[Build without the libusb library])],
[], [with_libusb=auto])
AS_IF([test "x$with_libusb" != "xno"], [
PKG_CHECK_MODULES([LIBUSB], [libusb-1.0], [have_libusb=yes], [have_libusb=no])
AS_IF([test "x$have_libusb" = "xyes"], [
AC_DEFINE([HAVE_LIBUSB], [1], [libusb library])
DEPENDENCIES="$DEPENDENCIES libusb-1.0"
])
])
# Checks for IrDA support.
AC_CHECK_HEADERS([winsock2.h af_irda.h], [irda_win32=yes], [irda_win32=no], [
# Checks for HIDAPI support.
AC_ARG_WITH([hidapi],
[AS_HELP_STRING([--without-hidapi],
[Build without the hidapi library])],
[], [with_hidapi=hidapi])
AS_IF([test "x$with_hidapi" != "xno"], [
PKG_CHECK_MODULES([HIDAPI], [$with_hidapi], [have_hidapi=yes], [have_hidapi=no])
AS_IF([test "x$have_hidapi" = "xyes"], [
AC_DEFINE([HAVE_HIDAPI], [1], [hidapi library])
DEPENDENCIES="$DEPENDENCIES $with_hidapi"
])
])
# Checks for BlueZ (bluetooth) support.
AC_ARG_WITH([bluez],
[AS_HELP_STRING([--without-bluez],
[Build without the BlueZ library])],
[], [with_bluez=auto])
AS_IF([test "x$with_bluez" != "xno"], [
PKG_CHECK_MODULES([BLUEZ], [bluez], [have_bluez=yes], [have_bluez=no])
AS_IF([test "x$have_bluez" = "xyes"], [
AC_DEFINE([HAVE_BLUEZ], [1], [BlueZ library])
DEPENDENCIES="$DEPENDENCIES bluez"
])
])
AC_SUBST([DEPENDENCIES])
# Checks for Windows bluetooth support.
AC_CHECK_HEADERS([winsock2.h ws2bth.h], , , [
#if HAVE_WINSOCK2_H
# include <winsock2.h>
# endif
])
AC_CHECK_HEADERS([sys/socket.h linux/types.h linux/irda.h], [irda_linux=yes], [irda_linux=no], [
# Checks for IrDA support.
AC_CHECK_HEADERS([winsock2.h af_irda.h], , , [
#if HAVE_WINSOCK2_H
# include <winsock2.h>
# endif
])
AC_CHECK_HEADERS([sys/socket.h linux/types.h linux/irda.h], , , [
#if HAVE_SYS_SOCKET_H
# include <sys/socket.h>
# endif
@ -89,19 +154,51 @@ AC_CHECK_HEADERS([sys/socket.h linux/types.h linux/irda.h], [irda_linux=yes], [i
# endif
])
if test "$irda_win32" = "yes" || test "$irda_linux" = "yes"; then
AC_DEFINE([HAVE_IRDA], [1], [IrDA support])
fi
AM_CONDITIONAL([IRDA], [test "$irda_win32" = "yes" || test "$irda_linux" = "yes"])
# Checks for header files.
AC_CHECK_HEADERS([linux/serial.h])
AC_CHECK_HEADERS([IOKit/serial/ioss.h])
AC_CHECK_HEADERS([unistd.h getopt.h])
AC_CHECK_HEADERS([sys/param.h])
AC_CHECK_HEADERS([pthread.h])
AC_CHECK_HEADERS([mach/mach_time.h])
# Checks for global variable declarations.
AC_CHECK_DECLS([optreset])
# Checks for structures.
AC_CHECK_MEMBERS([struct tm.tm_gmtoff],,,[
#include <time.h>
])
# Checks for library functions.
AC_FUNC_STRERROR_R
AC_CHECK_FUNCS([localtime_r gmtime_r])
AC_CHECK_FUNCS([localtime_r gmtime_r timegm _mkgmtime])
AC_CHECK_FUNCS([clock_gettime mach_absolute_time])
AC_CHECK_FUNCS([getopt_long])
# Checks for supported compiler options.
AX_APPEND_COMPILE_FLAGS([-Werror=unknown-warning-option],[ERROR_CFLAGS])
AX_APPEND_COMPILE_FLAGS([ \
-pedantic \
-Wall \
-Wextra \
-Wshadow \
-Wrestrict \
-Wformat=2 \
-Wwrite-strings \
-Wcast-qual \
-Wpointer-arith \
-Wstrict-prototypes \
-Wmissing-prototypes \
-Wmissing-declarations \
-Wno-unused-parameter \
-fmacro-prefix-map='$(top_srcdir)/'= \
],,[$ERROR_CFLAGS])
# Windows specific compiler options.
AS_IF([test "$platform" = "windows"], [
AX_APPEND_COMPILE_FLAGS([-Wno-pedantic-ms-format])
])
# Versioning.
AC_SUBST([DC_VERSION],[dc_version])
@ -115,6 +212,25 @@ m4_ifset([dc_version_suffix],[
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([
libdivecomputer.pc
Makefile
@ -122,7 +238,41 @@ AC_CONFIG_FILES([
include/libdivecomputer/Makefile
include/libdivecomputer/version.h
src/Makefile
src/libdivecomputer.rc
doc/Makefile
doc/doxygen.cfg
doc/man/Makefile
examples/Makefile
])
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.

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

@ -0,0 +1,144 @@
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
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

@ -0,0 +1,35 @@
# Atomic Aquatics Cobalt
SUBSYSTEM=="usb", ATTR{idVendor}=="0471", ATTR{idProduct}=="0888", GROUP="plugdev"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="0471", ATTRS{idProduct}=="0888", GROUP="plugdev"
# Suunto EON Steel
SUBSYSTEM=="usb", ATTR{idVendor}=="1493", ATTR{idProduct}=="0030", GROUP="plugdev"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="1493", ATTRS{idProduct}=="0030", GROUP="plugdev"
# Suunto EON Core
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
SUBSYSTEM=="usb", ATTR{idVendor}=="2e6c", ATTR{idProduct}=="3201", GROUP="plugdev"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="2e6c", ATTRS{idProduct}=="3201", GROUP="plugdev"
# Scubapro G2 Console
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
SUBSYSTEM=="usb", ATTR{idVendor}=="c251", ATTR{idProduct}=="2006", GROUP="plugdev"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="c251", ATTRS{idProduct}=="2006", GROUP="plugdev"

14
doc/Makefile.am Normal file
View File

@ -0,0 +1,14 @@
SUBDIRS = man
doxygen: doxygen.cfg
if HAVE_DOXYGEN
$(DOXYGEN) $(DOXYFLAGS) $<
touch $@
endif
all-local: doxygen
clean-local:
-$(RM) -rf html latex
CLEANFILES = doxygen

2427
doc/doxygen.cfg.in Normal file

File diff suppressed because it is too large Load Diff

72
doc/man/Makefile.am Normal file
View File

@ -0,0 +1,72 @@
MANPAGES = \
dc_buffer_append.3 \
dc_buffer_free.3 \
dc_buffer_get_data.3 \
dc_buffer_get_size.3 \
dc_buffer_new.3 \
dc_buffer_prepend.3 \
dc_context_free.3 \
dc_context_new.3 \
dc_context_set_logfunc.3 \
dc_context_set_loglevel.3 \
dc_datetime_gmtime.3 \
dc_datetime_localtime.3 \
dc_datetime_mktime.3 \
dc_datetime_now.3 \
dc_descriptor_free.3 \
dc_descriptor_get_model.3 \
dc_descriptor_get_product.3 \
dc_descriptor_get_vendor.3 \
dc_descriptor_get_transports.3 \
dc_descriptor_iterator.3 \
dc_device_close.3 \
dc_device_foreach.3 \
dc_device_open.3 \
dc_device_set_cancel.3 \
dc_device_set_events.3 \
dc_device_set_fingerprint.3 \
dc_iterator_free.3 \
dc_iterator_next.3 \
dc_parser_destroy.3 \
dc_parser_get_datetime.3 \
dc_parser_get_field.3 \
dc_parser_new.3 \
dc_parser_samples_foreach.3 \
dc_bluetooth_open.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)
dist_man_MANS = $(MANPAGES)
if HAVE_MANDOC
doc_DATA = $(HTMLPAGES)
endif
SUFFIXES = .3 .3.html
.3.3.html:
$(AM_V_GEN) $(MANDOC) -Thtml -Ostyle=mandoc.css,man=%N.%S.html $< > $@
CLEANFILES = $(HTMLPAGES)

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

@ -0,0 +1,61 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_BUFFER_APPEND 3
.Os
.Sh NAME
.Nm dc_buffer_append
.Nd append to a binary buffer
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/buffer.h
.Ft int
.Fo dc_buffer_append
.Fa "dc_buffer_t *buffer"
.Fa "const unsigned char data[]"
.Fa "size_t size"
.Fc
.Sh DESCRIPTION
Append
.Fa size
bytes of
.Fa data
into the
.Fa buffer
previously allocated with
.Xr dc_buffer_new 3 .
.Sh RETURN VALUES
Returns non-zero on success or zero on memory exhaustion or if
.Fa buffer
is
.Dv NULL .
.Sh SEE ALSO
.Xr dc_buffer_new 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

51
doc/man/dc_buffer_free.3 Normal file
View File

@ -0,0 +1,51 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_BUFFER_FREE 3
.Os
.Sh NAME
.Nm dc_buffer_free
.Nd free an resizable binary buffer
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/buffer.h
.Ft void
.Fo dc_buffer_free
.Fa "dc_buffer_t *buffer"
.Fc
.Sh DESCRIPTION
Frees a resizable binary buffer created with
.Xr dc_buffer_new 3 .
It's safe to pass
.Dv NULL
to this function.
.Sh SEE ALSO
.Xr dc_buffer_new 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,64 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_BUFFER_GET_DATA 3
.Os
.Sh NAME
.Nm dc_buffer_get_data
.Nd get the data of a buffer
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/buffer.h
.Ft "unsigned char *"
.Fo dc_buffer_get_data
.Fa "dc_buffer_t *buffer"
.Fc
.Sh DESCRIPTION
Get the data used by
.Fa buffer ,
previously allocated with
.Xr dc_buffer_new 3 .
For the buffer size, use
.Xr dc_buffer_get_size 3 .
.Pp
The returned pointer is not valid after subsequent calls to change the
buffer.
.Sh RETURN VALUES
Returns the data or
.Dv NULL
if
.Fa buffer
is
.Dv NULL
or no data has been allocated to the buffer.
.Sh SEE ALSO
.Xr dc_buffer_get_size 3 ,
.Xr dc_buffer_new 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,59 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_BUFFER_GET_SIZE 3
.Os
.Sh NAME
.Nm dc_buffer_get_size
.Nd get the size used by a buffer
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/buffer.h
.Ft size_t
.Fo dc_buffer_get_size
.Fa "dc_buffer_t *buffer"
.Fc
.Sh DESCRIPTION
Get the number of bytes currently used by
.Fa buffer ,
previously allocated with
.Xr dc_buffer_new 3 .
This shouldn't be confused with the capacity, which may be larger.
.Pp
The returned value is not valid after subsequent calls to change the
buffer.
.Sh RETURN VALUES
Returns the number of bytes used, which may be zero, or zero if
.Fa buffer
is
.Dv NULL .
.Sh SEE ALSO
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .
.Xr dc_buffer_new 3

57
doc/man/dc_buffer_new.3 Normal file
View File

@ -0,0 +1,57 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_BUFFER_NEW 3
.Os
.Sh NAME
.Nm dc_buffer_new
.Nd create an resizable binary buffer
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/buffer.h
.Ft "dc_buffer_t *"
.Fo dc_buffer_new
.Fa "size_t capacity"
.Fc
.Sh DESCRIPTION
Create a resizable binary buffer of initial size
.Fa capacity ,
which may be zero.
The created buffer must be freed with
.Xr dc_buffer_free 3 .
.Sh RETURN VALUES
Returns a pointer to a
.Vt dc_buffer_t
or
.Dv NULL
on memory exhaustion.
.Sh SEE ALSO
.Xr dc_buffer_free 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,61 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_BUFFER_PREPEND 3
.Os
.Sh NAME
.Nm dc_buffer_prepend
.Nd prepend to a binary buffer
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/buffer.h
.Ft int
.Fo dc_buffer_prepend
.Fa "dc_buffer_t *buffer"
.Fa "const unsigned char data[]"
.Fa "size_t size"
.Fc
.Sh DESCRIPTION
Prepend
.Fa size
bytes of
.Fa data
to the beginning of
.Fa buffer
previously allocated with
.Xr dc_buffer_new 3 .
.Sh RETURN VALUES
Returns non-zero on success or zero on memory exhaustion or if
.Fa buffer
is
.Dv NULL .
.Sh SEE ALSO
.Xr dc_buffer_new 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

54
doc/man/dc_context_free.3 Normal file
View File

@ -0,0 +1,54 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_CONTEXT_FREE 3
.Os
.Sh NAME
.Nm dc_context_free
.Nd free a device-handling context
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/context.h
.Ft dc_status_t
.Fo dc_context_free
.Fa "dc_context_t *context"
.Fc
.Sh DESCRIPTION
Free a context created by
.Xr dc_context_new 3 .
.Sh RETURN VALUES
This returns
.Dv DC_STATUS_OK
on success or if the pointer is
.Dv NULL .
Otherwise, it returns an error code.
.Sh SEE ALSO
.Xr dc_context_new 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

73
doc/man/dc_context_new.3 Normal file
View File

@ -0,0 +1,73 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_CONTEXT_NEW 3
.Os
.Sh NAME
.Nm dc_context_new
.Nd create a new device-handling context
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/context.h
.Ft dc_status_t
.Fo dc_context_new
.Fa "dc_context_t **context"
.Fc
.Sh DESCRIPTION
Create a context in which dive computers may be queried.
The
.Dq context
supplies logging messages and so on, and may be re-used for multiple
dive computer query sessions.
It is usually passed to
.Xr dc_device_open 3
to query a specific dive computer device.
.Pp
On success, the context must be freed with
.Xr dc_context_free 3 .
You may configure the context with
.Xr dc_context_set_loglevel 3
and
.Xr dc_context_set_logfunc 3 .
This is highly recommended as the default logging behaviour of
.Nm
depends upon compile-time values.
.Sh RETURN VALUES
This returns
.Dv DC_STATUS_OK
on success, in which case
.Fa context
is filled in, or an error code on failure.
.Sh SEE ALSO
.Xr dc_context_free 3 ,
.Xr dc_context_set_logfunc 3 ,
.Xr dc_context_set_loglevel 3 ,
.Xr dc_device_open 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,98 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_CONTEXT_SET_LOGFUNC 3
.Os
.Sh NAME
.Nm dc_context_set_logfunc
.Nd set the logging function for a dive computer context
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/context.h
.Ft typedef void
.Fo (*dc_logfunc_t)
.Fa "dc_context_t *context"
.Fa "dc_loglevel_t loglevel"
.Fa "const char *file"
.Fa "unsigned int line"
.Fa "const char *function"
.Fa "const char *message"
.Fa "void *userdata"
.Fc
.Ft dc_status_t
.Fo dc_context_set_logfunc
.Fa "dc_context_t *context"
.Fa "dc_logfunc_t logfunc"
.Fa "void *userdata"
.Fc
.Sh DESCRIPTION
Set the logging function
.Fa logfunc
associated with a dive computer context.
The logging function is invoked with argument
.Fa userdata
when the log level
.Pq see Xr dc_context_set_loglevel 3
has been exceeded.
.Pp
The
.Fa logfunc
accepts the following values:
.Bl -tag -width Ds
.It Fa context
The context in which it was invoked.
.It Fa loglevel
The level of the log message.
.It Fa file
The source file where the message was raised.
.It Fa line
The source line (from 1) where the message was raised.
.It Fa function
The function that raised the log message.
.It Fa message
The log message itself.
.It Fa userdata
The pointer passed to
.Nm dc_context_set_logfunc .
.El
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_OK
on setting the log level,
.Dv DC_STATUS_INVALIDARGS
if
.Fa context
is
.Dv NULL ,
or another error code on failure.
.Sh SEE ALSO
.Xr dc_context_new 3 ,
.Xr dc_context_set_loglevel 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,90 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_CONTEXT_SET_LOGLEVEL 3
.Os
.Sh NAME
.Nm dc_context_set_loglevel
.Nd set the logging level for a dive computer context
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/context.h
.Ft dc_status_t
.Fo dc_context_set_loglevel
.Fa "dc_context_t *context"
.Fa "dc_loglevel_t loglevel"
.Fc
.Sh DESCRIPTION
Set the
.Em minimum
log level required to raise a logging event with the
.Xr dc_context_set_logfunc 3
callback.
Operates on a dive computer context created with
.Xr dc_context_new 3 .
The log levels are ordered as follows:
.Bl -enum
.It
.Dv DC_LOGLEVEL_NONE
.It
.Dv DC_LOGLEVEL_ERROR
.It
.Dv DC_LOGLEVEL_WARNING
.It
.Dv DC_LOGLEVEL_INFO
.It
.Dv DC_LOGLEVEL_DEBUG
.It
.Dv DC_LOGLEVEL_ALL
.El
.Pp
By setting, for exammple,
.Dv DC_LOGLEVEL_INFO ,
all events of
.Dv DC_LOGLEVEL_ERROR ,
.Dv DC_LOGLEVEL_WARNING ,
and
.Dv DC_LOGLEVEL_INFO
will be reported via the callback in
.Xr dc_context_set_logfunc 3 .
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_OK
on setting the log level,
.Dv DC_STATUS_INVALIDARGS
if
.Fa context
is
.Dv NULL ,
or another error code on failure.
.Sh SEE ALSO
.Xr dc_context_new 3 ,
.Xr dc_context_set_logfunc 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,94 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 11, 2017
.Dt DC_DATETIME_GMTIME 3
.Os
.Sh NAME
.Nm dc_datetime_gmtime
.Nd convert an timestamp to GMT date and time
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/datetime.h
.Ft dc_datetime_t *
.Fo dc_datetime_gmtime
.Fa "dc_datetime_t *result"
.Fa "dc_ticks_t ticks"
.Fc
.Sh DESCRIPTION
Convert an integral timestamp
.Fa ticks
created with
.Xr dc_datetime_now 3
or
.Xr dc_datetime_mktime 3
into a broken-down GMT representation in
.Fa result .
The filled-in value consists of the
.Va year ,
.Va month ,
.Va day ,
.Va hour ,
.Va minute ,
and
.Va second
fields.
.Pp
.Em Note :
unlike in
.Vt "struct tm" ,
the value for
.Va year
is normalised, not less 1900; moreover, the value for
.Va month
is from one, not zero.
.Pp
The
.Nm
function may internally invoke libc's
.Xr gmtime 3 ,
or if available,
.Xr gmtime_r 3 .
.Sh RETURN VALUES
This returns the
.Fa result
pointer on success.
It returns
.Dv NULL
if
.Fa ticks
cannot be sanely converted or if
.Fa result
is
.Dv NULL .
.Sh SEE ALSO
.Xr dc_datetime_localtime 3 ,
.Xr dc_datetime_mktime 3 ,
.Xr dc_datetime_now 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,94 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 11, 2017
.Dt DC_DATETIME_LOCALTIME 3
.Os
.Sh NAME
.Nm dc_datetime_localtime
.Nd convert an timestamp to local date and time
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/datetime.h
.Ft dc_datetime_t *
.Fo dc_datetime_localtime
.Fa "dc_datetime_t *result"
.Fa "dc_ticks_t ticks"
.Fc
.Sh DESCRIPTION
Convert an integral timestamp
.Fa ticks
created with
.Xr dc_datetime_now 3
or
.Xr dc_datetime_mktime 3
into a broken-down local-time representation in
.Fa result .
The filled-in value consists of the
.Va year ,
.Va month ,
.Va day ,
.Va hour ,
.Va minute ,
and
.Va second
fields.
.Pp
.Em Note :
unlike in
.Vt "struct tm" ,
the value for
.Va year
is normalised, not less 1900; moreover, the value for
.Va month
is from one, not zero.
.Pp
The
.Nm
function may internally invoke libc's
.Xr localtime 3 ,
or if available,
.Xr localtime_r 3 .
.Sh RETURN VALUES
This returns the
.Fa result
pointer on success.
It returns
.Dv NULL
if
.Fa ticks
cannot be sanely converted or if
.Fa result
is
.Dv NULL .
.Sh SEE ALSO
.Xr dc_datetime_gmtime 3 ,
.Xr dc_datetime_mktime 3 ,
.Xr dc_datetime_now 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,59 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 11, 2017
.Dt DC_DATETIME_MKTIME 3
.Os
.Sh NAME
.Nm dc_datetime_mktime
.Nd convert an local date and time to a timestamp
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/datetime.h
.Ft dc_ticks_t
.Fo dc_datetime_mktime
.Fa "const dc_datetime_t *dt"
.Fc
.Sh DESCRIPTION
Convert a broken-down local date and time created with
.Xr dc_datetime_localtime 3
into an integral timestamp.
.Pp
The
.Nm
function may internally invoke libc's
.Xr mktime 3 .
.Sh RETURN VALUES
This returns the integral time-stamp or -1 if the given date and time
may not sanely be converted.
.Sh SEE ALSO
.Xr dc_datetime_gmtime 3 ,
.Xr dc_datetime_localtime 3 ,
.Xr dc_datetime_now 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

55
doc/man/dc_datetime_now.3 Normal file
View File

@ -0,0 +1,55 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 11, 2017
.Dt DC_DATETIME_NOW 3
.Os
.Sh NAME
.Nm dc_datetime_now
.Nd return the current integral timestamp
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/datetime.h
.Ft dc_ticks_t
.Fo dc_datetime_now
.Fc
.Sh DESCRIPTION
Get the current system timestamp as an integral value.
.Pp
The
.Nm
function may invoke libc's
.Xr time 3 .
.Sh RETURN VALUES
This always returns the system time.
.Sh SEE ALSO
.Xr dc_datetime_gmtime 3 ,
.Xr dc_datetime_localtime 3 ,
.Xr dc_datetime_mktime 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,54 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_DESCRIPTOR_FREE 3
.Os
.Sh NAME
.Nm dc_descriptor_free
.Nd free a dive computer descriptor reference
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/descriptor.h
.Ft void
.Fo dc_descriptor_free
.Fa "dc_descriptor_t *descriptor"
.Fc
.Sh DESCRIPTION
Frees a descriptor usually returned with
.Xr dc_iterator_next 3
as created with
.Xr dc_descriptor_iterator 3 .
It's safe to pass
.Dv NULL
to this function.
.Sh SEE ALSO
.Xr dc_descriptor_iterator 3 ,
.Xr dc_iterator_free 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,52 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2018 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 August 19, 2018
.Dt DC_DESCRIPTOR_GET_MODEL 3
.Os
.Sh NAME
.Nm dc_descriptor_get_model
.Nd get the model of a dive computer descriptor
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/descriptor.h
.Ft "unsigned int"
.Fo dc_descriptor_get_model
.Fa "dc_descriptor_t *descriptor"
.Fc
.Sh DESCRIPTION
Gets the model number of a dive computer descriptor or 0 if none was
defined for the computer.
0 is also a valid model number.
.Sh RETURN VALUES
This returns the model number or 0 if none exists.
.Sh SEE ALSO
.Xr dc_descriptor_iterator 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,59 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_DESCRIPTOR_GET_PRODUCT 3
.Os
.Sh NAME
.Nm dc_descriptor_get_product
.Nd get the product of a dive computer descriptor
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/descriptor.h
.Ft "const char *"
.Fo dc_descriptor_get_product
.Fa "dc_descriptor_t *descriptor"
.Fc
.Sh DESCRIPTION
Gets the product
.Pq e.g., Do D6i Dc for my Suunto
of a dive computer descriptor or
.Dv NULL
if none was declared.
.Sh RETURN VALUES
This returns the nil-terminated product string or
.Dv NULL
if none exists.
.Pp
The returned pointer is not valid after the
.Fa descriptor
has been freed.
.Sh SEE ALSO
.Xr dc_descriptor_get_vendor 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

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

@ -0,0 +1,59 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_DESCRIPTOR_GET_VENDOR 3
.Os
.Sh NAME
.Nm dc_descriptor_get_vendor
.Nd get the vendor of a dive computer descriptor
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/descriptor.h
.Ft "const char *"
.Fo dc_descriptor_get_vendor
.Fa "dc_descriptor_t *descriptor"
.Fc
.Sh DESCRIPTION
Gets the vendor
.Pq e.g., Dq Suunto
of a dive computer descriptor or
.Dv NULL
if none was declared.
.Sh RETURN VALUES
This returns the nil-terminated vendor string or
.Dv NULL
if none exists.
.Pp
The returned pointer is not valid after the
.Fa descriptor
has been freed.
.Sh SEE ALSO
.Xr dc_descriptor_get_product 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,78 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_DESCRIPTOR_ITERATOR 3
.Os
.Sh NAME
.Nm dc_descriptor_iterator
.Nd get all supported dive computers
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/descriptor.h
.Ft dc_status_t
.Fo dc_descriptor_iterator
.Fa "dc_iterator_t **iterator"
.Fc
.Sh DESCRIPTION
Gets all descriptors available to
.Lb libdivecomputer .
It must be matched with
.Xr dc_iterator_free 3
if the return value is
.Dv DC_STATUS_SUCCESS .
The
.Xr dc_iterator_next 3
function must be used to iterate over the iterator.
You must use
.Xr dc_descriptor_free 3
on the returned descriptor value.
.Sh RETURN VALUES
This returns
.Dv DC_STATUS_SUCCESS
and fills in the
.Fa iterator
pointer on success.
.Sh EXAMPLES
The following iterates over all descriptors, printing the vendor, then
frees the iterator.
It does no error checking.
.Bd -literal
dc_descriptor_iterator(&iter));
while (dc_iterator_next(iter, &desc) == DC_STATUS_SUCCESS) {
printf("%s\en", dc_descriptor_get_vendor(desc));
dc_descriptor_free(desc);
}
dc_iterator_free(iter);
.Ed
.Sh SEE ALSO
.Xr dc_descriptor_free 3 ,
.Xr dc_iterator_free 3 ,
.Xr dc_iterator_next 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

58
doc/man/dc_device_close.3 Normal file
View File

@ -0,0 +1,58 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_DEVICE_CLOSE 3
.Os
.Sh NAME
.Nm dc_device_close
.Nd close a dive computer device
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/device.h
.Ft dc_status_t
.Fo dc_device_close
.Fa "dc_device_t *device"
.Fc
.Sh DESCRIPTION
Closes a dive computer device opened with
.Xr dc_device_open 3 .
If
.Fa device
is
.Dv NULL ,
this returns
.Dv DC_STATUS_SUCCESS .
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_SUCCESS
on success or one of several error values on error.
.Sh SEE ALSO
.Xr dc_device_open 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,84 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_DEVICE_FOREACH 3
.Os
.Sh NAME
.Nm dc_device_foreach
.Nd iterate over dives in a dive computer
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/device.h
.Ft typedef int
.Fo (*dc_dive_callback_t)
.Fa "const unsigned char *data"
.Fa "unsigned int size"
.Fa "const unsigned char *fingerprint"
.Fa "unsigned int fsize"
.Fa "void *userdata"
.Fc
.Ft dc_status_t
.Fo dc_device_foreach
.Fa "dc_device_t *device"
.Fa "dc_dive_callback_t callback"
.Fa "void *userdata"
.Fc
.Sh DESCRIPTION
Iterate over all dives on
.Fa device
by calling
.Fa callback
with
.Fa userdata .
.Pp
Each dive invokes
.Fa callback
with the dive data, which should be parsed with
.Xr dc_parser_new 3 ,
and the binary fingerprint of the dive.
The fingerprint can be used to record the newest dive and stop
processing (on subsequent invocations) when the same dive fingerprint is
encountered.
.Pp
The
.Fa callback
function must return non-zero to continue downloading dives, or zero to
stop.
.Sh RETURN VALUES
This returns
.Dv DC_STATUS_SUCCESS
on success or one of several error values on error.
If
.Fa callback
returns zero, this will not be reflected in the return value (usually
.Dv DC_STATUS_SUCCESS ) .
.Sh SEE ALSO
.Xr dc_parser_new 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

87
doc/man/dc_device_open.3 Normal file
View File

@ -0,0 +1,87 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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_DEVICE_OPEN 3
.Os
.Sh NAME
.Nm dc_device_open
.Nd open a dive computer device
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/device.h
.Ft dc_status_t
.Fo dc_device_open
.Fa "dc_device_t **device"
.Fa "dc_context_t *context"
.Fa "dc_descriptor_t *descriptor"
.Fa "dc_iostream_t *iostream"
.Fc
.Sh DESCRIPTION
Open a dive computer device for processing.
Accepts a
.Fa context
opened with
.Xr dc_context_new 3 ,
a dive computer
.Fa descriptor
usually found by searching through
.Xr dc_descriptor_iterator 3 ,
and a
.Fa iostream
opened with a transport specific open function like
.Xr dc_usbhid_open 3 ,
.Xr dc_irda_open 3 ,
.Xr dc_serial_open 3 ,
or
.Xr dc_bluetooth_open 3
.Pc .
.Pp
Upon returning
.Dv DC_STATUS_SUCCESS ,
the
.Fa device
pointer must be freed with
.Xr dc_device_close 3 .
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_SUCCESS
on success or one of several error values on error.
On success, the
.Fa device
pointer is filled in with an open handle.
.Sh SEE ALSO
.Xr dc_context_new 3 ,
.Xr dc_descriptor_iterator 3 ,
.Xr dc_device_close 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
.br
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .
and
.An Vincent Hagen ,
.Mt vinnie@script4web.nl

View File

@ -0,0 +1,79 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_DEVICE_SET_CANCEL 3
.Os
.Sh NAME
.Nm dc_device_set_cancel
.Nd callback to check whether processing should cancel
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/device.h
.Ft "typedef int"
.Fo "(*dc_cancel_callback_t)"
.Fa "void *userdata"
.Fc
.Ft dc_status_t
.Fo dc_device_set_cancel
.Fa "dc_device_t *device"
.Fa "dc_cancel_callback_t callback"
.Fa "void *userdata"
.Fc
.Sh DESCRIPTION
Provide a function that the underlying
.Fa device
will periodically call to see if it should cancel its processing.
The
.Fa callback
will return zero if the operation should not be cancelled, one if it
should be cancelled.
.Pp
The callback usually checks a value that is set during a signal handling
callback.
For example, one can invoke
.Xr signal 3
to a function that sets a
.Vt "volatile sig_atomic_t"
value checked by the
.Fa callback
handler.
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_UNSUPPORTED
if the
.Fa device
is
.Dv NULL ,
or
.Dv DC_STATUS_SUCCESS
otherwise.
.Sh SEE ALSO
.Xr dc_device_open 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
These manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,125 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_DEVICE_SET_EVENTS 3
.Os
.Sh NAME
.Nm dc_device_set_events
.Nd set events logged during device interaction
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/device.h
.Ft "typedef void"
.Fo "(*dc_event_callback_t)"
.Fa "dc_device_t *device"
.Fa "dc_event_type_t event"
.Fa "const void *data"
.Fa "void *userdata"
.Fc
.Ft dc_status_t
.Fo dc_device_set_events
.Fa "dc_device_t *device"
.Fa "unsigned int events"
.Fa "dc_event_callback_t callback"
.Fa "void *userdata"
.Fc
.Sh DESCRIPTION
Register a series of event callbacks on a device opened with
.Xr dc_device_open 3 .
Event callbacks are informative messages during device processing passed
to the
.Fa callback
function with an optional argument
.Fa userdata.
.Pp
The
.Fa events
value is a bit-field of events, one of which is passed to the
.Fa callback
as
.Fa event .
The
.Fa data
field will be cast to an event-specific type:
.Bl -tag -width Ds
.It Dv DC_EVENT_WAITING
Indicate that the device is waiting for user input, such as activating
the data transfer mode on the device.
No
.Fa data
is set.
.It Dv DC_EVENT_PROGRESS
Progress metre of the parse.
The
.Fa data
variable is set to a
.Vt dc_event_progress_t ,
with the
.Va current
and
.Va maximum
progress values from which one can compute a percentage.
.It Dv DC_EVENT_DEVINFO
Sets the
.Fa data
value to a
.Vt dc_event_devinfo_t ,
which can be used to acquire the
.Va model ,
.Va firmware ,
and
.Va serial
numbers of the underlying device.
.It Dv DC_EVENT_CLOCK
Report the system (local machine) and device time in epoch seconds.
Fills in
.Fa data
as a
.Va dc_event_clock_t ,
with
.Va devtime
being the device and
.Va systime
being the system time.
See
.Xr time 3 .
.It Dv DC_EVENT_VENDOR
A vendor-specific event filling
.Fa data
as a
.Va dc_event_vendor_t .
.El
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_SUCCESS
on success or one of several error values on error.
.Sh SEE ALSO
.Xr dc_device_open 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
These manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,70 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_DEVICE_SET_FINGERPRINT 3
.Os
.Sh NAME
.Nm dc_device_set_fingerprint
.Nd set the last-seen dive fingerprint
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/device.h
.Ft dc_status_t
.Fo dc_device_set_fingerprint
.Fa "dc_device_t *device"
.Fa "const unsigned char data[]"
.Fa "unsigned int size"
.Fc
.Sh DESCRIPTION
Sets the last-seen dive fingerprint on a device opened with
.Xr dc_device_open 3 .
This mechanism is used to only download dives
.Dq newer
.Po
as reported by the dive computer, not necessarily on the calendar
.Pc
than the last seen dive.
.Pp
In general usage, the fingerprint is acquired (and saved) from the first
dive downloaded from a dive computer by
.Xr dc_device_foreach 3 .
In subsequent openings of the device, the fingerprint is set with
.Nm
and, when a dive reports a fingerprint matching that dive, the download
exits before reporting that dive.
.Pq The first fingerprint is saved again for subsequent invocations.
In this way, only the newest dives are reported.
.Sh RETURN VALUES
This returns
.Dv DC_STATUS_SUCCESS
if the fingerprint was set or one of several error values on error.
.Sh SEE ALSO
.Xr dc_device_open 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,60 @@
.\"
.\" 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_IOSTREAM_CLOSE 3
.Os
.Sh NAME
.Nm dc_iostream_close
.Nd Close the I/O stream and free all resources.
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/iostream.h
.Ft dc_status_t
.Fo dc_iostream_close
.Fa "dc_iostream_t *iostream"
.Fc
.Sh DESCRIPTION
Close the I/O stream and free all resources.
Accepts the
.Fa iostream
to close and free.
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_SUCCESS
on success, or another
.Ft dc_status_t
code on failure.
.Sh SEE ALSO
.Xr dc_usbhid_open 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

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

@ -0,0 +1,56 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_ITERATOR_FREE 3
.Os
.Sh NAME
.Nm dc_iterator_free
.Nd frees an iterator
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/iterator.h
.Ft dc_status_t
.Fo dc_iterator_free
.Fa "dc_iterator_t *iterator"
.Fc
.Sh DESCRIPTION
Frees the iterator
.Fa iterator .
It may be invoked on any iterator type, e.g., one created with
.Xr dc_descriptor_iterator 3 .
.Sh RETURN VALUES
This returns
.Dv DC_STATUS_SUCCESS
on success (or if
.Fa iterator
is
.Dv NULL )
or other values on failure.
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,55 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_ITERATOR_NEXT 3
.Os
.Sh NAME
.Nm dc_iterator_next
.Nd next element in an iterator
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/iterator.h
.Ft dc_status_t
.Fo dc_iterator_next
.Fa "dc_iterator_t *iterator"
.Fa "void *item"
.Fc
.Sh DESCRIPTION
Fills in
.Fa item
with the next element in the iterator
.Fa iterator ,
which may not be
.Dv NULL .
.Sh RETURN VALUES
This returns
.Dv DC_STATUS_SUCCESS
on success.
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,57 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_PARSER_DESTROY 3
.Os
.Sh NAME
.Nm dc_parser_destroy
.Nd destroys a single dive parser
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/parser.h
.Ft dc_status_t
.Fo dc_parser_destroy
.Fa "dc_parser_t *parser"
.Fc
.Sh DESCRIPTION
Destroys a parser allocated with
.Xr dc_parser_new 3 .
The
.Fa parser
parameter may be
.Dv NULL ,
in which case it will return with success.
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_OK
on success and another code on failure.
.Sh SEE ALSO
.Xr dc_parser_new 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,69 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_PARSER_GET_DATETIME 3
.Os
.Sh NAME
.Nm dc_parser_get_datetime
.Nd extract the date and time from a parsed dive
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/parser.h
.Ft dc_status_t
.Fo dc_parser_get_datetime
.Fa "dc_parser_t *parser"
.Fa "dc_datetime_t *datetime"
.Fc
.Sh DESCRIPTION
Extract the date and time of a dive,
.Fa parser ,
previously initialised with
.Xr dc_parser_new 3 .
This returns the broken-down time-stamp of the dive in the local time of
the dive.
.Pp
The
.Nm
function may internally invoke
.Xr dc_datetime_gmtime 3
or
.Xr dc_datetime_localtime 3 .
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_SUCCESS
if the date and time were retrieved,
.Dv DC_STATUS_UNSUPPORTED
if the date and time are not supported by the device, or other error
messages on further failure.
.Sh SEE ALSO
.Xr dc_datetime_gmtime 3 ,
.Xr dc_datetime_localtime 3 ,
.Xr dc_parser_new 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,199 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_PARSER_GET_FIELD 3
.Os
.Sh NAME
.Nm dc_parser_get_field
.Nd extract a field from a parsed dive
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/parser.h
.Ft dc_status_t
.Fo dc_parser_get_field
.Fa "dc_parser_t *parser"
.Fa "dc_field_type_t type"
.Fa "unsigned int flags"
.Fa "void *value"
.Fc
.Sh DESCRIPTION
Extract a field from a dive,
.Fa parser ,
previously initialised with
.Xr dc_parser_new 3 .
The
.Fa value
field type depends upon the
.Fa type .
The
.Fa flags
field is ignored for all types but
.Dv DC_FIELD_GASMIX
and
.Dv DC_FIELD_TANK .
.Pp
The
.Fa type
may be one of the following values:
.Bl -tag -width Ds
.It Dv DC_FIELD_DIVETIME
Time (duration) of dive in seconds.
The
.Fa value
must be an
.Vt unsigned int .
.It Dv DC_FIELD_MAXDEPTH
Maximum depth in metres.
The
.Fa value
must be a
.Vt double .
.It Dv DC_FIELD_AVGDEPTH
Average depth (over all samples) in metres.
The
.Fa value
must be a
.Vt double .
.It Dv DC_FIELD_GASMIX_COUNT
Number of different gas mixes used in this dive.
The
.Fa value
must be a
.Vt unsigned int .
.It Dv DC_FIELD_GASMIX
Mixture for a particular gas.
The
.Fa value
must be a
.Vt dc_gasmix_t ,
which has
.Vt double
fields for
.Va oxygen ,
.Va helium ,
and
.Va nitrogen .
These are set to the unit fraction of gas (not percentage).
The
.Fa flags
value is interpreted as the gas mixture index, which must be less than the
value of
.Dv DC_FIELD_GASMIX_COUNT .
.It Dv DC_FIELD_SALINITY
The water salinity as a
.Vt dc_salinity_t
field, which consists of a
.Va type ,
.Dv DC_WATER_FRESH
or
.Dv DC_WATER_SALT ,
and the salinity
.Va density .
.It Dv DC_FIELD_ATMOSPHERIC
Atmospheric pressure in bar.
The
.Fa value
field must be a
.Vt double .
.It Dv DC_FIELD_TEMPERATURE_SURFACE
Air temperature (at the surface) in Celsius.
The
.Fa value
field must be a
.Vt double .
.It Dv DC_FIELD_TEMPERATURE_MINIMUM
Minimum water temperature surface in Celsius.
The
.Fa value
field must be a
.Vt double .
.It Dv DC_FIELD_TEMPERATURE_MAXIMUM
Maximum water temperature in Celsius.
The
.Fa value
field must be a
.Vt double .
.It Dv DC_FIELD_TANK_COUNT
The number of tanks as an
.Vt unsigned int .
.It Dv DC_FIELD_TANK
Tank configuration as a
.Vt dc_tank_t .
This structure consists of a
.Va gasmix ,
which may be retrieved with
.Dv DC_FIELD_GASMIX ;
.Va type ,
the tank volume units as
.Dv DC_TANKVOLUME_NONE ,
.Dv DC_TANKVOLUME_IMPERIAL ,
or
.Dv DC_TANKVOLUME_METRIC ;
.Va volume ,
the tank volume in litres or zero if the tank is
.Dv DC_TANKVOLUME_NONE ;
.Va workpressure ,
the work pressure in bar or zero if
.Dv DC_TANKVOLUME_NONE
and maybe zero if
.Dv DC_TANKVOLUME_METRIC ;
.Va beginpressure
and
.Va endpressure
being the pressures at start and finish in bar.
The
.Fa flags
value is the tank index.
.It Dv DC_FIELD_DIVEMODE
Mode of the dive:
.Dv DC_DIVEMODE_FREEDIVE
for free-diving,
.Dv DC_DIVEMODE_GAUGE
for gauge (i.e., running as a record and not computing, say,
decompression events),
.Dv DC_DIVEMODE_OC
for standard open-circuit diving, and
.Dv DC_DIVEMODE_CCR
and
.Dv DC_DIVEMODE_SCR
for respectively closed circuit and semi closed circuit
.Dq rebreather
diving.
.El
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_SUCCESS
if the field was retrieved,
.Dv DC_STATUS_UNSUPPORTED
if the field is not supported by the device, or other error messages on
further failure.
.Sh SEE ALSO
.Xr dc_parser_new 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

76
doc/man/dc_parser_new.3 Normal file
View File

@ -0,0 +1,76 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_PARSER_NEW 3
.Os
.Sh NAME
.Nm dc_parser_new ,
.Nm dc_parser_new2
.Nd create a parser for a single dive
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/parser.h
.Ft dc_status_t
.Fo dc_parser_new
.Fa "dc_parser_t **parser"
.Fa "dc_device_t *device"
.Fc
.Ft dc_status_t
.Fo dc_parser_new2
.Fa "dc_parser_t **parser"
.Fa "dc_context_t *context"
.Fa "dc_descriptor_t *descriptor"
.Fc
.Sh DESCRIPTION
Creates a parser for a single dive extracted from the dive computer with
.Xr dc_device_foreach 3 .
The parser operates on the data extracted: it does not touch the device
directly to acquire data.
Thus, there are two forms of invocation:
.Nm dc_parser_new ,
which extracts relevant values from the
.Fa device
parameter; and
.Nm dc_parser_new2 ,
which is given device values (model, etc.) directly.
.Pp
The pointer must later be freed with
.Xr dc_parser_destroy 3 .
.Sh RETURN VALUES
These return
.Dv DC_STATUS_OK ,
and fill in the
.Fa parser
pointer on success.
Otherwise, an error is returned.
.Sh SEE ALSO
.Xr dc_device_foreach 3 ,
.Xr dc_parser_destroy 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -0,0 +1,196 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DC_PARSER_SAMPLES_FOREACH 3
.Os
.Sh NAME
.Nm dc_parser_samples_foreach
.Nd iterate over samples taken during a dive
.Sh LIBRARY
.Lb libdivecomputer
.Sh SYNOPSIS
.In libdivecomputer/parser.h
.Ft "typedef void"
.Fo "(*dc_sample_callback_t)"
.Fa "dc_sample_type_t type"
.Fa "const dc_sample_value_t *value"
.Fa "void *userdata"
.Fc
.Ft dc_status_t
.Fo dc_parser_samples_foreach
.Fa "dc_parser_t *parser"
.Fa "dc_sample_callback_t callback"
.Fa "void *userdata"
.Fc
.Sh DESCRIPTION
Extract the samples taken during a dive as previously initialised with
.Xr dc_parser_new 3 .
Each sample is passed to
.Fa callback
with the
.Fa type
of the sample and its data
.Fa value .
.Pp
Samples are invoked as a sequence of sample sets.
Each sequence begins with a
.Dv DC_SAMPLE_TIME ,
then a number of sample types in the set.
When the next
.Dv DC_SAMPLE_TIME
is recorded, the sample set may be closed and a new one reopened.
After all samples have been rendered, the last sample set should be
closed.
.Pp
The following sample types may be raised:
.Bl -tag -width Ds
.It Dv DC_SAMPLE_TIME
The time of the sample taken in milliseconds after the dive began.
Set in the
.Fa time
field.
.It Dv DC_SAMPLE_DEPTH
The depth taken at the sample in metres.
Set in the
.Fa depth
field.
.It Dv DC_SAMPLE_PRESSURE
Tank pressure taken at the sample.
Sets the
.Fa tank
index (see the
.Dv DC_FIELD_TANK_COUNT
in
.Xr dc_parser_get_field 3 )
and the
.Fa pressure
in bar.
.It Dv DC_SAMPLE_TEMPERATURE
Temperature in celsius.
Sets the
.Fa temperature
field.
.It Dv DC_SAMPLE_EVENT
An diving event raised by the computer.
This may have the
.Va type
value of the
.Va event
structure set to
.Dv SAMPLE_EVENT_NONE ,
.Dv SAMPLE_EVENT_DECOSTOP ,
.Dv SAMPLE_EVENT_RBT ,
.Dv SAMPLE_EVENT_ASCENT ,
.Dv SAMPLE_EVENT_CEILING ,
.Dv SAMPLE_EVENT_WORKLOAD ,
.Dv SAMPLE_EVENT_TRANSMITTER ,
.Dv SAMPLE_EVENT_VIOLATION ,
.Dv SAMPLE_EVENT_BOOKMARK ,
.Dv SAMPLE_EVENT_SURFACE ,
.Dv SAMPLE_EVENT_SAFETYSTOP ,
.Dv SAMPLE_EVENT_SAFETYSTOP_VOLUNTARY ,
.Dv SAMPLE_EVENT_SAFETYSTOP_MANDATORY ,
.Dv SAMPLE_EVENT_DEEPSTOP ,
.Dv SAMPLE_EVENT_CEILING_SAFETYSTOP ,
.Dv SAMPLE_EVENT_FLOOR ,
.Dv SAMPLE_EVENT_DIVETIME ,
.Dv SAMPLE_EVENT_MAXDEPTH ,
.Dv SAMPLE_EVENT_OLF ,
.Dv SAMPLE_EVENT_PO2 ,
.Dv SAMPLE_EVENT_AIRTIME ,
.Dv SAMPLE_EVENT_RGBM ,
.Dv SAMPLE_EVENT_HEADING ,
or
.Dv SAMPLE_EVENT_TISSUELEVEL .
.It Dv DC_SAMPLE_RBT
The remaining bottom time in seconds.
Sets the
.Fa rbt
field.
.It Dv DC_SAMPLE_HEARTBEAT
The diver's heartbeat in beats per minute.
Sets the
.Fa heartbeat
field.
.It Dv DC_SAMPLE_BEARING
The diver's bearing in degrees.
Sets the
.Fa bearing
field.
.It Dv DC_SAMPLE_VENDOR
A vendor-specific data field.
.It Dv DC_SAMPLE_SETPOINT
The closed-circuit setpoint (PO2) has changed.
Sets the
.Fa setpoint
value in bar.
.It Dv DC_SAMPLE_PPO2
The partial pressure of oxygen has changed (in bar).
Sets the
.Fa ppo2
field.
.It Dv DC_SAMPLE_CNS
The CNS (central nervous system oxygen toxicity) value as a unit
fraction.
Sets the
.Fa cns
value.
.It Dv DC_SAMPLE_DECO
Decompression phase of
.Fa type
.Dv DC_DECO_NDL
.Pq no decompression limit ,
.Dv DC_DECO_SAFETYSTOP
.Pq the safety stop ,
.Dv DC_DECO_DECOSTOP
.Pq a decompression stop ,
or
.Dv DC_DECO_DEEPSTOP
.Pq a mandatory or suggested deep-stop .
Also sets the
.Fa depth
in metres and the
.Fa time
in seconds.
.It Dv DC_SAMPLE_GASMIX
Switch to a given gas mix index (see the
.Dv DC_FIELD_GASMIX_COUNT
in
.Xr dc_parser_get_field 3 ) .
Sets the
.Fa gasmix
field.
.El
.Sh RETURN VALUES
Returns
.Dv DC_STATUS_OK
on success and another code on failure.
.Sh SEE ALSO
.Xr dc_parser_new 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
The manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

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 .

159
doc/man/libdivecomputer.3 Normal file
View File

@ -0,0 +1,159 @@
.\"
.\" libdivecomputer
.\"
.\" Copyright (C) 2017 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" 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 January 5, 2017
.Dt DIVECOMPUTER 3
.Os
.Sh NAME
.Nm divecomputer
.Nd communicate with dive computers
.Sh LIBRARY
.Lb libdivecomputer
.Sh DESCRIPTION
The
.Nm divecomputer
library is a cross-platform and open source library for communication
with dive computers from various manufacturers.
Systems interfacing with
.Nm divecomputer
must link with
.Fl l Ns Ar divecomputer .
.Pp
A system wishing to query dives in a dive computer generally follows
these steps:
.Bl -enum
.It
Create a new context with
.Xr dc_context_new 3
to initialize the library. Logging can be controlled with
.Xr dc_context_set_logfunc 3
and
.Xr dc_context_set_loglevel 3 .
.It
Find a descriptor for their dive computer by iterating through
.Xr dc_descriptor_iterator 3
and searching by name, vendor, or product family.
.It
Find the transport to use for the communication. To determine the supported transports use
.Xr dc_descriptor_get_transports 3 .
.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_fingerprint 3
and
.Xr dc_device_set_cancel 3
to set the logging events, last-seen fingerprint, and cancel routine,
respectively.
.It
Iterate over all dives with
.Xr dc_device_foreach 3 .
.It
For each iterated dive, create a new parser with
.Xr dc_parser_new 3 .
.It
Get attributes of the parsed dive with
.Xr dc_parser_get_field 3 .
.It
Iterate through the dive's samples (recorded data) with
.Xr dc_parser_samples_foreach 3 .
.El
.Sh RETURN VALUES
Most
.Nm libdivecomputer
functions return with a
.Vt dc_status_t
type with the following possible values:
.Bl -tag -width Ds
.It Dv DC_STATUS_SUCCESS
Completion with success: not an error.
.It Dv DC_STATUS_DONE
End of an iterator: not an error.
.It Dv DC_STATUS_UNSUPPORTED
Feature not implemented or not supported by device.
.Po
The difference depends on the context.
Since
.Nm libdivecomputer
is largely
based on reverse engineering, we often can't even tell them apart.
.Pc
.It Dv DC_STATUS_INVALIDARGS
Invalid parameter.
Usually indicates caller bug.
.It Dv DC_STATUS_NOMEMORY
Out of memory.
.It Dv DC_STATUS_NODEVICE
Device not found.
In this context the device refers to the low-level communication device
(serial, bluetooth, irda, etc), not the dive computer.
In most cases, and especially with serial communication, we can't detect
whether the dive computer is present.
This is always detected indirectly: no response is received, and thus a
timeout error.
.It Dv DC_STATUS_NOACCESS
Access denied (again, to the low-level communication device).
.It Dv DC_STATUS_TIMEOUT
See
.Dv DC_STATUS_NODEVICE .
.It Dv DC_STATUS_IO
Any other I/O error.
.It Dv DC_STATUS_PROTOCOL
Encountered unexpected data in the communication protocol data packets,
e.g., while downloading.
.It Dv DC_STATUS_DATAFORMAT
Encountered unexpected data in the interpretation of data contents,
e.g., while parsing.
.It Dv DC_STATUS_CANCELLED
Returned when the cancel callback requested to cancel the operation.
Note that cancellation is only checked at specific (safe) points, so
it's certainly possible it may not get noticed immediately and still
return
.Dv DC_STATUS_SUCCESS .
.El
.Sh SEE ALSO
.Xr dc_context_new 3 ,
.Xr dc_descriptor_iterator 3
.Xr dc_device_open 3
.Xr dc_parser_new 3
.Sh AUTHORS
The
.Lb libdivecomputer
library was written by
.An Jef Driesen ,
.Mt jef@libdivecomputer.org .
These manpages were written by
.An Kristaps Dzonsons ,
.Mt kristaps@bsd.lv .

View File

@ -2,86 +2,28 @@ AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
LDADD = $(top_builddir)/src/libdivecomputer.la
bin_PROGRAMS = \
universal \
solution \
eon \
vyper \
vyper2 \
d9 \
sensus \
sensuspro \
sensusultra \
aladin \
memomouse \
atom2 \
veo250 \
vtpro \
nemo \
puck \
darwin \
iconhd \
ostc \
frog \
edy \
leonardo \
n2ition3 \
predator
dctool
if IRDA
bin_PROGRAMS += smart
endif
COMMON = common.c common.h \
utils.c utils.h
universal_SOURCES = universal.c $(COMMON)
solution_SOURCES = suunto_solution_test.c $(COMMON)
eon_SOURCES = suunto_eon_test.c $(COMMON)
vyper_SOURCES = suunto_vyper_test.c $(COMMON)
vyper2_SOURCES = suunto_vyper2_test.c $(COMMON)
d9_SOURCES = suunto_d9_test.c $(COMMON)
sensus_SOURCES = reefnet_sensus_test.c $(COMMON)
sensuspro_SOURCES = reefnet_sensuspro_test.c $(COMMON)
sensusultra_SOURCES = reefnet_sensusultra_test.c $(COMMON)
aladin_SOURCES = uwatec_aladin_test.c $(COMMON)
memomouse_SOURCES = uwatec_memomouse_test.c $(COMMON)
atom2_SOURCES = oceanic_atom2_test.c $(COMMON)
veo250_SOURCES = oceanic_veo250_test.c $(COMMON)
vtpro_SOURCES = oceanic_vtpro_test.c $(COMMON)
nemo_SOURCES = mares_nemo_test.c $(COMMON)
puck_SOURCES = mares_puck_test.c $(COMMON)
darwin_SOURCES = mares_darwin_test.c $(COMMON)
iconhd_SOURCES = mares_iconhd_test.c $(COMMON)
ostc_SOURCES = hw_ostc_test.c $(COMMON)
frog_SOURCES = hw_frog_test.c $(COMMON)
edy_SOURCES = cressi_edy_test.c $(COMMON)
leonardo_SOURCES = cressi_leonardo_test.c $(COMMON)
n2ition3_SOURCES = zeagle_n2ition3_test.c $(COMMON)
predator_SOURCES = shearwater_predator_test.c $(COMMON)
if IRDA
smart_SOURCES = uwatec_smart_test.c $(COMMON)
endif
dctool_SOURCES = \
common.h \
common.c \
dctool.h \
dctool.c \
dctool_help.c \
dctool_version.c \
dctool_list.c \
dctool_scan.c \
dctool_download.c \
dctool_dump.c \
dctool_parse.c \
dctool_read.c \
dctool_write.c \
dctool_timesync.c \
dctool_fwupdate.c \
output.h \
output-private.h \
output.c \
output_xml.c \
output_raw.c \
utils.h \
utils.c

View File

@ -1,7 +1,7 @@
/*
* libdivecomputer
*
* Copyright (C) 2011 Jef Driesen
* Copyright (C) 2015 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -19,13 +19,102 @@
* MA 02110-1301 USA
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
#endif
#include <libdivecomputer/serial.h>
#include <libdivecomputer/bluetooth.h>
#include <libdivecomputer/irda.h>
#include <libdivecomputer/usb.h>
#include <libdivecomputer/usbhid.h>
#include "common.h"
#include "utils.h"
#ifdef _WIN32
#define DC_TICKS_FORMAT "%I64d"
#else
#define DC_TICKS_FORMAT "%lld"
#endif
#define C_ARRAY_SIZE(array) (sizeof (array) / sizeof *(array))
typedef struct backend_table_t {
const char *name;
dc_family_t type;
unsigned int model;
} backend_table_t;
typedef struct transport_table_t {
const char *name;
dc_transport_t type;
} transport_table_t;
static const backend_table_t g_backends[] = {
{"solution", DC_FAMILY_SUUNTO_SOLUTION, 0},
{"eon", DC_FAMILY_SUUNTO_EON, 0},
{"vyper", DC_FAMILY_SUUNTO_VYPER, 0x0A},
{"vyper2", DC_FAMILY_SUUNTO_VYPER2, 0x10},
{"d9", DC_FAMILY_SUUNTO_D9, 0x0E},
{"eonsteel", DC_FAMILY_SUUNTO_EONSTEEL, 0},
{"aladin", DC_FAMILY_UWATEC_ALADIN, 0x3F},
{"memomouse", DC_FAMILY_UWATEC_MEMOMOUSE, 0},
{"smart", DC_FAMILY_UWATEC_SMART, 0x10},
{"sensus", DC_FAMILY_REEFNET_SENSUS, 1},
{"sensuspro", DC_FAMILY_REEFNET_SENSUSPRO, 2},
{"sensusultra", DC_FAMILY_REEFNET_SENSUSULTRA, 3},
{"vtpro", DC_FAMILY_OCEANIC_VTPRO, 0x4245},
{"veo250", DC_FAMILY_OCEANIC_VEO250, 0x424C},
{"atom2", DC_FAMILY_OCEANIC_ATOM2, 0x4342},
{"i330r", DC_FAMILY_PELAGIC_I330R, 0x4744},
{"nemo", DC_FAMILY_MARES_NEMO, 0},
{"puck", DC_FAMILY_MARES_PUCK, 7},
{"darwin", DC_FAMILY_MARES_DARWIN, 0},
{"iconhd", DC_FAMILY_MARES_ICONHD, 0x14},
{"ostc", DC_FAMILY_HW_OSTC, 0},
{"frog", DC_FAMILY_HW_FROG, 0},
{"ostc3", DC_FAMILY_HW_OSTC3, 0x0A},
{"edy", DC_FAMILY_CRESSI_EDY, 0x08},
{"leonardo", DC_FAMILY_CRESSI_LEONARDO, 1},
{"goa", DC_FAMILY_CRESSI_GOA, 2},
{"n2ition3", DC_FAMILY_ZEAGLE_N2ITION3, 0},
{"cobalt", DC_FAMILY_ATOMICS_COBALT, 0},
{"predator", DC_FAMILY_SHEARWATER_PREDATOR, 2},
{"petrel", DC_FAMILY_SHEARWATER_PETREL, 3},
{"nitekq", DC_FAMILY_DIVERITE_NITEKQ, 0},
{"aqualand", DC_FAMILY_CITIZEN_AQUALAND, 0},
{"idive", DC_FAMILY_DIVESYSTEM_IDIVE, 0x03},
{"cochran", DC_FAMILY_COCHRAN_COMMANDER, 0},
{"divecomputereu", DC_FAMILY_TECDIVING_DIVECOMPUTEREU, 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},
};
static const transport_table_t g_transports[] = {
{"serial", DC_TRANSPORT_SERIAL},
{"usb", DC_TRANSPORT_USB},
{"usbhid", DC_TRANSPORT_USBHID},
{"irda", DC_TRANSPORT_IRDA},
{"bluetooth", DC_TRANSPORT_BLUETOOTH},
{"ble", DC_TRANSPORT_BLE},
};
const char *
errmsg (dc_status_t rc)
dctool_errmsg (dc_status_t status)
{
switch (rc) {
switch (status) {
case DC_STATUS_SUCCESS:
return "Success";
case DC_STATUS_UNSUPPORTED:
@ -53,14 +142,447 @@ errmsg (dc_status_t rc)
}
}
void
logfunc (dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *msg, void *userdata)
dc_family_t
dctool_family_type (const char *name)
{
const char *loglevels[] = {"NONE", "ERROR", "WARNING", "INFO", "DEBUG", "ALL"};
for (unsigned int i = 0; i < C_ARRAY_SIZE (g_backends); ++i) {
if (strcmp (name, g_backends[i].name) == 0)
return g_backends[i].type;
}
if (loglevel == DC_LOGLEVEL_ERROR || loglevel == DC_LOGLEVEL_WARNING) {
message ("%s: %s [in %s:%d (%s)]\n", loglevels[loglevel], msg, file, line, function);
} else {
message ("%s: %s\n", loglevels[loglevel], msg);
return DC_FAMILY_NULL;
}
const char *
dctool_family_name (dc_family_t type)
{
for (unsigned int i = 0; i < C_ARRAY_SIZE (g_backends); ++i) {
if (g_backends[i].type == type)
return g_backends[i].name;
}
return NULL;
}
unsigned int
dctool_family_model (dc_family_t type)
{
for (unsigned int i = 0; i < C_ARRAY_SIZE (g_backends); ++i) {
if (g_backends[i].type == type)
return g_backends[i].model;
}
return 0;
}
dc_transport_t
dctool_transport_type (const char *name)
{
for (size_t i = 0; i < C_ARRAY_SIZE (g_transports); ++i) {
if (strcmp (name, g_transports[i].name) == 0)
return g_transports[i].type;
}
return DC_TRANSPORT_NONE;
}
const char *
dctool_transport_name (dc_transport_t type)
{
for (size_t i = 0; i < C_ARRAY_SIZE (g_transports); ++i) {
if (g_transports[i].type == type)
return g_transports[i].name;
}
return NULL;
}
dc_transport_t
dctool_transport_default (dc_descriptor_t *descriptor)
{
unsigned int transports = dc_descriptor_get_transports (descriptor);
for (size_t i = 0; i < C_ARRAY_SIZE (g_transports); ++i) {
if (transports & g_transports[i].type)
return g_transports[i].type;
}
return DC_TRANSPORT_NONE;
}
void
dctool_event_cb (dc_device_t *device, dc_event_type_t event, const void *data, void *userdata)
{
const dc_event_progress_t *progress = (const dc_event_progress_t *) data;
const dc_event_devinfo_t *devinfo = (const dc_event_devinfo_t *) data;
const dc_event_clock_t *clock = (const dc_event_clock_t *) data;
const dc_event_vendor_t *vendor = (const dc_event_vendor_t *) data;
switch (event) {
case DC_EVENT_WAITING:
message ("Event: waiting for user action\n");
break;
case DC_EVENT_PROGRESS:
message ("Event: progress %3.2f%% (%u/%u)\n",
100.0 * (double) progress->current / (double) progress->maximum,
progress->current, progress->maximum);
break;
case DC_EVENT_DEVINFO:
message ("Event: model=%u (0x%08x), firmware=%u (0x%08x), serial=%u (0x%08x)\n",
devinfo->model, devinfo->model,
devinfo->firmware, devinfo->firmware,
devinfo->serial, devinfo->serial);
break;
case DC_EVENT_CLOCK:
message ("Event: systime=" DC_TICKS_FORMAT ", devtime=%u\n",
clock->systime, clock->devtime);
break;
case DC_EVENT_VENDOR:
message ("Event: vendor=");
for (unsigned int i = 0; i < vendor->size; ++i)
message ("%02X", vendor->data[i]);
message ("\n");
break;
default:
break;
}
}
dc_status_t
dctool_descriptor_search (dc_descriptor_t **out, const char *name, dc_family_t family, unsigned int model)
{
dc_status_t rc = DC_STATUS_SUCCESS;
dc_iterator_t *iterator = NULL;
rc = dc_descriptor_iterator (&iterator);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error creating the device descriptor iterator.");
return rc;
}
dc_descriptor_t *descriptor = NULL, *current = NULL;
while ((rc = dc_iterator_next (iterator, &descriptor)) == DC_STATUS_SUCCESS) {
if (name) {
const char *vendor = dc_descriptor_get_vendor (descriptor);
const char *product = dc_descriptor_get_product (descriptor);
size_t n = strlen (vendor);
if (strncasecmp (name, vendor, n) == 0 && name[n] == ' ' &&
strcasecmp (name + n + 1, product) == 0)
{
current = descriptor;
break;
} else if (strcasecmp (name, product) == 0) {
current = descriptor;
break;
}
} else {
if (family == dc_descriptor_get_type (descriptor)) {
if (model == dc_descriptor_get_model (descriptor)) {
// Exact match found. Return immediately.
dc_descriptor_free (current);
current = descriptor;
break;
} else {
// Possible match found. Keep searching for an exact match.
// If no exact match is found, the first match is returned.
if (current == NULL) {
current = descriptor;
descriptor = NULL;
}
}
}
}
dc_descriptor_free (descriptor);
}
if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_DONE) {
dc_descriptor_free (current);
dc_iterator_free (iterator);
ERROR ("Error iterating the device descriptors.");
return rc;
}
dc_iterator_free (iterator);
*out = current;
return DC_STATUS_SUCCESS;
}
static unsigned char
hex2dec (unsigned char value)
{
if (value >= '0' && value <= '9')
return value - '0';
else if (value >= 'A' && value <= 'F')
return value - 'A' + 10;
else if (value >= 'a' && value <= 'f')
return value - 'a' + 10;
else
return 0;
}
dc_buffer_t *
dctool_convert_hex2bin (const char *str)
{
// Get the length of the fingerprint data.
size_t nbytes = (str ? strlen (str) / 2 : 0);
if (nbytes == 0)
return NULL;
// Allocate a memory buffer.
dc_buffer_t *buffer = dc_buffer_new (nbytes);
// Convert the hexadecimal string.
for (unsigned int i = 0; i < nbytes; ++i) {
unsigned char msn = hex2dec (str[i * 2 + 0]);
unsigned char lsn = hex2dec (str[i * 2 + 1]);
unsigned char byte = (msn << 4) + lsn;
dc_buffer_append (buffer, &byte, 1);
}
return buffer;
}
void
dctool_file_write (const char *filename, dc_buffer_t *buffer)
{
FILE *fp = NULL;
// Open the file.
if (filename) {
fp = fopen (filename, "wb");
} else {
fp = stdout;
#ifdef _WIN32
// Change from text mode to binary mode.
_setmode (_fileno (fp), _O_BINARY);
#endif
}
if (fp == NULL)
return;
// Write the entire buffer to the file.
fwrite (dc_buffer_get_data (buffer), 1, dc_buffer_get_size (buffer), fp);
// Close the file.
fclose (fp);
}
dc_buffer_t *
dctool_file_read (const char *filename)
{
FILE *fp = NULL;
// Open the file.
if (filename) {
fp = fopen (filename, "rb");
} else {
fp = stdin;
#ifdef _WIN32
// Change from text mode to binary mode.
_setmode (_fileno (fp), _O_BINARY);
#endif
}
if (fp == NULL)
return NULL;
// Allocate a memory buffer.
dc_buffer_t *buffer = dc_buffer_new (0);
// Read the entire file into the buffer.
size_t n = 0;
unsigned char block[1024] = {0};
while ((n = fread (block, 1, sizeof (block), fp)) > 0) {
dc_buffer_append (buffer, block, n);
}
// Close the file.
fclose (fp);
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
dctool_usbhid_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 usbhid device.
dc_iterator_t *iterator = NULL;
dc_usbhid_device_t *device = NULL;
dc_usbhid_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 usbhid device.
status = dc_usbhid_open (&iostream, context, device);
if (status != DC_STATUS_SUCCESS) {
ERROR ("Failed to open the usbhid device.");
goto cleanup;
}
*out = iostream;
cleanup:
dc_usbhid_device_free (device);
return status;
}
static dc_status_t
dctool_irda_open (dc_iostream_t **out, dc_context_t *context, dc_descriptor_t *descriptor, const char *devname)
{
dc_status_t status = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
unsigned int address = 0;
if (devname) {
// Use the address.
address = strtoul(devname, NULL, 0);
} else {
// Discover the device address.
dc_iterator_t *iterator = NULL;
dc_irda_device_t *device = NULL;
dc_irda_iterator_new (&iterator, context, descriptor);
while (dc_iterator_next (iterator, &device) == DC_STATUS_SUCCESS) {
address = dc_irda_device_get_address (device);
dc_irda_device_free (device);
break;
}
dc_iterator_free (iterator);
}
if (address == 0) {
if (devname) {
ERROR ("No valid device address specified.");
} else {
ERROR ("No dive computer found.");
}
status = DC_STATUS_NODEVICE;
goto cleanup;
}
// Open the irda socket.
status = dc_irda_open (&iostream, context, address, 1);
if (status != DC_STATUS_SUCCESS) {
ERROR ("Failed to open the irda socket.");
goto cleanup;
}
*out = iostream;
cleanup:
return status;
}
static dc_status_t
dctool_bluetooth_open (dc_iostream_t **out, dc_context_t *context, dc_descriptor_t *descriptor, const char *devname)
{
dc_status_t status = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
dc_bluetooth_address_t address = 0;
if (devname) {
// Use the address.
address = dc_bluetooth_str2addr(devname);
} else {
// Discover the device address.
dc_iterator_t *iterator = NULL;
dc_bluetooth_device_t *device = NULL;
dc_bluetooth_iterator_new (&iterator, context, descriptor);
while (dc_iterator_next (iterator, &device) == DC_STATUS_SUCCESS) {
address = dc_bluetooth_device_get_address (device);
dc_bluetooth_device_free (device);
break;
}
dc_iterator_free (iterator);
}
if (address == 0) {
if (devname) {
ERROR ("No valid device address specified.");
} else {
ERROR ("No dive computer found.");
}
status = DC_STATUS_NODEVICE;
goto cleanup;
}
// Open the bluetooth socket.
status = dc_bluetooth_open (&iostream, context, address, 0);
if (status != DC_STATUS_SUCCESS) {
ERROR ("Failed to open the bluetooth socket.");
goto cleanup;
}
*out = iostream;
cleanup:
return status;
}
dc_status_t
dctool_iostream_open (dc_iostream_t **iostream, dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport, const char *devname)
{
switch (transport) {
case DC_TRANSPORT_SERIAL:
return dc_serial_open (iostream, context, devname);
case DC_TRANSPORT_USB:
return dctool_usb_open(iostream, context, descriptor);
case DC_TRANSPORT_USBHID:
return dctool_usbhid_open(iostream, context, descriptor);
case DC_TRANSPORT_IRDA:
return dctool_irda_open (iostream, context, descriptor, devname);
case DC_TRANSPORT_BLUETOOTH:
return dctool_bluetooth_open (iostream, context, descriptor, devname);
default:
return DC_STATUS_UNSUPPORTED;
}
}

View File

@ -1,7 +1,7 @@
/*
* libdivecomputer
*
* Copyright (C) 2011 Jef Driesen
* Copyright (C) 2015 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -19,23 +19,58 @@
* MA 02110-1301 USA
*/
#ifndef EXAMPLES_COMMON_H
#define EXAMPLES_COMMON_H
#ifndef DCTOOL_COMMON_H
#define DCTOOL_COMMON_H
#include <libdivecomputer/common.h>
#include <libdivecomputer/context.h>
#include <libdivecomputer/descriptor.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
const char *
errmsg (dc_status_t rc);
dctool_errmsg (dc_status_t status);
dc_family_t
dctool_family_type (const char *name);
const char *
dctool_family_name (dc_family_t type);
unsigned int
dctool_family_model (dc_family_t type);
dc_transport_t
dctool_transport_type (const char *name);
const char *
dctool_transport_name (dc_transport_t type);
dc_transport_t
dctool_transport_default (dc_descriptor_t *descriptor);
void
logfunc (dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *msg, void *userdata);
dctool_event_cb (dc_device_t *device, dc_event_type_t event, const void *data, void *userdata);
dc_status_t
dctool_descriptor_search (dc_descriptor_t **out, const char *name, dc_family_t family, unsigned int model);
dc_buffer_t *
dctool_convert_hex2bin (const char *str);
void
dctool_file_write (const char *filename, dc_buffer_t *buffer);
dc_buffer_t *
dctool_file_read (const char *filename);
dc_status_t
dctool_iostream_open (dc_iostream_t **iostream, dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport, const char *devname);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* EXAMPLES_COMMON_H */
#endif /* DCTOOL_COMMON_H */

View File

@ -1,107 +0,0 @@
/*
* libdivecomputer
*
* Copyright (C) 2009 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#include <stdio.h> // fopen, fwrite, fclose
#include <libdivecomputer/cressi_edy.h>
#include "utils.h"
#include "common.h"
dc_status_t
test_dump_memory (const char* name, const char* filename)
{
dc_context_t *context = NULL;
dc_device_t *device = NULL;
dc_context_new (&context);
dc_context_set_loglevel (context, DC_LOGLEVEL_ALL);
dc_context_set_logfunc (context, logfunc, NULL);
message ("cressi_edy_device_open\n");
dc_status_t rc = cressi_edy_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
dc_buffer_t *buffer = dc_buffer_new (0);
message ("dc_device_dump\n");
rc = dc_device_dump (device, buffer);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
message ("Dumping data\n");
FILE* fp = fopen (filename, "wb");
if (fp != NULL) {
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
fclose (fp);
}
dc_buffer_free (buffer);
message ("dc_device_close\n");
rc = dc_device_close (device);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot close device.");
dc_context_free (context);
return rc;
}
dc_context_free (context);
return DC_STATUS_SUCCESS;
}
int main(int argc, char *argv[])
{
message_set_logfile ("EDY.LOG");
#ifdef _WIN32
const char* name = "COM1";
#else
const char* name = "/dev/ttyS0";
#endif
if (argc > 1) {
name = argv[1];
}
message ("DEVICE=%s\n", name);
dc_status_t a = test_dump_memory (name, "EDY.DMP");
message ("\nSUMMARY\n");
message ("-------\n");
message ("test_dump_memory: %s\n", errmsg (a));
message_set_logfile (NULL);
return 0;
}

View File

@ -1,107 +0,0 @@
/*
* libdivecomputer
*
* Copyright (C) 2013 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#include <stdio.h> // fopen, fwrite, fclose
#include <libdivecomputer/cressi_leonardo.h>
#include "utils.h"
#include "common.h"
dc_status_t
test_dump_memory (const char* name, const char* filename)
{
dc_context_t *context = NULL;
dc_device_t *device = NULL;
dc_context_new (&context);
dc_context_set_loglevel (context, DC_LOGLEVEL_ALL);
dc_context_set_logfunc (context, logfunc, NULL);
message ("cressi_leonardo_device_open\n");
dc_status_t rc = cressi_leonardo_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
dc_buffer_t *buffer = dc_buffer_new (0);
message ("dc_device_dump\n");
rc = dc_device_dump (device, buffer);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
message ("Dumping data\n");
FILE* fp = fopen (filename, "wb");
if (fp != NULL) {
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
fclose (fp);
}
dc_buffer_free (buffer);
message ("dc_device_close\n");
rc = dc_device_close (device);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot close device.");
dc_context_free (context);
return rc;
}
dc_context_free (context);
return DC_STATUS_SUCCESS;
}
int main(int argc, char *argv[])
{
message_set_logfile ("LEONARDO.LOG");
#ifdef _WIN32
const char* name = "COM1";
#else
const char* name = "/dev/ttyS0";
#endif
if (argc > 1) {
name = argv[1];
}
message ("DEVICE=%s\n", name);
dc_status_t a = test_dump_memory (name, "LEONARDO.DMP");
message ("\nSUMMARY\n");
message ("-------\n");
message ("test_dump_memory: %s\n", errmsg (a));
message_set_logfile (NULL);
return 0;
}

319
examples/dctool.c Normal file
View File

@ -0,0 +1,319 @@
/*
* libdivecomputer
*
* Copyright (C) 2015 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
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <libdivecomputer/context.h>
#include <libdivecomputer/descriptor.h>
#include "common.h"
#include "dctool.h"
#include "utils.h"
#if defined(__GLIBC__) || defined(__MINGW32__)
#define RESET 0
#else
#define RESET 1
#endif
#if defined(__GLIBC__) || defined(__MINGW32__) || defined(BSD) || defined(__ANDROID__)
#define NOPERMUTATION "+"
#else
#define NOPERMUTATION ""
#endif
static const dctool_command_t *g_commands[] = {
&dctool_help,
&dctool_version,
&dctool_list,
&dctool_scan,
&dctool_download,
&dctool_dump,
&dctool_parse,
&dctool_read,
&dctool_write,
&dctool_timesync,
&dctool_fwupdate,
NULL
};
static volatile sig_atomic_t g_cancel = 0;
const dctool_command_t *
dctool_command_find (const char *name)
{
if (name == NULL)
return NULL;
size_t i = 0;
while (g_commands[i] != NULL) {
if (strcmp(g_commands[i]->name, name) == 0) {
break;
}
i++;
}
return g_commands[i];
}
void
dctool_command_showhelp (const dctool_command_t *command)
{
if (command == NULL) {
unsigned int maxlength = 0;
for (size_t i = 0; g_commands[i] != NULL; ++i) {
unsigned int length = strlen (g_commands[i]->name);
if (length > maxlength)
maxlength = length;
}
printf (
"A simple command line interface for the libdivecomputer library\n"
"\n"
"Usage:\n"
" dctool [options] <command> [<args>]\n"
"\n"
"Options:\n"
#ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n"
" -d, --device <device> Device name\n"
" -f, --family <family> Device family type\n"
" -m, --model <model> Device model number\n"
" -l, --logfile <logfile> Logfile\n"
" -q, --quiet Quiet mode\n"
" -v, --verbose Verbose mode\n"
#else
" -h Show help message\n"
" -d <device> Device name\n"
" -f <family> Family type\n"
" -m <model> Model number\n"
" -l <logfile> Logfile\n"
" -q Quiet mode\n"
" -v Verbose mode\n"
#endif
"\n"
"Available commands:\n");
for (size_t i = 0; g_commands[i] != NULL; ++i) {
printf (" %-*s%s\n", maxlength + 3, g_commands[i]->name, g_commands[i]->description);
}
printf ("\nSee 'dctool help <command>' for more information on a specific command.\n\n");
} else {
printf ("%s\n\n%s\n", command->description, command->usage);
}
}
int
dctool_cancel_cb (void *userdata)
{
return g_cancel;
}
static void
sighandler (int signum)
{
#ifndef _WIN32
// Restore the default signal handler.
signal (signum, SIG_DFL);
#endif
g_cancel = 1;
}
static void
logfunc (dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *msg, void *userdata)
{
const char *loglevels[] = {"NONE", "ERROR", "WARNING", "INFO", "DEBUG", "ALL"};
if (loglevel == DC_LOGLEVEL_ERROR || loglevel == DC_LOGLEVEL_WARNING) {
message ("%s: %s [in %s:%d (%s)]\n", loglevels[loglevel], msg, file, line, function);
} else {
message ("%s: %s\n", loglevels[loglevel], msg);
}
}
int
main (int argc, char *argv[])
{
int exitcode = EXIT_SUCCESS;
dc_status_t status = DC_STATUS_SUCCESS;
dc_context_t *context = NULL;
dc_descriptor_t *descriptor = NULL;
// Default option values.
unsigned int help = 0;
dc_loglevel_t loglevel = DC_LOGLEVEL_WARNING;
const char *logfile = NULL;
const char *device = NULL;
dc_family_t family = DC_FAMILY_NULL;
unsigned int model = 0;
unsigned int have_family = 0, have_model = 0;
// Parse the command-line options.
int opt = 0;
const char *optstring = NOPERMUTATION "hd:f:m:l:qv";
#ifdef HAVE_GETOPT_LONG
struct option options[] = {
{"help", no_argument, 0, 'h'},
{"device", required_argument, 0, 'd'},
{"family", required_argument, 0, 'f'},
{"model", required_argument, 0, 'm'},
{"logfile", required_argument, 0, 'l'},
{"quiet", no_argument, 0, 'q'},
{"verbose", no_argument, 0, 'v'},
{0, 0, 0, 0 }
};
while ((opt = getopt_long (argc, argv, optstring, options, NULL)) != -1) {
#else
while ((opt = getopt (argc, argv, optstring)) != -1) {
#endif
switch (opt) {
case 'h':
help = 1;
break;
case 'd':
device = optarg;
break;
case 'f':
family = dctool_family_type (optarg);
have_family = 1;
break;
case 'm':
model = strtoul (optarg, NULL, 0);
have_model = 1;
break;
case 'l':
logfile = optarg;
break;
case 'q':
loglevel = DC_LOGLEVEL_NONE;
break;
case 'v':
loglevel++;
break;
default:
return EXIT_FAILURE;
}
}
// Skip the processed arguments.
argc -= optind;
argv += optind;
optind = RESET;
#if defined(HAVE_DECL_OPTRESET) && HAVE_DECL_OPTRESET
optreset = 1;
#endif
// Set the default model number.
if (have_family && !have_model) {
model = dctool_family_model (family);
}
// Translate the help option into a command.
char helpcmd[] = "help";
char *argv_help[] = {helpcmd, NULL, NULL};
if (help || argv[0] == NULL) {
if (argv[0]) {
argv_help[1] = argv[0];
argv = argv_help;
argc = 2;
} else {
argv = argv_help;
argc = 1;
}
}
// Try to find the command.
const dctool_command_t *command = dctool_command_find (argv[0]);
if (command == NULL) {
message ("Unknown command %s.\n", argv[0]);
return EXIT_FAILURE;
}
// Setup the cancel signal handler.
signal (SIGINT, sighandler);
// Initialize the logfile.
message_set_logfile (logfile);
// Initialize a library context.
status = dc_context_new (&context);
if (status != DC_STATUS_SUCCESS) {
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Setup the logging.
dc_context_set_loglevel (context, loglevel);
dc_context_set_logfunc (context, logfunc, NULL);
if (device != NULL || family != DC_FAMILY_NULL) {
// Search for a matching device descriptor.
status = dctool_descriptor_search (&descriptor, device, family, model);
if (status != DC_STATUS_SUCCESS) {
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Fail if no device descriptor found.
if (descriptor == NULL) {
if (device) {
message ("No supported device found: %s\n",
device);
} else {
message ("No supported device found: %s, 0x%X\n",
dctool_family_name (family), model);
}
exitcode = EXIT_FAILURE;
goto cleanup;
}
}
// Check mandatory descriptor arguments.
if (command->config & DCTOOL_CONFIG_DESCRIPTOR && descriptor == NULL) {
message ("No device name or family type specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Execute the command.
exitcode = command->run (argc, argv, context, descriptor);
cleanup:
dc_descriptor_free (descriptor);
dc_context_free (context);
message_set_logfile (NULL);
return exitcode;
}

70
examples/dctool.h Normal file
View File

@ -0,0 +1,70 @@
/*
* libdivecomputer
*
* Copyright (C) 2015 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 DCTOOL_H
#define DCTOOL_H
#include <libdivecomputer/context.h>
#include <libdivecomputer/descriptor.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef enum dctool_config_t {
DCTOOL_CONFIG_NONE = 0,
DCTOOL_CONFIG_DESCRIPTOR = 1,
} dctool_config_t;
typedef struct dctool_command_t {
int (*run) (int argc, char *argv[], dc_context_t *context, dc_descriptor_t *descriptor);
unsigned int config;
const char *name;
const char *description;
const char *usage;
} dctool_command_t;
extern const dctool_command_t dctool_help;
extern const dctool_command_t dctool_version;
extern const dctool_command_t dctool_list;
extern const dctool_command_t dctool_scan;
extern const dctool_command_t dctool_download;
extern const dctool_command_t dctool_dump;
extern const dctool_command_t dctool_parse;
extern const dctool_command_t dctool_read;
extern const dctool_command_t dctool_write;
extern const dctool_command_t dctool_timesync;
extern const dctool_command_t dctool_fwupdate;
const dctool_command_t *
dctool_command_find (const char *name);
void
dctool_command_showhelp (const dctool_command_t *command);
int
dctool_cancel_cb (void *userdata);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* DCTOOL_H */

405
examples/dctool_download.c Normal file
View File

@ -0,0 +1,405 @@
/*
* libdivecomputer
*
* Copyright (C) 2015 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
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <libdivecomputer/context.h>
#include <libdivecomputer/descriptor.h>
#include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h>
#include "dctool.h"
#include "common.h"
#include "output.h"
#include "utils.h"
typedef struct event_data_t {
const char *cachedir;
dc_event_devinfo_t devinfo;
} event_data_t;
typedef struct dive_data_t {
dc_device_t *device;
dc_buffer_t **fingerprint;
unsigned int number;
dctool_output_t *output;
} dive_data_t;
static int
dive_cb (const unsigned char *data, unsigned int size, const unsigned char *fingerprint, unsigned int fsize, void *userdata)
{
dive_data_t *divedata = (dive_data_t *) userdata;
dc_status_t rc = DC_STATUS_SUCCESS;
dc_parser_t *parser = NULL;
divedata->number++;
message ("Dive: number=%u, size=%u, fingerprint=", divedata->number, size);
for (unsigned int i = 0; i < fsize; ++i)
message ("%02X", fingerprint[i]);
message ("\n");
// Keep a copy of the most recent fingerprint. Because dives are
// guaranteed to be downloaded in reverse order, the most recent
// dive is always the first dive.
if (divedata->number == 1) {
dc_buffer_t *fp = dc_buffer_new (fsize);
dc_buffer_append (fp, fingerprint, fsize);
*divedata->fingerprint = fp;
}
// Create the parser.
message ("Creating the parser.\n");
rc = dc_parser_new (&parser, divedata->device, data, size);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error creating the parser.");
goto cleanup;
}
// Parse the dive data.
message ("Parsing the dive data.\n");
rc = dctool_output_write (divedata->output, parser, data, size, fingerprint, fsize);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error parsing the dive data.");
goto cleanup;
}
cleanup:
dc_parser_destroy (parser);
return 1;
}
static void
event_cb (dc_device_t *device, dc_event_type_t event, const void *data, void *userdata)
{
const dc_event_devinfo_t *devinfo = (const dc_event_devinfo_t *) data;
event_data_t *eventdata = (event_data_t *) userdata;
// Forward to the default event handler.
dctool_event_cb (device, event, data, userdata);
switch (event) {
case DC_EVENT_DEVINFO:
// Load the fingerprint from the cache. If there is no
// fingerprint present in the cache, a NULL buffer is returned,
// and the registered fingerprint will be cleared.
if (eventdata->cachedir) {
char filename[1024] = {0};
dc_family_t family = DC_FAMILY_NULL;
dc_buffer_t *fingerprint = NULL;
// Generate the fingerprint filename.
family = dc_device_get_type (device);
snprintf (filename, sizeof (filename), "%s/%s-%08X.bin",
eventdata->cachedir, dctool_family_name (family), devinfo->serial);
// Read the fingerprint file.
fingerprint = dctool_file_read (filename);
// Register the fingerprint data.
dc_device_set_fingerprint (device,
dc_buffer_get_data (fingerprint),
dc_buffer_get_size (fingerprint));
// Free the buffer again.
dc_buffer_free (fingerprint);
}
// Keep a copy of the event data. It will be used for generating
// the fingerprint filename again after a (successful) download.
eventdata->devinfo = *devinfo;
break;
default:
break;
}
}
static dc_status_t
download (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport, const char *devname, const char *cachedir, dc_buffer_t *fingerprint, dctool_output_t *output)
{
dc_status_t rc = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
dc_device_t *device = NULL;
dc_buffer_t *ofingerprint = NULL;
// Open the I/O stream.
message ("Opening the I/O stream (%s, %s).\n",
dctool_transport_name (transport),
devname ? devname : "null");
rc = dctool_iostream_open (&iostream, context, descriptor, transport, devname);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the I/O stream.");
goto cleanup;
}
// Open the device.
message ("Opening the device (%s %s).\n",
dc_descriptor_get_vendor (descriptor),
dc_descriptor_get_product (descriptor));
rc = dc_device_open (&device, context, descriptor, iostream);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the device.");
goto cleanup;
}
// Initialize the event data.
event_data_t eventdata = {0};
if (fingerprint) {
eventdata.cachedir = NULL;
} else {
eventdata.cachedir = cachedir;
}
// Register the event handler.
message ("Registering the event handler.\n");
int events = DC_EVENT_WAITING | DC_EVENT_PROGRESS | DC_EVENT_DEVINFO | DC_EVENT_CLOCK | DC_EVENT_VENDOR;
rc = dc_device_set_events (device, events, event_cb, &eventdata);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error registering the event handler.");
goto cleanup;
}
// Register the cancellation handler.
message ("Registering the cancellation handler.\n");
rc = dc_device_set_cancel (device, dctool_cancel_cb, NULL);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error registering the cancellation handler.");
goto cleanup;
}
// Register the fingerprint data.
if (fingerprint) {
message ("Registering the fingerprint data.\n");
rc = dc_device_set_fingerprint (device, dc_buffer_get_data (fingerprint), dc_buffer_get_size (fingerprint));
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error registering the fingerprint data.");
goto cleanup;
}
}
// Initialize the dive data.
dive_data_t divedata = {0};
divedata.device = device;
divedata.fingerprint = &ofingerprint;
divedata.number = 0;
divedata.output = output;
// Download the dives.
message ("Downloading the dives.\n");
rc = dc_device_foreach (device, dive_cb, &divedata);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error downloading the dives.");
goto cleanup;
}
// Store the fingerprint data.
if (cachedir && ofingerprint) {
char filename[1024] = {0};
dc_family_t family = DC_FAMILY_NULL;
// Generate the fingerprint filename.
family = dc_device_get_type (device);
snprintf (filename, sizeof (filename), "%s/%s-%08X.bin",
cachedir, dctool_family_name (family), eventdata.devinfo.serial);
// Write the fingerprint file.
dctool_file_write (filename, ofingerprint);
}
cleanup:
dc_buffer_free (ofingerprint);
dc_device_close (device);
dc_iostream_close (iostream);
return rc;
}
static int
dctool_download_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t *descriptor)
{
int exitcode = EXIT_SUCCESS;
dc_status_t status = DC_STATUS_SUCCESS;
dc_buffer_t *fingerprint = NULL;
dctool_output_t *output = NULL;
dctool_units_t units = DCTOOL_UNITS_METRIC;
dc_transport_t transport = dctool_transport_default (descriptor);
// Default option values.
unsigned int help = 0;
const char *fphex = NULL;
const char *filename = NULL;
const char *cachedir = NULL;
const char *format = "xml";
// Parse the command-line options.
int opt = 0;
const char *optstring = "ht:o:p:c:f:u:";
#ifdef HAVE_GETOPT_LONG
struct option options[] = {
{"help", no_argument, 0, 'h'},
{"transport", required_argument, 0, 't'},
{"output", required_argument, 0, 'o'},
{"fingerprint", required_argument, 0, 'p'},
{"cache", required_argument, 0, 'c'},
{"format", required_argument, 0, 'f'},
{"units", required_argument, 0, 'u'},
{0, 0, 0, 0 }
};
while ((opt = getopt_long (argc, argv, optstring, options, NULL)) != -1) {
#else
while ((opt = getopt (argc, argv, optstring)) != -1) {
#endif
switch (opt) {
case 'h':
help = 1;
break;
case 't':
transport = dctool_transport_type (optarg);
break;
case 'o':
filename = optarg;
break;
case 'p':
fphex = optarg;
break;
case 'c':
cachedir = optarg;
break;
case 'f':
format = optarg;
break;
case 'u':
if (strcmp (optarg, "metric") == 0)
units = DCTOOL_UNITS_METRIC;
if (strcmp (optarg, "imperial") == 0)
units = DCTOOL_UNITS_IMPERIAL;
break;
default:
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
// Show help message.
if (help) {
dctool_command_showhelp (&dctool_download);
return EXIT_SUCCESS;
}
// Check the transport type.
if (transport == DC_TRANSPORT_NONE) {
message ("No valid transport type specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Convert the fingerprint to binary.
fingerprint = dctool_convert_hex2bin (fphex);
// Create the output.
if (strcasecmp(format, "raw") == 0) {
output = dctool_raw_output_new (filename);
} else if (strcasecmp(format, "xml") == 0) {
output = dctool_xml_output_new (filename, units);
} else {
message ("Unknown output format: %s\n", format);
exitcode = EXIT_FAILURE;
goto cleanup;
}
if (output == NULL) {
message ("Failed to create the output.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Download the dives.
status = download (context, descriptor, transport, argv[0], cachedir, fingerprint, output);
if (status != DC_STATUS_SUCCESS) {
message ("ERROR: %s\n", dctool_errmsg (status));
exitcode = EXIT_FAILURE;
goto cleanup;
}
cleanup:
dctool_output_free (output);
dc_buffer_free (fingerprint);
return exitcode;
}
const dctool_command_t dctool_download = {
dctool_download_run,
DCTOOL_CONFIG_DESCRIPTOR,
"download",
"Download the dives",
"Usage:\n"
" dctool download [options] <devname>\n"
"\n"
"Options:\n"
#ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n"
" -t, --transport <name> Transport type\n"
" -o, --output <filename> Output filename\n"
" -p, --fingerprint <data> Fingerprint data (hexadecimal)\n"
" -c, --cache <directory> Cache directory\n"
" -f, --format <format> Output format\n"
" -u, --units <units> Set units (metric or imperial)\n"
#else
" -h Show help message\n"
" -t <transport> Transport type\n"
" -o <filename> Output filename\n"
" -p <fingerprint> Fingerprint data (hexadecimal)\n"
" -c <directory> Cache directory\n"
" -f <format> Output format\n"
" -u <units> Set units (metric or imperial)\n"
#endif
"\n"
"Supported output formats:\n"
"\n"
" XML (default)\n"
"\n"
" All dives are exported to a single xml file.\n"
"\n"
" RAW\n"
"\n"
" Each dive is exported to a raw (binary) file. To output multiple\n"
" files, the filename is interpreted as a template and should\n"
" contain one or more placeholders.\n"
"\n"
"Supported template placeholders:\n"
"\n"
" %f Fingerprint (hexadecimal format)\n"
" %n Number (4 digits)\n"
" %t Timestamp (basic ISO 8601 date/time format)\n"
};

218
examples/dctool_dump.c Normal file
View File

@ -0,0 +1,218 @@
/*
* libdivecomputer
*
* Copyright (C) 2015 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
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <libdivecomputer/context.h>
#include <libdivecomputer/descriptor.h>
#include <libdivecomputer/device.h>
#include "dctool.h"
#include "common.h"
#include "utils.h"
static dc_status_t
dump (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport, const char *devname, dc_buffer_t *fingerprint, dc_buffer_t *buffer)
{
dc_status_t rc = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
dc_device_t *device = NULL;
// Open the I/O stream.
message ("Opening the I/O stream (%s, %s).\n",
dctool_transport_name (transport),
devname ? devname : "null");
rc = dctool_iostream_open (&iostream, context, descriptor, transport, devname);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the I/O stream.");
goto cleanup;
}
// Open the device.
message ("Opening the device (%s %s).\n",
dc_descriptor_get_vendor (descriptor),
dc_descriptor_get_product (descriptor));
rc = dc_device_open (&device, context, descriptor, iostream);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the device.");
goto cleanup;
}
// Register the event handler.
message ("Registering the event handler.\n");
int events = DC_EVENT_WAITING | DC_EVENT_PROGRESS | DC_EVENT_DEVINFO | DC_EVENT_CLOCK | DC_EVENT_VENDOR;
rc = dc_device_set_events (device, events, dctool_event_cb, NULL);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error registering the event handler.");
goto cleanup;
}
// Register the cancellation handler.
message ("Registering the cancellation handler.\n");
rc = dc_device_set_cancel (device, dctool_cancel_cb, NULL);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error registering the cancellation handler.");
goto cleanup;
}
// Register the fingerprint data.
if (fingerprint) {
message ("Registering the fingerprint data.\n");
rc = dc_device_set_fingerprint (device, dc_buffer_get_data (fingerprint), dc_buffer_get_size (fingerprint));
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error registering the fingerprint data.");
goto cleanup;
}
}
// Download the memory dump.
message ("Downloading the memory dump.\n");
rc = dc_device_dump (device, buffer);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error downloading the memory dump.");
goto cleanup;
}
cleanup:
dc_device_close (device);
dc_iostream_close (iostream);
return rc;
}
static int
dctool_dump_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t *descriptor)
{
int exitcode = EXIT_SUCCESS;
dc_status_t status = DC_STATUS_SUCCESS;
dc_buffer_t *fingerprint = NULL;
dc_buffer_t *buffer = NULL;
dc_transport_t transport = dctool_transport_default (descriptor);
// Default option values.
unsigned int help = 0;
const char *fphex = NULL;
const char *filename = NULL;
// Parse the command-line options.
int opt = 0;
const char *optstring = "ht:o:p:";
#ifdef HAVE_GETOPT_LONG
struct option options[] = {
{"help", no_argument, 0, 'h'},
{"transport", required_argument, 0, 't'},
{"output", required_argument, 0, 'o'},
{"fingerprint", required_argument, 0, 'p'},
{0, 0, 0, 0 }
};
while ((opt = getopt_long (argc, argv, optstring, options, NULL)) != -1) {
#else
while ((opt = getopt (argc, argv, optstring)) != -1) {
#endif
switch (opt) {
case 'h':
help = 1;
break;
case 't':
transport = dctool_transport_type (optarg);
break;
case 'o':
filename = optarg;
break;
case 'p':
fphex = optarg;
break;
default:
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
// Show help message.
if (help) {
dctool_command_showhelp (&dctool_dump);
return EXIT_SUCCESS;
}
// Check the transport type.
if (transport == DC_TRANSPORT_NONE) {
message ("No valid transport type specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Convert the fingerprint to binary.
fingerprint = dctool_convert_hex2bin (fphex);
// Allocate a memory buffer.
buffer = dc_buffer_new (0);
// Download the memory dump.
status = dump (context, descriptor, transport, argv[0], fingerprint, buffer);
if (status != DC_STATUS_SUCCESS) {
message ("ERROR: %s\n", dctool_errmsg (status));
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Write the memory dump to disk.
dctool_file_write (filename, buffer);
cleanup:
dc_buffer_free (buffer);
dc_buffer_free (fingerprint);
return exitcode;
}
const dctool_command_t dctool_dump = {
dctool_dump_run,
DCTOOL_CONFIG_DESCRIPTOR,
"dump",
"Download a memory dump",
"Usage:\n"
" dctool dump [options] <devname>\n"
"\n"
"Options:\n"
#ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n"
" -t, --transport <name> Transport type\n"
" -o, --output <filename> Output filename\n"
" -p, --fingerprint <data> Fingerprint data (hexadecimal)\n"
#else
" -h Show help message\n"
" -t <transport> Transport type\n"
" -o <filename> Output filename\n"
" -p <fingerprint> Fingerprint data (hexadecimal)\n"
#endif
};

210
examples/dctool_fwupdate.c Normal file
View File

@ -0,0 +1,210 @@
/*
* libdivecomputer
*
* Copyright (C) 2015 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
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <libdivecomputer/context.h>
#include <libdivecomputer/descriptor.h>
#include <libdivecomputer/device.h>
#include <libdivecomputer/hw_ostc.h>
#include <libdivecomputer/hw_ostc3.h>
#include <libdivecomputer/divesystem_idive.h>
#include "dctool.h"
#include "common.h"
#include "utils.h"
static dc_status_t
fwupdate (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport, const char *devname, const char *hexfile)
{
dc_status_t rc = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
dc_device_t *device = NULL;
// Open the I/O stream.
message ("Opening the I/O stream (%s, %s).\n",
dctool_transport_name (transport),
devname ? devname : "null");
rc = dctool_iostream_open (&iostream, context, descriptor, transport, devname);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the I/O stream.");
goto cleanup;
}
// Open the device.
message ("Opening the device (%s %s).\n",
dc_descriptor_get_vendor (descriptor),
dc_descriptor_get_product (descriptor));
rc = dc_device_open (&device, context, descriptor, iostream);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the device.");
goto cleanup;
}
// Register the event handler.
message ("Registering the event handler.\n");
int events = DC_EVENT_PROGRESS;
rc = dc_device_set_events (device, events, dctool_event_cb, NULL);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error registering the event handler.");
goto cleanup;
}
// Register the cancellation handler.
message ("Registering the cancellation handler.\n");
rc = dc_device_set_cancel (device, dctool_cancel_cb, NULL);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error registering the cancellation handler.");
goto cleanup;
}
// Update the firmware.
message ("Updating the firmware.\n");
switch (dc_device_get_type (device)) {
case DC_FAMILY_HW_OSTC:
rc = hw_ostc_device_fwupdate (device, hexfile);
break;
case DC_FAMILY_HW_OSTC3:
rc = hw_ostc3_device_fwupdate (device, hexfile);
break;
case DC_FAMILY_DIVESYSTEM_IDIVE:
rc = divesystem_idive_device_fwupdate (device, hexfile);
break;
default:
rc = DC_STATUS_UNSUPPORTED;
break;
}
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error updating the firmware.");
goto cleanup;
}
cleanup:
dc_device_close (device);
dc_iostream_close (iostream);
return rc;
}
static int
dctool_fwupdate_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t *descriptor)
{
int exitcode = EXIT_SUCCESS;
dc_status_t status = DC_STATUS_SUCCESS;
dc_transport_t transport = dctool_transport_default (descriptor);
// Default option values.
unsigned int help = 0;
const char *filename = NULL;
// Parse the command-line options.
int opt = 0;
const char *optstring = "ht:f:";
#ifdef HAVE_GETOPT_LONG
struct option options[] = {
{"help", no_argument, 0, 'h'},
{"transport", required_argument, 0, 't'},
{"firmware", required_argument, 0, 'f'},
{0, 0, 0, 0 }
};
while ((opt = getopt_long (argc, argv, optstring, options, NULL)) != -1) {
#else
while ((opt = getopt (argc, argv, optstring)) != -1) {
#endif
switch (opt) {
case 'f':
filename = optarg;
break;
case 't':
transport = dctool_transport_type (optarg);
break;
case 'h':
help = 1;
break;
default:
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
// Show help message.
if (help) {
dctool_command_showhelp (&dctool_fwupdate);
return EXIT_SUCCESS;
}
// Check the transport type.
if (transport == DC_TRANSPORT_NONE) {
message ("No valid transport type specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Check mandatory arguments.
if (!filename) {
message ("No firmware file specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Update the firmware.
status = fwupdate (context, descriptor, transport, argv[0], filename);
if (status != DC_STATUS_SUCCESS) {
message ("ERROR: %s\n", dctool_errmsg (status));
exitcode = EXIT_FAILURE;
goto cleanup;
}
cleanup:
return exitcode;
}
const dctool_command_t dctool_fwupdate = {
dctool_fwupdate_run,
DCTOOL_CONFIG_DESCRIPTOR,
"fwupdate",
"Update the firmware",
"Usage:\n"
" dctool fwupdate [options]\n"
"\n"
"Options:\n"
#ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n"
" -t, --transport <name> Transport type\n"
" -f, --firmware <filename> Firmware filename\n"
#else
" -h Show help message\n"
" -t <transport> Transport type\n"
" -f <filename> Firmware filename\n"
#endif
};

107
examples/dctool_help.c Normal file
View File

@ -0,0 +1,107 @@
/*
* libdivecomputer
*
* Copyright (C) 2015 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
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <libdivecomputer/context.h>
#include <libdivecomputer/descriptor.h>
#include "dctool.h"
#include "utils.h"
static int
dctool_help_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t *descriptor)
{
// Default option values.
unsigned int help = 0;
// Parse the command-line options.
int opt = 0;
const char *optstring = "h";
#ifdef HAVE_GETOPT_LONG
struct option options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0 }
};
while ((opt = getopt_long (argc, argv, optstring, options, NULL)) != -1) {
#else
while ((opt = getopt (argc, argv, optstring)) != -1) {
#endif
switch (opt) {
case 'h':
help = 1;
break;
default:
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
// Show help message.
if (help) {
dctool_command_showhelp (&dctool_help);
return EXIT_SUCCESS;
}
// Try to find the command.
const dctool_command_t *command = NULL;
if (argv[0] != NULL) {
command = dctool_command_find (argv[0]);
if (command == NULL) {
message ("Unknown command %s.\n", argv[0]);
return EXIT_FAILURE;
}
}
// Show help message for the command.
dctool_command_showhelp (command);
return EXIT_SUCCESS;
}
const dctool_command_t dctool_help = {
dctool_help_run,
DCTOOL_CONFIG_NONE,
"help",
"Show basic help instructions",
"Usage:\n"
" dctool help [options] [<command>]\n"
"\n"
"Options:\n"
#ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n"
#else
" -h Show help message\n"
#endif
};

105
examples/dctool_list.c Normal file
View File

@ -0,0 +1,105 @@
/*
* libdivecomputer
*
* Copyright (C) 2015 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
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <libdivecomputer/context.h>
#include <libdivecomputer/descriptor.h>
#include <libdivecomputer/iterator.h>
#include "dctool.h"
static int
dctool_list_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t *dummy)
{
// Default option values.
unsigned int help = 0;
// Parse the command-line options.
int opt = 0;
const char *optstring = "h";
#ifdef HAVE_GETOPT_LONG
struct option options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0 }
};
while ((opt = getopt_long (argc, argv, optstring, options, NULL)) != -1) {
#else
while ((opt = getopt (argc, argv, optstring)) != -1) {
#endif
switch (opt) {
case 'h':
help = 1;
break;
default:
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
// Show help message.
if (help) {
dctool_command_showhelp (&dctool_list);
return EXIT_SUCCESS;
}
dc_iterator_t *iterator = NULL;
dc_descriptor_t *descriptor = NULL;
dc_descriptor_iterator (&iterator);
while (dc_iterator_next (iterator, &descriptor) == DC_STATUS_SUCCESS) {
printf ("%s %s\n",
dc_descriptor_get_vendor (descriptor),
dc_descriptor_get_product (descriptor));
dc_descriptor_free (descriptor);
}
dc_iterator_free (iterator);
return EXIT_SUCCESS;
}
const dctool_command_t dctool_list = {
dctool_list_run,
DCTOOL_CONFIG_NONE,
"list",
"List supported devices",
"Usage:\n"
" dctool list [options]\n"
"\n"
"Options:\n"
#ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n"
#else
" -h Show help message\n"
#endif
};

207
examples/dctool_parse.c Normal file
View File

@ -0,0 +1,207 @@
/*
* libdivecomputer
*
* Copyright (C) 2015 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
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <libdivecomputer/context.h>
#include <libdivecomputer/descriptor.h>
#include <libdivecomputer/parser.h>
#include "dctool.h"
#include "output.h"
#include "common.h"
#include "utils.h"
#define REACTPROWHITE 0x4354
static dc_status_t
parse (dc_buffer_t *buffer, dc_context_t *context, dc_descriptor_t *descriptor, unsigned int devtime, dc_ticks_t systime, dctool_output_t *output)
{
dc_status_t rc = DC_STATUS_SUCCESS;
dc_parser_t *parser = NULL;
unsigned char *data = dc_buffer_get_data (buffer);
unsigned int size = dc_buffer_get_size (buffer);
// Create the parser.
message ("Creating the parser.\n");
rc = dc_parser_new2 (&parser, context, descriptor, data, size);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error creating the parser.");
goto cleanup;
}
// Set the clock.
message ("Setting the clock.\n");
rc = dc_parser_set_clock (parser, devtime, systime);
if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) {
ERROR ("Error setting the clock.");
goto cleanup;
}
// Parse the dive data.
message ("Parsing the dive data.\n");
rc = dctool_output_write (output, parser, data, size, NULL, 0);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error parsing the dive data.");
goto cleanup;
}
cleanup:
dc_parser_destroy (parser);
return rc;
}
static int
dctool_parse_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t *descriptor)
{
// Default values.
int exitcode = EXIT_SUCCESS;
dc_status_t status = DC_STATUS_SUCCESS;
dc_buffer_t *buffer = NULL;
dctool_output_t *output = NULL;
dctool_units_t units = DCTOOL_UNITS_METRIC;
// Default option values.
unsigned int help = 0;
const char *filename = NULL;
unsigned int devtime = 0;
dc_ticks_t systime = 0;
// Parse the command-line options.
int opt = 0;
const char *optstring = "ho:d:s:u:";
#ifdef HAVE_GETOPT_LONG
struct option options[] = {
{"help", no_argument, 0, 'h'},
{"output", required_argument, 0, 'o'},
{"devtime", required_argument, 0, 'd'},
{"systime", required_argument, 0, 's'},
{"units", required_argument, 0, 'u'},
{0, 0, 0, 0 }
};
while ((opt = getopt_long (argc, argv, optstring, options, NULL)) != -1) {
#else
while ((opt = getopt (argc, argv, optstring)) != -1) {
#endif
switch (opt) {
case 'h':
help = 1;
break;
case 'o':
filename = optarg;
break;
case 'd':
devtime = strtoul (optarg, NULL, 0);
break;
case 's':
systime = strtoll (optarg, NULL, 0);
break;
case 'u':
if (strcmp (optarg, "metric") == 0)
units = DCTOOL_UNITS_METRIC;
if (strcmp (optarg, "imperial") == 0)
units = DCTOOL_UNITS_IMPERIAL;
break;
default:
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
// Show help message.
if (help) {
dctool_command_showhelp (&dctool_parse);
return EXIT_SUCCESS;
}
// Create the output.
output = dctool_xml_output_new (filename, units);
if (output == NULL) {
message ("Failed to create the output.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
for (int i = 0; i < argc; ++i) {
// Read the input file.
buffer = dctool_file_read (argv[i]);
if (buffer == NULL) {
message ("Failed to open the input file.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Parse the dive.
status = parse (buffer, context, descriptor, devtime, systime, output);
if (status != DC_STATUS_SUCCESS) {
message ("ERROR: %s\n", dctool_errmsg (status));
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Cleanup.
dc_buffer_free (buffer);
buffer = NULL;
}
cleanup:
dc_buffer_free (buffer);
dctool_output_free (output);
return exitcode;
}
const dctool_command_t dctool_parse = {
dctool_parse_run,
DCTOOL_CONFIG_DESCRIPTOR,
"parse",
"Parse previously downloaded dives",
"Usage:\n"
" dctool parse [options] <filename>\n"
"\n"
"Options:\n"
#ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n"
" -o, --output <filename> Output filename\n"
" -d, --devtime <timestamp> Device time\n"
" -s, --systime <timestamp> System time\n"
" -u, --units <units> Set units (metric or imperial)\n"
#else
" -h Show help message\n"
" -o <filename> Output filename\n"
" -d <devtime> Device time\n"
" -s <systime> System time\n"
" -u <units> Set units (metric or imperial)\n"
#endif
};

224
examples/dctool_read.c Normal file
View File

@ -0,0 +1,224 @@
/*
* libdivecomputer
*
* Copyright (C) 2015 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
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <libdivecomputer/context.h>
#include <libdivecomputer/descriptor.h>
#include <libdivecomputer/device.h>
#include "dctool.h"
#include "common.h"
#include "utils.h"
static dc_status_t
doread (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport, const char *devname, unsigned int address, dc_buffer_t *buffer)
{
dc_status_t rc = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
dc_device_t *device = NULL;
// Open the I/O stream.
message ("Opening the I/O stream (%s, %s).\n",
dctool_transport_name (transport),
devname ? devname : "null");
rc = dctool_iostream_open (&iostream, context, descriptor, transport, devname);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the I/O stream.");
goto cleanup;
}
// Open the device.
message ("Opening the device (%s %s).\n",
dc_descriptor_get_vendor (descriptor),
dc_descriptor_get_product (descriptor));
rc = dc_device_open (&device, context, descriptor, iostream);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the device.");
goto cleanup;
}
// Register the event handler.
message ("Registering the event handler.\n");
int events = DC_EVENT_WAITING | DC_EVENT_PROGRESS | DC_EVENT_DEVINFO | DC_EVENT_CLOCK | DC_EVENT_VENDOR;
rc = dc_device_set_events (device, events, dctool_event_cb, NULL);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error registering the event handler.");
goto cleanup;
}
// Register the cancellation handler.
message ("Registering the cancellation handler.\n");
rc = dc_device_set_cancel (device, dctool_cancel_cb, NULL);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error registering the cancellation handler.");
goto cleanup;
}
// Read data from the internal memory.
message ("Reading data from the internal memory.\n");
rc = dc_device_read (device, address, dc_buffer_get_data (buffer), dc_buffer_get_size (buffer));
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error reading from the internal memory.");
goto cleanup;
}
cleanup:
dc_device_close (device);
dc_iostream_close (iostream);
return rc;
}
static int
dctool_read_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t *descriptor)
{
int exitcode = EXIT_SUCCESS;
dc_status_t status = DC_STATUS_SUCCESS;
dc_buffer_t *buffer = NULL;
dc_transport_t transport = dctool_transport_default (descriptor);
// Default option values.
unsigned int help = 0;
const char *filename = NULL;
unsigned int address = 0, have_address = 0;
unsigned int count = 0, have_count = 0;
// Parse the command-line options.
int opt = 0;
const char *optstring = "ht:a:c:o:";
#ifdef HAVE_GETOPT_LONG
struct option options[] = {
{"help", no_argument, 0, 'h'},
{"transport", required_argument, 0, 't'},
{"address", required_argument, 0, 'a'},
{"count", required_argument, 0, 'c'},
{"output", required_argument, 0, 'o'},
{0, 0, 0, 0 }
};
while ((opt = getopt_long (argc, argv, optstring, options, NULL)) != -1) {
#else
while ((opt = getopt (argc, argv, optstring)) != -1) {
#endif
switch (opt) {
case 'h':
help = 1;
break;
case 't':
transport = dctool_transport_type (optarg);
break;
case 'a':
address = strtoul (optarg, NULL, 0);
have_address = 1;
break;
case 'c':
count = strtoul (optarg, NULL, 0);
have_count = 1;
break;
case 'o':
filename = optarg;
break;
default:
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
// Show help message.
if (help) {
dctool_command_showhelp (&dctool_read);
return EXIT_SUCCESS;
}
// Check the transport type.
if (transport == DC_TRANSPORT_NONE) {
message ("No valid transport type specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Check mandatory arguments.
if (!have_address || !have_count) {
message ("No memory address or byte count specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Allocate a memory buffer.
buffer = dc_buffer_new (count);
dc_buffer_resize (buffer, count);
if (buffer == NULL) {
message ("Failed to allocate a memory buffer.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Read data from the internal memory.
status = doread (context, descriptor, transport, argv[0], address, buffer);
if (status != DC_STATUS_SUCCESS) {
message ("ERROR: %s\n", dctool_errmsg (status));
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Write the buffer to file.
dctool_file_write (filename, buffer);
cleanup:
dc_buffer_free (buffer);
return exitcode;
}
const dctool_command_t dctool_read = {
dctool_read_run,
DCTOOL_CONFIG_DESCRIPTOR,
"read",
"Read data from the internal memory",
"Usage:\n"
" dctool read [options] <devname>\n"
"\n"
"Options:\n"
#ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n"
" -t, --transport <name> Transport type\n"
" -a, --address <address> Memory address\n"
" -c, --count <count> Number of bytes\n"
" -o, --output <filename> Output filename\n"
#else
" -h Show help message\n"
" -t <transport> Transport type\n"
" -a <address> Memory address\n"
" -c <count> Number of bytes\n"
" -o <filename> Output filename\n"
#endif
};

202
examples/dctool_scan.c Normal file
View File

@ -0,0 +1,202 @@
/*
* libdivecomputer
*
* Copyright (C) 2017 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <libdivecomputer/context.h>
#include <libdivecomputer/descriptor.h>
#include <libdivecomputer/iterator.h>
#include <libdivecomputer/serial.h>
#include <libdivecomputer/irda.h>
#include <libdivecomputer/bluetooth.h>
#include <libdivecomputer/usb.h>
#include <libdivecomputer/usbhid.h>
#include "dctool.h"
#include "common.h"
#include "utils.h"
static dc_status_t
scan (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport)
{
dc_status_t status = DC_STATUS_SUCCESS;
dc_iterator_t *iterator = NULL;
// Create the device iterator.
switch (transport) {
case DC_TRANSPORT_SERIAL:
status = dc_serial_iterator_new (&iterator, context, descriptor);
break;
case DC_TRANSPORT_IRDA:
status = dc_irda_iterator_new (&iterator, context, descriptor);
break;
case DC_TRANSPORT_BLUETOOTH:
status = dc_bluetooth_iterator_new (&iterator, context, descriptor);
break;
case DC_TRANSPORT_USB:
status = dc_usb_iterator_new (&iterator, context, descriptor);
break;
case DC_TRANSPORT_USBHID:
status = dc_usbhid_iterator_new (&iterator, context, descriptor);
break;
default:
status = DC_STATUS_UNSUPPORTED;
break;
}
if (status != DC_STATUS_SUCCESS) {
ERROR ("Failed to create the device iterator.");
goto cleanup;
}
// Enumerate the devices.
void *device = NULL;
while ((status = dc_iterator_next (iterator, &device)) == DC_STATUS_SUCCESS) {
char buffer[DC_BLUETOOTH_SIZE];
switch (transport) {
case DC_TRANSPORT_SERIAL:
printf ("%s\n", dc_serial_device_get_name (device));
dc_serial_device_free (device);
break;
case DC_TRANSPORT_IRDA:
printf ("%08x\t%s\n", dc_irda_device_get_address (device), dc_irda_device_get_name (device));
dc_irda_device_free (device);
break;
case DC_TRANSPORT_BLUETOOTH:
printf ("%s\t%s\n",
dc_bluetooth_addr2str(dc_bluetooth_device_get_address (device), buffer, sizeof(buffer)),
dc_bluetooth_device_get_name (device));
dc_bluetooth_device_free (device);
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:
printf ("%04x:%04x\n", dc_usbhid_device_get_vid (device), dc_usbhid_device_get_pid (device));
dc_usbhid_device_free (device);
break;
default:
break;
}
}
if (status != DC_STATUS_SUCCESS && status != DC_STATUS_DONE) {
ERROR ("Failed to enumerate the devices.");
goto cleanup;
}
status = DC_STATUS_SUCCESS;
cleanup:
dc_iterator_free (iterator);
return status;
}
static int
dctool_scan_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t *descriptor)
{
int exitcode = EXIT_SUCCESS;
dc_status_t status = DC_STATUS_SUCCESS;
// Default option values.
unsigned int help = 0;
dc_transport_t transport = dctool_transport_default (descriptor);
// Parse the command-line options.
int opt = 0;
const char *optstring = "ht:";
#ifdef HAVE_GETOPT_LONG
struct option options[] = {
{"help", no_argument, 0, 'h'},
{"transport", required_argument, 0, 't'},
{0, 0, 0, 0 }
};
while ((opt = getopt_long (argc, argv, optstring, options, NULL)) != -1) {
#else
while ((opt = getopt (argc, argv, optstring)) != -1) {
#endif
switch (opt) {
case 'h':
help = 1;
break;
case 't':
transport = dctool_transport_type (optarg);
break;
default:
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
// Show help message.
if (help) {
dctool_command_showhelp (&dctool_scan);
return EXIT_SUCCESS;
}
// Check the transport type.
if (transport == DC_TRANSPORT_NONE) {
message ("No valid transport type specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Scan for supported devices.
status = scan (context, descriptor, transport);
if (status != DC_STATUS_SUCCESS) {
message ("ERROR: %s\n", dctool_errmsg (status));
exitcode = EXIT_FAILURE;
goto cleanup;
}
cleanup:
return exitcode;
}
const dctool_command_t dctool_scan = {
dctool_scan_run,
DCTOOL_CONFIG_NONE,
"scan",
"Scan for supported devices",
"Usage:\n"
" dctool scan [options]\n"
"\n"
"Options:\n"
#ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n"
" -t, --transport <name> Transport type\n"
#else
" -h Show help message\n"
" -t <transport> Transport type\n"
#endif
};

189
examples/dctool_timesync.c Normal file
View File

@ -0,0 +1,189 @@
/*
* libdivecomputer
*
* Copyright (C) 2017 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <libdivecomputer/context.h>
#include <libdivecomputer/descriptor.h>
#include <libdivecomputer/device.h>
#include "dctool.h"
#include "common.h"
#include "utils.h"
static dc_status_t
do_timesync (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport, const char *devname, const dc_datetime_t *datetime)
{
dc_status_t rc = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
dc_device_t *device = NULL;
// Open the I/O stream.
message ("Opening the I/O stream (%s, %s).\n",
dctool_transport_name (transport),
devname ? devname : "null");
rc = dctool_iostream_open (&iostream, context, descriptor, transport, devname);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the I/O stream.");
goto cleanup;
}
// Open the device.
message ("Opening the device (%s %s).\n",
dc_descriptor_get_vendor (descriptor),
dc_descriptor_get_product (descriptor));
rc = dc_device_open (&device, context, descriptor, iostream);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the device.");
goto cleanup;
}
// Register the event handler.
message ("Registering the event handler.\n");
int events = DC_EVENT_WAITING | DC_EVENT_PROGRESS | DC_EVENT_DEVINFO | DC_EVENT_CLOCK | DC_EVENT_VENDOR;
rc = dc_device_set_events (device, events, dctool_event_cb, NULL);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error registering the event handler.");
goto cleanup;
}
// Register the cancellation handler.
message ("Registering the cancellation handler.\n");
rc = dc_device_set_cancel (device, dctool_cancel_cb, NULL);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error registering the cancellation handler.");
goto cleanup;
}
// Syncronize the device clock.
message ("Syncronize the device clock.\n");
rc = dc_device_timesync (device, datetime);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error syncronizing the device clock.");
goto cleanup;
}
cleanup:
dc_device_close (device);
dc_iostream_close (iostream);
return rc;
}
static int
dctool_timesync_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t *descriptor)
{
int exitcode = EXIT_SUCCESS;
dc_status_t status = DC_STATUS_SUCCESS;
dc_transport_t transport = dctool_transport_default (descriptor);
// Default option values.
unsigned int help = 0;
// Parse the command-line options.
int opt = 0;
const char *optstring = "ht:";
#ifdef HAVE_GETOPT_LONG
struct option options[] = {
{"help", no_argument, 0, 'h'},
{"transport", required_argument, 0, 't'},
{0, 0, 0, 0 }
};
while ((opt = getopt_long (argc, argv, optstring, options, NULL)) != -1) {
#else
while ((opt = getopt (argc, argv, optstring)) != -1) {
#endif
switch (opt) {
case 'h':
help = 1;
break;
case 't':
transport = dctool_transport_type (optarg);
break;
default:
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
// Show help message.
if (help) {
dctool_command_showhelp (&dctool_timesync);
return EXIT_SUCCESS;
}
// Check the transport type.
if (transport == DC_TRANSPORT_NONE) {
message ("No valid transport type specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Get the system time.
dc_datetime_t datetime = {0};
dc_ticks_t now = dc_datetime_now ();
if (!dc_datetime_localtime(&datetime, now)) {
message ("ERROR: Failed to get the system time.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Synchronize the device clock.
status = do_timesync (context, descriptor, transport, argv[0], &datetime);
if (status != DC_STATUS_SUCCESS) {
message ("ERROR: %s\n", dctool_errmsg (status));
exitcode = EXIT_FAILURE;
goto cleanup;
}
cleanup:
return exitcode;
}
const dctool_command_t dctool_timesync = {
dctool_timesync_run,
DCTOOL_CONFIG_DESCRIPTOR,
"timesync",
"Synchronize the device clock",
"Usage:\n"
" dctool timesync [options]\n"
"\n"
"Options:\n"
#ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n"
" -t, --transport <name> Transport type\n"
#else
" -h Show help message\n"
" -t <transport> Transport type\n"
#endif
};

96
examples/dctool_version.c Normal file
View File

@ -0,0 +1,96 @@
/*
* libdivecomputer
*
* Copyright (C) 2015 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
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <libdivecomputer/context.h>
#include <libdivecomputer/descriptor.h>
#include <libdivecomputer/version.h>
#include "dctool.h"
static int
dctool_version_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t *descriptor)
{
// Default option values.
unsigned int help = 0;
// Parse the command-line options.
int opt = 0;
const char *optstring = "h";
#ifdef HAVE_GETOPT_LONG
struct option options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0 }
};
while ((opt = getopt_long (argc, argv, optstring, options, NULL)) != -1) {
#else
while ((opt = getopt (argc, argv, optstring)) != -1) {
#endif
switch (opt) {
case 'h':
help = 1;
break;
default:
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
// Show help message.
if (help) {
dctool_command_showhelp (&dctool_version);
return EXIT_SUCCESS;
}
printf ("libdivecomputer version %s\n", dc_version (NULL));
return EXIT_SUCCESS;
}
const dctool_command_t dctool_version = {
dctool_version_run,
DCTOOL_CONFIG_NONE,
"version",
"Show version information",
"Usage:\n"
" dctool version [options]\n"
"\n"
"Options:\n"
#ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n"
#else
" -h Show help message\n"
#endif
};

227
examples/dctool_write.c Normal file
View File

@ -0,0 +1,227 @@
/*
* libdivecomputer
*
* Copyright (C) 2015 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
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <libdivecomputer/context.h>
#include <libdivecomputer/descriptor.h>
#include <libdivecomputer/device.h>
#include "dctool.h"
#include "common.h"
#include "utils.h"
static dc_status_t
dowrite (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport, const char *devname, unsigned int address, dc_buffer_t *buffer)
{
dc_status_t rc = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
dc_device_t *device = NULL;
// Open the I/O stream.
message ("Opening the I/O stream (%s, %s).\n",
dctool_transport_name (transport),
devname ? devname : "null");
rc = dctool_iostream_open (&iostream, context, descriptor, transport, devname);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the I/O stream.");
goto cleanup;
}
// Open the device.
message ("Opening the device (%s %s).\n",
dc_descriptor_get_vendor (descriptor),
dc_descriptor_get_product (descriptor));
rc = dc_device_open (&device, context, descriptor, iostream);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the device.");
goto cleanup;
}
// Register the event handler.
message ("Registering the event handler.\n");
int events = DC_EVENT_WAITING | DC_EVENT_PROGRESS | DC_EVENT_DEVINFO | DC_EVENT_CLOCK | DC_EVENT_VENDOR;
rc = dc_device_set_events (device, events, dctool_event_cb, NULL);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error registering the event handler.");
goto cleanup;
}
// Register the cancellation handler.
message ("Registering the cancellation handler.\n");
rc = dc_device_set_cancel (device, dctool_cancel_cb, NULL);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error registering the cancellation handler.");
goto cleanup;
}
// Write data to the internal memory.
message ("Writing data to the internal memory.\n");
rc = dc_device_write (device, address, dc_buffer_get_data (buffer), dc_buffer_get_size (buffer));
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error writing to the internal memory.");
goto cleanup;
}
cleanup:
dc_device_close (device);
dc_iostream_close (iostream);
return rc;
}
static int
dctool_write_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t *descriptor)
{
int exitcode = EXIT_SUCCESS;
dc_status_t status = DC_STATUS_SUCCESS;
dc_buffer_t *buffer = NULL;
dc_transport_t transport = dctool_transport_default (descriptor);
// Default option values.
unsigned int help = 0;
const char *filename = NULL;
unsigned int address = 0, have_address = 0;
unsigned int count = 0, have_count = 0;
// Parse the command-line options.
int opt = 0;
const char *optstring = "ht:a:c:i:";
#ifdef HAVE_GETOPT_LONG
struct option options[] = {
{"help", no_argument, 0, 'h'},
{"transport", required_argument, 0, 't'},
{"address", required_argument, 0, 'a'},
{"count", required_argument, 0, 'c'},
{"input", required_argument, 0, 'i'},
{0, 0, 0, 0 }
};
while ((opt = getopt_long (argc, argv, optstring, options, NULL)) != -1) {
#else
while ((opt = getopt (argc, argv, optstring)) != -1) {
#endif
switch (opt) {
case 'h':
help = 1;
break;
case 't':
transport = dctool_transport_type (optarg);
break;
case 'a':
address = strtoul (optarg, NULL, 0);
have_address = 1;
break;
case 'c':
count = strtoul (optarg, NULL, 0);
have_count = 1;
break;
case 'i':
filename = optarg;
break;
default:
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
// Show help message.
if (help) {
dctool_command_showhelp (&dctool_write);
return EXIT_SUCCESS;
}
// Check the transport type.
if (transport == DC_TRANSPORT_NONE) {
message ("No valid transport type specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Check mandatory arguments.
if (!have_address) {
message ("No memory address specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Read the buffer from file.
buffer = dctool_file_read (filename);
if (buffer == NULL) {
message ("Failed to read the input file.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Check the number of bytes (if provided)
if (have_count && count != dc_buffer_get_size (buffer)) {
message ("Number of bytes doesn't match file length.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Write data to the internal memory.
status = dowrite (context, descriptor, transport, argv[0], address, buffer);
if (status != DC_STATUS_SUCCESS) {
message ("ERROR: %s\n", dctool_errmsg (status));
exitcode = EXIT_FAILURE;
goto cleanup;
}
cleanup:
dc_buffer_free (buffer);
return exitcode;
}
const dctool_command_t dctool_write = {
dctool_write_run,
DCTOOL_CONFIG_DESCRIPTOR,
"write",
"Write data to the internal memory",
"Usage:\n"
" dctool write [options] <devname>\n"
"\n"
"Options:\n"
#ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n"
" -t, --transport <name> Transport type\n"
" -a, --address <address> Memory address\n"
" -c, --count <count> Number of bytes\n"
" -i, --input <filename> Input filename\n"
#else
" -h Show help message\n"
" -t <transport> Transport type\n"
" -a <address> Memory address\n"
" -c <count> Number of bytes\n"
" -i <filename> Input filename\n"
#endif
};

View File

@ -1,95 +0,0 @@
/*
* libdivecomputer
*
* Copyright (C) 2012 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#include <stdio.h> // fopen, fwrite, fclose
#include <libdivecomputer/hw_frog.h>
#include "utils.h"
#include "common.h"
dc_status_t
test_dump_memory (const char* name, const char* filename)
{
dc_context_t *context = NULL;
dc_device_t *device = NULL;
dc_context_new (&context);
dc_context_set_loglevel (context, DC_LOGLEVEL_ALL);
dc_context_set_logfunc (context, logfunc, NULL);
message ("hw_frog_device_open\n");
dc_status_t rc = hw_frog_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
message ("dc_device_foreach\n");
rc = dc_device_foreach (device, NULL, NULL);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read memory.");
dc_device_close (device);
dc_context_free (context);
return rc;
}
message ("dc_device_close\n");
rc = dc_device_close (device);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot close device.");
dc_context_free (context);
return rc;
}
dc_context_free (context);
return DC_STATUS_SUCCESS;
}
int main(int argc, char *argv[])
{
message_set_logfile ("FROG.LOG");
#ifdef _WIN32
const char* name = "COM1";
#else
const char* name = "/dev/ttyS0";
#endif
if (argc > 1) {
name = argv[1];
}
message ("DEVICE=%s\n", name);
dc_status_t a = test_dump_memory (name, "FROG.DMP");
message ("SUMMARY\n");
message ("-------\n");
message ("test_dump_memory: %s\n", errmsg (a));
message_set_logfile (NULL);
return 0;
}

View File

@ -1,107 +0,0 @@
/*
* libdivecomputer
*
* Copyright (C) 2009 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#include <stdio.h> // fopen, fwrite, fclose
#include <libdivecomputer/hw_ostc.h>
#include "utils.h"
#include "common.h"
dc_status_t
test_dump_memory (const char* name, const char* filename)
{
dc_context_t *context = NULL;
dc_device_t *device = NULL;
dc_context_new (&context);
dc_context_set_loglevel (context, DC_LOGLEVEL_ALL);
dc_context_set_logfunc (context, logfunc, NULL);
message ("hw_ostc_device_open\n");
dc_status_t rc = hw_ostc_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
dc_buffer_t *buffer = dc_buffer_new (0);
message ("dc_device_dump\n");
rc = dc_device_dump (device, buffer);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
message ("Dumping data\n");
FILE* fp = fopen (filename, "wb");
if (fp != NULL) {
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
fclose (fp);
}
dc_buffer_free (buffer);
message ("dc_device_close\n");
rc = dc_device_close (device);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot close device.");
dc_context_free (context);
return rc;
}
dc_context_free (context);
return DC_STATUS_SUCCESS;
}
int main(int argc, char *argv[])
{
message_set_logfile ("OSTC.LOG");
#ifdef _WIN32
const char* name = "COM1";
#else
const char* name = "/dev/ttyS0";
#endif
if (argc > 1) {
name = argv[1];
}
message ("DEVICE=%s\n", name);
dc_status_t a = test_dump_memory (name, "OSTC.DMP");
message ("SUMMARY\n");
message ("-------\n");
message ("test_dump_memory: %s\n", errmsg (a));
message_set_logfile (NULL);
return 0;
}

View File

@ -1,107 +0,0 @@
/*
* libdivecomputer
*
* Copyright (C) 2011 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#include <stdio.h> // fopen, fwrite, fclose
#include <libdivecomputer/mares_darwin.h>
#include "utils.h"
#include "common.h"
dc_status_t
test_dump_memory (const char* name, const char* filename)
{
dc_context_t *context = NULL;
dc_device_t *device = NULL;
dc_context_new (&context);
dc_context_set_loglevel (context, DC_LOGLEVEL_ALL);
dc_context_set_logfunc (context, logfunc, NULL);
message ("mares_darwin_device_open\n");
dc_status_t rc = mares_darwin_device_open (&device, context, name, 0);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
dc_buffer_t *buffer = dc_buffer_new (0);
message ("dc_device_dump\n");
rc = dc_device_dump (device, buffer);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
message ("Dumping data\n");
FILE* fp = fopen (filename, "wb");
if (fp != NULL) {
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
fclose (fp);
}
dc_buffer_free (buffer);
message ("dc_device_close\n");
rc = dc_device_close (device);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot close device.");
dc_context_free (context);
return rc;
}
dc_context_free (context);
return DC_STATUS_SUCCESS;
}
int main(int argc, char *argv[])
{
message_set_logfile ("DARWIN.LOG");
#ifdef _WIN32
const char* name = "COM1";
#else
const char* name = "/dev/ttyS0";
#endif
if (argc > 1) {
name = argv[1];
}
message ("DEVICE=%s\n", name);
dc_status_t a = test_dump_memory (name, "DARWIN.DMP");
message ("SUMMARY\n");
message ("-------\n");
message ("test_dump_memory: %s\n", errmsg (a));
message_set_logfile (NULL);
return 0;
}

View File

@ -1,114 +0,0 @@
/*
* libdivecomputer
*
* Copyright (C) 2010 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#include <stdio.h> // fopen, fwrite, fclose
#include <stdlib.h>
#include <libdivecomputer/mares_iconhd.h>
#include "utils.h"
#include "common.h"
dc_status_t
test_dump_memory (const char* name, const char* filename, unsigned int model)
{
dc_context_t *context = NULL;
dc_device_t *device = NULL;
dc_context_new (&context);
dc_context_set_loglevel (context, DC_LOGLEVEL_ALL);
dc_context_set_logfunc (context, logfunc, NULL);
message ("mares_iconhd_device_open\n");
dc_status_t rc = mares_iconhd_device_open (&device, context, name, model);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
dc_buffer_t *buffer = dc_buffer_new (0);
message ("dc_device_dump\n");
rc = dc_device_dump (device, buffer);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
message ("Dumping data\n");
FILE* fp = fopen (filename, "wb");
if (fp != NULL) {
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
fclose (fp);
}
dc_buffer_free (buffer);
message ("dc_device_close\n");
rc = dc_device_close (device);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot close device.");
dc_context_free (context);
return rc;
}
dc_context_free (context);
return DC_STATUS_SUCCESS;
}
int main(int argc, char *argv[])
{
message_set_logfile ("ICONHD.LOG");
#ifdef _WIN32
const char* name = "COM1";
#else
const char* name = "/dev/ttyS0";
#endif
unsigned int model = 0;
if (argc > 1) {
name = argv[1];
}
if (argc > 2) {
model = strtoul (argv[2], NULL, 0);
}
message ("DEVICE=%s\n", name);
message ("MODEL=0x%02x\n", model);
dc_status_t a = test_dump_memory (name, "ICONHD.DMP", model);
message ("\nSUMMARY\n");
message ("-------\n");
message ("test_dump_memory: %s\n", errmsg (a));
message_set_logfile (NULL);
return 0;
}

View File

@ -1,107 +0,0 @@
/*
* libdivecomputer
*
* Copyright (C) 2008 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#include <stdio.h> // fopen, fwrite, fclose
#include <libdivecomputer/mares_nemo.h>
#include "utils.h"
#include "common.h"
dc_status_t
test_dump_memory (const char* name, const char* filename)
{
dc_context_t *context = NULL;
dc_device_t *device = NULL;
dc_context_new (&context);
dc_context_set_loglevel (context, DC_LOGLEVEL_ALL);
dc_context_set_logfunc (context, logfunc, NULL);
message ("mares_nemo_device_open\n");
dc_status_t rc = mares_nemo_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
dc_buffer_t *buffer = dc_buffer_new (0);
message ("dc_device_dump\n");
rc = dc_device_dump (device, buffer);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
message ("Dumping data\n");
FILE* fp = fopen (filename, "wb");
if (fp != NULL) {
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
fclose (fp);
}
dc_buffer_free (buffer);
message ("dc_device_close\n");
rc = dc_device_close (device);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot close device.");
dc_context_free (context);
return rc;
}
dc_context_free (context);
return DC_STATUS_SUCCESS;
}
int main(int argc, char *argv[])
{
message_set_logfile ("NEMO.LOG");
#ifdef _WIN32
const char* name = "COM1";
#else
const char* name = "/dev/ttyS0";
#endif
if (argc > 1) {
name = argv[1];
}
message ("DEVICE=%s\n", name);
dc_status_t a = test_dump_memory (name, "NEMO.DMP");
message ("\nSUMMARY\n");
message ("-------\n");
message ("test_dump_memory: %s\n", errmsg (a));
message_set_logfile (NULL);
return 0;
}

View File

@ -1,107 +0,0 @@
/*
* libdivecomputer
*
* Copyright (C) 2009 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#include <stdio.h> // fopen, fwrite, fclose
#include <libdivecomputer/mares_puck.h>
#include "utils.h"
#include "common.h"
dc_status_t
test_dump_memory (const char* name, const char* filename)
{
dc_context_t *context = NULL;
dc_device_t *device = NULL;
dc_context_new (&context);
dc_context_set_loglevel (context, DC_LOGLEVEL_ALL);
dc_context_set_logfunc (context, logfunc, NULL);
message ("mares_puck_device_open\n");
dc_status_t rc = mares_puck_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
dc_buffer_t *buffer = dc_buffer_new (0);
message ("dc_device_dump\n");
rc = dc_device_dump (device, buffer);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
message ("Dumping data\n");
FILE* fp = fopen (filename, "wb");
if (fp != NULL) {
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
fclose (fp);
}
dc_buffer_free (buffer);
message ("dc_device_close\n");
rc = dc_device_close (device);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot close device.");
dc_context_free (context);
return rc;
}
dc_context_free (context);
return DC_STATUS_SUCCESS;
}
int main(int argc, char *argv[])
{
message_set_logfile ("PUCK.LOG");
#ifdef _WIN32
const char* name = "COM1";
#else
const char* name = "/dev/ttyS0";
#endif
if (argc > 1) {
name = argv[1];
}
message ("DEVICE=%s\n", name);
dc_status_t a = test_dump_memory (name, "PUCK.DMP");
message ("SUMMARY\n");
message ("-------\n");
message ("test_dump_memory: %s\n", errmsg (a));
message_set_logfile (NULL);
return 0;
}

View File

@ -1,116 +0,0 @@
/*
* libdivecomputer
*
* Copyright (C) 2008 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#include <stdio.h> // fopen, fwrite, fclose
#include <libdivecomputer/oceanic_atom2.h>
#include "utils.h"
#include "common.h"
dc_status_t
test_dump_memory (const char* name, const char* filename)
{
dc_context_t *context = NULL;
dc_device_t *device = NULL;
dc_context_new (&context);
dc_context_set_loglevel (context, DC_LOGLEVEL_ALL);
dc_context_set_logfunc (context, logfunc, NULL);
message ("oceanic_atom2_device_open\n");
dc_status_t rc = oceanic_atom2_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
dc_buffer_t *buffer = dc_buffer_new (0);
message ("dc_device_dump\n");
rc = dc_device_dump (device, buffer);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
message ("Dumping data\n");
FILE* fp = fopen (filename, "wb");
if (fp != NULL) {
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
fclose (fp);
}
dc_buffer_free (buffer);
message ("dc_device_foreach\n");
rc = dc_device_foreach (device, NULL, NULL);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read dives.");
dc_device_close (device);
dc_context_free (context);
return rc;
}
message ("dc_device_close\n");
rc = dc_device_close (device);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot close device.");
dc_context_free (context);
return rc;
}
dc_context_free (context);
return DC_STATUS_SUCCESS;
}
int main(int argc, char *argv[])
{
message_set_logfile ("ATOM2.LOG");
#ifdef _WIN32
const char* name = "COM1";
#else
const char* name = "/dev/ttyS0";
#endif
if (argc > 1) {
name = argv[1];
}
message ("DEVICE=%s\n", name);
dc_status_t a = test_dump_memory (name, "ATOM2.DMP");
message ("\nSUMMARY\n");
message ("-------\n");
message ("test_dump_memory: %s\n", errmsg (a));
message_set_logfile (NULL);
return 0;
}

View File

@ -1,116 +0,0 @@
/*
* libdivecomputer
*
* Copyright (C) 2008 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#include <stdio.h> // fopen, fwrite, fclose
#include <libdivecomputer/oceanic_veo250.h>
#include "utils.h"
#include "common.h"
dc_status_t
test_dump_memory (const char* name, const char* filename)
{
dc_context_t *context = NULL;
dc_device_t *device = NULL;
dc_context_new (&context);
dc_context_set_loglevel (context, DC_LOGLEVEL_ALL);
dc_context_set_logfunc (context, logfunc, NULL);
message ("oceanic_veo250_device_open\n");
dc_status_t rc = oceanic_veo250_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
dc_buffer_t *buffer = dc_buffer_new (0);
message ("dc_device_dump\n");
rc = dc_device_dump (device, buffer);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
message ("Dumping data\n");
FILE* fp = fopen (filename, "wb");
if (fp != NULL) {
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
fclose (fp);
}
dc_buffer_free (buffer);
message ("dc_device_foreach\n");
rc = dc_device_foreach (device, NULL, NULL);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read dives.");
dc_device_close (device);
dc_context_free (context);
return rc;
}
message ("dc_device_close\n");
rc = dc_device_close (device);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot close device.");
dc_context_free (context);
return rc;
}
dc_context_free (context);
return DC_STATUS_SUCCESS;
}
int main(int argc, char *argv[])
{
message_set_logfile ("VEO250.LOG");
#ifdef _WIN32
const char* name = "COM1";
#else
const char* name = "/dev/ttyS0";
#endif
if (argc > 1) {
name = argv[1];
}
message ("DEVICE=%s\n", name);
dc_status_t a = test_dump_memory (name, "VEO250.DMP");
message ("\nSUMMARY\n");
message ("-------\n");
message ("test_dump_memory: %s\n", errmsg (a));
message_set_logfile (NULL);
return 0;
}

View File

@ -1,107 +0,0 @@
/*
* libdivecomputer
*
* Copyright (C) 2008 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#include <stdio.h> // fopen, fwrite, fclose
#include <libdivecomputer/oceanic_vtpro.h>
#include "utils.h"
#include "common.h"
dc_status_t
test_dump_memory (const char* name, const char* filename)
{
dc_context_t *context = NULL;
dc_device_t *device = NULL;
dc_context_new (&context);
dc_context_set_loglevel (context, DC_LOGLEVEL_ALL);
dc_context_set_logfunc (context, logfunc, NULL);
message ("oceanic_vtpro_device_open\n");
dc_status_t rc = oceanic_vtpro_device_open (&device, context, name);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error opening serial port.");
dc_context_free (context);
return rc;
}
dc_buffer_t *buffer = dc_buffer_new (0);
message ("dc_device_dump\n");
rc = dc_device_dump (device, buffer);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot read memory.");
dc_buffer_free (buffer);
dc_device_close (device);
dc_context_free (context);
return rc;
}
message ("Dumping data\n");
FILE* fp = fopen (filename, "wb");
if (fp != NULL) {
fwrite (dc_buffer_get_data (buffer), sizeof (unsigned char), dc_buffer_get_size (buffer), fp);
fclose (fp);
}
dc_buffer_free (buffer);
message ("dc_device_close\n");
rc = dc_device_close (device);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Cannot close device.");
dc_context_free (context);
return rc;
}
dc_context_free (context);
return DC_STATUS_SUCCESS;
}
int main(int argc, char *argv[])
{
message_set_logfile ("VTPRO.LOG");
#ifdef _WIN32
const char* name = "COM1";
#else
const char* name = "/dev/ttyS0";
#endif
if (argc > 1) {
name = argv[1];
}
message ("DEVICE=%s\n", name);
dc_status_t a = test_dump_memory (name, "VTPRO.DMP");
message ("\nSUMMARY\n");
message ("-------\n");
message ("test_dump_memory: %s\n", errmsg (a));
message_set_logfile (NULL);
return 0;
}

58
examples/output-private.h Normal file
View File

@ -0,0 +1,58 @@
/*
* libdivecomputer
*
* Copyright (C) 2016 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 DCTOOL_OUTPUT_PRIVATE_H
#define DCTOOL_OUTPUT_PRIVATE_H
#include <libdivecomputer/common.h>
#include <libdivecomputer/parser.h>
#include "output.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct dctool_output_vtable_t dctool_output_vtable_t;
struct dctool_output_t {
const dctool_output_vtable_t *vtable;
unsigned int number;
};
struct dctool_output_vtable_t {
size_t size;
dc_status_t (*write) (dctool_output_t *output, dc_parser_t *parser, const unsigned char data[], unsigned int size, const unsigned char fingerprint[], unsigned int fsize);
dc_status_t (*free) (dctool_output_t *output);
};
dctool_output_t *
dctool_output_allocate (const dctool_output_vtable_t *vtable);
void
dctool_output_deallocate (dctool_output_t *output);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* DCTOOL_OUTPUT_PRIVATE_H */

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