Shutdown the connection cleanly.
A shutdown command should be send to the device, before the connection is actually closed. In the absence of this command, the device will display an error, even if the data transfer itself was successful!
This commit is contained in:
parent
50fc64ac59
commit
2934c6a618
@ -256,7 +256,7 @@ shearwater_common_slip_read (shearwater_common_device_t *device, unsigned char d
|
||||
}
|
||||
|
||||
|
||||
static dc_status_t
|
||||
dc_status_t
|
||||
shearwater_common_transfer (shearwater_common_device_t *device, const unsigned char input[], unsigned int isize, unsigned char output[], unsigned int osize, unsigned int *actual)
|
||||
{
|
||||
dc_device_t *abstract = (dc_device_t *) device;
|
||||
@ -283,6 +283,13 @@ shearwater_common_transfer (shearwater_common_device_t *device, const unsigned c
|
||||
return DC_STATUS_TIMEOUT;
|
||||
}
|
||||
|
||||
// Return early if no response packet is requested.
|
||||
if (osize == 0) {
|
||||
if (actual)
|
||||
*actual = 0;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Receive the response packet.
|
||||
n = shearwater_common_slip_read (device, packet, sizeof (packet));
|
||||
if (n <= 0 || n > sizeof (packet)) {
|
||||
@ -309,7 +316,8 @@ shearwater_common_transfer (shearwater_common_device_t *device, const unsigned c
|
||||
}
|
||||
|
||||
memcpy (output, packet + 4, length - 1);
|
||||
*actual = length - 1;
|
||||
if (actual)
|
||||
*actual = length - 1;
|
||||
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -40,6 +40,9 @@ shearwater_common_open (shearwater_common_device_t *device, dc_context_t *contex
|
||||
dc_status_t
|
||||
shearwater_common_close (shearwater_common_device_t *device);
|
||||
|
||||
dc_status_t
|
||||
shearwater_common_transfer (shearwater_common_device_t *device, const unsigned char input[], unsigned int isize, unsigned char output[], unsigned int osize, unsigned int *actual);
|
||||
|
||||
dc_status_t
|
||||
shearwater_common_download (shearwater_common_device_t *device, dc_buffer_t *buffer, unsigned int address, unsigned int size, unsigned int compression);
|
||||
|
||||
|
||||
@ -101,6 +101,10 @@ shearwater_petrel_device_close (dc_device_t *abstract)
|
||||
dc_status_t rc = DC_STATUS_SUCCESS;
|
||||
shearwater_common_device_t *device = (shearwater_common_device_t *) abstract;
|
||||
|
||||
// Shutdown the device.
|
||||
unsigned char request[] = {0x2E, 0x90, 0x20, 0x00};
|
||||
shearwater_common_transfer (device, request, sizeof (request), NULL, 0, NULL);
|
||||
|
||||
// Close the device.
|
||||
rc = shearwater_common_close (device);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user