From 7788c33da8683555953bd21a472d6e041940aaa4 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Tue, 17 Aug 2010 13:29:01 +0000 Subject: [PATCH] Default serial-port paths are now fully hardcoded instead of half-hardcoded and soft-expanded. --- libnfc/buses/uart.h | 14 ++++++------ libnfc/drivers/arygon.c | 43 +++++++++++++---------------------- libnfc/drivers/pn532_uart.c | 45 +++++++++++++------------------------ 3 files changed, 38 insertions(+), 64 deletions(-) diff --git a/libnfc/buses/uart.h b/libnfc/buses/uart.h index 8b0ea8a..8ec4978 100644 --- a/libnfc/buses/uart.h +++ b/libnfc/buses/uart.h @@ -59,16 +59,16 @@ // Try to guess what we should use. // // XXX: Some review from users cross-compiling is welcome! -#if defined(_WIN32) - #define SERIAL_STRING "COM" -//#elif defined(__APPLE__) -// TODO: find UART connection string for PN53X device on Mac OS X -// #define SERIAL_STRING "" +#if defined (_WIN32) + #define DEFAULT_SERIAL_PORTS { "COM1", "COM2", "COM3", "COM4", NULL } +#elif defined(__APPLE__) + // XXX: find UART connection string for PN53X device on Mac OS X when multiples devices are used + #define DEFAULT_SERIAL_PORTS { "/dev/tty.SLAB_USBtoUART", NULL } #elif defined (__FreeBSD__) || defined (__OpenBSD__) // XXX: Not tested - #define SERIAL_STRING "/dev/cuau" + #define DEFAULT_SERIAL_PORTS { "/dev/cuau0", "/dev/cuau1", "/dev/cuau2", "/dev/cuau3", NULL } #elif defined (__linux__) - #define SERIAL_STRING "/dev/ttyUSB" + #define DEFAULT_SERIAL_PORTS { "/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB2", "/dev/ttyUSB3", "/dev/tty0", "/dev/tty1", "/dev/tty2", "/dev/tty3", NULL } #else #error "Can't determine serial string for your system" #endif diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index 0ff9090..eeb1bf5 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -109,21 +109,13 @@ arygon_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *p *pszDeviceFound = 0; serial_port sp; - char acPort[BUFFER_LENGTH]; - int iDevice; + const char** pcPorts = UNIX_SERIAL_PORT_DEVS; + const char* pcPort; + int iDevice = 0; - // I have no idea how MAC OS X deals with multiple devices, so a quick workaround - for (iDevice=0; iDevice= szDevices) break; } #ifdef DEBUG - if (sp == INVALID_SERIAL_PORT) DBG("Invalid serial port: %s",acPort); - if (sp == CLAIMED_SERIAL_PORT) DBG("Serial port already claimed: %s",acPort); + if (sp == INVALID_SERIAL_PORT) DBG("Invalid serial port: %s", pcPort); + if (sp == CLAIMED_SERIAL_PORT) DBG("Serial port already claimed: %s", pcPort); #endif /* DEBUG */ } #endif /* SERIAL_AUTOPROBE_ENABLED */ @@ -157,19 +149,14 @@ nfc_device_t* arygon_connect(const nfc_device_desc_t* pndd) serial_port sp; nfc_device_t* pnd = NULL; - if( pndd == NULL ) { - DBG("%s", "arygon_connect() need an nfc_device_desc_t struct."); - return NULL; - } else { - DBG("Attempt to connect to: %s at %d bauds.",pndd->pcPort, pndd->uiSpeed); - sp = uart_open(pndd->pcPort); + DBG("Attempt to connect to: %s at %d bauds.",pndd->pcPort, pndd->uiSpeed); + sp = uart_open(pndd->pcPort); - if (sp == INVALID_SERIAL_PORT) ERR("Invalid serial port: %s",pndd->pcPort); - if (sp == CLAIMED_SERIAL_PORT) ERR("Serial port already claimed: %s",pndd->pcPort); - if ((sp == CLAIMED_SERIAL_PORT) || (sp == INVALID_SERIAL_PORT)) return NULL; + if (sp == INVALID_SERIAL_PORT) ERR("Invalid serial port: %s",pndd->pcPort); + if (sp == CLAIMED_SERIAL_PORT) ERR("Serial port already claimed: %s",pndd->pcPort); + if ((sp == CLAIMED_SERIAL_PORT) || (sp == INVALID_SERIAL_PORT)) return NULL; - uart_set_speed(sp, pndd->uiSpeed); - } + uart_set_speed(sp, pndd->uiSpeed); DBG("Successfully connected to: %s",pndd->pcPort); diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 6359bcd..a0c3833 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -83,21 +83,13 @@ pn532_uart_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_ *pszDeviceFound = 0; serial_port sp; - char acPort[BUFFER_LENGTH]; - int iDevice; - - // I have no idea how MAC OS X deals with multiple devices, so a quick workaround - for (iDevice=0; iDevicepcPort, pndd->uiSpeed); - sp = uart_open(pndd->pcPort); + DBG("Attempt to connect to: %s at %d bauds.",pndd->pcPort, pndd->uiSpeed); + sp = uart_open(pndd->pcPort); - if (sp == INVALID_SERIAL_PORT) ERR("Invalid serial port: %s",pndd->pcPort); - if (sp == CLAIMED_SERIAL_PORT) ERR("Serial port already claimed: %s",pndd->pcPort); - if ((sp == CLAIMED_SERIAL_PORT) || (sp == INVALID_SERIAL_PORT)) return NULL; + if (sp == INVALID_SERIAL_PORT) ERR("Invalid serial port: %s",pndd->pcPort); + if (sp == CLAIMED_SERIAL_PORT) ERR("Serial port already claimed: %s",pndd->pcPort); + if ((sp == CLAIMED_SERIAL_PORT) || (sp == INVALID_SERIAL_PORT)) return NULL; - uart_set_speed(sp, pndd->uiSpeed); - } + uart_set_speed(sp, pndd->uiSpeed); + // PN532 could be powered down, we need to wake it up before line testing. pn532_uart_wakeup((nfc_device_spec_t)sp); // Check communication using "Diagnose" command, with "Comunication test" (0x00)