From b8ff29d15dcc96cd4b7c6d6f7d6eec8b706371ca Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 20 Feb 2009 12:24:59 +0000 Subject: [PATCH] Add a device info event for the Uwatec Memomouse. --- src/uwatec_memomouse.c | 22 ++++++++++++++++++++-- src/uwatec_memomouse.h | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/uwatec_memomouse.c b/src/uwatec_memomouse.c index 7c37e92..498af6d 100644 --- a/src/uwatec_memomouse.c +++ b/src/uwatec_memomouse.c @@ -500,7 +500,7 @@ uwatec_memomouse_device_foreach (device_t *abstract, dive_callback_t callback, v if (rc != DEVICE_STATUS_SUCCESS) return rc; - rc = uwatec_memomouse_extract_dives (buffer + 2, length - 3, callback, userdata); + rc = uwatec_memomouse_extract_dives (abstract, buffer + 2, length - 3, callback, userdata); if (rc != DEVICE_STATUS_SUCCESS) { free (buffer); return rc; @@ -513,8 +513,13 @@ uwatec_memomouse_device_foreach (device_t *abstract, dive_callback_t callback, v device_status_t -uwatec_memomouse_extract_dives (const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata) +uwatec_memomouse_extract_dives (device_t *abstract, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata) { + uwatec_memomouse_device_t *device = (uwatec_memomouse_device_t*) abstract; + + if (abstract && !device_is_uwatec_memomouse (abstract)) + return DEVICE_STATUS_TYPE_MISMATCH; + // Parse the data stream to find the total number of dives. unsigned int ndives = 0; unsigned int previous = 0; @@ -537,6 +542,19 @@ uwatec_memomouse_extract_dives (const unsigned char data[], unsigned int size, d if (current + len + 18 > size) return DEVICE_STATUS_ERROR; + // A memomouse can store data from several dive computers, but only + // the data of the connected dive computer can be transferred. + // Therefore, the device info will be the same for all dives, and + // only needs to be reported once. + if (abstract && ndives == 0) { + // Emit a device info event. + device_devinfo_t devinfo; + devinfo.model = data[current + 3]; + devinfo.firmware = 0; + devinfo.serial = (data[current + 0] << 16) + (data[current + 1] << 8) + data[current + 2]; + device_event_emit (abstract, DEVICE_EVENT_DEVINFO, &devinfo); + } + // Move to the next dive. previous = current; current += len + 18; diff --git a/src/uwatec_memomouse.h b/src/uwatec_memomouse.h index 2380d27..a758182 100644 --- a/src/uwatec_memomouse.h +++ b/src/uwatec_memomouse.h @@ -36,7 +36,7 @@ device_status_t uwatec_memomouse_device_set_timestamp (device_t *device, unsigned int timestamp); device_status_t -uwatec_memomouse_extract_dives (const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata); +uwatec_memomouse_extract_dives (device_t *device, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata); parser_status_t uwatec_memomouse_parser_create (parser_t **parser);