MERGE: libnfc-mingw-cross merge with trunk (r805-821)
This commit is contained in:
@@ -24,14 +24,14 @@ ADD_LIBRARY(nfc SHARED ${LIBRARY_SOURCES})
|
||||
TARGET_LINK_LIBRARIES(nfc ${LIBUSB_LIBRARIES} ${PCSC_LIBRARIES})
|
||||
SET_TARGET_PROPERTIES(nfc PROPERTIES SOVERSION 0)
|
||||
|
||||
IF(MSVC)
|
||||
IF(WIN32)
|
||||
# On Windows the shared (runtime) library should be either in the same
|
||||
# directory as the excutables or in the path, we add it to same directory
|
||||
INSTALL(TARGETS nfc RUNTIME DESTINATION bin COMPONENT libraries)
|
||||
|
||||
# At compile time we need the .LIB file, we place it in the lib directory
|
||||
INSTALL(TARGETS nfc ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT headers)
|
||||
ELSE(MSVC)
|
||||
ELSE(WIN32)
|
||||
INSTALL(TARGETS nfc LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries)
|
||||
ENDIF(MSVC)
|
||||
ENDIF(WIN32)
|
||||
|
||||
|
||||
+29
-10
@@ -104,11 +104,13 @@ uart_open (const char *pcPortName)
|
||||
}
|
||||
|
||||
// TODO Remove PN53x related timeout
|
||||
#define UART_TIMEOUT(X) ((X * 7) + 15000) // 1-byte duration (µs) * 6+1 bytes (ACK + 1 other chance) + 15 ms (PN532 Tmax to reply ACK)
|
||||
#define UART_TIMEOUT(X) ((X * 7) + 15000) // where X is 1-byte duration (µs): X * 6+1 bytes (PN53x's ACK + 1 other chance) + 15 ms (PN532 Tmax to reply ACK)
|
||||
// UART_SPEED_T0_TIME(X) convert baud rate to interval between 2 bytes (in us)
|
||||
#define UART_SPEED_T0_TIME(X) ((1000000 * 9)/ X) // 8,n,1 => 9 bits => data rate ~= bauds/9 (bytes/s); ex: 8N1@9600 ~= 1066 bytes/s
|
||||
void
|
||||
uart_set_speed (serial_port sp, const uint32_t uiPortSpeed)
|
||||
{
|
||||
long int iTimeout = UART_TIMEOUT(uiPortSpeed/9); // 8,n,1 => 9bits => ~ bauds/9
|
||||
long int iTimeout = UART_TIMEOUT(UART_SPEED_T0_TIME(uiPortSpeed));
|
||||
DBG ("Serial port speed requested to be set to %d bauds (%ld µs).", uiPortSpeed, iTimeout);
|
||||
const serial_port_unix *spu = (serial_port_unix *) sp;
|
||||
|
||||
@@ -351,11 +353,11 @@ uart_open (const char *pcPortName)
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
sp->ct.ReadIntervalTimeout = 0;
|
||||
sp->ct.ReadIntervalTimeout = 30;
|
||||
sp->ct.ReadTotalTimeoutMultiplier = 0;
|
||||
sp->ct.ReadTotalTimeoutConstant = 30;
|
||||
sp->ct.WriteTotalTimeoutMultiplier = 0;
|
||||
sp->ct.WriteTotalTimeoutConstant = 30;
|
||||
sp->ct.WriteTotalTimeoutMultiplier = 30;
|
||||
sp->ct.WriteTotalTimeoutConstant = 0;
|
||||
|
||||
if (!SetCommTimeouts (sp->hPort, &sp->ct)) {
|
||||
uart_close (sp);
|
||||
@@ -376,6 +378,7 @@ uart_close (const serial_port sp)
|
||||
free (sp);
|
||||
}
|
||||
|
||||
// TODO Remove PN53x related timeout
|
||||
void
|
||||
uart_set_speed (serial_port sp, const uint32_t uiPortSpeed)
|
||||
{
|
||||
@@ -393,16 +396,32 @@ uart_set_speed (serial_port sp, const uint32_t uiPortSpeed)
|
||||
case 460800:
|
||||
break;
|
||||
default:
|
||||
ERR
|
||||
("Unable to set serial port speed to %d bauds. Speed value must be one of these constants: 9600 (default), 19200, 38400, 57600, 115200, 230400 or 460800.",
|
||||
uiPortSpeed);
|
||||
ERR("Unable to set serial port speed to %d bauds. Speed value must be one of these constants: 9600 (default), 19200, 38400, 57600, 115200, 230400 or 460800.", uiPortSpeed);
|
||||
return;
|
||||
};
|
||||
|
||||
spw = (serial_port_windows *) sp;
|
||||
|
||||
// Set timeouts
|
||||
//printf ("UART_SPEED_T0_TIME (%d) = %d\n", uiPortSpeed, UART_SPEED_T0_TIME(uiPortSpeed));
|
||||
int iTimeout = 200;
|
||||
spw->ct.ReadIntervalTimeout = 2;
|
||||
spw->ct.ReadTotalTimeoutMultiplier = 0;
|
||||
spw->ct.ReadTotalTimeoutConstant = iTimeout;
|
||||
spw->ct.WriteTotalTimeoutMultiplier = iTimeout;
|
||||
spw->ct.WriteTotalTimeoutConstant = 0;
|
||||
|
||||
if (!SetCommTimeouts (spw->hPort, &spw->ct)) {
|
||||
ERR ("Unable to apply new timeout settings.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set baud rate
|
||||
spw->dcb.BaudRate = uiPortSpeed;
|
||||
if (!SetCommState (spw->hPort, &spw->dcb)) {
|
||||
ERR ("Unable to apply new speed settings.");
|
||||
return;
|
||||
}
|
||||
PurgeComm (spw->hPort, PURGE_RXABORT | PURGE_RXCLEAR);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
@@ -418,7 +437,7 @@ uart_get_speed (const serial_port sp)
|
||||
int
|
||||
uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRx)
|
||||
{
|
||||
if (!ReadFile (((serial_port_windows *) sp)->hPort, pbtRx, *pszRx, (LPDWORD) pszRx, NULL)) {
|
||||
if (!ReadFile (((serial_port_windows *) sp)->hPort, pbtRx, (DWORD)(*pszRx), (LPDWORD) pszRx, NULL)) {
|
||||
return DEIO;
|
||||
}
|
||||
if (!*pszRx)
|
||||
|
||||
@@ -39,10 +39,7 @@
|
||||
#include "../mirror-subr.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <windows.h>
|
||||
|
||||
# define strdup _strdup
|
||||
# define snprintf sprintf_s
|
||||
# include "../../contrib/windows.h"
|
||||
#endif
|
||||
|
||||
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||
|
||||
@@ -297,7 +297,7 @@ arygon_firmware (const nfc_device_spec_t nds, char * str)
|
||||
{
|
||||
const byte_t arygon_firmware_version_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'v' };
|
||||
byte_t abtRx[BUFFER_LENGTH];
|
||||
size_t szRx;
|
||||
size_t szRx = BUFFER_LENGTH;
|
||||
int res;
|
||||
|
||||
#ifdef DEBUG
|
||||
@@ -307,6 +307,7 @@ arygon_firmware (const nfc_device_spec_t nds, char * str)
|
||||
|
||||
res = uart_receive ((serial_port) nds, abtRx, &szRx);
|
||||
if (res != 0) {
|
||||
DBG ("Unable to retrieve ARYGON firmware version.");
|
||||
return;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
@@ -315,10 +316,9 @@ arygon_firmware (const nfc_device_spec_t nds, char * str)
|
||||
if ( 0 == memcmp (abtRx, arygon_error_none, 6)) {
|
||||
byte_t * p = abtRx + 6;
|
||||
unsigned int szData;
|
||||
sscanf (p, "%02x%s", &szData, p);
|
||||
sscanf ((const char*)p, "%02x%s", &szData, p);
|
||||
memcpy (str, p, szData);
|
||||
p += szData;
|
||||
*p = '\0';
|
||||
*(str + szData) = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ arygon_reset_tama (const nfc_device_spec_t nds)
|
||||
{
|
||||
const byte_t arygon_reset_tama_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'r' };
|
||||
byte_t abtRx[BUFFER_LENGTH];
|
||||
size_t szRx;
|
||||
size_t szRx = BUFFER_LENGTH;
|
||||
int res;
|
||||
|
||||
// Sometimes the first byte we send is not well-transmited (ie. a previously sent data on a wrong baud rate can put some junk in buffer)
|
||||
@@ -340,6 +340,7 @@ arygon_reset_tama (const nfc_device_spec_t nds)
|
||||
// or arygon_error_unknown_mode (ie. in case of the first byte was bad-transmitted)
|
||||
res = uart_receive ((serial_port) nds, abtRx, &szRx);
|
||||
if (res != 0) {
|
||||
DBG ("No reply to 'reset TAMA' command.");
|
||||
return false;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
|
||||
@@ -102,8 +102,6 @@ pn532_uart_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size
|
||||
bool bComOk;
|
||||
// Serial port claimed but we need to check if a PN532_UART is connected.
|
||||
uart_set_speed (sp, SERIAL_DEFAULT_PORT_SPEED);
|
||||
// Send ACK frame to cancel a previous command
|
||||
pn532_uart_ack ((nfc_device_spec_t) sp);
|
||||
// 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 "Communication test" (0x00)
|
||||
@@ -156,8 +154,6 @@ pn532_uart_connect (const nfc_device_desc_t * pndd)
|
||||
|
||||
uart_set_speed (sp, pndd->uiSpeed);
|
||||
|
||||
// Send ACK frame to cancel a previous command
|
||||
pn532_uart_ack ((nfc_device_spec_t) sp);
|
||||
// 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 "Communication test" (0x00)
|
||||
@@ -292,13 +288,14 @@ void
|
||||
pn532_uart_wakeup (const nfc_device_spec_t nds)
|
||||
{
|
||||
byte_t abtRx[BUFFER_LENGTH];
|
||||
size_t szRx;
|
||||
size_t szRx = BUFFER_LENGTH;
|
||||
/** PN532C106 wakeup. */
|
||||
/** High Speed Unit (HSU) wake up consist to send 0x55 and wait a "long" delay for PN532 being wakeup. */
|
||||
/** After the preamble we request the PN532C106 chip to switch to "normal" mode (SAM is not used) */
|
||||
const byte_t pncmd_pn532c106_wakeup_preamble[] =
|
||||
{ 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x03, 0xfd, 0xd4, 0x14, 0x01, 0x17, 0x00, 0x00, 0xff, 0x03, 0xfd,
|
||||
0xd4, 0x14, 0x01, 0x17, 0x00 };
|
||||
const byte_t pncmd_pn532c106_wakeup_preamble[] =
|
||||
{ 0x55, 0x55, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xff, 0x03, 0xfd, 0xd4, 0x14, 0x01, 0x17, // XXX: WTF this command is sent twice?
|
||||
0x00, 0x00, 0xff, 0x03, 0xfd, 0xd4, 0x14, 0x01, 0x17, 0x00 };
|
||||
#ifdef DEBUG
|
||||
PRINT_HEX ("TX", pncmd_pn532c106_wakeup_preamble, sizeof (pncmd_pn532c106_wakeup_preamble));
|
||||
#endif
|
||||
@@ -307,6 +304,8 @@ pn532_uart_wakeup (const nfc_device_spec_t nds)
|
||||
#ifdef DEBUG
|
||||
PRINT_HEX ("RX", abtRx, szRx);
|
||||
#endif
|
||||
} else {
|
||||
ERR ("Unable to wakeup the PN532.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,7 +313,7 @@ bool
|
||||
pn532_uart_check_communication (const nfc_device_spec_t nds, bool * success)
|
||||
{
|
||||
byte_t abtRx[BUFFER_LENGTH];
|
||||
size_t szRx;
|
||||
size_t szRx = BUFFER_LENGTH;
|
||||
const byte_t attempted_result[] =
|
||||
{ 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x09, 0xf7, 0xD5, 0x01, 0x00, 'l', 'i', 'b', 'n', 'f', 'c',
|
||||
0xbc, 0x00 };
|
||||
|
||||
+1
-3
@@ -35,9 +35,7 @@
|
||||
#include <nfc/nfc.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <windows.h>
|
||||
|
||||
# define snprintf sprintf_s
|
||||
# include "../contrib/windows.h"
|
||||
#endif
|
||||
|
||||
#include "chips.h"
|
||||
|
||||
Reference in New Issue
Block a user