From 732c607c22ca8dc1296a123378e8b75724ff5517 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 24 May 2019 22:52:28 +0200 Subject: [PATCH] Refactor the date/time parsing Split the offset calculation in two steps: first the offset to the header data, and then the date/time field. The main advantage is that the resulting code now follows the same logic as in the other functions. --- src/mares_iconhd_parser.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/mares_iconhd_parser.c b/src/mares_iconhd_parser.c index 70cf597..1cdb339 100644 --- a/src/mares_iconhd_parser.c +++ b/src/mares_iconhd_parser.c @@ -320,19 +320,19 @@ mares_iconhd_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime if (rc != DC_STATUS_SUCCESS) return rc; + // Pointer to the header data. const unsigned char *p = abstract->data + abstract->size - parser->headersize; - if (parser->model == SMART) { - if (parser->mode == FREEDIVE) { - p += 0x20; - } else { - p += 2; - } - } else if (parser->model == SMARTAPNEA) { + if (parser->model != SMART && parser->model != SMARTAPNEA && parser->model != SMARTAIR) { + p += 4; + } + + // Offset to the date/time field. + if (parser->model == SMARTAPNEA) { p += 0x40; - } else if (parser->model == SMARTAIR) { - p += 2; + } else if (parser->mode == FREEDIVE) { + p += 0x20; } else { - p += 6; + p += 2; } if (datetime) { @@ -359,6 +359,7 @@ mares_iconhd_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi if (rc != DC_STATUS_SUCCESS) return rc; + // Pointer to the header data. const unsigned char *p = abstract->data + abstract->size - parser->headersize; if (parser->model != SMART && parser->model != SMARTAPNEA && parser->model != SMARTAIR) { p += 4;