Merge r520-546 from trunk.
This commit is contained in:
commit
769eef20f7
16 changed files with 291 additions and 278 deletions
|
|
@ -84,21 +84,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; iDevice<DRIVERS_MAX_DEVICES; iDevice++)
|
||||
{
|
||||
#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);
|
||||
const char* pcPorts[] = DEFAULT_SERIAL_PORTS;
|
||||
const char* pcPort;
|
||||
int iDevice = 0;
|
||||
|
||||
while( pcPort = pcPorts[iDevice++] ) {
|
||||
sp = uart_open(pcPort);
|
||||
DBG("Trying to find PN532 device on serial port: %s at %d bauds.", pcPort, SERIAL_DEFAULT_PORT_SPEED);
|
||||
|
||||
if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT))
|
||||
{
|
||||
|
|
@ -114,11 +106,10 @@ pn532_uart_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_
|
|||
continue;
|
||||
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].pcDriver = PN532_UART_DRIVER_NAME;
|
||||
pnddDevices[*pszDeviceFound].pcPort = strdup(acPort);
|
||||
pnddDevices[*pszDeviceFound].pcPort[BUFFER_LENGTH] = '\0';
|
||||
pnddDevices[*pszDeviceFound].pcPort = strdup(pcPort);
|
||||
pnddDevices[*pszDeviceFound].uiSpeed = SERIAL_DEFAULT_PORT_SPEED;
|
||||
DBG("Device found: %s.", pnddDevices[*pszDeviceFound].acDevice);
|
||||
(*pszDeviceFound)++;
|
||||
|
|
@ -127,8 +118,8 @@ pn532_uart_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_
|
|||
if((*pszDeviceFound) >= 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 */
|
||||
|
|
@ -141,19 +132,15 @@ nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd)
|
|||
nfc_device_t* pnd = NULL;
|
||||
bool bComOk;
|
||||
|
||||
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);
|
||||
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)
|
||||
|
|
@ -240,7 +227,7 @@ bool pn532_uart_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t
|
|||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
PRINT_HEX("RX", abtRxBuf,szRxBufLen);
|
||||
PRINT_HEX("RX", abtRxBuf,szRxBufLen);
|
||||
#endif
|
||||
|
||||
// When the answer should be ignored, just return a successful result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue