diff --git a/include/libdivecomputer/iostream.h b/include/libdivecomputer/iostream.h index dab5daf..832680d 100644 --- a/include/libdivecomputer/iostream.h +++ b/include/libdivecomputer/iostream.h @@ -129,17 +129,6 @@ dc_iostream_set_timeout (dc_iostream_t *iostream, int timeout); dc_status_t dc_iostream_set_latency (dc_iostream_t *iostream, unsigned int value); -/** - * Set the state of the half duplex emulation. - * - * @param[in] iostream A valid I/O stream. - * @param[in] value The half duplex state. - * @returns #DC_STATUS_SUCCESS on success, or another #dc_status_t code - * on failure. - */ -dc_status_t -dc_iostream_set_halfduplex (dc_iostream_t *iostream, unsigned int value); - /** * Set the state of the break condition. * diff --git a/src/bluetooth.c b/src/bluetooth.c index 08347d5..772101f 100644 --- a/src/bluetooth.c +++ b/src/bluetooth.c @@ -99,7 +99,6 @@ static const dc_iostream_vtable_t dc_bluetooth_vtable = { sizeof(dc_socket_t), dc_socket_set_timeout, /* set_timeout */ dc_socket_set_latency, /* set_latency */ - dc_socket_set_halfduplex, /* set_halfduplex */ dc_socket_set_break, /* set_break */ dc_socket_set_dtr, /* set_dtr */ dc_socket_set_rts, /* set_rts */ diff --git a/src/custom.c b/src/custom.c index e96ba5f..519a39e 100644 --- a/src/custom.c +++ b/src/custom.c @@ -29,7 +29,6 @@ static dc_status_t dc_custom_set_timeout (dc_iostream_t *abstract, int timeout); static dc_status_t dc_custom_set_latency (dc_iostream_t *abstract, unsigned int value); -static dc_status_t dc_custom_set_halfduplex (dc_iostream_t *abstract, unsigned int value); static dc_status_t dc_custom_set_break (dc_iostream_t *abstract, unsigned int value); static dc_status_t dc_custom_set_dtr (dc_iostream_t *abstract, unsigned int value); static dc_status_t dc_custom_set_rts (dc_iostream_t *abstract, unsigned int value); @@ -55,7 +54,6 @@ static const dc_iostream_vtable_t dc_custom_vtable = { sizeof(dc_custom_t), dc_custom_set_timeout, /* set_timeout */ dc_custom_set_latency, /* set_latency */ - dc_custom_set_halfduplex, /* set_halfduplex */ dc_custom_set_break, /* set_break */ dc_custom_set_dtr, /* set_dtr */ dc_custom_set_rts, /* set_rts */ @@ -117,17 +115,6 @@ dc_custom_set_latency (dc_iostream_t *abstract, unsigned int value) return custom->callbacks.set_latency (custom->userdata, value); } -static dc_status_t -dc_custom_set_halfduplex (dc_iostream_t *abstract, unsigned int value) -{ - dc_custom_t *custom = (dc_custom_t *) abstract; - - if (custom->callbacks.set_halfduplex == NULL) - return DC_STATUS_UNSUPPORTED; - - return custom->callbacks.set_halfduplex (custom->userdata, value); -} - static dc_status_t dc_custom_set_break (dc_iostream_t *abstract, unsigned int value) { diff --git a/src/custom.h b/src/custom.h index f062cd3..f1ab5da 100644 --- a/src/custom.h +++ b/src/custom.h @@ -33,7 +33,6 @@ extern "C" { typedef struct dc_custom_cbs_t { dc_status_t (*set_timeout) (void *userdata, int timeout); dc_status_t (*set_latency) (void *userdata, unsigned int value); - dc_status_t (*set_halfduplex) (void *userdata, unsigned int value); dc_status_t (*set_break) (void *userdata, unsigned int value); dc_status_t (*set_dtr) (void *userdata, unsigned int value); dc_status_t (*set_rts) (void *userdata, unsigned int value); diff --git a/src/iostream-private.h b/src/iostream-private.h index 7f7be84..b9bd4f1 100644 --- a/src/iostream-private.h +++ b/src/iostream-private.h @@ -44,8 +44,6 @@ struct dc_iostream_vtable_t { dc_status_t (*set_latency) (dc_iostream_t *iostream, unsigned int value); - dc_status_t (*set_halfduplex) (dc_iostream_t *iostream, unsigned int value); - dc_status_t (*set_break) (dc_iostream_t *iostream, unsigned int value); dc_status_t (*set_dtr) (dc_iostream_t *iostream, unsigned int value); diff --git a/src/iostream.c b/src/iostream.c index e6c40ea..c1e3017 100644 --- a/src/iostream.c +++ b/src/iostream.c @@ -85,17 +85,6 @@ dc_iostream_set_latency (dc_iostream_t *iostream, unsigned int value) return iostream->vtable->set_latency (iostream, value); } -dc_status_t -dc_iostream_set_halfduplex (dc_iostream_t *iostream, unsigned int value) -{ - if (iostream == NULL || iostream->vtable->set_halfduplex == NULL) - return DC_STATUS_UNSUPPORTED; - - INFO (iostream->context, "Halfduplex: value=%i", value); - - return iostream->vtable->set_halfduplex (iostream, value); -} - dc_status_t dc_iostream_set_break (dc_iostream_t *iostream, unsigned int value) { diff --git a/src/irda.c b/src/irda.c index 1ac754b..d1aecfb 100644 --- a/src/irda.c +++ b/src/irda.c @@ -92,7 +92,6 @@ static const dc_iostream_vtable_t dc_irda_vtable = { sizeof(dc_socket_t), dc_socket_set_timeout, /* set_timeout */ dc_socket_set_latency, /* set_latency */ - dc_socket_set_halfduplex, /* set_halfduplex */ dc_socket_set_break, /* set_break */ dc_socket_set_dtr, /* set_dtr */ dc_socket_set_rts, /* set_rts */ diff --git a/src/libdivecomputer.symbols b/src/libdivecomputer.symbols index daed9ef..a0c3724 100644 --- a/src/libdivecomputer.symbols +++ b/src/libdivecomputer.symbols @@ -34,7 +34,6 @@ dc_descriptor_get_model dc_descriptor_get_transport dc_iostream_set_timeout -dc_iostream_set_halfduplex dc_iostream_set_latency dc_iostream_set_break dc_iostream_set_dtr diff --git a/src/serial_posix.c b/src/serial_posix.c index 8922c3a..352655b 100644 --- a/src/serial_posix.c +++ b/src/serial_posix.c @@ -68,7 +68,6 @@ static dc_status_t dc_serial_iterator_free (dc_iterator_t *iterator); static dc_status_t dc_serial_set_timeout (dc_iostream_t *iostream, int timeout); static dc_status_t dc_serial_set_latency (dc_iostream_t *iostream, unsigned int value); -static dc_status_t dc_serial_set_halfduplex (dc_iostream_t *iostream, unsigned int value); static dc_status_t dc_serial_set_break (dc_iostream_t *iostream, unsigned int value); static dc_status_t dc_serial_set_dtr (dc_iostream_t *iostream, unsigned int value); static dc_status_t dc_serial_set_rts (dc_iostream_t *iostream, unsigned int value); @@ -106,10 +105,6 @@ typedef struct dc_serial_t { * serial port is closed. */ struct termios tty; - /* Half-duplex settings */ - int halfduplex; - unsigned int baudrate; - unsigned int nbits; } dc_serial_t; static const dc_iterator_vtable_t dc_serial_iterator_vtable = { @@ -122,7 +117,6 @@ static const dc_iostream_vtable_t dc_serial_vtable = { sizeof(dc_serial_t), dc_serial_set_timeout, /* set_timeout */ dc_serial_set_latency, /* set_latency */ - dc_serial_set_halfduplex, /* set_halfduplex */ dc_serial_set_break, /* set_break */ dc_serial_set_dtr, /* set_dtr */ dc_serial_set_rts, /* set_rts */ @@ -286,11 +280,6 @@ dc_serial_open (dc_iostream_t **out, dc_context_t *context, const char *name) // Default to blocking reads. device->timeout = -1; - // Default to full-duplex. - device->halfduplex = 0; - device->baudrate = 0; - device->nbits = 0; - // Create a high resolution timer. status = dc_timer_new (&device->timer); if (status != DC_STATUS_SUCCESS) { @@ -619,9 +608,6 @@ dc_serial_configure (dc_iostream_t *abstract, unsigned int baudrate, unsigned in #endif } - device->baudrate = baudrate; - device->nbits = 1 + databits + stopbits + (parity ? 1 : 0); - return DC_STATUS_SUCCESS; } @@ -635,16 +621,6 @@ dc_serial_set_timeout (dc_iostream_t *abstract, int timeout) return DC_STATUS_SUCCESS; } -static dc_status_t -dc_serial_set_halfduplex (dc_iostream_t *abstract, unsigned int value) -{ - dc_serial_t *device = (dc_serial_t *) abstract; - - device->halfduplex = value; - - return DC_STATUS_SUCCESS; -} - static dc_status_t dc_serial_set_latency (dc_iostream_t *abstract, unsigned int milliseconds) { @@ -781,17 +757,6 @@ dc_serial_write (dc_iostream_t *abstract, const void *data, size_t size, size_t dc_serial_t *device = (dc_serial_t *) abstract; size_t nbytes = 0; - struct timeval tve, tvb; - if (device->halfduplex) { - // Get the current time. - if (gettimeofday (&tvb, NULL) != 0) { - int errcode = errno; - SYSERROR (abstract->context, errcode); - status = syserror (errcode); - goto out; - } - } - while (nbytes < size) { fd_set fds; FD_ZERO (&fds); @@ -839,35 +804,6 @@ dc_serial_write (dc_iostream_t *abstract, const void *data, size_t size, size_t } } - if (device->halfduplex) { - // Get the current time. - if (gettimeofday (&tve, NULL) != 0) { - int errcode = errno; - SYSERROR (abstract->context, errcode); - status = syserror (errcode); - goto out; - } - - // Calculate the elapsed time (microseconds). - struct timeval tvt; - timersub (&tve, &tvb, &tvt); - unsigned long elapsed = tvt.tv_sec * 1000000 + tvt.tv_usec; - - // Calculate the expected duration (microseconds). A 2 millisecond fudge - // factor is added because it improves the success rate significantly. - unsigned long expected = 1000000.0 * device->nbits / device->baudrate * size + 0.5 + 2000; - - // Wait for the remaining time. - if (elapsed < expected) { - unsigned long remaining = expected - elapsed; - - // 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. - dc_serial_sleep (abstract, (remaining + 999) / 1000); - } - } - out: if (actual) *actual = nbytes; diff --git a/src/serial_win32.c b/src/serial_win32.c index c9b31e9..b0c6050 100644 --- a/src/serial_win32.c +++ b/src/serial_win32.c @@ -37,7 +37,6 @@ static dc_status_t dc_serial_iterator_free (dc_iterator_t *iterator); static dc_status_t dc_serial_set_timeout (dc_iostream_t *iostream, int timeout); static dc_status_t dc_serial_set_latency (dc_iostream_t *iostream, unsigned int value); -static dc_status_t dc_serial_set_halfduplex (dc_iostream_t *iostream, unsigned int value); static dc_status_t dc_serial_set_break (dc_iostream_t *iostream, unsigned int value); static dc_status_t dc_serial_set_dtr (dc_iostream_t *iostream, unsigned int value); static dc_status_t dc_serial_set_rts (dc_iostream_t *iostream, unsigned int value); @@ -76,10 +75,6 @@ typedef struct dc_serial_t { */ DCB dcb; COMMTIMEOUTS timeouts; - /* Half-duplex settings */ - int halfduplex; - unsigned int baudrate; - unsigned int nbits; } dc_serial_t; static const dc_iterator_vtable_t dc_serial_iterator_vtable = { @@ -92,7 +87,6 @@ static const dc_iostream_vtable_t dc_serial_vtable = { sizeof(dc_serial_t), dc_serial_set_timeout, /* set_timeout */ dc_serial_set_latency, /* set_latency */ - dc_serial_set_halfduplex, /* set_halfduplex */ dc_serial_set_break, /* set_break */ dc_serial_set_dtr, /* set_dtr */ dc_serial_set_rts, /* set_rts */ @@ -288,11 +282,6 @@ dc_serial_open (dc_iostream_t **out, dc_context_t *context, const char *name) return DC_STATUS_NOMEMORY; } - // Default to full-duplex. - device->halfduplex = 0; - device->baudrate = 0; - device->nbits = 0; - // Open the device. device->hFile = CreateFileA (devname, GENERIC_READ | GENERIC_WRITE, 0, @@ -457,9 +446,6 @@ dc_serial_configure (dc_iostream_t *abstract, unsigned int baudrate, unsigned in return syserror (errcode); } - device->baudrate = baudrate; - device->nbits = 1 + databits + stopbits + (parity ? 1 : 0); - return DC_STATUS_SUCCESS; } @@ -510,16 +496,6 @@ dc_serial_set_timeout (dc_iostream_t *abstract, int timeout) return DC_STATUS_SUCCESS; } -static dc_status_t -dc_serial_set_halfduplex (dc_iostream_t *abstract, unsigned int value) -{ - dc_serial_t *device = (dc_serial_t *) abstract; - - device->halfduplex = value; - - return DC_STATUS_SUCCESS; -} - static dc_status_t dc_serial_set_latency (dc_iostream_t *abstract, unsigned int value) { @@ -558,18 +534,6 @@ dc_serial_write (dc_iostream_t *abstract, const void *data, size_t size, size_t dc_serial_t *device = (dc_serial_t *) abstract; DWORD dwWritten = 0; - LARGE_INTEGER begin, end, freq; - if (device->halfduplex) { - // Get the current time. - if (!QueryPerformanceFrequency(&freq) || - !QueryPerformanceCounter(&begin)) { - DWORD errcode = GetLastError (); - SYSERROR (abstract->context, errcode); - status = syserror (errcode); - goto out; - } - } - if (!WriteFile (device->hFile, data, size, &dwWritten, NULL)) { DWORD errcode = GetLastError (); SYSERROR (abstract->context, errcode); @@ -577,33 +541,6 @@ dc_serial_write (dc_iostream_t *abstract, const void *data, size_t size, size_t goto out; } - if (device->halfduplex) { - // Get the current time. - if (!QueryPerformanceCounter(&end)) { - DWORD errcode = GetLastError (); - SYSERROR (abstract->context, errcode); - status = syserror (errcode); - goto out; - } - - // Calculate the elapsed time (microseconds). - unsigned long elapsed = 1000000.0 * (end.QuadPart - begin.QuadPart) / freq.QuadPart + 0.5; - - // Calculate the expected duration (microseconds). A 2 millisecond fudge - // factor is added because it improves the success rate significantly. - unsigned long expected = 1000000.0 * device->nbits / device->baudrate * size + 0.5 + 2000; - - // Wait for the remaining time. - if (elapsed < expected) { - unsigned long remaining = expected - elapsed; - - // The remaining time is rounded up to the nearest millisecond - // because the Windows Sleep() function doesn't have a higher - // resolution. - dc_serial_sleep (abstract, (remaining + 999) / 1000); - } - } - if (dwWritten != size) { status = DC_STATUS_TIMEOUT; } diff --git a/src/socket.c b/src/socket.c index 5ce392f..1842a75 100644 --- a/src/socket.c +++ b/src/socket.c @@ -169,12 +169,6 @@ dc_socket_set_latency (dc_iostream_t *iostream, unsigned int value) return DC_STATUS_SUCCESS; } -dc_status_t -dc_socket_set_halfduplex (dc_iostream_t *iostream, unsigned int value) -{ - return DC_STATUS_SUCCESS; -} - dc_status_t dc_socket_set_break (dc_iostream_t *iostream, unsigned int value) { diff --git a/src/socket.h b/src/socket.h index d612603..626003c 100644 --- a/src/socket.h +++ b/src/socket.h @@ -107,9 +107,6 @@ dc_socket_set_timeout (dc_iostream_t *iostream, int timeout); dc_status_t dc_socket_set_latency (dc_iostream_t *iostream, unsigned int value); -dc_status_t -dc_socket_set_halfduplex (dc_iostream_t *iostream, unsigned int value); - dc_status_t dc_socket_set_break (dc_iostream_t *iostream, unsigned int value); diff --git a/src/usbhid.c b/src/usbhid.c index b2dfa16..244e175 100644 --- a/src/usbhid.c +++ b/src/usbhid.c @@ -119,7 +119,6 @@ static const dc_iostream_vtable_t dc_usbhid_vtable = { sizeof(dc_usbhid_t), dc_usbhid_set_timeout, /* set_timeout */ NULL, /* set_latency */ - NULL, /* set_halfduplex */ NULL, /* set_break */ NULL, /* set_dtr */ NULL, /* set_rts */