mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +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:
parent
8f63914d76
commit
dd73c4aa45
@ -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()
|
MHZ16::~MHZ16()
|
||||||
{
|
{
|
||||||
if (m_ttyFd != -1)
|
if (m_ttyFd != -1)
|
||||||
|
@ -40,12 +40,6 @@
|
|||||||
|
|
||||||
#include <mraa/uart.h>
|
#include <mraa/uart.h>
|
||||||
|
|
||||||
const int MHZ16_DEFAULT_UART = 0;
|
|
||||||
|
|
||||||
// protocol start and end codes
|
|
||||||
const uint8_t MHZ16_START = 0x7e;
|
|
||||||
const uint8_t MHZ16_END = 0x7e;
|
|
||||||
|
|
||||||
namespace upm {
|
namespace upm {
|
||||||
/**
|
/**
|
||||||
* @brief MHZ16 Serial CO2 Sensor
|
* @brief MHZ16 Serial CO2 Sensor
|
||||||
@ -80,14 +74,21 @@ namespace upm {
|
|||||||
/**
|
/**
|
||||||
* MHZ16 constructor
|
* MHZ16 constructor
|
||||||
*
|
*
|
||||||
* @param uart Default UART to use (0 or 1)
|
* @param uart Default mraa UART index to use
|
||||||
*/
|
*/
|
||||||
MHZ16(int uart);
|
MHZ16(int uart);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MHZ16 constructor
|
||||||
|
*
|
||||||
|
* @param uart_raw Full path to UART device.
|
||||||
|
*/
|
||||||
|
MHZ16(const std::string& uart_raw = "/dev/ttyS0");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MHZ16 destructor
|
* MHZ16 destructor
|
||||||
*/
|
*/
|
||||||
~MHZ16();
|
virtual ~MHZ16();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks to see if there is data available for reading
|
* Checks to see if there is data available for reading
|
||||||
|
Loading…
x
Reference in New Issue
Block a user