Use symbolic constants for the header offsets
This commit is contained in:
@@ -89,6 +89,16 @@
|
|||||||
#define NODELAY 0
|
#define NODELAY 0
|
||||||
#define TIMEOUT 400
|
#define TIMEOUT 400
|
||||||
|
|
||||||
|
#define HDR_COMPACT_LENGTH 0 // 3 bytes
|
||||||
|
#define HDR_COMPACT_SUMMARY 3 // 10 bytes
|
||||||
|
#define HDR_COMPACT_NUMBER 13 // 2 bytes
|
||||||
|
|
||||||
|
#define HDR_FULL_LENGTH 9 // 3 bytes
|
||||||
|
#define HDR_FULL_SUMMARY 12 // 10 bytes
|
||||||
|
#define HDR_FULL_NUMBER 80 // 2 bytes
|
||||||
|
|
||||||
|
#define HDR_FULL_FIRMWARE 48 // 2 bytes
|
||||||
|
|
||||||
typedef enum hw_ostc3_state_t {
|
typedef enum hw_ostc3_state_t {
|
||||||
OPEN,
|
OPEN,
|
||||||
DOWNLOAD,
|
DOWNLOAD,
|
||||||
@@ -155,16 +165,16 @@ static const dc_device_vtable_t hw_ostc3_device_vtable = {
|
|||||||
|
|
||||||
static const hw_ostc3_logbook_t hw_ostc3_logbook_compact = {
|
static const hw_ostc3_logbook_t hw_ostc3_logbook_compact = {
|
||||||
RB_LOGBOOK_SIZE_COMPACT, /* size */
|
RB_LOGBOOK_SIZE_COMPACT, /* size */
|
||||||
0, /* profile */
|
HDR_COMPACT_LENGTH, /* profile */
|
||||||
3, /* fingerprint */
|
HDR_COMPACT_SUMMARY, /* fingerprint */
|
||||||
13, /* number */
|
HDR_COMPACT_NUMBER, /* number */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const hw_ostc3_logbook_t hw_ostc3_logbook_full = {
|
static const hw_ostc3_logbook_t hw_ostc3_logbook_full = {
|
||||||
RB_LOGBOOK_SIZE_FULL, /* size */
|
RB_LOGBOOK_SIZE_FULL, /* size */
|
||||||
9, /* profile */
|
HDR_FULL_LENGTH, /* profile */
|
||||||
12, /* fingerprint */
|
HDR_FULL_SUMMARY, /* fingerprint */
|
||||||
80, /* number */
|
HDR_FULL_NUMBER, /* number */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -769,7 +779,7 @@ hw_ostc3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, voi
|
|||||||
unsigned int length = RB_LOGBOOK_SIZE_FULL + array_uint24_le (header + offset + logbook->profile) - 3;
|
unsigned int length = RB_LOGBOOK_SIZE_FULL + array_uint24_le (header + offset + logbook->profile) - 3;
|
||||||
if (!compact) {
|
if (!compact) {
|
||||||
// Workaround for a bug in older firmware versions.
|
// Workaround for a bug in older firmware versions.
|
||||||
unsigned int firmware = array_uint16_be (header + offset + 0x30);
|
unsigned int firmware = array_uint16_be (header + offset + HDR_FULL_FIRMWARE);
|
||||||
if (firmware < OSTC3FW(0,93))
|
if (firmware < OSTC3FW(0,93))
|
||||||
length -= 3;
|
length -= 3;
|
||||||
}
|
}
|
||||||
@@ -817,7 +827,7 @@ hw_ostc3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, voi
|
|||||||
unsigned int length = RB_LOGBOOK_SIZE_FULL + array_uint24_le (header + offset + logbook->profile) - 3;
|
unsigned int length = RB_LOGBOOK_SIZE_FULL + array_uint24_le (header + offset + logbook->profile) - 3;
|
||||||
if (!compact) {
|
if (!compact) {
|
||||||
// Workaround for a bug in older firmware versions.
|
// Workaround for a bug in older firmware versions.
|
||||||
unsigned int firmware = array_uint16_be (header + offset + 0x30);
|
unsigned int firmware = array_uint16_be (header + offset + HDR_FULL_FIRMWARE);
|
||||||
if (firmware < OSTC3FW(0,93))
|
if (firmware < OSTC3FW(0,93))
|
||||||
length -= 3;
|
length -= 3;
|
||||||
}
|
}
|
||||||
@@ -853,7 +863,7 @@ hw_ostc3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, voi
|
|||||||
// A profile containing only the 2 byte end-of-profile
|
// A profile containing only the 2 byte end-of-profile
|
||||||
// marker is considered a valid empty profile.
|
// marker is considered a valid empty profile.
|
||||||
} else if (length < RB_LOGBOOK_SIZE_FULL + 5 + 2 ||
|
} else if (length < RB_LOGBOOK_SIZE_FULL + 5 + 2 ||
|
||||||
array_uint24_le (profile + RB_LOGBOOK_SIZE_FULL) + delta != array_uint24_le (profile + 9)) {
|
array_uint24_le (profile + RB_LOGBOOK_SIZE_FULL) + delta != array_uint24_le (profile + HDR_FULL_LENGTH)) {
|
||||||
// If there is more data available, then there should be a
|
// If there is more data available, then there should be a
|
||||||
// valid profile header containing a length matching the
|
// valid profile header containing a length matching the
|
||||||
// length in the dive header.
|
// length in the dive header.
|
||||||
@@ -861,7 +871,7 @@ hw_ostc3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, voi
|
|||||||
length = RB_LOGBOOK_SIZE_FULL;
|
length = RB_LOGBOOK_SIZE_FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callback && !callback (profile, length, profile + 12, sizeof (device->fingerprint), userdata))
|
if (callback && !callback (profile, length, profile + HDR_FULL_SUMMARY, sizeof (device->fingerprint), userdata))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user