22 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
59b17858f4 Append the final block to each dive.
There are two good reasons for this change. First of all, it makes the
Predator data format more consistent with the Petrel data format, which
also has the final block appended to each dive. But even more important
is that we might actually need the information stored in the final block
someday.

The final block contains important information about the device, such as
the firmware and logbook version. Right now this information is simply
lost after the download. But if the data format ever changes to support
some new feature, we'll likely need that information to autodetect the
correct format.

Unfortunately this also changes the dive format in a non-backwards
compatible way. However, to minimize the inconvenience, the legacy
format (without the extra final block) remains supported in the parser.
2013-04-23 21:07:34 +02:00
Jef Driesen
2e5faae9da Avoid unnecessary large memory allocations.
Because the size of a dive isn't known in advance, we use the worst case
value of 0xFFFFFF (or nearly 16MB). However in practice, the real size
is many orders of magnitude smaller, even after the decompression.
Instead of pre-allocating a huge memory buffer, we now start with a much
smaller one, and increase when necessary.

For the predator and petrel manifests, where the size is known in
advance, we continue to pre-allocate the exact amount of memory as
before.
2013-04-19 21:31:28 +02:00
Jef Driesen
c4d3356b6e Add support for compressed data packets.
The new Petrel protocol uses a simple data compression scheme to reduce
the transfer times. The data is broken up into blocks of 32 bytes each.
Each block except the first is XOR'ed with the previous block, creating
large runs of zeros due to the similarity of the data. The zeros are
then run-length encoded (RLE) to save space.
2013-04-16 22:26:41 +02:00
Jef Driesen
6f3de69f0d Move the low-level communication to a common file.
This is done in preparation for the implementation of the new Petrel
protocol, which shares the low level communication with the existing
Predator protocol.
2013-04-16 22:26:41 +02:00
Jef Driesen
389933400f Replace hardcoded constants with parameters. 2013-04-16 21:39:19 +02:00
Jef Driesen
6419e189a4 Add a single isinstance function per object type.
Currently, each backend has it's own function to verify whether the
object vtable pointer is the expected one. All these functions can be
removed in favor of a single isintance function in the base class,
which takes the expected vtable pointer as a parameter.

Functions which are called through the vtable, don't need to verify the
vtable pointer, and those checks are removed.
2013-04-16 12:18:54 +02:00
Jef Driesen
007479fc92 Rename the backend structure to vtable.
The term "backend" can be confusing because it can refer to both the
virtual function table and the device/parser backends. The use of the
term "vtable" avoids this.
2013-04-16 12:18:53 +02:00
Jef Driesen
74b91f2791 Add support for the Shearwater Petrel.
The Petrel is slightly different from the Predator because the device
reorders the internal ringbuffer before sending the data. The most
recent dive is always the first one, and there is no need to search for
it, like we have to do for the Predator.
2012-12-21 21:44:18 +01:00
Jef Driesen
500fb1e16b Add support for the Shearwater Predator. 2012-12-05 16:08:47 +01:00