<ClInclude Include="..\src\lib\implementations\SLCommandHandler.h" />
<ClInclude Include="..\src\lib\implementations\VLCommandHandler.h" />
<ClInclude Include="..\src\lib\LibCEC.h" />
- <ClInclude Include="..\src\lib\platform\buffer.h" />
<ClInclude Include="..\src\lib\platform\os.h" />
- <ClInclude Include="..\src\lib\platform\serialport\baudrate.h" />
- <ClInclude Include="..\src\lib\platform\serialport\serialport.h" />
- <ClInclude Include="..\src\lib\platform\StdString.h" />
+ <ClInclude Include="..\src\lib\platform\sockets\serialport.h" />
+ <ClInclude Include="..\src\lib\platform\sockets\socket.h" />
<ClInclude Include="..\src\lib\platform\threads\mutex.h" />
<ClInclude Include="..\src\lib\platform\threads\threads.h" />
- <ClInclude Include="..\src\lib\platform\timeutils.h" />
+ <ClInclude Include="..\src\lib\platform\util\baudrate.h" />
+ <ClInclude Include="..\src\lib\platform\util\buffer.h" />
+ <ClInclude Include="..\src\lib\platform\util\StdString.h" />
+ <ClInclude Include="..\src\lib\platform\util\timeutils.h" />
+ <ClInclude Include="..\src\lib\platform\windows\os-socket.h" />
<ClInclude Include="..\src\lib\platform\windows\os-threads.h" />
<ClInclude Include="..\src\lib\platform\windows\os-types.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
-
+</Project>
\ No newline at end of file
<Filter Include="platform\windows">
<UniqueIdentifier>{fa3d5953-d288-45e9-93f4-8419e6b701c7}</UniqueIdentifier>
</Filter>
- <Filter Include="platform\serialport">
- <UniqueIdentifier>{e3945145-efa2-4393-b201-f50e1e775008}</UniqueIdentifier>
- </Filter>
<Filter Include="platform\threads">
<UniqueIdentifier>{38a27e9e-86ad-46f6-a4fb-e1e524267b74}</UniqueIdentifier>
</Filter>
<Filter Include="adapter">
<UniqueIdentifier>{51614b77-8a0e-47a8-8500-5beb0fd12d49}</UniqueIdentifier>
</Filter>
+ <Filter Include="platform\util">
+ <UniqueIdentifier>{4e963de7-5c42-40a0-9c81-bb112d5a24f9}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="platform\sockets">
+ <UniqueIdentifier>{e3945145-efa2-4393-b201-f50e1e775008}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\lib\CECProcessor.h" />
<ClInclude Include="..\src\lib\LibCEC.h" />
- <ClInclude Include="..\src\lib\platform\timeutils.h">
- <Filter>platform</Filter>
- </ClInclude>
<ClInclude Include="..\include\cec.h">
<Filter>exports</Filter>
</ClInclude>
<ClInclude Include="..\src\lib\platform\windows\os-types.h">
<Filter>platform\windows</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\platform\serialport\baudrate.h">
- <Filter>platform\serialport</Filter>
- </ClInclude>
- <ClInclude Include="..\src\lib\platform\serialport\serialport.h">
- <Filter>platform\serialport</Filter>
- </ClInclude>
<ClInclude Include="..\src\lib\platform\threads\mutex.h">
<Filter>platform\threads</Filter>
</ClInclude>
<ClInclude Include="..\src\lib\platform\threads\threads.h">
<Filter>platform\threads</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\platform\buffer.h">
- <Filter>platform</Filter>
- </ClInclude>
- <ClInclude Include="..\src\lib\platform\StdString.h">
- <Filter>platform</Filter>
- </ClInclude>
<ClInclude Include="..\src\lib\adapter\AdapterCommunication.h">
<Filter>adapter</Filter>
</ClInclude>
<ClInclude Include="..\src\lib\adapter\AdapterMessage.h">
<Filter>adapter</Filter>
</ClInclude>
+ <ClInclude Include="..\src\lib\platform\util\StdString.h">
+ <Filter>platform\util</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\platform\util\buffer.h">
+ <Filter>platform\util</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\platform\util\timeutils.h">
+ <Filter>platform\util</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\platform\sockets\serialport.h">
+ <Filter>platform\sockets</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\platform\sockets\socket.h">
+ <Filter>platform\sockets</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\platform\windows\os-socket.h">
+ <Filter>platform\windows</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\platform\util\baudrate.h">
+ <Filter>platform\util</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\lib\CECProcessor.cpp" />
<ClCompile Include="..\src\lib\devices\CECTV.cpp">
<Filter>devices</Filter>
</ClCompile>
- <ClCompile Include="..\src\lib\platform\windows\serialport.cpp">
- <Filter>platform\serialport</Filter>
- </ClCompile>
<ClCompile Include="..\src\lib\adapter\AdapterCommunication.cpp">
<Filter>adapter</Filter>
</ClCompile>
<ClCompile Include="..\src\lib\adapter\AdapterDetection.cpp">
<Filter>adapter</Filter>
</ClCompile>
+ <ClCompile Include="..\src\lib\platform\windows\serialport.cpp">
+ <Filter>platform\windows</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="libcec.rc" />
</ItemGroup>
-</Project>
-
+</Project>
\ No newline at end of file
* http://www.pulse-eight.net/
*/
-#include "platform/util/StdString.h"
+#include "../platform/util/StdString.h"
namespace CEC
{
#if !defined(__WINDOWS__)
#include <termios.h>
-#include "socket.h"
#endif
+#include "socket.h"
+
namespace PLATFORM
{
#define PAR_NONE 0
{
public:
CSerialPort(void);
- virtual ~CSerialPort(void) {};
+ virtual ~CSerialPort(void) {}
bool Open(std::string name, uint32_t baudrate, uint8_t databits = 8, uint8_t stopbits = 1, uint8_t parity = PAR_NONE);
return strName;
}
+ #ifdef __WINDOWS__
+ virtual bool IsOpen(void);
+ virtual void Close(void);
+ virtual int64_t Write(uint8_t* data, uint32_t len);
+ virtual int32_t Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs = 0);
+
private:
+ void FormatWindowsError(int iErrorCode, CStdString &strMessage);
bool SetBaudRate(uint32_t baudrate);
std::string m_name;
bool m_tostdout;
- #ifdef __WINDOWS__
bool SetTimeouts(bool bBlocking);
- HANDLE m_handle;
+ HANDLE m_handle;
bool m_bIsOpen;
uint32_t m_iBaudrate;
uint8_t m_iDatabits;
m_strError = "";
}
- int64_t Write(uint8_t* data, uint32_t len)
+ virtual int64_t Write(uint8_t* data, uint32_t len)
{
CLockObject lock(m_mutex);
int iError(0);
return iReturn;
}
- int32_t Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs = 0)
+ virtual int32_t Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs = 0)
{
CLockObject lock(m_mutex);
int iError(0);
#pragma once
+#include "../os.h"
#include <string>
#include <stdint.h>
#include <vector>
--- /dev/null
+#pragma once
+/*
+ * This file is part of the libCEC(R) library.
+ *
+ * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
+ * libCEC(R) is an original work, containing original code.
+ *
+ * libCEC(R) is a trademark of Pulse-Eight Limited.
+ *
+ * This program is dual-licensed; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *
+ * Alternatively, you can license this library under a commercial license,
+ * please contact Pulse-Eight Licensing for more information.
+ *
+ * For more information contact:
+ * Pulse-Eight Licensing <license@pulse-eight.com>
+ * http://www.pulse-eight.com/
+ * http://www.pulse-eight.net/
+ */
+
+#include "../os.h"
+#include "../util/timeutils.h"
+
+namespace PLATFORM
+{
+ inline void SocketClose(socket_t socket)
+ {
+ //TODO
+ }
+
+ inline void SocketSetBlocking(socket_t socket, bool bSetTo)
+ {
+ //TODO
+ }
+
+ inline int64_t SocketWrite(socket_t socket, int *iError, uint8_t* data, uint32_t len)
+ {
+ //TODO
+ return -1;
+ }
+
+ inline int32_t SocketRead(socket_t socket, int *iError, uint8_t* data, uint32_t len, uint64_t iTimeoutMs /*= 0*/)
+ {
+ // TODO
+ return -1;
+ }
+}
#define snprintf _snprintf
+typedef SOCKET socket_t;
+
#if defined(_MSC_VER)
#pragma warning (push)
#endif
using namespace std;
using namespace PLATFORM;
-void FormatWindowsError(int iErrorCode, string &strMessage)
+void CSerialPort::FormatWindowsError(int iErrorCode, CStdString &strMessage)
{
if (iErrorCode != ERROR_SUCCESS)
{
{
}
-CSerialPort::~CSerialPort(void)
-{
- Close();
-}
-
bool CSerialPort::Open(string name, uint32_t baudrate, uint8_t databits, uint8_t stopbits, uint8_t parity)
{
CStdString strComPath = "\\\\.\\" + name;
m_handle = CreateFile(strComPath.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (m_handle == INVALID_HANDLE_VALUE)
{
- m_error = "Unable to open COM port";
- FormatWindowsError(GetLastError(), m_error);
+ m_strError = "Unable to open COM port";
+ FormatWindowsError(GetLastError(), m_strError);
return false;
}
{
if (!SetCommConfig(m_handle, &commConfig,dwSize))
{
- m_error = "unable to set default config";
- FormatWindowsError(GetLastError(), m_error);
+ m_strError = "unable to set default config";
+ FormatWindowsError(GetLastError(), m_strError);
}
}
else
{
- m_error = "unable to get default config";
- FormatWindowsError(GetLastError(), m_error);
+ m_strError = "unable to get default config";
+ FormatWindowsError(GetLastError(), m_strError);
}
if (!SetupComm(m_handle, 64, 64))
{
- m_error = "unable to set up the com port";
- FormatWindowsError(GetLastError(), m_error);
+ m_strError = "unable to set up the com port";
+ FormatWindowsError(GetLastError(), m_strError);
}
m_iDatabits = databits;
m_iParity = parity;
if (!SetBaudRate(baudrate))
{
- m_error = "unable to set baud rate";
- FormatWindowsError(GetLastError(), m_error);
+ m_strError = "unable to set baud rate";
+ FormatWindowsError(GetLastError(), m_strError);
Close();
return false;
}
if (!SetTimeouts(false))
{
- m_error = "unable to set timeouts";
- FormatWindowsError(GetLastError(), m_error);
+ m_strError = "unable to set timeouts";
+ FormatWindowsError(GetLastError(), m_strError);
Close();
return false;
}
COMMTIMEOUTS cto;
if (!GetCommTimeouts(m_handle, &cto))
{
- m_error = "GetCommTimeouts failed";
- FormatWindowsError(GetLastError(), m_error);
+ m_strError = "GetCommTimeouts failed";
+ FormatWindowsError(GetLastError(), m_strError);
return false;
}
if (!SetCommTimeouts(m_handle, &cto))
{
- m_error = "SetCommTimeouts failed";
- FormatWindowsError(GetLastError(), m_error);
+ m_strError = "SetCommTimeouts failed";
+ FormatWindowsError(GetLastError(), m_strError);
return false;
}
if (!WriteFile(m_handle, data, len, &iBytesWritten, NULL))
{
- m_error = "Error while writing to COM port";
- FormatWindowsError(GetLastError(), m_error);
+ m_strError = "Error while writing to COM port";
+ FormatWindowsError(GetLastError(), m_strError);
return -1;
}
DWORD iBytesRead = 0;
if (m_handle == 0)
{
- m_error = "Error while reading from COM port: invalid handle";
+ m_strError = "Error while reading from COM port: invalid handle";
return iReturn;
}
if(!ReadFile(m_handle, data, len, &iBytesRead, NULL) != 0)
{
- m_error = "unable to read from device";
- FormatWindowsError(GetLastError(), m_error);
+ m_strError = "unable to read from device";
+ FormatWindowsError(GetLastError(), m_strError);
iReturn = -1;
}
else
if(!SetCommState(m_handle,&dcb))
{
- m_error = "SetCommState failed";
- FormatWindowsError(GetLastError(), m_error);
+ m_strError = "SetCommState failed";
+ FormatWindowsError(GetLastError(), m_strError);
return false;
}
return true;
}
-bool CSerialPort::IsOpen()
+bool CSerialPort::IsOpen(void)
{
CLockObject lock(m_mutex);
return m_bIsOpen;