Suunto D9 family: add extended information parsing

This adds the string field interface to the Suunto D9 family.

It's really just the proper serial number handling.  From Dirk's
original commit:

 "We have the correct firmware in the devinfo, but that's the firmware
  the dive computer is on NOW, not necessarily the firmware it was using
  when recording the dive"

so thus just serial number.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Dirk Hohndel 2014-11-21 14:29:53 -08:00 committed by Linus Torvalds
parent 72c99a6dcb
commit b0d72cd74c
3 changed files with 22 additions and 4 deletions

View File

@ -87,7 +87,7 @@ dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t fa
break; break;
case DC_FAMILY_SUUNTO_VYPER2: case DC_FAMILY_SUUNTO_VYPER2:
case DC_FAMILY_SUUNTO_D9: case DC_FAMILY_SUUNTO_D9:
rc = suunto_d9_parser_create (&parser, context, model); rc = suunto_d9_parser_create (&parser, context, model, serial);
break; break;
case DC_FAMILY_SUUNTO_EONSTEEL: case DC_FAMILY_SUUNTO_EONSTEEL:
rc = suunto_eonsteel_parser_create(&parser, context, model); rc = suunto_eonsteel_parser_create(&parser, context, model);

View File

@ -36,7 +36,7 @@ dc_status_t
suunto_d9_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream, unsigned int model); suunto_d9_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream, unsigned int model);
dc_status_t 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 #ifdef __cplusplus
} }

View File

@ -20,7 +20,8 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h> // memcmp #include <string.h> // memcmp, strdup
#include <stdio.h> // snprintf
#include "suunto_d9.h" #include "suunto_d9.h"
#include "context-private.h" #include "context-private.h"
@ -72,6 +73,7 @@ typedef struct suunto_d9_parser_t suunto_d9_parser_t;
struct suunto_d9_parser_t { struct suunto_d9_parser_t {
dc_parser_t base; dc_parser_t base;
unsigned int model; unsigned int model;
unsigned int serial;
// Cached fields. // Cached fields.
unsigned int cached; unsigned int cached;
unsigned int mode; unsigned int mode;
@ -231,7 +233,7 @@ suunto_d9_parser_cache (suunto_d9_parser_t *parser)
} }
dc_status_t 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)
{ {
suunto_d9_parser_t *parser = NULL; suunto_d9_parser_t *parser = NULL;
@ -247,6 +249,7 @@ suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int
// Set the default values. // Set the default values.
parser->model = model; parser->model = model;
parser->serial = serial;
parser->cached = 0; parser->cached = 0;
parser->mode = AIR; parser->mode = AIR;
parser->ngasmixes = 0; parser->ngasmixes = 0;
@ -326,6 +329,7 @@ suunto_d9_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime)
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }
#define BUFLEN 16
static dc_status_t static dc_status_t
suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value) suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value)
@ -341,6 +345,9 @@ suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigne
return rc; return rc;
dc_gasmix_t *gasmix = (dc_gasmix_t *) value; dc_gasmix_t *gasmix = (dc_gasmix_t *) value;
dc_field_string_t *string = (dc_field_string_t *) value;
char buf[BUFLEN];
if (value) { if (value) {
switch (type) { switch (type) {
@ -388,6 +395,17 @@ suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigne
return DC_STATUS_DATAFORMAT; return DC_STATUS_DATAFORMAT;
} }
break; break;
case DC_FIELD_STRING:
switch (flags) {
case 0: /* serial */
string->desc = "Serial";
snprintf(buf, BUFLEN, "%08u", parser->serial);
break;
default:
return DC_STATUS_UNSUPPORTED;
}
string->value = strdup(buf);
break;
default: default:
return DC_STATUS_UNSUPPORTED; return DC_STATUS_UNSUPPORTED;
} }