using namespace std;
#define CEC_MAX_RETRY 5
+#define CEC_BUTTON_TIMEOUT 500
/*!
* ICECDevice implementation
CCECParser::~CCECParser(void)
{
- Close(0);
+ Close();
m_communication->Close();
delete m_communication;
}
return false;
}
-bool CCECParser::Close(int iTimeoutMs /* = 2000 */)
+void CCECParser::Close(void)
{
m_bRunning = false;
- bool bExit(false);
- if (iTimeoutMs > 0)
- {
- bExit = m_exitCondition.Wait(&m_mutex, iTimeoutMs);
- m_mutex.Unlock();
- }
- else
- {
- pthread_join(m_thread, NULL);
- bExit = true;
- }
-
- return bExit;
+ pthread_join(m_thread, NULL);
}
void *CCECParser::ThreadHandler(CCECParser *parser)
while (m_bRunning)
{
cec_frame msg;
- while (m_bRunning && m_communication->IsOpen() && m_communication->Read(msg, 500))
+ while (m_bRunning && m_communication->IsOpen() && m_communication->Read(msg, CEC_BUTTON_TIMEOUT))
ParseMessage(msg);
now = GetTimeMs();
PushEscaped(output, MSGCODE_PING);
output.push_back(MSGEND);
- if (!TransmitFormatted(output, false, (int64_t) 5000))
+ if (!TransmitFormatted(output, false))
{
AddLog(CEC_LOG_ERROR, "could not send ping command");
return false;
PushEscaped(output, MSGCODE_START_BOOTLOADER);
output.push_back(MSGEND);
- if (!TransmitFormatted(output, false, (int64_t) 5000))
+ if (!TransmitFormatted(output, false))
{
AddLog(CEC_LOG_ERROR, "could not start the bootloader");
return false;
Transmit(frame);
}
-bool CCECParser::TransmitFormatted(const cec_frame &data, bool bWaitForAck /* = true */, int64_t iTimeout /* = 2000 */)
+bool CCECParser::TransmitFormatted(const cec_frame &data, bool bWaitForAck /* = true */)
{
- if (!m_communication || m_communication->Write(data) != data.size())
+ if (!m_communication || !m_communication->Write(data))
return false;
CCondition::Sleep((int) data.size() * 24 /*data*/ + 5 /*start bit (4.5 ms)*/ + 50 /* to be on the safe side */);
return true;
}
-bool CCECParser::Transmit(const cec_frame &data, bool bWaitForAck /* = true */, int64_t iTimeout /* = 5000 */)
+bool CCECParser::Transmit(const cec_frame &data, bool bWaitForAck /* = true */)
{
CStdString txStr = "transmit ";
for (unsigned int i = 0; i < data.size(); i++)
output.push_back(MSGEND);
}
- return TransmitFormatted(output, bWaitForAck, iTimeout);
+ return TransmitFormatted(output, bWaitForAck);
}
-bool CCECParser::WaitForAck(int64_t iTimeout /* = 1000 */)
+bool CCECParser::WaitForAck(int iTimeout /* = 1000 */)
{
bool bGotAck(false);
bool bError(false);
int64_t iNow = GetTimeMs();
- int64_t iTargetTime = iNow + iTimeout;
+ int64_t iTargetTime = iNow + (int64_t) iTimeout;
while (!bGotAck && !bError && (iTimeout <= 0 || iNow < iTargetTime))
{
void CCECParser::CheckKeypressTimeout(int64_t now)
{
- if (m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN && now - m_buttontime > 500)
+ if (m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN && now - m_buttontime > CEC_BUTTON_TIMEOUT)
{
AddKey();
m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN;
PushEscaped(output, (uint8_t)iMask);
output.push_back(MSGEND);
- if (m_communication->Write(output) == -1)
+ if (!m_communication->Write(output))
{
AddLog(CEC_LOG_ERROR, "could not set the ackmask");
return false;