cec: set line timeout when (re)transmitting. don't sleep after transmitting
[deb_libcec.git] / src / lib / implementations / SLCommandHandler.cpp
index 144cfc92d933bd033f4d7ac79908f30eef03770e..c6affec4330c3977c9fa6fb734af6b852a133e91 100644 (file)
  */
 
 #include "SLCommandHandler.h"
+#include "../devices/CECBusDevice.h"
+#include "../CECProcessor.h"
 
 using namespace CEC;
 
 CSLCommandHandler::CSLCommandHandler(CCECBusDevice *busDevice) :
-    CCECCommandHandler(busDevice)
+    CCECCommandHandler(busDevice),
+    m_bAwaitingReceiveFailed(false)
 {
 }
+
+bool CSLCommandHandler::HandleVendorCommand(const cec_command &command)
+{
+  if (command.parameters.size == 1 &&
+      command.parameters[0] == 0x01)
+  {
+    /* enable SL */
+    cec_command response;
+    cec_command::Format(response, command.destination, command.initiator, CEC_OPCODE_VENDOR_COMMAND);
+    response.PushBack(0x02);
+    response.PushBack(0x05);
+
+    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;
+}
+
+bool CSLCommandHandler::HandleGiveDeviceVendorId(const cec_command &command)
+{
+  /* imitate LG devices */
+  CCECBusDevice *device = GetDevice(command.destination);
+  if (device)
+    device->SetVendorId(CEC_VENDOR_LG);
+
+  return CCECCommandHandler::HandleGiveDeviceVendorId(command);
+}
+
+bool CSLCommandHandler::HandleCommand(const cec_command &command)
+{
+  bool bHandled(false);
+  if (m_busDevice->MyLogicalAddressContains(command.destination))
+  {
+    switch(command.opcode)
+    {
+    case CEC_OPCODE_VENDOR_COMMAND:
+      bHandled = HandleVendorCommand(command);
+      break;
+    default:
+      break;
+    }
+  }
+
+  if (!bHandled)
+    bHandled = CCECCommandHandler::HandleCommand(command);
+
+  return bHandled;
+}
+
+
+void CSLCommandHandler::HandlePoll(const cec_logical_address iInitiator, const cec_logical_address iDestination)
+{
+  CCECCommandHandler::HandlePoll(iInitiator, iDestination);
+  m_bAwaitingReceiveFailed = true;
+}
+
+bool CSLCommandHandler::HandleReceiveFailed(void)
+{
+  if (m_bAwaitingReceiveFailed)
+  {
+    m_bAwaitingReceiveFailed = false;
+    return false;
+  }
+
+  return true;
+}