From 8b2ca5da1c9dcde47988b3396c00aab0e4c7ddf5 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 27 May 2009 08:54:50 +0000 Subject: [PATCH] Use DEBUG define instead of _LIBNFC_VERBOSE_ to enable debug messages. Add --enable-debug option to ./configure --- configure.ac | 13 +++++++++++++ src/defines.h | 2 +- src/dev_acr122.c | 10 +++++----- src/dev_pn531.c | 22 +++++++++++----------- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index 73042c3..da0d2df 100644 --- a/configure.ac +++ b/configure.ac @@ -32,6 +32,19 @@ fi AC_SUBST(LIBPCSCLITE_LIBS) AC_SUBST(LIBPCSCLITE_CFLAGS) +# --enable-debug support +AC_ARG_ENABLE([debug],AS_HELP_STRING([--enable-debug],[Debug flags]),[enable_debug=$enableval],[enable_debug="no"]) + +AC_MSG_CHECKING(debug) +AC_MSG_RESULT($enable_debug) + +if test "x$enable_debug" = "xyes" +then + CFLAGS="$CFLAGS -g -Wall -DDEBUG" +fi +AC_SUBST([DEBUG_CFLAGS]) + + AC_CONFIG_FILES([ Makefile src/Makefile diff --git a/src/defines.h b/src/defines.h index 6ec18e2..2c63865 100644 --- a/src/defines.h +++ b/src/defines.h @@ -21,7 +21,7 @@ along with this program. If not, see . #ifndef _LIBNFC_DEFINES_H_ #define _LIBNFC_DEFINES_H_ -// #define _LIBNFC_VERBOSE_ +// #define DEBUG typedef unsigned char byte; typedef unsigned char ui8; diff --git a/src/dev_acr122.c b/src/dev_acr122.c index b8bb640..cb2495a 100644 --- a/src/dev_acr122.c +++ b/src/dev_acr122.c @@ -80,7 +80,7 @@ dev_info* dev_acr122_connect(const ui32 uiIndex) // Retrieve the string array of all available pcsc readers if (SCardListReaders(dsa.hCtx,null,acList,(void*)&ulListLen) != SCARD_S_SUCCESS) return INVALID_DEVICE_INFO; - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Found the following PCSC device(s)\n"); printf("- %s\n",acList); #endif @@ -105,7 +105,7 @@ dev_info* dev_acr122_connect(const ui32 uiIndex) uiReaderCount++; // Debug info - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("- %s\n",acList+uiPos+1); #endif } @@ -185,7 +185,7 @@ bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTx // Prepare and transmit the send buffer memcpy(abtTxBuf+5,pbtTx,uiTxLen); ulRxBufLen = sizeof(abtRxBuf); - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Tx: "); print_hex(abtTxBuf,uiTxLen+5); #endif @@ -211,7 +211,7 @@ bool dev_acr122_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTx if (SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtRxCmd,uiRxCmdLen,null,abtRxBuf,(void*)&ulRxBufLen) != SCARD_S_SUCCESS) return false; } - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Rx: "); print_hex(abtRxBuf,ulRxBufLen); #endif @@ -244,7 +244,7 @@ char* dev_acr122_firmware(const dev_spec ds) uiResult = SCardTransmit(pdsa->hCard,&(pdsa->ioCard),abtGetFw,sizeof(abtGetFw),null,(byte*)abtFw,(void*)&ulFwLen); } - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG if (uiResult != SCARD_S_SUCCESS) { printf("No ACR122 firmware received, Error: %08x\n",uiResult); diff --git a/src/dev_pn531.c b/src/dev_pn531.c index 0a8a1b8..a6d3bd0 100644 --- a/src/dev_pn531.c +++ b/src/dev_pn531.c @@ -57,7 +57,7 @@ void get_end_points(struct usb_device *dev, dev_spec_pn531* pdsp) // Test if we dealing with a bulk IN endpoint if((uiEndPoint & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_IN) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Bulk endpoint in : 0x%02X\n", uiEndPoint); #endif pdsp->uiEndPointIn = uiEndPoint; @@ -66,7 +66,7 @@ void get_end_points(struct usb_device *dev, dev_spec_pn531* pdsp) // Test if we dealing with a bulk OUT endpoint if((uiEndPoint & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_OUT) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Bulk endpoint in : 0x%02X\n", uiEndPoint); #endif pdsp->uiEndPointOut = uiEndPoint; @@ -112,7 +112,7 @@ dev_info* dev_pn531_connect(const ui32 uiIndex) uiDevIndex--; continue; } - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Found PN531 device\n"); #endif @@ -122,7 +122,7 @@ dev_info* dev_pn531_connect(const ui32 uiIndex) get_end_points(dev,&dsp); if(usb_set_configuration(dsp.pudh,1) < 0) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Setting config failed\n"); #endif usb_close(dsp.pudh); @@ -131,7 +131,7 @@ dev_info* dev_pn531_connect(const ui32 uiIndex) if(usb_claim_interface(dsp.pudh,0) < 0) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Can't claim interface\n"); #endif usb_close(dsp.pudh); @@ -188,7 +188,7 @@ bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxL // End of stream marker buffer[uiTxLen+6] = 0; - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Tx: "); print_hex((byte*)buffer,uiTxLen+7); #endif @@ -196,7 +196,7 @@ bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxL ret = usb_bulk_write(pdsp->pudh, pdsp->uiEndPointOut, buffer, uiTxLen+7, USB_TIMEOUT); if( ret < 0 ) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("usb_bulk_write failed with error %d\n", ret); #endif return false; @@ -205,13 +205,13 @@ bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxL ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, buf, BUFFER_LENGTH, USB_TIMEOUT); if( ret < 0 ) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf( "usb_bulk_read failed with error %d\n", ret); #endif return false; } - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Rx: "); print_hex((byte*)buf,ret); #endif @@ -221,13 +221,13 @@ bool dev_pn531_transceive(const dev_spec ds, const byte* pbtTx, const ui32 uiTxL ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, buf, BUFFER_LENGTH, USB_TIMEOUT); if( ret < 0 ) { - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("usb_bulk_read failed with error %d\n", ret); #endif return false; } - #ifdef _LIBNFC_VERBOSE_ + #ifdef DEBUG printf("Rx: "); print_hex((byte*)buf,ret); #endif