* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <iostream>//debug
-
#include <stdio.h>
-#include <unistd.h>
#include <fcntl.h>
-
#include "../serialport.h"
#include "../baudrate.h"
-#include "../../util/misc.h"
-#include "../../util/timeutils.h"
+#include "../timeutils.h"
using namespace std;
+using namespace CEC;
CSerialPort::CSerialPort()
{
- m_fd = -1;
+ m_fd = -1;
}
CSerialPort::~CSerialPort()
int returnv = select(m_fd + 1, NULL, &port, NULL, NULL);
if (returnv == -1)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return -1;
}
returnv = write(m_fd, data + byteswritten, len - byteswritten);
if (returnv == -1)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return -1;
}
byteswritten += returnv;
if (returnv == -1)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return -1;
}
else if (returnv == 0)
returnv = read(m_fd, data + bytesread, len - bytesread);
if (returnv == -1)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return -1;
}
bool CSerialPort::Open(string name, int baudrate, int databits/* = 8*/, int stopbits/* = 1*/, int parity/* = PAR_NONE*/)
{
m_name = name;
- m_error = GetErrno();
+ m_error = strerror(errno);
if (databits < 5 || databits > 8)
{
if (m_fd == -1)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return false;
}
if (tcsetattr(m_fd, TCSANOW, &m_options) != 0)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return false;
}
bool CSerialPort::SetBaudRate(int baudrate)
{
- int rate = IntToRate(baudrate);
+ int rate = IntToBaudrate(baudrate);
if (rate == -1)
{
char buff[255];
//get the current port attributes
if (tcgetattr(m_fd, &m_options) != 0)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return false;
}
if (cfsetispeed(&m_options, rate) != 0)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return false;
}
if (cfsetospeed(&m_options, rate) != 0)
{
- m_error = GetErrno();
+ m_error = strerror(errno);
return false;
}
return true;
}
+
+bool CSerialPort::IsOpen() const
+{
+ return m_fd != -1;
+}