diff --git a/libnfc/buses/uart.c b/libnfc/buses/uart.c index 0f6ecec..1b835e2 100644 --- a/libnfc/buses/uart.c +++ b/libnfc/buses/uart.c @@ -368,9 +368,8 @@ void uart_close(const serial_port sp) free(sp); } -void uart_set_speed(nfc_device_t* pnd, const uint32_t uiPortSpeed) +void uart_set_speed(serial_port sp, const uint32_t uiPortSpeed) { - serial_port sp = (serial_port)pnd->nds; serial_port_windows* spw; DBG("Serial port speed requested to be set to %d bauds.", uiPortSpeed); @@ -396,9 +395,8 @@ void uart_set_speed(nfc_device_t* pnd, const uint32_t uiPortSpeed) } } -uint32_t uart_get_speed(const nfc_device_t* pnd) +uint32_t uart_get_speed(const serial_port sp) { - serial_port sp = (serial_port)pnd->nds; const serial_port_windows* spw = (serial_port_windows*)sp; if (!GetCommState(spw->hPort, (serial_port)&spw->dcb)) return spw->dcb.BaudRate; @@ -406,25 +404,25 @@ uint32_t uart_get_speed(const nfc_device_t* pnd) return 0; } -bool uart_receive(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxLen) +int uart_receive(serial_port sp, byte_t* pbtRx, size_t* pszRxLen) { - serial_port sp = (serial_port)pnd->nds; if (!ReadFile(((serial_port_windows*)sp)->hPort,pbtRx,*pszRxLen,(LPDWORD)pszRxLen,NULL)) { - pnd->iLastError = DEIO; - return false; + return DEIO; } - return (*pszRxLen != 0); + if (!*pszRxLen) + return DEIO; + return 0; } -bool uart_send(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen) +int uart_send(serial_port sp, const byte_t* pbtTx, const size_t szTxLen) { - serial_port sp = (serial_port)pnd->nds; DWORD dwTxLen = 0; if (!WriteFile(((serial_port_windows*)sp)->hPort,pbtTx,szTxLen,&dwTxLen,NULL)) { - pnd->iLastError = DEIO; - return false; + return DEIO; } - return (dwTxLen != 0); + if (!dwTxLen) + return DEIO; + return 0; } #endif /* _WIN32 */ diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 2bef198..d6b18de 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -177,6 +177,7 @@ bool pn532_uart_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t byte_t abtRxBuf[BUFFER_LENGTH]; size_t szRxBufLen = BUFFER_LENGTH; size_t szPos; + int res; // TODO: Move this one level up for libnfc-1.6 uint8_t ack_frame[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00 }; @@ -200,7 +201,6 @@ bool pn532_uart_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t #ifdef DEBUG PRINT_HEX("TX", abtTxBuf,szTxLen+7); #endif - int res; res = uart_send((serial_port)pnd->nds,abtTxBuf,szTxLen+7); if(res != 0) { ERR("%s", "Unable to transmit data. (TX)");