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.
This commit is contained in:
Jef Driesen 2023-06-22 20:42:12 +02:00
parent 13705f2b2d
commit d4402aa296
2 changed files with 40 additions and 0 deletions

View File

@ -39,6 +39,9 @@
#define RDBI_REQUEST 0x22
#define RDBI_RESPONSE 0x62
#define WDBI_REQUEST 0x2E
#define WDBI_RESPONSE 0x6E
dc_status_t
shearwater_common_setup (shearwater_common_device_t *device, dc_context_t *context, dc_iostream_t *iostream)
{
@ -552,6 +555,40 @@ shearwater_common_rdbi (shearwater_common_device_t *device, unsigned int id, uns
return status;
}
dc_status_t
shearwater_common_wdbi (shearwater_common_device_t *device, unsigned int id, const unsigned char data[], unsigned int size)
{
dc_status_t status = DC_STATUS_SUCCESS;
dc_device_t *abstract = (dc_device_t *) device;
if (size + 3 > SZ_PACKET) {
return DC_STATUS_INVALIDARGS;
}
// Transfer the request.
unsigned int n = 0;
unsigned char request[SZ_PACKET] = {
WDBI_REQUEST,
(id >> 8) & 0xFF,
(id ) & 0xFF};
if (size) {
memcpy (request + 3, data, size);
}
unsigned char response[SZ_PACKET];
status = shearwater_common_transfer (device, request, size + 3, response, sizeof (response), &n);
if (status != DC_STATUS_SUCCESS) {
return status;
}
// Verify the response.
if (n < 3 || response[0] != WDBI_RESPONSE || response[1] != request[1] || response[2] != request[2]) {
ERROR (abstract->context, "Unexpected response packet.");
return DC_STATUS_PROTOCOL;
}
return status;
}
unsigned int
shearwater_common_get_model (shearwater_common_device_t *device, unsigned int hardware)
{

View File

@ -67,6 +67,9 @@ shearwater_common_download (shearwater_common_device_t *device, dc_buffer_t *buf
dc_status_t
shearwater_common_rdbi (shearwater_common_device_t *device, unsigned int id, unsigned char data[], unsigned int size);
dc_status_t
shearwater_common_wdbi (shearwater_common_device_t *device, unsigned int id, const unsigned char data[], unsigned int size);
unsigned int
shearwater_common_get_model (shearwater_common_device_t *device, unsigned int hardware);