Add a device info event for the Uwatec Memomouse.

This commit is contained in:
Jef Driesen 2009-02-20 12:24:59 +00:00
parent 8e05b91502
commit b8ff29d15d
2 changed files with 21 additions and 3 deletions

View File

@ -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;

View File

@ -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);