repositories
/
deb_libcec.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
win32: don't include the .pdb in the installer. only include include/cec*
[deb_libcec.git]
/
src
/
lib
/
platform
/
linux
/
serialport.cpp
diff --git
a/src/lib/platform/linux/serialport.cpp
b/src/lib/platform/linux/serialport.cpp
index e6bfafab44a611397e445f090ffe5669ae21ff3d..e362396e6cd471d41d4d562658fbc8adc5c54ec0 100644
(file)
--- a/
src/lib/platform/linux/serialport.cpp
+++ b/
src/lib/platform/linux/serialport.cpp
@@
-22,6
+22,17
@@
#include "../baudrate.h"
#include "../timeutils.h"
#include "../baudrate.h"
#include "../timeutils.h"
+#if defined(__APPLE__)
+#ifndef XCASE
+#define XCASE 0
+#endif
+#ifndef OLCUC
+#define OLCUC 0
+#endif
+#ifndef IUCLC
+#define IUCLC 0
+#endif
+#endif
using namespace std;
using namespace CEC;
using namespace std;
using namespace CEC;
@@
-35,19
+46,20
@@
CSerialPort::~CSerialPort()
Close();
}
Close();
}
-int
CSerialPort::Write(uint8_t* data, int len
)
+int
8_t CSerialPort::Write(CCECAdapterMessagePtr data
)
{
fd_set port;
{
fd_set port;
-
+
+ CLockObject lock(&m_mutex);
if (m_fd == -1)
{
m_error = "port closed";
return -1;
}
if (m_fd == -1)
{
m_error = "port closed";
return -1;
}
- int byteswritten = 0;
+ int
32_t
byteswritten = 0;
- while (byteswritten <
len
)
+ while (byteswritten <
(int32_t) data->size()
)
{
FD_ZERO(&port);
FD_SET(m_fd, &port);
{
FD_ZERO(&port);
FD_SET(m_fd, &port);
@@
-58,7
+70,7
@@
int CSerialPort::Write(uint8_t* data, int len)
return -1;
}
return -1;
}
- returnv = write(m_fd, data
+ byteswritten, len
- byteswritten);
+ returnv = write(m_fd, data
->packet.data + byteswritten, data->size()
- byteswritten);
if (returnv == -1)
{
m_error = strerror(errno);
if (returnv == -1)
{
m_error = strerror(errno);
@@
-73,35
+85,36
@@
int CSerialPort::Write(uint8_t* data, int len)
// printf("%s write:", m_name.c_str());
// for (int i = 0; i < byteswritten; i++)
// printf(" %02x", (unsigned int)data[i]);
// printf("%s write:", m_name.c_str());
// for (int i = 0; i < byteswritten; i++)
// printf(" %02x", (unsigned int)data[i]);
-
+//
// printf("\n");
// }
return byteswritten;
}
// printf("\n");
// }
return byteswritten;
}
-int
CSerialPort::Read(uint8_t* data, int len, int iTimeoutMs /*= -1
*/)
+int
32_t CSerialPort::Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs /*= 0
*/)
{
fd_set port;
struct timeval timeout, *tv;
{
fd_set port;
struct timeval timeout, *tv;
- int64_t now
, target
;
- int
bytesread = 0;
+ int64_t now
(0), target(0)
;
+ int
32_t
bytesread = 0;
+ CLockObject lock(&m_mutex);
if (m_fd == -1)
{
m_error = "port closed";
return -1;
}
if (m_fd == -1)
{
m_error = "port closed";
return -1;
}
- if (iTimeoutMs >
=
0)
+ if (iTimeoutMs > 0)
{
now = GetTimeMs();
target = now + (int64_t) iTimeoutMs;
}
{
now = GetTimeMs();
target = now + (int64_t) iTimeoutMs;
}
- while (bytesread <
len && (iTimeoutMs <
0 || target > now))
+ while (bytesread <
(int32_t) len && (iTimeoutMs ==
0 || target > now))
{
{
- if (iTimeoutMs
<
0)
+ if (iTimeoutMs
==
0)
{
tv = NULL;
}
{
tv = NULL;
}
@@
-114,7
+127,7
@@
int CSerialPort::Read(uint8_t* data, int len, int iTimeoutMs /*= -1*/)
FD_ZERO(&port);
FD_SET(m_fd, &port);
FD_ZERO(&port);
FD_SET(m_fd, &port);
- int returnv = select(m_fd + 1, &port, NULL, NULL, tv);
+ int
32_t
returnv = select(m_fd + 1, &port, NULL, NULL, tv);
if (returnv == -1)
{
if (returnv == -1)
{
@@
-153,11
+166,12
@@
int CSerialPort::Read(uint8_t* data, int len, int iTimeoutMs /*= -1*/)
}
//setting all this stuff up is a pain in the ass
}
//setting all this stuff up is a pain in the ass
-bool CSerialPort::Open(string name,
int baudrate, int databits/* = 8*/, int stopbits/* = 1*/, int parity/* = PAR_NONE
*/)
+bool CSerialPort::Open(string name,
uint32_t baudrate, uint8_t databits /* = 8 */, uint8_t stopbits /* = 1 */, uint8_t parity /* = PAR_NONE
*/)
{
m_name = name;
m_error = strerror(errno);
{
m_name = name;
m_error = strerror(errno);
-
+ CLockObject lock(&m_mutex);
+
if (databits < 5 || databits > 8)
{
m_error = "Databits has to be between 5 and 8";
if (databits < 5 || databits > 8)
{
m_error = "Databits has to be between 5 and 8";
@@
-244,6
+258,7
@@
bool CSerialPort::Open(string name, int baudrate, int databits/* = 8*/, int stop
void CSerialPort::Close()
{
void CSerialPort::Close()
{
+ CLockObject lock(&m_mutex);
if (m_fd != -1)
{
close(m_fd);
if (m_fd != -1)
{
close(m_fd);
@@
-253,7
+268,7
@@
void CSerialPort::Close()
}
}
}
}
-bool CSerialPort::SetBaudRate(
in
t baudrate)
+bool CSerialPort::SetBaudRate(
uint32_
t baudrate)
{
int rate = IntToBaudrate(baudrate);
if (rate == -1)
{
int rate = IntToBaudrate(baudrate);
if (rate == -1)
@@
-286,7
+301,8
@@
bool CSerialPort::SetBaudRate(int baudrate)
return true;
}
return true;
}
-bool CSerialPort::IsOpen()
const
+bool CSerialPort::IsOpen()
{
{
+ CLockObject lock(&m_mutex);
return m_fd != -1;
}
return m_fd != -1;
}