+libcec (0.4-2) unstable; urgency=low
+
+ * fixed int parameter sizes and some signed/unsigned warnings
+ * check whether m_port isn't NULL in ReadFromDevice
+ * stop the processor thread and delete the CSerialPort instance on exit
+ * added mutex in CSerialPort
+ * fix segfault on exit
+ * renamed libPlatform -> platform.
+ * stuck everything from libCEC in the CEC namespace to avoid namespace
+ polution
+
+ -- Pulse-Eight Packaging <packaging@pulse-eight.com> Tue, 04 Oct 2011 23:45:00 +0200
+
libcec (0.4-1) unstable; urgency=low
* bumped interface version to 4
AC_CHECK_LIB([pthread], [main],, AC_MSG_ERROR("required library 'pthread' is missing"))
AC_CHECK_LIB([udev], [main],, AC_MSG_ERROR("required library 'udev' is missing"))
+CXXFLAGS="-fPIC -Wall -Wextra $CXXFLAGS"
+
AC_CONFIG_FILES([src/lib/libcec.pc])
AC_OUTPUT([Makefile src/lib/Makefile src/testclient/Makefile])
+libcec (0.4-2) unstable; urgency=low
+
+ * fixed int parameter sizes and some signed/unsigned warnings
+ * check whether m_port isn't NULL in ReadFromDevice
+ * stop the processor thread and delete the CSerialPort instance on exit
+ * added mutex in CSerialPort
+ * fix segfault on exit
+ * renamed libPlatform -> platform.
+ * stuck everything from libCEC in the CEC namespace to avoid namespace
+ polution
+
+ -- Pulse-Eight Packaging <packaging@pulse-eight.com> Tue, 04 Oct 2011 23:45:00 +0200
+
libcec (0.4-1) unstable; urgency=low
* bumped interface version to 4
* @return True when initialised, false otherwise.
*/
#ifdef __cplusplus
-extern DECLSPEC bool cec_init(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
+extern DECLSPEC bool cec_init(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint8_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
#else
-extern DECLSPEC bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
+extern DECLSPEC bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, uint8_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
#endif
/*!
* @param iTimeout Connection timeout in ms.
* @return True when connected, false otherwise.
*/
-extern DECLSPEC bool cec_open(const char *strPort, int iTimeout);
+extern DECLSPEC bool cec_open(const char *strPort, uint64_t iTimeout);
/*!
* @brief Close the connection to the CEC adapter.
/*!
* @see cec_open
*/
- virtual bool Open(const char *strPort, int iTimeoutMs = 10000) = 0;
+ virtual bool Open(const char *strPort, uint64_t iTimeoutMs = 10000) = 0;
/*!
* @see cec_close
};
};
-extern DECLSPEC void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
+extern DECLSPEC void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint8_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
#if !defined(DLL_EXPORT)
#if defined(_WIN32) || defined(_WIN64)
/*!
* @see cec_init
*/
-inline CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS)
+inline CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint8_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS)
{
typedef void* (__cdecl*_CreateLibCec)(const char *, uint8_t, uint8_t);
_CreateLibCec CreateLibCec;
CreateLibCec = (_CreateLibCec) (GetProcAddress(g_libCEC, "CECCreate"));
if (!CreateLibCec)
return NULL;
- return static_cast< CEC::ICECAdapter* > (CreateLibCec(strName, iLogicalAddress, iPhysicalAddress));
+ return static_cast< CEC::ICECAdapter* > (CreateLibCec(strName, (uint8_t) iLogicalAddress, iPhysicalAddress));
}
/*!
*/
inline void UnloadLibCec(CEC::ICECAdapter *device)
{
+ device->Close();
delete device;
};
#endif

Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual Studio 2010
+# Visual C++ Express 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcec", "libcec.vcxproj", "{C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testclient", "testclient.vcxproj", "{F01222BF-6B3D-43BD-B254-434031CB9887}"
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Debug|Win32.ActiveCfg = Debug|Win32
{C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Debug|Win32.Build.0 = Debug|Win32
+ {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Release|Win32.ActiveCfg = Release|Win32
+ {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Release|Win32.Build.0 = Release|Win32
{F01222BF-6B3D-43BD-B254-434031CB9887}.Debug|Win32.ActiveCfg = Debug|Win32
{F01222BF-6B3D-43BD-B254-434031CB9887}.Debug|Win32.Build.0 = Debug|Win32
+ {F01222BF-6B3D-43BD-B254-434031CB9887}.Release|Win32.ActiveCfg = Release|Win32
+ {F01222BF-6B3D-43BD-B254-434031CB9887}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
<ClInclude Include="..\src\lib\AdapterDetection.h" />
<ClInclude Include="..\src\lib\CECProcessor.h" />
<ClInclude Include="..\src\lib\LibCEC.h" />
- <ClInclude Include="..\src\lib\libPlatform\baudrate.h" />
- <ClInclude Include="..\src\lib\libPlatform\os-dependent.h" />
- <ClInclude Include="..\src\lib\libPlatform\pthread_win32\pthread.h" />
- <ClInclude Include="..\src\lib\libPlatform\pthread_win32\sched.h" />
- <ClInclude Include="..\src\lib\libPlatform\pthread_win32\semaphore.h" />
- <ClInclude Include="..\src\lib\libPlatform\serialport.h" />
- <ClInclude Include="..\src\lib\libPlatform\windows\dlfcn-win32.h" />
- <ClInclude Include="..\src\lib\libPlatform\windows\os_windows.h" />
+ <ClInclude Include="..\src\lib\platform\baudrate.h" />
+ <ClInclude Include="..\src\lib\platform\os-dependent.h" />
+ <ClInclude Include="..\src\lib\platform\pthread_win32\pthread.h" />
+ <ClInclude Include="..\src\lib\platform\pthread_win32\sched.h" />
+ <ClInclude Include="..\src\lib\platform\pthread_win32\semaphore.h" />
+ <ClInclude Include="..\src\lib\platform\serialport.h" />
+ <ClInclude Include="..\src\lib\platform\threads.h" />
+ <ClInclude Include="..\src\lib\platform\timeutils.h" />
+ <ClInclude Include="..\src\lib\platform\windows\dlfcn-win32.h" />
+ <ClInclude Include="..\src\lib\platform\windows\os_windows.h" />
<ClInclude Include="..\src\lib\util\buffer.h" />
- <ClInclude Include="..\src\lib\util\misc.h" />
<ClInclude Include="..\src\lib\util\StdString.h" />
- <ClInclude Include="..\src\lib\util\threads.h" />
- <ClInclude Include="..\src\lib\util\timeutils.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\lib\AdapterCommunication.cpp" />
<ClCompile Include="..\src\lib\LibCEC.cpp" />
<ClCompile Include="..\src\lib\LibCECC.cpp" />
<ClCompile Include="..\src\lib\LibCECDll.cpp" />
- <ClCompile Include="..\src\lib\libPlatform\windows\dlfcn-win32.cpp" />
- <ClCompile Include="..\src\lib\libPlatform\windows\os_windows.cpp" />
- <ClCompile Include="..\src\lib\libPlatform\windows\serialport.cpp" />
- <ClCompile Include="..\src\lib\util\misc.cpp" />
- <ClCompile Include="..\src\lib\util\threads.cpp" />
- </ItemGroup>
- <ItemGroup>
- <Library Include="..\src\lib\libPlatform\pthread_win32\pthreadVC2.lib" />
- <Library Include="..\src\lib\libPlatform\pthread_win32\pthreadVC2d.lib" />
+ <ClCompile Include="..\src\lib\platform\threads.cpp" />
+ <ClCompile Include="..\src\lib\platform\windows\dlfcn-win32.cpp" />
+ <ClCompile Include="..\src\lib\platform\windows\os_windows.cpp" />
+ <ClCompile Include="..\src\lib\platform\windows\serialport.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}</ProjectGuid>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
- <WarningLevel>Level3</WarningLevel>
+ <WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE_32BIT_TIME_T;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;__WINDOWS__;DLL_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>$(SolutionDir)\..\src\lib\libPlatform\pthread_win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <DisableSpecificWarnings>4996</DisableSpecificWarnings>
+ <AdditionalIncludeDirectories>$(SolutionDir)\..\src\lib\platform\pthread_win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <DisableSpecificWarnings>4996;4100;4309</DisableSpecificWarnings>
+ <TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<OutputFile>$(SolutionDir)\..\$(TargetName)$(TargetExt)</OutputFile>
- <AdditionalDependencies>%(AdditionalDependencies);setupapi.lib</AdditionalDependencies>
+ <AdditionalDependencies>%(AdditionalDependencies);setupapi.lib;..\src\lib\platform\pthread_win32\pthreadVC2d.lib</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>libcmtd</IgnoreSpecificDefaultLibraries>
<Version>2</Version>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
- <WarningLevel>Level3</WarningLevel>
- <Optimization>MaxSpeed</Optimization>
+ <WarningLevel>Level4</WarningLevel>
+ <Optimization>Full</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
- <AdditionalIncludeDirectories>$(SolutionDir)\..\src\lib\libPlatform\pthread_win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>$(SolutionDir)\..\src\lib\platform\pthread_win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_WIN32;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE_32BIT_TIME_T;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;__WINDOWS__;DLL_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <DisableSpecificWarnings>4996</DisableSpecificWarnings>
+ <DisableSpecificWarnings>4100;4309</DisableSpecificWarnings>
+ <TreatWarningAsError>true</TreatWarningAsError>
+ <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile>
<Link>
- <GenerateDebugInformation>true</GenerateDebugInformation>
+ <GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<OutputFile>$(SolutionDir)\..\libcec.dll</OutputFile>
- <AdditionalDependencies>ws2_32.lib;$(SolutionDir)\..\src\lib\libPlatform\pthread_win32\pthreadVC2d.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>%(AdditionalDependencies);setupapi.lib;..\src\lib\platform\pthread_win32\pthreadVC2.lib</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>libcmt</IgnoreSpecificDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ClInclude Include="..\src\lib\util\buffer.h">
<Filter>util</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\util\misc.h">
- <Filter>util</Filter>
- </ClInclude>
<ClInclude Include="..\src\lib\util\StdString.h">
<Filter>util</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\util\threads.h">
- <Filter>util</Filter>
+ <ClInclude Include="..\include\CECExports.h">
+ <Filter>exports</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\libPlatform\os-dependent.h">
- <Filter>platform</Filter>
+ <ClInclude Include="..\include\CECExportsCpp.h">
+ <Filter>exports</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\libPlatform\windows\dlfcn-win32.h">
- <Filter>platform</Filter>
+ <ClInclude Include="..\include\CECTypes.h">
+ <Filter>exports</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\libPlatform\windows\os_windows.h">
- <Filter>platform</Filter>
+ <ClInclude Include="..\include\CECExportsC.h">
+ <Filter>exports</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\libPlatform\pthread_win32\pthread.h">
+ <ClInclude Include="..\src\lib\AdapterCommunication.h" />
+ <ClInclude Include="..\src\lib\AdapterDetection.h" />
+ <ClInclude Include="..\src\lib\CECProcessor.h" />
+ <ClInclude Include="..\src\lib\LibCEC.h" />
+ <ClInclude Include="..\src\lib\platform\baudrate.h">
<Filter>platform</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\libPlatform\pthread_win32\sched.h">
+ <ClInclude Include="..\src\lib\platform\os-dependent.h">
<Filter>platform</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\libPlatform\pthread_win32\semaphore.h">
+ <ClInclude Include="..\src\lib\platform\serialport.h">
<Filter>platform</Filter>
</ClInclude>
- <ClInclude Include="..\include\CECExports.h">
- <Filter>exports</Filter>
+ <ClInclude Include="..\src\lib\platform\threads.h">
+ <Filter>platform</Filter>
</ClInclude>
- <ClInclude Include="..\include\CECExportsCpp.h">
- <Filter>exports</Filter>
+ <ClInclude Include="..\src\lib\platform\timeutils.h">
+ <Filter>platform</Filter>
</ClInclude>
- <ClInclude Include="..\include\CECTypes.h">
- <Filter>exports</Filter>
+ <ClInclude Include="..\src\lib\platform\windows\dlfcn-win32.h">
+ <Filter>platform</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\libPlatform\serialport.h">
+ <ClInclude Include="..\src\lib\platform\windows\os_windows.h">
<Filter>platform</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\util\timeutils.h">
- <Filter>util</Filter>
+ <ClInclude Include="..\src\lib\platform\pthread_win32\pthread.h">
+ <Filter>platform</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\libPlatform\baudrate.h">
+ <ClInclude Include="..\src\lib\platform\pthread_win32\sched.h">
<Filter>platform</Filter>
</ClInclude>
- <ClInclude Include="..\include\CECExportsC.h">
- <Filter>exports</Filter>
+ <ClInclude Include="..\src\lib\platform\pthread_win32\semaphore.h">
+ <Filter>platform</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\AdapterCommunication.h" />
- <ClInclude Include="..\src\lib\AdapterDetection.h" />
- <ClInclude Include="..\src\lib\CECProcessor.h" />
- <ClInclude Include="..\src\lib\LibCEC.h" />
</ItemGroup>
<ItemGroup>
- <ClCompile Include="..\src\lib\util\misc.cpp">
- <Filter>util</Filter>
- </ClCompile>
- <ClCompile Include="..\src\lib\util\threads.cpp">
- <Filter>util</Filter>
- </ClCompile>
- <ClCompile Include="..\src\lib\libPlatform\windows\dlfcn-win32.cpp">
- <Filter>platform</Filter>
- </ClCompile>
- <ClCompile Include="..\src\lib\libPlatform\windows\os_windows.cpp">
- <Filter>platform</Filter>
- </ClCompile>
- <ClCompile Include="..\src\lib\libPlatform\windows\serialport.cpp">
- <Filter>platform</Filter>
- </ClCompile>
<ClCompile Include="..\src\lib\AdapterCommunication.cpp" />
<ClCompile Include="..\src\lib\AdapterDetection.cpp" />
<ClCompile Include="..\src\lib\CECProcessor.cpp" />
<ClCompile Include="..\src\lib\LibCEC.cpp" />
<ClCompile Include="..\src\lib\LibCECC.cpp" />
<ClCompile Include="..\src\lib\LibCECDll.cpp" />
- </ItemGroup>
- <ItemGroup>
- <Library Include="..\src\lib\libPlatform\pthread_win32\pthreadVC2.lib">
+ <ClCompile Include="..\src\lib\platform\threads.cpp">
<Filter>platform</Filter>
- </Library>
- <Library Include="..\src\lib\libPlatform\pthread_win32\pthreadVC2d.lib">
+ </ClCompile>
+ <ClCompile Include="..\src\lib\platform\windows\dlfcn-win32.cpp">
+ <Filter>platform</Filter>
+ </ClCompile>
+ <ClCompile Include="..\src\lib\platform\windows\os_windows.cpp">
<Filter>platform</Filter>
- </Library>
+ </ClCompile>
+ <ClCompile Include="..\src\lib\platform\windows\serialport.cpp">
+ <Filter>platform</Filter>
+ </ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
- <WarningLevel>Level3</WarningLevel>
+ <WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE_32BIT_TIME_T;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;__WINDOWS__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <TreatWarningAsError>true</TreatWarningAsError>
+ <DisableSpecificWarnings>4100;4309</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
- <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>..\src\lib\platform\pthread_win32\pthreadVC2d.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(SolutionDir)\..\$(TargetName)$(TargetExt)</OutputFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
- <WarningLevel>Level3</WarningLevel>
+ <WarningLevel>Level4</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
- <Optimization>MaxSpeed</Optimization>
- <FunctionLevelLinking>true</FunctionLevelLinking>
+ <Optimization>Full</Optimization>
+ <FunctionLevelLinking>false</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WIN32;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE_32BIT_TIME_T;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;__WINDOWS__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <TreatWarningAsError>true</TreatWarningAsError>
+ <DisableSpecificWarnings>4100;4309</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
- <GenerateDebugInformation>true</GenerateDebugInformation>
+ <GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
+ <AdditionalDependencies>$(SolutionDir)\..\src\lib\platform\pthread_win32\pthreadVC2.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\include\CECExports.h" />
<ClInclude Include="..\include\CECExportsCpp.h" />
- <ClInclude Include="..\src\lib\libPlatform\os-dependent.h" />
- <ClInclude Include="..\src\lib\libPlatform\windows\os_windows.h" />
- <ClInclude Include="..\src\lib\util\misc.h" />
+ <ClInclude Include="..\src\lib\platform\os-dependent.h" />
+ <ClInclude Include="..\src\lib\platform\threads.h" />
+ <ClInclude Include="..\src\lib\platform\windows\os_windows.h" />
<ClInclude Include="..\src\lib\util\StdString.h" />
- <ClInclude Include="..\src\lib\util\threads.h" />
- <ClInclude Include="..\src\lib\util\timeutils.h" />
</ItemGroup>
<ItemGroup>
- <ClCompile Include="..\src\lib\libPlatform\windows\os_windows.cpp" />
- <ClCompile Include="..\src\lib\util\misc.cpp" />
- <ClCompile Include="..\src\lib\util\threads.cpp" />
+ <ClCompile Include="..\src\lib\platform\threads.cpp" />
+ <ClCompile Include="..\src\lib\platform\windows\os_windows.cpp" />
<ClCompile Include="..\src\testclient\main.cpp" />
</ItemGroup>
- <ItemGroup>
- <Library Include="..\src\lib\libPlatform\pthread_win32\pthreadVC2.lib" />
- <Library Include="..\src\lib\libPlatform\pthread_win32\pthreadVC2d.lib" />
- </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<ClInclude Include="..\include\CECExportsCpp.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\util\misc.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="..\src\lib\util\threads.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="..\src\lib\util\StdString.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\util\timeutils.h">
+ <ClInclude Include="..\src\lib\platform\threads.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\libPlatform\os-dependent.h">
+ <ClInclude Include="..\src\lib\platform\os-dependent.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\libPlatform\windows\os_windows.h">
+ <ClInclude Include="..\src\lib\platform\windows\os_windows.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ClCompile Include="..\src\testclient\main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\src\lib\util\misc.cpp">
+ <ClCompile Include="..\src\lib\platform\threads.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\src\lib\util\threads.cpp">
+ <ClCompile Include="..\src\lib\platform\windows\os_windows.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\src\lib\libPlatform\windows\os_windows.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- </ItemGroup>
- <ItemGroup>
- <Library Include="..\src\lib\libPlatform\pthread_win32\pthreadVC2.lib">
- <Filter>Resource Files</Filter>
- </Library>
- <Library Include="..\src\lib\libPlatform\pthread_win32\pthreadVC2d.lib">
- <Filter>Resource Files</Filter>
- </Library>
</ItemGroup>
</Project>
\ No newline at end of file
#include "AdapterCommunication.h"
#include "LibCEC.h"
-#include "libPlatform/serialport.h"
+#include "platform/serialport.h"
#include "util/StdString.h"
using namespace std;
CAdapterCommunication::~CAdapterCommunication(void)
{
+ StopThread();
m_port->Close();
+ delete m_port;
m_port = NULL;
}
-bool CAdapterCommunication::Open(const char *strPort, int iBaudRate /* = 38400 */, int iTimeoutMs /* = 10000 */)
+bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint64_t iTimeoutMs /* = 10000 */)
{
CLockObject lock(&m_commMutex);
if (m_bStarted)
break;
}
- CCondition::Sleep(50);
+ if (!m_bStop)
+ CCondition::Sleep(50);
}
- m_controller->AddLog(CEC_LOG_DEBUG, "reader thread terminated");
-
CLockObject lock(&m_commMutex);
m_bStarted = false;
return NULL;
}
-bool CAdapterCommunication::ReadFromDevice(int iTimeout)
+bool CAdapterCommunication::ReadFromDevice(uint64_t iTimeout)
{
uint8_t buff[1024];
CLockObject lock(&m_commMutex);
- int iBytesRead = m_port->Read(buff, sizeof(buff), iTimeout);
+ if (!m_port)
+ return false;
+
+ int32_t iBytesRead = m_port->Read(buff, sizeof(buff), iTimeout);
lock.Leave();
- if (iBytesRead < 0)
+ if (iBytesRead < 0 || iBytesRead > 256)
{
CStdString strError;
strError.Format("error reading from serial port: %s", m_port->GetError().c_str());
return false;
}
else if (iBytesRead > 0)
- AddData(buff, iBytesRead);
+ AddData(buff, (uint8_t) iBytesRead);
return true;
}
-void CAdapterCommunication::AddData(uint8_t *data, int iLen)
+void CAdapterCommunication::AddData(uint8_t *data, uint8_t iLen)
{
CLockObject lock(&m_bufferMutex);
if (iLen + m_iInbufUsed > m_iInbufSize)
{
CLockObject lock(&m_commMutex);
- if (m_port->Write(data) != data.size())
+ if (m_port->Write(data) != (int) data.size())
{
CStdString strError;
strError.Format("error writing to serial port: %s", m_port->GetError().c_str());
return true;
}
-bool CAdapterCommunication::Read(cec_frame &msg, int iTimeout)
+bool CAdapterCommunication::Read(cec_frame &msg, uint64_t iTimeout)
{
CLockObject lock(&m_bufferMutex);
*/
#include "../../include/CECExports.h"
-#include "util/threads.h"
-
-class CSerialPort;
+#include "platform/threads.h"
namespace CEC
{
+ class CSerialPort;
class CLibCEC;
class CAdapterCommunication : CThread
CAdapterCommunication(CLibCEC *controller);
virtual ~CAdapterCommunication();
- bool Open(const char *strPort, int iBaudRate = 38400, int iTimeoutMs = 10000);
- bool Read(cec_frame &msg, int iTimeout = 1000);
+ bool Open(const char *strPort, uint16_t iBaudRate = 38400, uint64_t iTimeoutMs = 10000);
+ bool Read(cec_frame &msg, uint64_t iTimeout = 1000);
bool Write(const cec_frame &frame);
bool PingAdapter(void);
void Close(void);
bool SetAckMask(uint16_t iMask);
static void PushEscaped(cec_frame &vec, uint8_t byte);
private:
- void AddData(uint8_t *data, int iLen);
- bool ReadFromDevice(int iTimeout);
+ void AddData(uint8_t *data, uint8_t iLen);
+ bool ReadFromDevice(uint64_t iTimeout);
CSerialPort * m_port;
CLibCEC * m_controller;
*/
#include "AdapterDetection.h"
-#include "libPlatform/os-dependent.h"
+#include "platform/os-dependent.h"
#include "util/StdString.h"
#if !defined(__WINDOWS__)
#include "AdapterCommunication.h"
#include "LibCEC.h"
#include "util/StdString.h"
-#include "util/timeutils.h"
+#include "platform/timeutils.h"
using namespace CEC;
using namespace std;
bParseFrame = ParseMessage(msg);
}
- if (bParseFrame)
+ if (!m_bStop && bParseFrame)
ParseCurrentFrame();
- m_controller->CheckKeypressTimeout();
- CCondition::Sleep(50);
+ if (!m_bStop)
+ {
+ m_controller->CheckKeypressTimeout();
+ CCondition::Sleep(50);
+ }
}
- m_controller->AddLog(CEC_LOG_DEBUG, "processor thread terminated");
return NULL;
}
m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
cec_frame frame;
frame.push_back(GetSourceDestination(address));
- frame.push_back(CEC_OPCODE_TEXT_VIEW_ON);
+ frame.push_back((uint8_t) CEC_OPCODE_TEXT_VIEW_ON);
return Transmit(frame);
}
m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
cec_frame frame;
frame.push_back(GetSourceDestination(address));
- frame.push_back(CEC_OPCODE_STANDBY);
+ frame.push_back((uint8_t) CEC_OPCODE_STANDBY);
return Transmit(frame);
}
m_controller->AddLog(CEC_LOG_DEBUG, "setting active view");
cec_frame frame;
frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST));
- frame.push_back(CEC_OPCODE_ACTIVE_SOURCE);
+ frame.push_back((uint8_t) CEC_OPCODE_ACTIVE_SOURCE);
frame.push_back((m_physicaladdress >> 8) & 0xFF);
frame.push_back(m_physicaladdress & 0xFF);
return Transmit(frame);
m_controller->AddLog(CEC_LOG_DEBUG, "setting inactive view");
cec_frame frame;
frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST));
- frame.push_back(CEC_OPCODE_INACTIVE_SOURCE);
+ frame.push_back((uint8_t) CEC_OPCODE_INACTIVE_SOURCE);
frame.push_back((m_physicaladdress >> 8) & 0xFF);
frame.push_back(m_physicaladdress & 0xFF);
return Transmit(frame);
m_controller->AddLog(CEC_LOG_DEBUG, "transmitting abort message");
cec_frame frame;
frame.push_back(GetSourceDestination(address));
- frame.push_back(CEC_OPCODE_FEATURE_ABORT);
- frame.push_back(opcode);
- frame.push_back(reason);
+ frame.push_back((uint8_t) CEC_OPCODE_FEATURE_ABORT);
+ frame.push_back((uint8_t) opcode);
+ frame.push_back((uint8_t) reason);
Transmit(frame);
}
cec_frame frame;
m_controller->AddLog(CEC_LOG_NOTICE, "reporting CEC version as 1.3a");
frame.push_back(GetSourceDestination(address));
- frame.push_back(CEC_OPCODE_CEC_VERSION);
+ frame.push_back((uint8_t) CEC_OPCODE_CEC_VERSION);
frame.push_back(CEC_VERSION_1_3A);
Transmit(frame);
}
m_controller->AddLog(CEC_LOG_NOTICE, "reporting \"Off\" power status");
frame.push_back(GetSourceDestination(address));
- frame.push_back(CEC_OPCODE_REPORT_POWER_STATUS);
- frame.push_back(bOn ? CEC_POWER_STATUS_ON : CEC_POWER_STATUS_STANDBY);
+ frame.push_back((uint8_t) CEC_OPCODE_REPORT_POWER_STATUS);
+ frame.push_back(bOn ? (uint8_t) CEC_POWER_STATUS_ON : (uint8_t) CEC_POWER_STATUS_STANDBY);
Transmit(frame);
}
m_controller->AddLog(CEC_LOG_NOTICE, "reporting menu state as inactive");
frame.push_back(GetSourceDestination(address));
- frame.push_back(CEC_OPCODE_MENU_STATUS);
- frame.push_back(bActive ? CEC_MENU_STATE_ACTIVATED : CEC_MENU_STATE_DEACTIVATED);
+ frame.push_back((uint8_t) CEC_OPCODE_MENU_STATUS);
+ frame.push_back(bActive ? (uint8_t) CEC_MENU_STATE_ACTIVATED : (uint8_t) CEC_MENU_STATE_DEACTIVATED);
Transmit(frame);
}
strLog.Format("reporting OSD name as %s", osdname);
m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
frame.push_back(GetSourceDestination(address));
- frame.push_back(CEC_OPCODE_SET_OSD_NAME);
+ frame.push_back((uint8_t) CEC_OPCODE_SET_OSD_NAME);
for (unsigned int i = 0; i < strlen(osdname); i++)
frame.push_back(osdname[i]);
strLog.Format("reporting physical address as %04x", m_physicaladdress);
m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST));
- frame.push_back(CEC_OPCODE_REPORT_PHYSICAL_ADDRESS);
+ frame.push_back((uint8_t) CEC_OPCODE_REPORT_PHYSICAL_ADDRESS);
frame.push_back((m_physicaladdress >> 8) & 0xFF);
frame.push_back(m_physicaladdress & 0xFF);
frame.push_back(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
cec_frame frame;
m_controller->AddLog(CEC_LOG_NOTICE, "broadcasting active source");
frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST));
- frame.push_back(CEC_OPCODE_ACTIVE_SOURCE);
+ frame.push_back((uint8_t) CEC_OPCODE_ACTIVE_SOURCE);
frame.push_back((m_physicaladdress >> 8) & 0xFF);
frame.push_back(m_physicaladdress & 0xFF);
Transmit(frame);
#include "../../include/CECExports.h"
#include "../../include/CECTypes.h"
-#include "util/threads.h"
+#include "platform/threads.h"
#include "util/buffer.h"
class CSerialPort;
#include "AdapterDetection.h"
#include "CECProcessor.h"
#include "util/StdString.h"
-#include "util/timeutils.h"
+#include "platform/timeutils.h"
using namespace std;
using namespace CEC;
-CLibCEC::CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, int iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) :
+CLibCEC::CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint8_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) :
m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN),
m_buttontime(0)
{
m_comm = NULL;
}
-bool CLibCEC::Open(const char *strPort, int iTimeoutMs /* = 10000 */)
+bool CLibCEC::Open(const char *strPort, uint64_t iTimeoutMs /* = 10000 */)
{
if (!m_comm)
return false;
void CLibCEC::Close(void)
{
if (m_cec)
+ {
m_cec->StopThread();
+ delete m_cec;
+ m_cec = NULL;
+ }
if (m_comm)
+ {
m_comm->Close();
+ delete m_comm;
+ m_comm = NULL;
+ }
}
int CLibCEC::FindAdapters(std::vector<cec_adapter> &deviceList, const char *strDevicePath /* = NULL */)
m_buttontime = GetTimeMs();
}
-DECLSPEC void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress /*= CEC::CECDEVICE_PLAYBACKDEVICE1 */, int iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
+DECLSPEC void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress /*= CEC::CECDEVICE_PLAYBACKDEVICE1 */, uint8_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
{
return static_cast< void* > (new CLibCEC(strDeviceName, iLogicalAddress, iPhysicalAddress));
}
* ICECAdapter implementation
*/
//@{
- CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
+ CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, uint8_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
virtual ~CLibCEC(void);
- virtual bool Open(const char *strPort, int iTimeout = 10000);
+ virtual bool Open(const char *strPort, uint64_t iTimeout = 10000);
virtual void Close(void);
virtual int FindAdapters(std::vector<cec_adapter> &deviceList, const char *strDevicePath = NULL);
virtual bool PingAdapter(void);
//@{
ICECAdapter *cec_parser;
-bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, int iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
+bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint8_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
{
cec_parser = (ICECAdapter *) CECCreate(strDeviceName, iLogicalAddress, iPhysicalAddress);
return (cec_parser != NULL);
cec_parser = NULL;
}
-bool cec_open(const char *strPort, int iTimeout)
+bool cec_open(const char *strPort, uint64_t iTimeout)
{
if (cec_parser)
return cec_parser->Open(strPort, iTimeout);
../../include/CECExports.h \
../../include/CECExportsCpp.h \
../../include/CECExportsC.h \
- util/misc.cpp \
- util/misc.h \
util/StdString.h \
- util/threads.cpp \
- util/threads.h \
- util/timeutils.h \
- libPlatform/baudrate.h \
- libPlatform/os-dependent.h \
- libPlatform/linux/os_posix.h \
- libPlatform/linux/serialport.cpp \
- libPlatform/serialport.h
+ platform/timeutils.h \
+ platform/baudrate.h \
+ platform/os-dependent.h \
+ platform/linux/os_posix.h \
+ platform/linux/serialport.cpp \
+ platform/serialport.h \
+ platform/threads.cpp \
+ platform/threads.h
libcec_la_LDFLAGS = -lrt -lpthread -ludev -version-info @VERSION@
+++ /dev/null
-#pragma once
-
-/*
- * boblight
- * Copyright (C) Bob 2009
- *
- * boblight is free software: 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 3 of the License, or
- * (at your option) any later version.
- *
- * boblight 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, see <http://www.gnu.org/licenses/>.
- */
-
-//every baudrate I could find is in here in an #ifdef block
-//so it should compile on everything
-
-static struct sbaudrate
-{
- int rate;
- int symbol;
-}
-baudrates[] =
-{
-#ifdef B50
- { 50, B50 },
-#endif
-#ifdef B75
- { 75, B75 },
-#endif
-#ifdef B110
- { 110, B110 },
-#endif
-#ifdef B134
- { 134, B134 },
-#endif
-#ifdef B150
- { 150, B150 },
-#endif
-#ifdef B200
- { 200, B200 },
-#endif
-#ifdef B300
- { 300, B300 },
-#endif
-#ifdef B600
- { 600, B600 },
-#endif
-#ifdef B1200
- { 1200, B1200 },
-#endif
-#ifdef B1800
- { 1800, B1800 },
-#endif
-#ifdef B2400
- { 2400, B2400 },
-#endif
-#ifdef B4800
- { 4800, B4800 },
-#endif
-#ifdef B9600
- { 9600, B9600 },
-#endif
-#ifdef B14400
- { 14400, B14400 },
-#endif
-#ifdef B19200
- { 19200, B19200 },
-#endif
-#ifdef B28800
- { 28800, B28800 },
-#endif
-#ifdef B38400
- { 38400, B38400 },
-#endif
-#ifdef B57600
- { 57600, B57600 },
-#endif
-#ifdef B76800
- { 76800, B76800 },
-#endif
-#ifdef B115200
- { 115200, B115200 },
-#endif
-#ifdef B230400
- { 230400, B230400 },
-#endif
-#ifdef B250000
- { 250000, B250000 },
-#endif
-#ifdef B460800
- { 460800, B460800 },
-#endif
-#ifdef B500000
- { 500000, B500000 },
-#endif
-#ifdef B576000
- { 576000, B576000 },
-#endif
-#ifdef B921600
- { 921600, B921600 },
-#endif
-#ifdef B1000000
- { 1000000, B1000000 },
-#endif
-#ifdef B1152000
- { 1152000, B1152000 },
-#endif
-#ifdef B1500000
- { 1500000, B1500000 },
-#endif
-#ifdef B2000000
- { 2000000, B2000000 },
-#endif
-#ifdef B2500000
- { 2500000, B2500000 },
-#endif
-#ifdef B3000000
- { 3000000, B3000000 },
-#endif
-#ifdef B3500000
- { 3500000, B3500000 },
-#endif
-#ifdef B4000000
- { 4000000, B4000000 },
-#endif
-#ifdef CBR_110
- { 110, CBR_110 },
-#endif
-#ifdef CBR_300
- { 300, CBR_300 },
-#endif
-#ifdef CBR_600
- { 600, CBR_600 },
-#endif
-#ifdef CBR_1200
- { 1200, CBR_1200 },
-#endif
-#ifdef CBR_2400
- { 2400, CBR_2400 },
-#endif
-#ifdef CBR_4800
- { 4800, CBR_4800 },
-#endif
-#ifdef CBR_9600
- { 9600, CBR_9600 },
-#endif
-#ifdef CBR_11400
- { 11400, CBR_14400 },
-#endif
-#ifdef CBR_19200
- { 19200, CBR_19200 },
-#endif
-#ifdef CBR_38400
- { 38400, CBR_38400 },
-#endif
-#ifdef CBR_56000
- { 56000, CBR_56000 },
-#endif
-#ifdef CBR_57600
- { 57600, CBR_57600 },
-#endif
-#ifdef CBR_115200
- { 115200, CBR_115200 },
-#endif
-#ifdef CBR_128000
- { 128000, CBR_128000 },
-#endif
-#ifdef CBR_256000
- { 256000, CBR_256000 },
-#endif
- { -1, -1}
-};
+++ /dev/null
-#pragma once
-
-/*
- * boblight
- * Copyright (C) Bob 2009
- *
- * boblight is free software: 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 3 of the License, or
- * (at your option) any later version.
- *
- * boblight 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, see <http://www.gnu.org/licenses/>.
- */
-
-#include "os-dependent.h"
-#include <string>
-#include <vector>
-#include <stdint.h>
-
-#ifndef __WINDOWS__
-#include <termios.h>
-#else
-#include "../util/threads.h"
-#include "../util/buffer.h"
-
-class CSerialPort;
-
-typedef struct serial_cancel_options
-{
- CSerialPort *instance;
- uint64_t iWaitMs;
-} serial_cancel_options;
-
-#endif
-
-#define PAR_NONE 0
-#define PAR_EVEN 1
-#define PAR_ODD 2
-
-#include "baudrate.h"
-
-class CSerialPort
-{
- public:
- CSerialPort();
- virtual ~CSerialPort();
-
- bool Open(std::string name, int baudrate, int databits = 8, int stopbits = 1, int parity = PAR_NONE);
- void Close();
- int Write(std::vector<uint8_t> data)
- {
- return Write(&data[0], data.size());
- }
-
- int Write(uint8_t* data, int len);
- int Read(uint8_t* data, int len, int iTimeoutMs = -1);
-
- std::string GetError() { return m_name + ": " + m_error; }
- std::string GetName() { return m_name; }
-
- bool SetBaudRate(int baudrate);
-
- int IntToRate(int baudrate)
- {
- for (unsigned int i = 0; i < sizeof(baudrates) / sizeof(sbaudrate) - 1; i++)
- {
- if (baudrates[i].rate == baudrate)
- {
- return baudrates[i].symbol;
- }
- }
- return -1;
- };
-
-#ifdef __WINDOWS__
- bool IsOpen() const { return m_bIsOpen; }
-#else
- bool IsOpen() const { return m_fd != -1; }
-#endif
-
-private:
- std::string m_error;
- std::string m_name;
-
-#ifdef __WINDOWS__
- bool SetTimeouts(bool bBlocking);
-
- HANDLE m_handle;
- bool m_bIsOpen;
- int m_iBaudrate;
- int m_iDatabits;
- int m_iStopbits;
- int m_iParity;
- int64_t m_iTimeout;
- CecBuffer<uint8_t> m_buffer;
- HANDLE m_ovHandle;
-#else
- struct termios m_options;
- int m_fd;
-#endif
-};
--- /dev/null
+#pragma once
+
+/*
+ * boblight
+ * Copyright (C) Bob 2009
+ *
+ * boblight is free software: 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * boblight 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, see <http://www.gnu.org/licenses/>.
+ */
+
+//every baudrate I could find is in here in an #ifdef block
+//so it should compile on everything
+
+#include "os-dependent.h"
+
+#ifndef __WINDOWS__
+#include <termios.h>
+#endif
+
+namespace CEC
+{
+ static struct sbaudrate
+ {
+ int32_t rate;
+ int32_t symbol;
+ }
+ baudrates[] =
+ {
+ #ifdef B50
+ { 50, B50 },
+ #endif
+ #ifdef B75
+ { 75, B75 },
+ #endif
+ #ifdef B110
+ { 110, B110 },
+ #endif
+ #ifdef B134
+ { 134, B134 },
+ #endif
+ #ifdef B150
+ { 150, B150 },
+ #endif
+ #ifdef B200
+ { 200, B200 },
+ #endif
+ #ifdef B300
+ { 300, B300 },
+ #endif
+ #ifdef B600
+ { 600, B600 },
+ #endif
+ #ifdef B1200
+ { 1200, B1200 },
+ #endif
+ #ifdef B1800
+ { 1800, B1800 },
+ #endif
+ #ifdef B2400
+ { 2400, B2400 },
+ #endif
+ #ifdef B4800
+ { 4800, B4800 },
+ #endif
+ #ifdef B9600
+ { 9600, B9600 },
+ #endif
+ #ifdef B14400
+ { 14400, B14400 },
+ #endif
+ #ifdef B19200
+ { 19200, B19200 },
+ #endif
+ #ifdef B28800
+ { 28800, B28800 },
+ #endif
+ #ifdef B38400
+ { 38400, B38400 },
+ #endif
+ #ifdef B57600
+ { 57600, B57600 },
+ #endif
+ #ifdef B76800
+ { 76800, B76800 },
+ #endif
+ #ifdef B115200
+ { 115200, B115200 },
+ #endif
+ #ifdef B230400
+ { 230400, B230400 },
+ #endif
+ #ifdef B250000
+ { 250000, B250000 },
+ #endif
+ #ifdef B460800
+ { 460800, B460800 },
+ #endif
+ #ifdef B500000
+ { 500000, B500000 },
+ #endif
+ #ifdef B576000
+ { 576000, B576000 },
+ #endif
+ #ifdef B921600
+ { 921600, B921600 },
+ #endif
+ #ifdef B1000000
+ { 1000000, B1000000 },
+ #endif
+ #ifdef B1152000
+ { 1152000, B1152000 },
+ #endif
+ #ifdef B1500000
+ { 1500000, B1500000 },
+ #endif
+ #ifdef B2000000
+ { 2000000, B2000000 },
+ #endif
+ #ifdef B2500000
+ { 2500000, B2500000 },
+ #endif
+ #ifdef B3000000
+ { 3000000, B3000000 },
+ #endif
+ #ifdef B3500000
+ { 3500000, B3500000 },
+ #endif
+ #ifdef B4000000
+ { 4000000, B4000000 },
+ #endif
+ #ifdef CBR_110
+ { 110, CBR_110 },
+ #endif
+ #ifdef CBR_300
+ { 300, CBR_300 },
+ #endif
+ #ifdef CBR_600
+ { 600, CBR_600 },
+ #endif
+ #ifdef CBR_1200
+ { 1200, CBR_1200 },
+ #endif
+ #ifdef CBR_2400
+ { 2400, CBR_2400 },
+ #endif
+ #ifdef CBR_4800
+ { 4800, CBR_4800 },
+ #endif
+ #ifdef CBR_9600
+ { 9600, CBR_9600 },
+ #endif
+ #ifdef CBR_11400
+ { 11400, CBR_14400 },
+ #endif
+ #ifdef CBR_19200
+ { 19200, CBR_19200 },
+ #endif
+ #ifdef CBR_38400
+ { 38400, CBR_38400 },
+ #endif
+ #ifdef CBR_56000
+ { 56000, CBR_56000 },
+ #endif
+ #ifdef CBR_57600
+ { 57600, CBR_57600 },
+ #endif
+ #ifdef CBR_115200
+ { 115200, CBR_115200 },
+ #endif
+ #ifdef CBR_128000
+ { 128000, CBR_128000 },
+ #endif
+ #ifdef CBR_256000
+ { 256000, CBR_256000 },
+ #endif
+ { -1, -1}
+ };
+
+ static int32_t IntToBaudrate(uint32_t baudrate)
+ {
+ for (unsigned int i = 0; i < sizeof(baudrates) / sizeof(CEC::sbaudrate) - 1; i++)
+ {
+ if (baudrates[i].rate == (int32_t) baudrate)
+ return baudrates[i].symbol;
+ }
+
+ return -1;
+ };
+};
*/
#define _FILE_OFFSET_BITS 64
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
#include <string.h>
-#include <stdint.h>
-#include <unistd.h>
#include <errno.h>
-#include <fcntl.h>
-#include <sys/types.h>
#include <sys/time.h>
-#include <sys/timeb.h>
-#include <sys/resource.h>
-#include <sys/syscall.h>
#ifndef __APPLE__
#include <sys/prctl.h>
#endif
#define LIBTYPE
#define DECLSPEC
-
-#ifndef _STL_ALGOBASE_H
-template<class T> inline T min(T a, T b) { return a <= b ? a : b; }
-template<class T> inline T max(T a, T b) { return a >= b ? a : b; }
-template<class T> inline int sgn(T a) { return a < 0 ? -1 : a > 0 ? 1 : 0; }
-template<class T> inline void swap(T &a, T &b) { T t = a; a = b; b = t; }
-#endif
-
-/*!
- * @return the current time in seconds since unix epoch.
- */
-static inline uint64_t getcurrenttime(void)
-{
- struct timeval t;
- gettimeofday(&t, NULL);
- return ((uint64_t)t.tv_sec * 1000) + (t.tv_usec / 1000);
-}
* 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()
Close();
}
-int CSerialPort::Write(uint8_t* data, int len)
+int32_t CSerialPort::Write(uint8_t* data, uint32_t len)
{
fd_set port;
-
+
+ CLockObject lock(&m_mutex);
if (m_fd == -1)
{
m_error = "port closed";
return -1;
}
- int byteswritten = 0;
+ int32_t byteswritten = 0;
- while (byteswritten < len)
+ while (byteswritten < (int32_t) len)
{
FD_ZERO(&port);
FD_SET(m_fd, &port);
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;
return byteswritten;
}
-int CSerialPort::Read(uint8_t* data, int len, int iTimeoutMs /*= -1*/)
+int32_t CSerialPort::Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs /*= 0*/)
{
fd_set port;
struct timeval timeout, *tv;
- int64_t now, target;
- int bytesread = 0;
+ int64_t now(0), target(0);
+ int32_t bytesread = 0;
+ CLockObject lock(&m_mutex);
if (m_fd == -1)
{
m_error = "port closed";
return -1;
}
- if (iTimeoutMs >= 0)
+ if (iTimeoutMs > 0)
{
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;
}
FD_ZERO(&port);
FD_SET(m_fd, &port);
- int returnv = select(m_fd + 1, &port, NULL, NULL, tv);
+ int32_t returnv = select(m_fd + 1, &port, NULL, NULL, tv);
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;
}
}
//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 = GetErrno();
-
+ m_error = strerror(errno);
+ CLockObject lock(&m_mutex);
+
if (databits < 5 || databits > 8)
{
m_error = "Databits has to be between 5 and 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;
}
void CSerialPort::Close()
{
+ CLockObject lock(&m_mutex);
if (m_fd != -1)
{
close(m_fd);
}
}
-bool CSerialPort::SetBaudRate(int baudrate)
+bool CSerialPort::SetBaudRate(uint32_t 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()
+{
+ CLockObject lock(&m_mutex);
+ return m_fd != -1;
+}
--- /dev/null
+#pragma once
+
+/*
+ * boblight
+ * Copyright (C) Bob 2009
+ *
+ * boblight is free software: 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * boblight 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "os-dependent.h"
+#include <string>
+#include <vector>
+#include <stdint.h>
+#include "../platform/threads.h"
+
+#ifndef __WINDOWS__
+#include <termios.h>
+#else
+#include "../util/buffer.h"
+#endif
+
+namespace CEC
+{
+ #define PAR_NONE 0
+ #define PAR_EVEN 1
+ #define PAR_ODD 2
+
+ class CSerialPort
+ {
+ public:
+ CSerialPort();
+ virtual ~CSerialPort();
+
+ bool Open(std::string name, uint32_t baudrate, uint8_t databits = 8, uint8_t stopbits = 1, uint8_t parity = PAR_NONE);
+ bool IsOpen();
+ void Close();
+
+ int32_t Write(std::vector<uint8_t> data)
+ {
+ return Write(&data[0], (uint32_t) data.size());
+ }
+ int32_t Write(uint8_t* data, uint32_t len);
+ int32_t Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs = 0);
+
+ std::string GetError() { return m_error; }
+ std::string GetName() { return m_name; }
+
+ private:
+ bool SetBaudRate(uint32_t baudrate);
+
+ std::string m_error;
+ std::string m_name;
+ CMutex m_mutex;
+
+ #ifdef __WINDOWS__
+ bool SetTimeouts(bool bBlocking);
+
+ HANDLE m_handle;
+ bool m_bIsOpen;
+ uint32_t m_iBaudrate;
+ uint8_t m_iDatabits;
+ uint8_t m_iStopbits;
+ uint8_t m_iParity;
+ int64_t m_iTimeout;
+ CecBuffer<uint8_t> m_buffer;
+ HANDLE m_ovHandle;
+ #else
+ struct termios m_options;
+ int m_fd;
+ #endif
+ };
+};
#include "threads.h"
#include "timeutils.h"
+using namespace CEC;
+
CMutex::CMutex(void)
{
pthread_mutex_init(&m_mutex, NULL);
CCondition w;
CMutex m;
CLockObject lock(&m);
- w.Wait(&m, iTimeout);
+ w.Wait(&m, int64_t(iTimeout));
}
CThread::CThread(void) :
* http://www.pulse-eight.net/
*/
-#include "../libPlatform/os-dependent.h"
+#include "os-dependent.h"
-class CMutex;
-
-class CCondition
+namespace CEC
{
-public:
- CCondition(void);
- virtual ~CCondition(void);
+ class CMutex;
- void Signal(void);
- bool Wait(CMutex *mutex, int64_t iTimeout);
- static void Sleep(int iTimeout);
+ class CCondition
+ {
+ public:
+ CCondition(void);
+ virtual ~CCondition(void);
-private:
- pthread_cond_t m_cond;
-};
+ void Signal(void);
+ bool Wait(CMutex *mutex, int64_t iTimeout);
+ static void Sleep(int iTimeout);
-class CMutex
-{
-public:
- CMutex(void);
- virtual ~CMutex(void);
+ private:
+ pthread_cond_t m_cond;
+ };
- bool TryLock(void);
- bool Lock(void);
- void Unlock(void);
+ class CMutex
+ {
+ public:
+ CMutex(void);
+ virtual ~CMutex(void);
- pthread_mutex_t m_mutex;
-};
+ bool TryLock(void);
+ bool Lock(void);
+ void Unlock(void);
-class CLockObject
-{
-public:
- CLockObject(CMutex *mutex);
- ~CLockObject(void);
+ pthread_mutex_t m_mutex;
+ };
- bool IsLocked(void) const { return m_bLocked; }
- void Leave(void);
- void Lock(void);
+ class CLockObject
+ {
+ public:
+ CLockObject(CMutex *mutex);
+ ~CLockObject(void);
-private:
- CMutex *m_mutex;
- bool m_bLocked;
-};
+ bool IsLocked(void) const { return m_bLocked; }
+ void Leave(void);
+ void Lock(void);
-class CThread
-{
-public:
- CThread(void);
- virtual ~CThread(void);
+ private:
+ CMutex *m_mutex;
+ bool m_bLocked;
+ };
+
+ class CThread
+ {
+ public:
+ CThread(void);
+ virtual ~CThread(void);
- virtual bool IsRunning(void) const { return m_bRunning; }
- virtual bool CreateThread(void);
- virtual void StopThread(bool bWaitForExit = true);
+ virtual bool IsRunning(void) const { return m_bRunning; }
+ virtual bool CreateThread(void);
+ virtual void StopThread(bool bWaitForExit = true);
- static void *ThreadHandler(CThread *thread);
- virtual void *Process(void) = 0;
+ static void *ThreadHandler(CThread *thread);
+ virtual void *Process(void) = 0;
-protected:
- pthread_t m_thread;
- bool m_bRunning;
- bool m_bStop;
+ protected:
+ pthread_t m_thread;
+ bool m_bRunning;
+ bool m_bStop;
+ };
};
#include <stdint.h>
#include <time.h>
-inline int64_t GetTimeMs()
+namespace CEC
{
-#ifdef __WINDOWS__
- time_t rawtime;
- time(&rawtime);
-
- LARGE_INTEGER tickPerSecond;
- LARGE_INTEGER tick;
- if (QueryPerformanceFrequency(&tickPerSecond))
+ inline int64_t GetTimeMs()
{
- QueryPerformanceCounter(&tick);
- return (int64_t) (tick.QuadPart / 1000.);
- }
- return -1;
-#else
- struct timespec time;
- clock_gettime(CLOCK_MONOTONIC, &time);
+ #ifdef __WINDOWS__
+ time_t rawtime;
+ time(&rawtime);
- return ((int64_t)time.tv_sec * (int64_t)1000) + (int64_t)time.tv_nsec / (int64_t)1000;
-#endif
-}
+ LARGE_INTEGER tickPerSecond;
+ LARGE_INTEGER tick;
+ if (QueryPerformanceFrequency(&tickPerSecond))
+ {
+ QueryPerformanceCounter(&tick);
+ return (int64_t) (tick.QuadPart / 1000.);
+ }
+ return -1;
+ #else
+ struct timespec time;
+ clock_gettime(CLOCK_MONOTONIC, &time);
-template <class T>
-inline T GetTimeSec()
-{
- return (T)GetTimeMs() / (T)1000.0;
-}
+ return ((int64_t)time.tv_sec * (int64_t)1000) + (int64_t)time.tv_nsec / (int64_t)1000;
+ #endif
+ }
-void USleep(int64_t usecs, volatile bool* stop = NULL);
+ template <class T>
+ inline T GetTimeSec()
+ {
+ return (T)GetTimeMs() / (T)1000.0;
+ }
+};
#include "../serialport.h"
#include "../baudrate.h"
-#include "../../util/timeutils.h"
+#include "../timeutils.h"
using namespace std;
+using namespace CEC;
void FormatWindowsError(int iErrorCode, string &strMessage)
{
Close();
}
-bool CSerialPort::Open(string name, int baudrate, int databits, int stopbits, int parity)
+bool CSerialPort::Open(string name, uint32_t baudrate, uint8_t databits, uint8_t stopbits, uint8_t parity)
{
+ CLockObject lock(&m_mutex);
m_handle = CreateFile(name.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (m_handle == INVALID_HANDLE_VALUE)
{
void CSerialPort::Close(void)
{
+ CLockObject lock(&m_mutex);
if (m_bIsOpen)
{
CloseHandle(m_handle);
}
}
-int CSerialPort::Write(uint8_t* data, int len)
+int32_t CSerialPort::Write(uint8_t* data, uint32_t len)
{
+ CLockObject lock(&m_mutex);
DWORD iBytesWritten = 0;
if (!m_bIsOpen)
return -1;
return -1;
}
- return (int) iBytesWritten;
+ return iBytesWritten;
}
-int CSerialPort::Read(uint8_t* data, int len, int iTimeoutMs /* = -1 */)
+int32_t CSerialPort::Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs /* = 0 */)
{
+ CLockObject lock(&m_mutex);
+ int32_t iReturn(-1);
DWORD iBytesRead = 0;
if (m_handle == 0)
{
m_error = "Error while reading from COM port: invalid handle";
- return -1;
+ return iReturn;
}
if(!ReadFile(m_handle, data, len, &iBytesRead, NULL) != 0)
{
m_error = "unable to read from device";
FormatWindowsError(GetLastError(), m_error);
- iBytesRead = -1;
+ iReturn = -1;
+ }
+ else
+ {
+ iReturn = (int32_t) iBytesRead;
}
- return (int) iBytesRead;
+ return iReturn;
}
-bool CSerialPort::SetBaudRate(int baudrate)
+bool CSerialPort::SetBaudRate(uint32_t baudrate)
{
- m_iBaudrate = baudrate;
+ int32_t rate = IntToBaudrate(baudrate);
+ if (rate < 0)
+ m_iBaudrate = baudrate > 0 ? baudrate : 0;
+ else
+ m_iBaudrate = rate;
DCB dcb;
memset(&dcb,0,sizeof(dcb));
dcb.DCBlength = sizeof(dcb);
- dcb.BaudRate = IntToRate(m_iBaudrate);
+ dcb.BaudRate = IntToBaudrate(m_iBaudrate);
dcb.fBinary = true;
dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
return true;
}
+
+bool CSerialPort::IsOpen()
+{
+ CLockObject lock(&m_mutex);
+ return m_bIsOpen;
+}
* http://www.pulse-eight.net/
*/
-#include "threads.h"
+#include "../platform/threads.h"
#include <queue>
-template<typename _BType>
- struct CecBuffer
- {
- public:
- CecBuffer(int iMaxSize = 100)
+namespace CEC
+{
+ template<typename _BType>
+ struct CecBuffer
{
- m_maxSize = iMaxSize;
- }
- virtual ~CecBuffer(void) {}
+ public:
+ CecBuffer(unsigned int iMaxSize = 100)
+ {
+ m_maxSize = iMaxSize;
+ }
+ virtual ~CecBuffer(void) {}
- int Size(void) const { return m_buffer.size(); }
+ int Size(void) const { return m_buffer.size(); }
- bool Push(_BType entry)
- {
- CLockObject lock(&m_mutex);
- if (m_buffer.size() == m_maxSize)
- return false;
+ bool Push(_BType entry)
+ {
+ CLockObject lock(&m_mutex);
+ if (m_buffer.size() == m_maxSize)
+ return false;
- m_buffer.push(entry);
- return true;
- }
+ m_buffer.push(entry);
+ return true;
+ }
- bool Pop(_BType &entry)
- {
- bool bReturn(false);
- CLockObject lock(&m_mutex);
- if (m_buffer.size() > 0)
+ bool Pop(_BType &entry)
{
- entry = m_buffer.front();
- m_buffer.pop();
- bReturn = true;
+ bool bReturn(false);
+ CLockObject lock(&m_mutex);
+ if (m_buffer.size() > 0)
+ {
+ entry = m_buffer.front();
+ m_buffer.pop();
+ bReturn = true;
+ }
+ return bReturn;
}
- return bReturn;
- }
- private:
- int m_maxSize;
- std::queue<_BType> m_buffer;
- CMutex m_mutex;
- };
+ private:
+ unsigned int m_maxSize;
+ std::queue<_BType> m_buffer;
+ CMutex m_mutex;
+ };
+};
+++ /dev/null
-/*
- * boblight
- * Copyright (C) Bob 2009
- *
- * boblight is free software: 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 3 of the License, or
- * (at your option) any later version.
- *
- * boblight 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, see <http://www.gnu.org/licenses/>.
- */
-
-#include <iostream>
-#include <locale.h>
-#include "misc.h"
-
-using namespace std;
-
-void PrintError(const std::string& error)
-{
- std::cerr << "ERROR: " << error << "\n";
-}
-
-//get the first word (separated by whitespace) from string data and place that in word
-//then remove that word from string data
-bool GetWord(string& data, string& word)
-{
- stringstream datastream(data);
- string end;
-
- datastream >> word;
- if (datastream.fail())
- {
- data.clear();
- return false;
- }
-
- size_t pos = data.find(word) + word.length();
-
- if (pos >= data.length())
- {
- data.clear();
- return true;
- }
-
- data = data.substr(pos);
-
- datastream.clear();
- datastream.str(data);
-
- datastream >> end;
- if (datastream.fail())
- data.clear();
-
- return true;
-}
-
-//convert . or , to the current locale for correct conversion of ascii float
-void ConvertFloatLocale(std::string& strfloat)
-{
- static struct lconv* locale = localeconv();
-
- size_t pos = strfloat.find_first_of(",.");
-
- while (pos != string::npos)
- {
- strfloat.replace(pos, 1, 1, *locale->decimal_point);
- pos++;
-
- if (pos >= strfloat.size())
- break;
-
- pos = strfloat.find_first_of(",.", pos);
- }
-}
+++ /dev/null
-#pragma once
-
-/*
- * boblight
- * Copyright (C) Bob 2009
- *
- * boblight is free software: 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 3 of the License, or
- * (at your option) any later version.
- *
- * boblight 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, see <http://www.gnu.org/licenses/>.
- */
-
-#include <string>
-#include <sstream>
-#include <exception>
-#include <stdexcept>
-
-#include <stdint.h>
-#include <errno.h>
-#include <string.h>
-#include <stdio.h>
-#include <math.h>
-
-void PrintError(const std::string& error);
-bool GetWord(std::string& data, std::string& word);
-void ConvertFloatLocale(std::string& strfloat);
-
-template <class Value>
-inline std::string ToString(Value value)
-{
- std::string data;
- std::stringstream valuestream;
- valuestream << value;
- valuestream >> data;
- return data;
-}
-
-inline std::string GetErrno()
-{
- return strerror(errno);
-}
-
-inline std::string GetErrno(int err)
-{
- return strerror(err);
-}
-
-template <class A, class B, class C>
-inline A Clamp(A value, B min, C max)
-{
- return value < max ? (value > min ? value : min) : max;
-}
-
-template <class A, class B>
-inline A Max(A value1, B value2)
-{
- return value1 > value2 ? value1 : value2;
-}
-
-template <class A, class B, class C>
-inline A Max(A value1, B value2, C value3)
-{
- return (value1 > value2) ? (value1 > value3 ? value1 : value3) : (value2 > value3 ? value2 : value3);
-}
-
-template <class A, class B>
-inline A Min(A value1, B value2)
-{
- return value1 < value2 ? value1 : value2;
-}
-
-template <class A, class B, class C>
-inline A Min(A value1, B value2, C value3)
-{
- return (value1 < value2) ? (value1 < value3 ? value1 : value3) : (value2 < value3 ? value2 : value3);
-}
-
-template <class T>
-inline T Abs(T value)
-{
- return value > 0 ? value : -value;
-}
-
-template <class A, class B>
-inline A Round(B value)
-{
- if (value == 0.0)
- {
- return 0;
- }
- else if (value > 0.0)
- {
- return (A)(value + 0.5);
- }
- else
- {
- return (A)(value - 0.5);
- }
-}
-
-//inline int32_t Round32(float value)
-//{
-// return lroundf(value);
-//}
-//
-//inline int32_t Round32(double value)
-//{
-// return lround(value);
-//}
-//
-//inline int64_t Round64(float value)
-//{
-// return llroundf(value);
-//}
-//
-//inline int64_t Round64(double value)
-//{
-// return llround(value);
-//}
-
-inline bool StrToInt(const std::string& data, int& value)
-{
- return sscanf(data.c_str(), "%i", &value) == 1;
-}
-
-inline bool HexStrToInt(const std::string& data, int& value)
-{
- return sscanf(data.c_str(), "%x", &value) == 1;
-}
-
-inline bool StrToFloat(const std::string& data, float& value)
-{
- return sscanf(data.c_str(), "%f", &value) == 1;
-}
-
-inline bool StrToFloat(const std::string& data, double& value)
-{
- return sscanf(data.c_str(), "%lf", &value) == 1;
-}
-
-inline bool StrToBool(const std::string& data, bool& value)
-{
- std::string data2 = data;
- std::string word;
- if (!GetWord(data2, word))
- return false;
-
- if (word == "1" || word == "true" || word == "on" || word == "yes")
- {
- value = true;
- return true;
- }
- else if (word == "0" || word == "false" || word == "off" || word == "no")
- {
- value = false;
- return true;
- }
- else
- {
- int ivalue;
- if (StrToInt(word, ivalue))
- {
- value = ivalue != 0;
- return true;
- }
- }
-
- return false;
-}
*/
#include "../../include/CECExports.h"
-#include "../lib/util/threads.h"
-#include "../lib/util/misc.h"
+#include "../lib/platform/threads.h"
#include "../lib/util/StdString.h"
#include <cstdio>
#include <fcntl.h>
#include <iostream>
#include <string>
+#include <sstream>
using namespace CEC;
using namespace std;
#define CEC_TEST_CLIENT_VERSION 3
+
+inline bool HexStrToInt(const std::string& data, uint8_t& value)
+{
+ int iTmp(0);
+ if (sscanf(data.c_str(), "%x", &iTmp) == 1)
+ {
+ if (iTmp > 256)
+ value = 255;
+ else if (iTmp < 0)
+ value = 0;
+ else
+ value = (uint8_t) iTmp;
+
+ return true;
+ }
+
+ return false;
+}
+
+//get the first word (separated by whitespace) from string data and place that in word
+//then remove that word from string data
+bool GetWord(string& data, string& word)
+{
+ stringstream datastream(data);
+ string end;
+
+ datastream >> word;
+ if (datastream.fail())
+ {
+ data.clear();
+ return false;
+ }
+
+ size_t pos = data.find(word) + word.length();
+
+ if (pos >= data.length())
+ {
+ data.clear();
+ return true;
+ }
+
+ data = data.substr(pos);
+
+ datastream.clear();
+ datastream.str(data);
+
+ datastream >> end;
+ if (datastream.fail())
+ data.clear();
+
+ return true;
+}
+
void flush_log(ICECAdapter *cecParser)
{
cec_log_message message;
if (command == "tx")
{
string strvalue;
- int ivalue;
+ uint8_t ivalue;
vector<uint8_t> bytes;
while (GetWord(input, strvalue) && HexStrToInt(strvalue, ivalue))
bytes.push_back(ivalue);