Hi,
Windows API has a select() function (http://msdn.microsoft.com/en-us/library
85%29.aspx), but there is no sys/select.h .
So it is possible to get it to compile using a conditional include. I am not able to test if it is actually working however, since i currently have only an ACR122 reader which does not use the pn53x_usb driver afaik.
I am waiting for an ASK Logo reader to be delivered, so i can test this. It would be good if someone could test this in the mean time ..
Following patch against current trunk fixes the above, and some other problems i had when compiling on windows.
The cmake script is also modified so that the nfc-mfclassic nfc-mfultralight examples are build now (as requested in another thread)
Index: contrib/win32/err.h
===================================================================
--- contrib/win32/err.h (revision 967)
+++ contrib/win32/err.h (working copy)
@@ -14,6 +14,6 @@
exit (code); \
} while (0)
-#define err(code, ...) errx(code, ...)
+#define err errx
#endif /* !_ERR_H_ */
Index: contrib/windows.h
===================================================================
--- contrib/windows.h (revision 967)
+++ contrib/windows.h (working copy)
@@ -27,11 +27,14 @@
#define __WINDOWS_H__
# include <windows.h>
+# include <winerror.h>
+# include "win32/err.h"
# if defined (__MINGW32__)
# define snprintf(S, n, F, ...) sprintf(S, F, __VA_ARGS__)
# define MAX(a,b) max(a,b)
# define MIN(a,b) min(a,b)
# define pipe(fds) _pipe(fds, 5000, _O_BINARY)
+# define ETIMEDOUT WSAETIMEDOUT
# else
# define snprintf sprintf_s
# define strdup _strdup
Index: examples/CMakeLists.txt
===================================================================
--- examples/CMakeLists.txt (revision 967)
+++ examples/CMakeLists.txt (working copy)
@@ -1,5 +1,5 @@
-SET(EXAMPLES-SOURCES nfc-anticol nfc-dep-initiator nfc-dep-target nfc-emulate-forum-tag4 nfc-emulate-tag nfc-emulate-uid nfc-list nfc-poll nfc-relay nfc-relay-picc)
-#TODO nfc-mfclassic nfc-mfultralight pn53x-diagnose pn53x-sam pn53x-tamashell
+SET(EXAMPLES-SOURCES nfc-anticol nfc-dep-initiator nfc-dep-target nfc-emulate-forum-tag4 nfc-emulate-tag nfc-emulate-uid nfc-list nfc-poll nfc-relay nfc-relay-picc nfc-mfclassic nfc-mfultralight)
+#TODO pn53x-diagnose pn53x-sam pn53x-tamashell
# XXX: Examples should not use private API!
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../libnfc)
@@ -8,19 +8,19 @@
LINK_DIRECTORIES(${LIBUSB_LIBRARY_DIRS} ${PCSC_LIBRARY_DIRS})
ADD_LIBRARY(nfc-utils nfc-utils)
-#ADD_LIBRARY(mifare mifare)
# Examples
FOREACH(source ${EXAMPLES-SOURCES})
- ADD_EXECUTABLE(${source} ${source}.c)
+ IF((${source} MATCHES "nfc-mfultralight") OR (${source} MATCHES "nfc-mfclassic"))
+ ADD_EXECUTABLE(${source} ${source}.c mifare)
+ ELSE()
+ ADD_EXECUTABLE(${source} ${source}.c)
+ ENDIF((${source} MATCHES "nfc-mfultralight") OR (${source} MATCHES "nfc-mfclassic"))
TARGET_LINK_LIBRARIES(${source} nfc)
TARGET_LINK_LIBRARIES(${source} nfc-utils)
INSTALL(TARGETS ${source} RUNTIME DESTINATION bin COMPONENT examples)
ENDFOREACH(source)
-#TARGET_LINK_LIBRARIES(nfc-mfclassic mifare)
-#TARGET_LINK_LIBRARIES(nfc-mfultralight mifare)
-
IF(NOT WIN32)
# Manuals for the examples
FILE(GLOB manuals "${CMAKE_CURRENT_SOURCE_DIR}/*.1")
Index: examples/nfc-emulate-forum-tag4.c
===================================================================
--- examples/nfc-emulate-forum-tag4.c (revision 967)
+++ examples/nfc-emulate-forum-tag4.c (working copy)
@@ -59,6 +59,10 @@
#include "nfc-utils.h"
+#ifdef _WIN32
+# include "contrib/windows.h"
+# define ENOTSUP 134
+#endif
static nfc_device_t *pnd;
static bool quiet_output = false;
Index: include/nfc/nfc-emulation.h
===================================================================
--- include/nfc/nfc-emulation.h (revision 967)
+++ include/nfc/nfc-emulation.h (working copy)
@@ -22,6 +22,29 @@
#include <sys/types.h>
+# ifdef _WIN32
+ /* Windows platform */
+# ifndef _WINDLL
+ /* CMake compilation */
+# ifdef nfc_EXPORTS
+# define NFC_EXPORT __declspec(dllexport)
+# else
+ /* nfc_EXPORTS */
+# define NFC_EXPORT __declspec(dllimport)
+# endif
+ /* nfc_EXPORTS */
+# else
+ /* _WINDLL */
+ /* Manual makefile */
+# define NFC_EXPORT
+# endif
+ /* _WINDLL */
+# else
+ /* _WIN32 */
+# define NFC_EXPORT
+# endif
+ /* _WIN32 */
+
struct nfc_emulator;
struct nfc_emulation_state_machine;
@@ -37,6 +60,6 @@
void *data;
};
-int nfc_emulate_target (nfc_device_t* pnd, struct nfc_emulator *emulator);
+NFC_EXPORT int nfc_emulate_target (nfc_device_t* pnd, struct nfc_emulator *emulator);
#endif /* __NFC_EMULATION_H__ */
Index: libnfc/buses/uart_win32.c
===================================================================
--- libnfc/buses/uart_win32.c (revision 967)
+++ libnfc/buses/uart_win32.c (working copy)
@@ -149,7 +149,7 @@
if (!ReadFile (((serial_port_windows *) sp)->hPort, pbtRx, dwRxLen, &dwRxLen, NULL)) {
return DEIO;
}
- return (dwRwLen == (DWORD) szRx) ? 0 : DEIO;
+ return (dwRxLen == (DWORD) szRx) ? 0 : DEIO;
}
int
Index: libnfc/CMakeLists.txt
===================================================================
--- libnfc/CMakeLists.txt (revision 967)
+++ libnfc/CMakeLists.txt (working copy)
@@ -22,6 +22,9 @@
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
ADD_LIBRARY(nfc SHARED ${LIBRARY_SOURCES})
TARGET_LINK_LIBRARIES(nfc ${LIBUSB_LIBRARIES} ${PCSC_LIBRARIES})
+IF(WIN32)
+ TARGET_LINK_LIBRARIES(nfc wsock32)
+ENDIF(WIN32)
SET_TARGET_PROPERTIES(nfc PROPERTIES SOVERSION 0)
IF(WIN32)
Index: libnfc/drivers/pn53x_usb.c
===================================================================
--- libnfc/drivers/pn53x_usb.c (revision 967)
+++ libnfc/drivers/pn53x_usb.c (working copy)
@@ -32,7 +32,12 @@
Thanks to d18c7db and Okko for example code
*/
-#include <sys/select.h>
+#ifdef _WIN32
+# include "contrib/windows.h"
+#else
+# include <sys/select.h>
+#endif
+
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
Index: libnfc/nfc-device.c
===================================================================
--- libnfc/nfc-device.c (revision 967)
+++ libnfc/nfc-device.c (working copy)
@@ -26,6 +26,10 @@
#include <stdlib.h>
+#ifdef _WIN32
+# include "contrib/windows.h"
+#endif
+
#include "nfc-internal.h"
nfc_device_t *
Last edited by glenn (2011-03-31 10:00:36)