Attempt to provide an abort mecanism for windows users...

This commit is contained in:
Romuald Conty
2011-05-09 11:14:43 +00:00
parent 468027ba2b
commit 921d28d976
5 changed files with 55 additions and 15 deletions

View File

@@ -46,7 +46,7 @@ void uart_close (const serial_port sp);
void uart_set_speed (serial_port sp, const uint32_t uiPortSpeed);
uint32_t uart_get_speed (const serial_port sp);
int uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, int iAbortFd);
int uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p);
int uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx);
char **uart_list_ports (void);

View File

@@ -224,8 +224,9 @@ static const struct timeval tvTimeout = {
* @return 0 on success, otherwise driver error code
*/
int
uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, int iAbortFd)
uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p)
{
int iAbortFd = *((int*)abort_p);
struct timeval tv = tvTimeout;
struct timeval *ptv = &tv;
int received_bytes_count = 0;

View File

@@ -142,13 +142,16 @@ uart_get_speed (const serial_port sp)
}
int
uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, int iAbortFd)
uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p)
{
// TODO: Implement abort mecanism (using iAbortFd)
// TODO Test me with abort_p
volatile bool * abort_flag_p = (volatile bool *)abort_p;
DWORD dwRxLen = szRx;
if (!ReadFile (((serial_port_windows *) sp)->hPort, pbtRx, dwRxLen, &dwRxLen, NULL)) {
return DEIO;
}
do {
if (!ReadFile (((serial_port_windows *) sp)->hPort, pbtRx, dwRxLen, &dwRxLen, NULL)) {
return DEIO;
}
} while ( (dwRxLen != (DWORD) szRx) && ((abort_flag_p) && !(*abort_flag_p)) );
return (dwRxLen == (DWORD) szRx) ? 0 : DEIO;
}