#define ESCOFFSET 3
#define CEC_BUTTON_TIMEOUT 500
#define CEC_POWER_STATE_REFRESH_TIME 30000
+#define CEC_FW_VERSION_UNKNOWN 0xFFFF
#define CEC_DEFAULT_TRANSMIT_TIMEOUT 1000
#define CEC_DEFAULT_TRANSMIT_WAIT 2000
if ((bReturn = m_communication->Open(strPort, iBaudRate, iTimeoutMs)) == false)
m_controller->AddLog(CEC_LOG_ERROR, "could not open a connection");
+ /* try to ping the adapter */
+ if ((bReturn = m_communication->PingAdapter()) == false)
+ m_controller->AddLog(CEC_LOG_ERROR, "the adapter does not respond correctly");
+
+ uint16_t iFirmwareVersion = m_communication->GetFirmwareVersion();
+ if ((bReturn = (iFirmwareVersion != CEC_FW_VERSION_UNKNOWN)) == false)
+ m_controller->AddLog(CEC_LOG_ERROR, "the adapter is running an unknown firmware version");
+
+ CStdString strLog;
+ strLog.Format("CEC Adapter firmware version: %d", iFirmwareVersion);
+ m_controller->AddLog(CEC_LOG_NOTICE, strLog);
+
return bReturn;
}
CAdapterCommunication::CAdapterCommunication(CCECProcessor *processor) :
m_port(NULL),
m_processor(processor),
- m_iLineTimeout(0)
+ m_iLineTimeout(0),
+ m_iFirmwareVersion(CEC_FW_VERSION_UNKNOWN)
{
m_port = new PLATFORM::CSerialPort;
}
return bReturn;
}
+uint16_t CAdapterCommunication::GetFirmwareVersion(void)
+{
+ uint16_t iReturn(m_iFirmwareVersion);
+ if (!IsRunning())
+ return iReturn;
+
+ if (iReturn == CEC_FW_VERSION_UNKNOWN)
+ {
+ m_processor->AddLog(CEC_LOG_DEBUG, "requesting the firmware version");
+ CCECAdapterMessage *output = new CCECAdapterMessage;
+
+ output->PushBack(MSGSTART);
+ output->PushEscaped(MSGCODE_FIRMWARE_VERSION);
+ output->PushBack(MSGEND);
+ output->isTransmission = false;
+ output->expectControllerAck = false;
+
+ SendMessageToAdapter(output);
+ delete output;
+
+ CCECAdapterMessage input;
+ if (!Read(input, CEC_DEFAULT_TRANSMIT_WAIT) || input.Message() != MSGCODE_FIRMWARE_VERSION || input.Size() != 3)
+ m_processor->AddLog(CEC_LOG_ERROR, "no or invalid firmware version");
+ else
+ {
+ m_iFirmwareVersion = (input[1] << 8 | input[2]);
+ iReturn = m_iFirmwareVersion;
+ }
+ }
+
+ return iReturn;
+}
+
bool CAdapterCommunication::SetLineTimeout(uint8_t iTimeout)
{
bool bReturn(m_iLineTimeout != iTimeout);
if (!m_port)
return false;
+ CLockObject lock(m_mutex);
iBytesRead = m_port->Read(buff, sizeof(buff), iTimeout);
if (iBytesRead < 0 || iBytesRead > 256)
{
void CAdapterCommunication::SendMessageToAdapter(CCECAdapterMessage *msg)
{
+ CLockObject adapterLock(m_mutex);
CLockObject lock(msg->mutex);
if (m_port->Write(msg->packet.data, msg->Size()) != (int32_t) msg->Size())
{
bool Open(const char *strPort, uint16_t iBaudRate = 38400, uint32_t iTimeoutMs = 10000);
bool Read(CCECAdapterMessage &msg, uint32_t iTimeout = 1000);
bool Write(CCECAdapterMessage *data);
- bool PingAdapter(void);
void Close(void);
bool IsOpen(void);
std::string GetError(void) const;
bool SetLineTimeout(uint8_t iTimeout);
bool StartBootloader(void);
bool SetAckMask(uint16_t iMask);
+ bool PingAdapter(void);
+ uint16_t GetFirmwareVersion(void);
bool WaitForTransmitSucceeded(CCECAdapterMessage *message);
PLATFORM::CMutex m_mutex;
PLATFORM::CCondition m_rcvCondition;
uint8_t m_iLineTimeout;
+ uint16_t m_iFirmwareVersion;
};
};