#include "implementations/ANCommandHandler.h"
#include "implementations/CECCommandHandler.h"
#include "implementations/SLCommandHandler.h"
+#include "platform/timeutils.h"
using namespace CEC;
m_iLogicalAddress(iLogicalAddress),
m_processor(processor),
m_iVendorId(0),
- m_iVendorClass(0)
+ m_iVendorClass(CEC_VENDOR_UNKNOWN),
+ m_iLastActive(0)
{
m_handler = new CCECCommandHandler(this);
}
void CCECBusDevice::SetVendorId(uint16_t iVendorId, uint8_t iVendorClass /* = 0 */)
{
- delete m_handler;
m_iVendorId = iVendorId;
m_iVendorClass = iVendorClass;
switch (iVendorId)
{
case CEC_VENDOR_SAMSUNG:
- m_handler = new CANCommandHandler(this);
+ if (m_handler->GetVendorId() != CEC_VENDOR_SAMSUNG)
+ {
+ delete m_handler;
+ m_handler = new CANCommandHandler(this);
+ }
break;
case CEC_VENDOR_LG:
- m_handler = new CSLCommandHandler(this);
+ if (m_handler->GetVendorId() != CEC_VENDOR_LG)
+ {
+ delete m_handler;
+ m_handler = new CSLCommandHandler(this);
+ }
break;
default:
- m_handler = new CCECCommandHandler(this);
+ if (m_handler->GetVendorId() != CEC_VENDOR_UNKNOWN)
+ {
+ delete m_handler;
+ m_handler = new CCECCommandHandler(this);
+ }
break;
}
CStdString strLog;
- strLog.Format("device %d: vendor = %s (%04x) class = %2x", m_iLogicalAddress, CECVendorIdToString(iVendorId), iVendorId, iVendorClass);
+ strLog.Format("device %d: vendor = %s (%04x) class = %2x", m_iLogicalAddress, GetVendorName(), GetVendorId(), GetVendorClass());
m_processor->AddLog(CEC_LOG_DEBUG, strLog.c_str());
}
bool CCECBusDevice::HandleCommand(const cec_command &command)
{
CLockObject lock(&m_mutex);
+ m_iLastActive = GetTimeMs();
m_handler->HandleCommand(command);
return true;
}
+void CCECBusDevice::PollVendorId(void)
+{
+ CLockObject lock(&m_mutex);
+ if (m_iLastActive > 0 && m_iVendorId == CEC_VENDOR_UNKNOWN &&
+ GetTimeMs() - m_iLastActive > 5000)
+ {
+ m_iLastActive = GetTimeMs();
+
+ cec_command command;
+ cec_command::format(command, GetMyLogicalAddress(), GetLogicalAddress(), CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
+ m_processor->Transmit(command, false);
+ }
+}
+
const char *CCECBusDevice::CECVendorIdToString(const uint64_t iVendorId)
{
switch (iVendorId)
virtual uint16_t GetMyPhysicalAddress(void) const;
virtual void SetVendorId(uint16_t iVendorId, uint8_t iVendorClass = 0);
+ virtual const char *GetVendorName(void) const { return CECVendorIdToString(m_iVendorId); }
+ virtual uint64_t GetVendorId(void) const { return m_iVendorId; }
+ virtual uint8_t GetVendorClass(void) const { return m_iVendorClass; }
+
+ virtual uint64_t GetLastActive(void) const { return m_iLastActive; }
+
virtual bool HandleCommand(const cec_command &command);
virtual void AddLog(cec_log_level level, const CStdString &strMessage);
virtual CCECProcessor *GetProcessor() const { return m_processor; }
virtual CCECCommandHandler *GetHandler(void) const { return m_handler; };
+ virtual void PollVendorId(void);
+
static const char *CECVendorIdToString(const uint64_t iVendorId);
protected:
CCECCommandHandler *m_handler;
uint64_t m_iVendorId;
uint8_t m_iVendorClass;
+ uint64_t m_iLastActive;
CMutex m_mutex;
};
};