diff --git a/src/cressi_edy.c b/src/cressi_edy.c index 504b79c..2a7b271 100644 --- a/src/cressi_edy.c +++ b/src/cressi_edy.c @@ -444,7 +444,7 @@ cressi_edy_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, v last < layout->rb_logbook_begin || last >= layout->rb_logbook_end) { if (last == 0xFF) return DC_STATUS_SUCCESS; - ERROR (abstract->context, "Invalid ringbuffer pointer detected."); + ERROR (abstract->context, "Invalid ringbuffer pointer detected (0x%02x 0x%02x).", first, last); return DC_STATUS_DATAFORMAT; } @@ -454,7 +454,7 @@ cressi_edy_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, v // Get the profile pointer. unsigned int eop = array_uint_le (logbook + layout->config + 2, layout->rb_logbook_size) * SZ_PAGE + layout->rb_profile_begin; if (eop < layout->rb_profile_begin || eop >= layout->rb_profile_end) { - ERROR (abstract->context, "Invalid ringbuffer pointer detected."); + ERROR (abstract->context, "Invalid ringbuffer pointer detected (0x%04x).", eop); return DC_STATUS_DATAFORMAT; } @@ -469,7 +469,7 @@ cressi_edy_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, v // Get the pointer to the profile data. unsigned int current = array_uint_le (logbook + idx * layout->rb_logbook_size, layout->rb_logbook_size) * SZ_PAGE + layout->rb_profile_begin; if (current < layout->rb_profile_begin || current >= layout->rb_profile_end) { - ERROR (abstract->context, "Invalid ringbuffer pointer detected."); + ERROR (abstract->context, "Invalid ringbuffer pointer detected (0x%04x).", current); return DC_STATUS_DATAFORMAT; } @@ -532,7 +532,7 @@ cressi_edy_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, v // Get the pointer to the profile data. unsigned int current = array_uint_le (logbook + idx * layout->rb_logbook_size, layout->rb_logbook_size) * SZ_PAGE + layout->rb_profile_begin; if (current < layout->rb_profile_begin || current >= layout->rb_profile_end) { - ERROR (abstract->context, "Invalid ringbuffer pointer detected."); + ERROR (abstract->context, "Invalid ringbuffer pointer detected (0x%04x).", current); free(buffer); return DC_STATUS_DATAFORMAT; } diff --git a/src/cressi_leonardo.c b/src/cressi_leonardo.c index b2df764..2d6d177 100644 --- a/src/cressi_leonardo.c +++ b/src/cressi_leonardo.c @@ -343,7 +343,7 @@ cressi_leonardo_extract_dives (dc_device_t *abstract, const unsigned char data[] if (header < RB_PROFILE_BEGIN || header + 2 > RB_PROFILE_END || footer < RB_PROFILE_BEGIN || footer + 2 > RB_PROFILE_END) { - ERROR (context, "Invalid ringbuffer pointer detected."); + ERROR (context, "Invalid ringbuffer pointer detected (0x%04x 0x%04x).", header, footer); free (buffer); return DC_STATUS_DATAFORMAT; } @@ -352,7 +352,7 @@ cressi_leonardo_extract_dives (dc_device_t *abstract, const unsigned char data[] unsigned int header2 = array_uint16_le (data + footer); unsigned int footer2 = array_uint16_le (data + header); if (header2 != header || footer2 != footer) { - ERROR (context, "Invalid ringbuffer pointer detected."); + ERROR (context, "Invalid ringbuffer pointer detected (0x%04x 0x%04x).", header2, footer2); free (buffer); return DC_STATUS_DATAFORMAT; } diff --git a/src/diverite_nitekq.c b/src/diverite_nitekq.c index 661588f..6ca5356 100644 --- a/src/diverite_nitekq.c +++ b/src/diverite_nitekq.c @@ -381,7 +381,7 @@ diverite_nitekq_extract_dives (dc_device_t *abstract, const unsigned char data[] // Get the end of profile pointer. unsigned int eop = array_uint16_be(data + EOP); if (eop < RB_PROFILE_BEGIN || eop >= RB_PROFILE_END) { - ERROR (context, "Invalid ringbuffer pointer detected."); + ERROR (context, "Invalid ringbuffer pointer detected (0x%04x).", eop); free (buffer); return DC_STATUS_DATAFORMAT; } @@ -402,7 +402,7 @@ diverite_nitekq_extract_dives (dc_device_t *abstract, const unsigned char data[] // Get the address of the profile data. unsigned int address = array_uint16_be(data + ADDRESS + i * 2); if (address < RB_PROFILE_BEGIN || address >= RB_PROFILE_END) { - ERROR (context, "Invalid ringbuffer pointer detected."); + ERROR (context, "Invalid ringbuffer pointer detected (0x%04x).", address); free (buffer); return DC_STATUS_DATAFORMAT; } diff --git a/src/hw_frog.c b/src/hw_frog.c index ec760ac..43bc307 100644 --- a/src/hw_frog.c +++ b/src/hw_frog.c @@ -409,7 +409,7 @@ hw_frog_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void end < RB_PROFILE_BEGIN || end >= RB_PROFILE_END) { - ERROR (abstract->context, "Invalid ringbuffer pointer detected."); + ERROR (abstract->context, "Invalid ringbuffer pointer detected (0x%06x 0x%06x).", begin, end); free (header); return DC_STATUS_DATAFORMAT; } diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index 1a2b988..1250e1c 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -275,11 +275,15 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) gasmix[i].helium = data[19 + 2 * i + 1]; } } - if (initial < 1 || initial > ngasmixes) { - ERROR(abstract->context, "Invalid initial gas mix."); - return DC_STATUS_DATAFORMAT; + if (initial != 0xFF) { + if (initial < 1 || initial > ngasmixes) { + ERROR(abstract->context, "Invalid initial gas mix."); + return DC_STATUS_DATAFORMAT; + } + initial--; /* Convert to a zero based index. */ + } else { + WARNING(abstract->context, "No initial gas mix available."); } - initial--; /* Convert to a zero based index. */ // Cache the data for later use. parser->version = version; @@ -703,7 +707,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Initial gas mix. - if (time == samplerate) { + if (time == samplerate && parser->initial != 0xFF) { unsigned int idx = parser->initial; unsigned int o2 = parser->gasmix[idx].oxygen; unsigned int he = parser->gasmix[idx].helium; diff --git a/src/mares_common.c b/src/mares_common.c index 7f0655e..669de99 100644 --- a/src/mares_common.c +++ b/src/mares_common.c @@ -224,7 +224,7 @@ mares_common_extract_dives (dc_context_t *context, const mares_common_layout_t * // 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) { - ERROR (context, "Ringbuffer pointer out of range."); + ERROR (context, "Ringbuffer pointer out of range (0x%04x).", eop); return DC_STATUS_DATAFORMAT; } @@ -311,7 +311,7 @@ mares_common_extract_dives (dc_context_t *context, const mares_common_layout_t * // something is wrong and an error is returned. unsigned int length = array_uint16_le (buffer + offset); if (length != nbytes) { - ERROR (context, "Calculated and stored size are not equal."); + ERROR (context, "Calculated and stored size are not equal (%u %u).", length, nbytes); free (buffer); return DC_STATUS_DATAFORMAT; } @@ -339,7 +339,7 @@ mares_common_extract_dives (dc_context_t *context, const mares_common_layout_t * // equals the number of freedives in the profile data. If // both values are different, the profile data is incomplete. if (count != nsamples) { - ERROR (context, "Unexpected number of freedive sessions."); + ERROR (context, "Unexpected number of freedive sessions (%u %u).", count, nsamples); free (buffer); return DC_STATUS_DATAFORMAT; } diff --git a/src/mares_darwin.c b/src/mares_darwin.c index 5c2513b..957e7d9 100644 --- a/src/mares_darwin.c +++ b/src/mares_darwin.c @@ -267,14 +267,14 @@ mares_darwin_extract_dives (dc_device_t *abstract, const unsigned char data[], u // Get the profile pointer. unsigned int eop = array_uint16_be (data + 0x8A); if (eop < layout->rb_profile_begin || eop >= layout->rb_profile_end) { - ERROR (abstract->context, "Invalid ringbuffer pointer detected."); + ERROR (abstract->context, "Invalid ringbuffer pointer detected (0x%04x).", eop); return DC_STATUS_DATAFORMAT; } // Get the logbook index. unsigned int last = data[0x8C]; if (last >= layout->rb_logbook_count) { - ERROR (abstract->context, "Invalid ringbuffer pointer detected."); + ERROR (abstract->context, "Invalid ringbuffer pointer detected (0x%02x).", last); return DC_STATUS_DATAFORMAT; } diff --git a/src/mares_iconhd.c b/src/mares_iconhd.c index 49b7300..93b2dfc 100644 --- a/src/mares_iconhd.c +++ b/src/mares_iconhd.c @@ -478,7 +478,7 @@ mares_iconhd_extract_dives (dc_device_t *abstract, const unsigned char data[], u break; } if (eop < layout->rb_profile_begin || eop >= layout->rb_profile_end) { - ERROR (context, "Ringbuffer pointer out of range."); + ERROR (context, "Ringbuffer pointer out of range (0x%08x).", eop); return DC_STATUS_DATAFORMAT; } diff --git a/src/oceanic_atom2.c b/src/oceanic_atom2.c index 11cf940..98a8273 100644 --- a/src/oceanic_atom2.c +++ b/src/oceanic_atom2.c @@ -222,9 +222,9 @@ static const oceanic_common_layout_t oceanic_atom1_layout = { 0x0000, /* cf_devinfo */ 0x0040, /* cf_pointers */ 0x0240, /* rb_logbook_begin */ - 0x0A40, /* rb_logbook_end */ + 0x0440, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ - 0x0A40, /* rb_profile_begin */ + 0x0440, /* rb_profile_begin */ 0x8000, /* rb_profile_end */ 0, /* pt_mode_global */ 0 /* pt_mode_logbook */ diff --git a/src/oceanic_common.c b/src/oceanic_common.c index c51836f..f204309 100644 --- a/src/oceanic_common.c +++ b/src/oceanic_common.c @@ -261,7 +261,7 @@ oceanic_common_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac rb_logbook_last < layout->rb_logbook_begin || rb_logbook_last >= layout->rb_logbook_end) { - ERROR (abstract->context, "Invalid logbook pointer detected."); + ERROR (abstract->context, "Invalid logbook pointer detected (0x%04x 0x%04x).", rb_logbook_first, rb_logbook_last); return DC_STATUS_DATAFORMAT; } @@ -436,7 +436,7 @@ oceanic_common_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac rb_entry_last < layout->rb_profile_begin || rb_entry_last >= layout->rb_profile_end) { - ERROR (abstract->context, "Invalid ringbuffer pointer detected."); + ERROR (abstract->context, "Invalid ringbuffer pointer detected (0x%06x 0x%06x).", rb_entry_first, rb_entry_last); status = DC_STATUS_DATAFORMAT; begin = current + layout->rb_logbook_entry_size; abort = 1; diff --git a/src/shearwater_common.c b/src/shearwater_common.c index 801fce6..68a4209 100644 --- a/src/shearwater_common.c +++ b/src/shearwater_common.c @@ -36,7 +36,7 @@ #define ESC_END 0xDC #define ESC_ESC 0xDD -#define EXITCODE(n) ((n) < 0 ? (n) : 0) +#define EXITCODE(n) ((n) < 0 ? DC_STATUS_IO : DC_STATUS_TIMEOUT) dc_status_t shearwater_common_open (shearwater_common_device_t *device, dc_context_t *context, const char *name) @@ -173,7 +173,7 @@ shearwater_common_decompress_xor (unsigned char *data, unsigned int size) } -static int +static dc_status_t shearwater_common_slip_write (shearwater_common_device_t *device, const unsigned char data[], unsigned int size) { int n = 0; @@ -238,12 +238,12 @@ shearwater_common_slip_write (shearwater_common_device_t *device, const unsigned return EXITCODE(n); } - return size; + return DC_STATUS_SUCCESS; } -static int -shearwater_common_slip_read (shearwater_common_device_t *device, unsigned char data[], unsigned int size) +static dc_status_t +shearwater_common_slip_read (shearwater_common_device_t *device, unsigned char data[], unsigned int size, unsigned int *actual) { unsigned int received = 0; @@ -269,7 +269,7 @@ shearwater_common_slip_read (shearwater_common_device_t *device, unsigned char d // packets generated by the duplicate END characters which // are sent to try to detect line noise. if (received) - return received; + goto done; else break; case ESC: @@ -299,16 +299,25 @@ shearwater_common_slip_read (shearwater_common_device_t *device, unsigned char d } } - return received; +done: + + if (received > size) + return DC_STATUS_PROTOCOL; + + if (actual) + *actual = received; + + return DC_STATUS_SUCCESS; } dc_status_t shearwater_common_transfer (shearwater_common_device_t *device, const unsigned char input[], unsigned int isize, unsigned char output[], unsigned int osize, unsigned int *actual) { + dc_status_t status = DC_STATUS_SUCCESS; dc_device_t *abstract = (dc_device_t *) device; unsigned char packet[SZ_PACKET + 4]; - int n = 0; + unsigned int n = 0; if (isize > SZ_PACKET || osize > SZ_PACKET) return DC_STATUS_INVALIDARGS; @@ -324,13 +333,10 @@ shearwater_common_transfer (shearwater_common_device_t *device, const unsigned c memcpy (packet + 4, input, isize); // Send the request packet. - n = shearwater_common_slip_write (device, packet, isize + 4); - if (n != isize + 4) { + status = shearwater_common_slip_write (device, packet, isize + 4); + if (status != DC_STATUS_SUCCESS) { ERROR (abstract->context, "Failed to send the request packet."); - if (n < 0) - return DC_STATUS_IO; - else - return DC_STATUS_TIMEOUT; + return status; } // Return early if no response packet is requested. @@ -341,15 +347,10 @@ shearwater_common_transfer (shearwater_common_device_t *device, const unsigned c } // Receive the response packet. - n = shearwater_common_slip_read (device, packet, sizeof (packet)); - if (n <= 0 || n > sizeof (packet)) { + status = shearwater_common_slip_read (device, packet, sizeof (packet), &n); + if (status != DC_STATUS_SUCCESS) { ERROR (abstract->context, "Failed to receive the response packet."); - if (n < 0) - return DC_STATUS_IO; - else if (n > sizeof (packet)) - return DC_STATUS_PROTOCOL; - else - return DC_STATUS_TIMEOUT; + return status; } // Validate the packet header. diff --git a/src/suunto_common2.c b/src/suunto_common2.c index 366e63a..2149612 100644 --- a/src/suunto_common2.c +++ b/src/suunto_common2.c @@ -293,7 +293,7 @@ suunto_common2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac begin < layout->rb_profile_begin || begin >= layout->rb_profile_end) { - ERROR (abstract->context, "Invalid ringbuffer pointer detected."); + ERROR (abstract->context, "Invalid ringbuffer pointer detected (0x%04x 0x%04x 0x%04x %u).", begin, last, end, count); return DC_STATUS_DATAFORMAT; } @@ -335,7 +335,7 @@ suunto_common2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac unsigned int size = RB_PROFILE_DISTANCE (layout, current, previous, 1); if (size < 4 || size > remaining) { - ERROR (abstract->context, "Unexpected profile size."); + ERROR (abstract->context, "Unexpected profile size (%u %u).", size, remaining); free (data); return DC_STATUS_DATAFORMAT; } @@ -400,12 +400,12 @@ suunto_common2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac next < layout->rb_profile_begin || next >= layout->rb_profile_end) { - ERROR (abstract->context, "Invalid ringbuffer pointer detected."); + ERROR (abstract->context, "Invalid ringbuffer pointer detected (0x%04x 0x%04x).", prev, next); free (data); return DC_STATUS_DATAFORMAT; } if (next != previous && next != current) { - ERROR (abstract->context, "Profiles are not continuous."); + ERROR (abstract->context, "Profiles are not continuous (0x%04x 0x%04x 0x%04x).", current, next, previous); free (data); return DC_STATUS_DATAFORMAT; } @@ -422,7 +422,7 @@ suunto_common2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac return DC_STATUS_SUCCESS; } } else { - ERROR (abstract->context, "Skipping incomplete dive."); + ERROR (abstract->context, "Skipping incomplete dive (0x%04x 0x%04x 0x%04x).", current, next, previous); status = DC_STATUS_DATAFORMAT; } diff --git a/src/uwatec_smart_parser.c b/src/uwatec_smart_parser.c index 66542b3..969c7e4 100644 --- a/src/uwatec_smart_parser.c +++ b/src/uwatec_smart_parser.c @@ -721,7 +721,7 @@ uwatec_smart_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi *((unsigned int *) value) = array_uint16_le (data + table->divetime) * 60; break; case DC_FIELD_MAXDEPTH: - *((double *) value) = array_uint16_le (data + table->maxdepth) / 100.0 * salinity; + *((double *) value) = array_uint16_le (data + table->maxdepth) / 100.0 / salinity; break; case DC_FIELD_GASMIX_COUNT: *((unsigned int *) value) = parser->ngasmixes; @@ -1164,7 +1164,7 @@ uwatec_smart_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t } if (have_depth) { - sample.depth = (depth - depth_calibration) * salinity; + sample.depth = (depth - depth_calibration) / salinity; if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); } diff --git a/src/zeagle_n2ition3.c b/src/zeagle_n2ition3.c index 5c077d4..1c1dcf1 100644 --- a/src/zeagle_n2ition3.c +++ b/src/zeagle_n2ition3.c @@ -302,7 +302,7 @@ zeagle_n2ition3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callba last < RB_LOGBOOK_BEGIN || last >= RB_LOGBOOK_END) { if (last == 0xFF) return DC_STATUS_SUCCESS; - ERROR (abstract->context, "Invalid ringbuffer pointer detected."); + ERROR (abstract->context, "Invalid ringbuffer pointer detected (0x%02x 0x%02x).", first, last); return DC_STATUS_DATAFORMAT; } @@ -312,7 +312,7 @@ zeagle_n2ition3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callba // Get the profile pointer. unsigned int eop = array_uint16_le (config + 0x7E); if (eop < RB_PROFILE_BEGIN || eop >= RB_PROFILE_END) { - ERROR (abstract->context, "Invalid ringbuffer pointer detected."); + ERROR (abstract->context, "Invalid ringbuffer pointer detected (0x%04x).", eop); return DC_STATUS_DATAFORMAT; } @@ -327,7 +327,7 @@ zeagle_n2ition3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callba // Get the pointer to the profile data. unsigned int current = array_uint16_le (config + 2 * idx); if (current < RB_PROFILE_BEGIN || current >= RB_PROFILE_END) { - ERROR (abstract->context, "Invalid ringbuffer pointer detected."); + ERROR (abstract->context, "Invalid ringbuffer pointer detected (0x%04x).", current); return DC_STATUS_DATAFORMAT; }