From 9ab7426461fc8f8fb7f535750dee47bbb21daaaa Mon Sep 17 00:00:00 2001 From: g-vidal Date: Sun, 15 Apr 2018 16:06:13 +0200 Subject: [PATCH 1/3] Adding constructor to use raw path to create uart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: g-vidal Validated changes : modified : src/mhz16/mhz16.cxx modified : src/mhz16/mhz16.hpp --- src/mhz16/mhz16.cxx | 32 ++++++++++++++++++++++++++++++++ src/mhz16/mhz16.hpp | 8 ++++++++ 2 files changed, 40 insertions(+) diff --git a/src/mhz16/mhz16.cxx b/src/mhz16/mhz16.cxx index ca3162e7..b9533063 100644 --- a/src/mhz16/mhz16.cxx +++ b/src/mhz16/mhz16.cxx @@ -65,6 +65,38 @@ MHZ16::MHZ16(int uart) } } +MHZ16::MHZ16(char * uart_raw) +{ + m_ttyFd = -1; + + if ( !(m_uart = mraa_uart_init_raw(uart_raw)) ) + { + throw std::invalid_argument(std::string(__FUNCTION__) + + ": mraa_uart_init_raw() failed"); + return; + } + + // This requires a recent MRAA (1/2015) + const char *devPath = mraa_uart_get_dev_path(m_uart); + + if (!devPath) + { + throw std::runtime_error(std::string(__FUNCTION__) + + ": mraa_uart_get_dev_path() failed"); + return; + } + + // now open the tty + if ( (m_ttyFd = open(devPath, O_RDWR)) == -1) + { + throw std::runtime_error(std::string(__FUNCTION__) + + ": open of " + + string(devPath) + " failed: " + + string(strerror(errno))); + return; + } + + MHZ16::~MHZ16() { if (m_ttyFd != -1) diff --git a/src/mhz16/mhz16.hpp b/src/mhz16/mhz16.hpp index 999996c0..5d861103 100644 --- a/src/mhz16/mhz16.hpp +++ b/src/mhz16/mhz16.hpp @@ -41,6 +41,7 @@ #include const int MHZ16_DEFAULT_UART = 0; +const char * MHZ16_DEFAULT_UART_RAW="/dev/ttyS0"; // protocol start and end codes const uint8_t MHZ16_START = 0x7e; @@ -84,6 +85,13 @@ namespace upm { */ MHZ16(int uart); + /** + * MHZ16 constructor + * + * @param uart File path (/dev/ttyXXX to uart) + */ + MHZ16(char * uart_raw); + /** * MHZ16 destructor */ From c7584c76448d5aea2b0054611ff2c321f959abb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rard=20Vidal?= Date: Sun, 15 Apr 2018 16:22:59 +0200 Subject: [PATCH 2/3] Update mhz16.cxx copy/paste error --- src/mhz16/mhz16.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mhz16/mhz16.cxx b/src/mhz16/mhz16.cxx index b9533063..bfa7e75d 100644 --- a/src/mhz16/mhz16.cxx +++ b/src/mhz16/mhz16.cxx @@ -95,7 +95,7 @@ MHZ16::MHZ16(char * uart_raw) string(strerror(errno))); return; } - +} MHZ16::~MHZ16() { From 057d7f2a8fbeb33756a166ab335f648710b1b959 Mon Sep 17 00:00:00 2001 From: g-vidal Date: Sun, 15 Apr 2018 18:24:23 +0200 Subject: [PATCH 3/3] Copy/paste mistake Signed-off-by: g-vidal --- src/mhz16/mhz16.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mhz16/mhz16.cxx b/src/mhz16/mhz16.cxx index b9533063..bfa7e75d 100644 --- a/src/mhz16/mhz16.cxx +++ b/src/mhz16/mhz16.cxx @@ -95,7 +95,7 @@ MHZ16::MHZ16(char * uart_raw) string(strerror(errno))); return; } - +} MHZ16::~MHZ16() {