Exclude the 4 byte length from the sample data.
Correctly skip the 4 byte length in front of the sample data. The previous code happened to work by accident, because the header after the sample data was assumed to be 4 bytes larger, and thus those two errors cancelled each other out.
This commit is contained in:
parent
786e4a7ae4
commit
1ce8dec1d8
@ -36,6 +36,8 @@
|
|||||||
#define ACK 0xAA
|
#define ACK 0xAA
|
||||||
#define EOF 0xEA
|
#define EOF 0xEA
|
||||||
|
|
||||||
|
#define HEADER 0x5C
|
||||||
|
|
||||||
#define RB_PROFILE_BEGIN 0xA000
|
#define RB_PROFILE_BEGIN 0xA000
|
||||||
#define RB_PROFILE_END MARES_ICONHD_MEMORY_SIZE
|
#define RB_PROFILE_END MARES_ICONHD_MEMORY_SIZE
|
||||||
|
|
||||||
@ -382,9 +384,9 @@ mares_iconhd_extract_dives (device_t *abstract, const unsigned char data[], unsi
|
|||||||
memcpy (buffer + RB_PROFILE_END - eop, data + RB_PROFILE_BEGIN, eop - RB_PROFILE_BEGIN);
|
memcpy (buffer + RB_PROFILE_END - eop, data + RB_PROFILE_BEGIN, eop - RB_PROFILE_BEGIN);
|
||||||
|
|
||||||
unsigned int offset = RB_PROFILE_END - RB_PROFILE_BEGIN;
|
unsigned int offset = RB_PROFILE_END - RB_PROFILE_BEGIN;
|
||||||
while (offset >= 0x60) {
|
while (offset >= HEADER + 4) {
|
||||||
// Get the number of samples in the profile data.
|
// Get the number of samples in the profile data.
|
||||||
unsigned int nsamples = array_uint16_le (buffer + offset - 0x5A);
|
unsigned int nsamples = array_uint16_le (buffer + offset - HEADER + 2);
|
||||||
if (nsamples == 0xFFFF)
|
if (nsamples == 0xFFFF)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -392,7 +394,7 @@ mares_iconhd_extract_dives (device_t *abstract, const unsigned char data[], unsi
|
|||||||
// If the buffer does not contain that much bytes, we reached the
|
// If the buffer does not contain that much bytes, we reached the
|
||||||
// end of the ringbuffer. The current dive is incomplete (partially
|
// end of the ringbuffer. The current dive is incomplete (partially
|
||||||
// overwritten with newer data), and processing should stop.
|
// overwritten with newer data), and processing should stop.
|
||||||
unsigned int nbytes = nsamples * 8 + 0x60;
|
unsigned int nbytes = 4 + nsamples * 8 + HEADER;
|
||||||
if (offset < nbytes)
|
if (offset < nbytes)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -411,7 +413,7 @@ mares_iconhd_extract_dives (device_t *abstract, const unsigned char data[], unsi
|
|||||||
return DEVICE_STATUS_ERROR;
|
return DEVICE_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *fp = buffer + offset + length - 0x56;
|
unsigned char *fp = buffer + offset + length - HEADER + 6;
|
||||||
if (device && memcmp (fp, device->fingerprint, sizeof (device->fingerprint)) == 0) {
|
if (device && memcmp (fp, device->fingerprint, sizeof (device->fingerprint)) == 0) {
|
||||||
free (buffer);
|
free (buffer);
|
||||||
return DEVICE_STATUS_SUCCESS;
|
return DEVICE_STATUS_SUCCESS;
|
||||||
|
|||||||
@ -26,6 +26,8 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "array.h"
|
#include "array.h"
|
||||||
|
|
||||||
|
#define HEADER 0x5C
|
||||||
|
|
||||||
typedef struct mares_iconhd_parser_t mares_iconhd_parser_t;
|
typedef struct mares_iconhd_parser_t mares_iconhd_parser_t;
|
||||||
|
|
||||||
struct mares_iconhd_parser_t {
|
struct mares_iconhd_parser_t {
|
||||||
@ -108,10 +110,10 @@ mares_iconhd_parser_get_datetime (parser_t *abstract, dc_datetime_t *datetime)
|
|||||||
|
|
||||||
unsigned int length = array_uint32_le (abstract->data);
|
unsigned int length = array_uint32_le (abstract->data);
|
||||||
|
|
||||||
if (abstract->size < length || length < 0x60)
|
if (abstract->size < length || length < HEADER + 4)
|
||||||
return PARSER_STATUS_ERROR;
|
return PARSER_STATUS_ERROR;
|
||||||
|
|
||||||
const unsigned char *p = abstract->data + length - 0x56;
|
const unsigned char *p = abstract->data + length - HEADER + 6;
|
||||||
|
|
||||||
if (datetime) {
|
if (datetime) {
|
||||||
datetime->hour = array_uint16_le (p + 0);
|
datetime->hour = array_uint16_le (p + 0);
|
||||||
@ -134,27 +136,27 @@ mares_iconhd_parser_get_field (parser_t *abstract, parser_field_type_t type, uns
|
|||||||
|
|
||||||
unsigned int length = array_uint32_le (abstract->data);
|
unsigned int length = array_uint32_le (abstract->data);
|
||||||
|
|
||||||
if (abstract->size < length || length < 0x60)
|
if (abstract->size < length || length < HEADER + 4)
|
||||||
return PARSER_STATUS_ERROR;
|
return PARSER_STATUS_ERROR;
|
||||||
|
|
||||||
const unsigned char *p = abstract->data + length - 0x60;
|
const unsigned char *p = abstract->data + length - HEADER;
|
||||||
|
|
||||||
gasmix_t *gasmix = (gasmix_t *) value;
|
gasmix_t *gasmix = (gasmix_t *) value;
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case FIELD_TYPE_DIVETIME:
|
case FIELD_TYPE_DIVETIME:
|
||||||
*((unsigned int *) value) = array_uint16_le (p + 0x06) * 5;
|
*((unsigned int *) value) = array_uint16_le (p + 0x02) * 5;
|
||||||
break;
|
break;
|
||||||
case FIELD_TYPE_MAXDEPTH:
|
case FIELD_TYPE_MAXDEPTH:
|
||||||
*((double *) value) = array_uint16_le (p + 0x08) / 10.0;
|
*((double *) value) = array_uint16_le (p + 0x04) / 10.0;
|
||||||
break;
|
break;
|
||||||
case FIELD_TYPE_GASMIX_COUNT:
|
case FIELD_TYPE_GASMIX_COUNT:
|
||||||
*((unsigned int *) value) = 3;
|
*((unsigned int *) value) = 3;
|
||||||
break;
|
break;
|
||||||
case FIELD_TYPE_GASMIX:
|
case FIELD_TYPE_GASMIX:
|
||||||
gasmix->helium = 0.0;
|
gasmix->helium = 0.0;
|
||||||
gasmix->oxygen = p[0x18 + flags * 4] / 100.0;
|
gasmix->oxygen = p[0x14 + flags * 4] / 100.0;
|
||||||
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
|
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -174,16 +176,16 @@ mares_iconhd_parser_samples_foreach (parser_t *abstract, sample_callback_t callb
|
|||||||
|
|
||||||
unsigned int length = array_uint32_le (abstract->data);
|
unsigned int length = array_uint32_le (abstract->data);
|
||||||
|
|
||||||
if (abstract->size < length || length < 0x60)
|
if (abstract->size < length || length < HEADER + 4)
|
||||||
return PARSER_STATUS_ERROR;
|
return PARSER_STATUS_ERROR;
|
||||||
|
|
||||||
const unsigned char *data = abstract->data;
|
const unsigned char *data = abstract->data;
|
||||||
unsigned int size = length - 0x60;
|
unsigned int size = length - HEADER;
|
||||||
|
|
||||||
unsigned int time = 0;
|
unsigned int time = 0;
|
||||||
unsigned int interval = 5;
|
unsigned int interval = 5;
|
||||||
|
|
||||||
unsigned int offset = 0;
|
unsigned int offset = 4;
|
||||||
while (offset + 8 <= size) {
|
while (offset + 8 <= size) {
|
||||||
parser_sample_value_t sample = {0};
|
parser_sample_value_t sample = {0};
|
||||||
|
|
||||||
@ -193,12 +195,12 @@ mares_iconhd_parser_samples_foreach (parser_t *abstract, sample_callback_t callb
|
|||||||
if (callback) callback (SAMPLE_TYPE_TIME, sample, userdata);
|
if (callback) callback (SAMPLE_TYPE_TIME, sample, userdata);
|
||||||
|
|
||||||
// Depth (1/10 m).
|
// Depth (1/10 m).
|
||||||
unsigned int depth = array_uint16_le (data + offset + 4);
|
unsigned int depth = array_uint16_le (data + offset + 0);
|
||||||
sample.depth = depth / 10.0;
|
sample.depth = depth / 10.0;
|
||||||
if (callback) callback (SAMPLE_TYPE_DEPTH, sample, userdata);
|
if (callback) callback (SAMPLE_TYPE_DEPTH, sample, userdata);
|
||||||
|
|
||||||
// Temperature (1/10 °C).
|
// Temperature (1/10 °C).
|
||||||
unsigned int temperature = array_uint16_le (data + offset + 6);
|
unsigned int temperature = array_uint16_le (data + offset + 2);
|
||||||
sample.temperature = temperature / 10.0;
|
sample.temperature = temperature / 10.0;
|
||||||
if (callback) callback (SAMPLE_TYPE_TEMPERATURE, sample, userdata);
|
if (callback) callback (SAMPLE_TYPE_TEMPERATURE, sample, userdata);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user