Make libnfc compile under Windows

Apply adapted patch from Glenn (Thanks!)
This commit is contained in:
Romuald Conty
2011-03-09 09:41:40 +00:00
parent 3fb4b0e0ee
commit 544030099e
5 changed files with 48 additions and 53 deletions

View File

@@ -35,29 +35,6 @@
# include <nfc/nfc-types.h>
// Handle platform specific includes
# ifndef _WIN32
# include <termios.h>
# include <sys/ioctl.h>
# include <unistd.h>
# include <fcntl.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <limits.h>
# include <sys/time.h>
# include <unistd.h>
# define delay_ms( X ) usleep( X * 1000 )
# else
# include "contrib/windows.h"
# define delay_ms( X ) Sleep( X )
# endif
// Path to the serial port is OS-dependant.
// Try to guess what we should use.
# if defined (_WIN32)
# define DEFAULT_SERIAL_PORTS { "COM1", "COM2", "COM3", "COM4", NULL }
# endif
// Define shortcut to types to make code more readable
typedef void *serial_port;
# define INVALID_SERIAL_PORT (void*)(~1)

View File

@@ -27,16 +27,23 @@
/* vim: set ts=2 sw=2 et: */
# include <sys/types.h>
# include <sys/select.h>
# include <sys/param.h>
# include <ctype.h>
# include <dirent.h>
# include <errno.h>
# include <stdio.h>
# include <termios.h>
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/types.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
# include "nfc-internal.h"
#include "nfc-internal.h"
# if defined(__APPLE__)
// FIXME: find UART connection string for PN53X device on Mac OS X when multiples devices are used

View File

@@ -19,10 +19,14 @@
*/
/**
* @file uart.c
* @file uart_win32.c
* @brief Windows UART driver
*/
// Handle platform specific includes
#include "contrib/windows.h"
#define delay_ms( X ) Sleep( X )
typedef struct {
HANDLE hPort; // Serial port handle
DCB dcb; // Device control settings
@@ -140,14 +144,14 @@ uart_get_speed (const serial_port sp)
}
int
uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRx)
uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, int iAbortFd)
{
if (!ReadFile (((serial_port_windows *) sp)->hPort, pbtRx, (DWORD)(*pszRx), (LPDWORD) pszRx, NULL)) {
// TODO: Implement abort mecanism (using iAbortFd)
DWORD dwRxLen = szRx;
if (!ReadFile (((serial_port_windows *) sp)->hPort, pbtRx, dwRxLen, &dwRxLen, NULL)) {
return DEIO;
}
if (!*pszRx)
return DEIO;
return 0;
return (dwRwLen == (DWORD) szRx) ? 0 : DEIO;
}
int
@@ -162,3 +166,15 @@ uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx)
return 0;
}
// Path to the serial port is OS-dependant.
// Try to guess what we should use.
#define DEFAULT_SERIAL_PORTS { "COM1", "COM2", "COM3", "COM4", NULL }
char **
uart_list_ports (void)
{
// TODO: Wrote an automatic detection of Windows serial ports
// FIXME: Construct an dynamic allocated array of char* that contains default serial ports.
const char ** availablePorts = DEFAULT_SERIAL_PORTS;
return availablePorts;
}