Split the transfer code in a handshake, version and read function.
This commit is contained in:
parent
03b186e88b
commit
cd20f8a02d
@ -29,6 +29,25 @@ int test_dump_memory (const char* filename)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message ("uwatec_smart_handshake\n");
|
||||||
|
rc = uwatec_smart_handshake (device);
|
||||||
|
if (rc != UWATEC_SUCCESS) {
|
||||||
|
WARNING ("Handshake failed.");
|
||||||
|
uwatec_smart_close (device);
|
||||||
|
free (data);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ("uwatec_smart_version\n");
|
||||||
|
unsigned char version[UWATEC_SMART_VERSION_SIZE] = {0};
|
||||||
|
rc = uwatec_smart_version (device, version, sizeof (version));
|
||||||
|
if (rc != UWATEC_SUCCESS) {
|
||||||
|
WARNING ("Cannot identify computer.");
|
||||||
|
uwatec_smart_close (device);
|
||||||
|
free (data);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
message ("uwatec_smart_read\n");
|
message ("uwatec_smart_read\n");
|
||||||
rc = uwatec_smart_read (device, data, size);
|
rc = uwatec_smart_read (device, data, size);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
|||||||
@ -166,13 +166,13 @@ uwatec_smart_transfer (smart *device, const unsigned char command[], unsigned in
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
uwatec_smart_read (smart *device, unsigned char data[], unsigned int size)
|
uwatec_smart_handshake (smart *device)
|
||||||
{
|
{
|
||||||
if (device == NULL)
|
if (device == NULL)
|
||||||
return UWATEC_ERROR;
|
return UWATEC_ERROR;
|
||||||
|
|
||||||
unsigned char command[9] = {0};
|
unsigned char command[5] = {0};
|
||||||
unsigned char answer[4] = {0};
|
unsigned char answer[1] = {0};
|
||||||
|
|
||||||
// Handshake (stage 1).
|
// Handshake (stage 1).
|
||||||
|
|
||||||
@ -208,11 +208,24 @@ uwatec_smart_read (smart *device, unsigned char data[], unsigned int size)
|
|||||||
return UWATEC_ERROR_PROTOCOL;
|
return UWATEC_ERROR_PROTOCOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return UWATEC_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
uwatec_smart_version (smart *device, unsigned char data[], unsigned int size)
|
||||||
|
{
|
||||||
|
if (device == NULL)
|
||||||
|
return UWATEC_ERROR;
|
||||||
|
|
||||||
|
unsigned char command[1] = {0};
|
||||||
|
unsigned char answer[UWATEC_SMART_VERSION_SIZE] = {0};
|
||||||
|
|
||||||
// Dive Computer Time.
|
// Dive Computer Time.
|
||||||
|
|
||||||
command[0] = 0x1A;
|
command[0] = 0x1A;
|
||||||
|
|
||||||
rc = uwatec_smart_transfer (device, command, 1, answer, 4);
|
int rc = uwatec_smart_transfer (device, command, 1, answer + 0, 4);
|
||||||
if (rc != UWATEC_SUCCESS)
|
if (rc != UWATEC_SUCCESS)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
@ -231,23 +244,43 @@ uwatec_smart_read (smart *device, unsigned char data[], unsigned int size)
|
|||||||
|
|
||||||
command[0] = 0x14;
|
command[0] = 0x14;
|
||||||
|
|
||||||
rc = uwatec_smart_transfer (device, command, 1, answer, 4);
|
rc = uwatec_smart_transfer (device, command, 1, answer + 4, 4);
|
||||||
if (rc != UWATEC_SUCCESS)
|
if (rc != UWATEC_SUCCESS)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
unsigned int serial = answer[0] + (answer[1] << 8) +
|
unsigned int serial = answer[4] + (answer[5] << 8) +
|
||||||
(answer[2] << 16) + (answer[3] << 24);
|
(answer[6] << 16) + (answer[7] << 24);
|
||||||
message ("handshake: serial=0x%08x\n", serial);
|
message ("handshake: serial=0x%08x\n", serial);
|
||||||
|
|
||||||
// Dive Computer Model.
|
// Dive Computer Model.
|
||||||
|
|
||||||
command[0] = 0x10;
|
command[0] = 0x10;
|
||||||
|
|
||||||
rc = uwatec_smart_transfer (device, command, 1, answer, 1);
|
rc = uwatec_smart_transfer (device, command, 1, answer + 8, 1);
|
||||||
if (rc != UWATEC_SUCCESS)
|
if (rc != UWATEC_SUCCESS)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
message ("handshake: model=0x%02x\n", answer[0]);
|
message ("handshake: model=0x%02x\n", answer[8]);
|
||||||
|
|
||||||
|
if (size >= UWATEC_SMART_VERSION_SIZE) {
|
||||||
|
memcpy (data, answer, UWATEC_SMART_VERSION_SIZE);
|
||||||
|
} else {
|
||||||
|
WARNING ("Insufficient buffer space available.");
|
||||||
|
return UWATEC_ERROR_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return UWATEC_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
uwatec_smart_read (smart *device, unsigned char data[], unsigned int size)
|
||||||
|
{
|
||||||
|
if (device == NULL)
|
||||||
|
return UWATEC_ERROR;
|
||||||
|
|
||||||
|
unsigned char command[9] = {0};
|
||||||
|
unsigned char answer[4] = {0};
|
||||||
|
|
||||||
// Data Length.
|
// Data Length.
|
||||||
|
|
||||||
@ -261,7 +294,7 @@ uwatec_smart_read (smart *device, unsigned char data[], unsigned int size)
|
|||||||
command[7] = 0;
|
command[7] = 0;
|
||||||
command[8] = 0;
|
command[8] = 0;
|
||||||
|
|
||||||
rc = uwatec_smart_transfer (device, command, 9, answer, 4);
|
int rc = uwatec_smart_transfer (device, command, 9, answer, 4);
|
||||||
if (rc != UWATEC_SUCCESS)
|
if (rc != UWATEC_SUCCESS)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
|
|||||||
@ -7,12 +7,18 @@ extern "C" {
|
|||||||
|
|
||||||
typedef struct smart smart;
|
typedef struct smart smart;
|
||||||
|
|
||||||
|
#define UWATEC_SMART_VERSION_SIZE 9
|
||||||
|
|
||||||
int uwatec_smart_open (smart **device);
|
int uwatec_smart_open (smart **device);
|
||||||
|
|
||||||
int uwatec_smart_close (smart *device);
|
int uwatec_smart_close (smart *device);
|
||||||
|
|
||||||
int uwatec_smart_set_timestamp (smart *device, unsigned int timestamp);
|
int uwatec_smart_set_timestamp (smart *device, unsigned int timestamp);
|
||||||
|
|
||||||
|
int uwatec_smart_handshake (smart *device);
|
||||||
|
|
||||||
|
int uwatec_smart_version (smart *device, unsigned char data[], unsigned int size);
|
||||||
|
|
||||||
int uwatec_smart_read (smart *device, unsigned char data[], unsigned int size);
|
int uwatec_smart_read (smart *device, unsigned char data[], unsigned int size);
|
||||||
|
|
||||||
int uwatec_smart_extract_dives (const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);
|
int uwatec_smart_extract_dives (const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user