Merge branch 'master' into Subsurface-branch

This commit is contained in:
Dirk Hohndel 2015-11-06 22:24:56 -08:00
commit 290f2781ea
6 changed files with 234 additions and 122 deletions

View File

@ -26,9 +26,15 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#if defined(__GNUC__)
#define ATTR_FORMAT_PRINTF(a,b) __attribute__((format(printf, a, b)))
#else
#define ATTR_FORMAT_PRINTF(a,b)
#endif
#define WARNING(expr) message ("%s:%d: %s\n", __FILE__, __LINE__, expr) #define WARNING(expr) message ("%s:%d: %s\n", __FILE__, __LINE__, expr)
int message (const char* fmt, ...); int message (const char* fmt, ...) ATTR_FORMAT_PRINTF(1, 2);
void message_set_logfile (const char* filename); void message_set_logfile (const char* filename);

View File

@ -284,7 +284,7 @@ atomics_cobalt_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init,
unsigned char packet[8 * 1024] = {0}; unsigned char packet[8 * 1024] = {0};
rc = libusb_bulk_transfer (device->handle, 0x82, rc = libusb_bulk_transfer (device->handle, 0x82,
packet, sizeof (packet), &length, TIMEOUT); packet, sizeof (packet), &length, TIMEOUT);
if (rc != LIBUSB_SUCCESS) { if (rc != LIBUSB_SUCCESS && rc != LIBUSB_ERROR_TIMEOUT) {
ERROR (abstract->context, "Failed to receive the answer."); ERROR (abstract->context, "Failed to receive the answer.");
return EXITCODE(rc); return EXITCODE(rc);
} }

View File

@ -34,13 +34,25 @@ extern "C" {
#define UNUSED(x) (void)sizeof(x) #define UNUSED(x) (void)sizeof(x)
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
#define FUNCTION __func__
#else
#define FUNCTION __FUNCTION__
#endif
#if defined(__GNUC__)
#define ATTR_FORMAT_PRINTF(a,b) __attribute__((format(printf, a, b)))
#else
#define ATTR_FORMAT_PRINTF(a,b)
#endif
#ifdef ENABLE_LOGGING #ifdef ENABLE_LOGGING
#define HEXDUMP(context, loglevel, prefix, data, size) dc_context_hexdump (context, loglevel, __FILE__, __LINE__, __FUNCTION__, prefix, data, size) #define HEXDUMP(context, loglevel, prefix, data, size) dc_context_hexdump (context, loglevel, __FILE__, __LINE__, FUNCTION, prefix, data, size)
#define SYSERROR(context, errcode) dc_context_syserror (context, DC_LOGLEVEL_ERROR, __FILE__, __LINE__, __FUNCTION__, errcode) #define SYSERROR(context, errcode) dc_context_syserror (context, DC_LOGLEVEL_ERROR, __FILE__, __LINE__, FUNCTION, errcode)
#define ERROR(context, ...) dc_context_log (context, DC_LOGLEVEL_ERROR, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__) #define ERROR(context, ...) dc_context_log (context, DC_LOGLEVEL_ERROR, __FILE__, __LINE__, FUNCTION, __VA_ARGS__)
#define WARNING(context, ...) dc_context_log (context, DC_LOGLEVEL_WARNING, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__) #define WARNING(context, ...) dc_context_log (context, DC_LOGLEVEL_WARNING, __FILE__, __LINE__, FUNCTION, __VA_ARGS__)
#define INFO(context, ...) dc_context_log (context, DC_LOGLEVEL_INFO, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__) #define INFO(context, ...) dc_context_log (context, DC_LOGLEVEL_INFO, __FILE__, __LINE__, FUNCTION, __VA_ARGS__)
#define DEBUG(context, ...) dc_context_log (context, DC_LOGLEVEL_DEBUG, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__) #define DEBUG(context, ...) dc_context_log (context, DC_LOGLEVEL_DEBUG, __FILE__, __LINE__, FUNCTION, __VA_ARGS__)
#else #else
#define HEXDUMP(context, loglevel, prefix, data, size) UNUSED(context) #define HEXDUMP(context, loglevel, prefix, data, size) UNUSED(context)
#define SYSERROR(context, errcode) UNUSED(context) #define SYSERROR(context, errcode) UNUSED(context)
@ -51,7 +63,7 @@ extern "C" {
#endif #endif
dc_status_t dc_status_t
dc_context_log (dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *format, ...); dc_context_log (dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *format, ...) ATTR_FORMAT_PRINTF(6, 7);
dc_status_t dc_status_t
dc_context_syserror (dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, int errcode); dc_context_syserror (dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, int errcode);

View File

@ -232,6 +232,7 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser)
header = 256; header = 256;
break; break;
case 0x23: case 0x23:
case 0x24:
layout = &hw_ostc_layout_ostc3; layout = &hw_ostc_layout_ostc3;
header = 256; header = 256;
break; break;
@ -256,7 +257,7 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser)
gasmix[i].oxygen = data[25 + 2 * i]; gasmix[i].oxygen = data[25 + 2 * i];
gasmix[i].helium = 0; gasmix[i].helium = 0;
} }
} else if (version == 0x23) { } else if (version == 0x23 || version == 0x24) {
ngasmixes = 5; ngasmixes = 5;
for (unsigned int i = 0; i < ngasmixes; ++i) { for (unsigned int i = 0; i < ngasmixes; ++i) {
gasmix[i].oxygen = data[28 + 4 * i + 0]; gasmix[i].oxygen = data[28 + 4 * i + 0];
@ -392,7 +393,7 @@ hw_ostc_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime)
const unsigned char *p = data + layout->datetime; const unsigned char *p = data + layout->datetime;
dc_datetime_t dt; dc_datetime_t dt;
if (version == 0x23) { if (version == 0x23 || version == 0x24) {
dt.year = p[0] + 2000; dt.year = p[0] + 2000;
dt.month = p[1]; dt.month = p[1];
dt.day = p[2]; dt.day = p[2];
@ -405,14 +406,19 @@ hw_ostc_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime)
dt.minute = p[4]; dt.minute = p[4];
dt.second = 0; dt.second = 0;
dc_ticks_t ticks = dc_datetime_mktime (&dt); if (version == 0x24) {
if (ticks == (dc_ticks_t) -1) if (datetime)
return DC_STATUS_DATAFORMAT; *datetime = dt;
} else {
dc_ticks_t ticks = dc_datetime_mktime (&dt);
if (ticks == (dc_ticks_t) -1)
return DC_STATUS_DATAFORMAT;
ticks -= divetime; ticks -= divetime;
if (!dc_datetime_localtime (datetime, ticks)) if (!dc_datetime_localtime (datetime, ticks))
return DC_STATUS_DATAFORMAT; return DC_STATUS_DATAFORMAT;
}
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }
@ -446,7 +452,7 @@ hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned
dc_field_string_t *string = (dc_field_string_t *) value; dc_field_string_t *string = (dc_field_string_t *) value;
unsigned int salinity = data[layout->salinity]; unsigned int salinity = data[layout->salinity];
if (version == 0x23) if (version == 0x23 || version == 0x24)
salinity += 100; salinity += 100;
char buf[BUFLEN]; char buf[BUFLEN];
@ -518,7 +524,7 @@ hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned
default: default:
return DC_STATUS_DATAFORMAT; return DC_STATUS_DATAFORMAT;
} }
} else if (version == 0x23) { } else if (version == 0x23 || version == 0x24) {
switch (data[82]) { switch (data[82]) {
case OSTC3_OC: case OSTC3_OC:
*((dc_divemode_t *) value) = DC_DIVEMODE_OC; *((dc_divemode_t *) value) = DC_DIVEMODE_OC;
@ -616,14 +622,14 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call
// Get the sample rate. // Get the sample rate.
unsigned int samplerate = 0; unsigned int samplerate = 0;
if (version == 0x23) if (version == 0x23 || version == 0x24)
samplerate = data[header + 3]; samplerate = data[header + 3];
else else
samplerate = data[36]; samplerate = data[36];
// Get the salinity factor. // Get the salinity factor.
unsigned int salinity = data[layout->salinity]; unsigned int salinity = data[layout->salinity];
if (version == 0x23) if (version == 0x23 || version == 0x24)
salinity += 100; salinity += 100;
if (salinity < 100 || salinity > 104) if (salinity < 100 || salinity > 104)
salinity = 100; salinity = 100;
@ -631,7 +637,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call
// Get the number of sample descriptors. // Get the number of sample descriptors.
unsigned int nconfig = 0; unsigned int nconfig = 0;
if (version == 0x23) if (version == 0x23 || version == 0x24)
nconfig = data[header + 4]; nconfig = data[header + 4];
else else
nconfig = 6; nconfig = 6;
@ -643,7 +649,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call
// Get the extended sample configuration. // Get the extended sample configuration.
hw_ostc_sample_info_t info[MAXCONFIG] = {{0}}; hw_ostc_sample_info_t info[MAXCONFIG] = {{0}};
for (unsigned int i = 0; i < nconfig; ++i) { for (unsigned int i = 0; i < nconfig; ++i) {
if (version == 0x23) { if (version == 0x23 || version == 0x24) {
info[i].type = data[header + 5 + 3 * i + 0]; info[i].type = data[header + 5 + 3 * i + 0];
info[i].size = data[header + 5 + 3 * i + 1]; info[i].size = data[header + 5 + 3 * i + 1];
info[i].divisor = data[header + 5 + 3 * i + 2]; info[i].divisor = data[header + 5 + 3 * i + 2];
@ -684,7 +690,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call
unsigned int nsamples = 0; unsigned int nsamples = 0;
unsigned int offset = header; unsigned int offset = header;
if (version == 0x23) if (version == 0x23 || version == 0x24)
offset += 5 + 3 * nconfig; offset += 5 + 3 * nconfig;
while (offset + 3 <= size) { while (offset + 3 <= size) {
dc_sample_value_t sample = {0}; dc_sample_value_t sample = {0};
@ -728,7 +734,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call
unsigned int nbits = 0; unsigned int nbits = 0;
unsigned int events = 0; unsigned int events = 0;
while (data[offset - 1] & 0x80) { while (data[offset - 1] & 0x80) {
if (nbits && version != 0x23) if (nbits && version != 0x23 && version != 0x24)
break; break;
if (length < 1) { if (length < 1) {
ERROR (abstract->context, "Buffer overflow detected!"); ERROR (abstract->context, "Buffer overflow detected!");
@ -822,7 +828,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call
length--; length--;
} }
if (version == 0x23) { if (version == 0x23 || version == 0x24) {
// SetPoint Change // SetPoint Change
if (events & 0x40) { if (events & 0x40) {
if (length < 1) { if (length < 1) {
@ -912,7 +918,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call
} }
} }
if (version != 0x23) { if (version != 0x23 && version != 0x24) {
// SetPoint Change // SetPoint Change
if (events & 0x40) { if (events & 0x40) {
if (length < 1) { if (length < 1) {

View File

@ -81,6 +81,11 @@
#define GAUGE 1 #define GAUGE 1
#define FREEDIVE 2 #define FREEDIVE 2
#define NGASMIXES 6
#define HEADER 1
#define PROFILE 2
typedef struct oceanic_atom2_parser_t oceanic_atom2_parser_t; typedef struct oceanic_atom2_parser_t oceanic_atom2_parser_t;
struct oceanic_atom2_parser_t { struct oceanic_atom2_parser_t {
@ -91,6 +96,12 @@ struct oceanic_atom2_parser_t {
unsigned int serial; unsigned int serial;
// Cached fields. // Cached fields.
unsigned int cached; unsigned int cached;
unsigned int header;
unsigned int footer;
unsigned int mode;
unsigned int ngasmixes;
unsigned int oxygen[NGASMIXES];
unsigned int helium[NGASMIXES];
unsigned int divetime; unsigned int divetime;
double maxdepth; double maxdepth;
}; };
@ -156,6 +167,14 @@ oceanic_atom2_parser_create (dc_parser_t **out, dc_context_t *context, unsigned
parser->serial = serial; parser->serial = serial;
parser->cached = 0; parser->cached = 0;
parser->header = 0;
parser->footer = 0;
parser->mode = NORMAL;
parser->ngasmixes = 0;
for (unsigned int i = 0; i < NGASMIXES; ++i) {
parser->oxygen[i] = 0;
parser->helium[i] = 0;
}
parser->divetime = 0; parser->divetime = 0;
parser->maxdepth = 0.0; parser->maxdepth = 0.0;
@ -182,6 +201,14 @@ oceanic_atom2_parser_set_data (dc_parser_t *abstract, const unsigned char *data,
// Reset the cache. // Reset the cache.
parser->cached = 0; parser->cached = 0;
parser->header = 0;
parser->footer = 0;
parser->mode = NORMAL;
parser->ngasmixes = 0;
for (unsigned int i = 0; i < NGASMIXES; ++i) {
parser->oxygen[i] = 0;
parser->helium[i] = 0;
}
parser->divetime = 0; parser->divetime = 0;
parser->maxdepth = 0.0; parser->maxdepth = 0.0;
@ -325,12 +352,14 @@ oceanic_atom2_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetim
#define BUF_LEN 16 #define BUF_LEN 16
static dc_status_t static dc_status_t
oceanic_atom2_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value) oceanic_atom2_parser_cache (oceanic_atom2_parser_t *parser)
{ {
oceanic_atom2_parser_t *parser = (oceanic_atom2_parser_t *) abstract; const unsigned char *data = parser->base.data;
unsigned int size = parser->base.size;
const unsigned char *data = abstract->data; if (parser->cached) {
unsigned int size = abstract->size; return DC_STATUS_SUCCESS;
}
// Get the total amount of bytes before and after the profile data. // Get the total amount of bytes before and after the profile data.
unsigned int headersize = parser->headersize; unsigned int headersize = parser->headersize;
@ -357,14 +386,88 @@ oceanic_atom2_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, uns
mode = (data[1] & 0x60) >> 5; mode = (data[1] & 0x60) >> 5;
} }
if (!parser->cached) { // Get the gas mixes.
sample_statistics_t statistics = SAMPLE_STATISTICS_INITIALIZER; unsigned int ngasmixes = 0;
dc_status_t rc = oceanic_atom2_parser_samples_foreach ( unsigned int o2_offset = 0;
abstract, sample_statistics_cb, &statistics); unsigned int he_offset = 0;
if (rc != DC_STATUS_SUCCESS) if (mode == FREEDIVE) {
return rc; ngasmixes = 0;
} else if (parser->model == DATAMASK || parser->model == COMPUMASK) {
ngasmixes = 1;
o2_offset = header + 3;
} else if (parser->model == VT4 || parser->model == VT41 ||
parser->model == A300AI) {
o2_offset = header + 4;
ngasmixes = 4;
} else if (parser->model == OCI) {
o2_offset = 0x28;
ngasmixes = 4;
} else if (parser->model == TX1) {
o2_offset = 0x3E;
he_offset = 0x48;
ngasmixes = 6;
} else if (parser->model == A300CS || parser->model == VTX) {
o2_offset = 0x2A;
if (data[0x39] & 0x04) {
ngasmixes = 1;
} else if (data[0x39] & 0x08) {
ngasmixes = 2;
} else if (data[0x39] & 0x10) {
ngasmixes = 3;
} else {
ngasmixes = 4;
}
} else {
o2_offset = header + 4;
ngasmixes = 3;
}
parser->cached = 1; // Cache the data for later use.
parser->header = header;
parser->footer = footer;
parser->mode = mode;
parser->ngasmixes = ngasmixes;
for (unsigned int i = 0; i < ngasmixes; ++i) {
if (data[o2_offset + i]) {
parser->oxygen[i] = data[o2_offset + i];
} else {
parser->oxygen[i] = 21;
}
if (he_offset) {
parser->helium[i] = data[he_offset + i];
} else {
parser->helium[i] = 0;
}
}
parser->cached = HEADER;
return DC_STATUS_SUCCESS;
}
static dc_status_t
oceanic_atom2_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value)
{
dc_status_t status = DC_STATUS_SUCCESS;
oceanic_atom2_parser_t *parser = (oceanic_atom2_parser_t *) abstract;
const unsigned char *data = abstract->data;
unsigned int size = abstract->size;
// Cache the header data.
status = oceanic_atom2_parser_cache (parser);
if (status != DC_STATUS_SUCCESS)
return status;
// Cache the profile data.
if (parser->cached < PROFILE) {
sample_statistics_t statistics = SAMPLE_STATISTICS_INITIALIZER;
status = oceanic_atom2_parser_samples_foreach (
abstract, sample_statistics_cb, &statistics);
if (status != DC_STATUS_SUCCESS)
return status;
parser->cached = PROFILE;
parser->divetime = statistics.divetime; parser->divetime = statistics.divetime;
parser->maxdepth = statistics.maxdepth; parser->maxdepth = statistics.maxdepth;
} }
@ -373,8 +476,6 @@ oceanic_atom2_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, uns
dc_salinity_t *water = (dc_salinity_t *) value; dc_salinity_t *water = (dc_salinity_t *) value;
dc_field_string_t *string = (dc_field_string_t *) value; dc_field_string_t *string = (dc_field_string_t *) value;
unsigned int oxygen = 0;
unsigned int helium = 0;
char buf[BUF_LEN]; char buf[BUF_LEN];
if (value) { if (value) {
@ -389,47 +490,14 @@ oceanic_atom2_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, uns
if (parser->model == F10 || parser->model == F11) if (parser->model == F10 || parser->model == F11)
*((double *) value) = array_uint16_le (data + 4) / 16.0 * FEET; *((double *) value) = array_uint16_le (data + 4) / 16.0 * FEET;
else else
*((double *) value) = array_uint16_le (data + footer + 4) / 16.0 * FEET; *((double *) value) = array_uint16_le (data + parser->footer + 4) / 16.0 * FEET;
break; break;
case DC_FIELD_GASMIX_COUNT: case DC_FIELD_GASMIX_COUNT:
if (mode == FREEDIVE) { *((unsigned int *) value) = parser->ngasmixes;
*((unsigned int *) value) = 0;
} else if (parser->model == DATAMASK || parser->model == COMPUMASK) {
*((unsigned int *) value) = 1;
} else if (parser->model == VT4 || parser->model == VT41 ||
parser->model == OCI || parser->model == A300AI) {
*((unsigned int *) value) = 4;
} else if (parser->model == TX1) {
*((unsigned int *) value) = 6;
} else if (parser->model == A300CS || parser->model == VTX) {
if (data[0x39] & 0x04) {
*((unsigned int *) value) = 1;
} else if (data[0x39] & 0x08) {
*((unsigned int *) value) = 2;
} else if (data[0x39] & 0x10) {
*((unsigned int *) value) = 3;
} else {
*((unsigned int *) value) = 4;
}
} else {
*((unsigned int *) value) = 3;
}
break; break;
case DC_FIELD_GASMIX: case DC_FIELD_GASMIX:
if (parser->model == DATAMASK || parser->model == COMPUMASK) { gasmix->oxygen = parser->oxygen[flags] / 100.0;
oxygen = data[header + 3]; gasmix->helium = parser->helium[flags] / 100.0;
} else if (parser->model == OCI) {
oxygen = data[0x28 + flags];
} else if (parser->model == A300CS || parser->model == VTX) {
oxygen = data[0x2A + flags];
} else if (parser->model == TX1) {
oxygen = data[0x3E + flags];
helium = data[0x48 + flags];
} else {
oxygen = data[header + 4 + flags];
}
gasmix->helium = helium / 100.0;
gasmix->oxygen = (oxygen ? oxygen / 100.0 : 0.21);
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
break; break;
case DC_FIELD_SALINITY: case DC_FIELD_SALINITY:
@ -445,7 +513,7 @@ oceanic_atom2_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, uns
} }
break; break;
case DC_FIELD_DIVEMODE: case DC_FIELD_DIVEMODE:
switch (mode) { switch (parser->mode) {
case NORMAL: case NORMAL:
*((unsigned int *) value) = DC_DIVEMODE_OC; *((unsigned int *) value) = DC_DIVEMODE_OC;
break; break;
@ -482,38 +550,20 @@ oceanic_atom2_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, uns
static dc_status_t static dc_status_t
oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata) oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata)
{ {
dc_status_t status = DC_STATUS_SUCCESS;
oceanic_atom2_parser_t *parser = (oceanic_atom2_parser_t *) abstract; oceanic_atom2_parser_t *parser = (oceanic_atom2_parser_t *) abstract;
const unsigned char *data = abstract->data; const unsigned char *data = abstract->data;
unsigned int size = abstract->size; unsigned int size = abstract->size;
// Get the total amount of bytes before and after the profile data. // Cache the header data.
unsigned int headersize = parser->headersize; status = oceanic_atom2_parser_cache (parser);
unsigned int footersize = parser->footersize; if (status != DC_STATUS_SUCCESS)
if (size < headersize + footersize) return status;
return DC_STATUS_DATAFORMAT;
// Get the offset to the header sample.
unsigned int header = headersize - PAGESIZE / 2;
if (parser->model == VT4 || parser->model == VT41 ||
parser->model == A300AI) {
header = 3 * PAGESIZE;
}
// Get the dive mode.
unsigned int mode = NORMAL;
if (parser->model == F10 || parser->model == F11) {
mode = FREEDIVE;
} else if (parser->model == T3B || parser->model == VT3 ||
parser->model == DG03) {
mode = (data[2] & 0xC0) >> 6;
} else if (parser->model == VEO20 || parser->model == VEO30) {
mode = (data[1] & 0x60) >> 5;
}
unsigned int time = 0; unsigned int time = 0;
unsigned int interval = 1; unsigned int interval = 1;
if (mode != FREEDIVE) { if (parser->mode != FREEDIVE) {
unsigned int idx = 0x17; unsigned int idx = 0x17;
if (parser->model == A300CS || parser->model == VTX) if (parser->model == A300CS || parser->model == VTX)
idx = 0x1f; idx = 0x1f;
@ -534,7 +584,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_
} }
unsigned int samplesize = PAGESIZE / 2; unsigned int samplesize = PAGESIZE / 2;
if (mode == FREEDIVE) { if (parser->mode == FREEDIVE) {
if (parser->model == F10 || parser->model == F11) { if (parser->model == F10 || parser->model == F11) {
samplesize = 2; samplesize = 2;
} else { } else {
@ -548,7 +598,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_
} }
unsigned int have_temperature = 1, have_pressure = 1; unsigned int have_temperature = 1, have_pressure = 1;
if (mode == FREEDIVE) { if (parser->mode == FREEDIVE) {
have_temperature = 0; have_temperature = 0;
have_pressure = 0; have_pressure = 0;
} else if (parser->model == VEO30 || parser->model == OCS || } else if (parser->model == VEO30 || parser->model == OCS ||
@ -562,7 +612,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_
// Initial temperature. // Initial temperature.
unsigned int temperature = 0; unsigned int temperature = 0;
if (have_temperature) { if (have_temperature) {
temperature = data[header + 7]; temperature = data[parser->header + 7];
} }
// Initial tank pressure. // Initial tank pressure.
@ -572,14 +622,17 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_
unsigned int idx = 2; unsigned int idx = 2;
if (parser->model == A300CS || parser->model == VTX) if (parser->model == A300CS || parser->model == VTX)
idx = 16; idx = 16;
pressure = data[header + idx] + (data[header + idx + 1] << 8); pressure = array_uint16_le(data + parser->header + idx);
if (pressure == 10000) if (pressure == 10000)
have_pressure = 0; have_pressure = 0;
} }
// Initial gas mix.
unsigned int gasmix_previous = 0xFFFFFFFF;
unsigned int complete = 1; unsigned int complete = 1;
unsigned int offset = headersize; unsigned int offset = parser->headersize;
while (offset + samplesize <= size - footersize) { while (offset + samplesize <= size - parser->footersize) {
dc_sample_value_t sample = {0}; dc_sample_value_t sample = {0};
// Ignore empty samples. // Ignore empty samples.
@ -600,7 +653,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_
// Get the sample type. // Get the sample type.
unsigned int sampletype = data[offset + 0]; unsigned int sampletype = data[offset + 0];
if (mode == FREEDIVE) if (parser->mode == FREEDIVE)
sampletype = 0; sampletype = 0;
// The sample size is usually fixed, but some sample types have a // The sample size is usually fixed, but some sample types have a
@ -658,7 +711,8 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_
// Temperature (°F) // Temperature (°F)
if (have_temperature) { if (have_temperature) {
if (parser->model == GEO || parser->model == ATOM1 || if (parser->model == GEO || parser->model == ATOM1 ||
parser->model == ELEMENT2 || parser->model == MANTA) { parser->model == ELEMENT2 || parser->model == MANTA ||
parser->model == ZEN) {
temperature = data[offset + 6]; temperature = data[offset + 6];
} else if (parser->model == GEO20 || parser->model == VEO20 || } else if (parser->model == GEO20 || parser->model == VEO20 ||
parser->model == VEO30 || parser->model == OC1A || parser->model == VEO30 || parser->model == OC1A ||
@ -716,7 +770,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_
// Depth (1/16 ft) // Depth (1/16 ft)
unsigned int depth; unsigned int depth;
if (mode == FREEDIVE) if (parser->mode == FREEDIVE)
depth = array_uint16_le (data + offset); depth = array_uint16_le (data + offset);
else if (parser->model == GEO20 || parser->model == VEO20 || else if (parser->model == GEO20 || parser->model == VEO20 ||
parser->model == VEO30 || parser->model == OC1A || parser->model == VEO30 || parser->model == OC1A ||
@ -730,15 +784,48 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_
sample.depth = depth / 16.0 * FEET; sample.depth = depth / 16.0 * FEET;
if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata);
// Gas mix
unsigned int have_gasmix = 0;
unsigned int gasmix = 0;
if (parser->model == TX1) {
gasmix = data[offset] & 0x07;
have_gasmix = 1;
}
if (have_gasmix && gasmix != gasmix_previous) {
if (gasmix < 1 || gasmix > parser->ngasmixes) {
ERROR (abstract->context, "Invalid gas mix index (%u).", gasmix);
return DC_STATUS_DATAFORMAT;
}
unsigned int o2 = parser->oxygen[gasmix - 1];
unsigned int he = parser->helium[gasmix - 1];
sample.event.type = SAMPLE_EVENT_GASCHANGE2;
sample.event.time = 0;
sample.event.flags = 0;
sample.event.value = o2 | (he << 16);
if (callback) callback (DC_SAMPLE_EVENT, sample, userdata);
gasmix_previous = gasmix;
}
// NDL / Deco // NDL / Deco
// bits 6..4 of byte 15 encode deco state & depth unsigned int have_deco = 0;
// bytes 6 & 7 encode minutes of NDL / deco unsigned int decostop = 0, decotime = 0;
if (parser->model == A300CS || parser->model == VTX) { if (parser->model == A300CS || parser->model == VTX) {
unsigned int deco = (data[offset + 15] & 0x70) >> 4; decostop = (data[offset + 15] & 0x70) >> 4;
unsigned int decotime = array_uint16_le(data + offset + 6) & 0x03FF; decotime = array_uint16_le(data + offset + 6) & 0x03FF;
if (deco) { have_deco = 1;
} else if (parser->model == ZEN) {
decostop = (data[offset + 5] & 0xF0) >> 4;
decotime = array_uint16_le(data + offset + 4) & 0x0FFF;
have_deco = 1;
} else if (parser->model == TX1) {
decostop = data[offset + 10];
decotime = array_uint16_le(data + offset + 6);
have_deco = 1;
}
if (have_deco) {
if (decostop) {
sample.deco.type = DC_DECO_DECOSTOP; sample.deco.type = DC_DECO_DECOSTOP;
sample.deco.depth = deco * 10 * FEET; sample.deco.depth = decostop * 10 * FEET;
} else { } else {
sample.deco.type = DC_DECO_NDL; sample.deco.type = DC_DECO_NDL;
sample.deco.depth = 0.0; sample.deco.depth = 0.0;

View File

@ -760,8 +760,6 @@ uwatec_smart_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi
*((double *) value) = (signed short) array_uint16_le (data + table->temp_surface) / 10.0; *((double *) value) = (signed short) array_uint16_le (data + table->temp_surface) / 10.0;
break; break;
case DC_FIELD_DIVEMODE: case DC_FIELD_DIVEMODE:
if (parser->trimix)
return DC_STATUS_UNSUPPORTED;
if (parser->ngasmixes) if (parser->ngasmixes)
*((dc_divemode_t *) value) = DC_DIVEMODE_OC; *((dc_divemode_t *) value) = DC_DIVEMODE_OC;
else else
@ -1146,9 +1144,12 @@ uwatec_smart_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t
} }
if (have_pressure) { if (have_pressure) {
sample.pressure.tank = tank; idx = uwatec_smart_find_tank(parser, tank);
sample.pressure.value = pressure; if (idx < parser->ntanks) {
if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); sample.pressure.tank = idx;
sample.pressure.value = pressure;
if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata);
}
} }
if (have_heartrate) { if (have_heartrate) {