From 33051dd29483935998fb861f85af4ff838ba7fcf Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 25 Mar 2010 09:51:00 +0000 Subject: [PATCH] Use different layouts for the Mares Puck and Nemo Wide. --- src/mares_common.c | 4 ++++ src/mares_puck.c | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/mares_common.c b/src/mares_common.c index b1b2e44..ec4817a 100644 --- a/src/mares_common.c +++ b/src/mares_common.c @@ -75,6 +75,10 @@ mares_common_extract_dives (mares_common_device_t *device, const mares_common_la // Get the end of the profile ring buffer. unsigned int eop = array_uint16_le (data + 0x6B); + if (eop < layout->rb_profile_begin || eop >= layout->rb_profile_end) { + WARNING ("Ringbuffer pointer out of range."); + return DEVICE_STATUS_ERROR; + } // Make the ringbuffer linear, to avoid having to deal // with the wrap point. The buffer has extra space to diff --git a/src/mares_puck.c b/src/mares_puck.c index f0edc35..1f44ea4 100644 --- a/src/mares_puck.c +++ b/src/mares_puck.c @@ -63,8 +63,8 @@ static const device_backend_t mares_puck_device_backend = { static const mares_common_layout_t mares_puck_layout = { 0x4000, /* memsize */ 0x0070, /* rb_profile_begin */ - 0x3400, /* rb_profile_end */ - 0x3400, /* rb_freedives_begin */ + 0x4000, /* rb_profile_end */ + 0x4000, /* rb_freedives_begin */ 0x4000 /* rb_freedives_end */ }; @@ -76,6 +76,14 @@ static const mares_common_layout_t mares_nemoair_layout = { 0x8000 /* rb_freedives_end */ }; +static const mares_common_layout_t mares_nemowide_layout = { + 0x4000, /* memsize */ + 0x0070, /* rb_profile_begin */ + 0x3400, /* rb_profile_end */ + 0x3400, /* rb_freedives_begin */ + 0x4000 /* rb_freedives_end */ +}; + static int device_is_mares_puck (device_t *abstract) { @@ -149,10 +157,20 @@ mares_puck_device_open (device_t **out, const char* name) } // Override the base class values. - if (header[1] == 4) + switch (header[1]) { + case 1: // Nemo Wide + device->base.layout = &mares_nemowide_layout; + break; + case 4: // Nemo Air device->base.layout = &mares_nemoair_layout; - else + break; + case 7: // Puck device->base.layout = &mares_puck_layout; + break; + default: // Unknown, try puck + device->base.layout = &mares_puck_layout; + break; + } *out = (device_t*) device; @@ -422,10 +440,20 @@ mares_puck_extract_dives (device_t *abstract, const unsigned char data[], unsign return DEVICE_STATUS_ERROR; const mares_common_layout_t *layout = NULL; - if (data[1] == 4) + switch (data[1]) { + case 1: // Nemo Wide + layout = &mares_nemowide_layout; + break; + case 4: // Nemo Air layout = &mares_nemoair_layout; - else + break; + case 7: // Puck layout = &mares_puck_layout; + break; + default: // Unknown, try puck + layout = &mares_puck_layout; + break; + } if (size < layout->memsize) return DEVICE_STATUS_ERROR;