Fix build on Microsoft Windows (not tested, no hardware).

This commit is contained in:
Romain Tartiere 2010-08-19 18:19:40 +00:00
parent edba53c5da
commit 5744c67039
2 changed files with 13 additions and 15 deletions

View file

@ -368,9 +368,8 @@ void uart_close(const serial_port sp)
free(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; serial_port_windows* spw;
DBG("Serial port speed requested to be set to %d bauds.", uiPortSpeed); 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; const serial_port_windows* spw = (serial_port_windows*)sp;
if (!GetCommState(spw->hPort, (serial_port)&spw->dcb)) if (!GetCommState(spw->hPort, (serial_port)&spw->dcb))
return spw->dcb.BaudRate; return spw->dcb.BaudRate;
@ -406,25 +404,25 @@ uint32_t uart_get_speed(const nfc_device_t* pnd)
return 0; 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)) { if (!ReadFile(((serial_port_windows*)sp)->hPort,pbtRx,*pszRxLen,(LPDWORD)pszRxLen,NULL)) {
pnd->iLastError = DEIO; return DEIO;
return false;
} }
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; DWORD dwTxLen = 0;
if (!WriteFile(((serial_port_windows*)sp)->hPort,pbtTx,szTxLen,&dwTxLen,NULL)) { if (!WriteFile(((serial_port_windows*)sp)->hPort,pbtTx,szTxLen,&dwTxLen,NULL)) {
pnd->iLastError = DEIO; return DEIO;
return false;
} }
return (dwTxLen != 0); if (!dwTxLen)
return DEIO;
return 0;
} }
#endif /* _WIN32 */ #endif /* _WIN32 */

View file

@ -177,6 +177,7 @@ bool pn532_uart_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t
byte_t abtRxBuf[BUFFER_LENGTH]; byte_t abtRxBuf[BUFFER_LENGTH];
size_t szRxBufLen = BUFFER_LENGTH; size_t szRxBufLen = BUFFER_LENGTH;
size_t szPos; size_t szPos;
int res;
// TODO: Move this one level up for libnfc-1.6 // TODO: Move this one level up for libnfc-1.6
uint8_t ack_frame[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00 }; 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 #ifdef DEBUG
PRINT_HEX("TX", abtTxBuf,szTxLen+7); PRINT_HEX("TX", abtTxBuf,szTxLen+7);
#endif #endif
int res;
res = uart_send((serial_port)pnd->nds,abtTxBuf,szTxLen+7); res = uart_send((serial_port)pnd->nds,abtTxBuf,szTxLen+7);
if(res != 0) { if(res != 0) {
ERR("%s", "Unable to transmit data. (TX)"); ERR("%s", "Unable to transmit data. (TX)");