void CCECProcessor::Close(void)
{
+ StopThread(false);
+ SetInitialised(false);
StopThread();
CLockObject lock(m_mutex);
CLockObject lock(m_mutex);
LogOutput(data);
m_iLastTransmission = GetTimeMs();
- if (!m_communication)
+ if (!m_communication || !IsInitialised())
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "cannot transmit command: connection closed");
return false;
+ }
uint8_t iMaxTries = m_busDevices[data.initiator]->GetHandler()->GetTransmitRetries() + 1;
retVal = m_communication->Write(data, iMaxTries, m_iLineTimeout, m_iRetryLineTimeout);
}
void CUSBCECAdapterCommunication::Close(void)
{
- {
- CLockObject lock(m_mutex);
- m_bHasData = true;
- m_rcvCondition.Broadcast();
- }
- SetAckMask(0);
StopThread();
}
}
}
+ /* notify all threads that are waiting on messages to be sent */
CCECAdapterMessage *msg(NULL);
- if (m_outBuffer.Pop(msg))
+ while (m_outBuffer.Pop(msg))
msg->event.Broadcast();
+ /* set the ackmask to 0 before closing the connection */
+ SetAckMaskInternal(0, true);
+
if (m_port)
{
delete m_port;
{
data->state = ADAPTER_MESSAGE_STATE_WAITING_TO_BE_SENT;
m_outBuffer.Push(data);
- data->event.Wait();
+ data->event.Wait(5000);
if ((data->expectControllerAck && data->state != ADAPTER_MESSAGE_STATE_SENT_ACKED) ||
(!data->expectControllerAck && data->state != ADAPTER_MESSAGE_STATE_SENT))
}
bool CUSBCECAdapterCommunication::SetAckMask(uint16_t iMask)
+{
+ return SetAckMaskInternal(iMask, false);
+}
+
+bool CUSBCECAdapterCommunication::SetAckMaskInternal(uint16_t iMask, bool bWriteDirectly /* = false */)
{
bool bReturn(false);
CLibCEC::AddLog(CEC_LOG_DEBUG, "setting ackmask to %2x", iMask);
output->PushBack(MSGEND);
output->isTransmission = false;
- if ((bReturn = Write(output)) == false)
+ if (bWriteDirectly)
+ SendMessageToAdapter(output);
+ else if ((bReturn = Write(output)) == false)
CLibCEC::AddLog(CEC_LOG_ERROR, "could not set the ackmask");
delete output;
void CUSBCECAdapterCommunication::SendMessageToAdapter(CCECAdapterMessage *msg)
{
CLockObject adapterLock(m_mutex);
+ if (!m_port->IsOpen())
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "error writing to serial port: the connection is closed");
+ msg->state = ADAPTER_MESSAGE_STATE_ERROR;
+ return;
+ }
+
if (msg->tries == 1)
SetLineTimeout(msg->lineTimeout);
else