cec: set line timeout when (re)transmitting. don't sleep after transmitting
authorLars Op den Kamp <lars@opdenkamp.eu>
Sat, 3 Dec 2011 23:58:32 +0000 (00:58 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Sun, 4 Dec 2011 02:28:24 +0000 (03:28 +0100)
src/lib/AdapterCommunication.cpp
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/implementations/SLCommandHandler.cpp

index c13000b17533c01a64e33f13dab8353941c2da96..fc650f0651f82a986dd2cfe7df730d47dfa4b033 100644 (file)
@@ -379,7 +379,6 @@ void CAdapterCommunication::SendMessageToAdapter(CCECAdapterMessage *msg)
   else
   {
     m_processor->AddLog(CEC_LOG_DEBUG, "command sent");
-    CCondition::Sleep((uint32_t) msg->size() * 24 /*data*/ + 5 /*start bit (4.5 ms)*/);
     msg->state = ADAPTER_MESSAGE_STATE_SENT;
   }
   msg->condition.Signal();
index 8fc71dc31a2502e88e457c576063fac780414abe..f8ea3bc871f9eee71c4e2fe33fd7ff753708ca52 100644 (file)
@@ -55,7 +55,8 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, cec
     m_strDeviceName(strDeviceName),
     m_controller(controller),
     m_bMonitor(false),
-    m_busScan(NULL)
+    m_busScan(NULL),
+    m_iLineTimeout(0)
 {
   m_communication = new CAdapterCommunication(this);
   m_logicalAddresses.Clear();
@@ -72,7 +73,8 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, con
     m_strDeviceName(strDeviceName),
     m_types(types),
     m_controller(controller),
-    m_bMonitor(false)
+    m_bMonitor(false),
+    m_iLineTimeout(0)
 {
   m_communication = new CAdapterCommunication(this);
   m_logicalAddresses.Clear();
@@ -242,17 +244,22 @@ bool CCECProcessor::FindLogicalAddresses(void)
 
 bool CCECProcessor::SetLineTimeout(uint8_t iTimeout)
 {
-  bool bReturn(false);
-  CCECAdapterMessage *output = new CCECAdapterMessage;
+  bool bReturn(m_iLineTimeout != iTimeout);
 
-  output->push_back(MSGSTART);
-  output->push_escaped(MSGCODE_TRANSMIT_IDLETIME);
-  output->push_escaped(iTimeout);
-  output->push_back(MSGEND);
+  if (!bReturn)
+  {
+    CCECAdapterMessage *output = new CCECAdapterMessage;
+
+    output->push_back(MSGSTART);
+    output->push_escaped(MSGCODE_TRANSMIT_IDLETIME);
+    output->push_escaped(iTimeout);
+    output->push_back(MSGEND);
+
+    if ((bReturn = Transmit(output)) == false)
+      m_controller->AddLog(CEC_LOG_ERROR, "could not set the idletime");
+    delete output;
+  }
 
-  if ((bReturn = Transmit(output)) == false)
-    m_controller->AddLog(CEC_LOG_ERROR, "could not set the idletime");
-  delete output;
   return bReturn;
 }
 
@@ -674,8 +681,13 @@ bool CCECProcessor::Transmit(CCECAdapterMessage *output)
   bool bReturn(false);
   CLockObject lock(&m_mutex);
   {
+    SetLineTimeout(3);
+
     do
     {
+      if (output->tries > 0)
+        SetLineTimeout(5);
+
       CLockObject msgLock(&output->mutex);
       if (!m_communication || !m_communication->Write(output))
         return bReturn;
@@ -699,6 +711,8 @@ bool CCECProcessor::Transmit(CCECAdapterMessage *output)
     }while (output->transmit_timeout > 0 && output->needs_retry() && ++output->tries <= output->maxTries);
   }
 
+  SetLineTimeout(3);
+
   return bReturn;
 }
 
index 309365b8c9eb334e94f579ad09cb4acab4203905..82dc1499f5f25573856a51577c80463627e44923 100644 (file)
@@ -154,6 +154,7 @@ namespace CEC
       CecBuffer<cec_command> m_commandBuffer;
       cec_keypress           m_previousKey;
       CThread *              m_busScan;
+      uint8_t                m_iLineTimeout;
   };
 
   class CCECBusScan : public CThread
index 62e70d83e53bae1781012875f9e2075a9b161081..c6affec4330c3977c9fa6fb734af6b852a133e91 100644 (file)
@@ -55,6 +55,29 @@ bool CSLCommandHandler::HandleVendorCommand(const cec_command &command)
 
     return m_busDevice->GetProcessor()->Transmit(response);
   }
+  else if (command.parameters.size >= 1 &&
+      command.parameters[0] == 0x04)
+  {
+    /* enable SL */
+    cec_command response;
+    cec_command::Format(response, command.destination, command.initiator, CEC_OPCODE_VENDOR_COMMAND);
+    response.PushBack(0x05);
+    response.PushBack(0x04);
+
+    return m_busDevice->GetProcessor()->Transmit(response);
+  }
+  else if (command.parameters.size == 1 &&
+      command.parameters[0] == 0xa0)
+  {
+    /* enable SL */
+    cec_command response;
+    cec_command::Format(response, command.destination, command.initiator, CEC_OPCODE_VENDOR_COMMAND);
+    response.parameters.PushBack((uint8_t) (((uint64_t)CEC_VENDOR_LG >> 16) & 0xFF));
+    response.parameters.PushBack((uint8_t) (((uint64_t)CEC_VENDOR_LG >> 8) & 0xFF));
+    response.parameters.PushBack((uint8_t) ((uint64_t)CEC_VENDOR_LG & 0xFF));
+
+    return m_busDevice->GetProcessor()->Transmit(response);
+  }
 
   return false;
 }