Use common status codes for the device and parser layers.
This commit is contained in:
parent
e65025b501
commit
9136a52835
@ -22,26 +22,30 @@
|
||||
#include "common.h"
|
||||
|
||||
const char *
|
||||
errmsg (device_status_t rc)
|
||||
errmsg (dc_status_t rc)
|
||||
{
|
||||
switch (rc) {
|
||||
case DEVICE_STATUS_SUCCESS:
|
||||
case DC_STATUS_SUCCESS:
|
||||
return "Success";
|
||||
case DEVICE_STATUS_UNSUPPORTED:
|
||||
case DC_STATUS_UNSUPPORTED:
|
||||
return "Unsupported operation";
|
||||
case DEVICE_STATUS_TYPE_MISMATCH:
|
||||
return "Device type mismatch";
|
||||
case DEVICE_STATUS_ERROR:
|
||||
return "Generic error";
|
||||
case DEVICE_STATUS_IO:
|
||||
case DC_STATUS_INVALIDARGS:
|
||||
return "Invalid arguments";
|
||||
case DC_STATUS_NOMEMORY:
|
||||
return "Out of memory";
|
||||
case DC_STATUS_NODEVICE:
|
||||
return "No device found";
|
||||
case DC_STATUS_NOACCESS:
|
||||
return "Access denied";
|
||||
case DC_STATUS_IO:
|
||||
return "Input/output error";
|
||||
case DEVICE_STATUS_MEMORY:
|
||||
return "Memory error";
|
||||
case DEVICE_STATUS_PROTOCOL:
|
||||
return "Protocol error";
|
||||
case DEVICE_STATUS_TIMEOUT:
|
||||
case DC_STATUS_TIMEOUT:
|
||||
return "Timeout";
|
||||
case DEVICE_STATUS_CANCELLED:
|
||||
case DC_STATUS_PROTOCOL:
|
||||
return "Protocol error";
|
||||
case DC_STATUS_DATAFORMAT:
|
||||
return "Data format error";
|
||||
case DC_STATUS_CANCELLED:
|
||||
return "Cancelled";
|
||||
default:
|
||||
return "Unknown error";
|
||||
|
||||
@ -29,7 +29,7 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
const char *
|
||||
errmsg (device_status_t rc);
|
||||
errmsg (dc_status_t rc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -26,14 +26,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("cressi_edy_device_open\n");
|
||||
device_status_t rc = cressi_edy_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = cressi_edy_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -42,7 +42,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -60,12 +60,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "EDY.DMP");
|
||||
dc_status_t a = test_dump_memory (name, "EDY.DMP");
|
||||
|
||||
message ("\nSUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -26,21 +26,21 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("hw_frog_device_open\n");
|
||||
device_status_t rc = hw_frog_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = hw_frog_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
message ("device_foreach\n");
|
||||
rc = device_foreach (device, NULL, NULL);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
device_close (device);
|
||||
return rc;
|
||||
@ -48,12 +48,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -73,7 +73,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "FROG.DMP");
|
||||
dc_status_t a = test_dump_memory (name, "FROG.DMP");
|
||||
|
||||
message ("SUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -26,14 +26,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("hw_ostc_device_open\n");
|
||||
device_status_t rc = hw_ostc_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = hw_ostc_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -42,7 +42,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -60,12 +60,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "OSTC.DMP");
|
||||
dc_status_t a = test_dump_memory (name, "OSTC.DMP");
|
||||
|
||||
message ("SUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -26,14 +26,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("mares_darwin_device_open\n");
|
||||
device_status_t rc = mares_darwin_device_open (&device, name, 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = mares_darwin_device_open (&device, name, 0);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -42,7 +42,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -60,12 +60,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "DARWIN.DMP");
|
||||
dc_status_t a = test_dump_memory (name, "DARWIN.DMP");
|
||||
|
||||
message ("SUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -26,14 +26,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("mares_iconhd_device_open\n");
|
||||
device_status_t rc = mares_iconhd_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = mares_iconhd_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -42,7 +42,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -60,12 +60,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "ICONHD.DMP");
|
||||
dc_status_t a = test_dump_memory (name, "ICONHD.DMP");
|
||||
|
||||
message ("\nSUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -26,14 +26,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("mares_nemo_device_open\n");
|
||||
device_status_t rc = mares_nemo_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = mares_nemo_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -42,7 +42,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -60,12 +60,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "NEMO.DMP");
|
||||
dc_status_t a = test_dump_memory (name, "NEMO.DMP");
|
||||
|
||||
message ("\nSUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -26,14 +26,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("mares_puck_device_open\n");
|
||||
device_status_t rc = mares_puck_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = mares_puck_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -42,7 +42,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -60,12 +60,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "PUCK.DMP");
|
||||
dc_status_t a = test_dump_memory (name, "PUCK.DMP");
|
||||
|
||||
message ("SUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -26,14 +26,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("oceanic_atom2_device_open\n");
|
||||
device_status_t rc = oceanic_atom2_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = oceanic_atom2_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -42,7 +42,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -60,7 +60,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_foreach\n");
|
||||
rc = device_foreach (device, NULL, NULL);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read dives.");
|
||||
device_close (device);
|
||||
return rc;
|
||||
@ -68,12 +68,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -93,7 +93,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "ATOM2.DMP");
|
||||
dc_status_t a = test_dump_memory (name, "ATOM2.DMP");
|
||||
|
||||
message ("\nSUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -26,14 +26,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("oceanic_veo250_device_open\n");
|
||||
device_status_t rc = oceanic_veo250_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = oceanic_veo250_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -42,7 +42,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -60,7 +60,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_foreach\n");
|
||||
rc = device_foreach (device, NULL, NULL);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read dives.");
|
||||
device_close (device);
|
||||
return rc;
|
||||
@ -68,12 +68,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -93,7 +93,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "VEO250.DMP");
|
||||
dc_status_t a = test_dump_memory (name, "VEO250.DMP");
|
||||
|
||||
message ("\nSUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -26,14 +26,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("oceanic_vtpro_device_open\n");
|
||||
device_status_t rc = oceanic_vtpro_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = oceanic_vtpro_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -42,7 +42,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -60,12 +60,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "VTPRO.DMP");
|
||||
dc_status_t a = test_dump_memory (name, "VTPRO.DMP");
|
||||
|
||||
message ("\nSUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -27,14 +27,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("reefnet_sensus_device_open\n");
|
||||
device_status_t rc = reefnet_sensus_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = reefnet_sensus_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -48,7 +48,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -66,12 +66,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -91,7 +91,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "SENSUS.DMP");
|
||||
dc_status_t a = test_dump_memory (name, "SENSUS.DMP");
|
||||
|
||||
message ("SUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -27,14 +27,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("reefnet_sensuspro_device_open\n");
|
||||
device_status_t rc = reefnet_sensuspro_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = reefnet_sensuspro_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -48,7 +48,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -66,12 +66,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -91,7 +91,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "SENSUSPRO.DMP");
|
||||
dc_status_t a = test_dump_memory (name, "SENSUSPRO.DMP");
|
||||
|
||||
message ("SUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -27,14 +27,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory_dives (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("reefnet_sensusultra_device_open\n");
|
||||
device_status_t rc = reefnet_sensusultra_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = reefnet_sensusultra_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -46,7 +46,7 @@ test_dump_memory_dives (const char* name, const char* filename)
|
||||
|
||||
message ("device_foreach\n");
|
||||
rc = device_foreach (device, NULL, NULL);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read dives.");
|
||||
device_close (device);
|
||||
return rc;
|
||||
@ -54,23 +54,23 @@ test_dump_memory_dives (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory_data (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("reefnet_sensusultra_device_open\n");
|
||||
device_status_t rc = reefnet_sensusultra_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = reefnet_sensusultra_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -84,7 +84,7 @@ test_dump_memory_data (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -102,24 +102,24 @@ test_dump_memory_data (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory_user (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
unsigned char data[REEFNET_SENSUSULTRA_MEMORY_USER_SIZE] = {0};
|
||||
|
||||
message ("reefnet_sensusultra_device_open\n");
|
||||
device_status_t rc = reefnet_sensusultra_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = reefnet_sensusultra_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -131,7 +131,7 @@ test_dump_memory_user (const char* name, const char* filename)
|
||||
|
||||
message ("reefnet_sensusultra_device_read_user\n");
|
||||
rc = reefnet_sensusultra_device_read_user (device, data, sizeof (data));
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
device_close (device);
|
||||
return rc;
|
||||
@ -146,12 +146,12 @@ test_dump_memory_user (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -171,9 +171,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory_data (name, "SENSUSULTRA_DATA.DMP");
|
||||
device_status_t b = test_dump_memory_user (name, "SENSUSULTRA_USER.DMP");
|
||||
device_status_t c = test_dump_memory_dives (name, "SENSUSULTRA_DIVES.DMP");
|
||||
dc_status_t a = test_dump_memory_data (name, "SENSUSULTRA_DATA.DMP");
|
||||
dc_status_t b = test_dump_memory_user (name, "SENSUSULTRA_USER.DMP");
|
||||
dc_status_t c = test_dump_memory_dives (name, "SENSUSULTRA_DIVES.DMP");
|
||||
|
||||
message ("SUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -26,14 +26,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_sdm (const char* name)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("suunto_d9_device_open\n");
|
||||
device_status_t rc = suunto_d9_device_open (&device, name, 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = suunto_d9_device_open (&device, name, 0);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -41,7 +41,7 @@ test_dump_sdm (const char* name)
|
||||
message ("device_version\n");
|
||||
unsigned char version[SUUNTO_D9_VERSION_SIZE] = {0};
|
||||
rc = device_version (device, version, sizeof (version));
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot identify computer.");
|
||||
device_close (device);
|
||||
return rc;
|
||||
@ -49,7 +49,7 @@ test_dump_sdm (const char* name)
|
||||
|
||||
message ("device_foreach\n");
|
||||
rc = device_foreach (device, NULL, NULL);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read dives.");
|
||||
device_close (device);
|
||||
return rc;
|
||||
@ -57,23 +57,23 @@ test_dump_sdm (const char* name)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("suunto_d9_device_open\n");
|
||||
device_status_t rc = suunto_d9_device_open (&device, name, 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = suunto_d9_device_open (&device, name, 0);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -81,7 +81,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
message ("device_version\n");
|
||||
unsigned char version[SUUNTO_D9_VERSION_SIZE] = {0};
|
||||
rc = device_version (device, version, sizeof (version));
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot identify computer.");
|
||||
device_close (device);
|
||||
return rc;
|
||||
@ -91,7 +91,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -109,12 +109,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -134,8 +134,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "D9.DMP");
|
||||
device_status_t b = test_dump_sdm (name);
|
||||
dc_status_t a = test_dump_memory (name, "D9.DMP");
|
||||
dc_status_t b = test_dump_sdm (name);
|
||||
|
||||
message ("\nSUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -26,14 +26,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("suunto_eon_device_open\n");
|
||||
device_status_t rc = suunto_eon_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = suunto_eon_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -42,7 +42,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -60,12 +60,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "EON.DMP");
|
||||
dc_status_t a = test_dump_memory (name, "EON.DMP");
|
||||
|
||||
message ("SUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -5,14 +5,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("suunto_solution_device_open\n");
|
||||
int rc = suunto_solution_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -21,7 +21,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -39,12 +39,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -65,7 +65,7 @@ main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "SOLUTION.DMP");
|
||||
dc_status_t a = test_dump_memory (name, "SOLUTION.DMP");
|
||||
|
||||
message ("\nSUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -26,14 +26,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_sdm (const char* name)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("suunto_vyper2_device_open\n");
|
||||
device_status_t rc = suunto_vyper2_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = suunto_vyper2_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -41,7 +41,7 @@ test_dump_sdm (const char* name)
|
||||
message ("device_version\n");
|
||||
unsigned char version[SUUNTO_VYPER2_VERSION_SIZE] = {0};
|
||||
rc = device_version (device, version, sizeof (version));
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot identify computer.");
|
||||
device_close (device);
|
||||
return rc;
|
||||
@ -49,7 +49,7 @@ test_dump_sdm (const char* name)
|
||||
|
||||
message ("device_foreach\n");
|
||||
rc = device_foreach (device, NULL, NULL);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read dives.");
|
||||
device_close (device);
|
||||
return rc;
|
||||
@ -57,23 +57,23 @@ test_dump_sdm (const char* name)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("suunto_vyper2_device_open\n");
|
||||
device_status_t rc = suunto_vyper2_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = suunto_vyper2_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -81,7 +81,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
message ("device_version\n");
|
||||
unsigned char version[SUUNTO_VYPER2_VERSION_SIZE] = {0};
|
||||
rc = device_version (device, version, sizeof (version));
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot identify computer.");
|
||||
device_close (device);
|
||||
return rc;
|
||||
@ -91,7 +91,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -109,12 +109,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -134,8 +134,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "VYPER2.DMP");
|
||||
device_status_t b = test_dump_sdm (name);
|
||||
dc_status_t a = test_dump_memory (name, "VYPER2.DMP");
|
||||
dc_status_t b = test_dump_sdm (name);
|
||||
|
||||
message ("\nSUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -27,14 +27,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_sdm (const char* name, unsigned int delay)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("suunto_vyper_device_open\n");
|
||||
device_status_t rc = suunto_vyper_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = suunto_vyper_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -43,7 +43,7 @@ test_dump_sdm (const char* name, unsigned int delay)
|
||||
|
||||
message ("device_foreach\n");
|
||||
rc = device_foreach (device, NULL, NULL);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read dives.");
|
||||
device_close (device);
|
||||
return rc;
|
||||
@ -51,23 +51,23 @@ test_dump_sdm (const char* name, unsigned int delay)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, unsigned int delay, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("suunto_vyper_device_open\n");
|
||||
device_status_t rc = suunto_vyper_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = suunto_vyper_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -78,7 +78,7 @@ test_dump_memory (const char* name, unsigned int delay, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -96,12 +96,12 @@ test_dump_memory (const char* name, unsigned int delay, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -126,8 +126,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s, DELAY=%i\n", name, delay);
|
||||
|
||||
device_status_t a = test_dump_sdm (name, delay);
|
||||
device_status_t b = test_dump_memory (name, delay, "VYPER.DMP");
|
||||
dc_status_t a = test_dump_sdm (name, delay);
|
||||
dc_status_t b = test_dump_memory (name, delay, "VYPER.DMP");
|
||||
|
||||
message ("\nSUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -283,13 +283,13 @@ sample_cb (parser_sample_type_t type, parser_sample_value_t value, void *userdat
|
||||
}
|
||||
}
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
doparse (FILE *fp, device_data_t *devdata, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
// Create the parser.
|
||||
message ("Creating the parser.\n");
|
||||
parser_t *parser = NULL;
|
||||
parser_status_t rc = PARSER_STATUS_SUCCESS;
|
||||
dc_status_t rc = DC_STATUS_SUCCESS;
|
||||
switch (devdata->backend) {
|
||||
case DEVICE_TYPE_SUUNTO_SOLUTION:
|
||||
rc = suunto_solution_parser_create (&parser);
|
||||
@ -356,10 +356,10 @@ doparse (FILE *fp, device_data_t *devdata, const unsigned char data[], unsigned
|
||||
rc = atomics_cobalt_parser_create (&parser);
|
||||
break;
|
||||
default:
|
||||
rc = PARSER_STATUS_ERROR;
|
||||
rc = DC_STATUS_INVALIDARGS;
|
||||
break;
|
||||
}
|
||||
if (rc != PARSER_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error creating the parser.");
|
||||
return rc;
|
||||
}
|
||||
@ -367,7 +367,7 @@ doparse (FILE *fp, device_data_t *devdata, const unsigned char data[], unsigned
|
||||
// Register the data.
|
||||
message ("Registering the data.\n");
|
||||
rc = parser_set_data (parser, data, size);
|
||||
if (rc != PARSER_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error registering the data.");
|
||||
parser_destroy (parser);
|
||||
return rc;
|
||||
@ -377,7 +377,7 @@ doparse (FILE *fp, device_data_t *devdata, const unsigned char data[], unsigned
|
||||
message ("Parsing the datetime.\n");
|
||||
dc_datetime_t dt = {0};
|
||||
rc = parser_get_datetime (parser, &dt);
|
||||
if (rc != PARSER_STATUS_SUCCESS && rc != PARSER_STATUS_UNSUPPORTED) {
|
||||
if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) {
|
||||
WARNING ("Error parsing the datetime.");
|
||||
parser_destroy (parser);
|
||||
return rc;
|
||||
@ -391,7 +391,7 @@ doparse (FILE *fp, device_data_t *devdata, const unsigned char data[], unsigned
|
||||
message ("Parsing the divetime.\n");
|
||||
unsigned int divetime = 0;
|
||||
rc = parser_get_field (parser, FIELD_TYPE_DIVETIME, 0, &divetime);
|
||||
if (rc != PARSER_STATUS_SUCCESS && rc != PARSER_STATUS_UNSUPPORTED) {
|
||||
if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) {
|
||||
WARNING ("Error parsing the divetime.");
|
||||
parser_destroy (parser);
|
||||
return rc;
|
||||
@ -404,7 +404,7 @@ doparse (FILE *fp, device_data_t *devdata, const unsigned char data[], unsigned
|
||||
message ("Parsing the maxdepth.\n");
|
||||
double maxdepth = 0.0;
|
||||
rc = parser_get_field (parser, FIELD_TYPE_MAXDEPTH, 0, &maxdepth);
|
||||
if (rc != PARSER_STATUS_SUCCESS && rc != PARSER_STATUS_UNSUPPORTED) {
|
||||
if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) {
|
||||
WARNING ("Error parsing the maxdepth.");
|
||||
parser_destroy (parser);
|
||||
return rc;
|
||||
@ -417,7 +417,7 @@ doparse (FILE *fp, device_data_t *devdata, const unsigned char data[], unsigned
|
||||
message ("Parsing the gas mixes.\n");
|
||||
unsigned int ngases = 0;
|
||||
rc = parser_get_field (parser, FIELD_TYPE_GASMIX_COUNT, 0, &ngases);
|
||||
if (rc != PARSER_STATUS_SUCCESS && rc != PARSER_STATUS_UNSUPPORTED) {
|
||||
if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) {
|
||||
WARNING ("Error parsing the gas mix count.");
|
||||
parser_destroy (parser);
|
||||
return rc;
|
||||
@ -426,7 +426,7 @@ doparse (FILE *fp, device_data_t *devdata, const unsigned char data[], unsigned
|
||||
for (unsigned int i = 0; i < ngases; ++i) {
|
||||
gasmix_t gasmix = {0};
|
||||
rc = parser_get_field (parser, FIELD_TYPE_GASMIX, i, &gasmix);
|
||||
if (rc != PARSER_STATUS_SUCCESS && rc != PARSER_STATUS_UNSUPPORTED) {
|
||||
if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) {
|
||||
WARNING ("Error parsing the gas mix.");
|
||||
parser_destroy (parser);
|
||||
return rc;
|
||||
@ -451,7 +451,7 @@ doparse (FILE *fp, device_data_t *devdata, const unsigned char data[], unsigned
|
||||
// Parse the sample data.
|
||||
message ("Parsing the sample data.\n");
|
||||
rc = parser_samples_foreach (parser, sample_cb, &sampledata);
|
||||
if (rc != PARSER_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error parsing the sample data.");
|
||||
parser_destroy (parser);
|
||||
return rc;
|
||||
@ -463,12 +463,12 @@ doparse (FILE *fp, device_data_t *devdata, const unsigned char data[], unsigned
|
||||
// Destroy the parser.
|
||||
message ("Destroying the parser.\n");
|
||||
rc = parser_destroy (parser);
|
||||
if (rc != PARSER_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error destroying the parser.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -577,10 +577,10 @@ usage (const char *filename)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
dowork (device_type_t backend, unsigned int model, const char *devname, const char *rawfile, const char *xmlfile, int memory, int dives, dc_buffer_t *fingerprint)
|
||||
{
|
||||
device_status_t rc = DEVICE_STATUS_SUCCESS;
|
||||
dc_status_t rc = DC_STATUS_SUCCESS;
|
||||
|
||||
// Initialize the device data.
|
||||
device_data_t devdata = {0};
|
||||
@ -661,10 +661,10 @@ dowork (device_type_t backend, unsigned int model, const char *devname, const ch
|
||||
rc = atomics_cobalt_device_open (&device);
|
||||
break;
|
||||
default:
|
||||
rc = DEVICE_STATUS_ERROR;
|
||||
rc = DC_STATUS_INVALIDARGS;
|
||||
break;
|
||||
}
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening device.");
|
||||
return rc;
|
||||
}
|
||||
@ -673,7 +673,7 @@ dowork (device_type_t backend, unsigned int model, const char *devname, const ch
|
||||
message ("Registering the event handler.\n");
|
||||
int events = DEVICE_EVENT_WAITING | DEVICE_EVENT_PROGRESS | DEVICE_EVENT_DEVINFO | DEVICE_EVENT_CLOCK;
|
||||
rc = device_set_events (device, events, event_cb, &devdata);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error registering the event handler.");
|
||||
device_close (device);
|
||||
return rc;
|
||||
@ -682,7 +682,7 @@ dowork (device_type_t backend, unsigned int model, const char *devname, const ch
|
||||
// Register the cancellation handler.
|
||||
message ("Registering the cancellation handler.\n");
|
||||
rc = device_set_cancel (device, cancel_cb, NULL);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error registering the cancellation handler.");
|
||||
device_close (device);
|
||||
return rc;
|
||||
@ -692,7 +692,7 @@ dowork (device_type_t backend, unsigned int model, const char *devname, const ch
|
||||
if (fingerprint) {
|
||||
message ("Registering the fingerprint data.\n");
|
||||
rc = device_set_fingerprint (device, dc_buffer_get_data (fingerprint), dc_buffer_get_size (fingerprint));
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error registering the fingerprint data.");
|
||||
device_close (device);
|
||||
return rc;
|
||||
@ -706,7 +706,7 @@ dowork (device_type_t backend, unsigned int model, const char *devname, const ch
|
||||
// Download the memory dump.
|
||||
message ("Downloading the memory dump.\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error downloading the memory dump.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -737,7 +737,7 @@ dowork (device_type_t backend, unsigned int model, const char *devname, const ch
|
||||
// Download the dives.
|
||||
message ("Downloading the dives.\n");
|
||||
rc = device_foreach (device, dive_cb, &divedata);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error downloading the dives.");
|
||||
dc_buffer_free (divedata.fingerprint);
|
||||
if (divedata.fp) fclose (divedata.fp);
|
||||
@ -760,12 +760,12 @@ dowork (device_type_t backend, unsigned int model, const char *devname, const ch
|
||||
// Close the device.
|
||||
message ("Closing the device.\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error closing the device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -846,11 +846,11 @@ main (int argc, char *argv[])
|
||||
message_set_logfile (logfile);
|
||||
|
||||
dc_buffer_t *fp = fpconvert (fingerprint);
|
||||
device_status_t rc = dowork (backend, model, devname, rawfile, xmlfile, memory, dives, fp);
|
||||
dc_status_t rc = dowork (backend, model, devname, rawfile, xmlfile, memory, dives, fp);
|
||||
dc_buffer_free (fp);
|
||||
message ("Result: %s\n", errmsg (rc));
|
||||
|
||||
message_set_logfile (NULL);
|
||||
|
||||
return rc != DEVICE_STATUS_SUCCESS ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
return rc != DC_STATUS_SUCCESS ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -5,14 +5,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("uwatec_aladin_device_open\n");
|
||||
device_status_t rc = uwatec_aladin_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = uwatec_aladin_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -21,7 +21,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -39,12 +39,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -64,7 +64,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "ALADIN.DMP");
|
||||
dc_status_t a = test_dump_memory (name, "ALADIN.DMP");
|
||||
|
||||
message ("\nSUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -26,14 +26,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("uwatec_memomouse_device_open\n");
|
||||
device_status_t rc = uwatec_memomouse_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = uwatec_memomouse_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -42,7 +42,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -60,12 +60,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "MEMOMOUSE.DMP");
|
||||
dc_status_t a = test_dump_memory (name, "MEMOMOUSE.DMP");
|
||||
|
||||
message ("\nSUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -28,14 +28,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("uwatec_smart_device_open\n");
|
||||
device_status_t rc = uwatec_smart_device_open (&device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = uwatec_smart_device_open (&device);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot open device.");
|
||||
return rc;
|
||||
}
|
||||
@ -43,7 +43,7 @@ test_dump_memory (const char* filename)
|
||||
message ("device_version\n");
|
||||
unsigned char version[UWATEC_SMART_VERSION_SIZE] = {0};
|
||||
rc = device_version (device, version, sizeof (version));
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot identify computer.");
|
||||
device_close (device);
|
||||
return rc;
|
||||
@ -53,7 +53,7 @@ test_dump_memory (const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -71,12 +71,12 @@ test_dump_memory (const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -84,7 +84,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
message_set_logfile ("SMART.LOG");
|
||||
|
||||
device_status_t a = test_dump_memory ("SMART.DMP");
|
||||
dc_status_t a = test_dump_memory ("SMART.DMP");
|
||||
|
||||
message ("\nSUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -26,14 +26,14 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
test_dump_memory (const char* name, const char* filename)
|
||||
{
|
||||
device_t *device = NULL;
|
||||
|
||||
message ("zeagle_n2ition3_device_open\n");
|
||||
device_status_t rc = zeagle_n2ition3_device_open (&device, name);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = zeagle_n2ition3_device_open (&device, name);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Error opening serial port.");
|
||||
return rc;
|
||||
}
|
||||
@ -42,7 +42,7 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_dump\n");
|
||||
rc = device_dump (device, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
dc_buffer_free (buffer);
|
||||
device_close (device);
|
||||
@ -60,12 +60,12 @@ test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
message ("device_close\n");
|
||||
rc = device_close (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot close device.");
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
message ("DEVICE=%s\n", name);
|
||||
|
||||
device_status_t a = test_dump_memory (name, "N2ITION3.DMP");
|
||||
dc_status_t a = test_dump_memory (name, "N2ITION3.DMP");
|
||||
|
||||
message ("\nSUMMARY\n");
|
||||
message ("-------\n");
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
libdivecomputerdir = $(includedir)/libdivecomputer
|
||||
libdivecomputer_HEADERS = \
|
||||
version.h \
|
||||
common.h \
|
||||
utils.h \
|
||||
buffer.h \
|
||||
device.h \
|
||||
|
||||
@ -29,16 +29,16 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
atomics_cobalt_device_open (device_t **device);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
atomics_cobalt_device_set_simulation (device_t *abstract, unsigned int simulation);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
atomics_cobalt_parser_create (parser_t **parser);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
atomics_cobalt_parser_set_calibration (parser_t *abstract, double atmospheric, double hydrostatic);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
46
include/libdivecomputer/common.h
Normal file
46
include/libdivecomputer/common.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* libdivecomputer
|
||||
*
|
||||
* Copyright (C) 2011 Jef Driesen
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef DC_COMMON_H
|
||||
#define DC_COMMON_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef enum dc_status_t {
|
||||
DC_STATUS_SUCCESS = 0,
|
||||
DC_STATUS_UNSUPPORTED = -1,
|
||||
DC_STATUS_INVALIDARGS = -2,
|
||||
DC_STATUS_NOMEMORY = -3,
|
||||
DC_STATUS_NODEVICE = -4,
|
||||
DC_STATUS_NOACCESS = -5,
|
||||
DC_STATUS_IO = -6,
|
||||
DC_STATUS_TIMEOUT = -7,
|
||||
DC_STATUS_PROTOCOL = -8,
|
||||
DC_STATUS_DATAFORMAT = -9,
|
||||
DC_STATUS_CANCELLED = -10
|
||||
} dc_status_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* DC_COMMON_H */
|
||||
@ -32,10 +32,10 @@ extern "C" {
|
||||
#define CRESSI_EDY_MEMORY_SIZE 0x8000
|
||||
#define CRESSI_EDY_PACKET_SIZE 128
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
cressi_edy_device_open (device_t **device, const char* name);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
cressi_edy_parser_create (parser_t **parser, unsigned int model);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
#ifndef DEVICE_H
|
||||
#define DEVICE_H
|
||||
|
||||
#include "common.h"
|
||||
#include "buffer.h"
|
||||
#include "datetime.h"
|
||||
|
||||
@ -56,18 +57,6 @@ typedef enum device_type_t {
|
||||
DEVICE_TYPE_ATOMICS_COBALT
|
||||
} device_type_t;
|
||||
|
||||
typedef enum device_status_t {
|
||||
DEVICE_STATUS_SUCCESS = 0,
|
||||
DEVICE_STATUS_UNSUPPORTED = -1,
|
||||
DEVICE_STATUS_TYPE_MISMATCH = -2,
|
||||
DEVICE_STATUS_ERROR = -3,
|
||||
DEVICE_STATUS_IO = -4,
|
||||
DEVICE_STATUS_TIMEOUT = -5,
|
||||
DEVICE_STATUS_PROTOCOL = -6,
|
||||
DEVICE_STATUS_MEMORY = -7,
|
||||
DEVICE_STATUS_CANCELLED = -8
|
||||
} device_status_t;
|
||||
|
||||
typedef enum device_event_t {
|
||||
DEVICE_EVENT_WAITING = (1 << 0),
|
||||
DEVICE_EVENT_PROGRESS = (1 << 1),
|
||||
@ -101,23 +90,23 @@ typedef int (*dive_callback_t) (const unsigned char *data, unsigned int size, co
|
||||
|
||||
device_type_t device_get_type (device_t *device);
|
||||
|
||||
device_status_t device_set_cancel (device_t *device, device_cancel_callback_t callback, void *userdata);
|
||||
dc_status_t device_set_cancel (device_t *device, device_cancel_callback_t callback, void *userdata);
|
||||
|
||||
device_status_t device_set_events (device_t *device, unsigned int events, device_event_callback_t callback, void *userdata);
|
||||
dc_status_t device_set_events (device_t *device, unsigned int events, device_event_callback_t callback, void *userdata);
|
||||
|
||||
device_status_t device_set_fingerprint (device_t *device, const unsigned char data[], unsigned int size);
|
||||
dc_status_t device_set_fingerprint (device_t *device, const unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t device_version (device_t *device, unsigned char data[], unsigned int size);
|
||||
dc_status_t device_version (device_t *device, unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t device_read (device_t *device, unsigned int address, unsigned char data[], unsigned int size);
|
||||
dc_status_t device_read (device_t *device, unsigned int address, unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t device_write (device_t *device, unsigned int address, const unsigned char data[], unsigned int size);
|
||||
dc_status_t device_write (device_t *device, unsigned int address, const unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t device_dump (device_t *device, dc_buffer_t *buffer);
|
||||
dc_status_t device_dump (device_t *device, dc_buffer_t *buffer);
|
||||
|
||||
device_status_t device_foreach (device_t *device, dive_callback_t callback, void *userdata);
|
||||
dc_status_t device_foreach (device_t *device, dive_callback_t callback, void *userdata);
|
||||
|
||||
device_status_t device_close (device_t *device);
|
||||
dc_status_t device_close (device_t *device);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -30,16 +30,16 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_frog_device_open (device_t **device, const char *name);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_frog_device_clock (device_t *device, const dc_datetime_t *datetime);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_frog_device_display (device_t *device, const char *text);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_frog_device_customtext (device_t *abstract, const char *text);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -36,31 +36,31 @@ typedef enum hw_ostc_format_t {
|
||||
HW_OSTC_FORMAT_RGB24
|
||||
} hw_ostc_format_t;
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_ostc_device_open (device_t **device, const char* name);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_ostc_device_md2hash (device_t *abstract, unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_ostc_device_clock (device_t *abstract, const dc_datetime_t *datetime);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_ostc_device_eeprom_read (device_t *abstract, unsigned int bank, unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_ostc_device_eeprom_write (device_t *abstract, unsigned int bank, const unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_ostc_device_reset (device_t *abstract);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_ostc_device_screenshot (device_t *abstract, dc_buffer_t *buffer, hw_ostc_format_t format);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_ostc_extract_dives (device_t *abstract, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
hw_ostc_parser_create (parser_t **parser, unsigned int frog);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -29,13 +29,13 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_darwin_device_open (device_t **device, const char *name, unsigned int model);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_darwin_extract_dives (device_t *device, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
mares_darwin_parser_create (parser_t **parser, unsigned int model);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -31,13 +31,13 @@ extern "C" {
|
||||
|
||||
#define MARES_ICONHD_MEMORY_SIZE 0x100000
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_iconhd_device_open (device_t **device, const char* name);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_iconhd_extract_dives (device_t *abstract, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
mares_iconhd_parser_create (parser_t **parser, unsigned int model);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -29,13 +29,13 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_nemo_device_open (device_t **device, const char* name);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_nemo_extract_dives (device_t *device, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
mares_nemo_parser_create (parser_t **parser, unsigned int model);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -29,10 +29,10 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_puck_device_open (device_t **device, const char* name);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_puck_extract_dives (device_t *device, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -29,13 +29,13 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_atom2_device_open (device_t **device, const char* name);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_atom2_device_keepalive (device_t *device);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
oceanic_atom2_parser_create (parser_t **parser, unsigned int model);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -29,13 +29,13 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_veo250_device_open (device_t **device, const char* name);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_veo250_device_keepalive (device_t *device);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
oceanic_veo250_parser_create (parser_t **parser, unsigned int model);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -29,13 +29,13 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_vtpro_device_open (device_t **device, const char* name);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_vtpro_device_keepalive (device_t *device);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
oceanic_vtpro_parser_create (parser_t **parser);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
#ifndef PARSER_H
|
||||
#define PARSER_H
|
||||
|
||||
#include "common.h"
|
||||
#include "datetime.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -50,14 +51,6 @@ typedef enum parser_type_t {
|
||||
PARSER_TYPE_ATOMICS_COBALT
|
||||
} parser_type_t;
|
||||
|
||||
typedef enum parser_status_t {
|
||||
PARSER_STATUS_SUCCESS = 0,
|
||||
PARSER_STATUS_UNSUPPORTED = -1,
|
||||
PARSER_STATUS_TYPE_MISMATCH = -2,
|
||||
PARSER_STATUS_ERROR = -3,
|
||||
PARSER_STATUS_MEMORY = -7
|
||||
} parser_status_t;
|
||||
|
||||
typedef enum parser_sample_type_t {
|
||||
SAMPLE_TYPE_TIME,
|
||||
SAMPLE_TYPE_DEPTH,
|
||||
@ -158,19 +151,19 @@ typedef void (*sample_callback_t) (parser_sample_type_t type, parser_sample_valu
|
||||
parser_type_t
|
||||
parser_get_type (parser_t *device);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
parser_set_data (parser_t *parser, const unsigned char *data, unsigned int size);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
parser_get_datetime (parser_t *parser, dc_datetime_t *datetime);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
parser_get_field (parser_t *parser, parser_field_type_t type, unsigned int flags, void *value);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
parser_samples_foreach (parser_t *parser, sample_callback_t callback, void *userdata);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
parser_destroy (parser_t *parser);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -32,22 +32,22 @@ extern "C" {
|
||||
#define REEFNET_SENSUS_MEMORY_SIZE 32768
|
||||
#define REEFNET_SENSUS_HANDSHAKE_SIZE 10
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensus_device_open (device_t **device, const char* name);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensus_device_set_timestamp (device_t *device, unsigned int timestamp);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensus_device_get_handshake (device_t *abstract, unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensus_extract_dives (device_t *device, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
reefnet_sensus_parser_create (parser_t **parser, unsigned int devtime, dc_ticks_t systime);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
reefnet_sensus_parser_set_calibration (parser_t *parser, double atmospheric, double hydrostatic);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -32,25 +32,25 @@ extern "C" {
|
||||
#define REEFNET_SENSUSPRO_MEMORY_SIZE 56320
|
||||
#define REEFNET_SENSUSPRO_HANDSHAKE_SIZE 10
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensuspro_device_open (device_t **device, const char* name);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensuspro_device_set_timestamp (device_t *device, unsigned int timestamp);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensuspro_device_get_handshake (device_t *abstract, unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensuspro_device_write_interval (device_t *device, unsigned char interval);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensuspro_extract_dives (device_t *device, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
reefnet_sensuspro_parser_create (parser_t **parser, unsigned int devtime, dc_ticks_t systime);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
reefnet_sensuspro_parser_set_calibration (parser_t *parser, double atmospheric, double hydrostatic);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -43,37 +43,37 @@ typedef enum reefnet_sensusultra_parameter_t {
|
||||
REEFNET_SENSUSULTRA_PARAMETER_AVERAGING
|
||||
} reefnet_sensusultra_parameter_t;
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_device_open (device_t **device, const char* name);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_device_set_maxretries (device_t *device, unsigned int maxretries);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_device_set_timestamp (device_t *device, unsigned int timestamp);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_device_get_handshake (device_t *abstract, unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_device_read_user (device_t *device, unsigned char *data, unsigned int size);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_device_write_user (device_t *device, const unsigned char *data, unsigned int size);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_device_write_parameter (device_t *device, reefnet_sensusultra_parameter_t parameter, unsigned int value);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_device_sense (device_t *device, unsigned char *data, unsigned int size);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_extract_dives (device_t *device, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_parser_create (parser_t **parser, unsigned int devtime, dc_ticks_t systime);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_parser_set_calibration (parser_t *parser, double atmospheric, double hydrostatic);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -33,13 +33,13 @@ extern "C" {
|
||||
#define SUUNTO_D9_PACKET_SIZE 0x78
|
||||
#define SUUNTO_D9_VERSION_SIZE 0x04
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_d9_device_open (device_t **device, const char* name, unsigned int model);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_d9_device_reset_maxdepth (device_t *device);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
suunto_d9_parser_create (parser_t **parser, unsigned int model);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -31,19 +31,19 @@ extern "C" {
|
||||
|
||||
#define SUUNTO_EON_MEMORY_SIZE 0x900
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_eon_device_open (device_t **device, const char* name);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_eon_device_write_name (device_t *device, unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_eon_device_write_interval (device_t *device, unsigned char interval);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_eon_extract_dives (device_t *device, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
suunto_eon_parser_create (parser_t **parser, int spyder);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -31,13 +31,13 @@ extern "C" {
|
||||
|
||||
#define SUUNTO_SOLUTION_MEMORY_SIZE 256
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_solution_device_open (device_t **device, const char* name);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_solution_extract_dives (device_t *device, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
suunto_solution_parser_create (parser_t **parser);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -32,19 +32,19 @@ extern "C" {
|
||||
#define SUUNTO_VYPER_MEMORY_SIZE 0x2000
|
||||
#define SUUNTO_VYPER_PACKET_SIZE 32
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_vyper_device_open (device_t **device, const char* name);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_vyper_device_set_delay (device_t *device, unsigned int delay);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_vyper_device_read_dive (device_t *device, dc_buffer_t *buffer, int init);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_vyper_extract_dives (device_t *device, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
suunto_vyper_parser_create (parser_t **parser);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -32,10 +32,10 @@ extern "C" {
|
||||
#define SUUNTO_VYPER2_PACKET_SIZE 0x78
|
||||
#define SUUNTO_VYPER2_VERSION_SIZE 0x04
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_vyper2_device_open (device_t **device, const char* name);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_vyper2_device_reset_maxdepth (device_t *device);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -30,13 +30,13 @@ extern "C" {
|
||||
|
||||
#define UWATEC_ALADIN_MEMORY_SIZE 2048
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
uwatec_aladin_device_open (device_t **device, const char* name);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
uwatec_aladin_device_set_timestamp (device_t *device, unsigned int timestamp);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
uwatec_aladin_extract_dives (device_t *device, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -29,16 +29,16 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
uwatec_memomouse_device_open (device_t **device, const char* name);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
uwatec_memomouse_device_set_timestamp (device_t *device, unsigned int timestamp);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
uwatec_memomouse_extract_dives (device_t *device, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
uwatec_memomouse_parser_create (parser_t **parser, unsigned int devtime, dc_ticks_t systime);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -31,16 +31,16 @@ extern "C" {
|
||||
|
||||
#define UWATEC_SMART_VERSION_SIZE 9
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
uwatec_smart_device_open (device_t **device);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
uwatec_smart_device_set_timestamp (device_t *device, unsigned int timestamp);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
uwatec_smart_extract_dives (device_t *device, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
uwatec_smart_parser_create (parser_t **parser, unsigned int model, unsigned int devtime, dc_ticks_t systime);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -31,7 +31,7 @@ extern "C" {
|
||||
#define ZEAGLE_N2ITION3_MEMORY_SIZE 0x8000
|
||||
#define ZEAGLE_N2ITION3_PACKET_SIZE 64
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
zeagle_n2ition3_device_open (device_t **device, const char* name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -57,10 +57,10 @@ typedef struct atomics_cobalt_device_t {
|
||||
unsigned char version[SZ_VERSION];
|
||||
} atomics_cobalt_device_t;
|
||||
|
||||
static device_status_t atomics_cobalt_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t atomics_cobalt_device_version (device_t *abstract, unsigned char data[], unsigned int size);
|
||||
static device_status_t atomics_cobalt_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t atomics_cobalt_device_close (device_t *abstract);
|
||||
static dc_status_t atomics_cobalt_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static dc_status_t atomics_cobalt_device_version (device_t *abstract, unsigned char data[], unsigned int size);
|
||||
static dc_status_t atomics_cobalt_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static dc_status_t atomics_cobalt_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t atomics_cobalt_device_backend = {
|
||||
DEVICE_TYPE_ATOMICS_COBALT,
|
||||
@ -83,18 +83,18 @@ device_is_atomics_cobalt (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
atomics_cobalt_device_open (device_t **out)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
#ifdef HAVE_LIBUSB
|
||||
// Allocate memory.
|
||||
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) malloc (sizeof (atomics_cobalt_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -110,7 +110,7 @@ atomics_cobalt_device_open (device_t **out)
|
||||
if (rc < 0) {
|
||||
WARNING ("Failed to initialize usb support.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
device->handle = libusb_open_device_with_vid_pid (device->context, VID, PID);
|
||||
@ -118,7 +118,7 @@ atomics_cobalt_device_open (device_t **out)
|
||||
WARNING ("Failed to open the usb device.");
|
||||
libusb_exit (device->context);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
rc = libusb_claim_interface (device->handle, 0);
|
||||
@ -127,11 +127,11 @@ atomics_cobalt_device_open (device_t **out)
|
||||
libusb_close (device->handle);
|
||||
libusb_exit (device->context);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
device_status_t status = atomics_cobalt_device_version ((device_t *) device, device->version, sizeof (device->version));
|
||||
if (status != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t status = atomics_cobalt_device_version ((device_t *) device, device->version, sizeof (device->version));
|
||||
if (status != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Failed to identify the dive computer.");
|
||||
libusb_close (device->handle);
|
||||
libusb_exit (device->context);
|
||||
@ -141,20 +141,20 @@ atomics_cobalt_device_open (device_t **out)
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
#else
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
atomics_cobalt_device_close (device_t *abstract)
|
||||
{
|
||||
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract;
|
||||
|
||||
if (! device_is_atomics_cobalt (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
#ifdef HAVE_LIBUSB
|
||||
libusb_release_interface(device->handle, 0);
|
||||
@ -165,51 +165,51 @@ atomics_cobalt_device_close (device_t *abstract)
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
atomics_cobalt_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract;
|
||||
|
||||
if (! device_is_atomics_cobalt (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size && size != sizeof (device->fingerprint))
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size)
|
||||
memcpy (device->fingerprint, data, sizeof (device->fingerprint));
|
||||
else
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
atomics_cobalt_device_set_simulation (device_t *abstract, unsigned int simulation)
|
||||
{
|
||||
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract;
|
||||
|
||||
if (! device_is_atomics_cobalt (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
device->simulation = simulation;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
atomics_cobalt_device_version (device_t *abstract, unsigned char data[], unsigned int size)
|
||||
{
|
||||
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract;
|
||||
|
||||
if (size < SZ_VERSION)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
#ifdef HAVE_LIBUSB
|
||||
// Send the command to the dive computer.
|
||||
@ -219,7 +219,7 @@ atomics_cobalt_device_version (device_t *abstract, unsigned char data[], unsigne
|
||||
bRequest, 0, 0, NULL, 0, TIMEOUT);
|
||||
if (rc != LIBUSB_SUCCESS) {
|
||||
WARNING ("Failed to send the command.");
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Receive the answer from the dive computer.
|
||||
@ -229,7 +229,7 @@ atomics_cobalt_device_version (device_t *abstract, unsigned char data[], unsigne
|
||||
packet, sizeof (packet), &length, TIMEOUT);
|
||||
if (rc != LIBUSB_SUCCESS || length != sizeof (packet)) {
|
||||
WARNING ("Failed to receive the answer.");
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Verify the checksum of the packet.
|
||||
@ -237,31 +237,31 @@ atomics_cobalt_device_version (device_t *abstract, unsigned char data[], unsigne
|
||||
unsigned short ccrc = checksum_add_uint16 (packet, SZ_VERSION, 0x0);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
memcpy (data, packet, SZ_VERSION);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
#else
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
atomics_cobalt_read_dive (device_t *abstract, dc_buffer_t *buffer, int init, device_progress_t *progress)
|
||||
{
|
||||
#ifdef HAVE_LIBUSB
|
||||
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract;
|
||||
|
||||
if (device_is_cancelled (abstract))
|
||||
return DEVICE_STATUS_CANCELLED;
|
||||
return DC_STATUS_CANCELLED;
|
||||
|
||||
// Erase the current contents of the buffer.
|
||||
if (!dc_buffer_clear (buffer)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Send the command to the dive computer.
|
||||
@ -275,7 +275,7 @@ atomics_cobalt_read_dive (device_t *abstract, dc_buffer_t *buffer, int init, dev
|
||||
bRequest, 0, 0, NULL, 0, TIMEOUT);
|
||||
if (rc != LIBUSB_SUCCESS) {
|
||||
WARNING ("Failed to send the command.");
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
unsigned int nbytes = 0;
|
||||
@ -287,7 +287,7 @@ atomics_cobalt_read_dive (device_t *abstract, dc_buffer_t *buffer, int init, dev
|
||||
packet, sizeof (packet), &length, TIMEOUT);
|
||||
if (rc != LIBUSB_SUCCESS && rc != LIBUSB_ERROR_TIMEOUT) {
|
||||
WARNING ("Failed to receive the answer.");
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Update and emit a progress event.
|
||||
@ -308,20 +308,20 @@ atomics_cobalt_read_dive (device_t *abstract, dc_buffer_t *buffer, int init, dev
|
||||
// Check for a buffer error.
|
||||
if (dc_buffer_get_size (buffer) != nbytes) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Check for the minimum length.
|
||||
if (nbytes < 2) {
|
||||
WARNING ("Data packet is too short.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// When only two 0xFF bytes are received, there are no more dives.
|
||||
unsigned char *data = dc_buffer_get_data (buffer);
|
||||
if (nbytes == 2 && data[0] == 0xFF && data[1] == 0xFF) {
|
||||
dc_buffer_clear (buffer);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Verify the checksum of the packet.
|
||||
@ -329,26 +329,26 @@ atomics_cobalt_read_dive (device_t *abstract, dc_buffer_t *buffer, int init, dev
|
||||
unsigned short ccrc = checksum_add_uint16 (data, nbytes - 2, 0x0);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Remove the checksum bytes.
|
||||
dc_buffer_slice (buffer, 0, nbytes - 2);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
#else
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
atomics_cobalt_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract;
|
||||
|
||||
if (! device_is_atomics_cobalt (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Enable progress notifications.
|
||||
device_progress_t progress = DEVICE_PROGRESS_INITIALIZER;
|
||||
@ -370,27 +370,27 @@ atomics_cobalt_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
// Allocate a memory buffer.
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
|
||||
unsigned int ndives = 0;
|
||||
device_status_t rc = DEVICE_STATUS_SUCCESS;
|
||||
while ((rc = atomics_cobalt_read_dive (abstract, buffer, (ndives == 0), &progress)) == DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = DC_STATUS_SUCCESS;
|
||||
while ((rc = atomics_cobalt_read_dive (abstract, buffer, (ndives == 0), &progress)) == DC_STATUS_SUCCESS) {
|
||||
unsigned char *data = dc_buffer_get_data (buffer);
|
||||
unsigned int size = dc_buffer_get_size (buffer);
|
||||
|
||||
if (size == 0) {
|
||||
dc_buffer_free (buffer);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (memcmp (data + FP_OFFSET, device->fingerprint, sizeof (device->fingerprint)) == 0) {
|
||||
dc_buffer_free (buffer);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (callback && !callback (data, size, data + FP_OFFSET, sizeof (device->fingerprint), userdata)) {
|
||||
dc_buffer_free (buffer);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Adjust the maximum value to take into account the two checksum bytes
|
||||
|
||||
@ -42,11 +42,11 @@ struct atomics_cobalt_parser_t {
|
||||
double hydrostatic;
|
||||
};
|
||||
|
||||
static parser_status_t atomics_cobalt_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static parser_status_t atomics_cobalt_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static parser_status_t atomics_cobalt_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static parser_status_t atomics_cobalt_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static parser_status_t atomics_cobalt_parser_destroy (parser_t *abstract);
|
||||
static dc_status_t atomics_cobalt_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static dc_status_t atomics_cobalt_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static dc_status_t atomics_cobalt_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static dc_status_t atomics_cobalt_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static dc_status_t atomics_cobalt_parser_destroy (parser_t *abstract);
|
||||
|
||||
static const parser_backend_t atomics_cobalt_parser_backend = {
|
||||
PARSER_TYPE_ATOMICS_COBALT,
|
||||
@ -68,17 +68,17 @@ parser_is_atomics_cobalt (parser_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
atomics_cobalt_parser_create (parser_t **out)
|
||||
{
|
||||
if (out == NULL)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
atomics_cobalt_parser_t *parser = (atomics_cobalt_parser_t *) malloc (sizeof (atomics_cobalt_parser_t));
|
||||
if (parser == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return PARSER_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -90,53 +90,53 @@ atomics_cobalt_parser_create (parser_t **out)
|
||||
|
||||
*out = (parser_t*) parser;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
atomics_cobalt_parser_destroy (parser_t *abstract)
|
||||
{
|
||||
if (! parser_is_atomics_cobalt (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Free memory.
|
||||
free (abstract);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
atomics_cobalt_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
if (! parser_is_atomics_cobalt (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
atomics_cobalt_parser_set_calibration (parser_t *abstract, double atmospheric, double hydrostatic)
|
||||
{
|
||||
atomics_cobalt_parser_t *parser = (atomics_cobalt_parser_t*) abstract;
|
||||
|
||||
if (! parser_is_atomics_cobalt (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
parser->atmospheric = atmospheric;
|
||||
parser->hydrostatic = hydrostatic;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
atomics_cobalt_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
{
|
||||
if (abstract->size < SZ_HEADER)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *p = abstract->data;
|
||||
|
||||
@ -149,17 +149,17 @@ atomics_cobalt_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
datetime->second = 0;
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
atomics_cobalt_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value)
|
||||
{
|
||||
atomics_cobalt_parser_t *parser = (atomics_cobalt_parser_t *) abstract;
|
||||
|
||||
if (abstract->size < SZ_HEADER)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *p = abstract->data;
|
||||
|
||||
@ -188,15 +188,15 @@ atomics_cobalt_parser_get_field (parser_t *abstract, parser_field_type_t type, u
|
||||
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
atomics_cobalt_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata)
|
||||
{
|
||||
atomics_cobalt_parser_t *parser = (atomics_cobalt_parser_t *) abstract;
|
||||
@ -205,7 +205,7 @@ atomics_cobalt_parser_samples_foreach (parser_t *abstract, sample_callback_t cal
|
||||
unsigned int size = abstract->size;
|
||||
|
||||
if (size < SZ_HEADER)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int interval = data[0x1a];
|
||||
unsigned int ngasmixes = data[0x2a];
|
||||
@ -216,7 +216,7 @@ atomics_cobalt_parser_samples_foreach (parser_t *abstract, sample_callback_t cal
|
||||
SZ_GASSWITCH * nswitches;
|
||||
|
||||
if (size < header + SZ_SEGMENT * nsegments)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
double atmospheric = 0.0;
|
||||
if (parser->atmospheric)
|
||||
@ -253,5 +253,5 @@ atomics_cobalt_parser_samples_foreach (parser_t *abstract, sample_callback_t cal
|
||||
offset += SZ_SEGMENT;
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
108
src/cressi_edy.c
108
src/cressi_edy.c
@ -34,7 +34,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
#define PAGESIZE (CRESSI_EDY_PACKET_SIZE / 4)
|
||||
@ -55,11 +55,11 @@ typedef struct cressi_edy_device_t {
|
||||
unsigned int model;
|
||||
} cressi_edy_device_t;
|
||||
|
||||
static device_status_t cressi_edy_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t cressi_edy_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
static device_status_t cressi_edy_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t cressi_edy_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t cressi_edy_device_close (device_t *abstract);
|
||||
static dc_status_t cressi_edy_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static dc_status_t cressi_edy_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
static dc_status_t cressi_edy_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static dc_status_t cressi_edy_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static dc_status_t cressi_edy_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t cressi_edy_device_backend = {
|
||||
DEVICE_TYPE_CRESSI_EDY,
|
||||
@ -82,7 +82,7 @@ device_is_cressi_edy (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
cressi_edy_transfer (cressi_edy_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, int trailer)
|
||||
{
|
||||
assert (asize >= csize);
|
||||
@ -91,7 +91,7 @@ cressi_edy_transfer (cressi_edy_device_t *device, const unsigned char command[],
|
||||
int rc = serial_flush (device->port, SERIAL_QUEUE_INPUT);
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to flush the serial input buffer.");
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Send the command to the device.
|
||||
@ -111,20 +111,20 @@ cressi_edy_transfer (cressi_edy_device_t *device, const unsigned char command[],
|
||||
// Verify the echo.
|
||||
if (memcmp (answer, command, csize) != 0) {
|
||||
WARNING ("Unexpected echo.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Verify the trailer of the packet.
|
||||
if (trailer && answer[asize - 1] != 0x45) {
|
||||
WARNING ("Unexpected answer trailer byte.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
cressi_edy_init1 (cressi_edy_device_t *device)
|
||||
{
|
||||
unsigned char command[3] = {0x41, 0x42, 0x43};
|
||||
@ -134,23 +134,23 @@ cressi_edy_init1 (cressi_edy_device_t *device)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
cressi_edy_init2 (cressi_edy_device_t *device)
|
||||
{
|
||||
unsigned char command[1] = {0x44};
|
||||
unsigned char answer[2] = {0};
|
||||
|
||||
device_status_t rc = cressi_edy_transfer (device, command, sizeof (command), answer, sizeof (answer), 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = cressi_edy_transfer (device, command, sizeof (command), answer, sizeof (answer), 0);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
device->model = answer[1];
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
cressi_edy_init3 (cressi_edy_device_t *device)
|
||||
{
|
||||
unsigned char command[1] = {0x0C};
|
||||
@ -160,7 +160,7 @@ cressi_edy_init3 (cressi_edy_device_t *device)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
cressi_edy_quit (cressi_edy_device_t *device)
|
||||
{
|
||||
unsigned char command[1] = {0x46};
|
||||
@ -170,17 +170,17 @@ cressi_edy_quit (cressi_edy_device_t *device)
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
cressi_edy_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
cressi_edy_device_t *device = (cressi_edy_device_t *) malloc (sizeof (cressi_edy_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -195,7 +195,7 @@ cressi_edy_device_open (device_t **out, const char* name)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (1200 8N1).
|
||||
@ -204,7 +204,7 @@ cressi_edy_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (1000 ms).
|
||||
@ -212,7 +212,7 @@ cressi_edy_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the DTR and clear the RTS line.
|
||||
@ -221,7 +221,7 @@ cressi_edy_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the DTR/RTS line.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Send the init commands.
|
||||
@ -235,22 +235,22 @@ cressi_edy_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
cressi_edy_device_close (device_t *abstract)
|
||||
{
|
||||
cressi_edy_device_t *device = (cressi_edy_device_t*) abstract;
|
||||
|
||||
if (! device_is_cressi_edy (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Send the quit command.
|
||||
cressi_edy_quit (device);
|
||||
@ -258,27 +258,27 @@ cressi_edy_device_close (device_t *abstract)
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
cressi_edy_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size)
|
||||
{
|
||||
cressi_edy_device_t *device = (cressi_edy_device_t*) abstract;
|
||||
|
||||
if (! device_is_cressi_edy (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if ((address % (CRESSI_EDY_PACKET_SIZE / 4) != 0) ||
|
||||
(size % CRESSI_EDY_PACKET_SIZE != 0))
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// The data transmission is split in packages
|
||||
// of maximum $CRESSI_EDY_PACKET_SIZE bytes.
|
||||
@ -291,8 +291,8 @@ cressi_edy_device_read (device_t *abstract, unsigned int address, unsigned char
|
||||
unsigned char command[3] = {0x52,
|
||||
(number >> 8) & 0xFF, // high
|
||||
(number ) & 0xFF}; // low
|
||||
device_status_t rc = cressi_edy_transfer (device, command, sizeof (command), answer, sizeof (answer), 1);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = cressi_edy_transfer (device, command, sizeof (command), answer, sizeof (answer), 1);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
memcpy (data, answer + 3, CRESSI_EDY_PACKET_SIZE);
|
||||
@ -302,38 +302,38 @@ cressi_edy_device_read (device_t *abstract, unsigned int address, unsigned char
|
||||
data += CRESSI_EDY_PACKET_SIZE;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
cressi_edy_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
cressi_edy_device_t *device = (cressi_edy_device_t *) abstract;
|
||||
|
||||
if (size && size != sizeof (device->fingerprint))
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size)
|
||||
memcpy (device->fingerprint, data, sizeof (device->fingerprint));
|
||||
else
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
cressi_edy_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
if (! device_is_cressi_edy (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Erase the current contents of the buffer and
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, CRESSI_EDY_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
return device_dump_read (abstract, dc_buffer_get_data (buffer),
|
||||
@ -341,7 +341,7 @@ cressi_edy_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
cressi_edy_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
cressi_edy_device_t *device = (cressi_edy_device_t *) abstract;
|
||||
@ -361,8 +361,8 @@ cressi_edy_device_foreach (device_t *abstract, dive_callback_t callback, void *u
|
||||
|
||||
// Read the configuration data.
|
||||
unsigned char config[CRESSI_EDY_PACKET_SIZE] = {0};
|
||||
device_status_t rc = cressi_edy_device_read (abstract, 0x7F80, config, sizeof (config));
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = cressi_edy_device_read (abstract, 0x7F80, config, sizeof (config));
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Failed to read the configuration data.");
|
||||
return rc;
|
||||
}
|
||||
@ -377,9 +377,9 @@ cressi_edy_device_foreach (device_t *abstract, dive_callback_t callback, void *u
|
||||
if (first < RB_LOGBOOK_BEGIN || first >= RB_LOGBOOK_END ||
|
||||
last < RB_LOGBOOK_BEGIN || last >= RB_LOGBOOK_END) {
|
||||
if (last == 0xFF)
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
WARNING ("Invalid ringbuffer pointer detected.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
// Get the number of logbook items.
|
||||
@ -389,7 +389,7 @@ cressi_edy_device_foreach (device_t *abstract, dive_callback_t callback, void *u
|
||||
unsigned int eop = array_uint16_le (config + 0x7E) * PAGESIZE + BASE;
|
||||
if (eop < RB_PROFILE_BEGIN || eop >= RB_PROFILE_END) {
|
||||
WARNING ("Invalid ringbuffer pointer detected.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
// Memory buffer for the profile data.
|
||||
@ -407,7 +407,7 @@ cressi_edy_device_foreach (device_t *abstract, dive_callback_t callback, void *u
|
||||
unsigned int current = array_uint16_le (config + 2 * idx) * PAGESIZE + BASE;
|
||||
if (current < RB_PROFILE_BEGIN || current >= RB_PROFILE_END) {
|
||||
WARNING ("Invalid ringbuffer pointer detected.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
// Position the pointer at the start of the header.
|
||||
@ -427,7 +427,7 @@ cressi_edy_device_foreach (device_t *abstract, dive_callback_t callback, void *u
|
||||
|
||||
// Read the memory page.
|
||||
rc = cressi_edy_device_read (abstract, address, buffer + offset, CRESSI_EDY_PACKET_SIZE);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Failed to read the memory page.");
|
||||
return rc;
|
||||
}
|
||||
@ -445,15 +445,15 @@ cressi_edy_device_foreach (device_t *abstract, dive_callback_t callback, void *u
|
||||
unsigned char *p = buffer + offset + available;
|
||||
|
||||
if (memcmp (p, device->fingerprint, sizeof (device->fingerprint)) == 0)
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
||||
if (callback && !callback (p, length, p, sizeof (device->fingerprint), userdata))
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
||||
if (idx == RB_LOGBOOK_BEGIN)
|
||||
idx = RB_LOGBOOK_END;
|
||||
idx--;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -34,11 +34,11 @@ struct cressi_edy_parser_t {
|
||||
unsigned int model;
|
||||
};
|
||||
|
||||
static parser_status_t cressi_edy_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static parser_status_t cressi_edy_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static parser_status_t cressi_edy_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static parser_status_t cressi_edy_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static parser_status_t cressi_edy_parser_destroy (parser_t *abstract);
|
||||
static dc_status_t cressi_edy_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static dc_status_t cressi_edy_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static dc_status_t cressi_edy_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static dc_status_t cressi_edy_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static dc_status_t cressi_edy_parser_destroy (parser_t *abstract);
|
||||
|
||||
static const parser_backend_t cressi_edy_parser_backend = {
|
||||
PARSER_TYPE_CRESSI_EDY,
|
||||
@ -60,17 +60,17 @@ parser_is_cressi_edy (parser_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
cressi_edy_parser_create (parser_t **out, unsigned int model)
|
||||
{
|
||||
if (out == NULL)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
cressi_edy_parser_t *parser = (cressi_edy_parser_t *) malloc (sizeof (cressi_edy_parser_t));
|
||||
if (parser == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return PARSER_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -81,38 +81,38 @@ cressi_edy_parser_create (parser_t **out, unsigned int model)
|
||||
|
||||
*out = (parser_t*) parser;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
cressi_edy_parser_destroy (parser_t *abstract)
|
||||
{
|
||||
if (! parser_is_cressi_edy (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Free memory.
|
||||
free (abstract);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
cressi_edy_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
if (! parser_is_cressi_edy (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
cressi_edy_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
{
|
||||
if (abstract->size < 32)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *p = abstract->data;
|
||||
|
||||
@ -125,17 +125,17 @@ cressi_edy_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
datetime->second = 0;
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
cressi_edy_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value)
|
||||
{
|
||||
cressi_edy_parser_t *parser = (cressi_edy_parser_t *) abstract;
|
||||
|
||||
if (abstract->size < 32)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *p = abstract->data;
|
||||
|
||||
@ -161,15 +161,15 @@ cressi_edy_parser_get_field (parser_t *abstract, parser_field_type_t type, unsig
|
||||
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
cressi_edy_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata)
|
||||
{
|
||||
cressi_edy_parser_t *parser = (cressi_edy_parser_t *) abstract;
|
||||
@ -208,5 +208,5 @@ cressi_edy_parser_samples_foreach (parser_t *abstract, sample_callback_t callbac
|
||||
offset += 2 + extra;
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -51,19 +51,19 @@ struct device_t {
|
||||
struct device_backend_t {
|
||||
device_type_t type;
|
||||
|
||||
device_status_t (*set_fingerprint) (device_t *device, const unsigned char data[], unsigned int size);
|
||||
dc_status_t (*set_fingerprint) (device_t *device, const unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t (*version) (device_t *device, unsigned char data[], unsigned int size);
|
||||
dc_status_t (*version) (device_t *device, unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t (*read) (device_t *device, unsigned int address, unsigned char data[], unsigned int size);
|
||||
dc_status_t (*read) (device_t *device, unsigned int address, unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t (*write) (device_t *device, unsigned int address, const unsigned char data[], unsigned int size);
|
||||
dc_status_t (*write) (device_t *device, unsigned int address, const unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t (*dump) (device_t *device, dc_buffer_t *buffer);
|
||||
dc_status_t (*dump) (device_t *device, dc_buffer_t *buffer);
|
||||
|
||||
device_status_t (*foreach) (device_t *device, dive_callback_t callback, void *userdata);
|
||||
dc_status_t (*foreach) (device_t *device, dive_callback_t callback, void *userdata);
|
||||
|
||||
device_status_t (*close) (device_t *device);
|
||||
dc_status_t (*close) (device_t *device);
|
||||
};
|
||||
|
||||
void
|
||||
@ -75,7 +75,7 @@ device_event_emit (device_t *device, device_event_t event, const void *data);
|
||||
int
|
||||
device_is_cancelled (device_t *device);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
device_dump_read (device_t *device, unsigned char data[], unsigned int size, unsigned int blocksize);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
66
src/device.c
66
src/device.c
@ -49,106 +49,106 @@ device_get_type (device_t *device)
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
device_set_cancel (device_t *device, device_cancel_callback_t callback, void *userdata)
|
||||
{
|
||||
if (device == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
device->cancel_callback = callback;
|
||||
device->cancel_userdata = userdata;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
device_set_events (device_t *device, unsigned int events, device_event_callback_t callback, void *userdata)
|
||||
{
|
||||
if (device == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
device->event_mask = events;
|
||||
device->event_callback = callback;
|
||||
device->event_userdata = userdata;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
device_set_fingerprint (device_t *device, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
if (device == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
if (device->backend->set_fingerprint == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
return device->backend->set_fingerprint (device, data, size);
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
device_version (device_t *device, unsigned char data[], unsigned int size)
|
||||
{
|
||||
if (device == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
if (device->backend->version == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
return device->backend->version (device, data, size);
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
device_read (device_t *device, unsigned int address, unsigned char data[], unsigned int size)
|
||||
{
|
||||
if (device == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
if (device->backend->read == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
return device->backend->read (device, address, data, size);
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
device_write (device_t *device, unsigned int address, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
if (device == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
if (device->backend->write == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
return device->backend->write (device, address, data, size);
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
device_dump (device_t *device, dc_buffer_t *buffer)
|
||||
{
|
||||
if (device == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
if (device->backend->dump == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
return device->backend->dump (device, buffer);
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
device_dump_read (device_t *device, unsigned char data[], unsigned int size, unsigned int blocksize)
|
||||
{
|
||||
if (device == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
if (device->backend->read == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
// Enable progress notifications.
|
||||
device_progress_t progress = DEVICE_PROGRESS_INITIALIZER;
|
||||
@ -163,8 +163,8 @@ device_dump_read (device_t *device, unsigned char data[], unsigned int size, uns
|
||||
len = blocksize;
|
||||
|
||||
// Read the packet.
|
||||
device_status_t rc = device->backend->read (device, nbytes, data + nbytes, len);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = device->backend->read (device, nbytes, data + nbytes, len);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Update and emit a progress event.
|
||||
@ -174,31 +174,31 @@ device_dump_read (device_t *device, unsigned char data[], unsigned int size, uns
|
||||
nbytes += len;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
device_foreach (device_t *device, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
if (device == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
if (device->backend->foreach == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
return device->backend->foreach (device, callback, userdata);
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
device_close (device_t *device)
|
||||
{
|
||||
if (device == NULL)
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
||||
if (device->backend->close == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
return device->backend->close (device);
|
||||
}
|
||||
|
||||
118
src/hw_frog.c
118
src/hw_frog.c
@ -33,7 +33,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
#define SZ_DISPLAY 15
|
||||
@ -63,10 +63,10 @@ typedef struct hw_frog_device_t {
|
||||
unsigned char fingerprint[5];
|
||||
} hw_frog_device_t;
|
||||
|
||||
static device_status_t hw_frog_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t hw_frog_device_version (device_t *abstract, unsigned char data[], unsigned int size);
|
||||
static device_status_t hw_frog_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t hw_frog_device_close (device_t *abstract);
|
||||
static dc_status_t hw_frog_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static dc_status_t hw_frog_device_version (device_t *abstract, unsigned char data[], unsigned int size);
|
||||
static dc_status_t hw_frog_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static dc_status_t hw_frog_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t hw_frog_device_backend = {
|
||||
DEVICE_TYPE_HW_FROG,
|
||||
@ -90,7 +90,7 @@ device_is_hw_frog (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
hw_frog_transfer (hw_frog_device_t *device,
|
||||
device_progress_t *progress,
|
||||
unsigned char cmd,
|
||||
@ -119,7 +119,7 @@ hw_frog_transfer (hw_frog_device_t *device,
|
||||
// Verify the echo.
|
||||
if (memcmp (answer, command, sizeof (command)) != 0) {
|
||||
WARNING ("Unexpected echo.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,25 +176,25 @@ hw_frog_transfer (hw_frog_device_t *device,
|
||||
// Verify the ready byte.
|
||||
if (answer[0] != READY) {
|
||||
WARNING ("Unexpected ready byte.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_frog_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
hw_frog_device_t *device = (hw_frog_device_t *) malloc (sizeof (hw_frog_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -209,7 +209,7 @@ hw_frog_device_open (device_t **out, const char* name)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (115200 8N1).
|
||||
@ -218,7 +218,7 @@ hw_frog_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (3000ms).
|
||||
@ -226,7 +226,7 @@ hw_frog_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Make sure everything is in a sane state.
|
||||
@ -234,8 +234,8 @@ hw_frog_device_open (device_t **out, const char* name)
|
||||
serial_flush (device->port, SERIAL_QUEUE_BOTH);
|
||||
|
||||
// Send the init command.
|
||||
device_status_t status = hw_frog_transfer (device, NULL, INIT, NULL, 0, NULL, 0);
|
||||
if (status != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t status = hw_frog_transfer (device, NULL, INIT, NULL, 0, NULL, 0);
|
||||
if (status != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Failed to send the init command.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
@ -244,18 +244,18 @@ hw_frog_device_open (device_t **out, const char* name)
|
||||
|
||||
*out = (device_t *) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
hw_frog_device_close (device_t *abstract)
|
||||
{
|
||||
hw_frog_device_t *device = (hw_frog_device_t*) abstract;
|
||||
|
||||
// Send the exit command.
|
||||
device_status_t status = hw_frog_transfer (device, NULL, EXIT, NULL, 0, NULL, 0);
|
||||
if (status != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t status = hw_frog_transfer (device, NULL, EXIT, NULL, 0, NULL, 0);
|
||||
if (status != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Failed to send the exit command.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
@ -265,54 +265,54 @@ hw_frog_device_close (device_t *abstract)
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
hw_frog_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
hw_frog_device_t *device = (hw_frog_device_t *) abstract;
|
||||
|
||||
if (size && size != sizeof (device->fingerprint))
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size)
|
||||
memcpy (device->fingerprint, data, sizeof (device->fingerprint));
|
||||
else
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
hw_frog_device_version (device_t *abstract, unsigned char data[], unsigned int size)
|
||||
{
|
||||
hw_frog_device_t *device = (hw_frog_device_t *) abstract;
|
||||
|
||||
if (!device_is_hw_frog (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size != SZ_VERSION)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Send the command.
|
||||
device_status_t rc = hw_frog_transfer (device, NULL, IDENTITY, NULL, 0, data, size);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = hw_frog_transfer (device, NULL, IDENTITY, NULL, 0, data, size);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
hw_frog_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
hw_frog_device_t *device = (hw_frog_device_t *) abstract;
|
||||
@ -325,8 +325,8 @@ hw_frog_device_foreach (device_t *abstract, dive_callback_t callback, void *user
|
||||
|
||||
// Download the version data.
|
||||
unsigned char id[SZ_VERSION] = {0};
|
||||
device_status_t rc = hw_frog_device_version (abstract, id, sizeof (id));
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = hw_frog_device_version (abstract, id, sizeof (id));
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Failed to read the version.");
|
||||
return rc;
|
||||
}
|
||||
@ -342,13 +342,13 @@ hw_frog_device_foreach (device_t *abstract, dive_callback_t callback, void *user
|
||||
unsigned char *header = malloc (RB_LOGBOOK_SIZE * RB_LOGBOOK_COUNT);
|
||||
if (header == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Download the logbook headers.
|
||||
rc = hw_frog_transfer (device, &progress, HEADER,
|
||||
NULL, 0, header, RB_LOGBOOK_SIZE * RB_LOGBOOK_COUNT);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Failed to read the header.");
|
||||
free (header);
|
||||
return rc;
|
||||
@ -396,7 +396,7 @@ hw_frog_device_foreach (device_t *abstract, dive_callback_t callback, void *user
|
||||
{
|
||||
WARNING("Invalid ringbuffer pointer detected!");
|
||||
free (header);
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
// Calculate the profile length.
|
||||
@ -421,7 +421,7 @@ hw_frog_device_foreach (device_t *abstract, dive_callback_t callback, void *user
|
||||
if (profile == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
free (header);
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Download the dives.
|
||||
@ -440,7 +440,7 @@ hw_frog_device_foreach (device_t *abstract, dive_callback_t callback, void *user
|
||||
unsigned char number[1] = {idx};
|
||||
rc = hw_frog_transfer (device, &progress, DIVE,
|
||||
number, sizeof (number), profile, length);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Failed to read the dive.");
|
||||
free (profile);
|
||||
free (header);
|
||||
@ -454,48 +454,48 @@ hw_frog_device_foreach (device_t *abstract, dive_callback_t callback, void *user
|
||||
free (profile);
|
||||
free (header);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_frog_device_clock (device_t *abstract, const dc_datetime_t *datetime)
|
||||
{
|
||||
hw_frog_device_t *device = (hw_frog_device_t *) abstract;
|
||||
|
||||
if (!device_is_hw_frog (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (datetime == NULL) {
|
||||
WARNING ("Invalid parameter specified.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
// Send the command.
|
||||
unsigned char packet[6] = {
|
||||
datetime->hour, datetime->minute, datetime->second,
|
||||
datetime->month, datetime->day, datetime->year - 2000};
|
||||
device_status_t rc = hw_frog_transfer (device, NULL, CLOCK, packet, sizeof (packet), NULL, 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = hw_frog_transfer (device, NULL, CLOCK, packet, sizeof (packet), NULL, 0);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_frog_device_display (device_t *abstract, const char *text)
|
||||
{
|
||||
hw_frog_device_t *device = (hw_frog_device_t *) abstract;
|
||||
|
||||
if (!device_is_hw_frog (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Check the maximum length.
|
||||
size_t length = (text ? strlen (text) : 0);
|
||||
if (length > SZ_DISPLAY) {
|
||||
WARNING ("Invalid parameter specified.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
// Pad the data packet with spaces.
|
||||
@ -505,27 +505,27 @@ hw_frog_device_display (device_t *abstract, const char *text)
|
||||
memset (packet + length, 0x20, sizeof (packet) - length);
|
||||
|
||||
// Send the command.
|
||||
device_status_t rc = hw_frog_transfer (device, NULL, DISPLAY, packet, sizeof (packet), NULL, 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = hw_frog_transfer (device, NULL, DISPLAY, packet, sizeof (packet), NULL, 0);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_frog_device_customtext (device_t *abstract, const char *text)
|
||||
{
|
||||
hw_frog_device_t *device = (hw_frog_device_t *) abstract;
|
||||
|
||||
if (!device_is_hw_frog (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Check the maximum length.
|
||||
size_t length = (text ? strlen (text) : 0);
|
||||
if (length > SZ_CUSTOMTEXT) {
|
||||
WARNING ("Invalid parameter specified.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
// Pad the data packet with spaces.
|
||||
@ -535,9 +535,9 @@ hw_frog_device_customtext (device_t *abstract, const char *text)
|
||||
memset (packet + length, 0x20, sizeof (packet) - length);
|
||||
|
||||
// Send the command.
|
||||
device_status_t rc = hw_frog_transfer (device, NULL, CUSTOMTEXT, packet, sizeof (packet), NULL, 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = hw_frog_transfer (device, NULL, CUSTOMTEXT, packet, sizeof (packet), NULL, 0);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
156
src/hw_ostc.c
156
src/hw_ostc.c
@ -32,7 +32,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
#define FW_190 0x015A
|
||||
@ -54,10 +54,10 @@ typedef struct hw_ostc_device_t {
|
||||
unsigned char fingerprint[5];
|
||||
} hw_ostc_device_t;
|
||||
|
||||
static device_status_t hw_ostc_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t hw_ostc_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t hw_ostc_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t hw_ostc_device_close (device_t *abstract);
|
||||
static dc_status_t hw_ostc_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static dc_status_t hw_ostc_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static dc_status_t hw_ostc_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static dc_status_t hw_ostc_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t hw_ostc_device_backend = {
|
||||
DEVICE_TYPE_HW_OSTC,
|
||||
@ -81,7 +81,7 @@ device_is_hw_ostc (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
hw_ostc_send (hw_ostc_device_t *device, unsigned char cmd, unsigned int echo)
|
||||
{
|
||||
// Send the command.
|
||||
@ -104,25 +104,25 @@ hw_ostc_send (hw_ostc_device_t *device, unsigned char cmd, unsigned int echo)
|
||||
// Verify the echo.
|
||||
if (memcmp (answer, command, sizeof (command)) != 0) {
|
||||
WARNING ("Unexpected echo.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_ostc_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
hw_ostc_device_t *device = (hw_ostc_device_t *) malloc (sizeof (hw_ostc_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -137,7 +137,7 @@ hw_ostc_device_open (device_t **out, const char* name)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (115200 8N1).
|
||||
@ -146,7 +146,7 @@ hw_ostc_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data.
|
||||
@ -154,7 +154,7 @@ hw_ostc_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Make sure everything is in a sane state.
|
||||
@ -163,60 +163,60 @@ hw_ostc_device_open (device_t **out, const char* name)
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
hw_ostc_device_close (device_t *abstract)
|
||||
{
|
||||
hw_ostc_device_t *device = (hw_ostc_device_t*) abstract;
|
||||
|
||||
if (! device_is_hw_ostc (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
hw_ostc_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
hw_ostc_device_t *device = (hw_ostc_device_t *) abstract;
|
||||
|
||||
if (size && size != sizeof (device->fingerprint))
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size)
|
||||
memcpy (device->fingerprint, data, sizeof (device->fingerprint));
|
||||
else
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
hw_ostc_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
hw_ostc_device_t *device = (hw_ostc_device_t*) abstract;
|
||||
|
||||
if (! device_is_hw_ostc (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Erase the current contents of the buffer.
|
||||
if (!dc_buffer_clear (buffer)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Enable progress notifications.
|
||||
@ -244,7 +244,7 @@ hw_ostc_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
unsigned char preamble[] = {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0x55};
|
||||
if (memcmp (header, preamble, sizeof (preamble)) != 0) {
|
||||
WARNING ("Unexpected answer header.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
// Get the firmware version.
|
||||
@ -265,7 +265,7 @@ hw_ostc_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
// Allocate the required amount of memory.
|
||||
if (!dc_buffer_resize (buffer, size)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
unsigned char *data = dc_buffer_get_data (buffer);
|
||||
@ -301,19 +301,19 @@ hw_ostc_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
nbytes += len;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
hw_ostc_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
dc_buffer_t *buffer = dc_buffer_new (0);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
|
||||
device_status_t rc = hw_ostc_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = hw_ostc_device_dump (abstract, buffer);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
@ -335,22 +335,22 @@ hw_ostc_device_foreach (device_t *abstract, dive_callback_t callback, void *user
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_ostc_device_md2hash (device_t *abstract, unsigned char data[], unsigned int size)
|
||||
{
|
||||
hw_ostc_device_t *device = (hw_ostc_device_t *) abstract;
|
||||
|
||||
if (! device_is_hw_ostc (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size < SZ_MD2HASH) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
// Send the command.
|
||||
device_status_t rc = hw_ostc_send (device, 'e', 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = hw_ostc_send (device, 'e', 0);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Read the answer.
|
||||
@ -360,26 +360,26 @@ hw_ostc_device_md2hash (device_t *abstract, unsigned char data[], unsigned int s
|
||||
return EXITCODE (n);
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_ostc_device_clock (device_t *abstract, const dc_datetime_t *datetime)
|
||||
{
|
||||
hw_ostc_device_t *device = (hw_ostc_device_t *) abstract;
|
||||
|
||||
if (! device_is_hw_ostc (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (datetime == NULL) {
|
||||
WARNING ("Invalid parameter specified.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
// Send the command.
|
||||
device_status_t rc = hw_ostc_send (device, 'b', 1);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = hw_ostc_send (device, 'b', 1);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Send the data packet.
|
||||
@ -392,32 +392,32 @@ hw_ostc_device_clock (device_t *abstract, const dc_datetime_t *datetime)
|
||||
return EXITCODE (n);
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_ostc_device_eeprom_read (device_t *abstract, unsigned int bank, unsigned char data[], unsigned int size)
|
||||
{
|
||||
hw_ostc_device_t *device = (hw_ostc_device_t *) abstract;
|
||||
|
||||
if (! device_is_hw_ostc (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (bank > 1) {
|
||||
WARNING ("Invalid eeprom bank specified.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
if (size < SZ_EEPROM) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
// Send the command.
|
||||
unsigned char command = (bank == 0) ? 'g' : 'j';
|
||||
device_status_t rc = hw_ostc_send (device, command, 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = hw_ostc_send (device, command, 0);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Read the answer.
|
||||
@ -427,74 +427,74 @@ hw_ostc_device_eeprom_read (device_t *abstract, unsigned int bank, unsigned char
|
||||
return EXITCODE (n);
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_ostc_device_eeprom_write (device_t *abstract, unsigned int bank, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
hw_ostc_device_t *device = (hw_ostc_device_t *) abstract;
|
||||
|
||||
if (! device_is_hw_ostc (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (bank > 1) {
|
||||
WARNING ("Invalid eeprom bank specified.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
if (size != SZ_EEPROM) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
// Send the command.
|
||||
unsigned char command = (bank == 0) ? 'd' : 'i';
|
||||
device_status_t rc = hw_ostc_send (device, command, 1);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = hw_ostc_send (device, command, 1);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
for (unsigned int i = 4; i < SZ_EEPROM; ++i) {
|
||||
// Send the data byte.
|
||||
rc = hw_ostc_send (device, data[i], 1);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_ostc_device_reset (device_t *abstract)
|
||||
{
|
||||
hw_ostc_device_t *device = (hw_ostc_device_t *) abstract;
|
||||
|
||||
if (! device_is_hw_ostc (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Send the command.
|
||||
device_status_t rc = hw_ostc_send (device, 'h', 1);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = hw_ostc_send (device, 'h', 1);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_ostc_device_screenshot (device_t *abstract, dc_buffer_t *buffer, hw_ostc_format_t format)
|
||||
{
|
||||
hw_ostc_device_t *device = (hw_ostc_device_t *) abstract;
|
||||
|
||||
if (! device_is_hw_ostc (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Erase the current contents of the buffer.
|
||||
if (!dc_buffer_clear (buffer)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Bytes per pixel (RGB formats only).
|
||||
@ -506,7 +506,7 @@ hw_ostc_device_screenshot (device_t *abstract, dc_buffer_t *buffer, hw_ostc_form
|
||||
// initial guess and expanded when necessary.
|
||||
if (!dc_buffer_reserve (buffer, 4096)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
} else {
|
||||
// The RGB formats have a fixed size, depending only on the dimensions
|
||||
@ -515,7 +515,7 @@ hw_ostc_device_screenshot (device_t *abstract, dc_buffer_t *buffer, hw_ostc_form
|
||||
bpp = (format == HW_OSTC_FORMAT_RGB16) ? 2 : 3;
|
||||
if (!dc_buffer_resize (buffer, WIDTH * HEIGHT * bpp)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
@ -525,8 +525,8 @@ hw_ostc_device_screenshot (device_t *abstract, dc_buffer_t *buffer, hw_ostc_form
|
||||
device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress);
|
||||
|
||||
// Send the command.
|
||||
device_status_t rc = hw_ostc_send (device, 'l', 1);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = hw_ostc_send (device, 'l', 1);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Cache the pointer to the image data (RGB formats only).
|
||||
@ -573,7 +573,7 @@ hw_ostc_device_screenshot (device_t *abstract, dc_buffer_t *buffer, hw_ostc_form
|
||||
// Check for buffer overflows.
|
||||
if (npixels + count > WIDTH * HEIGHT) {
|
||||
WARNING ("Unexpected number of pixels received.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
if (format == HW_OSTC_FORMAT_RAW) {
|
||||
@ -614,17 +614,17 @@ hw_ostc_device_screenshot (device_t *abstract, dc_buffer_t *buffer, hw_ostc_form
|
||||
npixels += count;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
hw_ostc_extract_dives (device_t *abstract, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
hw_ostc_device_t *device = (hw_ostc_device_t *) abstract;
|
||||
|
||||
if (abstract && !device_is_hw_ostc (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
const unsigned char header[2] = {0xFA, 0xFA};
|
||||
const unsigned char footer[2] = {0xFD, 0xFD};
|
||||
@ -648,15 +648,15 @@ hw_ostc_extract_dives (device_t *abstract, const unsigned char data[], unsigned
|
||||
previous += sizeof (footer);
|
||||
|
||||
if (device && memcmp (current + 3, device->fingerprint, sizeof (device->fingerprint)) == 0)
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
||||
if (callback && !callback (current, previous - current, current + 3, 5, userdata))
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Prepare for the next iteration.
|
||||
previous = current;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -41,11 +41,11 @@ typedef struct hw_ostc_sample_info_t {
|
||||
unsigned int size;
|
||||
} hw_ostc_sample_info_t;
|
||||
|
||||
static parser_status_t hw_ostc_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static parser_status_t hw_ostc_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static parser_status_t hw_ostc_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static parser_status_t hw_ostc_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static parser_status_t hw_ostc_parser_destroy (parser_t *abstract);
|
||||
static dc_status_t hw_ostc_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static dc_status_t hw_ostc_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static dc_status_t hw_ostc_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static dc_status_t hw_ostc_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static dc_status_t hw_ostc_parser_destroy (parser_t *abstract);
|
||||
|
||||
static const parser_backend_t hw_ostc_parser_backend = {
|
||||
PARSER_TYPE_HW_OSTC,
|
||||
@ -67,17 +67,17 @@ parser_is_hw_ostc (parser_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
hw_ostc_parser_create (parser_t **out, unsigned int frog)
|
||||
{
|
||||
if (out == NULL)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
hw_ostc_parser_t *parser = (hw_ostc_parser_t *) malloc (sizeof (hw_ostc_parser_t));
|
||||
if (parser == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return PARSER_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -87,34 +87,34 @@ hw_ostc_parser_create (parser_t **out, unsigned int frog)
|
||||
|
||||
*out = (parser_t*) parser;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
hw_ostc_parser_destroy (parser_t *abstract)
|
||||
{
|
||||
if (! parser_is_hw_ostc (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Free memory.
|
||||
free (abstract);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
hw_ostc_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
if (! parser_is_hw_ostc (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
hw_ostc_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
{
|
||||
hw_ostc_parser_t *parser = (hw_ostc_parser_t *) abstract;
|
||||
@ -122,7 +122,7 @@ hw_ostc_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
unsigned int size = abstract->size;
|
||||
|
||||
if (size < 9)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// Check the profile version
|
||||
unsigned int version = data[parser->frog ? 8 : 2];
|
||||
@ -138,11 +138,11 @@ hw_ostc_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
header = 256;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
if (size < header)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int divetime = 0;
|
||||
if (version == 0x21 || version == 0x22) {
|
||||
@ -167,17 +167,17 @@ hw_ostc_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
|
||||
dc_ticks_t ticks = dc_datetime_mktime (&dt);
|
||||
if (ticks == (dc_ticks_t) -1)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
ticks -= divetime;
|
||||
|
||||
if (!dc_datetime_localtime (datetime, ticks))
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
hw_ostc_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value)
|
||||
{
|
||||
hw_ostc_parser_t *parser = (hw_ostc_parser_t *) abstract;
|
||||
@ -185,7 +185,7 @@ hw_ostc_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned
|
||||
unsigned int size = abstract->size;
|
||||
|
||||
if (size < 9)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// Check the profile version
|
||||
unsigned int version = data[parser->frog ? 8 : 2];
|
||||
@ -201,11 +201,11 @@ hw_ostc_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned
|
||||
header = 256;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
if (size < header)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
if (parser->frog)
|
||||
data += 6;
|
||||
@ -235,15 +235,15 @@ hw_ostc_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned
|
||||
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
hw_ostc_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata)
|
||||
{
|
||||
hw_ostc_parser_t *parser = (hw_ostc_parser_t *) abstract;
|
||||
@ -251,7 +251,7 @@ hw_ostc_parser_samples_foreach (parser_t *abstract, sample_callback_t callback,
|
||||
unsigned int size = abstract->size;
|
||||
|
||||
if (size < 9)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// Check the profile version
|
||||
unsigned int version = data[parser->frog ? 8 : 2];
|
||||
@ -267,11 +267,11 @@ hw_ostc_parser_samples_foreach (parser_t *abstract, sample_callback_t callback,
|
||||
header = 256;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
if (size < header)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// Get the sample rate.
|
||||
unsigned int samplerate = data[36];
|
||||
@ -284,7 +284,7 @@ hw_ostc_parser_samples_foreach (parser_t *abstract, sample_callback_t callback,
|
||||
switch (i) {
|
||||
case 0: // Temperature
|
||||
if (info[i].size != 2)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
break;
|
||||
default: // Not yet used.
|
||||
break;
|
||||
@ -318,7 +318,7 @@ hw_ostc_parser_samples_foreach (parser_t *abstract, sample_callback_t callback,
|
||||
|
||||
// Check for buffer overflows.
|
||||
if (offset + length > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// Get the event byte.
|
||||
if (events) {
|
||||
@ -373,7 +373,7 @@ hw_ostc_parser_samples_foreach (parser_t *abstract, sample_callback_t callback,
|
||||
}
|
||||
|
||||
if (data[offset] != 0xFD || data[offset + 1] != 0xFD)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
#define MAXRETRIES 4
|
||||
@ -122,13 +122,13 @@ mares_common_make_ascii (const unsigned char raw[], unsigned int rsize, unsigned
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_common_packet (mares_common_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize)
|
||||
{
|
||||
device_t *abstract = (device_t *) device;
|
||||
|
||||
if (device_is_cancelled (abstract))
|
||||
return DEVICE_STATUS_CANCELLED;
|
||||
return DC_STATUS_CANCELLED;
|
||||
|
||||
if (device->delay) {
|
||||
serial_sleep (device->delay);
|
||||
@ -166,7 +166,7 @@ mares_common_packet (mares_common_device_t *device, const unsigned char command[
|
||||
// Verify the header and trailer of the packet.
|
||||
if (answer[0] != '<' || answer[asize - 1] != '>') {
|
||||
WARNING ("Unexpected answer header/trailer byte.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Verify the checksum of the packet.
|
||||
@ -175,22 +175,22 @@ mares_common_packet (mares_common_device_t *device, const unsigned char command[
|
||||
mares_common_convert_ascii_to_binary (answer + asize - 3, 2, &crc, 1);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_common_transfer (mares_common_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize)
|
||||
{
|
||||
unsigned int nretries = 0;
|
||||
device_status_t rc = DEVICE_STATUS_SUCCESS;
|
||||
while ((rc = mares_common_packet (device, command, csize, answer, asize)) != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = DC_STATUS_SUCCESS;
|
||||
while ((rc = mares_common_packet (device, command, csize, answer, asize)) != DC_STATUS_SUCCESS) {
|
||||
// Automatically discard a corrupted packet,
|
||||
// and request a new one.
|
||||
if (rc != DEVICE_STATUS_PROTOCOL && rc != DEVICE_STATUS_TIMEOUT)
|
||||
if (rc != DC_STATUS_PROTOCOL && rc != DC_STATUS_TIMEOUT)
|
||||
return rc;
|
||||
|
||||
// Abort if the maximum number of retries is reached.
|
||||
@ -205,7 +205,7 @@ mares_common_transfer (mares_common_device_t *device, const unsigned char comman
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_common_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size)
|
||||
{
|
||||
mares_common_device_t *device = (mares_common_device_t*) abstract;
|
||||
@ -232,8 +232,8 @@ mares_common_device_read (device_t *abstract, unsigned int address, unsigned cha
|
||||
|
||||
// Send the command and receive the answer.
|
||||
unsigned char answer[2 * (PACKETSIZE + 2)] = {0};
|
||||
device_status_t rc = mares_common_transfer (device, command, sizeof (command), answer, 2 * (len + 2));
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = mares_common_transfer (device, command, sizeof (command), answer, 2 * (len + 2));
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Extract the raw data from the packet.
|
||||
@ -244,11 +244,11 @@ mares_common_device_read (device_t *abstract, unsigned int address, unsigned cha
|
||||
data += len;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_common_extract_dives (const mares_common_layout_t *layout, const unsigned char fingerprint[], const unsigned char data[], dive_callback_t callback, void *userdata)
|
||||
{
|
||||
assert (layout != NULL);
|
||||
@ -263,7 +263,7 @@ mares_common_extract_dives (const mares_common_layout_t *layout, const unsigned
|
||||
unsigned int eop = array_uint16_le (data + 0x6B);
|
||||
if (eop < layout->rb_profile_begin || eop >= layout->rb_profile_end) {
|
||||
WARNING ("Ringbuffer pointer out of range.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
// Make the ringbuffer linear, to avoid having to deal
|
||||
@ -274,7 +274,7 @@ mares_common_extract_dives (const mares_common_layout_t *layout, const unsigned
|
||||
layout->rb_freedives_end - layout->rb_freedives_begin);
|
||||
if (buffer == NULL) {
|
||||
WARNING ("Out of memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
memcpy (buffer + 0, data + eop, layout->rb_profile_end - eop);
|
||||
@ -351,7 +351,7 @@ mares_common_extract_dives (const mares_common_layout_t *layout, const unsigned
|
||||
if (length != nbytes) {
|
||||
WARNING ("Calculated and stored size are not equal.");
|
||||
free (buffer);
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
// Process the profile data for the most recent freedive entry.
|
||||
@ -379,7 +379,7 @@ mares_common_extract_dives (const mares_common_layout_t *layout, const unsigned
|
||||
if (count != nsamples) {
|
||||
WARNING ("Unexpected number of freedive sessions.");
|
||||
free (buffer);
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
// Append the profile data to the main logbook entry. The
|
||||
@ -392,16 +392,16 @@ mares_common_extract_dives (const mares_common_layout_t *layout, const unsigned
|
||||
unsigned int fp_offset = offset + length - extra - FP_OFFSET;
|
||||
if (fingerprint && memcmp (buffer + fp_offset, fingerprint, FP_SIZE) == 0) {
|
||||
free (buffer);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (callback && !callback (buffer + offset, nbytes, buffer + fp_offset, FP_SIZE, userdata)) {
|
||||
free (buffer);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
free (buffer);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -49,10 +49,10 @@ typedef struct mares_common_device_t {
|
||||
void
|
||||
mares_common_device_init (mares_common_device_t *device, const device_backend_t *backend);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_common_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_common_extract_dives (const mares_common_layout_t *layout, const unsigned char fingerprint[], const unsigned char data[], dive_callback_t callback, void *userdata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -55,10 +55,10 @@ typedef struct mares_darwin_device_t {
|
||||
unsigned char fingerprint[6];
|
||||
} mares_darwin_device_t;
|
||||
|
||||
static device_status_t mares_darwin_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t mares_darwin_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t mares_darwin_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t mares_darwin_device_close (device_t *abstract);
|
||||
static dc_status_t mares_darwin_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static dc_status_t mares_darwin_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static dc_status_t mares_darwin_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static dc_status_t mares_darwin_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t mares_darwin_device_backend = {
|
||||
DEVICE_TYPE_MARES_DARWIN,
|
||||
@ -100,17 +100,17 @@ device_is_mares_darwin (device_t *abstract)
|
||||
return abstract->backend == &mares_darwin_device_backend;
|
||||
}
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_darwin_device_open (device_t **out, const char* name, unsigned int model)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
mares_darwin_device_t *device = (mares_darwin_device_t *) malloc (sizeof (mares_darwin_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -129,7 +129,7 @@ mares_darwin_device_open (device_t **out, const char* name, unsigned int model)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (9600 8N1).
|
||||
@ -138,7 +138,7 @@ mares_darwin_device_open (device_t **out, const char* name, unsigned int model)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->base.port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (1000 ms).
|
||||
@ -146,7 +146,7 @@ mares_darwin_device_open (device_t **out, const char* name, unsigned int model)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->base.port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the DTR/RTS lines.
|
||||
@ -155,7 +155,7 @@ mares_darwin_device_open (device_t **out, const char* name, unsigned int model)
|
||||
WARNING ("Failed to set the DTR/RTS line.");
|
||||
serial_close (device->base.port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Make sure everything is in a sane state.
|
||||
@ -168,10 +168,10 @@ mares_darwin_device_open (device_t **out, const char* name, unsigned int model)
|
||||
|
||||
*out = (device_t *) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_darwin_device_close (device_t *abstract)
|
||||
{
|
||||
mares_darwin_device_t *device = (mares_darwin_device_t *) abstract;
|
||||
@ -179,34 +179,34 @@ mares_darwin_device_close (device_t *abstract)
|
||||
// Close the device.
|
||||
if (serial_close (device->base.port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_darwin_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
mares_darwin_device_t *device = (mares_darwin_device_t *) abstract;
|
||||
|
||||
if (size && size != sizeof (device->fingerprint))
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size)
|
||||
memcpy (device->fingerprint, data, sizeof (device->fingerprint));
|
||||
else
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_darwin_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
mares_darwin_device_t *device = (mares_darwin_device_t *) abstract;
|
||||
@ -217,7 +217,7 @@ mares_darwin_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, device->layout->memsize)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
return device_dump_read (abstract, dc_buffer_get_data (buffer),
|
||||
@ -225,7 +225,7 @@ mares_darwin_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_darwin_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
mares_darwin_device_t *device = (mares_darwin_device_t *) abstract;
|
||||
@ -234,10 +234,10 @@ mares_darwin_device_foreach (device_t *abstract, dive_callback_t callback, void
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (device->layout->memsize);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
|
||||
device_status_t rc = mares_darwin_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = mares_darwin_device_dump (abstract, buffer);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
@ -259,13 +259,13 @@ mares_darwin_device_foreach (device_t *abstract, dive_callback_t callback, void
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_darwin_extract_dives (device_t *abstract, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
mares_darwin_device_t *device = (mares_darwin_device_t *) abstract;
|
||||
|
||||
if (!device_is_mares_darwin (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
assert (device->layout != NULL);
|
||||
|
||||
@ -275,21 +275,21 @@ mares_darwin_extract_dives (device_t *abstract, const unsigned char data[], unsi
|
||||
unsigned int eop = array_uint16_be (data + 0x8A);
|
||||
if (eop < layout->rb_profile_begin || eop >= layout->rb_profile_end) {
|
||||
WARNING ("Invalid ringbuffer pointer detected.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
// Get the logbook index.
|
||||
unsigned int last = data[0x8C];
|
||||
if (last >= layout->rb_logbook_count) {
|
||||
WARNING ("Invalid ringbuffer pointer detected.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
// Allocate memory for the largest possible dive.
|
||||
unsigned char *buffer = malloc (layout->rb_logbook_size + layout->rb_profile_end - layout->rb_profile_begin);
|
||||
if (buffer == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// The logbook ringbuffer can store a fixed amount of entries, but there
|
||||
@ -327,12 +327,12 @@ mares_darwin_extract_dives (device_t *abstract, const unsigned char data[], unsi
|
||||
|
||||
if (device && memcmp (buffer, device->fingerprint, sizeof (device->fingerprint)) == 0) {
|
||||
free (buffer);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (callback && !callback (buffer, layout->rb_logbook_size + length, buffer, 6, userdata)) {
|
||||
free (buffer);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
remaining -= length;
|
||||
@ -340,5 +340,5 @@ mares_darwin_extract_dives (device_t *abstract, const unsigned char data[], unsi
|
||||
|
||||
free (buffer);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -40,11 +40,11 @@ struct mares_darwin_parser_t {
|
||||
unsigned int samplesize;
|
||||
};
|
||||
|
||||
static parser_status_t mares_darwin_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static parser_status_t mares_darwin_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static parser_status_t mares_darwin_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static parser_status_t mares_darwin_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static parser_status_t mares_darwin_parser_destroy (parser_t *abstract);
|
||||
static dc_status_t mares_darwin_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static dc_status_t mares_darwin_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static dc_status_t mares_darwin_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static dc_status_t mares_darwin_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static dc_status_t mares_darwin_parser_destroy (parser_t *abstract);
|
||||
|
||||
static const parser_backend_t mares_darwin_parser_backend = {
|
||||
PARSER_TYPE_MARES_DARWIN,
|
||||
@ -66,17 +66,17 @@ parser_is_mares_darwin (parser_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
mares_darwin_parser_create (parser_t **out, unsigned int model)
|
||||
{
|
||||
if (out == NULL)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
mares_darwin_parser_t *parser = (mares_darwin_parser_t *) malloc (sizeof (mares_darwin_parser_t));
|
||||
if (parser == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return PARSER_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -92,37 +92,37 @@ mares_darwin_parser_create (parser_t **out, unsigned int model)
|
||||
|
||||
*out = (parser_t *) parser;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
mares_darwin_parser_destroy (parser_t *abstract)
|
||||
{
|
||||
if (! parser_is_mares_darwin (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Free memory.
|
||||
free (abstract);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
mares_darwin_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
mares_darwin_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
{
|
||||
mares_darwin_parser_t *parser = (mares_darwin_parser_t *) abstract;
|
||||
|
||||
if (abstract->size < parser->headersize)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *p = abstract->data;
|
||||
|
||||
@ -135,17 +135,17 @@ mares_darwin_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
datetime->second = 0;
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
mares_darwin_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value)
|
||||
{
|
||||
mares_darwin_parser_t *parser = (mares_darwin_parser_t *) abstract;
|
||||
|
||||
if (abstract->size < parser->headersize)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *p = abstract->data;
|
||||
|
||||
@ -168,21 +168,21 @@ mares_darwin_parser_get_field (parser_t *abstract, parser_field_type_t type, uns
|
||||
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
mares_darwin_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata)
|
||||
{
|
||||
mares_darwin_parser_t *parser = (mares_darwin_parser_t *) abstract;
|
||||
|
||||
if (abstract->size < parser->headersize)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int time = 0;
|
||||
|
||||
@ -248,5 +248,5 @@ mares_darwin_parser_samples_foreach (parser_t *abstract, sample_callback_t callb
|
||||
offset += parser->samplesize;
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
#if defined(_WIN32) || defined(__APPLE__)
|
||||
@ -56,11 +56,11 @@ typedef struct mares_iconhd_device_t {
|
||||
unsigned char version[140];
|
||||
} mares_iconhd_device_t;
|
||||
|
||||
static device_status_t mares_iconhd_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t mares_iconhd_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
static device_status_t mares_iconhd_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t mares_iconhd_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t mares_iconhd_device_close (device_t *abstract);
|
||||
static dc_status_t mares_iconhd_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static dc_status_t mares_iconhd_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
static dc_status_t mares_iconhd_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static dc_status_t mares_iconhd_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static dc_status_t mares_iconhd_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t mares_iconhd_device_backend = {
|
||||
DEVICE_TYPE_MARES_ICONHD,
|
||||
@ -83,7 +83,7 @@ device_is_mares_iconhd (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static unsigned int
|
||||
mares_iconhd_get_model (mares_iconhd_device_t *device, unsigned int model)
|
||||
{
|
||||
// Try to correct an invalid model code using the version packet.
|
||||
@ -97,7 +97,7 @@ mares_iconhd_get_model (mares_iconhd_device_t *device, unsigned int model)
|
||||
return model;
|
||||
}
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_iconhd_transfer (mares_iconhd_device_t *device,
|
||||
const unsigned char command[], unsigned int csize,
|
||||
unsigned char answer[], unsigned int asize,
|
||||
@ -130,7 +130,7 @@ mares_iconhd_transfer (mares_iconhd_device_t *device,
|
||||
// Verify the header byte.
|
||||
if (header[0] != ACK) {
|
||||
WARNING ("Unexpected answer byte.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
unsigned int nbytes = 0;
|
||||
@ -174,14 +174,14 @@ mares_iconhd_transfer (mares_iconhd_device_t *device,
|
||||
// Verify the trailer byte.
|
||||
if (trailer[0] != EOF) {
|
||||
WARNING ("Unexpected answer byte.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_iconhd_version (mares_iconhd_device_t *device, unsigned char data[], unsigned int size)
|
||||
{
|
||||
unsigned char command[] = {0xC2, 0x67};
|
||||
@ -189,7 +189,7 @@ mares_iconhd_version (mares_iconhd_device_t *device, unsigned char data[], unsig
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_iconhd_read (mares_iconhd_device_t *device, unsigned int address, unsigned char data[], unsigned int size, int events)
|
||||
{
|
||||
unsigned char command[] = {0xE7, 0x42,
|
||||
@ -205,17 +205,17 @@ mares_iconhd_read (mares_iconhd_device_t *device, unsigned int address, unsigned
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_iconhd_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
mares_iconhd_device_t *device = (mares_iconhd_device_t *) malloc (sizeof (mares_iconhd_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -231,7 +231,7 @@ mares_iconhd_device_open (device_t **out, const char* name)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (256000 8N1).
|
||||
@ -240,7 +240,7 @@ mares_iconhd_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (1000 ms).
|
||||
@ -248,7 +248,7 @@ mares_iconhd_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the DTR/RTS lines.
|
||||
@ -258,15 +258,15 @@ mares_iconhd_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the DTR/RTS line.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Make sure everything is in a sane state.
|
||||
serial_flush (device->port, SERIAL_QUEUE_BOTH);
|
||||
|
||||
// Send the version command.
|
||||
device_status_t status = mares_iconhd_version (device, device->version, sizeof (device->version));
|
||||
if (status != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t status = mares_iconhd_version (device, device->version, sizeof (device->version));
|
||||
if (status != DC_STATUS_SUCCESS) {
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return status;
|
||||
@ -274,49 +274,49 @@ mares_iconhd_device_open (device_t **out, const char* name)
|
||||
|
||||
*out = (device_t *) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_iconhd_device_close (device_t *abstract)
|
||||
{
|
||||
mares_iconhd_device_t *device = (mares_iconhd_device_t*) abstract;
|
||||
|
||||
if (! device_is_mares_iconhd (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_iconhd_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
mares_iconhd_device_t *device = (mares_iconhd_device_t *) abstract;
|
||||
|
||||
if (size && size != sizeof (device->fingerprint))
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size)
|
||||
memcpy (device->fingerprint, data, sizeof (device->fingerprint));
|
||||
else
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_iconhd_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size)
|
||||
{
|
||||
mares_iconhd_device_t *device = (mares_iconhd_device_t *) abstract;
|
||||
@ -325,7 +325,7 @@ mares_iconhd_device_read (device_t *abstract, unsigned int address, unsigned cha
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_iconhd_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
mares_iconhd_device_t *device = (mares_iconhd_device_t *) abstract;
|
||||
@ -334,7 +334,7 @@ mares_iconhd_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
// pre-allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, MARES_ICONHD_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
return mares_iconhd_read (device, 0, dc_buffer_get_data (buffer),
|
||||
@ -342,17 +342,17 @@ mares_iconhd_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_iconhd_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
mares_iconhd_device_t *device = (mares_iconhd_device_t *) abstract;
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (MARES_ICONHD_MEMORY_SIZE);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
|
||||
device_status_t rc = mares_iconhd_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = mares_iconhd_device_dump (abstract, buffer);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
@ -374,16 +374,16 @@ mares_iconhd_device_foreach (device_t *abstract, dive_callback_t callback, void
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_iconhd_extract_dives (device_t *abstract, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
mares_iconhd_device_t *device = (mares_iconhd_device_t *) abstract;
|
||||
|
||||
if (abstract && !device_is_mares_iconhd (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size < MARES_ICONHD_MEMORY_SIZE)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// Get the model code.
|
||||
unsigned int model = mares_iconhd_get_model (device, data[0]);
|
||||
@ -403,14 +403,14 @@ mares_iconhd_extract_dives (device_t *abstract, const unsigned char data[], unsi
|
||||
}
|
||||
if (eop < RB_PROFILE_BEGIN || eop >= RB_PROFILE_END) {
|
||||
WARNING ("Ringbuffer pointer out of range.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
// Make the ringbuffer linear, to avoid having to deal with the wrap point.
|
||||
unsigned char *buffer = (unsigned char *) malloc (RB_PROFILE_END - RB_PROFILE_BEGIN);
|
||||
if (buffer == NULL) {
|
||||
WARNING ("Out of memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
memcpy (buffer + 0, data + eop, RB_PROFILE_END - eop);
|
||||
@ -447,22 +447,22 @@ mares_iconhd_extract_dives (device_t *abstract, const unsigned char data[], unsi
|
||||
if (length != nbytes) {
|
||||
WARNING ("Calculated and stored size are not equal.");
|
||||
free (buffer);
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
unsigned char *fp = buffer + offset + length - header + 6;
|
||||
if (device && memcmp (fp, device->fingerprint, sizeof (device->fingerprint)) == 0) {
|
||||
free (buffer);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (callback && !callback (buffer + offset, length, fp, sizeof (device->fingerprint), userdata)) {
|
||||
free (buffer);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
free (buffer);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -37,11 +37,11 @@ struct mares_iconhd_parser_t {
|
||||
unsigned int model;
|
||||
};
|
||||
|
||||
static parser_status_t mares_iconhd_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static parser_status_t mares_iconhd_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static parser_status_t mares_iconhd_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static parser_status_t mares_iconhd_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static parser_status_t mares_iconhd_parser_destroy (parser_t *abstract);
|
||||
static dc_status_t mares_iconhd_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static dc_status_t mares_iconhd_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static dc_status_t mares_iconhd_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static dc_status_t mares_iconhd_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static dc_status_t mares_iconhd_parser_destroy (parser_t *abstract);
|
||||
|
||||
static const parser_backend_t mares_iconhd_parser_backend = {
|
||||
PARSER_TYPE_MARES_ICONHD,
|
||||
@ -63,17 +63,17 @@ parser_is_mares_iconhd (parser_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
mares_iconhd_parser_create (parser_t **out, unsigned int model)
|
||||
{
|
||||
if (out == NULL)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
mares_iconhd_parser_t *parser = (mares_iconhd_parser_t *) malloc (sizeof (mares_iconhd_parser_t));
|
||||
if (parser == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return PARSER_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -84,31 +84,31 @@ mares_iconhd_parser_create (parser_t **out, unsigned int model)
|
||||
|
||||
*out = (parser_t*) parser;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
mares_iconhd_parser_destroy (parser_t *abstract)
|
||||
{
|
||||
if (! parser_is_mares_iconhd (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Free memory.
|
||||
free (abstract);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
mares_iconhd_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
mares_iconhd_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
{
|
||||
mares_iconhd_parser_t *parser = (mares_iconhd_parser_t *) abstract;
|
||||
@ -119,12 +119,12 @@ mares_iconhd_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
}
|
||||
|
||||
if (abstract->size < 4)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int length = array_uint32_le (abstract->data);
|
||||
|
||||
if (abstract->size < length || length < header + 4)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *p = abstract->data + length - header + 6;
|
||||
|
||||
@ -137,11 +137,11 @@ mares_iconhd_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
datetime->year = array_uint16_le (p + 8) + 1900;
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
mares_iconhd_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value)
|
||||
{
|
||||
mares_iconhd_parser_t *parser = (mares_iconhd_parser_t *) abstract;
|
||||
@ -152,12 +152,12 @@ mares_iconhd_parser_get_field (parser_t *abstract, parser_field_type_t type, uns
|
||||
}
|
||||
|
||||
if (abstract->size < 4)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int length = array_uint32_le (abstract->data);
|
||||
|
||||
if (abstract->size < length || length < header + 4)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *p = abstract->data + length - header;
|
||||
|
||||
@ -180,15 +180,15 @@ mares_iconhd_parser_get_field (parser_t *abstract, parser_field_type_t type, uns
|
||||
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
mares_iconhd_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata)
|
||||
{
|
||||
mares_iconhd_parser_t *parser = (mares_iconhd_parser_t *) abstract;
|
||||
@ -201,12 +201,12 @@ mares_iconhd_parser_samples_foreach (parser_t *abstract, sample_callback_t callb
|
||||
}
|
||||
|
||||
if (abstract->size < 4)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int length = array_uint32_le (abstract->data);
|
||||
|
||||
if (abstract->size < length || length < header + 4)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *data = abstract->data;
|
||||
unsigned int size = length - header;
|
||||
@ -240,7 +240,7 @@ mares_iconhd_parser_samples_foreach (parser_t *abstract, sample_callback_t callb
|
||||
// Some extra data.
|
||||
if (parser->model == ICONHDNET && (nsamples % 4) == 0) {
|
||||
if (offset + 8 > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// Pressure (1/100 bar).
|
||||
unsigned int pressure = array_uint16_le(data + offset);
|
||||
@ -252,5 +252,5 @@ mares_iconhd_parser_samples_foreach (parser_t *abstract, sample_callback_t callb
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
#ifdef PACKETSIZE
|
||||
@ -53,10 +53,10 @@ typedef struct mares_nemo_device_t {
|
||||
unsigned char fingerprint[5];
|
||||
} mares_nemo_device_t;
|
||||
|
||||
static device_status_t mares_nemo_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t mares_nemo_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t mares_nemo_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t mares_nemo_device_close (device_t *abstract);
|
||||
static dc_status_t mares_nemo_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static dc_status_t mares_nemo_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static dc_status_t mares_nemo_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static dc_status_t mares_nemo_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t mares_nemo_device_backend = {
|
||||
DEVICE_TYPE_MARES_NEMO,
|
||||
@ -95,17 +95,17 @@ device_is_mares_nemo (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_nemo_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
mares_nemo_device_t *device = (mares_nemo_device_t *) malloc (sizeof (mares_nemo_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -120,7 +120,7 @@ mares_nemo_device_open (device_t **out, const char* name)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (9600 8N1).
|
||||
@ -129,7 +129,7 @@ mares_nemo_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (1000 ms).
|
||||
@ -137,7 +137,7 @@ mares_nemo_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the DTR/RTS lines.
|
||||
@ -146,7 +146,7 @@ mares_nemo_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the DTR/RTS line.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Make sure everything is in a sane state.
|
||||
@ -154,49 +154,49 @@ mares_nemo_device_open (device_t **out, const char* name)
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_nemo_device_close (device_t *abstract)
|
||||
{
|
||||
mares_nemo_device_t *device = (mares_nemo_device_t*) abstract;
|
||||
|
||||
if (! device_is_mares_nemo (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_nemo_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
mares_nemo_device_t *device = (mares_nemo_device_t *) abstract;
|
||||
|
||||
if (size && size != sizeof (device->fingerprint))
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size)
|
||||
memcpy (device->fingerprint, data, sizeof (device->fingerprint));
|
||||
else
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_nemo_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
mares_nemo_device_t *device = (mares_nemo_device_t *) abstract;
|
||||
@ -205,7 +205,7 @@ mares_nemo_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
// pre-allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, MEMORYSIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Enable progress notifications.
|
||||
@ -216,7 +216,7 @@ mares_nemo_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
// Wait until some data arrives.
|
||||
while (serial_get_received (device->port) == 0) {
|
||||
if (device_is_cancelled (abstract))
|
||||
return DEVICE_STATUS_CANCELLED;
|
||||
return DC_STATUS_CANCELLED;
|
||||
|
||||
device_event_emit (abstract, DEVICE_EVENT_WAITING, NULL);
|
||||
serial_sleep (100);
|
||||
@ -260,7 +260,7 @@ mares_nemo_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
// Both packets have a correct checksum.
|
||||
if (memcmp (packet, packet + PACKETSIZE + 1, PACKETSIZE) != 0) {
|
||||
WARNING ("Both packets are not equal.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
dc_buffer_append (buffer, packet, PACKETSIZE);
|
||||
} else if (crc1 == ccrc1) {
|
||||
@ -273,7 +273,7 @@ mares_nemo_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
dc_buffer_append (buffer, packet + PACKETSIZE + 1, PACKETSIZE);
|
||||
} else {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Update and emit a progress event.
|
||||
@ -283,19 +283,19 @@ mares_nemo_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
nbytes += PACKETSIZE;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_nemo_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
dc_buffer_t *buffer = dc_buffer_new (MEMORYSIZE);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
|
||||
device_status_t rc = mares_nemo_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = mares_nemo_device_dump (abstract, buffer);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
@ -316,16 +316,16 @@ mares_nemo_device_foreach (device_t *abstract, dive_callback_t callback, void *u
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_nemo_extract_dives (device_t *abstract, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
mares_nemo_device_t *device = (mares_nemo_device_t*) abstract;
|
||||
|
||||
if (abstract && !device_is_mares_nemo (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size < PACKETSIZE)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned char *fingerprint = (device ? device->fingerprint : NULL);
|
||||
|
||||
@ -344,7 +344,7 @@ mares_nemo_extract_dives (device_t *abstract, const unsigned char data[], unsign
|
||||
}
|
||||
|
||||
if (size < layout->memsize)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
return mares_common_extract_dives (layout, fingerprint, data, callback, userdata);
|
||||
}
|
||||
|
||||
@ -52,11 +52,11 @@ struct mares_nemo_parser_t {
|
||||
unsigned int extra;
|
||||
};
|
||||
|
||||
static parser_status_t mares_nemo_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static parser_status_t mares_nemo_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static parser_status_t mares_nemo_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static parser_status_t mares_nemo_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static parser_status_t mares_nemo_parser_destroy (parser_t *abstract);
|
||||
static dc_status_t mares_nemo_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static dc_status_t mares_nemo_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static dc_status_t mares_nemo_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static dc_status_t mares_nemo_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static dc_status_t mares_nemo_parser_destroy (parser_t *abstract);
|
||||
|
||||
static const parser_backend_t mares_nemo_parser_backend = {
|
||||
PARSER_TYPE_MARES_NEMO,
|
||||
@ -78,17 +78,17 @@ parser_is_mares_nemo (parser_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
mares_nemo_parser_create (parser_t **out, unsigned int model)
|
||||
{
|
||||
if (out == NULL)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
mares_nemo_parser_t *parser = (mares_nemo_parser_t *) malloc (sizeof (mares_nemo_parser_t));
|
||||
if (parser == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return PARSER_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -111,24 +111,24 @@ mares_nemo_parser_create (parser_t **out, unsigned int model)
|
||||
|
||||
*out = (parser_t*) parser;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
mares_nemo_parser_destroy (parser_t *abstract)
|
||||
{
|
||||
if (! parser_is_mares_nemo (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Free memory.
|
||||
free (abstract);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
mares_nemo_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
mares_nemo_parser_t *parser = (mares_nemo_parser_t *) abstract;
|
||||
@ -144,14 +144,14 @@ mares_nemo_parser_set_data (parser_t *abstract, const unsigned char *data, unsig
|
||||
parser->extra = 0;
|
||||
|
||||
if (size == 0)
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
||||
if (size < 2 + 3)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int length = array_uint16_le (data);
|
||||
if (length > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int extra = 0;
|
||||
const unsigned char marker[3] = {0xAA, 0xBB, 0xCC};
|
||||
@ -163,7 +163,7 @@ mares_nemo_parser_set_data (parser_t *abstract, const unsigned char *data, unsig
|
||||
}
|
||||
|
||||
if (length < 2 + extra + 3)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int mode = data[length - extra - 1];
|
||||
|
||||
@ -184,7 +184,7 @@ mares_nemo_parser_set_data (parser_t *abstract, const unsigned char *data, unsig
|
||||
|
||||
unsigned int nbytes = 2 + nsamples * sample_size + header_size + extra;
|
||||
if (length != nbytes)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// Store the new state.
|
||||
parser->base.data = data;
|
||||
@ -196,17 +196,17 @@ mares_nemo_parser_set_data (parser_t *abstract, const unsigned char *data, unsig
|
||||
parser->header = header_size;
|
||||
parser->extra = extra;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
mares_nemo_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
{
|
||||
mares_nemo_parser_t *parser = (mares_nemo_parser_t *) abstract;
|
||||
|
||||
if (abstract->size == 0)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *p = abstract->data + parser->length - parser->extra - 8;
|
||||
|
||||
@ -219,17 +219,17 @@ mares_nemo_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
datetime->second = 0;
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
mares_nemo_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value)
|
||||
{
|
||||
mares_nemo_parser_t *parser = (mares_nemo_parser_t *) abstract;
|
||||
|
||||
if (abstract->size == 0)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *data = abstract->data;
|
||||
const unsigned char *p = abstract->data + 2 + parser->sample_count * parser->sample_size;
|
||||
@ -259,13 +259,13 @@ mares_nemo_parser_get_field (parser_t *abstract, parser_field_type_t type, unsig
|
||||
gasmix->oxygen = p[53 - 43] / 100.0;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
gasmix->helium = 0.0;
|
||||
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
} else {
|
||||
unsigned int divetime = 0;
|
||||
@ -284,22 +284,22 @@ mares_nemo_parser_get_field (parser_t *abstract, parser_field_type_t type, unsig
|
||||
*((unsigned int *) value) = 0;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
mares_nemo_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata)
|
||||
{
|
||||
mares_nemo_parser_t *parser = (mares_nemo_parser_t *) abstract;
|
||||
|
||||
if (abstract->size == 0)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *data = abstract->data;
|
||||
unsigned int size = abstract->size;
|
||||
@ -434,7 +434,7 @@ mares_nemo_parser_samples_foreach (parser_t *abstract, sample_callback_t callbac
|
||||
// the profile data is probably incorrect.
|
||||
if (count != n) {
|
||||
WARNING ("Unexpected number of samples.");
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
} else {
|
||||
// Dive Time (seconds).
|
||||
@ -449,5 +449,5 @@ mares_nemo_parser_samples_foreach (parser_t *abstract, sample_callback_t callbac
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -43,10 +43,10 @@ typedef struct mares_puck_device_t {
|
||||
unsigned char fingerprint[5];
|
||||
} mares_puck_device_t;
|
||||
|
||||
static device_status_t mares_puck_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t mares_puck_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t mares_puck_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t mares_puck_device_close (device_t *abstract);
|
||||
static dc_status_t mares_puck_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static dc_status_t mares_puck_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static dc_status_t mares_puck_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static dc_status_t mares_puck_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t mares_puck_device_backend = {
|
||||
DEVICE_TYPE_MARES_PUCK,
|
||||
@ -93,17 +93,17 @@ device_is_mares_puck (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_puck_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
mares_puck_device_t *device = (mares_puck_device_t *) malloc (sizeof (mares_puck_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -118,7 +118,7 @@ mares_puck_device_open (device_t **out, const char* name)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (38400 8N1).
|
||||
@ -127,7 +127,7 @@ mares_puck_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->base.port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (1000 ms).
|
||||
@ -135,7 +135,7 @@ mares_puck_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->base.port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Clear the DTR/RTS lines.
|
||||
@ -144,7 +144,7 @@ mares_puck_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the DTR/RTS line.");
|
||||
serial_close (device->base.port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Make sure everything is in a sane state.
|
||||
@ -152,8 +152,8 @@ mares_puck_device_open (device_t **out, const char* name)
|
||||
|
||||
// Identify the model number.
|
||||
unsigned char header[PACKETSIZE] = {0};
|
||||
device_status_t status = mares_common_device_read ((device_t *) device, 0, header, sizeof (header));
|
||||
if (status != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t status = mares_common_device_read ((device_t *) device, 0, header, sizeof (header));
|
||||
if (status != DC_STATUS_SUCCESS) {
|
||||
serial_close (device->base.port);
|
||||
free (device);
|
||||
return status;
|
||||
@ -178,11 +178,11 @@ mares_puck_device_open (device_t **out, const char* name)
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_puck_device_close (device_t *abstract)
|
||||
{
|
||||
mares_puck_device_t *device = (mares_puck_device_t*) abstract;
|
||||
@ -190,34 +190,34 @@ mares_puck_device_close (device_t *abstract)
|
||||
// Close the device.
|
||||
if (serial_close (device->base.port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_puck_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
mares_puck_device_t *device = (mares_puck_device_t *) abstract;
|
||||
|
||||
if (size && size != sizeof (device->fingerprint))
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size)
|
||||
memcpy (device->fingerprint, data, sizeof (device->fingerprint));
|
||||
else
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_puck_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
mares_puck_device_t *device = (mares_puck_device_t *) abstract;
|
||||
@ -228,7 +228,7 @@ mares_puck_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, device->layout->memsize)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
return device_dump_read (abstract, dc_buffer_get_data (buffer),
|
||||
@ -236,7 +236,7 @@ mares_puck_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
mares_puck_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
mares_puck_device_t *device = (mares_puck_device_t *) abstract;
|
||||
@ -245,10 +245,10 @@ mares_puck_device_foreach (device_t *abstract, dive_callback_t callback, void *u
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (device->layout->memsize);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
|
||||
device_status_t rc = mares_puck_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = mares_puck_device_dump (abstract, buffer);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
@ -269,16 +269,16 @@ mares_puck_device_foreach (device_t *abstract, dive_callback_t callback, void *u
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
mares_puck_extract_dives (device_t *abstract, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
mares_puck_device_t *device = (mares_puck_device_t*) abstract;
|
||||
|
||||
if (abstract && !device_is_mares_puck (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size < PACKETSIZE)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned char *fingerprint = (device ? device->fingerprint : NULL);
|
||||
|
||||
@ -300,7 +300,7 @@ mares_puck_extract_dives (device_t *abstract, const unsigned char data[], unsign
|
||||
}
|
||||
|
||||
if (size < layout->memsize)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
return mares_common_extract_dives (layout, fingerprint, data, callback, userdata);
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
#define ACK 0x5A
|
||||
@ -48,10 +48,10 @@ typedef struct oceanic_atom2_device_t {
|
||||
unsigned char version[PAGESIZE];
|
||||
} oceanic_atom2_device_t;
|
||||
|
||||
static device_status_t oceanic_atom2_device_version (device_t *abstract, unsigned char data[], unsigned int size);
|
||||
static device_status_t oceanic_atom2_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
static device_status_t oceanic_atom2_device_write (device_t *abstract, unsigned int address, const unsigned char data[], unsigned int size);
|
||||
static device_status_t oceanic_atom2_device_close (device_t *abstract);
|
||||
static dc_status_t oceanic_atom2_device_version (device_t *abstract, unsigned char data[], unsigned int size);
|
||||
static dc_status_t oceanic_atom2_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
static dc_status_t oceanic_atom2_device_write (device_t *abstract, unsigned int address, const unsigned char data[], unsigned int size);
|
||||
static dc_status_t oceanic_atom2_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t oceanic_atom2_device_backend = {
|
||||
DEVICE_TYPE_OCEANIC_ATOM2,
|
||||
@ -215,13 +215,13 @@ device_is_oceanic_atom2 (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_atom2_send (oceanic_atom2_device_t *device, const unsigned char command[], unsigned int csize, unsigned char ack)
|
||||
{
|
||||
device_t *abstract = (device_t *) device;
|
||||
|
||||
if (device_is_cancelled (abstract))
|
||||
return DEVICE_STATUS_CANCELLED;
|
||||
return DC_STATUS_CANCELLED;
|
||||
|
||||
// Send the command to the dive computer.
|
||||
int n = serial_write (device->port, command, csize);
|
||||
@ -241,14 +241,14 @@ oceanic_atom2_send (oceanic_atom2_device_t *device, const unsigned char command[
|
||||
// Verify the response of the dive computer.
|
||||
if (response != ack) {
|
||||
WARNING ("Unexpected answer start byte(s).");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_atom2_transfer (oceanic_atom2_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize)
|
||||
{
|
||||
// Send the command to the device. If the device responds with an
|
||||
@ -258,9 +258,9 @@ oceanic_atom2_transfer (oceanic_atom2_device_t *device, const unsigned char comm
|
||||
// returning an error.
|
||||
|
||||
unsigned int nretries = 0;
|
||||
device_status_t rc = DEVICE_STATUS_SUCCESS;
|
||||
while ((rc = oceanic_atom2_send (device, command, csize, ACK)) != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DEVICE_STATUS_TIMEOUT && rc != DEVICE_STATUS_PROTOCOL)
|
||||
dc_status_t rc = DC_STATUS_SUCCESS;
|
||||
while ((rc = oceanic_atom2_send (device, command, csize, ACK)) != DC_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_TIMEOUT && rc != DC_STATUS_PROTOCOL)
|
||||
return rc;
|
||||
|
||||
// Abort if the maximum number of retries is reached.
|
||||
@ -285,38 +285,38 @@ oceanic_atom2_transfer (oceanic_atom2_device_t *device, const unsigned char comm
|
||||
unsigned char ccrc = checksum_add_uint8 (answer, asize - 1, 0x00);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_atom2_quit (oceanic_atom2_device_t *device)
|
||||
{
|
||||
// Send the command to the dive computer.
|
||||
unsigned char command[4] = {0x6A, 0x05, 0xA5, 0x00};
|
||||
device_status_t rc = oceanic_atom2_send (device, command, sizeof (command), NAK);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = oceanic_atom2_send (device, command, sizeof (command), NAK);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_atom2_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
oceanic_atom2_device_t *device = (oceanic_atom2_device_t *) malloc (sizeof (oceanic_atom2_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -331,7 +331,7 @@ oceanic_atom2_device_open (device_t **out, const char* name)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (38400 8N1).
|
||||
@ -340,7 +340,7 @@ oceanic_atom2_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (3000 ms).
|
||||
@ -348,7 +348,7 @@ oceanic_atom2_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Give the interface 100 ms to settle and draw power up.
|
||||
@ -360,8 +360,8 @@ oceanic_atom2_device_open (device_t **out, const char* name)
|
||||
// Switch the device from surface mode into download mode. Before sending
|
||||
// this command, the device needs to be in PC mode (automatically activated
|
||||
// by connecting the device), or already in download mode.
|
||||
device_status_t status = oceanic_atom2_device_version ((device_t *) device, device->version, sizeof (device->version));
|
||||
if (status != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t status = oceanic_atom2_device_version ((device_t *) device, device->version, sizeof (device->version));
|
||||
if (status != DC_STATUS_SUCCESS) {
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return status;
|
||||
@ -404,17 +404,17 @@ oceanic_atom2_device_open (device_t **out, const char* name)
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_atom2_device_close (device_t *abstract)
|
||||
{
|
||||
oceanic_atom2_device_t *device = (oceanic_atom2_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_atom2 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Send the quit command.
|
||||
oceanic_atom2_quit (device);
|
||||
@ -422,68 +422,68 @@ oceanic_atom2_device_close (device_t *abstract)
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_atom2_device_keepalive (device_t *abstract)
|
||||
{
|
||||
oceanic_atom2_device_t *device = (oceanic_atom2_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_atom2 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Send the command to the dive computer.
|
||||
unsigned char command[4] = {0x91, 0x05, 0xA5, 0x00};
|
||||
device_status_t rc = oceanic_atom2_transfer (device, command, sizeof (command), NULL, 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = oceanic_atom2_transfer (device, command, sizeof (command), NULL, 0);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_atom2_device_version (device_t *abstract, unsigned char data[], unsigned int size)
|
||||
{
|
||||
oceanic_atom2_device_t *device = (oceanic_atom2_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_atom2 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size < PAGESIZE)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
unsigned char answer[PAGESIZE + 1] = {0};
|
||||
unsigned char command[2] = {0x84, 0x00};
|
||||
device_status_t rc = oceanic_atom2_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = oceanic_atom2_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
memcpy (data, answer, PAGESIZE);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_atom2_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size)
|
||||
{
|
||||
oceanic_atom2_device_t *device = (oceanic_atom2_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_atom2 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if ((address % PAGESIZE != 0) ||
|
||||
(size % PAGESIZE != 0))
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// The data transmission is split in packages
|
||||
// of maximum $PAGESIZE bytes.
|
||||
@ -497,8 +497,8 @@ oceanic_atom2_device_read (device_t *abstract, unsigned int address, unsigned ch
|
||||
(number >> 8) & 0xFF, // high
|
||||
(number ) & 0xFF, // low
|
||||
0};
|
||||
device_status_t rc = oceanic_atom2_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = oceanic_atom2_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
memcpy (data, answer, PAGESIZE);
|
||||
@ -508,21 +508,21 @@ oceanic_atom2_device_read (device_t *abstract, unsigned int address, unsigned ch
|
||||
data += PAGESIZE;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_atom2_device_write (device_t *abstract, unsigned int address, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
oceanic_atom2_device_t *device = (oceanic_atom2_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_atom2 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if ((address % PAGESIZE != 0) ||
|
||||
(size % PAGESIZE != 0))
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// The data transmission is split in packages
|
||||
// of maximum $PAGESIZE bytes.
|
||||
@ -535,8 +535,8 @@ oceanic_atom2_device_write (device_t *abstract, unsigned int address, const unsi
|
||||
(number >> 8) & 0xFF, // high
|
||||
(number ) & 0xFF, // low
|
||||
0x00};
|
||||
device_status_t rc = oceanic_atom2_transfer (device, prepare, sizeof (prepare), NULL, 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = oceanic_atom2_transfer (device, prepare, sizeof (prepare), NULL, 0);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Write the package.
|
||||
@ -544,7 +544,7 @@ oceanic_atom2_device_write (device_t *abstract, unsigned int address, const unsi
|
||||
memcpy (command, data, PAGESIZE);
|
||||
command[PAGESIZE] = checksum_add_uint8 (command, PAGESIZE, 0x00);
|
||||
rc = oceanic_atom2_transfer (device, command, sizeof (command), NULL, 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
nbytes += PAGESIZE;
|
||||
@ -552,5 +552,5 @@ oceanic_atom2_device_write (device_t *abstract, unsigned int address, const unsi
|
||||
data += PAGESIZE;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -61,11 +61,11 @@ struct oceanic_atom2_parser_t {
|
||||
double maxdepth;
|
||||
};
|
||||
|
||||
static parser_status_t oceanic_atom2_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static parser_status_t oceanic_atom2_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static parser_status_t oceanic_atom2_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static parser_status_t oceanic_atom2_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static parser_status_t oceanic_atom2_parser_destroy (parser_t *abstract);
|
||||
static dc_status_t oceanic_atom2_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static dc_status_t oceanic_atom2_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static dc_status_t oceanic_atom2_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static dc_status_t oceanic_atom2_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static dc_status_t oceanic_atom2_parser_destroy (parser_t *abstract);
|
||||
|
||||
static const parser_backend_t oceanic_atom2_parser_backend = {
|
||||
PARSER_TYPE_OCEANIC_ATOM2,
|
||||
@ -87,17 +87,17 @@ parser_is_oceanic_atom2 (parser_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
oceanic_atom2_parser_create (parser_t **out, unsigned int model)
|
||||
{
|
||||
if (out == NULL)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
oceanic_atom2_parser_t *parser = (oceanic_atom2_parser_t *) malloc (sizeof (oceanic_atom2_parser_t));
|
||||
if (parser == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return PARSER_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -111,41 +111,41 @@ oceanic_atom2_parser_create (parser_t **out, unsigned int model)
|
||||
|
||||
*out = (parser_t*) parser;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
oceanic_atom2_parser_destroy (parser_t *abstract)
|
||||
{
|
||||
if (! parser_is_oceanic_atom2 (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Free memory.
|
||||
free (abstract);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
oceanic_atom2_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
oceanic_atom2_parser_t *parser = (oceanic_atom2_parser_t *) abstract;
|
||||
|
||||
if (! parser_is_oceanic_atom2 (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Reset the cache.
|
||||
parser->cached = 0;
|
||||
parser->divetime = 0;
|
||||
parser->maxdepth = 0.0;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
oceanic_atom2_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
{
|
||||
oceanic_atom2_parser_t *parser = (oceanic_atom2_parser_t *) abstract;
|
||||
@ -155,7 +155,7 @@ oceanic_atom2_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
header = 32;
|
||||
|
||||
if (abstract->size < header)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *p = abstract->data;
|
||||
|
||||
@ -250,11 +250,11 @@ oceanic_atom2_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
oceanic_atom2_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value)
|
||||
{
|
||||
oceanic_atom2_parser_t *parser = (oceanic_atom2_parser_t *) abstract;
|
||||
@ -279,7 +279,7 @@ oceanic_atom2_parser_get_field (parser_t *abstract, parser_field_type_t type, un
|
||||
}
|
||||
|
||||
if (size < headersize + footersize)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// Get the offset to the header and footer sample.
|
||||
unsigned int header = headersize - PAGESIZE / 2;
|
||||
@ -290,9 +290,9 @@ oceanic_atom2_parser_get_field (parser_t *abstract, parser_field_type_t type, un
|
||||
|
||||
if (!parser->cached) {
|
||||
sample_statistics_t statistics = SAMPLE_STATISTICS_INITIALIZER;
|
||||
parser_status_t rc = oceanic_atom2_parser_samples_foreach (
|
||||
dc_status_t rc = oceanic_atom2_parser_samples_foreach (
|
||||
abstract, sample_statistics_cb, &statistics);
|
||||
if (rc != PARSER_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
parser->cached = 1;
|
||||
@ -336,21 +336,21 @@ oceanic_atom2_parser_get_field (parser_t *abstract, parser_field_type_t type, un
|
||||
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
oceanic_atom2_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata)
|
||||
{
|
||||
oceanic_atom2_parser_t *parser = (oceanic_atom2_parser_t *) abstract;
|
||||
|
||||
if (! parser_is_oceanic_atom2 (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
const unsigned char *data = abstract->data;
|
||||
unsigned int size = abstract->size;
|
||||
@ -372,7 +372,7 @@ oceanic_atom2_parser_samples_foreach (parser_t *abstract, sample_callback_t call
|
||||
}
|
||||
|
||||
if (size < headersize + footersize)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// Get the offset to the header sample.
|
||||
unsigned int header = headersize - PAGESIZE / 2;
|
||||
@ -457,7 +457,7 @@ oceanic_atom2_parser_samples_foreach (parser_t *abstract, sample_callback_t call
|
||||
if (sampletype == 0xBB) {
|
||||
length = PAGESIZE;
|
||||
if (offset + length > size - PAGESIZE)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
// Vendor specific data
|
||||
@ -558,5 +558,5 @@ oceanic_atom2_parser_samples_foreach (parser_t *abstract, sample_callback_t call
|
||||
offset += length;
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ oceanic_common_device_init (oceanic_common_device_t *device, const device_backen
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_common_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
oceanic_common_device_t *device = (oceanic_common_device_t *) abstract;
|
||||
@ -132,18 +132,18 @@ oceanic_common_device_set_fingerprint (device_t *abstract, const unsigned char d
|
||||
unsigned int fpsize = device->layout->rb_logbook_entry_size;
|
||||
|
||||
if (size && size != fpsize)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size)
|
||||
memcpy (device->fingerprint, data, fpsize);
|
||||
else
|
||||
memset (device->fingerprint, 0, fpsize);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_common_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
oceanic_common_device_t *device = (oceanic_common_device_t *) abstract;
|
||||
@ -155,7 +155,7 @@ oceanic_common_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, device->layout->memsize)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
return device_dump_read (abstract, dc_buffer_get_data (buffer),
|
||||
@ -163,7 +163,7 @@ oceanic_common_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_common_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
oceanic_common_device_t *device = (oceanic_common_device_t *) abstract;
|
||||
@ -183,8 +183,8 @@ oceanic_common_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
|
||||
// Read the device id.
|
||||
unsigned char id[PAGESIZE] = {0};
|
||||
device_status_t rc = device_read (abstract, layout->cf_devinfo, id, sizeof (id));
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = device_read (abstract, layout->cf_devinfo, id, sizeof (id));
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read device id.");
|
||||
return rc;
|
||||
}
|
||||
@ -206,7 +206,7 @@ oceanic_common_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
// Read the pointer data.
|
||||
unsigned char pointers[PAGESIZE] = {0};
|
||||
rc = device_read (abstract, layout->cf_pointers, pointers, sizeof (pointers));
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read pointers.");
|
||||
return rc;
|
||||
}
|
||||
@ -282,7 +282,7 @@ oceanic_common_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
// Memory buffer for the logbook entries.
|
||||
unsigned char *logbooks = (unsigned char *) malloc (rb_logbook_page_size);
|
||||
if (logbooks == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
|
||||
// Since entries are not necessary aligned on page boundaries,
|
||||
// the memory buffer may contain padding entries on both sides.
|
||||
@ -296,7 +296,7 @@ oceanic_common_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
}
|
||||
|
||||
// Error status for delayed errors.
|
||||
device_status_t status = DEVICE_STATUS_SUCCESS;
|
||||
dc_status_t status = DC_STATUS_SUCCESS;
|
||||
|
||||
// Keep track of the previous dive.
|
||||
unsigned int remaining = layout->rb_profile_end - layout->rb_profile_begin;
|
||||
@ -329,7 +329,7 @@ oceanic_common_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
|
||||
// Read the logbook page.
|
||||
rc = device_read (abstract, address, logbooks + offset, len);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
free (logbooks);
|
||||
return rc;
|
||||
}
|
||||
@ -396,7 +396,7 @@ oceanic_common_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
rb_entry_last >= layout->rb_profile_end)
|
||||
{
|
||||
WARNING("Invalid ringbuffer pointer detected!");
|
||||
status = DEVICE_STATUS_ERROR;
|
||||
status = DC_STATUS_DATAFORMAT;
|
||||
begin = current + layout->rb_logbook_entry_size;
|
||||
abort = 1;
|
||||
break;
|
||||
@ -458,7 +458,7 @@ oceanic_common_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
unsigned char *profiles = (unsigned char *) malloc (rb_profile_size + (end - begin));
|
||||
if (profiles == NULL) {
|
||||
free (logbooks);
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// When using multipage reads, the last packet can contain data from more
|
||||
@ -514,7 +514,7 @@ oceanic_common_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
|
||||
// Read the profile page.
|
||||
rc = device_read (abstract, address, profiles + offset, len);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
free (logbooks);
|
||||
free (profiles);
|
||||
return rc;
|
||||
@ -543,7 +543,7 @@ oceanic_common_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
if (callback && !callback (p, rb_entry_size + layout->rb_logbook_entry_size, p, layout->rb_logbook_entry_size, userdata)) {
|
||||
free (logbooks);
|
||||
free (profiles);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -66,13 +66,13 @@ oceanic_common_match (const unsigned char *pattern, const unsigned char *string,
|
||||
void
|
||||
oceanic_common_device_init (oceanic_common_device_t *device, const device_backend_t *backend);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_common_device_set_fingerprint (device_t *device, const unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_common_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_common_device_foreach (device_t *device, dive_callback_t callback, void *userdata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
#define ACK 0x5A
|
||||
@ -49,9 +49,9 @@ typedef struct oceanic_veo250_device_t {
|
||||
unsigned char version[PAGESIZE];
|
||||
} oceanic_veo250_device_t;
|
||||
|
||||
static device_status_t oceanic_veo250_device_version (device_t *abstract, unsigned char data[], unsigned int size);
|
||||
static device_status_t oceanic_veo250_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
static device_status_t oceanic_veo250_device_close (device_t *abstract);
|
||||
static dc_status_t oceanic_veo250_device_version (device_t *abstract, unsigned char data[], unsigned int size);
|
||||
static dc_status_t oceanic_veo250_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
static dc_status_t oceanic_veo250_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t oceanic_veo250_device_backend = {
|
||||
DEVICE_TYPE_OCEANIC_VEO250,
|
||||
@ -88,13 +88,13 @@ device_is_oceanic_veo250 (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_veo250_send (oceanic_veo250_device_t *device, const unsigned char command[], unsigned int csize)
|
||||
{
|
||||
device_t *abstract = (device_t *) device;
|
||||
|
||||
if (device_is_cancelled (abstract))
|
||||
return DEVICE_STATUS_CANCELLED;
|
||||
return DC_STATUS_CANCELLED;
|
||||
|
||||
// Discard garbage bytes.
|
||||
serial_flush (device->port, SERIAL_QUEUE_INPUT);
|
||||
@ -117,14 +117,14 @@ oceanic_veo250_send (oceanic_veo250_device_t *device, const unsigned char comman
|
||||
// Verify the response of the dive computer.
|
||||
if (response != ACK) {
|
||||
WARNING ("Unexpected answer start byte(s).");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_veo250_transfer (oceanic_veo250_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize)
|
||||
{
|
||||
// Send the command to the device. If the device responds with an
|
||||
@ -134,9 +134,9 @@ oceanic_veo250_transfer (oceanic_veo250_device_t *device, const unsigned char co
|
||||
// returning an error.
|
||||
|
||||
unsigned int nretries = 0;
|
||||
device_status_t rc = DEVICE_STATUS_SUCCESS;
|
||||
while ((rc = oceanic_veo250_send (device, command, csize)) != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DEVICE_STATUS_TIMEOUT && rc != DEVICE_STATUS_PROTOCOL)
|
||||
dc_status_t rc = DC_STATUS_SUCCESS;
|
||||
while ((rc = oceanic_veo250_send (device, command, csize)) != DC_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_TIMEOUT && rc != DC_STATUS_PROTOCOL)
|
||||
return rc;
|
||||
|
||||
// Abort if the maximum number of retries is reached.
|
||||
@ -157,14 +157,14 @@ oceanic_veo250_transfer (oceanic_veo250_device_t *device, const unsigned char co
|
||||
// Verify the last byte of the answer.
|
||||
if (answer[asize - 1] != NAK) {
|
||||
WARNING ("Unexpected answer byte.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_veo250_init (oceanic_veo250_device_t *device)
|
||||
{
|
||||
// Send the command to the dive computer.
|
||||
@ -181,7 +181,7 @@ oceanic_veo250_init (oceanic_veo250_device_t *device)
|
||||
if (n != sizeof (answer)) {
|
||||
WARNING ("Failed to receive the answer.");
|
||||
if (n == 0)
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
return EXITCODE (n);
|
||||
}
|
||||
|
||||
@ -191,14 +191,14 @@ oceanic_veo250_init (oceanic_veo250_device_t *device)
|
||||
0x5F, 0x56, 0x32, 0x2E, 0x30, 0x30};
|
||||
if (memcmp (answer, response, sizeof (response)) != 0) {
|
||||
WARNING ("Unexpected answer byte(s).");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_veo250_quit (oceanic_veo250_device_t *device)
|
||||
{
|
||||
// Send the command to the dive computer.
|
||||
@ -209,21 +209,21 @@ oceanic_veo250_quit (oceanic_veo250_device_t *device)
|
||||
return EXITCODE (n);
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_veo250_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
oceanic_veo250_device_t *device = (oceanic_veo250_device_t *) malloc (sizeof (oceanic_veo250_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -243,7 +243,7 @@ oceanic_veo250_device_open (device_t **out, const char* name)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (9600 8N1).
|
||||
@ -252,7 +252,7 @@ oceanic_veo250_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (3000 ms).
|
||||
@ -260,7 +260,7 @@ oceanic_veo250_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the DTR and RTS lines.
|
||||
@ -269,7 +269,7 @@ oceanic_veo250_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the DTR/RTS line.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Give the interface 100 ms to settle and draw power up.
|
||||
@ -279,8 +279,8 @@ oceanic_veo250_device_open (device_t **out, const char* name)
|
||||
serial_flush (device->port, SERIAL_QUEUE_BOTH);
|
||||
|
||||
// Initialize the data cable (PPS mode).
|
||||
device_status_t status = oceanic_veo250_init (device);
|
||||
if (status != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t status = oceanic_veo250_init (device);
|
||||
if (status != DC_STATUS_SUCCESS) {
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return status;
|
||||
@ -293,7 +293,7 @@ oceanic_veo250_device_open (device_t **out, const char* name)
|
||||
// this command, the device needs to be in PC mode (manually activated by
|
||||
// the user), or already in download mode.
|
||||
status = oceanic_veo250_device_version ((device_t *) device, device->version, sizeof (device->version));
|
||||
if (status != DEVICE_STATUS_SUCCESS) {
|
||||
if (status != DC_STATUS_SUCCESS) {
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return status;
|
||||
@ -301,17 +301,17 @@ oceanic_veo250_device_open (device_t **out, const char* name)
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_veo250_device_close (device_t *abstract)
|
||||
{
|
||||
oceanic_veo250_device_t *device = (oceanic_veo250_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_veo250 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Switch the device back to surface mode.
|
||||
oceanic_veo250_quit (device);
|
||||
@ -319,58 +319,58 @@ oceanic_veo250_device_close (device_t *abstract)
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_veo250_device_keepalive (device_t *abstract)
|
||||
{
|
||||
oceanic_veo250_device_t *device = (oceanic_veo250_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_veo250 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
unsigned char answer[2] = {0};
|
||||
unsigned char command[4] = {0x91,
|
||||
(device->last ) & 0xFF, // low
|
||||
(device->last >> 8) & 0xFF, // high
|
||||
0x00};
|
||||
device_status_t rc = oceanic_veo250_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = oceanic_veo250_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Verify the answer.
|
||||
if (answer[0] != NAK) {
|
||||
WARNING ("Unexpected answer byte(s).");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_veo250_device_version (device_t *abstract, unsigned char data[], unsigned int size)
|
||||
{
|
||||
oceanic_veo250_device_t *device = (oceanic_veo250_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_veo250 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size < PAGESIZE)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
unsigned char answer[PAGESIZE + 2] = {0};
|
||||
unsigned char command[2] = {0x90, 0x00};
|
||||
device_status_t rc = oceanic_veo250_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = oceanic_veo250_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Verify the checksum of the answer.
|
||||
@ -378,26 +378,26 @@ oceanic_veo250_device_version (device_t *abstract, unsigned char data[], unsigne
|
||||
unsigned char ccrc = checksum_add_uint8 (answer, PAGESIZE, 0x00);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
memcpy (data, answer, PAGESIZE);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_veo250_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size)
|
||||
{
|
||||
oceanic_veo250_device_t *device = (oceanic_veo250_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_veo250 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if ((address % PAGESIZE != 0) ||
|
||||
(size % PAGESIZE != 0))
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// The data transmission is split in packages
|
||||
// of maximum $PAGESIZE bytes.
|
||||
@ -419,8 +419,8 @@ oceanic_veo250_device_read (device_t *abstract, unsigned int address, unsigned c
|
||||
(last ) & 0xFF, // low
|
||||
(last >> 8) & 0xFF, // high
|
||||
0};
|
||||
device_status_t rc = oceanic_veo250_transfer (device, command, sizeof (command), answer, (PAGESIZE + 1) * npackets + 1);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = oceanic_veo250_transfer (device, command, sizeof (command), answer, (PAGESIZE + 1) * npackets + 1);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
device->last = last;
|
||||
@ -432,7 +432,7 @@ oceanic_veo250_device_read (device_t *abstract, unsigned int address, unsigned c
|
||||
unsigned char ccrc = checksum_add_uint8 (answer + offset, PAGESIZE, 0x00);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
memcpy (data, answer + offset, PAGESIZE);
|
||||
@ -444,5 +444,5 @@ oceanic_veo250_device_read (device_t *abstract, unsigned int address, unsigned c
|
||||
}
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -40,11 +40,11 @@ struct oceanic_veo250_parser_t {
|
||||
double maxdepth;
|
||||
};
|
||||
|
||||
static parser_status_t oceanic_veo250_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static parser_status_t oceanic_veo250_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static parser_status_t oceanic_veo250_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static parser_status_t oceanic_veo250_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static parser_status_t oceanic_veo250_parser_destroy (parser_t *abstract);
|
||||
static dc_status_t oceanic_veo250_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static dc_status_t oceanic_veo250_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static dc_status_t oceanic_veo250_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static dc_status_t oceanic_veo250_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static dc_status_t oceanic_veo250_parser_destroy (parser_t *abstract);
|
||||
|
||||
static const parser_backend_t oceanic_veo250_parser_backend = {
|
||||
PARSER_TYPE_OCEANIC_VEO250,
|
||||
@ -66,17 +66,17 @@ parser_is_oceanic_veo250 (parser_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
oceanic_veo250_parser_create (parser_t **out, unsigned int model)
|
||||
{
|
||||
if (out == NULL)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
oceanic_veo250_parser_t *parser = (oceanic_veo250_parser_t *) malloc (sizeof (oceanic_veo250_parser_t));
|
||||
if (parser == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return PARSER_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -90,47 +90,47 @@ oceanic_veo250_parser_create (parser_t **out, unsigned int model)
|
||||
|
||||
*out = (parser_t*) parser;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
oceanic_veo250_parser_destroy (parser_t *abstract)
|
||||
{
|
||||
if (! parser_is_oceanic_veo250 (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Free memory.
|
||||
free (abstract);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
oceanic_veo250_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
oceanic_veo250_parser_t *parser = (oceanic_veo250_parser_t *) abstract;
|
||||
|
||||
if (! parser_is_oceanic_veo250 (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Reset the cache.
|
||||
parser->cached = 0;
|
||||
parser->divetime = 0;
|
||||
parser->maxdepth = 0.0;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
oceanic_veo250_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
{
|
||||
oceanic_veo250_parser_t *parser = (oceanic_veo250_parser_t *) abstract;
|
||||
|
||||
if (abstract->size < 8)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *p = abstract->data;
|
||||
|
||||
@ -146,11 +146,11 @@ oceanic_veo250_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
datetime->year += 3;
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
oceanic_veo250_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value)
|
||||
{
|
||||
oceanic_veo250_parser_t *parser = (oceanic_veo250_parser_t *) abstract;
|
||||
@ -159,13 +159,13 @@ oceanic_veo250_parser_get_field (parser_t *abstract, parser_field_type_t type, u
|
||||
unsigned int size = abstract->size;
|
||||
|
||||
if (size < 7 * PAGESIZE / 2)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
if (!parser->cached) {
|
||||
sample_statistics_t statistics = SAMPLE_STATISTICS_INITIALIZER;
|
||||
parser_status_t rc = oceanic_veo250_parser_samples_foreach (
|
||||
dc_status_t rc = oceanic_veo250_parser_samples_foreach (
|
||||
abstract, sample_statistics_cb, &statistics);
|
||||
if (rc != PARSER_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
parser->cached = 1;
|
||||
@ -197,25 +197,25 @@ oceanic_veo250_parser_get_field (parser_t *abstract, parser_field_type_t type, u
|
||||
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
oceanic_veo250_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata)
|
||||
{
|
||||
if (! parser_is_oceanic_veo250 (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
const unsigned char *data = abstract->data;
|
||||
unsigned int size = abstract->size;
|
||||
|
||||
if (size < 7 * PAGESIZE / 2)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int time = 0;
|
||||
unsigned int interval = 0;
|
||||
@ -268,5 +268,5 @@ oceanic_veo250_parser_samples_foreach (parser_t *abstract, sample_callback_t cal
|
||||
offset += PAGESIZE / 2;
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
#define ACK 0x5A
|
||||
@ -49,9 +49,9 @@ typedef struct oceanic_vtpro_device_t {
|
||||
unsigned char version[PAGESIZE];
|
||||
} oceanic_vtpro_device_t;
|
||||
|
||||
static device_status_t oceanic_vtpro_device_version (device_t *abstract, unsigned char data[], unsigned int size);
|
||||
static device_status_t oceanic_vtpro_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
static device_status_t oceanic_vtpro_device_close (device_t *abstract);
|
||||
static dc_status_t oceanic_vtpro_device_version (device_t *abstract, unsigned char data[], unsigned int size);
|
||||
static dc_status_t oceanic_vtpro_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
static dc_status_t oceanic_vtpro_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t oceanic_vtpro_device_backend = {
|
||||
DEVICE_TYPE_OCEANIC_VTPRO,
|
||||
@ -103,13 +103,13 @@ device_is_oceanic_vtpro (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_vtpro_send (oceanic_vtpro_device_t *device, const unsigned char command[], unsigned int csize)
|
||||
{
|
||||
device_t *abstract = (device_t *) device;
|
||||
|
||||
if (device_is_cancelled (abstract))
|
||||
return DEVICE_STATUS_CANCELLED;
|
||||
return DC_STATUS_CANCELLED;
|
||||
|
||||
// Send the command to the dive computer.
|
||||
int n = serial_write (device->port, command, csize);
|
||||
@ -129,14 +129,14 @@ oceanic_vtpro_send (oceanic_vtpro_device_t *device, const unsigned char command[
|
||||
// Verify the response of the dive computer.
|
||||
if (response != ACK) {
|
||||
WARNING ("Unexpected answer start byte(s).");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_vtpro_transfer (oceanic_vtpro_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize)
|
||||
{
|
||||
// Send the command to the device. If the device responds with an
|
||||
@ -146,9 +146,9 @@ oceanic_vtpro_transfer (oceanic_vtpro_device_t *device, const unsigned char comm
|
||||
// returning an error.
|
||||
|
||||
unsigned int nretries = 0;
|
||||
device_status_t rc = DEVICE_STATUS_SUCCESS;
|
||||
while ((rc = oceanic_vtpro_send (device, command, csize)) != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DEVICE_STATUS_TIMEOUT && rc != DEVICE_STATUS_PROTOCOL)
|
||||
dc_status_t rc = DC_STATUS_SUCCESS;
|
||||
while ((rc = oceanic_vtpro_send (device, command, csize)) != DC_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_TIMEOUT && rc != DC_STATUS_PROTOCOL)
|
||||
return rc;
|
||||
|
||||
// Abort if the maximum number of retries is reached.
|
||||
@ -163,11 +163,11 @@ oceanic_vtpro_transfer (oceanic_vtpro_device_t *device, const unsigned char comm
|
||||
return EXITCODE (n);
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_vtpro_init (oceanic_vtpro_device_t *device)
|
||||
{
|
||||
// Send the command to the dive computer.
|
||||
@ -192,34 +192,34 @@ oceanic_vtpro_init (oceanic_vtpro_device_t *device)
|
||||
0x5F, 0x56, 0x32, 0x2E, 0x30, 0x30};
|
||||
if (memcmp (answer, response, sizeof (response)) != 0) {
|
||||
WARNING ("Unexpected answer byte(s).");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_vtpro_quit (oceanic_vtpro_device_t *device)
|
||||
{
|
||||
// Send the command to the dive computer.
|
||||
unsigned char answer[1] = {0};
|
||||
unsigned char command[4] = {0x6A, 0x05, 0xA5, 0x00};
|
||||
device_status_t rc = oceanic_vtpro_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = oceanic_vtpro_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Verify the last byte of the answer.
|
||||
if (answer[0] != END) {
|
||||
WARNING ("Unexpected answer byte(s).");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_vtpro_calibrate (oceanic_vtpro_device_t *device)
|
||||
{
|
||||
// Send the command to the dive computer.
|
||||
@ -228,32 +228,32 @@ oceanic_vtpro_calibrate (oceanic_vtpro_device_t *device)
|
||||
unsigned char answer[2] = {0};
|
||||
unsigned char command[2] = {0x18, 0x00};
|
||||
serial_set_timeout (device->port, 9000);
|
||||
device_status_t rc = oceanic_vtpro_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||
dc_status_t rc = oceanic_vtpro_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||
serial_set_timeout (device->port, 3000);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Verify the last byte of the answer.
|
||||
if (answer[1] != 0x00) {
|
||||
WARNING ("Unexpected answer byte(s).");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_vtpro_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
oceanic_vtpro_device_t *device = (oceanic_vtpro_device_t *) malloc (sizeof (oceanic_vtpro_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -271,7 +271,7 @@ oceanic_vtpro_device_open (device_t **out, const char* name)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (9600 8N1).
|
||||
@ -280,7 +280,7 @@ oceanic_vtpro_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (3000 ms).
|
||||
@ -288,7 +288,7 @@ oceanic_vtpro_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the DTR and RTS lines.
|
||||
@ -297,7 +297,7 @@ oceanic_vtpro_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the DTR/RTS line.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Give the interface 100 ms to settle and draw power up.
|
||||
@ -307,8 +307,8 @@ oceanic_vtpro_device_open (device_t **out, const char* name)
|
||||
serial_flush (device->port, SERIAL_QUEUE_BOTH);
|
||||
|
||||
// Initialize the data cable (MOD mode).
|
||||
device_status_t status = oceanic_vtpro_init (device);
|
||||
if (status != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t status = oceanic_vtpro_init (device);
|
||||
if (status != DC_STATUS_SUCCESS) {
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return status;
|
||||
@ -318,7 +318,7 @@ oceanic_vtpro_device_open (device_t **out, const char* name)
|
||||
// this command, the device needs to be in PC mode (manually activated by
|
||||
// the user), or already in download mode.
|
||||
status = oceanic_vtpro_device_version ((device_t *) device, device->version, sizeof (device->version));
|
||||
if (status != DEVICE_STATUS_SUCCESS) {
|
||||
if (status != DC_STATUS_SUCCESS) {
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return status;
|
||||
@ -328,7 +328,7 @@ oceanic_vtpro_device_open (device_t **out, const char* name)
|
||||
// recommended because it reduces the transfer time considerably, even
|
||||
// when processing the command itself is quite slow.
|
||||
status = oceanic_vtpro_calibrate (device);
|
||||
if (status != DEVICE_STATUS_SUCCESS) {
|
||||
if (status != DC_STATUS_SUCCESS) {
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return status;
|
||||
@ -342,17 +342,17 @@ oceanic_vtpro_device_open (device_t **out, const char* name)
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_vtpro_device_close (device_t *abstract)
|
||||
{
|
||||
oceanic_vtpro_device_t *device = (oceanic_vtpro_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_vtpro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Switch the device back to surface mode.
|
||||
oceanic_vtpro_quit (device);
|
||||
@ -360,51 +360,51 @@ oceanic_vtpro_device_close (device_t *abstract)
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
oceanic_vtpro_device_keepalive (device_t *abstract)
|
||||
{
|
||||
oceanic_vtpro_device_t *device = (oceanic_vtpro_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_vtpro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Send the command to the dive computer.
|
||||
unsigned char answer[1] = {0};
|
||||
unsigned char command[4] = {0x6A, 0x08, 0x00, 0x00};
|
||||
device_status_t rc = oceanic_vtpro_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = oceanic_vtpro_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Verify the last byte of the answer.
|
||||
if (answer[0] != END) {
|
||||
WARNING ("Unexpected answer byte(s).");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_vtpro_device_version (device_t *abstract, unsigned char data[], unsigned int size)
|
||||
{
|
||||
oceanic_vtpro_device_t *device = (oceanic_vtpro_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_vtpro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size < PAGESIZE)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Switch the device into download mode. The response is ignored here,
|
||||
// since it is identical (except for the missing trailing byte) to the
|
||||
@ -412,8 +412,8 @@ oceanic_vtpro_device_version (device_t *abstract, unsigned char data[], unsigned
|
||||
|
||||
unsigned char cmd[2] = {0x88, 0x00};
|
||||
unsigned char ans[PAGESIZE / 2 + 1] = {0};
|
||||
device_status_t rc = oceanic_vtpro_transfer (device, cmd, sizeof (cmd), ans, sizeof (ans));
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = oceanic_vtpro_transfer (device, cmd, sizeof (cmd), ans, sizeof (ans));
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Verify the checksum of the answer.
|
||||
@ -421,7 +421,7 @@ oceanic_vtpro_device_version (device_t *abstract, unsigned char data[], unsigned
|
||||
unsigned char ccrc = checksum_add_uint4 (ans, PAGESIZE / 2, 0x00);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Obtain the device identification string. This string is
|
||||
@ -431,7 +431,7 @@ oceanic_vtpro_device_version (device_t *abstract, unsigned char data[], unsigned
|
||||
unsigned char command[4] = {0x72, 0x03, i * 0x10, 0x00};
|
||||
unsigned char answer[PAGESIZE / 2 + 2] = {0};
|
||||
rc = oceanic_vtpro_transfer (device, command, sizeof (command), answer, sizeof (answer));
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Verify the checksum of the answer.
|
||||
@ -439,34 +439,34 @@ oceanic_vtpro_device_version (device_t *abstract, unsigned char data[], unsigned
|
||||
unsigned char ccrc = checksum_add_uint4 (answer, PAGESIZE / 2, 0x00);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Verify the last byte of the answer.
|
||||
if (answer[PAGESIZE / 2 + 1] != END) {
|
||||
WARNING ("Unexpected answer byte.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Append the answer to the output buffer.
|
||||
memcpy (data + i * PAGESIZE / 2, answer, PAGESIZE / 2);
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
oceanic_vtpro_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size)
|
||||
{
|
||||
oceanic_vtpro_device_t *device = (oceanic_vtpro_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_vtpro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if ((address % PAGESIZE != 0) ||
|
||||
(size % PAGESIZE != 0))
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// The data transmission is split in packages
|
||||
// of maximum $PAGESIZE bytes.
|
||||
@ -488,8 +488,8 @@ oceanic_vtpro_device_read (device_t *abstract, unsigned int address, unsigned ch
|
||||
(last >> 8) & 0xFF, // high
|
||||
(last ) & 0xFF, // low
|
||||
0x00};
|
||||
device_status_t rc = oceanic_vtpro_transfer (device, command, sizeof (command), answer, (PAGESIZE + 1) * npackets);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = oceanic_vtpro_transfer (device, command, sizeof (command), answer, (PAGESIZE + 1) * npackets);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
unsigned int offset = 0;
|
||||
@ -499,7 +499,7 @@ oceanic_vtpro_device_read (device_t *abstract, unsigned int address, unsigned ch
|
||||
unsigned char ccrc = checksum_add_uint8 (answer + offset, PAGESIZE, 0x00);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
memcpy (data, answer + offset, PAGESIZE);
|
||||
@ -511,5 +511,5 @@ oceanic_vtpro_device_read (device_t *abstract, unsigned int address, unsigned ch
|
||||
}
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -39,11 +39,11 @@ struct oceanic_vtpro_parser_t {
|
||||
double maxdepth;
|
||||
};
|
||||
|
||||
static parser_status_t oceanic_vtpro_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static parser_status_t oceanic_vtpro_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static parser_status_t oceanic_vtpro_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static parser_status_t oceanic_vtpro_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static parser_status_t oceanic_vtpro_parser_destroy (parser_t *abstract);
|
||||
static dc_status_t oceanic_vtpro_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static dc_status_t oceanic_vtpro_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static dc_status_t oceanic_vtpro_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static dc_status_t oceanic_vtpro_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static dc_status_t oceanic_vtpro_parser_destroy (parser_t *abstract);
|
||||
|
||||
static const parser_backend_t oceanic_vtpro_parser_backend = {
|
||||
PARSER_TYPE_OCEANIC_VTPRO,
|
||||
@ -65,17 +65,17 @@ parser_is_oceanic_vtpro (parser_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
oceanic_vtpro_parser_create (parser_t **out)
|
||||
{
|
||||
if (out == NULL)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
oceanic_vtpro_parser_t *parser = (oceanic_vtpro_parser_t *) malloc (sizeof (oceanic_vtpro_parser_t));
|
||||
if (parser == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return PARSER_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -88,45 +88,45 @@ oceanic_vtpro_parser_create (parser_t **out)
|
||||
|
||||
*out = (parser_t*) parser;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
oceanic_vtpro_parser_destroy (parser_t *abstract)
|
||||
{
|
||||
if (! parser_is_oceanic_vtpro (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Free memory.
|
||||
free (abstract);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
oceanic_vtpro_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
oceanic_vtpro_parser_t *parser = (oceanic_vtpro_parser_t *) abstract;
|
||||
|
||||
if (! parser_is_oceanic_vtpro (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Reset the cache.
|
||||
parser->cached = 0;
|
||||
parser->divetime = 0;
|
||||
parser->maxdepth = 0.0;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
oceanic_vtpro_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
{
|
||||
if (abstract->size < 8)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *p = abstract->data;
|
||||
|
||||
@ -149,11 +149,11 @@ oceanic_vtpro_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
datetime->hour += 12;
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
oceanic_vtpro_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value)
|
||||
{
|
||||
oceanic_vtpro_parser_t *parser = (oceanic_vtpro_parser_t *) abstract;
|
||||
@ -162,13 +162,13 @@ oceanic_vtpro_parser_get_field (parser_t *abstract, parser_field_type_t type, un
|
||||
unsigned int size = abstract->size;
|
||||
|
||||
if (size < 7 * PAGESIZE / 2)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
if (!parser->cached) {
|
||||
sample_statistics_t statistics = SAMPLE_STATISTICS_INITIALIZER;
|
||||
parser_status_t rc = oceanic_vtpro_parser_samples_foreach (
|
||||
dc_status_t rc = oceanic_vtpro_parser_samples_foreach (
|
||||
abstract, sample_statistics_cb, &statistics);
|
||||
if (rc != PARSER_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
parser->cached = 1;
|
||||
@ -200,25 +200,25 @@ oceanic_vtpro_parser_get_field (parser_t *abstract, parser_field_type_t type, un
|
||||
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
oceanic_vtpro_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata)
|
||||
{
|
||||
if (! parser_is_oceanic_vtpro (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
const unsigned char *data = abstract->data;
|
||||
unsigned int size = abstract->size;
|
||||
|
||||
if (size < 7 * PAGESIZE / 2)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int time = 0;
|
||||
unsigned int interval = 0;
|
||||
@ -257,7 +257,7 @@ oceanic_vtpro_parser_samples_foreach (parser_t *abstract, sample_callback_t call
|
||||
unsigned int current = bcd2dec (data[offset + 1] & 0x0F) * 60 + bcd2dec (data[offset + 0]);
|
||||
if (current < timestamp) {
|
||||
WARNING ("Timestamp moved backwards.");
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
if (current != timestamp || count == 0) {
|
||||
@ -295,11 +295,11 @@ oceanic_vtpro_parser_samples_foreach (parser_t *abstract, sample_callback_t call
|
||||
if (interval) {
|
||||
if (current > timestamp + 1) {
|
||||
WARNING ("Unexpected timestamp jump.");
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
if (i >= count) {
|
||||
WARNING ("Unexpected number of samples with the same timestamp.");
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
@ -333,5 +333,5 @@ oceanic_vtpro_parser_samples_foreach (parser_t *abstract, sample_callback_t call
|
||||
offset += PAGESIZE / 2;
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -42,15 +42,15 @@ struct parser_t {
|
||||
struct parser_backend_t {
|
||||
parser_type_t type;
|
||||
|
||||
parser_status_t (*set_data) (parser_t *parser, const unsigned char *data, unsigned int size);
|
||||
dc_status_t (*set_data) (parser_t *parser, const unsigned char *data, unsigned int size);
|
||||
|
||||
parser_status_t (*datetime) (parser_t *parser, dc_datetime_t *datetime);
|
||||
dc_status_t (*datetime) (parser_t *parser, dc_datetime_t *datetime);
|
||||
|
||||
parser_status_t (*field) (parser_t *parser, parser_field_type_t type, unsigned int flags, void *value);
|
||||
dc_status_t (*field) (parser_t *parser, parser_field_type_t type, unsigned int flags, void *value);
|
||||
|
||||
parser_status_t (*samples_foreach) (parser_t *parser, sample_callback_t callback, void *userdata);
|
||||
dc_status_t (*samples_foreach) (parser_t *parser, sample_callback_t callback, void *userdata);
|
||||
|
||||
parser_status_t (*destroy) (parser_t *parser);
|
||||
dc_status_t (*destroy) (parser_t *parser);
|
||||
};
|
||||
|
||||
void
|
||||
|
||||
30
src/parser.c
30
src/parser.c
@ -43,14 +43,14 @@ parser_get_type (parser_t *parser)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
parser_set_data (parser_t *parser, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
if (parser == NULL)
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
if (parser->backend->set_data == NULL)
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
parser->data = data;
|
||||
parser->size = size;
|
||||
@ -59,52 +59,52 @@ parser_set_data (parser_t *parser, const unsigned char *data, unsigned int size)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
parser_get_datetime (parser_t *parser, dc_datetime_t *datetime)
|
||||
{
|
||||
if (parser == NULL)
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
if (parser->backend->datetime == NULL)
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
return parser->backend->datetime (parser, datetime);
|
||||
}
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
parser_get_field (parser_t *parser, parser_field_type_t type, unsigned int flags, void *value)
|
||||
{
|
||||
if (parser == NULL)
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
if (parser->backend->field == NULL)
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
return parser->backend->field (parser, type, flags, value);
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
parser_samples_foreach (parser_t *parser, sample_callback_t callback, void *userdata)
|
||||
{
|
||||
if (parser == NULL)
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
if (parser->backend->samples_foreach == NULL)
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
return parser->backend->samples_foreach (parser, callback, userdata);
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
parser_destroy (parser_t *parser)
|
||||
{
|
||||
if (parser == NULL)
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
||||
if (parser->backend->destroy == NULL)
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
return parser->backend->destroy (parser);
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
typedef struct reefnet_sensus_device_t {
|
||||
@ -45,10 +45,10 @@ typedef struct reefnet_sensus_device_t {
|
||||
dc_ticks_t systime;
|
||||
} reefnet_sensus_device_t;
|
||||
|
||||
static device_status_t reefnet_sensus_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t reefnet_sensus_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t reefnet_sensus_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t reefnet_sensus_device_close (device_t *abstract);
|
||||
static dc_status_t reefnet_sensus_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static dc_status_t reefnet_sensus_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static dc_status_t reefnet_sensus_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static dc_status_t reefnet_sensus_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t reefnet_sensus_device_backend = {
|
||||
DEVICE_TYPE_REEFNET_SENSUS,
|
||||
@ -71,7 +71,7 @@ device_is_reefnet_sensus (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensus_cancel (reefnet_sensus_device_t *device)
|
||||
{
|
||||
// Send the command to the device.
|
||||
@ -85,21 +85,21 @@ reefnet_sensus_cancel (reefnet_sensus_device_t *device)
|
||||
// The device leaves the waiting state.
|
||||
device->waiting = 0;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensus_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
reefnet_sensus_device_t *device = (reefnet_sensus_device_t *) malloc (sizeof (reefnet_sensus_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -118,7 +118,7 @@ reefnet_sensus_device_open (device_t **out, const char* name)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (19200 8N1).
|
||||
@ -127,7 +127,7 @@ reefnet_sensus_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (3000 ms).
|
||||
@ -135,7 +135,7 @@ reefnet_sensus_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Make sure everything is in a sane state.
|
||||
@ -143,17 +143,17 @@ reefnet_sensus_device_open (device_t **out, const char* name)
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensus_device_close (device_t *abstract)
|
||||
{
|
||||
reefnet_sensus_device_t *device = (reefnet_sensus_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensus (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Safely close the connection if the last handshake was
|
||||
// successful, but no data transfer was ever initiated.
|
||||
@ -163,70 +163,70 @@ reefnet_sensus_device_close (device_t *abstract)
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensus_device_get_handshake (device_t *abstract, unsigned char data[], unsigned int size)
|
||||
{
|
||||
reefnet_sensus_device_t *device = (reefnet_sensus_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensus (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size < REEFNET_SENSUS_HANDSHAKE_SIZE) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
memcpy (data, device->handshake, REEFNET_SENSUS_HANDSHAKE_SIZE);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensus_device_set_timestamp (device_t *abstract, unsigned int timestamp)
|
||||
{
|
||||
reefnet_sensus_device_t *device = (reefnet_sensus_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensus (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
device->timestamp = timestamp;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensus_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
reefnet_sensus_device_t *device = (reefnet_sensus_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensus (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size && size != 4)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size)
|
||||
device->timestamp = array_uint32_le (data);
|
||||
else
|
||||
device->timestamp = 0;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensus_handshake (reefnet_sensus_device_t *device)
|
||||
{
|
||||
// Send the command to the device.
|
||||
@ -248,7 +248,7 @@ reefnet_sensus_handshake (reefnet_sensus_device_t *device)
|
||||
// Verify the header of the packet.
|
||||
if (handshake[0] != 'O' || handshake[1] != 'K') {
|
||||
WARNING ("Unexpected answer header.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// The device is now waiting for a data request.
|
||||
@ -279,23 +279,23 @@ reefnet_sensus_handshake (reefnet_sensus_device_t *device)
|
||||
|
||||
serial_sleep (10);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensus_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
reefnet_sensus_device_t *device = (reefnet_sensus_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensus (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Erase the current contents of the buffer and
|
||||
// pre-allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, REEFNET_SENSUS_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Enable progress notifications.
|
||||
@ -304,8 +304,8 @@ reefnet_sensus_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress);
|
||||
|
||||
// Wake-up the device.
|
||||
device_status_t rc = reefnet_sensus_handshake (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = reefnet_sensus_handshake (device);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Send the command to the device.
|
||||
@ -344,7 +344,7 @@ reefnet_sensus_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
if (memcmp (answer, "DATA", 4) != 0 ||
|
||||
memcmp (answer + sizeof (answer) - 3, "END", 3) != 0) {
|
||||
WARNING ("Unexpected answer start or end byte(s).");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Verify the checksum of the package.
|
||||
@ -352,27 +352,27 @@ reefnet_sensus_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
unsigned short ccrc = checksum_add_uint16 (answer + 4, REEFNET_SENSUS_MEMORY_SIZE, 0x00);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
dc_buffer_append (buffer, answer + 4, REEFNET_SENSUS_MEMORY_SIZE);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensus_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
if (! device_is_reefnet_sensus (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (REEFNET_SENSUS_MEMORY_SIZE);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
|
||||
device_status_t rc = reefnet_sensus_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = reefnet_sensus_device_dump (abstract, buffer);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
@ -386,13 +386,13 @@ reefnet_sensus_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensus_extract_dives (device_t *abstract, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
reefnet_sensus_device_t *device = (reefnet_sensus_device_t*) abstract;
|
||||
|
||||
if (abstract && !device_is_reefnet_sensus (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Search the entire data stream for start markers.
|
||||
unsigned int previous = size;
|
||||
@ -436,16 +436,16 @@ reefnet_sensus_extract_dives (device_t *abstract, const unsigned char data[], un
|
||||
// Report an error if no end of dive was found.
|
||||
if (!found) {
|
||||
WARNING ("No end of dive found.");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
// Automatically abort when a dive is older than the provided timestamp.
|
||||
unsigned int timestamp = array_uint32_le (data + current + 2);
|
||||
if (device && timestamp <= device->timestamp)
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
||||
if (callback && !callback (data + current, offset - current, data + current + 2, 4, userdata))
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
||||
// Prepare for the next dive.
|
||||
previous = current;
|
||||
@ -453,5 +453,5 @@ reefnet_sensus_extract_dives (device_t *abstract, const unsigned char data[], un
|
||||
}
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -46,11 +46,11 @@ struct reefnet_sensus_parser_t {
|
||||
unsigned int maxdepth;
|
||||
};
|
||||
|
||||
static parser_status_t reefnet_sensus_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static parser_status_t reefnet_sensus_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static parser_status_t reefnet_sensus_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static parser_status_t reefnet_sensus_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static parser_status_t reefnet_sensus_parser_destroy (parser_t *abstract);
|
||||
static dc_status_t reefnet_sensus_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static dc_status_t reefnet_sensus_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static dc_status_t reefnet_sensus_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static dc_status_t reefnet_sensus_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static dc_status_t reefnet_sensus_parser_destroy (parser_t *abstract);
|
||||
|
||||
static const parser_backend_t reefnet_sensus_parser_backend = {
|
||||
PARSER_TYPE_REEFNET_SENSUS,
|
||||
@ -72,17 +72,17 @@ parser_is_reefnet_sensus (parser_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
reefnet_sensus_parser_create (parser_t **out, unsigned int devtime, dc_ticks_t systime)
|
||||
{
|
||||
if (out == NULL)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
reefnet_sensus_parser_t *parser = (reefnet_sensus_parser_t *) malloc (sizeof (reefnet_sensus_parser_t));
|
||||
if (parser == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return PARSER_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -99,81 +99,81 @@ reefnet_sensus_parser_create (parser_t **out, unsigned int devtime, dc_ticks_t s
|
||||
|
||||
*out = (parser_t*) parser;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensus_parser_destroy (parser_t *abstract)
|
||||
{
|
||||
if (! parser_is_reefnet_sensus (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Free memory.
|
||||
free (abstract);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensus_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
reefnet_sensus_parser_t *parser = (reefnet_sensus_parser_t*) abstract;
|
||||
|
||||
if (! parser_is_reefnet_sensus (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Reset the cache.
|
||||
parser->cached = 0;
|
||||
parser->divetime = 0;
|
||||
parser->maxdepth = 0;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
reefnet_sensus_parser_set_calibration (parser_t *abstract, double atmospheric, double hydrostatic)
|
||||
{
|
||||
reefnet_sensus_parser_t *parser = (reefnet_sensus_parser_t*) abstract;
|
||||
|
||||
if (! parser_is_reefnet_sensus (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
parser->atmospheric = atmospheric;
|
||||
parser->hydrostatic = hydrostatic;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensus_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
{
|
||||
reefnet_sensus_parser_t *parser = (reefnet_sensus_parser_t *) abstract;
|
||||
|
||||
if (abstract->size < 2 + 4)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int timestamp = array_uint32_le (abstract->data + 2);
|
||||
|
||||
dc_ticks_t ticks = parser->systime - (parser->devtime - timestamp);
|
||||
|
||||
if (!dc_datetime_localtime (datetime, ticks))
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensus_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value)
|
||||
{
|
||||
reefnet_sensus_parser_t *parser = (reefnet_sensus_parser_t *) abstract;
|
||||
|
||||
if (abstract->size < 7)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
if (!parser->cached) {
|
||||
const unsigned char *data = abstract->data;
|
||||
@ -226,21 +226,21 @@ reefnet_sensus_parser_get_field (parser_t *abstract, parser_field_type_t type, u
|
||||
*((unsigned int *) value) = 0;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensus_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata)
|
||||
{
|
||||
reefnet_sensus_parser_t *parser = (reefnet_sensus_parser_t*) abstract;
|
||||
|
||||
if (! parser_is_reefnet_sensus (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
const unsigned char *data = abstract->data;
|
||||
unsigned int size = abstract->size;
|
||||
@ -270,7 +270,7 @@ reefnet_sensus_parser_samples_foreach (parser_t *abstract, sample_callback_t cal
|
||||
// Temperature (degrees Fahrenheit)
|
||||
if ((nsamples % 6) == 0) {
|
||||
if (offset + 1 > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
unsigned int temperature = data[offset++];
|
||||
sample.temperature = (temperature - 32.0) * (5.0 / 9.0);
|
||||
if (callback) callback (SAMPLE_TYPE_TEMPERATURE, sample, userdata);
|
||||
@ -296,5 +296,5 @@ reefnet_sensus_parser_samples_foreach (parser_t *abstract, sample_callback_t cal
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
typedef struct reefnet_sensuspro_device_t {
|
||||
@ -44,10 +44,10 @@ typedef struct reefnet_sensuspro_device_t {
|
||||
dc_ticks_t systime;
|
||||
} reefnet_sensuspro_device_t;
|
||||
|
||||
static device_status_t reefnet_sensuspro_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t reefnet_sensuspro_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t reefnet_sensuspro_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t reefnet_sensuspro_device_close (device_t *abstract);
|
||||
static dc_status_t reefnet_sensuspro_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static dc_status_t reefnet_sensuspro_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static dc_status_t reefnet_sensuspro_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static dc_status_t reefnet_sensuspro_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t reefnet_sensuspro_device_backend = {
|
||||
DEVICE_TYPE_REEFNET_SENSUSPRO,
|
||||
@ -70,17 +70,17 @@ device_is_reefnet_sensuspro (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensuspro_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t *) malloc (sizeof (reefnet_sensuspro_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -98,7 +98,7 @@ reefnet_sensuspro_device_open (device_t **out, const char* name)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (19200 8N1).
|
||||
@ -107,7 +107,7 @@ reefnet_sensuspro_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (3000ms).
|
||||
@ -115,7 +115,7 @@ reefnet_sensuspro_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Make sure everything is in a sane state.
|
||||
@ -123,85 +123,85 @@ reefnet_sensuspro_device_open (device_t **out, const char* name)
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensuspro_device_close (device_t *abstract)
|
||||
{
|
||||
reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensuspro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensuspro_device_get_handshake (device_t *abstract, unsigned char data[], unsigned int size)
|
||||
{
|
||||
reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensuspro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size < REEFNET_SENSUSPRO_HANDSHAKE_SIZE) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
memcpy (data, device->handshake, REEFNET_SENSUSPRO_HANDSHAKE_SIZE);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensuspro_device_set_timestamp (device_t *abstract, unsigned int timestamp)
|
||||
{
|
||||
reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensuspro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
device->timestamp = timestamp;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensuspro_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensuspro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size && size != 4)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size)
|
||||
device->timestamp = array_uint32_le (data);
|
||||
else
|
||||
device->timestamp = 0;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensuspro_handshake (reefnet_sensuspro_device_t *device)
|
||||
{
|
||||
// Assert a break condition.
|
||||
@ -223,7 +223,7 @@ reefnet_sensuspro_handshake (reefnet_sensuspro_device_t *device)
|
||||
unsigned short ccrc = checksum_crc_ccitt_uint16 (handshake, REEFNET_SENSUSPRO_HANDSHAKE_SIZE);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Store the clock calibration values.
|
||||
@ -248,16 +248,16 @@ reefnet_sensuspro_handshake (reefnet_sensuspro_device_t *device)
|
||||
|
||||
serial_sleep (10);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensuspro_send (reefnet_sensuspro_device_t *device, unsigned char command)
|
||||
{
|
||||
// Wake-up the device.
|
||||
device_status_t rc = reefnet_sensuspro_handshake (device);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = reefnet_sensuspro_handshake (device);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Send the instruction code to the device.
|
||||
@ -267,23 +267,23 @@ reefnet_sensuspro_send (reefnet_sensuspro_device_t *device, unsigned char comman
|
||||
return EXITCODE (n);
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensuspro_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensuspro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Erase the current contents of the buffer and
|
||||
// pre-allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, REEFNET_SENSUSPRO_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Enable progress notifications.
|
||||
@ -292,8 +292,8 @@ reefnet_sensuspro_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress);
|
||||
|
||||
// Wake-up the device and send the instruction code.
|
||||
device_status_t rc = reefnet_sensuspro_send (device, 0xB4);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = reefnet_sensuspro_send (device, 0xB4);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
unsigned int nbytes = 0;
|
||||
@ -320,27 +320,27 @@ reefnet_sensuspro_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
unsigned short ccrc = checksum_crc_ccitt_uint16 (answer, REEFNET_SENSUSPRO_MEMORY_SIZE);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
dc_buffer_append (buffer, answer, REEFNET_SENSUSPRO_MEMORY_SIZE);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensuspro_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
if (! device_is_reefnet_sensuspro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (REEFNET_SENSUSPRO_MEMORY_SIZE);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
|
||||
device_status_t rc = reefnet_sensuspro_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = reefnet_sensuspro_device_dump (abstract, buffer);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
@ -354,20 +354,20 @@ reefnet_sensuspro_device_foreach (device_t *abstract, dive_callback_t callback,
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensuspro_device_write_interval (device_t *abstract, unsigned char interval)
|
||||
{
|
||||
reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensuspro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (interval < 1 || interval > 127)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Wake-up the device and send the instruction code.
|
||||
device_status_t rc = reefnet_sensuspro_send (device, 0xB5);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = reefnet_sensuspro_send (device, 0xB5);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
serial_sleep (10);
|
||||
@ -378,17 +378,17 @@ reefnet_sensuspro_device_write_interval (device_t *abstract, unsigned char inter
|
||||
return EXITCODE (n);
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensuspro_extract_dives (device_t *abstract, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t*) abstract;
|
||||
|
||||
if (abstract && !device_is_reefnet_sensuspro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
const unsigned char header[4] = {0x00, 0x00, 0x00, 0x00};
|
||||
const unsigned char footer[2] = {0xFF, 0xFF};
|
||||
@ -415,15 +415,15 @@ reefnet_sensuspro_extract_dives (device_t *abstract, const unsigned char data[],
|
||||
|
||||
// Report an error if no stop marker was found.
|
||||
if (!found)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// Automatically abort when a dive is older than the provided timestamp.
|
||||
unsigned int timestamp = array_uint32_le (data + current + 6);
|
||||
if (device && timestamp <= device->timestamp)
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
||||
if (callback && !callback (data + current, offset + 2 - current, data + current + 6, 4, userdata))
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
||||
// Prepare for the next dive.
|
||||
previous = current;
|
||||
@ -431,5 +431,5 @@ reefnet_sensuspro_extract_dives (device_t *abstract, const unsigned char data[],
|
||||
}
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -45,11 +45,11 @@ struct reefnet_sensuspro_parser_t {
|
||||
unsigned int maxdepth;
|
||||
};
|
||||
|
||||
static parser_status_t reefnet_sensuspro_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static parser_status_t reefnet_sensuspro_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static parser_status_t reefnet_sensuspro_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static parser_status_t reefnet_sensuspro_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static parser_status_t reefnet_sensuspro_parser_destroy (parser_t *abstract);
|
||||
static dc_status_t reefnet_sensuspro_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static dc_status_t reefnet_sensuspro_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static dc_status_t reefnet_sensuspro_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static dc_status_t reefnet_sensuspro_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static dc_status_t reefnet_sensuspro_parser_destroy (parser_t *abstract);
|
||||
|
||||
static const parser_backend_t reefnet_sensuspro_parser_backend = {
|
||||
PARSER_TYPE_REEFNET_SENSUSPRO,
|
||||
@ -71,17 +71,17 @@ parser_is_reefnet_sensuspro (parser_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
reefnet_sensuspro_parser_create (parser_t **out, unsigned int devtime, dc_ticks_t systime)
|
||||
{
|
||||
if (out == NULL)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
reefnet_sensuspro_parser_t *parser = (reefnet_sensuspro_parser_t *) malloc (sizeof (reefnet_sensuspro_parser_t));
|
||||
if (parser == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return PARSER_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -98,81 +98,81 @@ reefnet_sensuspro_parser_create (parser_t **out, unsigned int devtime, dc_ticks_
|
||||
|
||||
*out = (parser_t*) parser;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensuspro_parser_destroy (parser_t *abstract)
|
||||
{
|
||||
if (! parser_is_reefnet_sensuspro (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Free memory.
|
||||
free (abstract);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensuspro_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
reefnet_sensuspro_parser_t *parser = (reefnet_sensuspro_parser_t*) abstract;
|
||||
|
||||
if (! parser_is_reefnet_sensuspro (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Reset the cache.
|
||||
parser->cached = 0;
|
||||
parser->divetime = 0;
|
||||
parser->maxdepth = 0;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
reefnet_sensuspro_parser_set_calibration (parser_t *abstract, double atmospheric, double hydrostatic)
|
||||
{
|
||||
reefnet_sensuspro_parser_t *parser = (reefnet_sensuspro_parser_t*) abstract;
|
||||
|
||||
if (! parser_is_reefnet_sensuspro (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
parser->atmospheric = atmospheric;
|
||||
parser->hydrostatic = hydrostatic;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensuspro_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
{
|
||||
reefnet_sensuspro_parser_t *parser = (reefnet_sensuspro_parser_t *) abstract;
|
||||
|
||||
if (abstract->size < 6 + 4)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int timestamp = array_uint32_le (abstract->data + 6);
|
||||
|
||||
dc_ticks_t ticks = parser->systime - (parser->devtime - timestamp);
|
||||
|
||||
if (!dc_datetime_localtime (datetime, ticks))
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensuspro_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value)
|
||||
{
|
||||
reefnet_sensuspro_parser_t *parser = (reefnet_sensuspro_parser_t *) abstract;
|
||||
|
||||
if (abstract->size < 12)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
if (!parser->cached) {
|
||||
const unsigned char footer[2] = {0xFF, 0xFF};
|
||||
@ -215,21 +215,21 @@ reefnet_sensuspro_parser_get_field (parser_t *abstract, parser_field_type_t type
|
||||
*((unsigned int *) value) = 0;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensuspro_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata)
|
||||
{
|
||||
reefnet_sensuspro_parser_t *parser = (reefnet_sensuspro_parser_t*) abstract;
|
||||
|
||||
if (! parser_is_reefnet_sensuspro (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
const unsigned char header[4] = {0x00, 0x00, 0x00, 0x00};
|
||||
const unsigned char footer[2] = {0xFF, 0xFF};
|
||||
@ -241,7 +241,7 @@ reefnet_sensuspro_parser_samples_foreach (parser_t *abstract, sample_callback_t
|
||||
while (offset + sizeof (header) <= size) {
|
||||
if (memcmp (data + offset, header, sizeof (header)) == 0) {
|
||||
if (offset + 10 > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int time = 0;
|
||||
unsigned int interval = array_uint16_le (data + offset + 4);
|
||||
@ -277,5 +277,5 @@ reefnet_sensuspro_parser_samples_foreach (parser_t *abstract, sample_callback_t
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
#define PROMPT 0xA5
|
||||
@ -50,10 +50,10 @@ typedef struct reefnet_sensusultra_device_t {
|
||||
dc_ticks_t systime;
|
||||
} reefnet_sensusultra_device_t;
|
||||
|
||||
static device_status_t reefnet_sensusultra_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t reefnet_sensusultra_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t reefnet_sensusultra_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t reefnet_sensusultra_device_close (device_t *abstract);
|
||||
static dc_status_t reefnet_sensusultra_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static dc_status_t reefnet_sensusultra_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static dc_status_t reefnet_sensusultra_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static dc_status_t reefnet_sensusultra_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t reefnet_sensusultra_device_backend = {
|
||||
DEVICE_TYPE_REEFNET_SENSUSULTRA,
|
||||
@ -76,17 +76,17 @@ device_is_reefnet_sensusultra (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t *) malloc (sizeof (reefnet_sensusultra_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -105,7 +105,7 @@ reefnet_sensusultra_device_open (device_t **out, const char* name)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (115200 8N1).
|
||||
@ -114,7 +114,7 @@ reefnet_sensusultra_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (3000ms).
|
||||
@ -122,7 +122,7 @@ reefnet_sensusultra_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Make sure everything is in a sane state.
|
||||
@ -130,99 +130,99 @@ reefnet_sensusultra_device_open (device_t **out, const char* name)
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensusultra_device_close (device_t *abstract)
|
||||
{
|
||||
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensusultra (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_device_get_handshake (device_t *abstract, unsigned char data[], unsigned int size)
|
||||
{
|
||||
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensusultra (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size < REEFNET_SENSUSULTRA_HANDSHAKE_SIZE) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
memcpy (data, device->handshake, REEFNET_SENSUSULTRA_HANDSHAKE_SIZE);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_device_set_maxretries (device_t *abstract, unsigned int maxretries)
|
||||
{
|
||||
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensusultra (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
device->maxretries = maxretries;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_device_set_timestamp (device_t *abstract, unsigned int timestamp)
|
||||
{
|
||||
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensusultra (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
device->timestamp = timestamp;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensusultra_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensusultra (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size && size != 4)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size)
|
||||
device->timestamp = array_uint32_le (data);
|
||||
else
|
||||
device->timestamp = 0;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensusultra_send_uchar (reefnet_sensusultra_device_t *device, unsigned char value)
|
||||
{
|
||||
// Wait for the prompt byte.
|
||||
@ -236,7 +236,7 @@ reefnet_sensusultra_send_uchar (reefnet_sensusultra_device_t *device, unsigned c
|
||||
// Verify the prompt byte.
|
||||
if (prompt != PROMPT) {
|
||||
WARNING ("Unexpected answer data.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Send the value to the device.
|
||||
@ -246,30 +246,30 @@ reefnet_sensusultra_send_uchar (reefnet_sensusultra_device_t *device, unsigned c
|
||||
return EXITCODE (rc);
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensusultra_send_ushort (reefnet_sensusultra_device_t *device, unsigned short value)
|
||||
{
|
||||
// Send the least-significant byte.
|
||||
unsigned char lsb = value & 0xFF;
|
||||
device_status_t rc = reefnet_sensusultra_send_uchar (device, lsb);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = reefnet_sensusultra_send_uchar (device, lsb);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Send the most-significant byte.
|
||||
unsigned char msb = (value >> 8) & 0xFF;
|
||||
rc = reefnet_sensusultra_send_uchar (device, msb);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensusultra_packet (reefnet_sensusultra_device_t *device, unsigned char *data, unsigned int size, unsigned int header)
|
||||
{
|
||||
assert (size >= header + 2);
|
||||
@ -277,7 +277,7 @@ reefnet_sensusultra_packet (reefnet_sensusultra_device_t *device, unsigned char
|
||||
device_t *abstract = (device_t *) device;
|
||||
|
||||
if (device_is_cancelled (abstract))
|
||||
return DEVICE_STATUS_CANCELLED;
|
||||
return DC_STATUS_CANCELLED;
|
||||
|
||||
// Receive the data packet.
|
||||
int rc = serial_read (device->port, data, size);
|
||||
@ -291,20 +291,20 @@ reefnet_sensusultra_packet (reefnet_sensusultra_device_t *device, unsigned char
|
||||
unsigned short ccrc = checksum_crc_ccitt_uint16 (data + header, size - header - 2);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensusultra_handshake (reefnet_sensusultra_device_t *device, unsigned short value)
|
||||
{
|
||||
// Wake-up the device.
|
||||
unsigned char handshake[REEFNET_SENSUSULTRA_HANDSHAKE_SIZE + 2] = {0};
|
||||
device_status_t rc = reefnet_sensusultra_packet (device, handshake, sizeof (handshake), 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = reefnet_sensusultra_packet (device, handshake, sizeof (handshake), 0);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Store the clock calibration values.
|
||||
@ -329,24 +329,24 @@ reefnet_sensusultra_handshake (reefnet_sensusultra_device_t *device, unsigned sh
|
||||
|
||||
// Send the instruction code to the device.
|
||||
rc = reefnet_sensusultra_send_ushort (device, value);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensusultra_page (reefnet_sensusultra_device_t *device, unsigned char *data, unsigned int size, unsigned int pagenum)
|
||||
{
|
||||
assert (size >= REEFNET_SENSUSULTRA_PACKET_SIZE + 4);
|
||||
|
||||
unsigned int nretries = 0;
|
||||
device_status_t rc = DEVICE_STATUS_SUCCESS;
|
||||
while ((rc = reefnet_sensusultra_packet (device, data, size, 2)) != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = DC_STATUS_SUCCESS;
|
||||
while ((rc = reefnet_sensusultra_packet (device, data, size, 2)) != DC_STATUS_SUCCESS) {
|
||||
// Automatically discard a corrupted packet,
|
||||
// and request a new one.
|
||||
if (rc != DEVICE_STATUS_PROTOCOL)
|
||||
if (rc != DC_STATUS_PROTOCOL)
|
||||
return rc;
|
||||
|
||||
// Abort if the maximum number of retries is reached.
|
||||
@ -355,7 +355,7 @@ reefnet_sensusultra_page (reefnet_sensusultra_device_t *device, unsigned char *d
|
||||
|
||||
// Reject the packet.
|
||||
rc = reefnet_sensusultra_send_uchar (device, REJECT);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -363,14 +363,14 @@ reefnet_sensusultra_page (reefnet_sensusultra_device_t *device, unsigned char *d
|
||||
unsigned int page = array_uint16_le (data);
|
||||
if (page != pagenum) {
|
||||
WARNING ("Unexpected page number.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensusultra_send (reefnet_sensusultra_device_t *device, unsigned short command)
|
||||
{
|
||||
// Flush the input and output buffers.
|
||||
@ -378,11 +378,11 @@ reefnet_sensusultra_send (reefnet_sensusultra_device_t *device, unsigned short c
|
||||
|
||||
// Wake-up the device and send the instruction code.
|
||||
unsigned int nretries = 0;
|
||||
device_status_t rc = DEVICE_STATUS_SUCCESS;
|
||||
while ((rc = reefnet_sensusultra_handshake (device, command)) != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = DC_STATUS_SUCCESS;
|
||||
while ((rc = reefnet_sensusultra_handshake (device, command)) != DC_STATUS_SUCCESS) {
|
||||
// Automatically discard a corrupted handshake packet,
|
||||
// and wait for the next one.
|
||||
if (rc != DEVICE_STATUS_PROTOCOL && rc != DEVICE_STATUS_TIMEOUT)
|
||||
if (rc != DC_STATUS_PROTOCOL && rc != DC_STATUS_TIMEOUT)
|
||||
return rc;
|
||||
|
||||
// Abort if the maximum number of retries is reached.
|
||||
@ -398,23 +398,23 @@ reefnet_sensusultra_send (reefnet_sensusultra_device_t *device, unsigned short c
|
||||
serial_flush (device->port, SERIAL_QUEUE_BOTH);
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensusultra_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensusultra (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Erase the current contents of the buffer and
|
||||
// pre-allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, REEFNET_SENSUSULTRA_MEMORY_DATA_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Enable progress notifications.
|
||||
@ -423,8 +423,8 @@ reefnet_sensusultra_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress);
|
||||
|
||||
// Wake-up the device and send the instruction code.
|
||||
device_status_t rc = reefnet_sensusultra_send (device, 0xB421);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = reefnet_sensusultra_send (device, 0xB421);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
unsigned int nbytes = 0;
|
||||
@ -433,7 +433,7 @@ reefnet_sensusultra_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
// Receive the packet.
|
||||
unsigned char packet[REEFNET_SENSUSULTRA_PACKET_SIZE + 4] = {0};
|
||||
rc = reefnet_sensusultra_page (device, packet, sizeof (packet), npages);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Update and emit a progress event.
|
||||
@ -443,38 +443,38 @@ reefnet_sensusultra_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
// Prepend the packet to the buffer.
|
||||
if (!dc_buffer_prepend (buffer, packet + 2, REEFNET_SENSUSULTRA_PACKET_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Accept the packet.
|
||||
rc = reefnet_sensusultra_send_uchar (device, ACCEPT);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
nbytes += REEFNET_SENSUSULTRA_PACKET_SIZE;
|
||||
npages++;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_device_read_user (device_t *abstract, unsigned char *data, unsigned int size)
|
||||
{
|
||||
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensusultra (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size < REEFNET_SENSUSULTRA_MEMORY_USER_SIZE) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
// Wake-up the device and send the instruction code.
|
||||
device_status_t rc = reefnet_sensusultra_send (device, 0xB420);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = reefnet_sensusultra_send (device, 0xB420);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
unsigned int nbytes = 0;
|
||||
@ -483,7 +483,7 @@ reefnet_sensusultra_device_read_user (device_t *abstract, unsigned char *data, u
|
||||
// Receive the packet.
|
||||
unsigned char packet[REEFNET_SENSUSULTRA_PACKET_SIZE + 4] = {0};
|
||||
rc = reefnet_sensusultra_page (device, packet, sizeof (packet), npages);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Append the packet to the buffer.
|
||||
@ -491,28 +491,28 @@ reefnet_sensusultra_device_read_user (device_t *abstract, unsigned char *data, u
|
||||
|
||||
// Accept the packet.
|
||||
rc = reefnet_sensusultra_send_uchar (device, ACCEPT);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
nbytes += REEFNET_SENSUSULTRA_PACKET_SIZE;
|
||||
npages++;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_device_write_user (device_t *abstract, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensusultra (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size < REEFNET_SENSUSULTRA_MEMORY_USER_SIZE) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
// Enable progress notifications.
|
||||
@ -521,14 +521,14 @@ reefnet_sensusultra_device_write_user (device_t *abstract, const unsigned char *
|
||||
device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress);
|
||||
|
||||
// Wake-up the device and send the instruction code.
|
||||
device_status_t rc = reefnet_sensusultra_send (device, 0xB430);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = reefnet_sensusultra_send (device, 0xB430);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Send the data to the device.
|
||||
for (unsigned int i = 0; i < REEFNET_SENSUSULTRA_MEMORY_USER_SIZE; ++i) {
|
||||
rc = reefnet_sensusultra_send_uchar (device, data[i]);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Update and emit a progress event.
|
||||
@ -539,24 +539,24 @@ reefnet_sensusultra_device_write_user (device_t *abstract, const unsigned char *
|
||||
// Send the checksum to the device.
|
||||
unsigned short crc = checksum_crc_ccitt_uint16 (data, REEFNET_SENSUSULTRA_MEMORY_USER_SIZE);
|
||||
rc = reefnet_sensusultra_send_ushort (device, crc);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Update and emit a progress event.
|
||||
progress.current += 2;
|
||||
device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_device_write_parameter (device_t *abstract, reefnet_sensusultra_parameter_t parameter, unsigned int value)
|
||||
{
|
||||
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensusultra (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Set the instruction code and validate the new value.
|
||||
unsigned short code = 0;
|
||||
@ -564,72 +564,72 @@ reefnet_sensusultra_device_write_parameter (device_t *abstract, reefnet_sensusul
|
||||
case REEFNET_SENSUSULTRA_PARAMETER_INTERVAL:
|
||||
code = 0xB410;
|
||||
if (value < 1 || value > 65535)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
break;
|
||||
case REEFNET_SENSUSULTRA_PARAMETER_THRESHOLD:
|
||||
code = 0xB411;
|
||||
if (value < 1 || value > 65535)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
break;
|
||||
case REEFNET_SENSUSULTRA_PARAMETER_ENDCOUNT:
|
||||
code = 0xB412;
|
||||
if (value < 1 || value > 65535)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
break;
|
||||
case REEFNET_SENSUSULTRA_PARAMETER_AVERAGING:
|
||||
code = 0xB413;
|
||||
if (value != 1 && value != 2 && value != 4)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
break;
|
||||
default:
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
// Wake-up the device and send the instruction code.
|
||||
device_status_t rc = reefnet_sensusultra_send (device, code);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = reefnet_sensusultra_send (device, code);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Send the new value to the device.
|
||||
rc = reefnet_sensusultra_send_ushort (device, value);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_device_sense (device_t *abstract, unsigned char *data, unsigned int size)
|
||||
{
|
||||
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensusultra (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size < REEFNET_SENSUSULTRA_SENSE_SIZE) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
// Wake-up the device and send the instruction code.
|
||||
device_status_t rc = reefnet_sensusultra_send (device, 0xB440);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = reefnet_sensusultra_send (device, 0xB440);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Receive the packet.
|
||||
unsigned char package[REEFNET_SENSUSULTRA_SENSE_SIZE + 2] = {0};
|
||||
rc = reefnet_sensusultra_packet (device, package, sizeof (package), 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
memcpy (data, package, REEFNET_SENSUSULTRA_SENSE_SIZE);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensusultra_parse (reefnet_sensusultra_device_t *device,
|
||||
const unsigned char data[], unsigned int *premaining, unsigned int *pprevious,
|
||||
int *aborted, dive_callback_t callback, void *userdata)
|
||||
@ -670,13 +670,13 @@ reefnet_sensusultra_parse (reefnet_sensusultra_device_t *device,
|
||||
if (device && timestamp <= device->timestamp) {
|
||||
if (aborted)
|
||||
*aborted = 1;
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (callback && !callback (current, previous - current, current + 4, 4, userdata)) {
|
||||
if (aborted)
|
||||
*aborted = 1;
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -695,22 +695,22 @@ reefnet_sensusultra_parse (reefnet_sensusultra_device_t *device,
|
||||
if (aborted)
|
||||
*aborted = 0;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensusultra_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
|
||||
|
||||
if (! device_is_reefnet_sensusultra (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (REEFNET_SENSUSULTRA_MEMORY_DATA_SIZE);
|
||||
if (buffer == NULL) {
|
||||
WARNING ("Memory allocation error.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Enable progress notifications.
|
||||
@ -719,8 +719,8 @@ reefnet_sensusultra_device_foreach (device_t *abstract, dive_callback_t callback
|
||||
device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress);
|
||||
|
||||
// Wake-up the device and send the instruction code.
|
||||
device_status_t rc = reefnet_sensusultra_send (device, 0xB421);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = reefnet_sensusultra_send (device, 0xB421);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
@ -735,7 +735,7 @@ reefnet_sensusultra_device_foreach (device_t *abstract, dive_callback_t callback
|
||||
// Receive the packet.
|
||||
unsigned char packet[REEFNET_SENSUSULTRA_PACKET_SIZE + 4] = {0};
|
||||
rc = reefnet_sensusultra_page (device, packet, sizeof (packet), npages);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
@ -751,7 +751,7 @@ reefnet_sensusultra_device_foreach (device_t *abstract, dive_callback_t callback
|
||||
// Prepend the packet to the buffer.
|
||||
if (!dc_buffer_prepend (buffer, packet + 2, REEFNET_SENSUSULTRA_PACKET_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Update the parser state.
|
||||
@ -762,7 +762,7 @@ reefnet_sensusultra_device_foreach (device_t *abstract, dive_callback_t callback
|
||||
int aborted = 0;
|
||||
rc = reefnet_sensusultra_parse (device, dc_buffer_get_data (buffer),
|
||||
&remaining, &previous, &aborted, callback, userdata);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
@ -771,7 +771,7 @@ reefnet_sensusultra_device_foreach (device_t *abstract, dive_callback_t callback
|
||||
|
||||
// Accept the packet.
|
||||
rc = reefnet_sensusultra_send_uchar (device, ACCEPT);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
@ -782,17 +782,17 @@ reefnet_sensusultra_device_foreach (device_t *abstract, dive_callback_t callback
|
||||
|
||||
dc_buffer_free (buffer);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_extract_dives (device_t *abstract, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t *) abstract;
|
||||
|
||||
if (abstract && !device_is_reefnet_sensusultra (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
unsigned int remaining = size;
|
||||
unsigned int previous = size;
|
||||
|
||||
@ -45,11 +45,11 @@ struct reefnet_sensusultra_parser_t {
|
||||
unsigned int maxdepth;
|
||||
};
|
||||
|
||||
static parser_status_t reefnet_sensusultra_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static parser_status_t reefnet_sensusultra_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static parser_status_t reefnet_sensusultra_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static parser_status_t reefnet_sensusultra_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static parser_status_t reefnet_sensusultra_parser_destroy (parser_t *abstract);
|
||||
static dc_status_t reefnet_sensusultra_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static dc_status_t reefnet_sensusultra_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static dc_status_t reefnet_sensusultra_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static dc_status_t reefnet_sensusultra_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static dc_status_t reefnet_sensusultra_parser_destroy (parser_t *abstract);
|
||||
|
||||
static const parser_backend_t reefnet_sensusultra_parser_backend = {
|
||||
PARSER_TYPE_REEFNET_SENSUSULTRA,
|
||||
@ -71,17 +71,17 @@ parser_is_reefnet_sensusultra (parser_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_parser_create (parser_t **out, unsigned int devtime, dc_ticks_t systime)
|
||||
{
|
||||
if (out == NULL)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
reefnet_sensusultra_parser_t *parser = (reefnet_sensusultra_parser_t *) malloc (sizeof (reefnet_sensusultra_parser_t));
|
||||
if (parser == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return PARSER_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -98,81 +98,81 @@ reefnet_sensusultra_parser_create (parser_t **out, unsigned int devtime, dc_tick
|
||||
|
||||
*out = (parser_t*) parser;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensusultra_parser_destroy (parser_t *abstract)
|
||||
{
|
||||
if (! parser_is_reefnet_sensusultra (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Free memory.
|
||||
free (abstract);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensusultra_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
reefnet_sensusultra_parser_t *parser = (reefnet_sensusultra_parser_t*) abstract;
|
||||
|
||||
if (! parser_is_reefnet_sensusultra (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Reset the cache.
|
||||
parser->cached = 0;
|
||||
parser->divetime = 0;
|
||||
parser->maxdepth = 0;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
reefnet_sensusultra_parser_set_calibration (parser_t *abstract, double atmospheric, double hydrostatic)
|
||||
{
|
||||
reefnet_sensusultra_parser_t *parser = (reefnet_sensusultra_parser_t*) abstract;
|
||||
|
||||
if (! parser_is_reefnet_sensusultra (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
parser->atmospheric = atmospheric;
|
||||
parser->hydrostatic = hydrostatic;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensusultra_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
{
|
||||
reefnet_sensusultra_parser_t *parser = (reefnet_sensusultra_parser_t *) abstract;
|
||||
|
||||
if (abstract->size < 4 + 4)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int timestamp = array_uint32_le (abstract->data + 4);
|
||||
|
||||
dc_ticks_t ticks = parser->systime - (parser->devtime - timestamp);
|
||||
|
||||
if (!dc_datetime_localtime (datetime, ticks))
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensusultra_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value)
|
||||
{
|
||||
reefnet_sensusultra_parser_t *parser = (reefnet_sensusultra_parser_t *) abstract;
|
||||
|
||||
if (abstract->size < 20)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
if (!parser->cached) {
|
||||
const unsigned char footer[4] = {0xFF, 0xFF, 0xFF, 0xFF};
|
||||
@ -216,21 +216,21 @@ reefnet_sensusultra_parser_get_field (parser_t *abstract, parser_field_type_t ty
|
||||
*((unsigned int *) value) = 0;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
reefnet_sensusultra_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata)
|
||||
{
|
||||
reefnet_sensusultra_parser_t *parser = (reefnet_sensusultra_parser_t*) abstract;
|
||||
|
||||
if (! parser_is_reefnet_sensusultra (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
const unsigned char header[4] = {0x00, 0x00, 0x00, 0x00};
|
||||
const unsigned char footer[4] = {0xFF, 0xFF, 0xFF, 0xFF};
|
||||
@ -242,7 +242,7 @@ reefnet_sensusultra_parser_samples_foreach (parser_t *abstract, sample_callback_
|
||||
while (offset + sizeof (header) <= size) {
|
||||
if (memcmp (data + offset, header, sizeof (header)) == 0) {
|
||||
if (offset + 16 > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int time = 0;
|
||||
unsigned int interval = array_uint16_le (data + offset + 8);
|
||||
@ -276,5 +276,5 @@ reefnet_sensusultra_parser_samples_foreach (parser_t *abstract, sample_callback_
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ suunto_common_device_init (suunto_common_device_t *device, const device_backend_
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
suunto_common_device_t *device = (suunto_common_device_t *) abstract;
|
||||
@ -51,18 +51,18 @@ suunto_common_device_set_fingerprint (device_t *abstract, const unsigned char da
|
||||
assert (device != NULL);
|
||||
|
||||
if (size && size != sizeof (device->fingerprint))
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size)
|
||||
memcpy (device->fingerprint, data, sizeof (device->fingerprint));
|
||||
else
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common_extract_dives (suunto_common_device_t *device, const suunto_common_layout_t *layout, const unsigned char data[], dive_callback_t callback, void *userdata)
|
||||
{
|
||||
assert (layout != NULL);
|
||||
@ -87,14 +87,14 @@ suunto_common_extract_dives (suunto_common_device_t *device, const suunto_common
|
||||
eop >= layout->rb_profile_end ||
|
||||
data[eop] != 0x82)
|
||||
{
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
// Memory buffer for the profile ringbuffer.
|
||||
unsigned int length = layout->rb_profile_end - layout->rb_profile_begin;
|
||||
unsigned char *buffer = (unsigned char *) malloc (length);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
|
||||
unsigned int current = eop;
|
||||
unsigned int previous = eop;
|
||||
@ -124,12 +124,12 @@ suunto_common_extract_dives (suunto_common_device_t *device, const suunto_common
|
||||
|
||||
if (device && memcmp (buffer + layout->fp_offset, device->fingerprint, sizeof (device->fingerprint)) == 0) {
|
||||
free (buffer);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (callback && !callback (buffer, len, buffer + layout->fp_offset, sizeof (device->fingerprint), userdata)) {
|
||||
free (buffer);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
previous = current;
|
||||
@ -139,7 +139,7 @@ suunto_common_extract_dives (suunto_common_device_t *device, const suunto_common
|
||||
free (buffer);
|
||||
|
||||
if (data[current] != 0x82)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -48,10 +48,10 @@ typedef struct suunto_common_layout_t {
|
||||
void
|
||||
suunto_common_device_init (suunto_common_device_t *device, const device_backend_t *backend);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common_device_set_fingerprint (device_t *device, const unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common_extract_dives (suunto_common_device_t *device, const suunto_common_layout_t *layout, const unsigned char data[], dive_callback_t callback, void *userdata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -56,13 +56,13 @@ suunto_common2_device_init (suunto_common2_device_t *device, const suunto_common
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_common2_transfer (device_t *abstract, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size)
|
||||
{
|
||||
assert (asize >= size + 4);
|
||||
|
||||
if (BACKEND (abstract)->packet == NULL)
|
||||
return DEVICE_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
// Occasionally, the dive computer does not respond to a command.
|
||||
// In that case we retry the command a number of times before
|
||||
@ -70,11 +70,11 @@ suunto_common2_transfer (device_t *abstract, const unsigned char command[], unsi
|
||||
// again during one of the retries.
|
||||
|
||||
unsigned int nretries = 0;
|
||||
device_status_t rc = DEVICE_STATUS_SUCCESS;
|
||||
while ((rc = BACKEND (abstract)->packet (abstract, command, csize, answer, asize, size)) != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = DC_STATUS_SUCCESS;
|
||||
while ((rc = BACKEND (abstract)->packet (abstract, command, csize, answer, asize, size)) != DC_STATUS_SUCCESS) {
|
||||
// Automatically discard a corrupted packet,
|
||||
// and request a new one.
|
||||
if (rc != DEVICE_STATUS_TIMEOUT && rc != DEVICE_STATUS_PROTOCOL)
|
||||
if (rc != DC_STATUS_TIMEOUT && rc != DC_STATUS_PROTOCOL)
|
||||
return rc;
|
||||
|
||||
// Abort if the maximum number of retries is reached.
|
||||
@ -86,57 +86,57 @@ suunto_common2_transfer (device_t *abstract, const unsigned char command[], unsi
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common2_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
suunto_common2_device_t *device = (suunto_common2_device_t*) abstract;
|
||||
|
||||
if (size && size != sizeof (device->fingerprint))
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size)
|
||||
memcpy (device->fingerprint, data, sizeof (device->fingerprint));
|
||||
else
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common2_device_version (device_t *abstract, unsigned char data[], unsigned int size)
|
||||
{
|
||||
if (size < SZ_VERSION) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
unsigned char answer[SZ_VERSION + 4] = {0};
|
||||
unsigned char command[4] = {0x0F, 0x00, 0x00, 0x0F};
|
||||
device_status_t rc = suunto_common2_transfer (abstract, command, sizeof (command), answer, sizeof (answer), 4);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = suunto_common2_transfer (abstract, command, sizeof (command), answer, sizeof (answer), 4);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
memcpy (data, answer + 3, SZ_VERSION);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common2_device_reset_maxdepth (device_t *abstract)
|
||||
{
|
||||
unsigned char answer[4] = {0};
|
||||
unsigned char command[4] = {0x20, 0x00, 0x00, 0x20};
|
||||
device_status_t rc = suunto_common2_transfer (abstract, command, sizeof (command), answer, sizeof (answer), 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = suunto_common2_transfer (abstract, command, sizeof (command), answer, sizeof (answer), 0);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common2_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size)
|
||||
{
|
||||
// The data transmission is split in packages
|
||||
@ -157,8 +157,8 @@ suunto_common2_device_read (device_t *abstract, unsigned int address, unsigned c
|
||||
len, // count
|
||||
0}; // CRC
|
||||
command[6] = checksum_xor_uint8 (command, 6, 0x00);
|
||||
device_status_t rc = suunto_common2_transfer (abstract, command, sizeof (command), answer, len + 7, len);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = suunto_common2_transfer (abstract, command, sizeof (command), answer, len + 7, len);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
memcpy (data, answer + 6, len);
|
||||
@ -168,11 +168,11 @@ suunto_common2_device_read (device_t *abstract, unsigned int address, unsigned c
|
||||
data += len;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common2_device_write (device_t *abstract, unsigned int address, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
// The data transmission is split in packages
|
||||
@ -194,8 +194,8 @@ suunto_common2_device_write (device_t *abstract, unsigned int address, const uns
|
||||
0}; // data + CRC
|
||||
memcpy (command + 6, data, len);
|
||||
command[len + 6] = checksum_xor_uint8 (command, len + 6, 0x00);
|
||||
device_status_t rc = suunto_common2_transfer (abstract, command, len + 7, answer, sizeof (answer), 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = suunto_common2_transfer (abstract, command, len + 7, answer, sizeof (answer), 0);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
nbytes += len;
|
||||
@ -203,11 +203,11 @@ suunto_common2_device_write (device_t *abstract, unsigned int address, const uns
|
||||
data += len;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common2_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
suunto_common2_device_t *device = (suunto_common2_device_t *) abstract;
|
||||
@ -219,7 +219,7 @@ suunto_common2_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, device->layout->memsize)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
return device_dump_read (abstract, dc_buffer_get_data (buffer),
|
||||
@ -227,7 +227,7 @@ suunto_common2_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common2_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
suunto_common2_device_t *device = (suunto_common2_device_t*) abstract;
|
||||
@ -238,7 +238,7 @@ suunto_common2_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
const suunto_common2_layout_t *layout = device->layout;
|
||||
|
||||
// Error status for delayed errors.
|
||||
device_status_t status = DEVICE_STATUS_SUCCESS;
|
||||
dc_status_t status = DC_STATUS_SUCCESS;
|
||||
|
||||
// Enable progress notifications.
|
||||
device_progress_t progress = DEVICE_PROGRESS_INITIALIZER;
|
||||
@ -248,8 +248,8 @@ suunto_common2_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
|
||||
// Read the version info.
|
||||
unsigned char version[SZ_VERSION] = {0};
|
||||
device_status_t rc = suunto_common2_device_version (abstract, version, sizeof (version));
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = suunto_common2_device_version (abstract, version, sizeof (version));
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory header.");
|
||||
return rc;
|
||||
}
|
||||
@ -261,7 +261,7 @@ suunto_common2_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
// Read the serial number.
|
||||
unsigned char serial[SZ_MINIMUM > 4 ? SZ_MINIMUM : 4] = {0};
|
||||
rc = suunto_common2_device_read (abstract, layout->serial, serial, sizeof (serial));
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory header.");
|
||||
return rc;
|
||||
}
|
||||
@ -280,7 +280,7 @@ suunto_common2_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
// Read the header bytes.
|
||||
unsigned char header[8] = {0};
|
||||
rc = suunto_common2_device_read (abstract, 0x0190, header, sizeof (header));
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory header.");
|
||||
return rc;
|
||||
}
|
||||
@ -298,7 +298,7 @@ suunto_common2_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
begin >= layout->rb_profile_end)
|
||||
{
|
||||
WARNING("Invalid ringbuffer pointer detected!");
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
// Memory buffer to store all the dives.
|
||||
@ -306,7 +306,7 @@ suunto_common2_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
unsigned char *data = (unsigned char *) malloc (layout->rb_profile_end - layout->rb_profile_begin + SZ_MINIMUM);
|
||||
if (data == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Calculate the total amount of bytes.
|
||||
@ -341,7 +341,7 @@ suunto_common2_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
if (size < 4 || size > remaining) {
|
||||
WARNING ("Unexpected profile size.");
|
||||
free (data);
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
unsigned int nbytes = available;
|
||||
@ -375,7 +375,7 @@ suunto_common2_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
|
||||
// Read the package.
|
||||
rc = suunto_common2_device_read (abstract, address - extra, data + offset - extra, len + extra);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Cannot read memory.");
|
||||
free (data);
|
||||
return rc;
|
||||
@ -406,12 +406,12 @@ suunto_common2_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
{
|
||||
WARNING("Invalid ringbuffer pointer detected!");
|
||||
free (data);
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
if (next != previous && next != current) {
|
||||
WARNING ("Profiles are not continuous.");
|
||||
free (data);
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
if (next != current) {
|
||||
@ -421,16 +421,16 @@ suunto_common2_device_foreach (device_t *abstract, dive_callback_t callback, voi
|
||||
|
||||
if (memcmp (p + fp_offset, device->fingerprint, sizeof (device->fingerprint)) == 0) {
|
||||
free (data);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (callback && !callback (p + 4, size - 4, p + fp_offset, sizeof (device->fingerprint), userdata)) {
|
||||
free (data);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
WARNING ("Skipping incomplete dive.");
|
||||
status = DEVICE_STATUS_ERROR;
|
||||
status = DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
// Next dive.
|
||||
|
||||
@ -46,31 +46,31 @@ typedef struct suunto_common2_device_t {
|
||||
|
||||
typedef struct suunto_common2_device_backend_t {
|
||||
device_backend_t base;
|
||||
device_status_t (*packet) (device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size);
|
||||
dc_status_t (*packet) (device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size);
|
||||
} suunto_common2_device_backend_t;
|
||||
|
||||
void
|
||||
suunto_common2_device_init (suunto_common2_device_t *device, const suunto_common2_device_backend_t *backend);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common2_device_set_fingerprint (device_t *device, const unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common2_device_version (device_t *device, unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common2_device_read (device_t *device, unsigned int address, unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common2_device_write (device_t *device, unsigned int address, const unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common2_device_dump (device_t *device, dc_buffer_t *buffer);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common2_device_foreach (device_t *device, dive_callback_t callback, void *userdata);
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_common2_device_reset_maxdepth (device_t *device);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
#define C_ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
|
||||
@ -48,8 +48,8 @@ typedef struct suunto_d9_device_t {
|
||||
unsigned char version[4];
|
||||
} suunto_d9_device_t;
|
||||
|
||||
static device_status_t suunto_d9_device_packet (device_t *abstract, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size);
|
||||
static device_status_t suunto_d9_device_close (device_t *abstract);
|
||||
static dc_status_t suunto_d9_device_packet (device_t *abstract, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size);
|
||||
static dc_status_t suunto_d9_device_close (device_t *abstract);
|
||||
|
||||
static const suunto_common2_device_backend_t suunto_d9_device_backend = {
|
||||
{
|
||||
@ -89,10 +89,10 @@ device_is_suunto_d9 (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_d9_device_autodetect (suunto_d9_device_t *device, unsigned int model)
|
||||
{
|
||||
device_status_t status = DEVICE_STATUS_SUCCESS;
|
||||
dc_status_t status = DC_STATUS_SUCCESS;
|
||||
|
||||
// The list with possible baudrates.
|
||||
const int baudrates[] = {9600, 115200};
|
||||
@ -110,12 +110,12 @@ suunto_d9_device_autodetect (suunto_d9_device_t *device, unsigned int model)
|
||||
int rc = serial_configure (device->port, baudrates[idx], 8, SERIAL_PARITY_NONE, 1, SERIAL_FLOWCONTROL_NONE);
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Try reading the version info.
|
||||
status = suunto_common2_device_version ((device_t *) device, device->version, sizeof (device->version));
|
||||
if (status == DEVICE_STATUS_SUCCESS)
|
||||
if (status == DC_STATUS_SUCCESS)
|
||||
break;
|
||||
}
|
||||
|
||||
@ -123,17 +123,17 @@ suunto_d9_device_autodetect (suunto_d9_device_t *device, unsigned int model)
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_d9_device_open (device_t **out, const char* name, unsigned int model)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
suunto_d9_device_t *device = (suunto_d9_device_t *) malloc (sizeof (suunto_d9_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -148,7 +148,7 @@ suunto_d9_device_open (device_t **out, const char* name, unsigned int model)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (9600 8N1).
|
||||
@ -157,7 +157,7 @@ suunto_d9_device_open (device_t **out, const char* name, unsigned int model)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (3000 ms).
|
||||
@ -165,7 +165,7 @@ suunto_d9_device_open (device_t **out, const char* name, unsigned int model)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the DTR line (power supply for the interface).
|
||||
@ -173,7 +173,7 @@ suunto_d9_device_open (device_t **out, const char* name, unsigned int model)
|
||||
WARNING ("Failed to set the DTR line.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Give the interface 100 ms to settle and draw power up.
|
||||
@ -183,8 +183,8 @@ suunto_d9_device_open (device_t **out, const char* name, unsigned int model)
|
||||
serial_flush (device->port, SERIAL_QUEUE_BOTH);
|
||||
|
||||
// Try to autodetect the protocol variant.
|
||||
device_status_t status = suunto_d9_device_autodetect (device, model);
|
||||
if (status != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t status = suunto_d9_device_autodetect (device, model);
|
||||
if (status != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Failed to identify the protocol variant.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
@ -200,38 +200,38 @@ suunto_d9_device_open (device_t **out, const char* name, unsigned int model)
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_d9_device_close (device_t *abstract)
|
||||
{
|
||||
suunto_d9_device_t *device = (suunto_d9_device_t*) abstract;
|
||||
|
||||
if (! device_is_suunto_d9 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_d9_device_packet (device_t *abstract, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size)
|
||||
{
|
||||
suunto_d9_device_t *device = (suunto_d9_device_t *) abstract;
|
||||
|
||||
if (device_is_cancelled (abstract))
|
||||
return DEVICE_STATUS_CANCELLED;
|
||||
return DC_STATUS_CANCELLED;
|
||||
|
||||
// Clear RTS to send the command.
|
||||
serial_set_rts (device->port, 0);
|
||||
@ -255,7 +255,7 @@ suunto_d9_device_packet (device_t *abstract, const unsigned char command[], unsi
|
||||
// Verify the echo.
|
||||
if (memcmp (command, echo, csize) != 0) {
|
||||
WARNING ("Unexpected echo.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Set RTS to receive the reply.
|
||||
@ -271,19 +271,19 @@ suunto_d9_device_packet (device_t *abstract, const unsigned char command[], unsi
|
||||
// Verify the header of the package.
|
||||
if (answer[0] != command[0]) {
|
||||
WARNING ("Unexpected answer header.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Verify the size of the package.
|
||||
if (array_uint16_be (answer + 1) + 4 != asize) {
|
||||
WARNING ("Unexpected answer size.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Verify the parameters of the package.
|
||||
if (memcmp (command + 3, answer + 3, asize - size - 4) != 0) {
|
||||
WARNING ("Unexpected answer parameters.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Verify the checksum of the package.
|
||||
@ -291,18 +291,18 @@ suunto_d9_device_packet (device_t *abstract, const unsigned char command[], unsi
|
||||
unsigned char ccrc = checksum_xor_uint8 (answer, asize - 1, 0x00);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_d9_device_reset_maxdepth (device_t *abstract)
|
||||
{
|
||||
if (! device_is_suunto_d9 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
return suunto_common2_device_reset_maxdepth (abstract);
|
||||
}
|
||||
|
||||
@ -57,11 +57,11 @@ typedef struct sample_info_t {
|
||||
unsigned int divisor;
|
||||
} sample_info_t;
|
||||
|
||||
static parser_status_t suunto_d9_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static parser_status_t suunto_d9_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static parser_status_t suunto_d9_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static parser_status_t suunto_d9_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static parser_status_t suunto_d9_parser_destroy (parser_t *abstract);
|
||||
static dc_status_t suunto_d9_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static dc_status_t suunto_d9_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static dc_status_t suunto_d9_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static dc_status_t suunto_d9_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static dc_status_t suunto_d9_parser_destroy (parser_t *abstract);
|
||||
|
||||
static const parser_backend_t suunto_d9_parser_backend = {
|
||||
PARSER_TYPE_SUUNTO_D9,
|
||||
@ -83,17 +83,17 @@ parser_is_suunto_d9 (parser_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
suunto_d9_parser_create (parser_t **out, unsigned int model)
|
||||
{
|
||||
if (out == NULL)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
suunto_d9_parser_t *parser = (suunto_d9_parser_t *) malloc (sizeof (suunto_d9_parser_t));
|
||||
if (parser == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return PARSER_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -104,34 +104,34 @@ suunto_d9_parser_create (parser_t **out, unsigned int model)
|
||||
|
||||
*out = (parser_t*) parser;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_d9_parser_destroy (parser_t *abstract)
|
||||
{
|
||||
if (! parser_is_suunto_d9 (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Free memory.
|
||||
free (abstract);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_d9_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
if (! parser_is_suunto_d9 (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_d9_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
{
|
||||
suunto_d9_parser_t *parser = (suunto_d9_parser_t*) abstract;
|
||||
@ -143,7 +143,7 @@ suunto_d9_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
offset = 0x13;
|
||||
|
||||
if (abstract->size < offset + 7)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *p = abstract->data + offset;
|
||||
|
||||
@ -165,11 +165,11 @@ suunto_d9_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_d9_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value)
|
||||
{
|
||||
suunto_d9_parser_t *parser = (suunto_d9_parser_t*) abstract;
|
||||
@ -184,7 +184,7 @@ suunto_d9_parser_get_field (parser_t *abstract, parser_field_type_t type, unsign
|
||||
if (parser->model == HELO2)
|
||||
config += 74;
|
||||
if (size < config)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
gasmix_t *gasmix = (gasmix_t *) value;
|
||||
|
||||
@ -230,21 +230,21 @@ suunto_d9_parser_get_field (parser_t *abstract, parser_field_type_t type, unsign
|
||||
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_d9_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata)
|
||||
{
|
||||
suunto_d9_parser_t *parser = (suunto_d9_parser_t*) abstract;
|
||||
|
||||
if (! parser_is_suunto_d9 (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
const unsigned char *data = abstract->data;
|
||||
unsigned int size = abstract->size;
|
||||
@ -262,12 +262,12 @@ suunto_d9_parser_samples_foreach (parser_t *abstract, sample_callback_t callback
|
||||
if (parser->model == D9tx)
|
||||
config = 0xB7;
|
||||
if (config + 1 > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// Number of parameters in the configuration data.
|
||||
unsigned int nparams = data[config];
|
||||
if (nparams > MAXPARAMS)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// Available divisor values.
|
||||
const unsigned int divisors[] = {1, 2, 4, 5, 10, 50, 100, 1000};
|
||||
@ -288,21 +288,21 @@ suunto_d9_parser_samples_foreach (parser_t *abstract, sample_callback_t callback
|
||||
info[i].size = 1;
|
||||
break;
|
||||
default: // Unknown sample type
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
// Offset to the profile data.
|
||||
unsigned int profile = config + 2 + nparams * 3;
|
||||
if (profile + 5 > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// HelO2 dives can have an additional data block.
|
||||
const unsigned char sequence[] = {0x01, 0x00, 0x00};
|
||||
if (parser->model == HELO2 && memcmp (data + profile, sequence, sizeof (sequence)) != 0)
|
||||
profile += 12;
|
||||
if (profile + 5 > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// Sample recording interval.
|
||||
unsigned int interval_sample_offset = 0x1C - SKIP;
|
||||
@ -312,7 +312,7 @@ suunto_d9_parser_samples_foreach (parser_t *abstract, sample_callback_t callback
|
||||
interval_sample_offset = 0x1E;
|
||||
unsigned int interval_sample = data[interval_sample_offset];
|
||||
if (interval_sample == 0)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// Offset to the first marker position.
|
||||
unsigned int marker = array_uint16_le (data + profile + 3);
|
||||
@ -331,7 +331,7 @@ suunto_d9_parser_samples_foreach (parser_t *abstract, sample_callback_t callback
|
||||
for (unsigned int i = 0; i < nparams; ++i) {
|
||||
if (info[i].interval && (nsamples % info[i].interval) == 0) {
|
||||
if (offset + info[i].size > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int value = 0;
|
||||
switch (info[i].type) {
|
||||
@ -353,7 +353,7 @@ suunto_d9_parser_samples_foreach (parser_t *abstract, sample_callback_t callback
|
||||
if (callback) callback (SAMPLE_TYPE_TEMPERATURE, sample, userdata);
|
||||
break;
|
||||
default: // Unknown sample type
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
offset += info[i].size;
|
||||
@ -373,17 +373,17 @@ suunto_d9_parser_samples_foreach (parser_t *abstract, sample_callback_t callback
|
||||
switch (event) {
|
||||
case 0x01: // Next Event Marker
|
||||
if (offset + 4 > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
current = array_uint16_le (data + offset + 0);
|
||||
next = array_uint16_le (data + offset + 2);
|
||||
if (marker != current)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
marker += next;
|
||||
offset += 4;
|
||||
break;
|
||||
case 0x02: // Surfaced
|
||||
if (offset + 2 > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
unknown = data[offset + 0];
|
||||
seconds = data[offset + 1];
|
||||
sample.event.type = SAMPLE_EVENT_SURFACE;
|
||||
@ -393,7 +393,7 @@ suunto_d9_parser_samples_foreach (parser_t *abstract, sample_callback_t callback
|
||||
break;
|
||||
case 0x03: // Event
|
||||
if (offset + 2 > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
type = data[offset + 0];
|
||||
seconds = data[offset + 1];
|
||||
switch (type & 0x7F) {
|
||||
@ -472,7 +472,7 @@ suunto_d9_parser_samples_foreach (parser_t *abstract, sample_callback_t callback
|
||||
break;
|
||||
case 0x04: // Bookmark/Heading
|
||||
if (offset + 4 > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
unknown = data[offset + 0];
|
||||
seconds = data[offset + 1];
|
||||
heading = array_uint16_le (data + offset + 2);
|
||||
@ -489,7 +489,7 @@ suunto_d9_parser_samples_foreach (parser_t *abstract, sample_callback_t callback
|
||||
break;
|
||||
case 0x05: // Gas Change
|
||||
if (offset + 2 > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
percentage = data[offset + 0];
|
||||
seconds = data[offset + 1];
|
||||
sample.event.type = SAMPLE_EVENT_GASCHANGE;
|
||||
@ -500,7 +500,7 @@ suunto_d9_parser_samples_foreach (parser_t *abstract, sample_callback_t callback
|
||||
break;
|
||||
case 0x06: // Gas Change
|
||||
if (offset + 4 > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
unknown = data[offset + 0];
|
||||
unknown = data[offset + 1];
|
||||
percentage = data[offset + 2];
|
||||
@ -524,5 +524,5 @@ suunto_d9_parser_samples_foreach (parser_t *abstract, sample_callback_t callback
|
||||
nsamples++;
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
typedef struct suunto_eon_device_t {
|
||||
@ -41,9 +41,9 @@ typedef struct suunto_eon_device_t {
|
||||
serial_t *port;
|
||||
} suunto_eon_device_t;
|
||||
|
||||
static device_status_t suunto_eon_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t suunto_eon_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t suunto_eon_device_close (device_t *abstract);
|
||||
static dc_status_t suunto_eon_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static dc_status_t suunto_eon_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static dc_status_t suunto_eon_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t suunto_eon_device_backend = {
|
||||
DEVICE_TYPE_SUUNTO_EON,
|
||||
@ -75,17 +75,17 @@ device_is_suunto_eon (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_eon_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
suunto_eon_device_t *device = (suunto_eon_device_t *) malloc (sizeof (suunto_eon_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -99,7 +99,7 @@ suunto_eon_device_open (device_t **out, const char* name)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (1200 8N2).
|
||||
@ -108,7 +108,7 @@ suunto_eon_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (1000ms).
|
||||
@ -116,7 +116,7 @@ suunto_eon_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Clear the RTS line.
|
||||
@ -124,49 +124,49 @@ suunto_eon_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the DTR/RTS line.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_eon_device_close (device_t *abstract)
|
||||
{
|
||||
suunto_eon_device_t *device = (suunto_eon_device_t*) abstract;
|
||||
|
||||
if (! device_is_suunto_eon (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_eon_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
suunto_eon_device_t *device = (suunto_eon_device_t*) abstract;
|
||||
|
||||
if (! device_is_suunto_eon (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Erase the current contents of the buffer and
|
||||
// pre-allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, SUUNTO_EON_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Enable progress notifications.
|
||||
@ -199,24 +199,24 @@ suunto_eon_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
unsigned char ccrc = checksum_add_uint8 (answer, sizeof (answer) - 1, 0x00);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
dc_buffer_append (buffer, answer, SUUNTO_EON_MEMORY_SIZE);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_eon_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
dc_buffer_t *buffer = dc_buffer_new (SUUNTO_EON_MEMORY_SIZE);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
|
||||
device_status_t rc = suunto_eon_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = suunto_eon_device_dump (abstract, buffer);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
@ -238,16 +238,16 @@ suunto_eon_device_foreach (device_t *abstract, dive_callback_t callback, void *u
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_eon_device_write_name (device_t *abstract, unsigned char data[], unsigned int size)
|
||||
{
|
||||
suunto_eon_device_t *device = (suunto_eon_device_t*) abstract;
|
||||
|
||||
if (! device_is_suunto_eon (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size > 20)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Send the command.
|
||||
unsigned char command[21] = {'N'};
|
||||
@ -258,17 +258,17 @@ suunto_eon_device_write_name (device_t *abstract, unsigned char data[], unsigned
|
||||
return EXITCODE (rc);
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_eon_device_write_interval (device_t *abstract, unsigned char interval)
|
||||
{
|
||||
suunto_eon_device_t *device = (suunto_eon_device_t*) abstract;
|
||||
|
||||
if (! device_is_suunto_eon (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Send the command.
|
||||
unsigned char command[2] = {'T', interval};
|
||||
@ -278,20 +278,20 @@ suunto_eon_device_write_interval (device_t *abstract, unsigned char interval)
|
||||
return EXITCODE (rc);
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_eon_extract_dives (device_t *abstract, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
suunto_common_device_t *device = (suunto_common_device_t*) abstract;
|
||||
|
||||
if (abstract && !device_is_suunto_eon (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size < SUUNTO_EON_MEMORY_SIZE)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
return suunto_common_extract_dives (device, &suunto_eon_layout, data, callback, userdata);
|
||||
}
|
||||
|
||||
@ -39,11 +39,11 @@ struct suunto_eon_parser_t {
|
||||
unsigned int maxdepth;
|
||||
};
|
||||
|
||||
static parser_status_t suunto_eon_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static parser_status_t suunto_eon_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static parser_status_t suunto_eon_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static parser_status_t suunto_eon_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static parser_status_t suunto_eon_parser_destroy (parser_t *abstract);
|
||||
static dc_status_t suunto_eon_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static dc_status_t suunto_eon_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static dc_status_t suunto_eon_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static dc_status_t suunto_eon_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static dc_status_t suunto_eon_parser_destroy (parser_t *abstract);
|
||||
|
||||
static const parser_backend_t suunto_eon_parser_backend = {
|
||||
PARSER_TYPE_SUUNTO_EON,
|
||||
@ -65,17 +65,17 @@ parser_is_suunto_eon (parser_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
suunto_eon_parser_create (parser_t **out, int spyder)
|
||||
{
|
||||
if (out == NULL)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
suunto_eon_parser_t *parser = (suunto_eon_parser_t *) malloc (sizeof (suunto_eon_parser_t));
|
||||
if (parser == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return PARSER_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -89,47 +89,47 @@ suunto_eon_parser_create (parser_t **out, int spyder)
|
||||
|
||||
*out = (parser_t*) parser;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_eon_parser_destroy (parser_t *abstract)
|
||||
{
|
||||
if (! parser_is_suunto_eon (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Free memory.
|
||||
free (abstract);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_eon_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
suunto_eon_parser_t *parser = (suunto_eon_parser_t *) abstract;
|
||||
|
||||
if (! parser_is_suunto_eon (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Reset the cache.
|
||||
parser->cached = 0;
|
||||
parser->divetime = 0;
|
||||
parser->maxdepth = 0;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_eon_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
{
|
||||
suunto_eon_parser_t *parser = (suunto_eon_parser_t *) abstract;
|
||||
|
||||
if (abstract->size < 6 + 5)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *p = abstract->data + 6;
|
||||
|
||||
@ -150,11 +150,11 @@ suunto_eon_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
datetime->second = 0;
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_eon_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value)
|
||||
{
|
||||
suunto_eon_parser_t *parser = (suunto_eon_parser_t *) abstract;
|
||||
@ -163,7 +163,7 @@ suunto_eon_parser_get_field (parser_t *abstract, parser_field_type_t type, unsig
|
||||
unsigned int size = abstract->size;
|
||||
|
||||
if (size < 13)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
if (!parser->cached) {
|
||||
unsigned int interval = data[3];
|
||||
@ -183,7 +183,7 @@ suunto_eon_parser_get_field (parser_t *abstract, parser_field_type_t type, unsig
|
||||
// Store the offset to the end marker.
|
||||
unsigned int marker = offset;
|
||||
if (marker + 2 >= size || data[marker] != 0x80)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
parser->cached = 1;
|
||||
parser->divetime = nsamples * interval;
|
||||
@ -212,27 +212,27 @@ suunto_eon_parser_get_field (parser_t *abstract, parser_field_type_t type, unsig
|
||||
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_eon_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata)
|
||||
{
|
||||
suunto_eon_parser_t *parser = (suunto_eon_parser_t *) abstract;
|
||||
|
||||
if (! parser_is_suunto_eon (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
const unsigned char *data = abstract->data;
|
||||
unsigned int size = abstract->size;
|
||||
|
||||
if (size < 13)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// Find the maximum depth.
|
||||
unsigned int depth = 0, maxdepth = 0;
|
||||
@ -249,7 +249,7 @@ suunto_eon_parser_samples_foreach (parser_t *abstract, sample_callback_t callbac
|
||||
// Store the offset to the end marker.
|
||||
unsigned int marker = offset;
|
||||
if (marker + 2 >= size || data[marker] != 0x80)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// The Solution Nitrox/Vario stores nitrox data, not tank pressure.
|
||||
unsigned int nitrox = !parser->spyder && (data[4] & 0x80);
|
||||
@ -352,5 +352,5 @@ suunto_eon_parser_samples_foreach (parser_t *abstract, sample_callback_t callbac
|
||||
sample.depth = 0;
|
||||
if (callback) callback (SAMPLE_TYPE_DEPTH, sample, userdata);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
#define RB_PROFILE_BEGIN 0x020
|
||||
@ -43,9 +43,9 @@ typedef struct suunto_solution_device_t {
|
||||
serial_t *port;
|
||||
} suunto_solution_device_t;
|
||||
|
||||
static device_status_t suunto_solution_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t suunto_solution_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t suunto_solution_device_close (device_t *abstract);
|
||||
static dc_status_t suunto_solution_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static dc_status_t suunto_solution_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static dc_status_t suunto_solution_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t suunto_solution_device_backend = {
|
||||
DEVICE_TYPE_SUUNTO_SOLUTION,
|
||||
@ -68,17 +68,17 @@ device_is_suunto_solution (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_solution_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
suunto_solution_device_t *device = (suunto_solution_device_t *) malloc (sizeof (suunto_solution_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -92,7 +92,7 @@ suunto_solution_device_open (device_t **out, const char* name)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (1200 8N2).
|
||||
@ -101,7 +101,7 @@ suunto_solution_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (1000ms).
|
||||
@ -109,7 +109,7 @@ suunto_solution_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Clear the RTS line.
|
||||
@ -117,49 +117,49 @@ suunto_solution_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the DTR/RTS line.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_solution_device_close (device_t *abstract)
|
||||
{
|
||||
suunto_solution_device_t *device = (suunto_solution_device_t*) abstract;
|
||||
|
||||
if (! device_is_suunto_solution (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_solution_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
suunto_solution_device_t *device = (suunto_solution_device_t*) abstract;
|
||||
|
||||
if (! device_is_suunto_solution (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Erase the current contents of the buffer and
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, SUUNTO_SOLUTION_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
unsigned char *data = dc_buffer_get_data (buffer);
|
||||
@ -247,22 +247,22 @@ suunto_solution_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
progress.current += 1;
|
||||
device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_solution_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
if (! device_is_suunto_solution (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (SUUNTO_SOLUTION_MEMORY_SIZE);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
|
||||
device_status_t rc = suunto_solution_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = suunto_solution_device_dump (abstract, buffer);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
@ -284,14 +284,14 @@ suunto_solution_device_foreach (device_t *abstract, dive_callback_t callback, vo
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_solution_extract_dives (device_t *abstract, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
if (abstract && !device_is_suunto_solution (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size < SUUNTO_SOLUTION_MEMORY_SIZE)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned char buffer[RB_PROFILE_END - RB_PROFILE_BEGIN] = {0};
|
||||
|
||||
@ -301,7 +301,7 @@ suunto_solution_extract_dives (device_t *abstract, const unsigned char data[], u
|
||||
eop >= RB_PROFILE_END ||
|
||||
data[eop] != 0x82)
|
||||
{
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
}
|
||||
|
||||
// The profile data is stored backwards in the ringbuffer. To locate
|
||||
@ -333,14 +333,14 @@ suunto_solution_extract_dives (device_t *abstract, const unsigned char data[], u
|
||||
unsigned int len = ringbuffer_distance (previous, current, 0, RB_PROFILE_BEGIN, RB_PROFILE_END);
|
||||
|
||||
if (callback && !callback (buffer + idx, len, NULL, 0, userdata))
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
||||
previous = current;
|
||||
}
|
||||
}
|
||||
|
||||
if (data[current] != 0x82)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -37,10 +37,10 @@ struct suunto_solution_parser_t {
|
||||
unsigned int maxdepth;
|
||||
};
|
||||
|
||||
static parser_status_t suunto_solution_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static parser_status_t suunto_solution_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static parser_status_t suunto_solution_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static parser_status_t suunto_solution_parser_destroy (parser_t *abstract);
|
||||
static dc_status_t suunto_solution_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static dc_status_t suunto_solution_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static dc_status_t suunto_solution_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static dc_status_t suunto_solution_parser_destroy (parser_t *abstract);
|
||||
|
||||
static const parser_backend_t suunto_solution_parser_backend = {
|
||||
PARSER_TYPE_SUUNTO_SOLUTION,
|
||||
@ -62,17 +62,17 @@ parser_is_suunto_solution (parser_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
suunto_solution_parser_create (parser_t **out)
|
||||
{
|
||||
if (out == NULL)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
suunto_solution_parser_t *parser = (suunto_solution_parser_t *) malloc (sizeof (suunto_solution_parser_t));
|
||||
if (parser == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return PARSER_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -85,41 +85,41 @@ suunto_solution_parser_create (parser_t **out)
|
||||
|
||||
*out = (parser_t*) parser;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_solution_parser_destroy (parser_t *abstract)
|
||||
{
|
||||
if (! parser_is_suunto_solution (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Free memory.
|
||||
free (abstract);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_solution_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
suunto_solution_parser_t *parser = (suunto_solution_parser_t *) abstract;
|
||||
|
||||
if (! parser_is_suunto_solution (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Reset the cache.
|
||||
parser->cached = 0;
|
||||
parser->divetime = 0;
|
||||
parser->maxdepth = 0;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_solution_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value)
|
||||
{
|
||||
suunto_solution_parser_t *parser = (suunto_solution_parser_t *) abstract;
|
||||
@ -128,7 +128,7 @@ suunto_solution_parser_get_field (parser_t *abstract, parser_field_type_t type,
|
||||
unsigned int size = abstract->size;
|
||||
|
||||
if (size < 4)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
if (!parser->cached) {
|
||||
unsigned int nsamples = 0;
|
||||
@ -140,7 +140,7 @@ suunto_solution_parser_get_field (parser_t *abstract, parser_field_type_t type,
|
||||
depth += (signed char) value;
|
||||
if (value == 0x7D || value == 0x83) {
|
||||
if (offset + 1 > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
depth += (signed char) data[offset++];
|
||||
}
|
||||
if (depth > maxdepth)
|
||||
@ -152,7 +152,7 @@ suunto_solution_parser_get_field (parser_t *abstract, parser_field_type_t type,
|
||||
// Store the offset to the end marker.
|
||||
unsigned int marker = offset;
|
||||
if (marker + 1 >= size || data[marker] != 0x80)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
parser->cached = 1;
|
||||
parser->divetime = (nsamples * 3 + data[marker + 1]) * 60;
|
||||
@ -178,24 +178,24 @@ suunto_solution_parser_get_field (parser_t *abstract, parser_field_type_t type,
|
||||
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_solution_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata)
|
||||
{
|
||||
if (! parser_is_suunto_solution (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
const unsigned char *data = abstract->data;
|
||||
unsigned int size = abstract->size;
|
||||
|
||||
if (size < 4)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int time = 0, depth = 0;
|
||||
|
||||
@ -216,7 +216,7 @@ suunto_solution_parser_samples_foreach (parser_t *abstract, sample_callback_t ca
|
||||
// or ascent greater than 124 feet. The remaining part of
|
||||
// the total delta value is stored in the next byte.
|
||||
if (offset + 1 > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
depth += (signed char) data[offset++];
|
||||
}
|
||||
sample.depth = depth * FEET;
|
||||
@ -246,7 +246,7 @@ suunto_solution_parser_samples_foreach (parser_t *abstract, sample_callback_t ca
|
||||
}
|
||||
|
||||
if (data[offset] != 0x80)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||
@ -51,11 +51,11 @@ typedef struct suunto_vyper_device_t {
|
||||
unsigned int delay;
|
||||
} suunto_vyper_device_t;
|
||||
|
||||
static device_status_t suunto_vyper_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
static device_status_t suunto_vyper_device_write (device_t *abstract, unsigned int address, const unsigned char data[], unsigned int size);
|
||||
static device_status_t suunto_vyper_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t suunto_vyper_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t suunto_vyper_device_close (device_t *abstract);
|
||||
static dc_status_t suunto_vyper_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
static dc_status_t suunto_vyper_device_write (device_t *abstract, unsigned int address, const unsigned char data[], unsigned int size);
|
||||
static dc_status_t suunto_vyper_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static dc_status_t suunto_vyper_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static dc_status_t suunto_vyper_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t suunto_vyper_device_backend = {
|
||||
DEVICE_TYPE_SUUNTO_VYPER,
|
||||
@ -95,17 +95,17 @@ device_is_suunto_vyper (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_vyper_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
suunto_vyper_device_t *device = (suunto_vyper_device_t *) malloc (sizeof (suunto_vyper_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -120,7 +120,7 @@ suunto_vyper_device_open (device_t **out, const char* name)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (2400 8O1).
|
||||
@ -129,7 +129,7 @@ suunto_vyper_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (1000 ms).
|
||||
@ -137,7 +137,7 @@ suunto_vyper_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the DTR line (power supply for the interface).
|
||||
@ -145,7 +145,7 @@ suunto_vyper_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the DTR line.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Give the interface 100 ms to settle and draw power up.
|
||||
@ -156,46 +156,46 @@ suunto_vyper_device_open (device_t **out, const char* name)
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_vyper_device_close (device_t *abstract)
|
||||
{
|
||||
suunto_vyper_device_t *device = (suunto_vyper_device_t*) abstract;
|
||||
|
||||
if (! device_is_suunto_vyper (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_vyper_device_set_delay (device_t *abstract, unsigned int delay)
|
||||
{
|
||||
suunto_vyper_device_t *device = (suunto_vyper_device_t*) abstract;
|
||||
|
||||
if (! device_is_suunto_vyper (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
device->delay = delay;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_vyper_send (suunto_vyper_device_t *device, const unsigned char command[], unsigned int csize)
|
||||
{
|
||||
serial_sleep (device->delay);
|
||||
@ -227,11 +227,11 @@ suunto_vyper_send (suunto_vyper_device_t *device, const unsigned char command[],
|
||||
// Clear RTS to receive the reply.
|
||||
serial_set_rts (device->port, 0);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_vyper_transfer (suunto_vyper_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size)
|
||||
{
|
||||
assert (asize >= size + 2);
|
||||
@ -239,11 +239,11 @@ suunto_vyper_transfer (suunto_vyper_device_t *device, const unsigned char comman
|
||||
device_t *abstract = (device_t *) device;
|
||||
|
||||
if (device_is_cancelled (abstract))
|
||||
return DEVICE_STATUS_CANCELLED;
|
||||
return DC_STATUS_CANCELLED;
|
||||
|
||||
// Send the command to the dive computer.
|
||||
device_status_t rc = suunto_vyper_send (device, command, csize);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = suunto_vyper_send (device, command, csize);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Failed to send the command.");
|
||||
return rc;
|
||||
}
|
||||
@ -258,7 +258,7 @@ suunto_vyper_transfer (suunto_vyper_device_t *device, const unsigned char comman
|
||||
// Verify the header of the package.
|
||||
if (memcmp (command, answer, asize - size - 1) != 0) {
|
||||
WARNING ("Unexpected answer start byte(s).");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Verify the checksum of the package.
|
||||
@ -266,20 +266,20 @@ suunto_vyper_transfer (suunto_vyper_device_t *device, const unsigned char comman
|
||||
unsigned char ccrc = checksum_xor_uint8 (answer, asize - 1, 0x00);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_vyper_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size)
|
||||
{
|
||||
suunto_vyper_device_t *device = (suunto_vyper_device_t*) abstract;
|
||||
|
||||
if (! device_is_suunto_vyper (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// The data transmission is split in packages
|
||||
// of maximum $SUUNTO_VYPER_PACKET_SIZE bytes.
|
||||
@ -297,8 +297,8 @@ suunto_vyper_device_read (device_t *abstract, unsigned int address, unsigned cha
|
||||
len, // count
|
||||
0}; // CRC
|
||||
command[4] = checksum_xor_uint8 (command, 4, 0x00);
|
||||
device_status_t rc = suunto_vyper_transfer (device, command, sizeof (command), answer, len + 5, len);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = suunto_vyper_transfer (device, command, sizeof (command), answer, len + 5, len);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
memcpy (data, answer + 4, len);
|
||||
@ -308,17 +308,17 @@ suunto_vyper_device_read (device_t *abstract, unsigned int address, unsigned cha
|
||||
data += len;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_vyper_device_write (device_t *abstract, unsigned int address, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
suunto_vyper_device_t *device = (suunto_vyper_device_t*) abstract;
|
||||
|
||||
if (! device_is_suunto_vyper (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// The data transmission is split in packages
|
||||
// of maximum $SUUNTO_VYPER_PACKET_SIZE bytes.
|
||||
@ -331,8 +331,8 @@ suunto_vyper_device_write (device_t *abstract, unsigned int address, const unsig
|
||||
// Prepare to write the package.
|
||||
unsigned char panswer[3] = {0};
|
||||
unsigned char pcommand[3] = {0x07, 0xA5, 0xA2};
|
||||
device_status_t rc = suunto_vyper_transfer (device, pcommand, sizeof (pcommand), panswer, sizeof (panswer), 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = suunto_vyper_transfer (device, pcommand, sizeof (pcommand), panswer, sizeof (panswer), 0);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Write the package.
|
||||
@ -345,7 +345,7 @@ suunto_vyper_device_write (device_t *abstract, unsigned int address, const unsig
|
||||
memcpy (wcommand + 4, data, len);
|
||||
wcommand[len + 4] = checksum_xor_uint8 (wcommand, len + 4, 0x00);
|
||||
rc = suunto_vyper_transfer (device, wcommand, len + 5, wanswer, sizeof (wanswer), 0);
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
nbytes += len;
|
||||
@ -353,29 +353,29 @@ suunto_vyper_device_write (device_t *abstract, unsigned int address, const unsig
|
||||
data += len;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_vyper_read_dive (device_t *abstract, dc_buffer_t *buffer, int init, device_progress_t *progress)
|
||||
{
|
||||
suunto_vyper_device_t *device = (suunto_vyper_device_t*) abstract;
|
||||
|
||||
if (device_is_cancelled (abstract))
|
||||
return DEVICE_STATUS_CANCELLED;
|
||||
return DC_STATUS_CANCELLED;
|
||||
|
||||
// Erase the current contents of the buffer.
|
||||
if (!dc_buffer_clear (buffer)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Send the command to the dive computer.
|
||||
unsigned char command[3] = {init ? 0x08 : 0x09, 0xA5, 0x00};
|
||||
command[2] = checksum_xor_uint8 (command, 2, 0x00);
|
||||
device_status_t rc = suunto_vyper_send (device, command, 3);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = suunto_vyper_send (device, command, 3);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
WARNING ("Failed to send the command.");
|
||||
return rc;
|
||||
}
|
||||
@ -407,7 +407,7 @@ suunto_vyper_read_dive (device_t *abstract, dc_buffer_t *buffer, int init, devic
|
||||
if (answer[0] != command[0] ||
|
||||
answer[1] > SUUNTO_VYPER_PACKET_SIZE) {
|
||||
WARNING ("Unexpected answer start byte(s).");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Receive the remaining part of the package.
|
||||
@ -423,7 +423,7 @@ suunto_vyper_read_dive (device_t *abstract, dc_buffer_t *buffer, int init, devic
|
||||
unsigned char ccrc = checksum_xor_uint8 (answer, len + 2, 0x00);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// The DC sends a null package (a package with length zero) when it
|
||||
@ -432,7 +432,7 @@ suunto_vyper_read_dive (device_t *abstract, dc_buffer_t *buffer, int init, devic
|
||||
// we discard the current (incomplete) dive and end the transmission.
|
||||
if (len == 0) {
|
||||
dc_buffer_clear (buffer);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Update and emit a progress event.
|
||||
@ -463,7 +463,7 @@ suunto_vyper_read_dive (device_t *abstract, dc_buffer_t *buffer, int init, devic
|
||||
// Check for a buffer error.
|
||||
if (dc_buffer_get_size (buffer) != nbytes) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// The DC traverses its internal ring buffer backwards. The most recent
|
||||
@ -472,31 +472,31 @@ suunto_vyper_read_dive (device_t *abstract, dc_buffer_t *buffer, int init, devic
|
||||
// the bytes again before returning them to the application.
|
||||
array_reverse_bytes (dc_buffer_get_data (buffer), dc_buffer_get_size (buffer));
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_vyper_device_read_dive (device_t *abstract, dc_buffer_t *buffer, int init)
|
||||
{
|
||||
if (! device_is_suunto_vyper (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
return suunto_vyper_read_dive (abstract, buffer, init, NULL);
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_vyper_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
if (! device_is_suunto_vyper (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Erase the current contents of the buffer and
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, SUUNTO_VYPER_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
return device_dump_read (abstract, dc_buffer_get_data (buffer),
|
||||
@ -504,13 +504,13 @@ suunto_vyper_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_vyper_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
suunto_common_device_t *device = (suunto_common_device_t*) abstract;
|
||||
|
||||
if (! device_is_suunto_vyper (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Enable progress notifications.
|
||||
device_progress_t progress = DEVICE_PROGRESS_INITIALIZER;
|
||||
@ -522,8 +522,8 @@ suunto_vyper_device_foreach (device_t *abstract, dive_callback_t callback, void
|
||||
// we read a larger block of memory that always contains the data
|
||||
// for both devices.
|
||||
unsigned char header[HDR_DEVINFO_END - HDR_DEVINFO_BEGIN] = {0};
|
||||
device_status_t rc = suunto_vyper_device_read (abstract, HDR_DEVINFO_BEGIN, header, sizeof (header));
|
||||
if (rc != DEVICE_STATUS_SUCCESS)
|
||||
dc_status_t rc = suunto_vyper_device_read (abstract, HDR_DEVINFO_BEGIN, header, sizeof (header));
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
|
||||
// Identify the connected device as a Vyper or a Spyder, by inspecting
|
||||
@ -552,26 +552,26 @@ suunto_vyper_device_foreach (device_t *abstract, dive_callback_t callback, void
|
||||
// Allocate a memory buffer.
|
||||
dc_buffer_t *buffer = dc_buffer_new (layout->rb_profile_end - layout->rb_profile_begin);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
|
||||
unsigned int ndives = 0;
|
||||
while ((rc = suunto_vyper_read_dive (abstract, buffer, (ndives == 0), &progress)) == DEVICE_STATUS_SUCCESS) {
|
||||
while ((rc = suunto_vyper_read_dive (abstract, buffer, (ndives == 0), &progress)) == DC_STATUS_SUCCESS) {
|
||||
unsigned char *data = dc_buffer_get_data (buffer);
|
||||
unsigned int size = dc_buffer_get_size (buffer);
|
||||
|
||||
if (size == 0) {
|
||||
dc_buffer_free (buffer);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (memcmp (data + layout->fp_offset, device->fingerprint, sizeof (device->fingerprint)) == 0) {
|
||||
dc_buffer_free (buffer);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (callback && !callback (data, size, data + layout->fp_offset, sizeof (device->fingerprint), userdata)) {
|
||||
dc_buffer_free (buffer);
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
ndives++;
|
||||
@ -583,16 +583,16 @@ suunto_vyper_device_foreach (device_t *abstract, dive_callback_t callback, void
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_vyper_extract_dives (device_t *abstract, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
suunto_common_device_t *device = (suunto_common_device_t*) abstract;
|
||||
|
||||
if (abstract && !device_is_suunto_vyper (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size < SUUNTO_VYPER_MEMORY_SIZE)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const suunto_common_layout_t *layout = &suunto_vyper_layout;
|
||||
if (data[HDR_DEVINFO_VYPER] == 20 || data[HDR_DEVINFO_VYPER] == 30 || data[HDR_DEVINFO_VYPER] == 60)
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
typedef struct suunto_vyper2_device_t {
|
||||
@ -40,8 +40,8 @@ typedef struct suunto_vyper2_device_t {
|
||||
serial_t *port;
|
||||
} suunto_vyper2_device_t;
|
||||
|
||||
static device_status_t suunto_vyper2_device_packet (device_t *abstract, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size);
|
||||
static device_status_t suunto_vyper2_device_close (device_t *abstract);
|
||||
static dc_status_t suunto_vyper2_device_packet (device_t *abstract, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size);
|
||||
static dc_status_t suunto_vyper2_device_close (device_t *abstract);
|
||||
|
||||
static const suunto_common2_device_backend_t suunto_vyper2_device_backend = {
|
||||
{
|
||||
@ -74,17 +74,17 @@ device_is_suunto_vyper2 (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_vyper2_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
suunto_vyper2_device_t *device = (suunto_vyper2_device_t *) malloc (sizeof (suunto_vyper2_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -98,7 +98,7 @@ suunto_vyper2_device_open (device_t **out, const char* name)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (9600 8N1).
|
||||
@ -107,7 +107,7 @@ suunto_vyper2_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (3000 ms).
|
||||
@ -115,7 +115,7 @@ suunto_vyper2_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the DTR line (power supply for the interface).
|
||||
@ -123,7 +123,7 @@ suunto_vyper2_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the DTR line.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Give the interface 100 ms to settle and draw power up.
|
||||
@ -140,38 +140,38 @@ suunto_vyper2_device_open (device_t **out, const char* name)
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_vyper2_device_close (device_t *abstract)
|
||||
{
|
||||
suunto_vyper2_device_t *device = (suunto_vyper2_device_t*) abstract;
|
||||
|
||||
if (! device_is_suunto_vyper2 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
suunto_vyper2_device_packet (device_t *abstract, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size)
|
||||
{
|
||||
suunto_vyper2_device_t *device = (suunto_vyper2_device_t *) abstract;
|
||||
|
||||
if (device_is_cancelled (abstract))
|
||||
return DEVICE_STATUS_CANCELLED;
|
||||
return DC_STATUS_CANCELLED;
|
||||
|
||||
serial_sleep (0x190 + 0xC8);
|
||||
|
||||
@ -198,19 +198,19 @@ suunto_vyper2_device_packet (device_t *abstract, const unsigned char command[],
|
||||
// Verify the header of the package.
|
||||
if (answer[0] != command[0]) {
|
||||
WARNING ("Unexpected answer header.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Verify the size of the package.
|
||||
if (array_uint16_be (answer + 1) + 4 != asize) {
|
||||
WARNING ("Unexpected answer size.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Verify the parameters of the package.
|
||||
if (memcmp (command + 3, answer + 3, asize - size - 4) != 0) {
|
||||
WARNING ("Unexpected answer parameters.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Verify the checksum of the package.
|
||||
@ -218,18 +218,18 @@ suunto_vyper2_device_packet (device_t *abstract, const unsigned char command[],
|
||||
unsigned char ccrc = checksum_xor_uint8 (answer, asize - 1, 0x00);
|
||||
if (crc != ccrc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
suunto_vyper2_device_reset_maxdepth (device_t *abstract)
|
||||
{
|
||||
if (! device_is_suunto_vyper2 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
return suunto_common2_device_reset_maxdepth (abstract);
|
||||
}
|
||||
|
||||
@ -37,11 +37,11 @@ struct suunto_vyper_parser_t {
|
||||
unsigned int maxdepth;
|
||||
};
|
||||
|
||||
static parser_status_t suunto_vyper_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static parser_status_t suunto_vyper_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static parser_status_t suunto_vyper_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static parser_status_t suunto_vyper_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static parser_status_t suunto_vyper_parser_destroy (parser_t *abstract);
|
||||
static dc_status_t suunto_vyper_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size);
|
||||
static dc_status_t suunto_vyper_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime);
|
||||
static dc_status_t suunto_vyper_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value);
|
||||
static dc_status_t suunto_vyper_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata);
|
||||
static dc_status_t suunto_vyper_parser_destroy (parser_t *abstract);
|
||||
|
||||
static const parser_backend_t suunto_vyper_parser_backend = {
|
||||
PARSER_TYPE_SUUNTO_VYPER,
|
||||
@ -63,17 +63,17 @@ parser_is_suunto_vyper (parser_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
parser_status_t
|
||||
dc_status_t
|
||||
suunto_vyper_parser_create (parser_t **out)
|
||||
{
|
||||
if (out == NULL)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
suunto_vyper_parser_t *parser = (suunto_vyper_parser_t *) malloc (sizeof (suunto_vyper_parser_t));
|
||||
if (parser == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return PARSER_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -86,45 +86,45 @@ suunto_vyper_parser_create (parser_t **out)
|
||||
|
||||
*out = (parser_t*) parser;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_vyper_parser_destroy (parser_t *abstract)
|
||||
{
|
||||
if (! parser_is_suunto_vyper (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Free memory.
|
||||
free (abstract);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_vyper_parser_set_data (parser_t *abstract, const unsigned char *data, unsigned int size)
|
||||
{
|
||||
suunto_vyper_parser_t *parser = (suunto_vyper_parser_t *) abstract;
|
||||
|
||||
if (! parser_is_suunto_vyper (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Reset the cache.
|
||||
parser->cached = 0;
|
||||
parser->divetime = 0;
|
||||
parser->maxdepth = 0;
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_vyper_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
{
|
||||
if (abstract->size < 9 + 5)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
const unsigned char *p = abstract->data + 9;
|
||||
|
||||
@ -137,11 +137,11 @@ suunto_vyper_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
||||
datetime->second = 0;
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_vyper_parser_get_field (parser_t *abstract, parser_field_type_t type, unsigned int flags, void *value)
|
||||
{
|
||||
suunto_vyper_parser_t *parser = (suunto_vyper_parser_t *) abstract;
|
||||
@ -150,7 +150,7 @@ suunto_vyper_parser_get_field (parser_t *abstract, parser_field_type_t type, uns
|
||||
unsigned int size = abstract->size;
|
||||
|
||||
if (size < 18)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
if (!parser->cached) {
|
||||
unsigned int interval = data[3];
|
||||
@ -170,7 +170,7 @@ suunto_vyper_parser_get_field (parser_t *abstract, parser_field_type_t type, uns
|
||||
// Store the offset to the end marker.
|
||||
unsigned int marker = offset;
|
||||
if (marker + 4 >= size || data[marker] != 0x80)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
parser->cached = 1;
|
||||
parser->divetime = nsamples * interval;
|
||||
@ -199,24 +199,24 @@ suunto_vyper_parser_get_field (parser_t *abstract, parser_field_type_t type, uns
|
||||
gas->nitrogen = 1.0 - gas->oxygen;
|
||||
break;
|
||||
default:
|
||||
return PARSER_STATUS_UNSUPPORTED;
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static parser_status_t
|
||||
static dc_status_t
|
||||
suunto_vyper_parser_samples_foreach (parser_t *abstract, sample_callback_t callback, void *userdata)
|
||||
{
|
||||
if (! parser_is_suunto_vyper (abstract))
|
||||
return PARSER_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
const unsigned char *data = abstract->data;
|
||||
unsigned int size = abstract->size;
|
||||
|
||||
if (size < 18)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// Find the maximum depth.
|
||||
unsigned int depth = 0, maxdepth = 0;
|
||||
@ -233,7 +233,7 @@ suunto_vyper_parser_samples_foreach (parser_t *abstract, sample_callback_t callb
|
||||
// Store the offset to the end marker.
|
||||
unsigned int marker = offset;
|
||||
if (marker + 4 >= size || data[marker] != 0x80)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
unsigned int time = 0;
|
||||
unsigned int interval = data[3];
|
||||
@ -315,7 +315,7 @@ suunto_vyper_parser_samples_foreach (parser_t *abstract, sample_callback_t callb
|
||||
break;
|
||||
case 0x87: // Gas Change
|
||||
if (offset + 1 > size)
|
||||
return PARSER_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
sample.event.type = SAMPLE_EVENT_GASCHANGE;
|
||||
sample.event.value = data[offset++];
|
||||
break;
|
||||
@ -348,5 +348,5 @@ suunto_vyper_parser_samples_foreach (parser_t *abstract, sample_callback_t callb
|
||||
sample.depth = 0;
|
||||
if (callback) callback (SAMPLE_TYPE_DEPTH, sample, userdata);
|
||||
|
||||
return PARSER_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
|
||||
#define EXITCODE(rc) \
|
||||
( \
|
||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
|
||||
)
|
||||
|
||||
#define RB_PROFILE_BEGIN 0x000
|
||||
@ -51,10 +51,10 @@ typedef struct uwatec_aladin_device_t {
|
||||
dc_ticks_t systime;
|
||||
} uwatec_aladin_device_t ;
|
||||
|
||||
static device_status_t uwatec_aladin_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static device_status_t uwatec_aladin_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t uwatec_aladin_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t uwatec_aladin_device_close (device_t *abstract);
|
||||
static dc_status_t uwatec_aladin_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
static dc_status_t uwatec_aladin_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static dc_status_t uwatec_aladin_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static dc_status_t uwatec_aladin_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t uwatec_aladin_device_backend = {
|
||||
DEVICE_TYPE_UWATEC_ALADIN,
|
||||
@ -77,17 +77,17 @@ device_is_uwatec_aladin (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
uwatec_aladin_device_open (device_t **out, const char* name)
|
||||
{
|
||||
if (out == NULL)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
uwatec_aladin_device_t *device = (uwatec_aladin_device_t *) malloc (sizeof (uwatec_aladin_device_t));
|
||||
if (device == NULL) {
|
||||
WARNING ("Failed to allocate memory.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
@ -104,7 +104,7 @@ uwatec_aladin_device_open (device_t **out, const char* name)
|
||||
if (rc == -1) {
|
||||
WARNING ("Failed to open the serial port.");
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the serial communication protocol (19200 8N1).
|
||||
@ -113,7 +113,7 @@ uwatec_aladin_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the terminal attributes.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (INFINITE).
|
||||
@ -121,7 +121,7 @@ uwatec_aladin_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the timeout.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Clear the RTS line and set the DTR line.
|
||||
@ -130,83 +130,83 @@ uwatec_aladin_device_open (device_t **out, const char* name)
|
||||
WARNING ("Failed to set the DTR/RTS line.");
|
||||
serial_close (device->port);
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
*out = (device_t*) device;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
uwatec_aladin_device_close (device_t *abstract)
|
||||
{
|
||||
uwatec_aladin_device_t *device = (uwatec_aladin_device_t*) abstract;
|
||||
|
||||
if (! device_is_uwatec_aladin (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Close the device.
|
||||
if (serial_close (device->port) == -1) {
|
||||
free (device);
|
||||
return DEVICE_STATUS_IO;
|
||||
return DC_STATUS_IO;
|
||||
}
|
||||
|
||||
// Free memory.
|
||||
free (device);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
uwatec_aladin_device_set_timestamp (device_t *abstract, unsigned int timestamp)
|
||||
{
|
||||
uwatec_aladin_device_t *device = (uwatec_aladin_device_t*) abstract;
|
||||
|
||||
if (! device_is_uwatec_aladin (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
device->timestamp = timestamp;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
uwatec_aladin_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
uwatec_aladin_device_t *device = (uwatec_aladin_device_t*) abstract;
|
||||
|
||||
if (! device_is_uwatec_aladin (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size && size != 4)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size)
|
||||
device->timestamp = array_uint32_le (data);
|
||||
else
|
||||
device->timestamp = 0;
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
uwatec_aladin_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
uwatec_aladin_device_t *device = (uwatec_aladin_device_t*) abstract;
|
||||
|
||||
if (! device_is_uwatec_aladin (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Erase the current contents of the buffer and
|
||||
// pre-allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, UWATEC_ALADIN_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Enable progress notifications.
|
||||
@ -219,7 +219,7 @@ uwatec_aladin_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
// Receive the header of the package.
|
||||
for (unsigned int i = 0; i < 4;) {
|
||||
if (device_is_cancelled (abstract))
|
||||
return DEVICE_STATUS_CANCELLED;
|
||||
return DC_STATUS_CANCELLED;
|
||||
|
||||
int rc = serial_read (device->port, answer + i, 1);
|
||||
if (rc != 1) {
|
||||
@ -260,7 +260,7 @@ uwatec_aladin_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
unsigned short ccrc = checksum_add_uint16 (answer, UWATEC_ALADIN_MEMORY_SIZE, 0x0000);
|
||||
if (ccrc != crc) {
|
||||
WARNING ("Unexpected answer CRC.");
|
||||
return DEVICE_STATUS_PROTOCOL;
|
||||
return DC_STATUS_PROTOCOL;
|
||||
}
|
||||
|
||||
// Store the clock calibration values.
|
||||
@ -275,22 +275,22 @@ uwatec_aladin_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
|
||||
dc_buffer_append (buffer, answer, UWATEC_ALADIN_MEMORY_SIZE);
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
static dc_status_t
|
||||
uwatec_aladin_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
if (! device_is_uwatec_aladin (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
dc_buffer_t *buffer = dc_buffer_new (UWATEC_ALADIN_MEMORY_SIZE);
|
||||
if (buffer == NULL)
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
return DC_STATUS_NOMEMORY;
|
||||
|
||||
device_status_t rc = uwatec_aladin_device_dump (abstract, buffer);
|
||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||
dc_status_t rc = uwatec_aladin_device_dump (abstract, buffer);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
dc_buffer_free (buffer);
|
||||
return rc;
|
||||
}
|
||||
@ -312,16 +312,16 @@ uwatec_aladin_device_foreach (device_t *abstract, dive_callback_t callback, void
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
dc_status_t
|
||||
uwatec_aladin_extract_dives (device_t *abstract, const unsigned char* data, unsigned int size, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
uwatec_aladin_device_t *device = (uwatec_aladin_device_t*) abstract;
|
||||
|
||||
if (abstract && !device_is_uwatec_aladin (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (size < UWATEC_ALADIN_MEMORY_SIZE)
|
||||
return DEVICE_STATUS_ERROR;
|
||||
return DC_STATUS_DATAFORMAT;
|
||||
|
||||
// The logbook ring buffer can store up to 37 dives. But
|
||||
// if the total number of dives is less, not all logbook
|
||||
@ -414,11 +414,11 @@ uwatec_aladin_extract_dives (device_t *abstract, const unsigned char* data, unsi
|
||||
// Automatically abort when a dive is older than the provided timestamp.
|
||||
unsigned int timestamp = array_uint32_le (buffer + 11);
|
||||
if (device && timestamp <= device->timestamp)
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
||||
if (callback && !callback (buffer, len + 18, buffer + 11, 4, userdata))
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user