Integrate the tcdrain() call into the write function.

This commit is contained in:
Jef Driesen 2011-12-03 20:20:13 +01:00
parent 060cc95d5c
commit 3c07a3017f
6 changed files with 8 additions and 42 deletions

View File

@ -92,7 +92,6 @@ int serial_read (serial_t *device, void* data, unsigned int size);
int serial_write (serial_t *device, const void* data, unsigned int size);
int serial_flush (serial_t *device, int queue);
int serial_drain (serial_t *device);
int serial_send_break (serial_t *device);

View File

@ -541,6 +541,14 @@ serial_write (serial_t *device, const void *data, unsigned int size)
nbytes += n;
}
// Wait until all data has been transmitted.
while (tcdrain (device->fd) != 0) {
if (errno != EINTR ) {
TRACE ("tcdrain");
return -1;
}
}
return nbytes;
}
@ -574,23 +582,6 @@ serial_flush (serial_t *device, int queue)
}
int
serial_drain (serial_t *device)
{
if (device == NULL)
return -1; // EINVAL (Invalid argument)
while (tcdrain (device->fd) != 0) {
if (errno != EINTR ) {
TRACE ("tcdrain");
return -1;
}
}
return 0;
}
int
serial_send_break (serial_t *device)
{

View File

@ -399,21 +399,6 @@ serial_flush (serial_t *device, int queue)
}
int
serial_drain (serial_t *device)
{
if (device == NULL)
return -1; // ERROR_INVALID_PARAMETER (The parameter is incorrect)
if (!FlushFileBuffers (device->hFile)) {
TRACE ("FlushFileBuffers");
return -1;
}
return 0;
}
int
serial_send_break (serial_t *device)
{

View File

@ -242,9 +242,6 @@ suunto_d9_device_packet (device_t *abstract, const unsigned char command[], unsi
return EXITCODE (n);
}
// Wait until all data has been transmitted.
serial_drain (device->port);
// Receive the echo.
unsigned char echo[128] = {0};
assert (sizeof (echo) >= csize);

View File

@ -209,9 +209,6 @@ suunto_vyper_send (suunto_vyper_device_t *device, const unsigned char command[],
return EXITCODE (n);
}
// Wait until all data has been transmitted.
serial_drain (device->port);
// If the interface sends an echo back (which is the case for many clone
// interfaces), this echo should be removed from the input queue before
// attempting to read the real reply from the dive computer. Otherwise,

View File

@ -181,9 +181,6 @@ suunto_vyper2_device_packet (device_t *abstract, const unsigned char command[],
return EXITCODE (n);
}
// Wait until all data has been transmitted.
serial_drain (device->port);
serial_sleep (0x9);
// Clear RTS to receive the reply.