From 19cad5cf24f8cdb8cb800bc59bfaa96854a1dd56 Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Fri, 22 May 2015 14:06:05 +0100 Subject: [PATCH] uart: bunch of small changes to make C api work Signed-off-by: Brendan Le Foll --- api/mraa/uart.h | 12 ------------ api/mraa/uart.hpp | 46 +++++++++------------------------------------- src/uart/uart.c | 8 +++++--- 3 files changed, 14 insertions(+), 52 deletions(-) diff --git a/api/mraa/uart.h b/api/mraa/uart.h index a1df471..8e7a069 100644 --- a/api/mraa/uart.h +++ b/api/mraa/uart.h @@ -76,18 +76,6 @@ mraa_result_t mraa_uart_set_timeout(mraa_uart_context dev, int read, int write, */ char* mraa_uart_get_dev_path(mraa_uart_context dev); -/** - * Open the TTY device associated with a UART context, and set up the - * terminal modes and baud rate. The TTY is setup for a 'raw' - * mode. 81N, no echo or special character handling, such as flow - * control or line editing semantics. - * - * @param dev uart context - * @param baud desired baud rate - * @return mraa_result_t - */ -mraa_result_t mraa_uart_open_dev(mraa_uart_context dev, unsigned int baud); - /** * Destroy a mraa_uart_context * diff --git a/api/mraa/uart.hpp b/api/mraa/uart.hpp index 3f4a53b..482deac 100644 --- a/api/mraa/uart.hpp +++ b/api/mraa/uart.hpp @@ -58,8 +58,7 @@ class Uart */ ~Uart() { - stopDevice(); - return; + mraa_uart_stop(m_uart); } /** @@ -75,57 +74,30 @@ class Uart return ret_val; } - /** - * Open the TTY device associated with a UART context, and set up the - * terminal modes and baud rate. The TTY is setup for a 'raw' - * mode. 81N, no echo or special character handling, such as flow - * control or line editing semantics. - * - * @param baud desired baud rate - * @return mraa_result_t - */ - mraa_result_t - openDevice(unsigned int baud) - { - return mraa_uart_open_dev(m_uart, baud); - } - - /** - * Close a device previously opened with mraa_uart_open_dev(). - * - * @param dev uart context - * @return mraa_result_t - */ - mraa_result_t - stopDevice() - { - return mraa_uart_stop(m_uart); - } - /** * Read bytes from the device into a buffer * - * @param buf buffer pointer - * @param len maximum size of buffer + * @param data buffer pointer + * @param length maximum size of buffer * @return the number of bytes read, or -1 if an error occurred */ int - read(char* buf, size_t len) + read(char* data, int length) { - return mraa_uart_read(m_uart, buf, len); + return mraa_uart_read(m_uart, data, length); } /** * Write bytes in buffer to a device * - * @param buf buffer pointer - * @param len maximum size of buffer + * @param data buffer pointer + * @param length maximum size of buffer * @return the number of bytes written, or -1 if an error occurred */ int - write(char* buf, size_t len) + write(char* data, int length) { - return mraa_uart_write(m_uart, buf, len); + return mraa_uart_write(m_uart, data, length); } /** diff --git a/src/uart/uart.c b/src/uart/uart.c index cc1a06d..71bcefa 100644 --- a/src/uart/uart.c +++ b/src/uart/uart.c @@ -198,8 +198,9 @@ mraa_uart_init_raw(int index) struct termios termio; // get current modes - if (!tcgetattr(dev->fd, &termio)) { + if (tcgetattr(dev->fd, &termio)) { syslog(LOG_ERR, "uart: tcgetattr() failed"); + close(dev->fd); free(dev); return NULL; } @@ -209,7 +210,8 @@ mraa_uart_init_raw(int index) // cfmakeraw is not POSIX! cfmakeraw(&termio); - if (!mraa_uart_set_baudrate(dev, 9600)) { + if (mraa_uart_set_baudrate(dev, 9600) != MRAA_SUCCESS) { + close(dev->fd); free(dev); return NULL; } @@ -259,7 +261,7 @@ mraa_uart_set_baudrate(mraa_uart_context dev, unsigned int baud) } struct termios termio; - if (!tcgetattr(dev->fd, &termio)) { + if (tcgetattr(dev->fd, &termio)) { syslog(LOG_ERR, "uart: tcgetattr() failed"); return MRAA_ERROR_INVALID_HANDLE; }