Default serial-port paths are now fully hardcoded instead of half-hardcoded and soft-expanded.

This commit is contained in:
Romuald Conty 2010-08-17 13:29:01 +00:00
parent 476c05cfb4
commit 7788c33da8
3 changed files with 38 additions and 64 deletions

View file

@ -59,16 +59,16 @@
// Try to guess what we should use. // Try to guess what we should use.
// //
// XXX: Some review from users cross-compiling is welcome! // XXX: Some review from users cross-compiling is welcome!
#if defined(_WIN32) #if defined (_WIN32)
#define SERIAL_STRING "COM" #define DEFAULT_SERIAL_PORTS { "COM1", "COM2", "COM3", "COM4", NULL }
//#elif defined(__APPLE__) #elif defined(__APPLE__)
// TODO: find UART connection string for PN53X device on Mac OS X // XXX: find UART connection string for PN53X device on Mac OS X when multiples devices are used
// #define SERIAL_STRING "" #define DEFAULT_SERIAL_PORTS { "/dev/tty.SLAB_USBtoUART", NULL }
#elif defined (__FreeBSD__) || defined (__OpenBSD__) #elif defined (__FreeBSD__) || defined (__OpenBSD__)
// XXX: Not tested // XXX: Not tested
#define SERIAL_STRING "/dev/cuau" #define DEFAULT_SERIAL_PORTS { "/dev/cuau0", "/dev/cuau1", "/dev/cuau2", "/dev/cuau3", NULL }
#elif defined (__linux__) #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 #else
#error "Can't determine serial string for your system" #error "Can't determine serial string for your system"
#endif #endif

View file

@ -109,21 +109,13 @@ arygon_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *p
*pszDeviceFound = 0; *pszDeviceFound = 0;
serial_port sp; serial_port sp;
char acPort[BUFFER_LENGTH]; const char** pcPorts = UNIX_SERIAL_PORT_DEVS;
int iDevice; const char* pcPort;
int iDevice = 0;
// I have no idea how MAC OS X deals with multiple devices, so a quick workaround while( pcPort = pcPorts[i++] ) {
for (iDevice=0; iDevice<DRIVERS_MAX_DEVICES; iDevice++) sp = uart_open(pcPort);
{ DBG("Trying to find ARYGON device on serial port: %s at %d bauds.", pcPort, SERIAL_DEFAULT_PORT_SPEED);
#ifdef __APPLE__
strncpy(acPort, SERIAL_STRING, BUFFER_LENGTH - 1);
acPort[BUFFER_LENGTH - 1] = '\0';
#else /* __APPLE__ */
snprintf(acPort, BUFFER_LENGTH - 1, "%s%d", SERIAL_STRING, iDevice);
acPort[BUFFER_LENGTH - 1] = '\0';
#endif /* __APPLE__ */
sp = uart_open(acPort);
DBG("Trying to find ARYGON device on serial port: %s at %d bauds.",acPort, SERIAL_DEFAULT_PORT_SPEED);
if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT)) if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT))
{ {
@ -135,7 +127,7 @@ arygon_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *p
snprintf(pnddDevices[*pszDeviceFound].acDevice, DEVICE_NAME_LENGTH - 1, "%s (%s)", "ARYGON", acPort); snprintf(pnddDevices[*pszDeviceFound].acDevice, DEVICE_NAME_LENGTH - 1, "%s (%s)", "ARYGON", acPort);
pnddDevices[*pszDeviceFound].acDevice[DEVICE_NAME_LENGTH - 1] = '\0'; pnddDevices[*pszDeviceFound].acDevice[DEVICE_NAME_LENGTH - 1] = '\0';
pnddDevices[*pszDeviceFound].pcDriver = ARYGON_DRIVER_NAME; pnddDevices[*pszDeviceFound].pcDriver = ARYGON_DRIVER_NAME;
pnddDevices[*pszDeviceFound].pcPort = strdup(acPort); pnddDevices[*pszDeviceFound].pcPort = strdup(pcPort);
pnddDevices[*pszDeviceFound].uiSpeed = SERIAL_DEFAULT_PORT_SPEED; pnddDevices[*pszDeviceFound].uiSpeed = SERIAL_DEFAULT_PORT_SPEED;
DBG("Device found: %s.", pnddDevices[*pszDeviceFound].acDevice); DBG("Device found: %s.", pnddDevices[*pszDeviceFound].acDevice);
(*pszDeviceFound)++; (*pszDeviceFound)++;
@ -144,8 +136,8 @@ arygon_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *p
if((*pszDeviceFound) >= szDevices) break; if((*pszDeviceFound) >= szDevices) break;
} }
#ifdef DEBUG #ifdef DEBUG
if (sp == INVALID_SERIAL_PORT) DBG("Invalid serial port: %s",acPort); if (sp == INVALID_SERIAL_PORT) DBG("Invalid serial port: %s", pcPort);
if (sp == CLAIMED_SERIAL_PORT) DBG("Serial port already claimed: %s",acPort); if (sp == CLAIMED_SERIAL_PORT) DBG("Serial port already claimed: %s", pcPort);
#endif /* DEBUG */ #endif /* DEBUG */
} }
#endif /* SERIAL_AUTOPROBE_ENABLED */ #endif /* SERIAL_AUTOPROBE_ENABLED */
@ -157,10 +149,6 @@ nfc_device_t* arygon_connect(const nfc_device_desc_t* pndd)
serial_port sp; serial_port sp;
nfc_device_t* pnd = NULL; 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); DBG("Attempt to connect to: %s at %d bauds.",pndd->pcPort, pndd->uiSpeed);
sp = uart_open(pndd->pcPort); sp = uart_open(pndd->pcPort);
@ -169,7 +157,6 @@ nfc_device_t* arygon_connect(const nfc_device_desc_t* pndd)
if ((sp == CLAIMED_SERIAL_PORT) || (sp == INVALID_SERIAL_PORT)) return NULL; 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); DBG("Successfully connected to: %s",pndd->pcPort);

View file

@ -83,21 +83,13 @@ pn532_uart_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_
*pszDeviceFound = 0; *pszDeviceFound = 0;
serial_port sp; serial_port sp;
char acPort[BUFFER_LENGTH]; const char** pcPorts = UNIX_SERIAL_PORT_DEVS;
int iDevice; const char* pcPort;
int iDevice = 0;
// I have no idea how MAC OS X deals with multiple devices, so a quick workaround while( pcPort = pcPorts[i++] ) {
for (iDevice=0; iDevice<DRIVERS_MAX_DEVICES; iDevice++) sp = uart_open(pcPort);
{ DBG("Trying to find PN532 device on serial port: %s at %d bauds.", pcPort, SERIAL_DEFAULT_PORT_SPEED);
#ifdef __APPLE__
strncpy(acPort,SERIAL_STRING, BUFFER_LENGTH - 1);
acPort[BUFFER_LENGTH - 1] = '\0';
#else /* __APPLE__ */
snprintf(acPort,BUFFER_LENGTH - 1,"%s%d",SERIAL_STRING,iDevice);
acPort[BUFFER_LENGTH - 1] = '\0';
#endif /* __APPLE__ */
sp = uart_open(acPort);
DBG("Trying to find PN532 device on serial port: %s at %d bauds.",acPort, SERIAL_DEFAULT_PORT_SPEED);
if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT)) if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT))
{ {
@ -109,11 +101,10 @@ pn532_uart_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_
if(!pn532_uart_check_communication((nfc_device_spec_t)sp)) continue; if(!pn532_uart_check_communication((nfc_device_spec_t)sp)) continue;
uart_close(sp); uart_close(sp);
snprintf(pnddDevices[*pszDeviceFound].acDevice, DEVICE_NAME_LENGTH - 1, "%s (%s)", "PN532", acPort); snprintf(pnddDevices[*pszDeviceFound].acDevice, DEVICE_NAME_LENGTH - 1, "%s (%s)", "PN532", pcPort);
pnddDevices[*pszDeviceFound].acDevice[DEVICE_NAME_LENGTH - 1] = '\0'; pnddDevices[*pszDeviceFound].acDevice[DEVICE_NAME_LENGTH - 1] = '\0';
pnddDevices[*pszDeviceFound].pcDriver = PN532_UART_DRIVER_NAME; pnddDevices[*pszDeviceFound].pcDriver = PN532_UART_DRIVER_NAME;
pnddDevices[*pszDeviceFound].pcPort = strdup(acPort); pnddDevices[*pszDeviceFound].pcPort = strdup(pcPort);
pnddDevices[*pszDeviceFound].pcPort[BUFFER_LENGTH] = '\0';
pnddDevices[*pszDeviceFound].uiSpeed = SERIAL_DEFAULT_PORT_SPEED; pnddDevices[*pszDeviceFound].uiSpeed = SERIAL_DEFAULT_PORT_SPEED;
DBG("Device found: %s.", pnddDevices[*pszDeviceFound].acDevice); DBG("Device found: %s.", pnddDevices[*pszDeviceFound].acDevice);
(*pszDeviceFound)++; (*pszDeviceFound)++;
@ -135,10 +126,6 @@ nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd)
serial_port sp; serial_port sp;
nfc_device_t* pnd = NULL; nfc_device_t* pnd = NULL;
if( pndd == NULL ) {
DBG("%s", "pn532_uart_connect() need an nfc_device_desc_t struct.");
return NULL;
} else {
DBG("Attempt to connect to: %s at %d bauds.",pndd->pcPort, pndd->uiSpeed); DBG("Attempt to connect to: %s at %d bauds.",pndd->pcPort, pndd->uiSpeed);
sp = uart_open(pndd->pcPort); sp = uart_open(pndd->pcPort);
@ -147,7 +134,7 @@ nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd)
if ((sp == CLAIMED_SERIAL_PORT) || (sp == INVALID_SERIAL_PORT)) return NULL; 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 could be powered down, we need to wake it up before line testing.
pn532_uart_wakeup((nfc_device_spec_t)sp); pn532_uart_wakeup((nfc_device_spec_t)sp);
// Check communication using "Diagnose" command, with "Comunication test" (0x00) // Check communication using "Diagnose" command, with "Comunication test" (0x00)