repositories
/
deb_libcec.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
added CCECTypeUtils::PhysicalAddressIsIncluded()
[deb_libcec.git]
/
src
/
lib
/
platform
/
windows
/
serialport.cpp
diff --git
a/src/lib/platform/windows/serialport.cpp
b/src/lib/platform/windows/serialport.cpp
index fe917255d5ad2e921b4ce628077ea42d57027c49..00ba7bb80e0ce3530182cb95542176bb75ee89be 100644
(file)
--- a/
src/lib/platform/windows/serialport.cpp
+++ b/
src/lib/platform/windows/serialport.cpp
@@
-30,14
+30,15
@@
* http://www.pulse-eight.net/
*/
* http://www.pulse-eight.net/
*/
-#include "../sockets/serialport.h"
-#include "../util/baudrate.h"
-#include "../util/timeutils.h"
+#include "env.h"
+#include "lib/platform/sockets/serialport.h"
+#include "lib/platform/util/baudrate.h"
+#include "lib/platform/util/timeutils.h"
using namespace std;
using namespace PLATFORM;
using namespace std;
using namespace PLATFORM;
-void FormatWindowsError(int iErrorCode,
CStdS
tring &strMessage)
+void FormatWindowsError(int iErrorCode,
std::s
tring &strMessage)
{
if (iErrorCode != ERROR_SUCCESS)
{
{
if (iErrorCode != ERROR_SUCCESS)
{
@@
-48,32
+49,38
@@
void FormatWindowsError(int iErrorCode, CStdString &strMessage)
}
}
}
}
-bool CSerialSocket::SetTimeouts(serial_socket_t socket, int* iError, DWORD iTimeout)
+bool CSerialSocket::SetTimeouts(serial_socket_t socket, int* iError, DWORD iTimeout
Ms
)
{
if (socket == INVALID_HANDLE_VALUE)
return false;
{
if (socket == INVALID_HANDLE_VALUE)
return false;
- if (iTimeout
== m_iCurrent
Timeout)
+ if (iTimeout
Ms == m_iCurrentRead
Timeout)
return true;
COMMTIMEOUTS cto;
return true;
COMMTIMEOUTS cto;
- if (
!GetCommTimeouts(socket, &cto)
)
+ if (
iTimeoutMs == 0
)
{
{
- *iError = GetLastError();
- return false;
+ cto.ReadIntervalTimeout = MAXDWORD;
+ cto.ReadTotalTimeoutConstant = 0;
+ cto.ReadTotalTimeoutMultiplier = 0;
+ }
+ else
+ {
+ cto.ReadIntervalTimeout = 0;
+ cto.ReadTotalTimeoutConstant = iTimeoutMs;
+ cto.ReadTotalTimeoutMultiplier = 0;
}
}
-
- cto.ReadIntervalTimeout = 0;
- cto.ReadTotalTimeoutConstant = iTimeout;
- cto.ReadTotalTimeoutMultiplier = 0;
if (!SetCommTimeouts(socket, &cto))
{
*iError = GetLastError();
return false;
}
if (!SetCommTimeouts(socket, &cto))
{
*iError = GetLastError();
return false;
}
+ else
+ {
+ m_iCurrentReadTimeout = iTimeoutMs;
+ }
- m_iCurrentTimeout = iTimeout;
return true;
}
return true;
}
@@
-93,25
+100,28
@@
void CSerialSocket::Shutdown(void)
ssize_t CSerialSocket::Write(void* data, size_t len)
{
ssize_t CSerialSocket::Write(void* data, size_t len)
{
- return IsOpen() ? SerialSocketWrite(m_socket, &m_iError, data, len) : -1;
+ if (IsOpen())
+ {
+ ssize_t iReturn = SerialSocketWrite(m_socket, &m_iError, data, len);
+ if (iReturn != (ssize_t)len)
+ {
+ m_strError = "unable to write to the serial port";
+ FormatWindowsError(GetLastError(), m_strError);
+ }
+ return iReturn;
+ }
+ return -1;
}
ssize_t CSerialSocket::Read(void* data, size_t len, uint64_t iTimeoutMs /* = 0 */)
{
}
ssize_t CSerialSocket::Read(void* data, size_t len, uint64_t iTimeoutMs /* = 0 */)
{
- if (IsOpen())
- {
- DWORD iTimeout((DWORD)iTimeoutMs);
- if (iTimeout != iTimeoutMs)
- return -1;
-
- int iError(0);
- if (!SetTimeouts(m_socket, &iError, iTimeout))
- return -1;
+ DWORD dwTimeoutMs((DWORD)iTimeoutMs);
+ if (iTimeoutMs != (uint64_t)iTimeoutMs)
+ dwTimeoutMs = MAXDWORD;
- return SerialSocketRead(m_socket, &m_iError, data, len, iTimeoutMs);
- }
-
- return -1;
+ return IsOpen() && SetTimeouts(m_socket, &m_iError, dwTimeoutMs) ?
+ SerialSocketRead(m_socket, &m_iError, data, len, iTimeoutMs) :
+ -1;
}
bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */)
}
bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */)
@@
-120,7
+130,7
@@
bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */)
if (IsOpen())
return false;
if (IsOpen())
return false;
-
CStdS
tring strComPath = "\\\\.\\" + m_strName;
+
std::s
tring strComPath = "\\\\.\\" + m_strName;
CLockObject lock(m_mutex);
m_socket = CreateFile(strComPath.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (m_socket == INVALID_HANDLE_VALUE)
CLockObject lock(m_mutex);
m_socket = CreateFile(strComPath.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (m_socket == INVALID_HANDLE_VALUE)
@@
-161,7
+171,7
@@
bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */)
return false;
}
return false;
}
- if (!SetTimeouts(m_socket, &m_iError,
MAXDWORD
))
+ if (!SetTimeouts(m_socket, &m_iError,
0
))
{
m_strError = "unable to set timeouts";
FormatWindowsError(GetLastError(), m_strError);
{
m_strError = "unable to set timeouts";
FormatWindowsError(GetLastError(), m_strError);
@@
-169,6
+179,7
@@
bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */)
return false;
}
return false;
}
+ m_strError.clear();
m_bIsOpen = true;
return m_bIsOpen;
}
m_bIsOpen = true;
return m_bIsOpen;
}