firmata: Added option to set uart non blocking state
Signed-off-by: Shiran Ben-Melech <shiran.ben-melech@intel.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
committed by
Brendan Le Foll
parent
04f7cbff5d
commit
cae63bbd52
@@ -118,6 +118,15 @@ mraa_result_t mraa_uart_set_flowcontrol(mraa_uart_context dev, mraa_boolean_t xo
|
||||
*/
|
||||
mraa_result_t mraa_uart_set_timeout(mraa_uart_context dev, int read, int write, int interchar);
|
||||
|
||||
/**
|
||||
* Set the blocking state for write operations
|
||||
*
|
||||
* @param dev The UART context
|
||||
* @param nonblock new nonblocking state
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t mraa_uart_set_non_blocking(mraa_uart_context dev, mraa_boolean_t nonblock);
|
||||
|
||||
/**
|
||||
* Get Char pointer with tty device path within Linux
|
||||
* For example. Could point to "/dev/ttyS0"
|
||||
|
||||
@@ -236,6 +236,19 @@ class Uart
|
||||
return (Result) mraa_uart_set_timeout(m_uart, read, write, interchar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the blocking state for write operations
|
||||
*
|
||||
* @param dev The UART context
|
||||
* @param nonblock new nonblocking state
|
||||
* @return Result of operation
|
||||
*/
|
||||
Result
|
||||
SetNonBlocking(bool nonblock)
|
||||
{
|
||||
return (Result) mraa_uart_set_non_blocking(m_uart, nonblock);
|
||||
}
|
||||
|
||||
private:
|
||||
mraa_uart_context m_uart;
|
||||
};
|
||||
|
||||
@@ -451,6 +451,28 @@ mraa_uart_set_timeout(mraa_uart_context dev, int read, int write, int interchar)
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_uart_set_non_blocking(mraa_uart_context dev, mraa_boolean_t nonblock)
|
||||
{
|
||||
// get current flags
|
||||
int flags = fcntl(dev->fd, F_GETFL);
|
||||
|
||||
// update flags with new blocking state according to nonblock bool
|
||||
if (nonblock) {
|
||||
flags |= O_NONBLOCK;
|
||||
} else {
|
||||
flags &= ~O_NONBLOCK;
|
||||
}
|
||||
|
||||
// set new flags
|
||||
if (fcntl(dev->fd, F_SETFL, flags) < 0) {
|
||||
syslog(LOG_ERR, "failed changing fd blocking state");
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
}
|
||||
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
const char*
|
||||
mraa_uart_get_dev_path(mraa_uart_context dev)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user