diff --git a/include/libdivecomputer/suunto_d9.h b/include/libdivecomputer/suunto_d9.h index d177c6c..1fb1824 100644 --- a/include/libdivecomputer/suunto_d9.h +++ b/include/libdivecomputer/suunto_d9.h @@ -42,7 +42,7 @@ dc_status_t suunto_d9_device_reset_maxdepth (dc_device_t *device); dc_status_t -suunto_d9_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +suunto_d9_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model, unsigned int serial); #ifdef __cplusplus } diff --git a/src/parser.c b/src/parser.c index 6471e3f..66bb80a 100644 --- a/src/parser.c +++ b/src/parser.c @@ -66,7 +66,7 @@ dc_parser_new (dc_parser_t **out, dc_device_t *device) break; case DC_FAMILY_SUUNTO_VYPER2: case DC_FAMILY_SUUNTO_D9: - rc = suunto_d9_parser_create (&parser, context, device->devinfo.model); + rc = suunto_d9_parser_create (&parser, context, device->devinfo.model, device->devinfo.serial); break; case DC_FAMILY_SUUNTO_EONSTEEL: rc = suunto_eonsteel_parser_create(&parser, context, device->devinfo.model); diff --git a/src/suunto_d9_parser.c b/src/suunto_d9_parser.c index 4fd94aa..86771ff 100644 --- a/src/suunto_d9_parser.c +++ b/src/suunto_d9_parser.c @@ -20,7 +20,8 @@ */ #include -#include // memcmp +#include // memcmp, strdup +#include // snprintf #include @@ -62,6 +63,7 @@ typedef struct suunto_d9_parser_t suunto_d9_parser_t; struct suunto_d9_parser_t { dc_parser_t base; unsigned int model; + unsigned int serial; // Cached fields. unsigned int cached; unsigned int mode; @@ -188,7 +190,7 @@ suunto_d9_parser_cache (suunto_d9_parser_t *parser) } dc_status_t -suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int serial) { if (out == NULL) return DC_STATUS_INVALIDARGS; @@ -205,6 +207,7 @@ suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int // Set the default values. parser->model = model; + parser->serial = serial; parser->cached = 0; parser->mode = AIR; parser->ngasmixes = 0; @@ -289,6 +292,7 @@ suunto_d9_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) return DC_STATUS_SUCCESS; } +#define BUFLEN 16 static dc_status_t suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value) @@ -304,6 +308,9 @@ suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigne return rc; dc_gasmix_t *gasmix = (dc_gasmix_t *) value; + dc_field_string_t *string = (dc_field_string_t *) value; + + char buf[BUFLEN]; if (value) { switch (type) { @@ -349,6 +356,19 @@ suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigne return DC_STATUS_DATAFORMAT; } break; + case DC_FIELD_STRING: + switch (flags) { + case 0: /* serial */ + string->desc = "Serial"; + snprintf(buf, BUFLEN, "%02d%02d%02d%02d", (parser->serial >> 24) & 0xff, + (parser->serial >> 16) & 0xff, (parser->serial >> 8) & 0xff, + parser->serial & 0xff); + break; + default: + return DC_STATUS_UNSUPPORTED; + } + string->value = strdup(buf); + break; default: return DC_STATUS_UNSUPPORTED; }