Attempt to provide an abort mecanism for windows users...
This commit is contained in:
parent
468027ba2b
commit
921d28d976
5 changed files with 55 additions and 15 deletions
|
@ -46,7 +46,7 @@ void uart_close (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, int iAbortFd);
|
||||
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);
|
||||
|
||||
char **uart_list_ports (void);
|
||||
|
|
|
@ -224,8 +224,9 @@ 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, int iAbortFd)
|
||||
uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p)
|
||||
{
|
||||
int iAbortFd = *((int*)abort_p);
|
||||
struct timeval tv = tvTimeout;
|
||||
struct timeval *ptv = &tv;
|
||||
int received_bytes_count = 0;
|
||||
|
|
|
@ -142,13 +142,16 @@ uart_get_speed (const serial_port sp)
|
|||
}
|
||||
|
||||
int
|
||||
uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, int iAbortFd)
|
||||
uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p)
|
||||
{
|
||||
// TODO: Implement abort mecanism (using iAbortFd)
|
||||
// TODO Test me with abort_p
|
||||
volatile bool * abort_flag_p = (volatile bool *)abort_p;
|
||||
DWORD dwRxLen = szRx;
|
||||
do {
|
||||
if (!ReadFile (((serial_port_windows *) sp)->hPort, pbtRx, dwRxLen, &dwRxLen, NULL)) {
|
||||
return DEIO;
|
||||
}
|
||||
} while ( (dwRxLen != (DWORD) szRx) && ((abort_flag_p) && !(*abort_flag_p)) );
|
||||
return (dwRxLen == (DWORD) szRx) ? 0 : DEIO;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,7 +72,11 @@ const struct pn53x_io arygon_tama_io;
|
|||
|
||||
struct arygon_data {
|
||||
serial_port port;
|
||||
#ifndef WIN32
|
||||
int iAbortFds[2];
|
||||
#else
|
||||
volatile bool abort_flag;
|
||||
#endif
|
||||
};
|
||||
|
||||
static const byte_t arygon_error_none[] = "FF000000\x0d\x0a";
|
||||
|
@ -186,8 +190,12 @@ arygon_connect (const nfc_device_desc_t * pndd)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
// pipe-based abort mecanism
|
||||
pipe (DRIVER_DATA (pnd)->iAbortFds);
|
||||
#else
|
||||
DRIVER_DATA (pnd)->abort_flag = false;
|
||||
#endif
|
||||
|
||||
char arygon_firmware_version[10];
|
||||
arygon_firmware (pnd, arygon_firmware_version);
|
||||
|
@ -206,9 +214,11 @@ arygon_disconnect (nfc_device_t * pnd)
|
|||
// Release UART port
|
||||
uart_close (DRIVER_DATA (pnd)->port);
|
||||
|
||||
#ifndef WIN32
|
||||
// Release file descriptors used for abort mecanism
|
||||
close (DRIVER_DATA (pnd)->iAbortFds[0]);
|
||||
close (DRIVER_DATA (pnd)->iAbortFds[1]);
|
||||
#endif
|
||||
|
||||
nfc_device_free (pnd);
|
||||
}
|
||||
|
@ -280,7 +290,7 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe
|
|||
{
|
||||
byte_t abtRxBuf[5];
|
||||
size_t len;
|
||||
int abort_fd = 0;
|
||||
void * abort_p = NULL;
|
||||
|
||||
switch (CHIP_DATA (pnd)->ui8LastCommand) {
|
||||
case InAutoPoll:
|
||||
|
@ -288,15 +298,19 @@ arygon_tama_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLe
|
|||
case InJumpForDEP:
|
||||
case TgGetData:
|
||||
case TgInitAsTarget:
|
||||
abort_fd = DRIVER_DATA (pnd)->iAbortFds[1];
|
||||
#ifndef WIN32
|
||||
abort_p = &(DRIVER_DATA (pnd)->iAbortFds[1]);
|
||||
#else
|
||||
abort_p = &(DRIVER_DATA (pnd)->abort_flag);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
pnd->iLastError = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 5, abort_fd);
|
||||
pnd->iLastError = uart_receive (DRIVER_DATA (pnd)->port, abtRxBuf, 5, abort_p);
|
||||
|
||||
if (abort_fd && (DEABORT == pnd->iLastError)) {
|
||||
if (abort_p && (DEABORT == pnd->iLastError)) {
|
||||
arygon_abort (pnd);
|
||||
|
||||
/* iLastError got reset by arygon_abort() */
|
||||
|
@ -456,8 +470,12 @@ bool
|
|||
arygon_abort_command (nfc_device_t * pnd)
|
||||
{
|
||||
if (pnd) {
|
||||
#ifndef WIN32
|
||||
close (DRIVER_DATA (pnd)->iAbortFds[0]);
|
||||
pipe (DRIVER_DATA (pnd)->iAbortFds);
|
||||
#else
|
||||
DRIVER_DATA (pnd)->abort_flag = true;
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -56,7 +56,11 @@ const struct pn53x_io pn532_uart_io;
|
|||
|
||||
struct pn532_uart_data {
|
||||
serial_port port;
|
||||
#ifndef WIN32
|
||||
int iAbortFds[2];
|
||||
#else
|
||||
volatile bool abort_flag;
|
||||
#endif
|
||||
};
|
||||
|
||||
#define DRIVER_DATA(pnd) ((struct pn532_uart_data*)(pnd->driver_data))
|
||||
|
@ -173,8 +177,12 @@ pn532_uart_connect (const nfc_device_desc_t * pndd)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
// pipe-based abort mecanism
|
||||
pipe (DRIVER_DATA (pnd)->iAbortFds);
|
||||
#else
|
||||
abort_flag = false;
|
||||
#endif
|
||||
|
||||
pn53x_init(pnd);
|
||||
return pnd;
|
||||
|
@ -186,9 +194,11 @@ pn532_uart_disconnect (nfc_device_t * pnd)
|
|||
// Release UART port
|
||||
uart_close (DRIVER_DATA(pnd)->port);
|
||||
|
||||
#ifndef WIN32
|
||||
// Release file descriptors used for abort mecanism
|
||||
close (DRIVER_DATA (pnd)->iAbortFds[0]);
|
||||
close (DRIVER_DATA (pnd)->iAbortFds[1]);
|
||||
#endif
|
||||
|
||||
nfc_device_free (pnd);
|
||||
}
|
||||
|
@ -267,7 +277,7 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
|
|||
{
|
||||
byte_t abtRxBuf[5];
|
||||
size_t len;
|
||||
int abort_fd = 0;
|
||||
void * abort_p = NULL;
|
||||
|
||||
switch (CHIP_DATA (pnd)->ui8LastCommand) {
|
||||
case InAutoPoll:
|
||||
|
@ -275,15 +285,19 @@ pn532_uart_receive (nfc_device_t * pnd, byte_t * pbtData, const size_t szDataLen
|
|||
case InJumpForDEP:
|
||||
case TgGetData:
|
||||
case TgInitAsTarget:
|
||||
abort_fd = DRIVER_DATA (pnd)->iAbortFds[1];
|
||||
#ifndef WIN32
|
||||
abort_p = &(DRIVER_DATA (pnd)->iAbortFds[1]);
|
||||
#else
|
||||
abort_p = &(DRIVER_DATA (pnd)->abort_flag);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 5, abort_fd);
|
||||
pnd->iLastError = uart_receive (DRIVER_DATA(pnd)->port, abtRxBuf, 5, abort_p);
|
||||
|
||||
if (abort_fd && (DEABORT == pnd->iLastError)) {
|
||||
if (abort_p && (DEABORT == pnd->iLastError)) {
|
||||
pn532_uart_ack (pnd);
|
||||
return -1;
|
||||
}
|
||||
|
@ -407,8 +421,12 @@ bool
|
|||
pn532_uart_abort_command (nfc_device_t * pnd)
|
||||
{
|
||||
if (pnd) {
|
||||
#ifndef WIN32
|
||||
close (DRIVER_DATA (pnd)->iAbortFds[0]);
|
||||
pipe (DRIVER_DATA (pnd)->iAbortFds);
|
||||
#else
|
||||
DRIVER_DATA (pnd)->abort_flag = true;
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue