Error out on uart_send_single if any byte fails tx

This commit is contained in:
Samy Kamkar 2021-01-18 11:41:48 -08:00
parent c8cf4b924e
commit 4c50adc0eb
2 changed files with 33 additions and 25 deletions

View File

@ -237,7 +237,7 @@ uart_send(serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout)
}
if (!dwTxLen)
return NFC_EIO;
return 0;
return NFC_SUCCESS;
}
/**
@ -249,17 +249,21 @@ int
uart_send_single(serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout)
{
(void) timeout;
int error = 0;
int ret;
for (int i = 0; i < szTx; i++)
{
error |= uart_send(sp, pbtTx+i, 1, timeout);
ret = uart_send(sp, pbtTx+i, 1, timeout);
// if we didn't transmit byte, bail out
if (ret != NFC_SUCCESS)
return ret;
delay_ms(1); // ceil(1_000_000us / 115200baud) = 9us but no usleep on windows
}
return error ? NFC_EIO : 0;
return NFC_SUCCESS;
}
BOOL is_port_available(int nPort)
{
TCHAR szPort[15];

View File

@ -384,26 +384,6 @@ select:
return NFC_SUCCESS;
}
/**
* @brief Send \a pbtTx content to UART one byte at a time
*
* @return 0 on success, otherwise a driver error is returned
*/
int
uart_send_single(serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout)
{
(void) timeout;
int error = 0;
for (int i = 0; i < szTx; i++)
{
error |= uart_send(sp, pbtTx+i, 1, timeout);
usleep(9);
}
return error ? NFC_EIO : NFC_SUCCESS;
}
/**
* @brief Send \a pbtTx content to UART
*
@ -420,6 +400,30 @@ uart_send(serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout)
return NFC_EIO;
}
/**
* @brief Send \a pbtTx content to UART one byte at a time
*
* @return 0 on success, otherwise a driver error is returned
*/
int
uart_send_single(serial_port sp, const uint8_t *pbtTx, const size_t szTx, int timeout)
{
(void) timeout;
int ret;
for (int i = 0; i < szTx; i++)
{
ret = uart_send(sp, pbtTx+i, 1, timeout);
// if we didn't transmit byte, bail out
if (ret != NFC_SUCCESS)
return ret;
usleep(9); // sleep for ceil(1_000_000us / 115200baud) = 9us
}
return NFC_SUCCESS;
}
char **
uart_list_ports(void)
{