mirror of
https://github.com/eclipse/upm.git
synced 2025-07-03 18:31:13 +03:00
mhz16: Adding raw path constructor for UART
This commit adds an additional constructor to the MHZ16 which takes a path (string reference) to a UART device on the filesystem. Example: MHZ16("/dev/ttyS0"); * Added constructor for device path w/default * Removed unused global consts from header Signed-off-by: g-vidal <gerard.vidal@ens-lyon.fr> Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
@ -65,6 +65,38 @@ MHZ16::MHZ16(int uart)
|
||||
}
|
||||
}
|
||||
|
||||
MHZ16::MHZ16(const std::string& uart_raw)
|
||||
{
|
||||
m_ttyFd = -1;
|
||||
|
||||
if ( !(m_uart = mraa_uart_init_raw(uart_raw.c_str())) )
|
||||
{
|
||||
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)
|
||||
|
Reference in New Issue
Block a user