mirror of
https://github.com/nfc-tools/libnfc.git
synced 2026-03-12 10:33:47 +00:00
- Add timeout capablities to nfc_initiator_transceive_bytes(), nfc_target_send_bytes() and nfc_target_receive_bytes();
- Bump version to 1.5.1.
This commit is contained in:
@@ -28,6 +28,8 @@
|
||||
#ifndef __NFC_BUS_UART_H__
|
||||
# define __NFC_BUS_UART_H__
|
||||
|
||||
# include <sys/time.h>
|
||||
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
@@ -47,8 +49,8 @@ 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);
|
||||
|
||||
int uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p);
|
||||
int uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx);
|
||||
int uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p, struct timeval *timeout);
|
||||
int uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx, struct timeval *timeout);
|
||||
|
||||
char **uart_list_ports (void);
|
||||
|
||||
|
||||
@@ -254,10 +254,14 @@ static const struct timeval tvTimeout = {
|
||||
* @return 0 on success, otherwise driver error code
|
||||
*/
|
||||
int
|
||||
uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p)
|
||||
uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p, struct timeval *timeout)
|
||||
{
|
||||
int iAbortFd = abort_p ? *((int*)abort_p) : 0;
|
||||
struct timeval tv = tvTimeout;
|
||||
struct timeval tv;
|
||||
if (timeout)
|
||||
tv = *timeout;
|
||||
else
|
||||
tv = tvTimeout;
|
||||
struct timeval *ptv = &tv;
|
||||
int received_bytes_count = 0;
|
||||
int available_bytes_count = 0;
|
||||
@@ -275,6 +279,7 @@ select:
|
||||
ptv = NULL;
|
||||
}
|
||||
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "timeout = %p", ptv);
|
||||
res = select (MAX(((serial_port_unix *) sp)->fd, iAbortFd) + 1, &rfds, NULL, NULL, ptv);
|
||||
|
||||
if ((res < 0) && (EINTR == errno)) {
|
||||
@@ -325,8 +330,9 @@ select:
|
||||
* @return 0 on success, otherwise a driver error is returned
|
||||
*/
|
||||
int
|
||||
uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx)
|
||||
uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx, struct timeval *timeout)
|
||||
{
|
||||
(void) timeout;
|
||||
LOG_HEX ("TX", pbtTx, szTx);
|
||||
if ((int) szTx == write (((serial_port_unix *) sp)->fd, pbtTx, szTx))
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user