From 3df5cb09d711a62c4f31e1bd0a7d1bb64062acb7 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sat, 14 Jul 2012 22:50:35 +0200 Subject: [PATCH] Require a serial handle for the sleep function. --- src/hw_frog.c | 2 +- src/hw_ostc.c | 2 +- src/mares_common.c | 2 +- src/mares_darwin.c | 2 +- src/mares_nemo.c | 2 +- src/oceanic_atom2.c | 4 ++-- src/oceanic_veo250.c | 6 +++--- src/oceanic_vtpro.c | 2 +- src/reefnet_sensus.c | 2 +- src/reefnet_sensuspro.c | 4 ++-- src/reefnet_sensusultra.c | 2 +- src/serial.h | 2 +- src/serial_posix.c | 7 +++++-- src/serial_win32.c | 7 +++++-- src/suunto_d9.c | 2 +- src/suunto_vyper.c | 6 +++--- src/suunto_vyper2.c | 4 ++-- src/uwatec_memomouse.c | 8 ++++---- 18 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/hw_frog.c b/src/hw_frog.c index 19f26d0..021952f 100644 --- a/src/hw_frog.c +++ b/src/hw_frog.c @@ -230,7 +230,7 @@ hw_frog_device_open (dc_device_t **out, const char *name) } // Make sure everything is in a sane state. - serial_sleep (300); + serial_sleep (device->port, 300); serial_flush (device->port, SERIAL_QUEUE_BOTH); // Send the init command. diff --git a/src/hw_ostc.c b/src/hw_ostc.c index 750664a..ab399ba 100644 --- a/src/hw_ostc.c +++ b/src/hw_ostc.c @@ -158,7 +158,7 @@ hw_ostc_device_open (dc_device_t **out, const char *name) } // Make sure everything is in a sane state. - serial_sleep (100); + serial_sleep (device->port, 100); serial_flush (device->port, SERIAL_QUEUE_BOTH); *out = (dc_device_t*) device; diff --git a/src/mares_common.c b/src/mares_common.c index 926d960..e7f21f0 100644 --- a/src/mares_common.c +++ b/src/mares_common.c @@ -135,7 +135,7 @@ mares_common_packet (mares_common_device_t *device, const unsigned char command[ return DC_STATUS_CANCELLED; if (device->delay) { - serial_sleep (device->delay); + serial_sleep (device->port, device->delay); } // Send the command to the device. diff --git a/src/mares_darwin.c b/src/mares_darwin.c index 45c5784..4a78d2b 100644 --- a/src/mares_darwin.c +++ b/src/mares_darwin.c @@ -159,7 +159,7 @@ mares_darwin_device_open (dc_device_t **out, const char *name, unsigned int mode } // Make sure everything is in a sane state. - serial_sleep (100); + serial_sleep (device->base.port, 100); serial_flush (device->base.port, SERIAL_QUEUE_BOTH); // Override the base class values. diff --git a/src/mares_nemo.c b/src/mares_nemo.c index 83b4b6d..43137b5 100644 --- a/src/mares_nemo.c +++ b/src/mares_nemo.c @@ -219,7 +219,7 @@ mares_nemo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) return DC_STATUS_CANCELLED; device_event_emit (abstract, DC_EVENT_WAITING, NULL); - serial_sleep (100); + serial_sleep (device->port, 100); } // Receive the header of the package. diff --git a/src/oceanic_atom2.c b/src/oceanic_atom2.c index 81945c1..0c1ae23 100644 --- a/src/oceanic_atom2.c +++ b/src/oceanic_atom2.c @@ -268,7 +268,7 @@ oceanic_atom2_transfer (oceanic_atom2_device_t *device, const unsigned char comm return rc; // Delay the next attempt. - serial_sleep (100); + serial_sleep (device->port, 100); serial_flush (device->port, SERIAL_QUEUE_INPUT); } @@ -352,7 +352,7 @@ oceanic_atom2_device_open (dc_device_t **out, const char *name) } // Give the interface 100 ms to settle and draw power up. - serial_sleep (100); + serial_sleep (device->port, 100); // Make sure everything is in a sane state. serial_flush (device->port, SERIAL_QUEUE_BOTH); diff --git a/src/oceanic_veo250.c b/src/oceanic_veo250.c index 2445dac..d73d350 100644 --- a/src/oceanic_veo250.c +++ b/src/oceanic_veo250.c @@ -144,7 +144,7 @@ oceanic_veo250_transfer (oceanic_veo250_device_t *device, const unsigned char co return rc; // Delay the next attempt. - serial_sleep (100); + serial_sleep (device->port, 100); } // Receive the answer of the dive computer. @@ -273,7 +273,7 @@ oceanic_veo250_device_open (dc_device_t **out, const char *name) } // Give the interface 100 ms to settle and draw power up. - serial_sleep (100); + serial_sleep (device->port, 100); // Make sure everything is in a sane state. serial_flush (device->port, SERIAL_QUEUE_BOTH); @@ -287,7 +287,7 @@ oceanic_veo250_device_open (dc_device_t **out, const char *name) } // Delay the sending of the version command. - serial_sleep (100); + serial_sleep (device->port, 100); // Switch the device from surface mode into download mode. Before sending // this command, the device needs to be in PC mode (manually activated by diff --git a/src/oceanic_vtpro.c b/src/oceanic_vtpro.c index fabd0d4..a3f4f9e 100644 --- a/src/oceanic_vtpro.c +++ b/src/oceanic_vtpro.c @@ -301,7 +301,7 @@ oceanic_vtpro_device_open (dc_device_t **out, const char *name) } // Give the interface 100 ms to settle and draw power up. - serial_sleep (100); + serial_sleep (device->port, 100); // Make sure everything is in a sane state. serial_flush (device->port, SERIAL_QUEUE_BOTH); diff --git a/src/reefnet_sensus.c b/src/reefnet_sensus.c index 35187df..212ce64 100644 --- a/src/reefnet_sensus.c +++ b/src/reefnet_sensus.c @@ -277,7 +277,7 @@ reefnet_sensus_handshake (reefnet_sensus_device_t *device) // Wait at least 10 ms to ensures the data line is // clear before transmission from the host begins. - serial_sleep (10); + serial_sleep (device->port, 10); return DC_STATUS_SUCCESS; } diff --git a/src/reefnet_sensuspro.c b/src/reefnet_sensuspro.c index 210f147..a29d423 100644 --- a/src/reefnet_sensuspro.c +++ b/src/reefnet_sensuspro.c @@ -246,7 +246,7 @@ reefnet_sensuspro_handshake (reefnet_sensuspro_device_t *device) devinfo.serial = array_uint16_le (handshake + 4); device_event_emit (&device->base, DC_EVENT_DEVINFO, &devinfo); - serial_sleep (10); + serial_sleep (device->port, 10); return DC_STATUS_SUCCESS; } @@ -370,7 +370,7 @@ reefnet_sensuspro_device_write_interval (dc_device_t *abstract, unsigned char in if (rc != DC_STATUS_SUCCESS) return rc; - serial_sleep (10); + serial_sleep (device->port, 10); int n = serial_write (device->port, &interval, 1); if (n != 1) { diff --git a/src/reefnet_sensusultra.c b/src/reefnet_sensusultra.c index 7a53ecf..ee7dbb4 100644 --- a/src/reefnet_sensusultra.c +++ b/src/reefnet_sensusultra.c @@ -394,7 +394,7 @@ reefnet_sensusultra_send (reefnet_sensusultra_device_t *device, unsigned short c // not accidentally buffered by the host and (mis)interpreted as part // of the next packet. - serial_sleep (250); + serial_sleep (device->port, 250); serial_flush (device->port, SERIAL_QUEUE_BOTH); } diff --git a/src/serial.h b/src/serial.h index 24b5212..9047561 100644 --- a/src/serial.h +++ b/src/serial.h @@ -106,7 +106,7 @@ int serial_get_transmitted (serial_t *device); int serial_get_line (serial_t *device, int line); -int serial_sleep (unsigned long timeout /* milliseconds */); +int serial_sleep (serial_t *device, unsigned long timeout /* milliseconds */); #ifdef __cplusplus } diff --git a/src/serial_posix.c b/src/serial_posix.c index 1279300..0be68b1 100644 --- a/src/serial_posix.c +++ b/src/serial_posix.c @@ -606,7 +606,7 @@ serial_write (serial_t *device, const void *data, unsigned int size) // The remaining time is rounded up to the nearest millisecond to // match the Windows implementation. The higher resolution is // pointless anyway, since we already added a fudge factor above. - serial_sleep ((remaining + 999) / 1000); + serial_sleep (device, (remaining + 999) / 1000); } } @@ -773,8 +773,11 @@ serial_get_line (serial_t *device, int line) int -serial_sleep (unsigned long timeout) +serial_sleep (serial_t *device, unsigned long timeout) { + if (device == NULL) + return -1; + struct timespec ts; ts.tv_sec = (timeout / 1000); ts.tv_nsec = (timeout % 1000) * 1000000; diff --git a/src/serial_win32.c b/src/serial_win32.c index ac81197..56e6181 100644 --- a/src/serial_win32.c +++ b/src/serial_win32.c @@ -423,7 +423,7 @@ serial_write (serial_t *device, const void* data, unsigned int size) // The remaining time is rounded up to the nearest millisecond // because the Windows Sleep() function doesn't have a higher // resolution. - serial_sleep ((remaining + 999) / 1000); + serial_sleep (device, (remaining + 999) / 1000); } } @@ -601,8 +601,11 @@ serial_get_line (serial_t *device, int line) int -serial_sleep (unsigned long timeout) +serial_sleep (serial_t *device, unsigned long timeout) { + if (device == NULL) + return -1; + Sleep (timeout); return 0; diff --git a/src/suunto_d9.c b/src/suunto_d9.c index 386194d..3beb9c5 100644 --- a/src/suunto_d9.c +++ b/src/suunto_d9.c @@ -177,7 +177,7 @@ suunto_d9_device_open (dc_device_t **out, const char *name, unsigned int model) } // Give the interface 100 ms to settle and draw power up. - serial_sleep (100); + serial_sleep (device->port, 100); // Make sure everything is in a sane state. serial_flush (device->port, SERIAL_QUEUE_BOTH); diff --git a/src/suunto_vyper.c b/src/suunto_vyper.c index ef40abe..183ac3a 100644 --- a/src/suunto_vyper.c +++ b/src/suunto_vyper.c @@ -149,7 +149,7 @@ suunto_vyper_device_open (dc_device_t **out, const char *name) } // Give the interface 100 ms to settle and draw power up. - serial_sleep (100); + serial_sleep (device->port, 100); // Make sure everything is in a sane state. serial_flush (device->port, SERIAL_QUEUE_BOTH); @@ -198,7 +198,7 @@ suunto_vyper_device_set_delay (dc_device_t *abstract, unsigned int delay) static dc_status_t suunto_vyper_send (suunto_vyper_device_t *device, const unsigned char command[], unsigned int csize) { - serial_sleep (device->delay); + serial_sleep (device->port, device->delay); // Set RTS to send the command. serial_set_rts (device->port, 1); @@ -221,7 +221,7 @@ suunto_vyper_send (suunto_vyper_device_t *device, const unsigned char command[], // receive the reply before RTS is cleared. We have to wait some time // before clearing RTS (around 30ms). But if we wait too long (> 500ms), // the reply disappears again. - serial_sleep (200); + serial_sleep (device->port, 200); serial_flush (device->port, SERIAL_QUEUE_INPUT); // Clear RTS to receive the reply. diff --git a/src/suunto_vyper2.c b/src/suunto_vyper2.c index 0c02dbb..a4a7f3d 100644 --- a/src/suunto_vyper2.c +++ b/src/suunto_vyper2.c @@ -127,7 +127,7 @@ suunto_vyper2_device_open (dc_device_t **out, const char *name) } // Give the interface 100 ms to settle and draw power up. - serial_sleep (100); + serial_sleep (device->port, 100); // Make sure everything is in a sane state. serial_flush (device->port, SERIAL_QUEUE_BOTH); @@ -173,7 +173,7 @@ suunto_vyper2_device_packet (dc_device_t *abstract, const unsigned char command[ if (device_is_cancelled (abstract)) return DC_STATUS_CANCELLED; - serial_sleep (0x190 + 0xC8); + serial_sleep (device->port, 600); // Set RTS to send the command. serial_set_rts (device->port, 1); diff --git a/src/uwatec_memomouse.c b/src/uwatec_memomouse.c index f46f7bb..00ad56d 100644 --- a/src/uwatec_memomouse.c +++ b/src/uwatec_memomouse.c @@ -372,7 +372,7 @@ uwatec_memomouse_dump_internal (uwatec_memomouse_device_t *device, dc_buffer_t * return EXITCODE (n); } - serial_sleep (300); + serial_sleep (device->port, 300); } // Read the ID string. @@ -395,7 +395,7 @@ uwatec_memomouse_dump_internal (uwatec_memomouse_device_t *device, dc_buffer_t * // Wait a small amount of time before sending the command. // Without this delay, the transfer will fail most of the time. - serial_sleep (50); + serial_sleep (device->port, 50); // Keep send the command to the device, // until the ACK answer is received. @@ -431,7 +431,7 @@ uwatec_memomouse_dump_internal (uwatec_memomouse_device_t *device, dc_buffer_t * return DC_STATUS_CANCELLED; device_event_emit (&device->base, DC_EVENT_WAITING, NULL); - serial_sleep (100); + serial_sleep (device->port, 100); } // Fetch the current system time. @@ -472,7 +472,7 @@ uwatec_memomouse_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) // Give the interface some time to notice the DTR // line change from a previous transfer (if any). - serial_sleep (500); + serial_sleep (device->port, 500); // Set the DTR line. if (serial_set_dtr (device->port, 1) == -1) {