Use helper functions to allocate and free objects.
Both the allocation and initialization of the object data structure is now moved to a single function. The corresponding deallocation function is intended to free objects that have been allocated, but are not fully initialized yet. The public cleanup function shouldn't be used in such case, because it may try to release resources that haven't been initialized yet.
This commit is contained in:
parent
9bc14dca10
commit
ff29d218bb
@ -69,6 +69,7 @@ static dc_status_t atomics_cobalt_device_foreach (dc_device_t *abstract, dc_dive
|
||||
static dc_status_t atomics_cobalt_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t atomics_cobalt_device_vtable = {
|
||||
sizeof(atomics_cobalt_device_t),
|
||||
DC_FAMILY_ATOMICS_COBALT,
|
||||
atomics_cobalt_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -92,15 +93,12 @@ atomics_cobalt_device_open (dc_device_t **out, dc_context_t *context)
|
||||
|
||||
#ifdef HAVE_LIBUSB
|
||||
// Allocate memory.
|
||||
device = (atomics_cobalt_device_t *) malloc (sizeof (atomics_cobalt_device_t));
|
||||
device = (atomics_cobalt_device_t *) dc_device_allocate (context, &atomics_cobalt_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &atomics_cobalt_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->context = NULL;
|
||||
device->handle = NULL;
|
||||
@ -143,7 +141,7 @@ error_usb_close:
|
||||
error_usb_exit:
|
||||
libusb_exit (device->context);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
#else
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
|
||||
@ -50,6 +50,7 @@ static dc_status_t atomics_cobalt_parser_get_field (dc_parser_t *abstract, dc_fi
|
||||
static dc_status_t atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t atomics_cobalt_parser_vtable = {
|
||||
sizeof(atomics_cobalt_parser_t),
|
||||
DC_FAMILY_ATOMICS_COBALT,
|
||||
atomics_cobalt_parser_set_data, /* set_data */
|
||||
atomics_cobalt_parser_get_datetime, /* datetime */
|
||||
@ -62,19 +63,18 @@ static const dc_parser_vtable_t atomics_cobalt_parser_vtable = {
|
||||
dc_status_t
|
||||
atomics_cobalt_parser_create (dc_parser_t **out, dc_context_t *context)
|
||||
{
|
||||
atomics_cobalt_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
atomics_cobalt_parser_t *parser = (atomics_cobalt_parser_t *) malloc (sizeof (atomics_cobalt_parser_t));
|
||||
parser = (atomics_cobalt_parser_t *) dc_parser_allocate (context, &atomics_cobalt_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &atomics_cobalt_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
parser->atmospheric = 0.0;
|
||||
parser->hydrostatic = 1025.0 * GRAVITY;
|
||||
|
||||
@ -50,6 +50,7 @@ static dc_status_t citizen_aqualand_device_foreach (dc_device_t *abstract, dc_di
|
||||
static dc_status_t citizen_aqualand_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t citizen_aqualand_device_vtable = {
|
||||
sizeof(citizen_aqualand_device_t),
|
||||
DC_FAMILY_CITIZEN_AQUALAND,
|
||||
citizen_aqualand_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -70,15 +71,12 @@ citizen_aqualand_device_open (dc_device_t **out, dc_context_t *context, const ch
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (citizen_aqualand_device_t *) malloc (sizeof (citizen_aqualand_device_t));
|
||||
device = (citizen_aqualand_device_t *) dc_device_allocate (context, &citizen_aqualand_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &citizen_aqualand_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
@ -117,7 +115,7 @@ citizen_aqualand_device_open (dc_device_t **out, dc_context_t *context, const ch
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -42,6 +42,7 @@ static dc_status_t citizen_aqualand_parser_get_field (dc_parser_t *abstract, dc_
|
||||
static dc_status_t citizen_aqualand_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t citizen_aqualand_parser_vtable = {
|
||||
sizeof(citizen_aqualand_parser_t),
|
||||
DC_FAMILY_CITIZEN_AQUALAND,
|
||||
citizen_aqualand_parser_set_data, /* set_data */
|
||||
citizen_aqualand_parser_get_datetime, /* datetime */
|
||||
@ -54,19 +55,18 @@ static const dc_parser_vtable_t citizen_aqualand_parser_vtable = {
|
||||
dc_status_t
|
||||
citizen_aqualand_parser_create (dc_parser_t **out, dc_context_t *context)
|
||||
{
|
||||
citizen_aqualand_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
citizen_aqualand_parser_t *parser = (citizen_aqualand_parser_t *) malloc (sizeof (citizen_aqualand_parser_t));
|
||||
parser = (citizen_aqualand_parser_t *) dc_parser_allocate (context, &citizen_aqualand_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &citizen_aqualand_parser_vtable);
|
||||
|
||||
*out = (dc_parser_t*) parser;
|
||||
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
||||
@ -73,6 +73,7 @@ static dc_status_t cressi_edy_device_foreach (dc_device_t *abstract, dc_dive_cal
|
||||
static dc_status_t cressi_edy_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t cressi_edy_device_vtable = {
|
||||
sizeof(cressi_edy_device_t),
|
||||
DC_FAMILY_CRESSI_EDY,
|
||||
cressi_edy_device_set_fingerprint, /* set_fingerprint */
|
||||
cressi_edy_device_read, /* read */
|
||||
@ -243,15 +244,12 @@ cressi_edy_device_open (dc_device_t **out, dc_context_t *context, const char *na
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (cressi_edy_device_t *) malloc (sizeof (cressi_edy_device_t));
|
||||
device = (cressi_edy_device_t *) dc_device_allocate (context, &cressi_edy_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &cressi_edy_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
device->layout = NULL;
|
||||
@ -323,7 +321,7 @@ cressi_edy_device_open (dc_device_t **out, dc_context_t *context, const char *na
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -45,6 +45,7 @@ static dc_status_t cressi_edy_parser_get_field (dc_parser_t *abstract, dc_field_
|
||||
static dc_status_t cressi_edy_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t cressi_edy_parser_vtable = {
|
||||
sizeof(cressi_edy_parser_t),
|
||||
DC_FAMILY_CRESSI_EDY,
|
||||
cressi_edy_parser_set_data, /* set_data */
|
||||
cressi_edy_parser_get_datetime, /* datetime */
|
||||
@ -72,19 +73,18 @@ cressi_edy_parser_count_gasmixes (const unsigned char *data)
|
||||
dc_status_t
|
||||
cressi_edy_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
|
||||
{
|
||||
cressi_edy_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
cressi_edy_parser_t *parser = (cressi_edy_parser_t *) malloc (sizeof (cressi_edy_parser_t));
|
||||
parser = (cressi_edy_parser_t *) dc_parser_allocate (context, &cressi_edy_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &cressi_edy_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
parser->model = model;
|
||||
|
||||
|
||||
@ -62,6 +62,7 @@ static dc_status_t cressi_leonardo_device_foreach (dc_device_t *abstract, dc_div
|
||||
static dc_status_t cressi_leonardo_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t cressi_leonardo_device_vtable = {
|
||||
sizeof(cressi_leonardo_device_t),
|
||||
DC_FAMILY_CRESSI_LEONARDO,
|
||||
cressi_leonardo_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -81,15 +82,12 @@ cressi_leonardo_device_open (dc_device_t **out, dc_context_t *context, const cha
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (cressi_leonardo_device_t *) malloc (sizeof (cressi_leonardo_device_t));
|
||||
device = (cressi_leonardo_device_t *) dc_device_allocate (context, &cressi_leonardo_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &cressi_leonardo_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
@ -135,7 +133,7 @@ cressi_leonardo_device_open (dc_device_t **out, dc_context_t *context, const cha
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -43,6 +43,7 @@ static dc_status_t cressi_leonardo_parser_get_field (dc_parser_t *abstract, dc_f
|
||||
static dc_status_t cressi_leonardo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t cressi_leonardo_parser_vtable = {
|
||||
sizeof(cressi_leonardo_parser_t),
|
||||
DC_FAMILY_CRESSI_EDY,
|
||||
cressi_leonardo_parser_set_data, /* set_data */
|
||||
cressi_leonardo_parser_get_datetime, /* datetime */
|
||||
@ -55,19 +56,18 @@ static const dc_parser_vtable_t cressi_leonardo_parser_vtable = {
|
||||
dc_status_t
|
||||
cressi_leonardo_parser_create (dc_parser_t **out, dc_context_t *context)
|
||||
{
|
||||
cressi_leonardo_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
cressi_leonardo_parser_t *parser = (cressi_leonardo_parser_t *) malloc (sizeof (cressi_leonardo_parser_t));
|
||||
parser = (cressi_leonardo_parser_t *) dc_parser_allocate (context, &cressi_leonardo_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &cressi_leonardo_parser_vtable);
|
||||
|
||||
*out = (dc_parser_t*) parser;
|
||||
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
||||
@ -57,6 +57,8 @@ struct dc_device_t {
|
||||
};
|
||||
|
||||
struct dc_device_vtable_t {
|
||||
size_t size;
|
||||
|
||||
dc_family_t type;
|
||||
|
||||
dc_status_t (*set_fingerprint) (dc_device_t *device, const unsigned char data[], unsigned int size);
|
||||
@ -75,8 +77,11 @@ struct dc_device_vtable_t {
|
||||
int
|
||||
dc_device_isinstance (dc_device_t *device, const dc_device_vtable_t *vtable);
|
||||
|
||||
dc_device_t *
|
||||
dc_device_allocate (dc_context_t *context, const dc_device_vtable_t *vtable);
|
||||
|
||||
void
|
||||
device_init (dc_device_t *device, dc_context_t *context, const dc_device_vtable_t *vtable);
|
||||
dc_device_deallocate (dc_device_t *device);
|
||||
|
||||
void
|
||||
device_event_emit (dc_device_t *device, dc_event_type_t event, const void *data);
|
||||
|
||||
27
src/device.c
27
src/device.c
@ -40,10 +40,21 @@
|
||||
#include "device-private.h"
|
||||
#include "context-private.h"
|
||||
|
||||
|
||||
void
|
||||
device_init (dc_device_t *device, dc_context_t *context, const dc_device_vtable_t *vtable)
|
||||
dc_device_t *
|
||||
dc_device_allocate (dc_context_t *context, const dc_device_vtable_t *vtable)
|
||||
{
|
||||
dc_device_t *device = NULL;
|
||||
|
||||
assert(vtable != NULL);
|
||||
assert(vtable->size >= sizeof(dc_device_t));
|
||||
|
||||
// Allocate memory.
|
||||
device = (dc_device_t *) malloc (vtable->size);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return device;
|
||||
}
|
||||
|
||||
device->vtable = vtable;
|
||||
|
||||
device->context = context;
|
||||
@ -57,6 +68,14 @@ device_init (dc_device_t *device, dc_context_t *context, const dc_device_vtable_
|
||||
|
||||
memset (&device->devinfo, 0, sizeof (device->devinfo));
|
||||
memset (&device->clock, 0, sizeof (device->clock));
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
void
|
||||
dc_device_deallocate (dc_device_t *device)
|
||||
{
|
||||
free (device);
|
||||
}
|
||||
|
||||
dc_status_t
|
||||
@ -340,7 +359,7 @@ dc_device_close (dc_device_t *device)
|
||||
status = device->vtable->close (device);
|
||||
}
|
||||
|
||||
free (device);
|
||||
dc_device_deallocate (device);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -68,6 +68,7 @@ static dc_status_t diverite_nitekq_device_foreach (dc_device_t *abstract, dc_div
|
||||
static dc_status_t diverite_nitekq_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t diverite_nitekq_device_vtable = {
|
||||
sizeof(diverite_nitekq_device_t),
|
||||
DC_FAMILY_DIVERITE_NITEKQ,
|
||||
diverite_nitekq_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -156,15 +157,12 @@ diverite_nitekq_device_open (dc_device_t **out, dc_context_t *context, const cha
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (diverite_nitekq_device_t *) malloc (sizeof (diverite_nitekq_device_t));
|
||||
device = (diverite_nitekq_device_t *) dc_device_allocate (context, &diverite_nitekq_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &diverite_nitekq_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
@ -210,7 +208,7 @@ diverite_nitekq_device_open (dc_device_t **out, dc_context_t *context, const cha
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -54,6 +54,7 @@ static dc_status_t diverite_nitekq_parser_get_field (dc_parser_t *abstract, dc_f
|
||||
static dc_status_t diverite_nitekq_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t diverite_nitekq_parser_vtable = {
|
||||
sizeof(diverite_nitekq_parser_t),
|
||||
DC_FAMILY_DIVERITE_NITEKQ,
|
||||
diverite_nitekq_parser_set_data, /* set_data */
|
||||
diverite_nitekq_parser_get_datetime, /* datetime */
|
||||
@ -66,19 +67,18 @@ static const dc_parser_vtable_t diverite_nitekq_parser_vtable = {
|
||||
dc_status_t
|
||||
diverite_nitekq_parser_create (dc_parser_t **out, dc_context_t *context)
|
||||
{
|
||||
diverite_nitekq_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
diverite_nitekq_parser_t *parser = (diverite_nitekq_parser_t *) malloc (sizeof (diverite_nitekq_parser_t));
|
||||
parser = (diverite_nitekq_parser_t *) dc_parser_allocate (context, &diverite_nitekq_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &diverite_nitekq_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
parser->cached = 0;
|
||||
parser->metric = 0;
|
||||
|
||||
@ -77,6 +77,7 @@ static dc_status_t divesystem_idive_device_foreach (dc_device_t *abstract, dc_di
|
||||
static dc_status_t divesystem_idive_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t divesystem_idive_device_vtable = {
|
||||
sizeof(divesystem_idive_device_t),
|
||||
DC_FAMILY_DIVESYSTEM_IDIVE,
|
||||
divesystem_idive_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -117,15 +118,12 @@ divesystem_idive_device_open2 (dc_device_t **out, dc_context_t *context, const c
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (divesystem_idive_device_t *) malloc (sizeof (divesystem_idive_device_t));
|
||||
device = (divesystem_idive_device_t *) dc_device_allocate (context, &divesystem_idive_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &divesystem_idive_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
@ -165,7 +163,7 @@ divesystem_idive_device_open2 (dc_device_t **out, dc_context_t *context, const c
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -64,6 +64,7 @@ static dc_status_t divesystem_idive_parser_get_field (dc_parser_t *abstract, dc_
|
||||
static dc_status_t divesystem_idive_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t divesystem_idive_parser_vtable = {
|
||||
sizeof(divesystem_idive_parser_t),
|
||||
DC_FAMILY_DIVESYSTEM_IDIVE,
|
||||
divesystem_idive_parser_set_data, /* set_data */
|
||||
divesystem_idive_parser_get_datetime, /* datetime */
|
||||
@ -83,19 +84,18 @@ divesystem_idive_parser_create (dc_parser_t **out, dc_context_t *context)
|
||||
dc_status_t
|
||||
divesystem_idive_parser_create2 (dc_parser_t **out, dc_context_t *context, unsigned int model)
|
||||
{
|
||||
divesystem_idive_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
divesystem_idive_parser_t *parser = (divesystem_idive_parser_t *) malloc (sizeof (divesystem_idive_parser_t));
|
||||
parser = (divesystem_idive_parser_t *) dc_parser_allocate (context, &divesystem_idive_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &divesystem_idive_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
if (model >= IX3M_EASY && model <= IX3M_REB) {
|
||||
parser->headersize = SZ_HEADER_IX3M;
|
||||
|
||||
@ -70,6 +70,7 @@ static dc_status_t hw_frog_device_foreach (dc_device_t *abstract, dc_dive_callba
|
||||
static dc_status_t hw_frog_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t hw_frog_device_vtable = {
|
||||
sizeof(hw_frog_device_t),
|
||||
DC_FAMILY_HW_FROG,
|
||||
hw_frog_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -209,15 +210,12 @@ hw_frog_device_open (dc_device_t **out, dc_context_t *context, const char *name)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (hw_frog_device_t *) malloc (sizeof (hw_frog_device_t));
|
||||
device = (hw_frog_device_t *) dc_device_allocate (context, &hw_frog_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &hw_frog_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
@ -263,7 +261,7 @@ hw_frog_device_open (dc_device_t **out, dc_context_t *context, const char *name)
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -79,6 +79,7 @@ static dc_status_t hw_ostc_device_foreach (dc_device_t *abstract, dc_dive_callba
|
||||
static dc_status_t hw_ostc_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t hw_ostc_device_vtable = {
|
||||
sizeof(hw_ostc_device_t),
|
||||
DC_FAMILY_HW_OSTC,
|
||||
hw_ostc_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -132,15 +133,12 @@ hw_ostc_device_open (dc_device_t **out, dc_context_t *context, const char *name)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (hw_ostc_device_t *) malloc (sizeof (hw_ostc_device_t));
|
||||
device = (hw_ostc_device_t *) dc_device_allocate (context, &hw_ostc_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &hw_ostc_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
@ -179,7 +177,7 @@ hw_ostc_device_open (dc_device_t **out, dc_context_t *context, const char *name)
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -123,6 +123,7 @@ static dc_status_t hw_ostc3_device_foreach (dc_device_t *abstract, dc_dive_callb
|
||||
static dc_status_t hw_ostc3_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t hw_ostc3_device_vtable = {
|
||||
sizeof(hw_ostc3_device_t),
|
||||
DC_FAMILY_HW_OSTC3,
|
||||
hw_ostc3_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -282,15 +283,12 @@ hw_ostc3_device_open (dc_device_t **out, dc_context_t *context, const char *name
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (hw_ostc3_device_t *) malloc (sizeof (hw_ostc3_device_t));
|
||||
device = (hw_ostc3_device_t *) dc_device_allocate (context, &hw_ostc3_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &hw_ostc3_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
@ -331,7 +329,7 @@ hw_ostc3_device_open (dc_device_t **out, dc_context_t *context, const char *name
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -99,6 +99,7 @@ static dc_status_t hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_typ
|
||||
static dc_status_t hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t hw_ostc_parser_vtable = {
|
||||
sizeof(hw_ostc_parser_t),
|
||||
DC_FAMILY_HW_OSTC,
|
||||
hw_ostc_parser_set_data, /* set_data */
|
||||
hw_ostc_parser_get_datetime, /* datetime */
|
||||
@ -266,19 +267,18 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser)
|
||||
dc_status_t
|
||||
hw_ostc_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int frog)
|
||||
{
|
||||
hw_ostc_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
hw_ostc_parser_t *parser = (hw_ostc_parser_t *) malloc (sizeof (hw_ostc_parser_t));
|
||||
parser = (hw_ostc_parser_t *) dc_parser_allocate (context, &hw_ostc_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &hw_ostc_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
parser->frog = frog;
|
||||
parser->cached = 0;
|
||||
|
||||
@ -52,13 +52,10 @@
|
||||
#define GAUGE 3
|
||||
|
||||
void
|
||||
mares_common_device_init (mares_common_device_t *device, dc_context_t *context, const dc_device_vtable_t *vtable)
|
||||
mares_common_device_init (mares_common_device_t *device)
|
||||
{
|
||||
assert (device != NULL);
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
device->echo = 0;
|
||||
|
||||
@ -47,7 +47,7 @@ typedef struct mares_common_device_t {
|
||||
} mares_common_device_t;
|
||||
|
||||
void
|
||||
mares_common_device_init (mares_common_device_t *device, dc_context_t *context, const dc_device_vtable_t *vtable);
|
||||
mares_common_device_init (mares_common_device_t *device);
|
||||
|
||||
dc_status_t
|
||||
mares_common_device_read (dc_device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||
|
||||
@ -63,6 +63,7 @@ static dc_status_t mares_darwin_device_foreach (dc_device_t *abstract, dc_dive_c
|
||||
static dc_status_t mares_darwin_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t mares_darwin_device_vtable = {
|
||||
sizeof(mares_darwin_device_t),
|
||||
DC_FAMILY_MARES_DARWIN,
|
||||
mares_darwin_device_set_fingerprint, /* set_fingerprint */
|
||||
mares_common_device_read, /* read */
|
||||
@ -103,14 +104,14 @@ mares_darwin_device_open (dc_device_t **out, dc_context_t *context, const char *
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (mares_darwin_device_t *) malloc (sizeof (mares_darwin_device_t));
|
||||
device = (mares_darwin_device_t *) dc_device_allocate (context, &mares_darwin_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
mares_common_device_init (&device->base, context, &mares_darwin_device_vtable);
|
||||
mares_common_device_init (&device->base);
|
||||
|
||||
// Set the default values.
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
@ -166,7 +167,7 @@ mares_darwin_device_open (dc_device_t **out, dc_context_t *context, const char *
|
||||
error_close:
|
||||
serial_close (device->base.port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -49,6 +49,7 @@ static dc_status_t mares_darwin_parser_get_field (dc_parser_t *abstract, dc_fiel
|
||||
static dc_status_t mares_darwin_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t mares_darwin_parser_vtable = {
|
||||
sizeof(mares_darwin_parser_t),
|
||||
DC_FAMILY_MARES_DARWIN,
|
||||
mares_darwin_parser_set_data, /* set_data */
|
||||
mares_darwin_parser_get_datetime, /* datetime */
|
||||
@ -61,19 +62,18 @@ static const dc_parser_vtable_t mares_darwin_parser_vtable = {
|
||||
dc_status_t
|
||||
mares_darwin_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
|
||||
{
|
||||
mares_darwin_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
mares_darwin_parser_t *parser = (mares_darwin_parser_t *) malloc (sizeof (mares_darwin_parser_t));
|
||||
parser = (mares_darwin_parser_t *) dc_parser_allocate (context, &mares_darwin_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &mares_darwin_parser_vtable);
|
||||
|
||||
parser->model = model;
|
||||
|
||||
if (model == DARWINAIR) {
|
||||
|
||||
@ -84,6 +84,7 @@ static dc_status_t mares_iconhd_device_foreach (dc_device_t *abstract, dc_dive_c
|
||||
static dc_status_t mares_iconhd_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t mares_iconhd_device_vtable = {
|
||||
sizeof(mares_iconhd_device_t),
|
||||
DC_FAMILY_MARES_ICONHD,
|
||||
mares_iconhd_device_set_fingerprint, /* set_fingerprint */
|
||||
mares_iconhd_device_read, /* read */
|
||||
@ -221,15 +222,12 @@ mares_iconhd_device_open (dc_device_t **out, dc_context_t *context, const char *
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (mares_iconhd_device_t *) malloc (sizeof (mares_iconhd_device_t));
|
||||
device = (mares_iconhd_device_t *) dc_device_allocate (context, &mares_iconhd_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &mares_iconhd_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
device->layout = NULL;
|
||||
@ -316,7 +314,7 @@ mares_iconhd_device_open (dc_device_t **out, dc_context_t *context, const char *
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -62,6 +62,7 @@ static dc_status_t mares_iconhd_parser_get_field (dc_parser_t *abstract, dc_fiel
|
||||
static dc_status_t mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t mares_iconhd_parser_vtable = {
|
||||
sizeof(mares_iconhd_parser_t),
|
||||
DC_FAMILY_MARES_ICONHD,
|
||||
mares_iconhd_parser_set_data, /* set_data */
|
||||
mares_iconhd_parser_get_datetime, /* datetime */
|
||||
@ -197,19 +198,18 @@ mares_iconhd_parser_cache (mares_iconhd_parser_t *parser)
|
||||
dc_status_t
|
||||
mares_iconhd_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
|
||||
{
|
||||
mares_iconhd_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
mares_iconhd_parser_t *parser = (mares_iconhd_parser_t *) malloc (sizeof (mares_iconhd_parser_t));
|
||||
parser = (mares_iconhd_parser_t *) dc_parser_allocate (context, &mares_iconhd_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &mares_iconhd_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
parser->model = model;
|
||||
parser->cached = 0;
|
||||
|
||||
@ -61,6 +61,7 @@ static dc_status_t mares_nemo_device_foreach (dc_device_t *abstract, dc_dive_cal
|
||||
static dc_status_t mares_nemo_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t mares_nemo_device_vtable = {
|
||||
sizeof(mares_nemo_device_t),
|
||||
DC_FAMILY_MARES_NEMO,
|
||||
mares_nemo_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -97,15 +98,12 @@ mares_nemo_device_open (dc_device_t **out, dc_context_t *context, const char *na
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (mares_nemo_device_t *) malloc (sizeof (mares_nemo_device_t));
|
||||
device = (mares_nemo_device_t *) dc_device_allocate (context, &mares_nemo_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &mares_nemo_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
@ -151,7 +149,7 @@ mares_nemo_device_open (dc_device_t **out, dc_context_t *context, const char *na
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -65,6 +65,7 @@ static dc_status_t mares_nemo_parser_get_field (dc_parser_t *abstract, dc_field_
|
||||
static dc_status_t mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t mares_nemo_parser_vtable = {
|
||||
sizeof(mares_nemo_parser_t),
|
||||
DC_FAMILY_MARES_NEMO,
|
||||
mares_nemo_parser_set_data, /* set_data */
|
||||
mares_nemo_parser_get_datetime, /* datetime */
|
||||
@ -77,19 +78,18 @@ static const dc_parser_vtable_t mares_nemo_parser_vtable = {
|
||||
dc_status_t
|
||||
mares_nemo_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
|
||||
{
|
||||
mares_nemo_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
mares_nemo_parser_t *parser = (mares_nemo_parser_t *) malloc (sizeof (mares_nemo_parser_t));
|
||||
parser = (mares_nemo_parser_t *) dc_parser_allocate (context, &mares_nemo_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &mares_nemo_parser_vtable);
|
||||
|
||||
// Get the freedive mode for this model.
|
||||
unsigned int freedive = FREEDIVE;
|
||||
if (model == NEMOWIDE || model == NEMOAIR || model == PUCK || model == PUCKAIR)
|
||||
|
||||
@ -51,6 +51,7 @@ static dc_status_t mares_puck_device_foreach (dc_device_t *abstract, dc_dive_cal
|
||||
static dc_status_t mares_puck_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t mares_puck_device_vtable = {
|
||||
sizeof(mares_puck_device_t),
|
||||
DC_FAMILY_MARES_PUCK,
|
||||
mares_puck_device_set_fingerprint, /* set_fingerprint */
|
||||
mares_common_device_read, /* read */
|
||||
@ -95,14 +96,14 @@ mares_puck_device_open (dc_device_t **out, dc_context_t *context, const char *na
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (mares_puck_device_t *) malloc (sizeof (mares_puck_device_t));
|
||||
device = (mares_puck_device_t *) dc_device_allocate (context, &mares_puck_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
mares_common_device_init (&device->base, context, &mares_puck_device_vtable);
|
||||
mares_common_device_init (&device->base);
|
||||
|
||||
// Set the default values.
|
||||
device->layout = NULL;
|
||||
@ -173,7 +174,7 @@ mares_puck_device_open (dc_device_t **out, dc_context_t *context, const char *na
|
||||
error_close:
|
||||
serial_close (device->base.port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -71,6 +71,7 @@ static dc_status_t oceanic_atom2_device_write (dc_device_t *abstract, unsigned i
|
||||
static dc_status_t oceanic_atom2_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t oceanic_atom2_device_vtable = {
|
||||
sizeof(oceanic_atom2_device_t),
|
||||
DC_FAMILY_OCEANIC_ATOM2,
|
||||
oceanic_common_device_set_fingerprint, /* set_fingerprint */
|
||||
oceanic_atom2_device_read, /* read */
|
||||
@ -528,14 +529,14 @@ oceanic_atom2_device_open2 (dc_device_t **out, dc_context_t *context, const char
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (oceanic_atom2_device_t *) malloc (sizeof (oceanic_atom2_device_t));
|
||||
device = (oceanic_atom2_device_t *) dc_device_allocate (context, &oceanic_atom2_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
oceanic_common_device_init (&device->base, context, &oceanic_atom2_device_vtable);
|
||||
oceanic_common_device_init (&device->base);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
@ -643,7 +644,7 @@ oceanic_atom2_device_open2 (dc_device_t **out, dc_context_t *context, const char
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -109,6 +109,7 @@ static dc_status_t oceanic_atom2_parser_get_field (dc_parser_t *abstract, dc_fie
|
||||
static dc_status_t oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t oceanic_atom2_parser_vtable = {
|
||||
sizeof(oceanic_atom2_parser_t),
|
||||
DC_FAMILY_OCEANIC_ATOM2,
|
||||
oceanic_atom2_parser_set_data, /* set_data */
|
||||
oceanic_atom2_parser_get_datetime, /* datetime */
|
||||
@ -121,19 +122,18 @@ static const dc_parser_vtable_t oceanic_atom2_parser_vtable = {
|
||||
dc_status_t
|
||||
oceanic_atom2_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
|
||||
{
|
||||
oceanic_atom2_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
oceanic_atom2_parser_t *parser = (oceanic_atom2_parser_t *) malloc (sizeof (oceanic_atom2_parser_t));
|
||||
parser = (oceanic_atom2_parser_t *) dc_parser_allocate (context, &oceanic_atom2_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &oceanic_atom2_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
parser->model = model;
|
||||
parser->headersize = 9 * PAGESIZE / 2;
|
||||
|
||||
@ -125,13 +125,10 @@ oceanic_common_match (const unsigned char *version, const oceanic_common_version
|
||||
|
||||
|
||||
void
|
||||
oceanic_common_device_init (oceanic_common_device_t *device, dc_context_t *context, const dc_device_vtable_t *vtable)
|
||||
oceanic_common_device_init (oceanic_common_device_t *device)
|
||||
{
|
||||
assert (device != NULL);
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, vtable);
|
||||
|
||||
// Set the default values.
|
||||
memset (device->version, 0, sizeof (device->version));
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
|
||||
@ -71,7 +71,7 @@ int
|
||||
oceanic_common_match (const unsigned char *version, const oceanic_common_version_t patterns[], unsigned int n);
|
||||
|
||||
void
|
||||
oceanic_common_device_init (oceanic_common_device_t *device, dc_context_t *context, const dc_device_vtable_t *vtable);
|
||||
oceanic_common_device_init (oceanic_common_device_t *device);
|
||||
|
||||
dc_status_t
|
||||
oceanic_common_device_set_fingerprint (dc_device_t *device, const unsigned char data[], unsigned int size);
|
||||
|
||||
@ -54,6 +54,7 @@ static dc_status_t oceanic_veo250_device_read (dc_device_t *abstract, unsigned i
|
||||
static dc_status_t oceanic_veo250_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t oceanic_veo250_device_vtable = {
|
||||
sizeof(oceanic_veo250_device_t),
|
||||
DC_FAMILY_OCEANIC_VEO250,
|
||||
oceanic_common_device_set_fingerprint, /* set_fingerprint */
|
||||
oceanic_veo250_device_read, /* read */
|
||||
@ -228,14 +229,14 @@ oceanic_veo250_device_open (dc_device_t **out, dc_context_t *context, const char
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (oceanic_veo250_device_t *) malloc (sizeof (oceanic_veo250_device_t));
|
||||
device = (oceanic_veo250_device_t *) dc_device_allocate (context, &oceanic_veo250_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
oceanic_common_device_init (&device->base, context, &oceanic_veo250_device_vtable);
|
||||
oceanic_common_device_init (&device->base);
|
||||
|
||||
// Override the base class values.
|
||||
device->base.layout = &oceanic_veo250_layout;
|
||||
@ -306,7 +307,7 @@ oceanic_veo250_device_open (dc_device_t **out, dc_context_t *context, const char
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -53,6 +53,7 @@ static dc_status_t oceanic_veo250_parser_get_field (dc_parser_t *abstract, dc_fi
|
||||
static dc_status_t oceanic_veo250_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t oceanic_veo250_parser_vtable = {
|
||||
sizeof(oceanic_veo250_parser_t),
|
||||
DC_FAMILY_OCEANIC_VEO250,
|
||||
oceanic_veo250_parser_set_data, /* set_data */
|
||||
oceanic_veo250_parser_get_datetime, /* datetime */
|
||||
@ -65,19 +66,18 @@ static const dc_parser_vtable_t oceanic_veo250_parser_vtable = {
|
||||
dc_status_t
|
||||
oceanic_veo250_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
|
||||
{
|
||||
oceanic_veo250_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
oceanic_veo250_parser_t *parser = (oceanic_veo250_parser_t *) malloc (sizeof (oceanic_veo250_parser_t));
|
||||
parser = (oceanic_veo250_parser_t *) dc_parser_allocate (context, &oceanic_veo250_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &oceanic_veo250_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
parser->model = model;
|
||||
parser->cached = 0;
|
||||
|
||||
@ -54,6 +54,7 @@ static dc_status_t oceanic_vtpro_device_read (dc_device_t *abstract, unsigned in
|
||||
static dc_status_t oceanic_vtpro_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t oceanic_vtpro_device_vtable = {
|
||||
sizeof(oceanic_vtpro_device_t),
|
||||
DC_FAMILY_OCEANIC_VTPRO,
|
||||
oceanic_common_device_set_fingerprint, /* set_fingerprint */
|
||||
oceanic_vtpro_device_read, /* read */
|
||||
@ -261,14 +262,14 @@ oceanic_vtpro_device_open (dc_device_t **out, dc_context_t *context, const char
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (oceanic_vtpro_device_t *) malloc (sizeof (oceanic_vtpro_device_t));
|
||||
device = (oceanic_vtpro_device_t *) dc_device_allocate (context, &oceanic_vtpro_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
oceanic_common_device_init (&device->base, context, &oceanic_vtpro_device_vtable);
|
||||
oceanic_common_device_init (&device->base);
|
||||
|
||||
// Override the base class values.
|
||||
device->base.multipage = MULTIPAGE;
|
||||
@ -349,7 +350,7 @@ oceanic_vtpro_device_open (dc_device_t **out, dc_context_t *context, const char
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -47,6 +47,7 @@ static dc_status_t oceanic_vtpro_parser_get_field (dc_parser_t *abstract, dc_fie
|
||||
static dc_status_t oceanic_vtpro_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t oceanic_vtpro_parser_vtable = {
|
||||
sizeof(oceanic_vtpro_parser_t),
|
||||
DC_FAMILY_OCEANIC_VTPRO,
|
||||
oceanic_vtpro_parser_set_data, /* set_data */
|
||||
oceanic_vtpro_parser_get_datetime, /* datetime */
|
||||
@ -59,19 +60,18 @@ static const dc_parser_vtable_t oceanic_vtpro_parser_vtable = {
|
||||
dc_status_t
|
||||
oceanic_vtpro_parser_create (dc_parser_t **out, dc_context_t *context)
|
||||
{
|
||||
oceanic_vtpro_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
oceanic_vtpro_parser_t *parser = (oceanic_vtpro_parser_t *) malloc (sizeof (oceanic_vtpro_parser_t));
|
||||
parser = (oceanic_vtpro_parser_t *) dc_parser_allocate (context, &oceanic_vtpro_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &oceanic_vtpro_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
parser->cached = 0;
|
||||
parser->divetime = 0;
|
||||
|
||||
@ -42,6 +42,8 @@ struct dc_parser_t {
|
||||
};
|
||||
|
||||
struct dc_parser_vtable_t {
|
||||
size_t size;
|
||||
|
||||
dc_family_t type;
|
||||
|
||||
dc_status_t (*set_data) (dc_parser_t *parser, const unsigned char *data, unsigned int size);
|
||||
@ -55,8 +57,11 @@ struct dc_parser_vtable_t {
|
||||
dc_status_t (*destroy) (dc_parser_t *parser);
|
||||
};
|
||||
|
||||
dc_parser_t *
|
||||
dc_parser_allocate (dc_context_t *context, const dc_parser_vtable_t *vtable);
|
||||
|
||||
void
|
||||
parser_init (dc_parser_t *parser, dc_context_t *context, const dc_parser_vtable_t *vtable);
|
||||
dc_parser_deallocate (dc_parser_t *parser);
|
||||
|
||||
int
|
||||
dc_parser_isinstance (dc_parser_t *parser, const dc_parser_vtable_t *vtable);
|
||||
|
||||
28
src/parser.c
28
src/parser.c
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <libdivecomputer/suunto.h>
|
||||
#include <libdivecomputer/reefnet.h>
|
||||
@ -35,6 +36,7 @@
|
||||
#include <libdivecomputer/citizen.h>
|
||||
#include <libdivecomputer/divesystem.h>
|
||||
|
||||
#include "context-private.h"
|
||||
#include "parser-private.h"
|
||||
#include "device-private.h"
|
||||
|
||||
@ -152,15 +154,35 @@ dc_parser_new (dc_parser_t **out, dc_device_t *device)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
parser_init (dc_parser_t *parser, dc_context_t *context, const dc_parser_vtable_t *vtable)
|
||||
dc_parser_t *
|
||||
dc_parser_allocate (dc_context_t *context, const dc_parser_vtable_t *vtable)
|
||||
{
|
||||
dc_parser_t *parser = NULL;
|
||||
|
||||
assert(vtable != NULL);
|
||||
assert(vtable->size >= sizeof(dc_parser_t));
|
||||
|
||||
// Allocate memory.
|
||||
parser = (dc_parser_t *) malloc (vtable->size);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return parser;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser->vtable = vtable;
|
||||
parser->context = context;
|
||||
parser->data = NULL;
|
||||
parser->size = 0;
|
||||
|
||||
return parser;
|
||||
}
|
||||
|
||||
void
|
||||
dc_parser_deallocate (dc_parser_t *parser)
|
||||
{
|
||||
free (parser);
|
||||
}
|
||||
|
||||
int
|
||||
dc_parser_isinstance (dc_parser_t *parser, const dc_parser_vtable_t *vtable)
|
||||
@ -248,7 +270,7 @@ dc_parser_destroy (dc_parser_t *parser)
|
||||
status = parser->vtable->destroy (parser);
|
||||
}
|
||||
|
||||
free (parser);
|
||||
dc_parser_deallocate (parser);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -56,6 +56,7 @@ static dc_status_t reefnet_sensus_device_foreach (dc_device_t *abstract, dc_dive
|
||||
static dc_status_t reefnet_sensus_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t reefnet_sensus_device_vtable = {
|
||||
sizeof(reefnet_sensus_device_t),
|
||||
DC_FAMILY_REEFNET_SENSUS,
|
||||
reefnet_sensus_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -96,15 +97,12 @@ reefnet_sensus_device_open (dc_device_t **out, dc_context_t *context, const char
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (reefnet_sensus_device_t *) malloc (sizeof (reefnet_sensus_device_t));
|
||||
device = (reefnet_sensus_device_t *) dc_device_allocate (context, &reefnet_sensus_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &reefnet_sensus_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
device->waiting = 0;
|
||||
@ -146,7 +144,7 @@ reefnet_sensus_device_open (dc_device_t **out, dc_context_t *context, const char
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -54,6 +54,7 @@ static dc_status_t reefnet_sensus_parser_get_field (dc_parser_t *abstract, dc_fi
|
||||
static dc_status_t reefnet_sensus_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t reefnet_sensus_parser_vtable = {
|
||||
sizeof(reefnet_sensus_parser_t),
|
||||
DC_FAMILY_REEFNET_SENSUS,
|
||||
reefnet_sensus_parser_set_data, /* set_data */
|
||||
reefnet_sensus_parser_get_datetime, /* datetime */
|
||||
@ -66,19 +67,18 @@ static const dc_parser_vtable_t reefnet_sensus_parser_vtable = {
|
||||
dc_status_t
|
||||
reefnet_sensus_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int devtime, dc_ticks_t systime)
|
||||
{
|
||||
reefnet_sensus_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
reefnet_sensus_parser_t *parser = (reefnet_sensus_parser_t *) malloc (sizeof (reefnet_sensus_parser_t));
|
||||
parser = (reefnet_sensus_parser_t *) dc_parser_allocate (context, &reefnet_sensus_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &reefnet_sensus_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
parser->atmospheric = ATM;
|
||||
parser->hydrostatic = 1025.0 * GRAVITY;
|
||||
|
||||
@ -55,6 +55,7 @@ static dc_status_t reefnet_sensuspro_device_foreach (dc_device_t *abstract, dc_d
|
||||
static dc_status_t reefnet_sensuspro_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t reefnet_sensuspro_device_vtable = {
|
||||
sizeof(reefnet_sensuspro_device_t),
|
||||
DC_FAMILY_REEFNET_SENSUSPRO,
|
||||
reefnet_sensuspro_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -75,15 +76,12 @@ reefnet_sensuspro_device_open (dc_device_t **out, dc_context_t *context, const c
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (reefnet_sensuspro_device_t *) malloc (sizeof (reefnet_sensuspro_device_t));
|
||||
device = (reefnet_sensuspro_device_t *) dc_device_allocate (context, &reefnet_sensuspro_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &reefnet_sensuspro_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
device->timestamp = 0;
|
||||
@ -124,7 +122,7 @@ reefnet_sensuspro_device_open (dc_device_t **out, dc_context_t *context, const c
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -53,6 +53,7 @@ static dc_status_t reefnet_sensuspro_parser_get_field (dc_parser_t *abstract, dc
|
||||
static dc_status_t reefnet_sensuspro_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t reefnet_sensuspro_parser_vtable = {
|
||||
sizeof(reefnet_sensuspro_parser_t),
|
||||
DC_FAMILY_REEFNET_SENSUSPRO,
|
||||
reefnet_sensuspro_parser_set_data, /* set_data */
|
||||
reefnet_sensuspro_parser_get_datetime, /* datetime */
|
||||
@ -65,19 +66,18 @@ static const dc_parser_vtable_t reefnet_sensuspro_parser_vtable = {
|
||||
dc_status_t
|
||||
reefnet_sensuspro_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int devtime, dc_ticks_t systime)
|
||||
{
|
||||
reefnet_sensuspro_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
reefnet_sensuspro_parser_t *parser = (reefnet_sensuspro_parser_t *) malloc (sizeof (reefnet_sensuspro_parser_t));
|
||||
parser = (reefnet_sensuspro_parser_t *) dc_parser_allocate (context, &reefnet_sensuspro_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &reefnet_sensuspro_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
parser->atmospheric = ATM;
|
||||
parser->hydrostatic = 1025.0 * GRAVITY;
|
||||
|
||||
@ -64,6 +64,7 @@ static dc_status_t reefnet_sensusultra_device_foreach (dc_device_t *abstract, dc
|
||||
static dc_status_t reefnet_sensusultra_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t reefnet_sensusultra_device_vtable = {
|
||||
sizeof(reefnet_sensusultra_device_t),
|
||||
DC_FAMILY_REEFNET_SENSUSULTRA,
|
||||
reefnet_sensusultra_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -84,15 +85,12 @@ reefnet_sensusultra_device_open (dc_device_t **out, dc_context_t *context, const
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (reefnet_sensusultra_device_t *) malloc (sizeof (reefnet_sensusultra_device_t));
|
||||
device = (reefnet_sensusultra_device_t *) dc_device_allocate (context, &reefnet_sensusultra_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &reefnet_sensusultra_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
device->timestamp = 0;
|
||||
@ -133,7 +131,7 @@ reefnet_sensusultra_device_open (dc_device_t **out, dc_context_t *context, const
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -53,6 +53,7 @@ static dc_status_t reefnet_sensusultra_parser_get_field (dc_parser_t *abstract,
|
||||
static dc_status_t reefnet_sensusultra_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t reefnet_sensusultra_parser_vtable = {
|
||||
sizeof(reefnet_sensusultra_parser_t),
|
||||
DC_FAMILY_REEFNET_SENSUSULTRA,
|
||||
reefnet_sensusultra_parser_set_data, /* set_data */
|
||||
reefnet_sensusultra_parser_get_datetime, /* datetime */
|
||||
@ -65,19 +66,18 @@ static const dc_parser_vtable_t reefnet_sensusultra_parser_vtable = {
|
||||
dc_status_t
|
||||
reefnet_sensusultra_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int devtime, dc_ticks_t systime)
|
||||
{
|
||||
reefnet_sensusultra_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
reefnet_sensusultra_parser_t *parser = (reefnet_sensusultra_parser_t *) malloc (sizeof (reefnet_sensusultra_parser_t));
|
||||
parser = (reefnet_sensusultra_parser_t *) dc_parser_allocate (context, &reefnet_sensusultra_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &reefnet_sensusultra_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
parser->atmospheric = ATM;
|
||||
parser->hydrostatic = 1025.0 * GRAVITY;
|
||||
|
||||
@ -51,6 +51,7 @@ static dc_status_t shearwater_petrel_device_foreach (dc_device_t *abstract, dc_d
|
||||
static dc_status_t shearwater_petrel_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t shearwater_petrel_device_vtable = {
|
||||
sizeof(shearwater_petrel_device_t),
|
||||
DC_FAMILY_SHEARWATER_PETREL,
|
||||
shearwater_petrel_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -86,15 +87,12 @@ shearwater_petrel_device_open (dc_device_t **out, dc_context_t *context, const c
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (shearwater_petrel_device_t *) malloc (sizeof (shearwater_petrel_device_t));
|
||||
device = (shearwater_petrel_device_t *) dc_device_allocate (context, &shearwater_petrel_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base.base, context, &shearwater_petrel_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
|
||||
@ -109,7 +107,7 @@ shearwater_petrel_device_open (dc_device_t **out, dc_context_t *context, const c
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -52,6 +52,7 @@ static dc_status_t shearwater_predator_device_foreach (dc_device_t *abstract, dc
|
||||
static dc_status_t shearwater_predator_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t shearwater_predator_device_vtable = {
|
||||
sizeof(shearwater_predator_device_t),
|
||||
DC_FAMILY_SHEARWATER_PREDATOR,
|
||||
shearwater_predator_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -72,15 +73,12 @@ shearwater_predator_device_open (dc_device_t **out, dc_context_t *context, const
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (shearwater_predator_device_t *) malloc (sizeof (shearwater_predator_device_t));
|
||||
device = (shearwater_predator_device_t *) dc_device_allocate (context, &shearwater_predator_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base.base, context, &shearwater_predator_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
|
||||
@ -95,7 +93,7 @@ shearwater_predator_device_open (dc_device_t **out, dc_context_t *context, const
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -69,6 +69,7 @@ static dc_status_t shearwater_predator_parser_get_field (dc_parser_t *abstract,
|
||||
static dc_status_t shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t shearwater_predator_parser_vtable = {
|
||||
sizeof(shearwater_predator_parser_t),
|
||||
DC_FAMILY_SHEARWATER_PREDATOR,
|
||||
shearwater_predator_parser_set_data, /* set_data */
|
||||
shearwater_predator_parser_get_datetime, /* datetime */
|
||||
@ -78,6 +79,7 @@ static const dc_parser_vtable_t shearwater_predator_parser_vtable = {
|
||||
};
|
||||
|
||||
static const dc_parser_vtable_t shearwater_petrel_parser_vtable = {
|
||||
sizeof(shearwater_predator_parser_t),
|
||||
DC_FAMILY_SHEARWATER_PETREL,
|
||||
shearwater_predator_parser_set_data, /* set_data */
|
||||
shearwater_predator_parser_get_datetime, /* datetime */
|
||||
@ -104,27 +106,31 @@ shearwater_predator_find_gasmix (shearwater_predator_parser_t *parser, unsigned
|
||||
dc_status_t
|
||||
shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int petrel)
|
||||
{
|
||||
shearwater_predator_parser_t *parser = NULL;
|
||||
const dc_parser_vtable_t *vtable = NULL;
|
||||
unsigned int samplesize = 0;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
if (petrel) {
|
||||
vtable = &shearwater_petrel_parser_vtable;
|
||||
samplesize = SZ_SAMPLE_PETREL;
|
||||
} else {
|
||||
vtable = &shearwater_predator_parser_vtable;
|
||||
samplesize = SZ_SAMPLE_PREDATOR;
|
||||
}
|
||||
|
||||
// Allocate memory.
|
||||
shearwater_predator_parser_t *parser = (shearwater_predator_parser_t *) malloc (sizeof (shearwater_predator_parser_t));
|
||||
parser = (shearwater_predator_parser_t *) dc_parser_allocate (context, vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser->petrel = petrel;
|
||||
if (petrel) {
|
||||
parser_init (&parser->base, context, &shearwater_petrel_parser_vtable);
|
||||
parser->samplesize = SZ_SAMPLE_PETREL;
|
||||
} else {
|
||||
parser_init (&parser->base, context, &shearwater_predator_parser_vtable);
|
||||
parser->samplesize = SZ_SAMPLE_PREDATOR;
|
||||
}
|
||||
|
||||
// Set the default values.
|
||||
parser->petrel = petrel;
|
||||
parser->samplesize = samplesize;
|
||||
parser->cached = 0;
|
||||
parser->headersize = 0;
|
||||
parser->footersize = 0;
|
||||
|
||||
@ -31,13 +31,10 @@
|
||||
#define RB_PROFILE_PEEK(a,l) ringbuffer_decrement (a, l->peek, l->rb_profile_begin, l->rb_profile_end)
|
||||
|
||||
void
|
||||
suunto_common_device_init (suunto_common_device_t *device, dc_context_t *context, const dc_device_vtable_t *vtable)
|
||||
suunto_common_device_init (suunto_common_device_t *device)
|
||||
{
|
||||
assert (device != NULL);
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, vtable);
|
||||
|
||||
// Set the default values.
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ typedef struct suunto_common_layout_t {
|
||||
} suunto_common_layout_t;
|
||||
|
||||
void
|
||||
suunto_common_device_init (suunto_common_device_t *device, dc_context_t *context, const dc_device_vtable_t *vtable);
|
||||
suunto_common_device_init (suunto_common_device_t *device);
|
||||
|
||||
dc_status_t
|
||||
suunto_common_device_set_fingerprint (dc_device_t *device, const unsigned char data[], unsigned int size);
|
||||
|
||||
@ -40,13 +40,10 @@
|
||||
#define VTABLE(abstract) ((suunto_common2_device_vtable_t *) abstract->vtable)
|
||||
|
||||
void
|
||||
suunto_common2_device_init (suunto_common2_device_t *device, dc_context_t *context, const suunto_common2_device_vtable_t *vtable)
|
||||
suunto_common2_device_init (suunto_common2_device_t *device)
|
||||
{
|
||||
assert (device != NULL);
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &vtable->base);
|
||||
|
||||
// Set the default values.
|
||||
device->layout = NULL;
|
||||
memset (device->version, 0, sizeof (device->version));
|
||||
|
||||
@ -53,7 +53,7 @@ typedef struct suunto_common2_device_vtable_t {
|
||||
} suunto_common2_device_vtable_t;
|
||||
|
||||
void
|
||||
suunto_common2_device_init (suunto_common2_device_t *device, dc_context_t *context, const suunto_common2_device_vtable_t *vtable);
|
||||
suunto_common2_device_init (suunto_common2_device_t *device);
|
||||
|
||||
dc_status_t
|
||||
suunto_common2_device_set_fingerprint (dc_device_t *device, const unsigned char data[], unsigned int size);
|
||||
|
||||
@ -55,6 +55,7 @@ static dc_status_t suunto_d9_device_close (dc_device_t *abstract);
|
||||
|
||||
static const suunto_common2_device_vtable_t suunto_d9_device_vtable = {
|
||||
{
|
||||
sizeof(suunto_d9_device_t),
|
||||
DC_FAMILY_SUUNTO_D9,
|
||||
suunto_common2_device_set_fingerprint, /* set_fingerprint */
|
||||
suunto_common2_device_read, /* read */
|
||||
@ -136,14 +137,14 @@ suunto_d9_device_open (dc_device_t **out, dc_context_t *context, const char *nam
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (suunto_d9_device_t *) malloc (sizeof (suunto_d9_device_t));
|
||||
device = (suunto_d9_device_t *) dc_device_allocate (context, &suunto_d9_device_vtable.base);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
suunto_common2_device_init (&device->base, context, &suunto_d9_device_vtable);
|
||||
suunto_common2_device_init (&device->base);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
@ -207,7 +208,7 @@ suunto_d9_device_open (dc_device_t **out, dc_context_t *context, const char *nam
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -85,6 +85,7 @@ static dc_status_t suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_t
|
||||
static dc_status_t suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t suunto_d9_parser_vtable = {
|
||||
sizeof(suunto_d9_parser_t),
|
||||
DC_FAMILY_SUUNTO_D9,
|
||||
suunto_d9_parser_set_data, /* set_data */
|
||||
suunto_d9_parser_get_datetime, /* datetime */
|
||||
@ -202,19 +203,18 @@ suunto_d9_parser_cache (suunto_d9_parser_t *parser)
|
||||
dc_status_t
|
||||
suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
|
||||
{
|
||||
suunto_d9_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
suunto_d9_parser_t *parser = (suunto_d9_parser_t *) malloc (sizeof (suunto_d9_parser_t));
|
||||
parser = (suunto_d9_parser_t *) dc_parser_allocate (context, &suunto_d9_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &suunto_d9_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
parser->model = model;
|
||||
parser->cached = 0;
|
||||
|
||||
@ -50,6 +50,7 @@ static dc_status_t suunto_eon_device_foreach (dc_device_t *abstract, dc_dive_cal
|
||||
static dc_status_t suunto_eon_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t suunto_eon_device_vtable = {
|
||||
sizeof(suunto_eon_device_t),
|
||||
DC_FAMILY_SUUNTO_EON,
|
||||
suunto_common_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -78,14 +79,14 @@ suunto_eon_device_open (dc_device_t **out, dc_context_t *context, const char *na
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (suunto_eon_device_t *) malloc (sizeof (suunto_eon_device_t));
|
||||
device = (suunto_eon_device_t *) dc_device_allocate (context, &suunto_eon_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
suunto_common_device_init (&device->base, context, &suunto_eon_device_vtable);
|
||||
suunto_common_device_init (&device->base);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
@ -127,7 +128,7 @@ suunto_eon_device_open (dc_device_t **out, dc_context_t *context, const char *na
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -49,6 +49,7 @@ static dc_status_t suunto_eon_parser_get_field (dc_parser_t *abstract, dc_field_
|
||||
static dc_status_t suunto_eon_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t suunto_eon_parser_vtable = {
|
||||
sizeof(suunto_eon_parser_t),
|
||||
DC_FAMILY_SUUNTO_EON,
|
||||
suunto_eon_parser_set_data, /* set_data */
|
||||
suunto_eon_parser_get_datetime, /* datetime */
|
||||
@ -110,19 +111,18 @@ suunto_eon_parser_cache (suunto_eon_parser_t *parser)
|
||||
dc_status_t
|
||||
suunto_eon_parser_create (dc_parser_t **out, dc_context_t *context, int spyder)
|
||||
{
|
||||
suunto_eon_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
suunto_eon_parser_t *parser = (suunto_eon_parser_t *) malloc (sizeof (suunto_eon_parser_t));
|
||||
parser = (suunto_eon_parser_t *) dc_parser_allocate (context, &suunto_eon_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &suunto_eon_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
parser->spyder = spyder;
|
||||
parser->cached = 0;
|
||||
|
||||
@ -85,6 +85,7 @@ static dc_status_t suunto_eonsteel_device_foreach(dc_device_t *abstract, dc_dive
|
||||
static dc_status_t suunto_eonsteel_device_close(dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t suunto_eonsteel_device_vtable = {
|
||||
sizeof(suunto_eonsteel_device_t),
|
||||
DC_FAMILY_SUUNTO_EONSTEEL,
|
||||
NULL, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -557,12 +558,12 @@ dc_status_t
|
||||
suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, const char *name, unsigned int model)
|
||||
{
|
||||
dc_status_t status = DC_STATUS_SUCCESS;
|
||||
suunto_eonsteel_device_t *eon;
|
||||
suunto_eonsteel_device_t *eon = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
eon = (suunto_eonsteel_device_t *) calloc(1, sizeof(suunto_eonsteel_device_t));
|
||||
eon = (suunto_eonsteel_device_t *) dc_device_allocate(context, &suunto_eonsteel_device_vtable);
|
||||
if (!eon)
|
||||
return DC_STATUS_NOMEMORY;
|
||||
|
||||
@ -570,9 +571,6 @@ suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, const char
|
||||
eon->magic = INIT_MAGIC;
|
||||
eon->seq = INIT_SEQ;
|
||||
|
||||
// Set up the libdivecomputer interfaces
|
||||
device_init(&eon->base, context, &suunto_eonsteel_device_vtable);
|
||||
|
||||
if (libusb_init(&eon->ctx)) {
|
||||
ERROR(context, "libusb_init() failed");
|
||||
status = DC_STATUS_IO;
|
||||
|
||||
@ -1196,6 +1196,7 @@ suunto_eonsteel_parser_destroy(dc_parser_t *parser)
|
||||
}
|
||||
|
||||
static const dc_parser_vtable_t suunto_eonsteel_parser_vtable = {
|
||||
sizeof(suunto_eonsteel_parser_t),
|
||||
DC_FAMILY_SUUNTO_EONSTEEL,
|
||||
suunto_eonsteel_parser_set_data, /* set_data */
|
||||
suunto_eonsteel_parser_get_datetime, /* datetime */
|
||||
@ -1207,18 +1208,21 @@ static const dc_parser_vtable_t suunto_eonsteel_parser_vtable = {
|
||||
dc_status_t
|
||||
suunto_eonsteel_parser_create(dc_parser_t **out, dc_context_t *context, unsigned int model)
|
||||
{
|
||||
suunto_eonsteel_parser_t *eon;
|
||||
suunto_eonsteel_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
eon = (suunto_eonsteel_parser_t *) calloc(1, sizeof(*eon));
|
||||
if (!eon)
|
||||
parser = (suunto_eonsteel_parser_t *) dc_parser_allocate (context, &suunto_eonsteel_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
parser_init(&eon->base, context, &suunto_eonsteel_parser_vtable);
|
||||
memset(&parser->type_desc, 0, sizeof(parser->type_desc));
|
||||
memset(&parser->cache, 0, sizeof(parser->cache));
|
||||
|
||||
*out = (dc_parser_t *) eon;
|
||||
*out = (dc_parser_t *) parser;
|
||||
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -52,6 +52,7 @@ static dc_status_t suunto_solution_device_foreach (dc_device_t *abstract, dc_div
|
||||
static dc_status_t suunto_solution_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t suunto_solution_device_vtable = {
|
||||
sizeof(suunto_solution_device_t),
|
||||
DC_FAMILY_SUUNTO_SOLUTION,
|
||||
NULL, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -72,15 +73,12 @@ suunto_solution_device_open (dc_device_t **out, dc_context_t *context, const cha
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (suunto_solution_device_t *) malloc (sizeof (suunto_solution_device_t));
|
||||
device = (suunto_solution_device_t *) dc_device_allocate (context, &suunto_solution_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &suunto_solution_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
|
||||
@ -121,7 +119,7 @@ suunto_solution_device_open (dc_device_t **out, dc_context_t *context, const cha
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -44,6 +44,7 @@ static dc_status_t suunto_solution_parser_get_field (dc_parser_t *abstract, dc_f
|
||||
static dc_status_t suunto_solution_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t suunto_solution_parser_vtable = {
|
||||
sizeof(suunto_solution_parser_t),
|
||||
DC_FAMILY_SUUNTO_SOLUTION,
|
||||
suunto_solution_parser_set_data, /* set_data */
|
||||
NULL, /* datetime */
|
||||
@ -56,19 +57,18 @@ static const dc_parser_vtable_t suunto_solution_parser_vtable = {
|
||||
dc_status_t
|
||||
suunto_solution_parser_create (dc_parser_t **out, dc_context_t *context)
|
||||
{
|
||||
suunto_solution_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
suunto_solution_parser_t *parser = (suunto_solution_parser_t *) malloc (sizeof (suunto_solution_parser_t));
|
||||
parser = (suunto_solution_parser_t *) dc_parser_allocate (context, &suunto_solution_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &suunto_solution_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
parser->cached = 0;
|
||||
parser->divetime = 0;
|
||||
|
||||
@ -62,6 +62,7 @@ static dc_status_t suunto_vyper_device_foreach (dc_device_t *abstract, dc_dive_c
|
||||
static dc_status_t suunto_vyper_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t suunto_vyper_device_vtable = {
|
||||
sizeof(suunto_vyper_device_t),
|
||||
DC_FAMILY_SUUNTO_VYPER,
|
||||
suunto_common_device_set_fingerprint, /* set_fingerprint */
|
||||
suunto_vyper_device_read, /* read */
|
||||
@ -98,14 +99,14 @@ suunto_vyper_device_open (dc_device_t **out, dc_context_t *context, const char *
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (suunto_vyper_device_t *) malloc (sizeof (suunto_vyper_device_t));
|
||||
device = (suunto_vyper_device_t *) dc_device_allocate (context, &suunto_vyper_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
suunto_common_device_init (&device->base, context, &suunto_vyper_device_vtable);
|
||||
suunto_common_device_init (&device->base);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
@ -153,7 +154,7 @@ suunto_vyper_device_open (dc_device_t **out, dc_context_t *context, const char *
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -49,6 +49,7 @@ static dc_status_t suunto_vyper2_device_close (dc_device_t *abstract);
|
||||
|
||||
static const suunto_common2_device_vtable_t suunto_vyper2_device_vtable = {
|
||||
{
|
||||
sizeof(suunto_vyper2_device_t),
|
||||
DC_FAMILY_SUUNTO_VYPER2,
|
||||
suunto_common2_device_set_fingerprint, /* set_fingerprint */
|
||||
suunto_common2_device_read, /* read */
|
||||
@ -87,14 +88,14 @@ suunto_vyper2_device_open (dc_device_t **out, dc_context_t *context, const char
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (suunto_vyper2_device_t *) malloc (sizeof (suunto_vyper2_device_t));
|
||||
device = (suunto_vyper2_device_t *) dc_device_allocate (context, &suunto_vyper2_device_vtable.base);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
suunto_common2_device_init (&device->base, context, &suunto_vyper2_device_vtable);
|
||||
suunto_common2_device_init (&device->base);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
@ -159,7 +160,7 @@ suunto_vyper2_device_open (dc_device_t **out, dc_context_t *context, const char
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -50,6 +50,7 @@ static dc_status_t suunto_vyper_parser_get_field (dc_parser_t *abstract, dc_fiel
|
||||
static dc_status_t suunto_vyper_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t suunto_vyper_parser_vtable = {
|
||||
sizeof(suunto_vyper_parser_t),
|
||||
DC_FAMILY_SUUNTO_VYPER,
|
||||
suunto_vyper_parser_set_data, /* set_data */
|
||||
suunto_vyper_parser_get_datetime, /* datetime */
|
||||
@ -160,19 +161,18 @@ suunto_vyper_parser_cache (suunto_vyper_parser_t *parser)
|
||||
dc_status_t
|
||||
suunto_vyper_parser_create (dc_parser_t **out, dc_context_t *context)
|
||||
{
|
||||
suunto_vyper_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
suunto_vyper_parser_t *parser = (suunto_vyper_parser_t *) malloc (sizeof (suunto_vyper_parser_t));
|
||||
parser = (suunto_vyper_parser_t *) dc_parser_allocate (context, &suunto_vyper_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &suunto_vyper_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
parser->cached = 0;
|
||||
parser->divetime = 0;
|
||||
|
||||
@ -61,6 +61,7 @@ static dc_status_t uwatec_aladin_device_foreach (dc_device_t *abstract, dc_dive_
|
||||
static dc_status_t uwatec_aladin_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t uwatec_aladin_device_vtable = {
|
||||
sizeof(uwatec_aladin_device_t),
|
||||
DC_FAMILY_UWATEC_ALADIN,
|
||||
uwatec_aladin_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -81,15 +82,12 @@ uwatec_aladin_device_open (dc_device_t **out, dc_context_t *context, const char
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (uwatec_aladin_device_t *) malloc (sizeof (uwatec_aladin_device_t));
|
||||
device = (uwatec_aladin_device_t *) dc_device_allocate (context, &uwatec_aladin_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &uwatec_aladin_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
device->timestamp = 0;
|
||||
@ -134,7 +132,7 @@ uwatec_aladin_device_open (dc_device_t **out, dc_context_t *context, const char
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -57,6 +57,7 @@ static dc_status_t uwatec_memomouse_device_foreach (dc_device_t *abstract, dc_di
|
||||
static dc_status_t uwatec_memomouse_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t uwatec_memomouse_device_vtable = {
|
||||
sizeof(uwatec_memomouse_device_t),
|
||||
DC_FAMILY_UWATEC_MEMOMOUSE,
|
||||
uwatec_memomouse_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -77,15 +78,12 @@ uwatec_memomouse_device_open (dc_device_t **out, dc_context_t *context, const ch
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (uwatec_memomouse_device_t *) malloc (sizeof (uwatec_memomouse_device_t));
|
||||
device = (uwatec_memomouse_device_t *) dc_device_allocate (context, &uwatec_memomouse_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &uwatec_memomouse_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
device->timestamp = 0;
|
||||
@ -133,7 +131,7 @@ uwatec_memomouse_device_open (dc_device_t **out, dc_context_t *context, const ch
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -44,6 +44,7 @@ static dc_status_t uwatec_memomouse_parser_get_field (dc_parser_t *abstract, dc_
|
||||
static dc_status_t uwatec_memomouse_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t uwatec_memomouse_parser_vtable = {
|
||||
sizeof(uwatec_memomouse_parser_t),
|
||||
DC_FAMILY_UWATEC_MEMOMOUSE,
|
||||
uwatec_memomouse_parser_set_data, /* set_data */
|
||||
uwatec_memomouse_parser_get_datetime, /* datetime */
|
||||
@ -56,19 +57,18 @@ static const dc_parser_vtable_t uwatec_memomouse_parser_vtable = {
|
||||
dc_status_t
|
||||
uwatec_memomouse_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int devtime, dc_ticks_t systime)
|
||||
{
|
||||
uwatec_memomouse_parser_t *parser = NULL;
|
||||
|
||||
if (out == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
uwatec_memomouse_parser_t *parser = (uwatec_memomouse_parser_t *) malloc (sizeof (uwatec_memomouse_parser_t));
|
||||
parser = (uwatec_memomouse_parser_t *) dc_parser_allocate (context, &uwatec_memomouse_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &uwatec_memomouse_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
parser->devtime = devtime;
|
||||
parser->systime = systime;
|
||||
|
||||
@ -55,6 +55,7 @@ static dc_status_t uwatec_meridian_device_foreach (dc_device_t *abstract, dc_div
|
||||
static dc_status_t uwatec_meridian_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t uwatec_meridian_device_vtable = {
|
||||
sizeof(uwatec_meridian_device_t),
|
||||
DC_FAMILY_UWATEC_MERIDIAN,
|
||||
uwatec_meridian_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -193,15 +194,12 @@ uwatec_meridian_device_open (dc_device_t **out, dc_context_t *context, const cha
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (uwatec_meridian_device_t *) malloc (sizeof (uwatec_meridian_device_t));
|
||||
device = (uwatec_meridian_device_t *) dc_device_allocate (context, &uwatec_meridian_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &uwatec_meridian_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
device->timestamp = 0;
|
||||
@ -244,7 +242,7 @@ uwatec_meridian_device_open (dc_device_t **out, dc_context_t *context, const cha
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -51,6 +51,7 @@ static dc_status_t uwatec_smart_device_foreach (dc_device_t *abstract, dc_dive_c
|
||||
static dc_status_t uwatec_smart_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t uwatec_smart_device_vtable = {
|
||||
sizeof(uwatec_smart_device_t),
|
||||
DC_FAMILY_UWATEC_SMART,
|
||||
uwatec_smart_device_set_fingerprint, /* set_fingerprint */
|
||||
NULL, /* read */
|
||||
@ -152,15 +153,12 @@ uwatec_smart_device_open (dc_device_t **out, dc_context_t *context)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (uwatec_smart_device_t *) malloc (sizeof (uwatec_smart_device_t));
|
||||
device = (uwatec_smart_device_t *) dc_device_allocate (context, &uwatec_smart_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &uwatec_smart_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->socket = NULL;
|
||||
device->address = 0;
|
||||
@ -208,7 +206,7 @@ uwatec_smart_device_open (dc_device_t **out, dc_context_t *context)
|
||||
error_close:
|
||||
irda_socket_close (device->socket);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -152,6 +152,7 @@ static dc_status_t uwatec_smart_parser_get_field (dc_parser_t *abstract, dc_fiel
|
||||
static dc_status_t uwatec_smart_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata);
|
||||
|
||||
static const dc_parser_vtable_t uwatec_smart_parser_vtable = {
|
||||
sizeof(uwatec_smart_parser_t),
|
||||
DC_FAMILY_UWATEC_SMART,
|
||||
uwatec_smart_parser_set_data, /* set_data */
|
||||
uwatec_smart_parser_get_datetime, /* datetime */
|
||||
@ -518,15 +519,12 @@ uwatec_smart_parser_create (dc_parser_t **out, dc_context_t *context, unsigned i
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
parser = (uwatec_smart_parser_t *) malloc (sizeof (uwatec_smart_parser_t));
|
||||
parser = (uwatec_smart_parser_t *) dc_parser_allocate (context, &uwatec_smart_parser_vtable);
|
||||
if (parser == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
parser_init (&parser->base, context, &uwatec_smart_parser_vtable);
|
||||
|
||||
// Set the default values.
|
||||
parser->model = model;
|
||||
parser->devtime = devtime;
|
||||
@ -620,7 +618,7 @@ uwatec_smart_parser_create (dc_parser_t **out, dc_context_t *context, unsigned i
|
||||
return DC_STATUS_SUCCESS;
|
||||
|
||||
error_free:
|
||||
free (parser);
|
||||
dc_parser_deallocate ((dc_parser_t *) parser);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -62,6 +62,7 @@ static dc_status_t zeagle_n2ition3_device_foreach (dc_device_t *abstract, dc_div
|
||||
static dc_status_t zeagle_n2ition3_device_close (dc_device_t *abstract);
|
||||
|
||||
static const dc_device_vtable_t zeagle_n2ition3_device_vtable = {
|
||||
sizeof(zeagle_n2ition3_device_t),
|
||||
DC_FAMILY_ZEAGLE_N2ITION3,
|
||||
zeagle_n2ition3_device_set_fingerprint, /* set_fingerprint */
|
||||
zeagle_n2ition3_device_read, /* read */
|
||||
@ -144,15 +145,12 @@ zeagle_n2ition3_device_open (dc_device_t **out, dc_context_t *context, const cha
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
// Allocate memory.
|
||||
device = (zeagle_n2ition3_device_t *) malloc (sizeof (zeagle_n2ition3_device_t));
|
||||
device = (zeagle_n2ition3_device_t *) dc_device_allocate (context, &zeagle_n2ition3_device_vtable);
|
||||
if (device == NULL) {
|
||||
ERROR (context, "Failed to allocate memory.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
// Initialize the base class.
|
||||
device_init (&device->base, context, &zeagle_n2ition3_device_vtable);
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
@ -193,7 +191,7 @@ zeagle_n2ition3_device_open (dc_device_t **out, dc_context_t *context, const cha
|
||||
error_close:
|
||||
serial_close (device->port);
|
||||
error_free:
|
||||
free (device);
|
||||
dc_device_deallocate ((dc_device_t *) device);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user