Remove the half-duplex emulation from the I/O api

Now that the half-duplex emulation code isn't used anymore, it can be
removed from the I/O stream api.
This commit is contained in:
Jef Driesen 2018-02-24 09:48:17 +01:00
parent 4897a8351b
commit 38ff1f75dd
13 changed files with 0 additions and 178 deletions

View File

@ -129,17 +129,6 @@ dc_iostream_set_timeout (dc_iostream_t *iostream, int timeout);
dc_status_t dc_status_t
dc_iostream_set_latency (dc_iostream_t *iostream, unsigned int value); 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. * Set the state of the break condition.
* *

View File

@ -99,7 +99,6 @@ static const dc_iostream_vtable_t dc_bluetooth_vtable = {
sizeof(dc_socket_t), sizeof(dc_socket_t),
dc_socket_set_timeout, /* set_timeout */ dc_socket_set_timeout, /* set_timeout */
dc_socket_set_latency, /* set_latency */ dc_socket_set_latency, /* set_latency */
dc_socket_set_halfduplex, /* set_halfduplex */
dc_socket_set_break, /* set_break */ dc_socket_set_break, /* set_break */
dc_socket_set_dtr, /* set_dtr */ dc_socket_set_dtr, /* set_dtr */
dc_socket_set_rts, /* set_rts */ dc_socket_set_rts, /* set_rts */

View File

@ -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_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_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_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_dtr (dc_iostream_t *abstract, unsigned int value);
static dc_status_t dc_custom_set_rts (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), sizeof(dc_custom_t),
dc_custom_set_timeout, /* set_timeout */ dc_custom_set_timeout, /* set_timeout */
dc_custom_set_latency, /* set_latency */ dc_custom_set_latency, /* set_latency */
dc_custom_set_halfduplex, /* set_halfduplex */
dc_custom_set_break, /* set_break */ dc_custom_set_break, /* set_break */
dc_custom_set_dtr, /* set_dtr */ dc_custom_set_dtr, /* set_dtr */
dc_custom_set_rts, /* set_rts */ 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); 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 static dc_status_t
dc_custom_set_break (dc_iostream_t *abstract, unsigned int value) dc_custom_set_break (dc_iostream_t *abstract, unsigned int value)
{ {

View File

@ -33,7 +33,6 @@ extern "C" {
typedef struct dc_custom_cbs_t { typedef struct dc_custom_cbs_t {
dc_status_t (*set_timeout) (void *userdata, int timeout); dc_status_t (*set_timeout) (void *userdata, int timeout);
dc_status_t (*set_latency) (void *userdata, unsigned int value); 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_break) (void *userdata, unsigned int value);
dc_status_t (*set_dtr) (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); dc_status_t (*set_rts) (void *userdata, unsigned int value);

View File

@ -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_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_break) (dc_iostream_t *iostream, unsigned int value);
dc_status_t (*set_dtr) (dc_iostream_t *iostream, unsigned int value); dc_status_t (*set_dtr) (dc_iostream_t *iostream, unsigned int value);

View File

@ -85,17 +85,6 @@ dc_iostream_set_latency (dc_iostream_t *iostream, unsigned int value)
return iostream->vtable->set_latency (iostream, 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_status_t
dc_iostream_set_break (dc_iostream_t *iostream, unsigned int value) dc_iostream_set_break (dc_iostream_t *iostream, unsigned int value)
{ {

View File

@ -92,7 +92,6 @@ static const dc_iostream_vtable_t dc_irda_vtable = {
sizeof(dc_socket_t), sizeof(dc_socket_t),
dc_socket_set_timeout, /* set_timeout */ dc_socket_set_timeout, /* set_timeout */
dc_socket_set_latency, /* set_latency */ dc_socket_set_latency, /* set_latency */
dc_socket_set_halfduplex, /* set_halfduplex */
dc_socket_set_break, /* set_break */ dc_socket_set_break, /* set_break */
dc_socket_set_dtr, /* set_dtr */ dc_socket_set_dtr, /* set_dtr */
dc_socket_set_rts, /* set_rts */ dc_socket_set_rts, /* set_rts */

View File

@ -34,7 +34,6 @@ dc_descriptor_get_model
dc_descriptor_get_transport dc_descriptor_get_transport
dc_iostream_set_timeout dc_iostream_set_timeout
dc_iostream_set_halfduplex
dc_iostream_set_latency dc_iostream_set_latency
dc_iostream_set_break dc_iostream_set_break
dc_iostream_set_dtr dc_iostream_set_dtr

View File

@ -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_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_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_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_dtr (dc_iostream_t *iostream, unsigned int value);
static dc_status_t dc_serial_set_rts (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. * serial port is closed.
*/ */
struct termios tty; struct termios tty;
/* Half-duplex settings */
int halfduplex;
unsigned int baudrate;
unsigned int nbits;
} dc_serial_t; } dc_serial_t;
static const dc_iterator_vtable_t dc_serial_iterator_vtable = { 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), sizeof(dc_serial_t),
dc_serial_set_timeout, /* set_timeout */ dc_serial_set_timeout, /* set_timeout */
dc_serial_set_latency, /* set_latency */ dc_serial_set_latency, /* set_latency */
dc_serial_set_halfduplex, /* set_halfduplex */
dc_serial_set_break, /* set_break */ dc_serial_set_break, /* set_break */
dc_serial_set_dtr, /* set_dtr */ dc_serial_set_dtr, /* set_dtr */
dc_serial_set_rts, /* set_rts */ 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. // Default to blocking reads.
device->timeout = -1; device->timeout = -1;
// Default to full-duplex.
device->halfduplex = 0;
device->baudrate = 0;
device->nbits = 0;
// Create a high resolution timer. // Create a high resolution timer.
status = dc_timer_new (&device->timer); status = dc_timer_new (&device->timer);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
@ -619,9 +608,6 @@ dc_serial_configure (dc_iostream_t *abstract, unsigned int baudrate, unsigned in
#endif #endif
} }
device->baudrate = baudrate;
device->nbits = 1 + databits + stopbits + (parity ? 1 : 0);
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }
@ -635,16 +621,6 @@ dc_serial_set_timeout (dc_iostream_t *abstract, int timeout)
return DC_STATUS_SUCCESS; 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 static dc_status_t
dc_serial_set_latency (dc_iostream_t *abstract, unsigned int milliseconds) 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; dc_serial_t *device = (dc_serial_t *) abstract;
size_t nbytes = 0; 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) { while (nbytes < size) {
fd_set fds; fd_set fds;
FD_ZERO (&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: out:
if (actual) if (actual)
*actual = nbytes; *actual = nbytes;

View File

@ -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_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_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_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_dtr (dc_iostream_t *iostream, unsigned int value);
static dc_status_t dc_serial_set_rts (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; DCB dcb;
COMMTIMEOUTS timeouts; COMMTIMEOUTS timeouts;
/* Half-duplex settings */
int halfduplex;
unsigned int baudrate;
unsigned int nbits;
} dc_serial_t; } dc_serial_t;
static const dc_iterator_vtable_t dc_serial_iterator_vtable = { 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), sizeof(dc_serial_t),
dc_serial_set_timeout, /* set_timeout */ dc_serial_set_timeout, /* set_timeout */
dc_serial_set_latency, /* set_latency */ dc_serial_set_latency, /* set_latency */
dc_serial_set_halfduplex, /* set_halfduplex */
dc_serial_set_break, /* set_break */ dc_serial_set_break, /* set_break */
dc_serial_set_dtr, /* set_dtr */ dc_serial_set_dtr, /* set_dtr */
dc_serial_set_rts, /* set_rts */ 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; return DC_STATUS_NOMEMORY;
} }
// Default to full-duplex.
device->halfduplex = 0;
device->baudrate = 0;
device->nbits = 0;
// Open the device. // Open the device.
device->hFile = CreateFileA (devname, device->hFile = CreateFileA (devname,
GENERIC_READ | GENERIC_WRITE, 0, GENERIC_READ | GENERIC_WRITE, 0,
@ -457,9 +446,6 @@ dc_serial_configure (dc_iostream_t *abstract, unsigned int baudrate, unsigned in
return syserror (errcode); return syserror (errcode);
} }
device->baudrate = baudrate;
device->nbits = 1 + databits + stopbits + (parity ? 1 : 0);
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }
@ -510,16 +496,6 @@ dc_serial_set_timeout (dc_iostream_t *abstract, int timeout)
return DC_STATUS_SUCCESS; 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 static dc_status_t
dc_serial_set_latency (dc_iostream_t *abstract, unsigned int value) 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; dc_serial_t *device = (dc_serial_t *) abstract;
DWORD dwWritten = 0; 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)) { if (!WriteFile (device->hFile, data, size, &dwWritten, NULL)) {
DWORD errcode = GetLastError (); DWORD errcode = GetLastError ();
SYSERROR (abstract->context, errcode); 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; 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) { if (dwWritten != size) {
status = DC_STATUS_TIMEOUT; status = DC_STATUS_TIMEOUT;
} }

View File

@ -169,12 +169,6 @@ dc_socket_set_latency (dc_iostream_t *iostream, unsigned int value)
return DC_STATUS_SUCCESS; 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_status_t
dc_socket_set_break (dc_iostream_t *iostream, unsigned int value) dc_socket_set_break (dc_iostream_t *iostream, unsigned int value)
{ {

View File

@ -107,9 +107,6 @@ dc_socket_set_timeout (dc_iostream_t *iostream, int timeout);
dc_status_t dc_status_t
dc_socket_set_latency (dc_iostream_t *iostream, unsigned int value); 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_status_t
dc_socket_set_break (dc_iostream_t *iostream, unsigned int value); dc_socket_set_break (dc_iostream_t *iostream, unsigned int value);

View File

@ -119,7 +119,6 @@ static const dc_iostream_vtable_t dc_usbhid_vtable = {
sizeof(dc_usbhid_t), sizeof(dc_usbhid_t),
dc_usbhid_set_timeout, /* set_timeout */ dc_usbhid_set_timeout, /* set_timeout */
NULL, /* set_latency */ NULL, /* set_latency */
NULL, /* set_halfduplex */
NULL, /* set_break */ NULL, /* set_break */
NULL, /* set_dtr */ NULL, /* set_dtr */
NULL, /* set_rts */ NULL, /* set_rts */