Attempt to provide an abort mecanism for windows users...

This commit is contained in:
Romuald Conty
2011-05-09 11:14:43 +00:00
parent 468027ba2b
commit 921d28d976
5 changed files with 55 additions and 15 deletions
+22 -4
View File
@@ -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;
}
+22 -4
View File
@@ -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;
}