From ce590b5bc92ad4595de10d08efde299e001c45a5 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sat, 2 Sep 2017 09:47:49 +0200 Subject: [PATCH] Use two passes to parse the profile data In the trimix data format, the tank and gas mix information is no longer stored in the header, but in a special sample. Because this sample is usually located at the end of the profile, the info isn't available yet during the first pass. Hence the need for a second pass. Without this change, the tank and gas mix samples will be missing unless the caller calls the dc_parser_get_field() function before calling the dc_parser_samples_foreach() function. --- src/uwatec_smart_parser.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/uwatec_smart_parser.c b/src/uwatec_smart_parser.c index c1311ee..78f68bd 100644 --- a/src/uwatec_smart_parser.c +++ b/src/uwatec_smart_parser.c @@ -158,6 +158,8 @@ static dc_status_t uwatec_smart_parser_get_datetime (dc_parser_t *abstract, dc_d static dc_status_t uwatec_smart_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t uwatec_smart_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); +static dc_status_t uwatec_smart_parse (uwatec_smart_parser_t *parser, dc_sample_callback_t callback, void *userdata); + static const dc_parser_vtable_t uwatec_smart_parser_vtable = { sizeof(uwatec_smart_parser_t), DC_FAMILY_UWATEC_SMART, @@ -758,7 +760,7 @@ uwatec_smart_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi // Cache the profile data. if (parser->cached < PROFILE) { - rc = uwatec_smart_parser_samples_foreach (abstract, NULL, NULL); + rc = uwatec_smart_parse (parser, NULL, NULL); if (rc != DC_STATUS_SUCCESS) return rc; } @@ -890,18 +892,13 @@ uwatec_smart_fixsignbit (unsigned int x, unsigned int n) static dc_status_t -uwatec_smart_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata) +uwatec_smart_parse (uwatec_smart_parser_t *parser, dc_sample_callback_t callback, void *userdata) { - uwatec_smart_parser_t *parser = (uwatec_smart_parser_t*) abstract; + dc_parser_t *abstract = (dc_parser_t *) parser; const unsigned char *data = abstract->data; unsigned int size = abstract->size; - // Cache the parser data. - dc_status_t rc = uwatec_smart_parser_cache (parser); - if (rc != DC_STATUS_SUCCESS) - return rc; - const uwatec_smart_sample_info_t *table = parser->samples; unsigned int entries = parser->nsamples; @@ -1226,3 +1223,24 @@ uwatec_smart_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t return DC_STATUS_SUCCESS; } + + +static dc_status_t +uwatec_smart_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata) +{ + uwatec_smart_parser_t *parser = (uwatec_smart_parser_t *) abstract; + + // Cache the parser data. + dc_status_t rc = uwatec_smart_parser_cache (parser); + if (rc != DC_STATUS_SUCCESS) + return rc; + + // Cache the profile data. + if (parser->cached < PROFILE) { + rc = uwatec_smart_parse (parser, NULL, NULL); + if (rc != DC_STATUS_SUCCESS) + return rc; + } + + return uwatec_smart_parse (parser, callback, userdata); +}