From: Lars Op den Kamp Date: Thu, 1 Dec 2011 22:58:30 +0000 (+0100) Subject: cec: don't delete a message before it's been sent when starting the bootloader or... X-Git-Tag: upstream/2.2.0~1^2~44^2~69 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a96eb42e890b2fb1224190f3b2bd1a1be55d848a;p=deb_libcec.git cec: don't delete a message before it's been sent when starting the bootloader or when sending a ping. thanks bobo1on1 --- diff --git a/src/lib/AdapterCommunication.cpp b/src/lib/AdapterCommunication.cpp index 74ea9e3..d665561 100644 --- a/src/lib/AdapterCommunication.cpp +++ b/src/lib/AdapterCommunication.cpp @@ -229,7 +229,7 @@ bool CCECAdapterMessage::is_error(void) const void CCECAdapterMessage::push_escaped(uint8_t byte) { - if (byte >= MSGESC && byte != MSGSTART) + if (byte >= MSGESC) { push_back(MSGESC); push_back(byte - ESCOFFSET); @@ -357,23 +357,27 @@ void CAdapterCommunication::WriteNextCommand(void) { CCECAdapterMessage *msg; if (m_outBuffer.Pop(msg)) + SendMessageToAdapter(msg); +} + +void CAdapterCommunication::SendMessageToAdapter(CCECAdapterMessage *msg) +{ + bool bReturn(true); + CLockObject lock(&msg->mutex); + if (m_port->Write(msg) != (int32_t) msg->size()) { - CLockObject lock(&msg->mutex); - if (m_port->Write(msg) != (int32_t) msg->size()) - { - CStdString strError; - strError.Format("error writing to serial port: %s", m_port->GetError().c_str()); - m_controller->AddLog(CEC_LOG_ERROR, strError); - msg->state = ADAPTER_MESSAGE_STATE_ERROR; - } - else - { - m_controller->AddLog(CEC_LOG_DEBUG, "command sent"); - CCondition::Sleep((uint32_t) msg->size() * 24 /*data*/ + 5 /*start bit (4.5 ms)*/ + 10); - msg->state = ADAPTER_MESSAGE_STATE_SENT; - } - msg->condition.Signal(); + CStdString strError; + strError.Format("error writing to serial port: %s", m_port->GetError().c_str()); + m_controller->AddLog(CEC_LOG_ERROR, strError); + msg->state = ADAPTER_MESSAGE_STATE_ERROR; } + else + { + m_controller->AddLog(CEC_LOG_DEBUG, "command sent"); + CCondition::Sleep((uint32_t) msg->size() * 24 /*data*/ + 5 /*start bit (4.5 ms)*/ + 10); + msg->state = ADAPTER_MESSAGE_STATE_SENT; + } + msg->condition.Signal(); } bool CAdapterCommunication::Write(CCECAdapterMessage *data) @@ -455,9 +459,8 @@ bool CAdapterCommunication::StartBootloader(void) output->push_escaped(MSGCODE_START_BOOTLOADER); output->push_back(MSGEND); - if ((bReturn = Write(output)) == false) - m_controller->AddLog(CEC_LOG_ERROR, "could not start the bootloader"); - + SendMessageToAdapter(output); + bReturn = output->state == ADAPTER_MESSAGE_STATE_SENT; delete output; return bReturn; @@ -476,10 +479,8 @@ bool CAdapterCommunication::PingAdapter(void) output->push_escaped(MSGCODE_PING); output->push_back(MSGEND); - if ((bReturn = Write(output)) == false) - m_controller->AddLog(CEC_LOG_ERROR, "could not send ping command"); - - // TODO check for pong + SendMessageToAdapter(output); + bReturn = output->state == ADAPTER_MESSAGE_STATE_SENT; delete output; return bReturn; diff --git a/src/lib/AdapterCommunication.h b/src/lib/AdapterCommunication.h index 1fdcf05..aaa0747 100644 --- a/src/lib/AdapterCommunication.h +++ b/src/lib/AdapterCommunication.h @@ -102,6 +102,7 @@ namespace CEC bool StartBootloader(void); private: + void SendMessageToAdapter(CCECAdapterMessage *msg); void WriteNextCommand(void); void AddData(uint8_t *data, uint8_t iLen); bool ReadFromDevice(uint32_t iTimeout);