Timeout is now integer.

This commit is contained in:
Audrey Diacre
2011-11-25 11:37:30 +00:00
parent dad3603936
commit 5c7454a2f7
29 changed files with 133 additions and 145 deletions
+2 -2
View File
@@ -310,7 +310,7 @@ acr122_disconnect (nfc_device * pnd)
}
bool
acr122_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout)
acr122_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, int timeout)
{
// FIXME: timeout is not handled
(void) timeout;
@@ -381,7 +381,7 @@ acr122_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, str
}
int
acr122_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szData, struct timeval *timeout)
acr122_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szData, int timeout)
{
// FIXME: timeout is not handled
(void) timeout;
+2 -2
View File
@@ -30,8 +30,8 @@ bool acr122_probe (nfc_connstring connstrings[], size_t connstrings_len, size
// Functions used by developer to handle connection to this device
nfc_device *acr122_connect (const nfc_connstring connstring);
bool acr122_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout);
int acr122_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szData, struct timeval *timeout);
bool acr122_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, int timeout);
int acr122_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szData, int timeout);
void acr122_disconnect (nfc_device * pnd);
extern const struct nfc_driver_t acr122_driver;
+7 -11
View File
@@ -304,7 +304,7 @@ arygon_disconnect (nfc_device * pnd)
#define ARYGON_TX_BUFFER_LEN (PN53x_NORMAL_FRAME__DATA_MAX_LEN + PN53x_NORMAL_FRAME__OVERHEAD + 1)
#define ARYGON_RX_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
bool
arygon_tama_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout)
arygon_tama_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, int timeout)
{
// Before sending anything, we need to discard from any junk bytes
uart_flush_input (DRIVER_DATA(pnd)->port);
@@ -359,14 +359,14 @@ arygon_abort (nfc_device *pnd)
// Send a valid TAMA packet to wakup the PN53x (we will not have an answer, according to Arygon manual)
uint8_t dummy[] = { 0x32, 0x00, 0x00, 0xff, 0x09, 0xf7, 0xd4, 0x00, 0x00, 0x6c, 0x69, 0x62, 0x6e, 0x66, 0x63, 0xbe, 0x00 };
uart_send (DRIVER_DATA (pnd)->port, dummy, sizeof (dummy), NULL);
uart_send (DRIVER_DATA (pnd)->port, dummy, sizeof (dummy), 0);
// Using Arygon device we can't send ACK frame to abort the running command
return (pn53x_check_communication (pnd)) ? 0 : -1;
}
int
arygon_tama_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szDataLen, struct timeval *timeout)
arygon_tama_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szDataLen, int timeout)
{
uint8_t abtRxBuf[5];
size_t len;
@@ -491,12 +491,12 @@ arygon_firmware (nfc_device * pnd, char * str)
size_t szRx = sizeof(abtRx);
int res = uart_send (DRIVER_DATA (pnd)->port, arygon_firmware_version_cmd, sizeof (arygon_firmware_version_cmd), NULL);
int res = uart_send (DRIVER_DATA (pnd)->port, arygon_firmware_version_cmd, sizeof (arygon_firmware_version_cmd), 0);
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Unable to send ARYGON firmware command.");
return;
}
res = uart_receive (DRIVER_DATA (pnd)->port, abtRx, szRx, 0, NULL);
res = uart_receive (DRIVER_DATA (pnd)->port, abtRx, szRx, 0, 0);
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Unable to retrieve ARYGON firmware version.");
return;
@@ -519,15 +519,11 @@ arygon_reset_tama (nfc_device * pnd)
size_t szRx = sizeof(abtRx);
int res;
struct timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 0;
uart_send (DRIVER_DATA (pnd)->port, arygon_reset_tama_cmd, sizeof (arygon_reset_tama_cmd), &tv);
uart_send (DRIVER_DATA (pnd)->port, arygon_reset_tama_cmd, sizeof (arygon_reset_tama_cmd), 1000);
// Two reply are possible from ARYGON device: arygon_error_none (ie. in case the byte is well-sent)
// or arygon_error_unknown_mode (ie. in case of the first byte was bad-transmitted)
res = uart_receive (DRIVER_DATA (pnd)->port, abtRx, szRx, 0, &tv);
res = uart_receive (DRIVER_DATA (pnd)->port, abtRx, szRx, 0, 1000);
if (res != 0) {
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "No reply to 'reset TAMA' command.");
return false;
+2 -2
View File
@@ -35,8 +35,8 @@ bool arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size
nfc_device *arygon_connect (const nfc_connstring connstring);
void arygon_disconnect (nfc_device * pnd);
bool arygon_tama_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout);
int arygon_tama_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szDat, struct timeval *timeouta);
bool arygon_tama_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, int timeout);
int arygon_tama_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szDat, int timeouta);
extern const struct nfc_driver_t arygon_driver;
+5 -8
View File
@@ -282,14 +282,14 @@ pn532_uart_wakeup (nfc_device * pnd)
{
/* High Speed Unit (HSU) wake up consist to send 0x55 and wait a "long" delay for PN532 being wakeup. */
const uint8_t pn532_wakeup_preamble[] = { 0x55, 0x55, 0x00, 0x00, 0x00 };
int res = uart_send (DRIVER_DATA(pnd)->port, pn532_wakeup_preamble, sizeof (pn532_wakeup_preamble), NULL);
int res = uart_send (DRIVER_DATA(pnd)->port, pn532_wakeup_preamble, sizeof (pn532_wakeup_preamble), 0);
CHIP_DATA(pnd)->power_mode = NORMAL; // PN532 should now be awake
return res;
}
#define PN532_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
bool
pn532_uart_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout)
pn532_uart_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, int timeout)
{
// Before sending anything, we need to discard from any junk bytes
uart_flush_input (DRIVER_DATA(pnd)->port);
@@ -301,10 +301,7 @@ pn532_uart_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData,
return false;
}
// According to PN532 application note, C106 appendix: to go out Low Vbat mode and enter in normal mode we need to send a SAMConfiguration command
struct timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 0;
if (!pn53x_SAMConfiguration (pnd, 0x01, &tv)) {
if (!pn53x_SAMConfiguration (pnd, 0x01, 1000)) {
return false;
}
}
@@ -352,7 +349,7 @@ pn532_uart_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData,
}
int
pn532_uart_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szDataLen, struct timeval *timeout)
pn532_uart_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szDataLen, int timeout)
{
uint8_t abtRxBuf[5];
size_t len;
@@ -483,7 +480,7 @@ pn532_uart_ack (nfc_device * pnd)
return -1;
}
}
return (0 == uart_send (DRIVER_DATA(pnd)->port, pn53x_ack_frame, sizeof (pn53x_ack_frame), NULL)) ? 0 : -1;
return (0 == uart_send (DRIVER_DATA(pnd)->port, pn53x_ack_frame, sizeof (pn53x_ack_frame), 0)) ? 0 : -1;
}
bool
+2 -2
View File
@@ -33,8 +33,8 @@ bool pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len,
nfc_device *pn532_uart_connect (const nfc_connstring connstring);
void pn532_uart_disconnect (nfc_device * pnd);
bool pn532_uart_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout);
int pn532_uart_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szData, struct timeval *timeout);
bool pn532_uart_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, int timeout);
int pn532_uart_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szData, int timeout);
extern const struct nfc_driver_t pn532_uart_driver;
+16 -15
View File
@@ -121,11 +121,11 @@ bool pn53x_usb_get_usb_device_name (struct usb_device *dev, usb_dev_handle *udev
bool pn53x_usb_init (nfc_device *pnd);
int
pn53x_usb_bulk_read (struct pn53x_usb_data *data, uint8_t abtRx[], const size_t szRx, struct timeval *timeout)
pn53x_usb_bulk_read (struct pn53x_usb_data *data, uint8_t abtRx[], const size_t szRx, int timeout)
{
int timeout_ms = USB_INFINITE_TIMEOUT;
if (timeout) {
timeout_ms = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
if (timeout > 0) {
timeout_ms = timeout;
if (timeout_ms == USB_INFINITE_TIMEOUT) {
// timeout < 1 ms
timeout_ms++;
@@ -143,12 +143,12 @@ pn53x_usb_bulk_read (struct pn53x_usb_data *data, uint8_t abtRx[], const size_t
}
int
pn53x_usb_bulk_write (struct pn53x_usb_data *data, uint8_t abtTx[], const size_t szTx, struct timeval *timeout)
pn53x_usb_bulk_write (struct pn53x_usb_data *data, uint8_t abtTx[], const size_t szTx, int timeout)
{
LOG_HEX ("TX", abtTx, szTx);
int timeout_ms = USB_INFINITE_TIMEOUT;
if (timeout)
timeout_ms = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
if (timeout > 0)
timeout_ms = timeout;
int res = usb_bulk_write (data->pudh, data->uiEndPointOut, (char *) abtTx, szTx, timeout_ms);
if (res > 0) {
@@ -519,7 +519,7 @@ pn53x_usb_disconnect (nfc_device * pnd)
#define PN53X_USB_BUFFER_LEN (PN53x_EXTENDED_FRAME__DATA_MAX_LEN + PN53x_EXTENDED_FRAME__OVERHEAD)
bool
pn53x_usb_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout)
pn53x_usb_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, int timeout)
{
uint8_t abtFrame[PN53X_USB_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
size_t szFrame = 0;
@@ -565,7 +565,7 @@ pn53x_usb_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData,
}
int
pn53x_usb_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szDataLen, struct timeval *timeout)
pn53x_usb_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szDataLen, int timeout)
{
size_t len;
off_t offset = 0;
@@ -583,11 +583,12 @@ pn53x_usb_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szDataLen,
};
struct timeval remaining_time, usb_timeout;
if (timeout) {
remaining_time = *timeout;
if (timeout > 0) {
remaining_time.tv_sec = (timeout / 1000);
remaining_time.tv_usec = ((timeout % 1000) * 1000);
}
read:
if (timeout) {
if (timeout > 0) {
// A user-provided timeout is set, we have to cut it in multiple chunk to be able to keep an nfc_abort_command() mecanism
struct timeval tmp;
if (1 == timeval_subtract (&tmp, &remaining_time, &fixed_timeout)) {
@@ -607,7 +608,7 @@ read:
pnd->iLastError = ECOMTIMEOUT;
return -1;
}
res = pn53x_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf), &usb_timeout);
res = pn53x_usb_bulk_read (DRIVER_DATA (pnd), abtRxBuf, sizeof (abtRxBuf), ((usb_timeout.tv_sec * 1000) + (usb_timeout.tv_usec / 1000)));
if (res == -USB_TIMEDOUT) {
if (DRIVER_DATA (pnd)->abort_flag) {
@@ -717,7 +718,7 @@ read:
int
pn53x_usb_ack (nfc_device * pnd)
{
return pn53x_usb_bulk_write (DRIVER_DATA (pnd), (uint8_t *) pn53x_ack_frame, sizeof (pn53x_ack_frame), NULL);
return pn53x_usb_bulk_write (DRIVER_DATA (pnd), (uint8_t *) pn53x_ack_frame, sizeof (pn53x_ack_frame), 0);
}
bool
@@ -726,13 +727,13 @@ pn53x_usb_init (nfc_device *pnd)
// Sometimes PN53x USB doesn't reply ACK one the first frame, so we need to send a dummy one...
//pn53x_check_communication (pnd); // Sony RC-S360 doesn't support this command for now so let's use a get_firmware_version instead:
const uint8_t abtCmd[] = { GetFirmwareVersion };
pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, NULL);
pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, 0);
// ...and we don't care about error
pnd->iLastError = 0;
if (SONY_RCS360 == DRIVER_DATA (pnd)->model) {
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "SONY RC-S360 initialization.");
const uint8_t abtCmd2[] = { 0x18, 0x01 };
pn53x_transceive (pnd, abtCmd2, sizeof (abtCmd2), NULL, NULL, NULL);
pn53x_transceive (pnd, abtCmd2, sizeof (abtCmd2), NULL, NULL, 0);
pn53x_usb_ack (pnd);
}
+2 -2
View File
@@ -31,8 +31,8 @@
bool pn53x_usb_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound);
nfc_device *pn53x_usb_connect (const nfc_connstring connstring);
bool pn53x_usb_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, struct timeval *timeout);
int pn53x_usb_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szData, struct timeval *timeout);
bool pn53x_usb_send (nfc_device * pnd, const uint8_t * pbtData, const size_t szData, int timeout);
int pn53x_usb_receive (nfc_device * pnd, uint8_t * pbtData, const size_t szData, int timeout);
void pn53x_usb_disconnect (nfc_device * pnd);
extern const struct nfc_driver_t pn53x_usb_driver;