mirror of
https://github.com/nfc-tools/libnfc.git
synced 2026-03-12 10:33:47 +00:00
drivers: UART based drivers could now use uart_flush_input() to discard junk bytes on input.
This commit is contained in:
@@ -42,6 +42,7 @@ typedef void *serial_port;
|
||||
|
||||
serial_port uart_open (const char *pcPortName);
|
||||
void uart_close (const serial_port sp);
|
||||
void uart_flush_input (const serial_port sp);
|
||||
|
||||
void uart_set_speed (serial_port sp, const uint32_t uiPortSpeed);
|
||||
uint32_t uart_get_speed (const serial_port sp);
|
||||
|
||||
@@ -100,9 +100,6 @@ uart_open (const char *pcPortName)
|
||||
sp->tiNew.c_cc[VMIN] = 0; // block until n bytes are received
|
||||
sp->tiNew.c_cc[VTIME] = 0; // block until a timer expires (n * 100 mSec.)
|
||||
|
||||
// This line seems to produce absolutely no effect on my system (GNU/Linux 2.6.35)
|
||||
tcflush (sp->fd, TCIFLUSH);
|
||||
|
||||
if (tcsetattr (sp->fd, TCSANOW, &sp->tiNew) == -1) {
|
||||
uart_close (sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
@@ -110,6 +107,29 @@ uart_open (const char *pcPortName)
|
||||
return sp;
|
||||
}
|
||||
|
||||
void
|
||||
uart_flush_input (serial_port sp)
|
||||
{
|
||||
// This line seems to produce absolutely no effect on my system (GNU/Linux 2.6.35)
|
||||
tcflush (((serial_port_unix *) sp)->fd, TCIFLUSH);
|
||||
// So, I wrote this byte-eater
|
||||
// Retrieve the count of the incoming bytes
|
||||
int available_bytes_count = 0;
|
||||
int res;
|
||||
res = ioctl (((serial_port_unix *) sp)->fd, FIONREAD, &available_bytes_count);
|
||||
if (res != 0) {
|
||||
return;
|
||||
}
|
||||
if (available_bytes_count == 0) {
|
||||
return;
|
||||
}
|
||||
char* rx = malloc (available_bytes_count);
|
||||
// There is something available, read the data
|
||||
res = read (((serial_port_unix *) sp)->fd, rx, available_bytes_count);
|
||||
DBG ("%d bytes have eatten.", available_bytes_count);
|
||||
free (rx);
|
||||
}
|
||||
|
||||
void
|
||||
uart_set_speed (serial_port sp, const uint32_t uiPortSpeed)
|
||||
{
|
||||
|
||||
@@ -87,6 +87,12 @@ uart_close (const serial_port sp)
|
||||
free (sp);
|
||||
}
|
||||
|
||||
void
|
||||
uart_flush_input (const serial_port sp)
|
||||
{
|
||||
// TODO: Implement me
|
||||
}
|
||||
|
||||
void
|
||||
uart_set_speed (serial_port sp, const uint32_t uiPortSpeed)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user