/* Blinker
Copyright 2011-2014Stefan Schuermans <stefan@blinkenarea.org>
Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
a blinkenarea.org project */
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string>
#include <strings.h>
#include <termios.h>
#include <unistd.h>
#include "Device.h"
#include "Io.h"
#include "SerCfg.h"
namespace Blinker {
/**
* @brief constructor
* @param[in] path path to device
*/
Device::Device(const std::string &path)
{
// open device
m_fd = open(path.c_str(), O_RDWR | O_CLOEXEC | O_NOCTTY | O_NONBLOCK);
}
/// destructor
Device::~Device()
{
// exit if not initialized
if (m_fd == -1)
return;
// close device
close(m_fd);
}
/**
* @brief set serial port configuration
* @param[in] serCfg serial port configuration
* @return if configuration succeeded
*
* This function should only be used if device is a serial port.
*/
bool Device::setSerCfg(const SerCfg& serCfg)
{
struct termios tio;