Store the layout descriptor in the device handle.
This commit is contained in:
parent
32fd37df2c
commit
45f51fedfb
@ -47,26 +47,24 @@ typedef struct oceanic_atom2_device_t {
|
||||
unsigned char version[PAGESIZE];
|
||||
} oceanic_atom2_device_t;
|
||||
|
||||
static device_status_t oceanic_atom2_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
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_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t oceanic_atom2_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t oceanic_atom2_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t oceanic_atom2_device_backend = {
|
||||
DEVICE_TYPE_OCEANIC_ATOM2,
|
||||
oceanic_atom2_device_set_fingerprint, /* set_fingerprint */
|
||||
oceanic_common_device_set_fingerprint, /* set_fingerprint */
|
||||
oceanic_atom2_device_version, /* version */
|
||||
oceanic_atom2_device_read, /* read */
|
||||
oceanic_atom2_device_write, /* write */
|
||||
oceanic_atom2_device_dump, /* dump */
|
||||
oceanic_atom2_device_foreach, /* foreach */
|
||||
oceanic_common_device_dump, /* dump */
|
||||
oceanic_common_device_foreach, /* foreach */
|
||||
oceanic_atom2_device_close /* close */
|
||||
};
|
||||
|
||||
static const oceanic_common_layout_t oceanic_atom2_layout = {
|
||||
0x10000, /* memsize */
|
||||
0x0000, /* cf_devinfo */
|
||||
0x0040, /* cf_pointers */
|
||||
0x0240, /* rb_logbook_begin */
|
||||
@ -236,6 +234,9 @@ oceanic_atom2_device_open (device_t **out, const char* name)
|
||||
// Initialize the base class.
|
||||
oceanic_common_device_init (&device->base, &oceanic_atom2_device_backend);
|
||||
|
||||
// Override the base class values.
|
||||
device->base.layout = &oceanic_atom2_layout;
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
memset (device->version, 0, sizeof (device->version));
|
||||
@ -285,18 +286,6 @@ oceanic_atom2_device_open (device_t **out, const char* name)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
oceanic_atom2_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
oceanic_common_device_t *device = (oceanic_common_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_atom2 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
return oceanic_common_device_set_fingerprint (device, data, size);
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
oceanic_atom2_device_close (device_t *abstract)
|
||||
{
|
||||
@ -466,33 +455,3 @@ oceanic_atom2_device_write (device_t *abstract, unsigned int address, const unsi
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
oceanic_atom2_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
if (! device_is_oceanic_atom2 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
// Erase the current contents of the buffer and
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, OCEANIC_ATOM2_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
|
||||
return device_dump_read (abstract, dc_buffer_get_data (buffer),
|
||||
dc_buffer_get_size (buffer), PAGESIZE);
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
oceanic_atom2_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
oceanic_common_device_t *device = (oceanic_common_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_atom2 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
return oceanic_common_device_foreach (device, &oceanic_atom2_layout, callback, userdata);
|
||||
}
|
||||
|
||||
@ -29,8 +29,6 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OCEANIC_ATOM2_MEMORY_SIZE 0x10000
|
||||
|
||||
device_status_t
|
||||
oceanic_atom2_device_open (device_t **device, const char* name);
|
||||
|
||||
|
||||
@ -92,12 +92,15 @@ oceanic_common_device_init (oceanic_common_device_t *device, const device_backen
|
||||
|
||||
// Set the default values.
|
||||
memset (device->fingerprint, 0, sizeof (device->fingerprint));
|
||||
device->layout = NULL;
|
||||
}
|
||||
|
||||
|
||||
device_status_t
|
||||
oceanic_common_device_set_fingerprint (oceanic_common_device_t *device, const unsigned char data[], unsigned int size)
|
||||
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;
|
||||
|
||||
assert (device != NULL);
|
||||
|
||||
if (size && size != sizeof (device->fingerprint))
|
||||
@ -113,12 +116,34 @@ oceanic_common_device_set_fingerprint (oceanic_common_device_t *device, const un
|
||||
|
||||
|
||||
device_status_t
|
||||
oceanic_common_device_foreach (oceanic_common_device_t *device, const oceanic_common_layout_t *layout, dive_callback_t callback, void *userdata)
|
||||
oceanic_common_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
device_t *abstract = (device_t *) device;
|
||||
oceanic_common_device_t *device = (oceanic_common_device_t *) abstract;
|
||||
|
||||
assert (abstract != NULL);
|
||||
assert (layout != NULL);
|
||||
assert (device != NULL);
|
||||
assert (device->layout != NULL);
|
||||
|
||||
// Erase the current contents of the buffer and
|
||||
// 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 device_dump_read (abstract, dc_buffer_get_data (buffer),
|
||||
dc_buffer_get_size (buffer), PAGESIZE);
|
||||
}
|
||||
|
||||
|
||||
device_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;
|
||||
|
||||
assert (device != NULL);
|
||||
assert (device->layout != NULL);
|
||||
|
||||
const oceanic_common_layout_t *layout = device->layout;
|
||||
|
||||
// Enable progress notifications.
|
||||
device_progress_t progress = DEVICE_PROGRESS_INITIALIZER;
|
||||
|
||||
@ -30,12 +30,9 @@ extern "C" {
|
||||
|
||||
#define PAGESIZE 0x10
|
||||
|
||||
typedef struct oceanic_common_device_t {
|
||||
device_t base;
|
||||
unsigned char fingerprint[8];
|
||||
} oceanic_common_device_t;
|
||||
|
||||
typedef struct oceanic_common_layout_t {
|
||||
// Memory size.
|
||||
unsigned int memsize;
|
||||
// Device info.
|
||||
unsigned int cf_devinfo;
|
||||
// Ringbuffer pointers.
|
||||
@ -53,14 +50,23 @@ typedef struct oceanic_common_layout_t {
|
||||
unsigned int mode;
|
||||
} oceanic_common_layout_t;
|
||||
|
||||
typedef struct oceanic_common_device_t {
|
||||
device_t base;
|
||||
unsigned char fingerprint[PAGESIZE / 2];
|
||||
const oceanic_common_layout_t *layout;
|
||||
} oceanic_common_device_t;
|
||||
|
||||
void
|
||||
oceanic_common_device_init (oceanic_common_device_t *device, const device_backend_t *backend);
|
||||
|
||||
device_status_t
|
||||
oceanic_common_device_set_fingerprint (oceanic_common_device_t *device, const unsigned char data[], unsigned int size);
|
||||
oceanic_common_device_set_fingerprint (device_t *device, const unsigned char data[], unsigned int size);
|
||||
|
||||
device_status_t
|
||||
oceanic_common_device_foreach (oceanic_common_device_t *device, const oceanic_common_layout_t *layout, dive_callback_t callback, void *userdata);
|
||||
oceanic_common_device_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
|
||||
device_status_t
|
||||
oceanic_common_device_foreach (device_t *device, dive_callback_t callback, void *userdata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -48,25 +48,23 @@ typedef struct oceanic_veo250_device_t {
|
||||
unsigned char version[PAGESIZE];
|
||||
} oceanic_veo250_device_t;
|
||||
|
||||
static device_status_t oceanic_veo250_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
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_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t oceanic_veo250_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t oceanic_veo250_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t oceanic_veo250_device_backend = {
|
||||
DEVICE_TYPE_OCEANIC_VEO250,
|
||||
oceanic_veo250_device_set_fingerprint, /* set_fingerprint */
|
||||
oceanic_common_device_set_fingerprint, /* set_fingerprint */
|
||||
oceanic_veo250_device_version, /* version */
|
||||
oceanic_veo250_device_read, /* read */
|
||||
NULL, /* write */
|
||||
oceanic_veo250_device_dump, /* dump */
|
||||
oceanic_veo250_device_foreach, /* foreach */
|
||||
oceanic_common_device_dump, /* dump */
|
||||
oceanic_common_device_foreach, /* foreach */
|
||||
oceanic_veo250_device_close /* close */
|
||||
};
|
||||
|
||||
static const oceanic_common_layout_t oceanic_veo250_layout = {
|
||||
0x8000, /* memsize */
|
||||
0x0000, /* cf_devinfo */
|
||||
0x0040, /* cf_pointers */
|
||||
0x0400, /* rb_logbook_begin */
|
||||
@ -224,6 +222,9 @@ oceanic_veo250_device_open (device_t **out, const char* name)
|
||||
// Initialize the base class.
|
||||
oceanic_common_device_init (&device->base, &oceanic_veo250_device_backend);
|
||||
|
||||
// Override the base class values.
|
||||
device->base.layout = &oceanic_veo250_layout;
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
device->last = 0;
|
||||
@ -283,18 +284,6 @@ oceanic_veo250_device_open (device_t **out, const char* name)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
oceanic_veo250_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
oceanic_common_device_t *device = (oceanic_common_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_veo250 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
return oceanic_common_device_set_fingerprint (device, data, size);
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
oceanic_veo250_device_close (device_t *abstract)
|
||||
{
|
||||
@ -438,33 +427,3 @@ oceanic_veo250_device_read (device_t *abstract, unsigned int address, unsigned c
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
oceanic_veo250_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
if (! device_is_oceanic_veo250 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
// Erase the current contents of the buffer and
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, OCEANIC_VEO250_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
|
||||
return device_dump_read (abstract, dc_buffer_get_data (buffer),
|
||||
dc_buffer_get_size (buffer), PAGESIZE);
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
oceanic_veo250_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
oceanic_common_device_t *device = (oceanic_common_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_veo250 (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
return oceanic_common_device_foreach (device, &oceanic_veo250_layout, callback, userdata);
|
||||
}
|
||||
|
||||
@ -29,8 +29,6 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OCEANIC_VEO250_MEMORY_SIZE 0x8000
|
||||
|
||||
device_status_t
|
||||
oceanic_veo250_device_open (device_t **device, const char* name);
|
||||
|
||||
|
||||
@ -48,25 +48,23 @@ typedef struct oceanic_vtpro_device_t {
|
||||
unsigned char version[PAGESIZE];
|
||||
} oceanic_vtpro_device_t;
|
||||
|
||||
static device_status_t oceanic_vtpro_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||
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_dump (device_t *abstract, dc_buffer_t *buffer);
|
||||
static device_status_t oceanic_vtpro_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata);
|
||||
static device_status_t oceanic_vtpro_device_close (device_t *abstract);
|
||||
|
||||
static const device_backend_t oceanic_vtpro_device_backend = {
|
||||
DEVICE_TYPE_OCEANIC_VTPRO,
|
||||
oceanic_vtpro_device_set_fingerprint, /* set_fingerprint */
|
||||
oceanic_common_device_set_fingerprint, /* set_fingerprint */
|
||||
oceanic_vtpro_device_version, /* version */
|
||||
oceanic_vtpro_device_read, /* read */
|
||||
NULL, /* write */
|
||||
oceanic_vtpro_device_dump, /* dump */
|
||||
oceanic_vtpro_device_foreach, /* foreach */
|
||||
oceanic_common_device_dump, /* dump */
|
||||
oceanic_common_device_foreach, /* foreach */
|
||||
oceanic_vtpro_device_close /* close */
|
||||
};
|
||||
|
||||
static const oceanic_common_layout_t oceanic_vtpro_layout = {
|
||||
0x8000, /* memsize */
|
||||
0x0000, /* cf_devinfo */
|
||||
0x0040, /* cf_pointers */
|
||||
0x0240, /* rb_logbook_begin */
|
||||
@ -244,6 +242,9 @@ oceanic_vtpro_device_open (device_t **out, const char* name)
|
||||
// Initialize the base class.
|
||||
oceanic_common_device_init (&device->base, &oceanic_vtpro_device_backend);
|
||||
|
||||
// Override the base class values.
|
||||
device->base.layout = &oceanic_vtpro_layout;
|
||||
|
||||
// Set the default values.
|
||||
device->port = NULL;
|
||||
memset (device->version, 0, sizeof (device->version));
|
||||
@ -331,17 +332,6 @@ oceanic_vtpro_device_close (device_t *abstract)
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
oceanic_vtpro_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||
{
|
||||
oceanic_common_device_t *device = (oceanic_common_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_vtpro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
return oceanic_common_device_set_fingerprint (device, data, size);
|
||||
}
|
||||
|
||||
device_status_t
|
||||
oceanic_vtpro_device_keepalive (device_t *abstract)
|
||||
{
|
||||
@ -492,33 +482,3 @@ oceanic_vtpro_device_read (device_t *abstract, unsigned int address, unsigned ch
|
||||
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
oceanic_vtpro_device_dump (device_t *abstract, dc_buffer_t *buffer)
|
||||
{
|
||||
if (! device_is_oceanic_vtpro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
// Erase the current contents of the buffer and
|
||||
// allocate the required amount of memory.
|
||||
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, OCEANIC_VTPRO_MEMORY_SIZE)) {
|
||||
WARNING ("Insufficient buffer space available.");
|
||||
return DEVICE_STATUS_MEMORY;
|
||||
}
|
||||
|
||||
return device_dump_read (abstract, dc_buffer_get_data (buffer),
|
||||
dc_buffer_get_size (buffer), PAGESIZE);
|
||||
}
|
||||
|
||||
|
||||
static device_status_t
|
||||
oceanic_vtpro_device_foreach (device_t *abstract, dive_callback_t callback, void *userdata)
|
||||
{
|
||||
oceanic_common_device_t *device = (oceanic_common_device_t*) abstract;
|
||||
|
||||
if (! device_is_oceanic_vtpro (abstract))
|
||||
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||
|
||||
return oceanic_common_device_foreach (device, &oceanic_vtpro_layout, callback, userdata);
|
||||
}
|
||||
|
||||
@ -29,8 +29,6 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OCEANIC_VTPRO_MEMORY_SIZE 0x8000
|
||||
|
||||
device_status_t
|
||||
oceanic_vtpro_device_open (device_t **device, const char* name);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user