Merge branch 'master' into release
authorLars Op den Kamp <lars@opdenkamp.eu>
Tue, 4 Oct 2011 21:48:29 +0000 (23:48 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Tue, 4 Oct 2011 21:49:05 +0000 (23:49 +0200)
  * 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

43 files changed:
ChangeLog
configure.ac
debian/changelog
include/CECExportsC.h
include/CECExportsCpp.h
project/libcec.sln
project/libcec.vcxproj
project/libcec.vcxproj.filters
project/testclient.vcxproj
project/testclient.vcxproj.filters
src/lib/AdapterCommunication.cpp
src/lib/AdapterCommunication.h
src/lib/AdapterDetection.cpp
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/LibCEC.cpp
src/lib/LibCEC.h
src/lib/LibCECC.cpp
src/lib/Makefile.am
src/lib/libPlatform/baudrate.h [deleted file]
src/lib/libPlatform/serialport.h [deleted file]
src/lib/platform/baudrate.h [new file with mode: 0644]
src/lib/platform/linux/os_posix.h [moved from src/lib/libPlatform/linux/os_posix.h with 56% similarity]
src/lib/platform/linux/serialport.cpp [moved from src/lib/libPlatform/linux/serialport.cpp with 80% similarity]
src/lib/platform/os-dependent.h [moved from src/lib/libPlatform/os-dependent.h with 100% similarity]
src/lib/platform/pthread_win32/pthread.h [moved from src/lib/libPlatform/pthread_win32/pthread.h with 100% similarity]
src/lib/platform/pthread_win32/pthreadVC2.lib [moved from src/lib/libPlatform/pthread_win32/pthreadVC2.lib with 100% similarity]
src/lib/platform/pthread_win32/pthreadVC2d.lib [moved from src/lib/libPlatform/pthread_win32/pthreadVC2d.lib with 100% similarity]
src/lib/platform/pthread_win32/sched.h [moved from src/lib/libPlatform/pthread_win32/sched.h with 100% similarity]
src/lib/platform/pthread_win32/semaphore.h [moved from src/lib/libPlatform/pthread_win32/semaphore.h with 100% similarity]
src/lib/platform/serialport.h [new file with mode: 0644]
src/lib/platform/threads.cpp [moved from src/lib/util/threads.cpp with 98% similarity]
src/lib/platform/threads.h [moved from src/lib/util/threads.h with 53% similarity]
src/lib/platform/timeutils.h [moved from src/lib/util/timeutils.h with 55% similarity]
src/lib/platform/windows/dlfcn-win32.cpp [moved from src/lib/libPlatform/windows/dlfcn-win32.cpp with 100% similarity]
src/lib/platform/windows/dlfcn-win32.h [moved from src/lib/libPlatform/windows/dlfcn-win32.h with 100% similarity]
src/lib/platform/windows/os_windows.cpp [moved from src/lib/libPlatform/windows/os_windows.cpp with 100% similarity]
src/lib/platform/windows/os_windows.h [moved from src/lib/libPlatform/windows/os_windows.h with 100% similarity]
src/lib/platform/windows/serialport.cpp [moved from src/lib/libPlatform/windows/serialport.cpp with 85% similarity]
src/lib/util/buffer.h
src/lib/util/misc.cpp [deleted file]
src/lib/util/misc.h [deleted file]
src/testclient/main.cpp

index 10c85f199556890f357c851bd110adddc40308c3..793462578b1a4f641913b3613386dd165b1914e3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+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
index bd97334aa8a1ab87a63aaa7c9c1ea4154a3803e2..dffe00b64805765160ae9fb5262c1fa2db1e5ea7 100644 (file)
@@ -8,5 +8,7 @@ AC_CHECK_LIB([rt], [main],, AC_MSG_ERROR("required library 'rt' is missing"))
 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])
index 10c85f199556890f357c851bd110adddc40308c3..793462578b1a4f641913b3613386dd165b1914e3 100644 (file)
@@ -1,3 +1,16 @@
+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
index 61cabd2bd4e18fee19588af863c5e3f67b8e6e75..b96beba585ff7eacfbb39d340b2ac52da96a60d5 100644 (file)
@@ -46,9 +46,9 @@ extern "C" {
  * @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
 
 /*!
@@ -62,7 +62,7 @@ extern DECLSPEC void cec_destroy(void);
  * @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.
index 54dbcbfe3770e16eb027451f1b6970cf814fc066..f0a0ac9306040bb171d39160442b4d13b8a14cfe 100644 (file)
@@ -41,7 +41,7 @@ namespace CEC
     /*!
      * @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
@@ -122,7 +122,7 @@ namespace CEC
   };
 };
 
-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)
@@ -135,7 +135,7 @@ static int g_iLibCECInstanceCount = 0;
 /*!
  * @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;
@@ -149,7 +149,7 @@ inline CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_addres
   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));
 }
 
 /*!
@@ -183,6 +183,7 @@ inline CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_addres
  */
 inline void UnloadLibCec(CEC::ICECAdapter *device)
 {
+  device->Close();
   delete device;
 };
 #endif
index 2284eec9447d6c03c32791c98276df9d329ca33d..2255a1b0f0f9362ea2ac5c53b70d8b2e0f5d2644 100644 (file)
@@ -1,6 +1,6 @@
 ï»¿
 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}"
@@ -11,12 +11,17 @@ EndProject
 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
index a9edbba0b9cdd689cf745086cc18c2c0e6e8a9e1..65200d3fdc1604cbc064ff681cf11565f21ba94b 100644 (file)
     <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>
index 2bc976f0ed3022b908412c8265f91632b23dc6df..7bd7b5949287ff97c75f54b1c38065713340803e 100644 (file)
     <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
index caa2a0346fa1974ceee6d40bb6d8c415bfaff7b5..94c7f24c445f0fd7dd2d7a79ef451f5d2e67e3bb 100644 (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>
index a6fda369cd14bc3c0c8831b4148258c32ceab5c9..76735fba1074b00476c70608ea3ef1e7fac80a84 100644 (file)
     <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
index 266842f7f64927d966842aea1172988c619a95dd..4b0bcdd1b238ac26aa7882a8b4ebae1c62de90da 100644 (file)
@@ -33,7 +33,7 @@
 #include "AdapterCommunication.h"
 
 #include "LibCEC.h"
-#include "libPlatform/serialport.h"
+#include "platform/serialport.h"
 #include "util/StdString.h"
 
 using namespace std;
@@ -52,11 +52,13 @@ CAdapterCommunication::CAdapterCommunication(CLibCEC *controller) :
 
 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)
@@ -110,23 +112,25 @@ void *CAdapterCommunication::Process(void)
       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());
@@ -134,12 +138,12 @@ bool CAdapterCommunication::ReadFromDevice(int iTimeout)
     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)
@@ -158,7 +162,7 @@ bool CAdapterCommunication::Write(const cec_frame &data)
 {
   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());
@@ -173,7 +177,7 @@ bool CAdapterCommunication::Write(const cec_frame &data)
   return true;
 }
 
-bool CAdapterCommunication::Read(cec_frame &msg, int iTimeout)
+bool CAdapterCommunication::Read(cec_frame &msg, uint64_t iTimeout)
 {
   CLockObject lock(&m_bufferMutex);
 
index f7dafa0250dbd1e5bc9030d9a62a4ae00ff17c50..c95f729998d75d5505323125011397229599422b 100644 (file)
  */
 
 #include "../../include/CECExports.h"
-#include "util/threads.h"
-
-class CSerialPort;
+#include "platform/threads.h"
 
 namespace CEC
 {
+  class CSerialPort;
   class CLibCEC;
 
   class CAdapterCommunication : CThread
@@ -46,8 +45,8 @@ namespace CEC
     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);
@@ -60,8 +59,8 @@ namespace CEC
     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;
index 747ea16d24565f882e1890a9cad50c07326007f5..e21d3dc20808a9b2d334b60da8588a0cf8507a9b 100644 (file)
@@ -31,7 +31,7 @@
  */
 
 #include "AdapterDetection.h"
-#include "libPlatform/os-dependent.h"
+#include "platform/os-dependent.h"
 #include "util/StdString.h"
 
 #if !defined(__WINDOWS__)
index f3b89c3e3fe7e2e1382767430e063ad5e3451c06..258e16419f9b79dd3b7cb3e413e651085329748c 100644 (file)
@@ -35,7 +35,7 @@
 #include "AdapterCommunication.h"
 #include "LibCEC.h"
 #include "util/StdString.h"
-#include "util/timeutils.h"
+#include "platform/timeutils.h"
 
 using namespace CEC;
 using namespace std;
@@ -89,14 +89,16 @@ void *CCECProcessor::Process(void)
         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;
 }
 
@@ -110,7 +112,7 @@ bool CCECProcessor::PowerOnDevices(cec_logical_address address /* = CECDEVICE_TV
   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);
 }
 
@@ -124,7 +126,7 @@ bool CCECProcessor::StandbyDevices(cec_logical_address address /* = CECDEVICE_BR
   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);
 }
 
@@ -136,7 +138,7 @@ bool CCECProcessor::SetActiveView(void)
   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);
@@ -150,7 +152,7 @@ bool CCECProcessor::SetInactiveView(void)
   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);
@@ -230,9 +232,9 @@ void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode
   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);
 }
 
@@ -241,7 +243,7 @@ void CCECProcessor::ReportCECVersion(cec_logical_address address /* = CECDEVICE_
   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);
 }
@@ -255,8 +257,8 @@ void CCECProcessor::ReportPowerState(cec_logical_address address /*= CECDEVICE_T
     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);
 }
 
@@ -269,8 +271,8 @@ void CCECProcessor::ReportMenuState(cec_logical_address address /* = CECDEVICE_T
     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);
 }
 
@@ -288,7 +290,7 @@ void CCECProcessor::ReportOSDName(cec_logical_address address /* = CECDEVICE_TV
   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]);
@@ -303,7 +305,7 @@ void CCECProcessor::ReportPhysicalAddress(void)
   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);
@@ -315,7 +317,7 @@ void CCECProcessor::BroadcastActiveSource(void)
   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);
index 339653c3bf8164fa988897d91bded8e98857468b..aea17c88d7853af010456dabf65aec7be96598ad 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "../../include/CECExports.h"
 #include "../../include/CECTypes.h"
-#include "util/threads.h"
+#include "platform/threads.h"
 #include "util/buffer.h"
 
 class CSerialPort;
index 23c4b18b544cd9be3886388389ab2b02b9e2c5a9..3437e451ee132f1a62e8da013825957d61fadd85 100644 (file)
 #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)
 {
@@ -58,7 +58,7 @@ CLibCEC::~CLibCEC(void)
   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;
@@ -87,9 +87,17 @@ bool CLibCEC::Open(const char *strPort, int iTimeoutMs /* = 10000 */)
 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 */)
@@ -225,7 +233,7 @@ void CLibCEC::SetCurrentButton(cec_user_control_code iButtonCode)
   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));
 }
index b863cb49c91a5f7922ab4b2b975779e16956e2bc..cb9eb8c6e6e538691a098bf3581d076cbfff7174 100644 (file)
@@ -47,10 +47,10 @@ namespace CEC
      * 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);
index 7f2475b5eb38118b28090f79b516f4b2e1c3284d..60ada61b749fcc13c77f39ff1e292ecfbc19bfdf 100644 (file)
@@ -41,7 +41,7 @@ using namespace std;
 //@{
 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);
@@ -54,7 +54,7 @@ void cec_destroy(void)
   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);
index 47664b8758a7ddf4b20c67a6014425af79978426..3522cb5644e1563d976e13734a4239bbb20e59c2 100644 (file)
@@ -20,16 +20,14 @@ libcec_la_SOURCES = AdapterCommunication.cpp \
                     ../../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@
diff --git a/src/lib/libPlatform/baudrate.h b/src/lib/libPlatform/baudrate.h
deleted file mode 100644 (file)
index 39a4b1a..0000000
+++ /dev/null
@@ -1,179 +0,0 @@
-#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}
-};
diff --git a/src/lib/libPlatform/serialport.h b/src/lib/libPlatform/serialport.h
deleted file mode 100644 (file)
index f592ee3..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-#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
-};
diff --git a/src/lib/platform/baudrate.h b/src/lib/platform/baudrate.h
new file mode 100644 (file)
index 0000000..759b1f1
--- /dev/null
@@ -0,0 +1,199 @@
+#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;
+  };
+};
similarity index 56%
rename from src/lib/libPlatform/linux/os_posix.h
rename to src/lib/platform/linux/os_posix.h
index 1ea8aa5a022624745bc4f877a2685d06ef82bb25..9cc4d095424f4f3c7792c251f4e5f4d9b7277904 100644 (file)
  */
 
 #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);
-}
similarity index 80%
rename from src/lib/libPlatform/linux/serialport.cpp
rename to src/lib/platform/linux/serialport.cpp
index 33a7385212989238980c7aefe6a1bb9db5ea09ad..e8fb8e5b411f52c34fbe82066b7800256bc89124 100644 (file)
  * 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()
@@ -39,33 +35,34 @@ 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;
@@ -84,28 +81,29 @@ int CSerialPort::Write(uint8_t* data, int len)
   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;
     }
@@ -118,11 +116,11 @@ int CSerialPort::Read(uint8_t* data, int len, int iTimeoutMs /*= -1*/)
 
     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)
@@ -133,7 +131,7 @@ int CSerialPort::Read(uint8_t* data, int len, int iTimeoutMs /*= -1*/)
     returnv = read(m_fd, data + bytesread, len - bytesread);
     if (returnv == -1)
     {
-      m_error = GetErrno();
+      m_error = strerror(errno);
       return -1;
     }
 
@@ -157,11 +155,12 @@ int CSerialPort::Read(uint8_t* data, int len, int iTimeoutMs /*= -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";
@@ -184,7 +183,7 @@ bool CSerialPort::Open(string name, int baudrate, int databits/* = 8*/, int stop
 
   if (m_fd == -1)
   {
-    m_error = GetErrno();
+    m_error = strerror(errno);
     return false;
   }
 
@@ -236,7 +235,7 @@ bool CSerialPort::Open(string name, int baudrate, int databits/* = 8*/, int stop
 
   if (tcsetattr(m_fd, TCSANOW, &m_options) != 0)
   {
-    m_error = GetErrno();
+    m_error = strerror(errno);
     return false;
   }
   
@@ -248,6 +247,7 @@ bool CSerialPort::Open(string name, int baudrate, int databits/* = 8*/, int stop
 
 void CSerialPort::Close()
 {
+  CLockObject lock(&m_mutex);
   if (m_fd != -1)
   {
     close(m_fd);
@@ -257,9 +257,9 @@ void CSerialPort::Close()
   }
 }
 
-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];
@@ -271,21 +271,27 @@ bool CSerialPort::SetBaudRate(int baudrate)
   //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;
+}
diff --git a/src/lib/platform/serialport.h b/src/lib/platform/serialport.h
new file mode 100644 (file)
index 0000000..ea6cdea
--- /dev/null
@@ -0,0 +1,83 @@
+#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
+  };
+};
similarity index 98%
rename from src/lib/util/threads.cpp
rename to src/lib/platform/threads.cpp
index 58aff3630f61314d5f695b266e173de4832508bd..7c5b6ce4ed716de8cda00689de685482fca57eda 100644 (file)
@@ -33,6 +33,8 @@
 #include "threads.h"
 #include "timeutils.h"
 
+using namespace CEC;
+
 CMutex::CMutex(void)
 {
   pthread_mutex_init(&m_mutex, NULL);
@@ -118,7 +120,7 @@ void CCondition::Sleep(int iTimeout)
   CCondition w;
   CMutex m;
   CLockObject lock(&m);
-  w.Wait(&m, iTimeout);
+  w.Wait(&m, int64_t(iTimeout));
 }
 
 CThread::CThread(void) :
similarity index 53%
rename from src/lib/util/threads.h
rename to src/lib/platform/threads.h
index d1b6239e852252a482e9334c152235f9fea8bab0..4ae5ac72557433464e96236e9821aee8ba414561 100644 (file)
  *     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;
+  };
 };
similarity index 55%
rename from src/lib/util/timeutils.h
rename to src/lib/platform/timeutils.h
index f1c0e63c0d9fd408ad5b621c7a84aa7210a5dcda..c4140203736bc258e3551a31fda001009a985e45 100644 (file)
 #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;
+  }
+};
similarity index 85%
rename from src/lib/libPlatform/windows/serialport.cpp
rename to src/lib/platform/windows/serialport.cpp
index f4b8c62d4e69a9b8af68d4eeda0c38531b49da52..ce299cf0d443177ed9ff1bf289761eede2e082e2 100644 (file)
 
 #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)
 {
@@ -62,8 +63,9 @@ CSerialPort::~CSerialPort(void)
   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)
   {
@@ -156,6 +158,7 @@ bool CSerialPort::SetTimeouts(bool bBlocking)
 
 void CSerialPort::Close(void)
 {
+  CLockObject lock(&m_mutex);
   if (m_bIsOpen)
   {
     CloseHandle(m_handle);
@@ -163,8 +166,9 @@ void CSerialPort::Close(void)
   }
 }
 
-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;
@@ -176,36 +180,46 @@ int CSerialPort::Write(uint8_t* data, int len)
     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;
@@ -238,3 +252,9 @@ bool CSerialPort::SetBaudRate(int baudrate)
 
   return true;
 }
+
+bool CSerialPort::IsOpen()
+{
+  CLockObject lock(&m_mutex);
+  return m_bIsOpen;
+}
index cafa65574414b5864718038b175d697566572cf9..d49de62554ea7ea8305c1c810ce2809d8f2228eb 100644 (file)
  *     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;
+    };
+};
diff --git a/src/lib/util/misc.cpp b/src/lib/util/misc.cpp
deleted file mode 100644 (file)
index 3cf71bd..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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);
-  }
-}
diff --git a/src/lib/util/misc.h b/src/lib/util/misc.h
deleted file mode 100644 (file)
index e3ff857..0000000
+++ /dev/null
@@ -1,177 +0,0 @@
-#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;
-}
index 90158edbec031ac5fb0ef0dc4fefe28d9b27e4eb..983ba13736fff90d6b3b16c9fce8985206ead71c 100644 (file)
  */
 
 #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;
@@ -213,7 +266,7 @@ int main (int argc, char *argv[])
         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);