From 88a4ae8043ea4debe4f359e70e4f2408d45694ba Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Mon, 5 Oct 2009 09:12:48 +0000 Subject: [PATCH] Code cleanup, it removes some warnings and should fix Issue 35. --- src/dev_pn531.c | 16 ++++++++-------- src/dev_pn533.c | 18 +++++++++--------- src/emulate.c | 2 +- src/initiator.c | 2 +- src/list.c | 2 +- src/rs232.c | 5 +++-- 6 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/dev_pn531.c b/src/dev_pn531.c index 646c6a6..cbc3924 100644 --- a/src/dev_pn531.c +++ b/src/dev_pn531.c @@ -173,8 +173,8 @@ bool dev_pn531_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t s { size_t uiPos = 0; int ret = 0; - char abtTx[BUFFER_LENGTH] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" - char abtRx[BUFFER_LENGTH]; + byte_t abtTx[BUFFER_LENGTH] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" + byte_t abtRx[BUFFER_LENGTH]; dev_spec_pn531* pdsp = (dev_spec_pn531*)ds; // Packet length = data length (len) + checksum (1) + end of stream marker (1) @@ -196,10 +196,10 @@ bool dev_pn531_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t s #ifdef DEBUG printf("Tx: "); - print_hex((byte_t*)abtTx,szTxLen+7); + print_hex(abtTx,szTxLen+7); #endif - ret = usb_bulk_write(pdsp->pudh, pdsp->uiEndPointOut, abtTx, szTxLen+7, USB_TIMEOUT); + ret = usb_bulk_write(pdsp->pudh, pdsp->uiEndPointOut, (char*)abtTx, szTxLen+7, USB_TIMEOUT); if( ret < 0 ) { #ifdef DEBUG @@ -208,7 +208,7 @@ bool dev_pn531_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t s return false; } - ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, abtRx, BUFFER_LENGTH, USB_TIMEOUT); + ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, (char*)abtRx, BUFFER_LENGTH, USB_TIMEOUT); if( ret < 0 ) { #ifdef DEBUG @@ -219,12 +219,12 @@ bool dev_pn531_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t s #ifdef DEBUG printf("Rx: "); - print_hex((byte_t*)abtRx,ret); + print_hex(abtRx,ret); #endif if( ret == 6 ) { - ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, abtRx, BUFFER_LENGTH, USB_TIMEOUT); + ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, (char*)abtRx, BUFFER_LENGTH, USB_TIMEOUT); if( ret < 0 ) { #ifdef DEBUG @@ -235,7 +235,7 @@ bool dev_pn531_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t s #ifdef DEBUG printf("Rx: "); - print_hex((byte_t*)abtRx,ret); + print_hex(abtRx,ret); #endif } diff --git a/src/dev_pn533.c b/src/dev_pn533.c index 04762e7..a16cd1e 100644 --- a/src/dev_pn533.c +++ b/src/dev_pn533.c @@ -168,8 +168,8 @@ bool dev_pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t s { size_t uiPos = 0; int ret = 0; - char abtTx[BUFFER_LENGTH] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" - char abtRx[BUFFER_LENGTH]; + byte_t abtTx[BUFFER_LENGTH] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" + byte_t abtRx[BUFFER_LENGTH]; dev_spec_pn533* pdsp = (dev_spec_pn533*)ds; // Packet length = data length (len) + checksum (1) + end of stream marker (1) @@ -191,10 +191,10 @@ bool dev_pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t s #ifdef DEBUG printf(" TX: "); - print_hex((byte_t*)abtTx,szTxLen+7); + print_hex(abtTx,szTxLen+7); #endif - ret = usb_bulk_write(pdsp->pudh, pdsp->uiEndPointOut, abtTx, szTxLen+7, USB_TIMEOUT); + ret = usb_bulk_write(pdsp->pudh, pdsp->uiEndPointOut, (char*)abtTx, szTxLen+7, USB_TIMEOUT); if( ret < 0 ) { #ifdef DEBUG @@ -203,7 +203,7 @@ bool dev_pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t s return false; } - ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, abtRx, BUFFER_LENGTH, USB_TIMEOUT); + ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, (char*)abtRx, BUFFER_LENGTH, USB_TIMEOUT); if( ret < 0 ) { #ifdef DEBUG @@ -214,12 +214,12 @@ bool dev_pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t s #ifdef DEBUG printf(" RX: "); - print_hex((byte_t*)abtRx,ret); + print_hex(abtRx,ret); #endif if( ret == 6 ) { - ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, abtRx, BUFFER_LENGTH, USB_TIMEOUT); + ret = usb_bulk_read(pdsp->pudh, pdsp->uiEndPointIn, (char*)abtRx, BUFFER_LENGTH, USB_TIMEOUT); if( ret < 0 ) { #ifdef DEBUG @@ -230,7 +230,7 @@ bool dev_pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t s #ifdef DEBUG printf(" RX: "); - print_hex((byte_t*)abtRx,ret); + print_hex(abtRx,ret); #endif } @@ -244,7 +244,7 @@ bool dev_pn533_transceive(const dev_spec ds, const byte_t* pbtTx, const size_t s *pszRxLen = ret - 7 - 2; // Get register: nuke extra byte (awful hack) - if ((abtRx[5]==(char)0xd5) && (abtRx[6]==(char)0x07) && (*pszRxLen==2)) { + if ((abtRx[5]==0xd5) && (abtRx[6]==0x07) && (*pszRxLen==2)) { // printf("Got %02x %02x, keep %02x\n", abtRx[7], abtRx[8], abtRx[8]); *pszRxLen = (*pszRxLen) - 1; memcpy( pbtRx, abtRx + 8, *pszRxLen); diff --git a/src/emulate.c b/src/emulate.c index be3989b..08ff640 100644 --- a/src/emulate.c +++ b/src/emulate.c @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) for(i= 0; i < 4; ++i) { memcpy(abtTmp,argv[arg]+i*2,2); - abtUidBcc[i]= (byte_t) strtol(abtTmp,NULL,16); + abtUidBcc[i]= (byte_t) strtol((char*)abtTmp,NULL,16); abtUidBcc[4] ^= abtUidBcc[i]; } } else { diff --git a/src/initiator.c b/src/initiator.c index 7e1f7cd..d1c5c41 100644 --- a/src/initiator.c +++ b/src/initiator.c @@ -22,7 +22,7 @@ int main(int argc, const char *argv[]) printf("Sending : %s\n", send); if (!nfc_initiator_transceive_dep_bytes(pdi, send, - strlen(send), abtRecv, + strlen((char*)send), abtRecv, &szRecvBits)) { printf("unable to send data\n"); return 1; diff --git a/src/list.c b/src/list.c index cbc7c37..34a12e4 100644 --- a/src/list.c +++ b/src/list.c @@ -92,7 +92,7 @@ int main(int argc, const char* argv[]) } // Poll for a ISO14443B tag - if (nfc_initiator_select_tag(pdi,IM_ISO14443B_106,"\x00",1,&ti)) + if (nfc_initiator_select_tag(pdi,IM_ISO14443B_106,(byte_t*)"\x00",1,&ti)) { printf("The following (NFC) ISO14443-B tag was found:\n\n"); printf(" ATQB: "); print_hex(ti.tib.abtAtqb,12); diff --git a/src/rs232.c b/src/rs232.c index 1091de9..f082eca 100644 --- a/src/rs232.c +++ b/src/rs232.c @@ -31,6 +31,7 @@ available: http://www.teuniz.net/RS-232/index.html // Test if we are dealing with unix operating systems #ifndef _WIN32 +#include typedef struct termios term_info; typedef struct { int fd; // Serial port file descriptor @@ -124,8 +125,8 @@ void rs232_set_speed(serial_port sp, const uint32_t uiPortSpeed) #endif }; const serial_port_unix* spu = (serial_port_unix*)sp; - cfsetispeed(&spu->tiNew, stPortSpeed); - cfsetospeed(&spu->tiNew, stPortSpeed); + cfsetispeed((struct termios*)&spu->tiNew, stPortSpeed); + cfsetospeed((struct termios*)&spu->tiNew, stPortSpeed); if( tcsetattr(spu->fd, TCSADRAIN, &spu->tiNew) == -1) { ERR("Unable to apply new speed settings.");