From 7cba1913225f33c36bfc1830602e3612d4834865 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 20 Feb 2009 12:11:25 +0000 Subject: [PATCH] Port the Uwatec Aladin, Memomouse and Smart to the new event code. --- src/uwatec_aladin.c | 15 ++++++++++----- src/uwatec_memomouse.c | 22 +++++++++++++++------- src/uwatec_smart.c | 20 +++++++++++++------- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/uwatec_aladin.c b/src/uwatec_aladin.c index 493b3e5..29f081b 100644 --- a/src/uwatec_aladin.c +++ b/src/uwatec_aladin.c @@ -185,8 +185,9 @@ uwatec_aladin_device_dump (device_t *abstract, unsigned char data[], unsigned in } // Enable progress notifications. - device_progress_state_t progress; - progress_init (&progress, abstract, UWATEC_ALADIN_MEMORY_SIZE + 2); + device_progress_t progress = DEVICE_PROGRESS_INITIALIZER; + progress.maximum = UWATEC_ALADIN_MEMORY_SIZE + 2; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress); unsigned char answer[UWATEC_ALADIN_MEMORY_SIZE + 2] = {0}; @@ -201,11 +202,13 @@ uwatec_aladin_device_dump (device_t *abstract, unsigned char data[], unsigned in i++; // Continue. } else { i = 0; // Reset. - progress_event (&progress, DEVICE_EVENT_WAITING, 0); + device_event_emit (abstract, DEVICE_EVENT_WAITING, NULL); } } - progress_event (&progress, DEVICE_EVENT_PROGRESS, 4); + // Update and emit a progress event. + progress.current += 4; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress); // Receive the remaining part of the package. int rc = serial_read (device->port, answer + 4, sizeof (answer) - 4); @@ -214,7 +217,9 @@ uwatec_aladin_device_dump (device_t *abstract, unsigned char data[], unsigned in return EXITCODE (rc); } - progress_event (&progress, DEVICE_EVENT_PROGRESS, sizeof (answer) - 4); + // Update and emit a progress event. + progress.current += sizeof (answer) - 4; + device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress); // Reverse the bit order. array_reverse_bits (answer, sizeof (answer)); diff --git a/src/uwatec_memomouse.c b/src/uwatec_memomouse.c index 497d3c1..7c37e92 100644 --- a/src/uwatec_memomouse.c +++ b/src/uwatec_memomouse.c @@ -282,7 +282,7 @@ uwatec_memomouse_read_packet_outer (uwatec_memomouse_device_t *device, unsigned static device_status_t -uwatec_memomouse_read_packet_inner (uwatec_memomouse_device_t *device, unsigned char *data[], unsigned int *size, device_progress_state_t *progress) +uwatec_memomouse_read_packet_inner (uwatec_memomouse_device_t *device, unsigned char *data[], unsigned int *size, device_progress_t *progress) { // Read the first package. unsigned int length = 0; @@ -306,8 +306,12 @@ uwatec_memomouse_read_packet_inner (uwatec_memomouse_device_t *device, unsigned // Calculate the total size of the inner package. unsigned int total = package[0] + (package[1] << 8) + 3; - progress_set_maximum (progress, total); - progress_event (progress, DEVICE_EVENT_PROGRESS, length); + // Update and emit a progress event. + if (progress) { + progress->maximum = total; + progress->current += length; + device_event_emit (&device->base, DEVICE_EVENT_PROGRESS, progress); + } // Allocate memory for the entire package. unsigned char *buffer = (unsigned char *) malloc (total * sizeof (unsigned char)); @@ -336,7 +340,11 @@ uwatec_memomouse_read_packet_inner (uwatec_memomouse_device_t *device, unsigned return rc; } - progress_event (progress, DEVICE_EVENT_PROGRESS, length); + // Update and emit a progress event. + if (progress) { + progress->current += length; + device_event_emit (&device->base, DEVICE_EVENT_PROGRESS, progress); + } nbytes += length; } @@ -360,8 +368,8 @@ static device_status_t uwatec_memomouse_dump (uwatec_memomouse_device_t *device, unsigned char *data[], unsigned int *size) { // Enable progress notifications. - device_progress_state_t progress; - progress_init (&progress, &device->base, INFINITE); + device_progress_t progress = DEVICE_PROGRESS_INITIALIZER; + device_event_emit (&device->base, DEVICE_EVENT_PROGRESS, &progress); // Waiting for greeting message. while (serial_get_received (device->port) == 0) { @@ -439,7 +447,7 @@ uwatec_memomouse_dump (uwatec_memomouse_device_t *device, unsigned char *data[], // Wait for the data packet. while (serial_get_received (device->port) == 0) { - progress_event (&progress, DEVICE_EVENT_WAITING, 0); + device_event_emit (&device->base, DEVICE_EVENT_WAITING, NULL); serial_sleep (100); } diff --git a/src/uwatec_smart.c b/src/uwatec_smart.c index 7ed5613..db41c6a 100644 --- a/src/uwatec_smart.c +++ b/src/uwatec_smart.c @@ -337,8 +337,8 @@ static device_status_t uwatec_smart_dump (uwatec_smart_device_t *device, unsigned char *data[], unsigned int *size) { // Enable progress notifications. - device_progress_state_t progress; - progress_init (&progress, &device->base, INFINITE); + device_progress_t progress = DEVICE_PROGRESS_INITIALIZER; + device_event_emit (&device->base, DEVICE_EVENT_PROGRESS, &progress); unsigned char command[9] = {0}; unsigned char answer[4] = {0}; @@ -363,6 +363,11 @@ uwatec_smart_dump (uwatec_smart_device_t *device, unsigned char *data[], unsigne (answer[2] << 16) + (answer[3] << 24); message ("handshake: length=%u\n", length); + // Update and emit a progress event. + progress.maximum = 4 + (length ? length + 4 : 0); + progress.current += 4; + device_event_emit (&device->base, DEVICE_EVENT_PROGRESS, &progress); + if (length == 0) return DEVICE_STATUS_SUCCESS; @@ -372,9 +377,6 @@ uwatec_smart_dump (uwatec_smart_device_t *device, unsigned char *data[], unsigne return DEVICE_STATUS_MEMORY; } - progress_set_maximum (&progress, length + 8); - progress_event (&progress, DEVICE_EVENT_PROGRESS, 4); - // Data. command[0] = 0xC4; @@ -397,7 +399,9 @@ uwatec_smart_dump (uwatec_smart_device_t *device, unsigned char *data[], unsigne (answer[2] << 16) + (answer[3] << 24); message ("handshake: total=%u\n", total); - progress_event (&progress, DEVICE_EVENT_PROGRESS, 4); + // Update and emit a progress event. + progress.current += 4; + device_event_emit (&device->base, DEVICE_EVENT_PROGRESS, &progress); assert (total == length + 4); @@ -413,7 +417,9 @@ uwatec_smart_dump (uwatec_smart_device_t *device, unsigned char *data[], unsigne return EXITCODE (n); } - progress_event (&progress, DEVICE_EVENT_PROGRESS, len); + // Update and emit a progress event. + progress.current += n; + device_event_emit (&device->base, DEVICE_EVENT_PROGRESS, &progress); nbytes += n; }