[RFC] Work done so far

Jef Driesen jef at libdivecomputer.org
Fri May 30 01:47:15 PDT 2014


On 2014-05-30 09:52, Joshua Joseph wrote:
> Please check and see if I am on the right track.

I quickly checked the patched, and noticed one libdivecomputer related 
mistake: you shouldn't use the vendor or product strings to check the 
device type. There are much better ways to do this. The strings are 
mainly intended for display in the user interface.

> 0003-Read-basic-details-from-dive-computer.patch:
> 
> +	rc = dc_device_open(&data->device, data->context, data->descriptor, 
> data->devname);
> +	if (rc == DC_STATUS_SUCCESS) {
> +		if (vendor.trimmed() == "Heinrichs Weikamp") {
> +			unsigned char hw_data[10];
> +			hw_frog_device_version(data->device, hw_data, 10);
> 

Here, you check for "Heinrichs Weikamp", and then call the 
hw_frog_device_version function. As the name indicates, this function 
does support the HW Frog only. But there are several other devices made 
by Heinrichs Weikamp (e.g. OSTC2 and OSTC3), which do not support this 
function!

> 0004-Create-class-to-write-settings-to-dive-computer.patch:
> 
> +		if (product.trimmed() == "OSTC 3") {
> +			if (m_settingName == "Name") {
> +				supported = true;
> +				result = hw_ostc3_device_customtext(data->device, 
> m_settingValue.toByteArray().data());
> +			}
> +		}
> 

If a future model remains backwards compatible with the ostc3 protocol, 
but changes its name to something different than "OSTC 3", this code 
will not be able to support this new model!

The solution to both of these problems, is to check the family type 
instead, using the dc_device_get_type or dc_descriptor_get_type 
function:

if (dc_device_get_type(data->device) == DC_FAMILY_HW_FROG) {
    ...
    hw_frog_device_version(data->device, hw_data, 10);
    ...
}

Jef


More information about the subsurface mailing list