cec: clean ups and only include what we need from lib/platform.
[deb_libcec.git] / src / lib / adapter / AdapterCommunication.cpp
index 05ab9b836dd1f6c7ebea9744bcfb8fc7f238ada8..ff69a7f4a73f2aeb6a10cf43bb9a888e21190330 100644 (file)
@@ -34,7 +34,8 @@
 
 #include "AdapterMessage.h"
 #include "../CECProcessor.h"
-#include "../platform/serialport/serialport.h"
+#include "../platform/sockets/serialport.h"
+#include "../platform/util/timeutils.h"
 #include "../LibCEC.h"
 
 using namespace std;
@@ -98,11 +99,15 @@ bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38
     return false;
   }
 
-  CLibCEC::AddLog(CEC_LOG_DEBUG, "connection opened");
+  CLibCEC::AddLog(CEC_LOG_DEBUG, "connection opened, clearing any previous input and waiting for active transmissions to end before starting");
 
   //clear any input bytes
-  uint8_t buff[1];
-  while (m_port->Read(buff, 1, 5) == 1) {}
+  uint8_t buff[1024];
+  while (m_port->Read(buff, 1024, 100) > 0)
+  {
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "data received, clearing it");
+    Sleep(250);
+  }
 
   if (CreateThread())
   {
@@ -230,9 +235,11 @@ bool CAdapterCommunication::Read(CCECAdapterMessage &msg, uint32_t iTimeout)
   return bGotFullMessage;
 }
 
-std::string CAdapterCommunication::GetError(void) const
+CStdString CAdapterCommunication::GetError(void) const
 {
-  return m_port->GetError();
+  CStdString strError;
+  strError = m_port->GetError();
+  return strError;
 }
 
 bool CAdapterCommunication::StartBootloader(void)
@@ -300,7 +307,7 @@ uint16_t CAdapterCommunication::GetFirmwareVersion(void)
 
     CCECAdapterMessage input;
     if (!Read(input, CEC_DEFAULT_TRANSMIT_WAIT) || input.Message() != MSGCODE_FIRMWARE_VERSION || input.Size() != 3)
-      CLibCEC::AddLog(CEC_LOG_ERROR, "no or invalid firmware version");
+      CLibCEC::AddLog(CEC_LOG_ERROR, "no or invalid firmware version (size = %d, message = %d)", input.Size(), input.Message());
     else
     {
       m_iFirmwareVersion = (input[1] << 8 | input[2]);