if (m_outBuffer.Pop(msg))
{
CLockObject lock(&msg->mutex);
- if (m_port->Write(msg) != (int32_t) msg.get()->size())
+ 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.get()->size() * (uint32_t)24 /*data*/ + (uint32_t)5 /*start bit (4.5 ms)*/);
+ CCondition::Sleep((uint32_t) msg->size() * (uint32_t)24 /*data*/ + (uint32_t)5 /*start bit (4.5 ms)*/);
+ msg->state = ADAPTER_MESSAGE_STATE_SENT;
}
msg->condition.Signal();
}
bool CAdapterCommunication::Write(CCECAdapterMessagePtr data)
{
+ data->state = ADAPTER_MESSAGE_STATE_WAITING;
m_outBuffer.Push(data);
return true;
}
msg.push_back(buf);
}
+ if (bGotFullMessage)
+ msg.state = ADAPTER_MESSAGE_STATE_RECEIVED;
+
return bGotFullMessage;
}
namespace CEC
{
+ typedef enum cec_adapter_message_state
+ {
+ ADAPTER_MESSAGE_STATE_UNKNOWN = 0,
+ ADAPTER_MESSAGE_STATE_WAITING,
+ ADAPTER_MESSAGE_STATE_SENT,
+ ADAPTER_MESSAGE_STATE_RECEIVED,
+ ADAPTER_MESSAGE_STATE_ERROR
+ } cec_adapter_message_state;
+
+
class CCECAdapterMessage : public boost::enable_shared_from_this<CCECAdapterMessage>
{
public:
- CCECAdapterMessage(void) {}
+ CCECAdapterMessage(void) { clear(); }
CCECAdapterMessage(const cec_command &command);
bool empty(void) const { return packet.empty(); }
uint8_t operator[](uint8_t pos) const { return packet[pos]; }
uint8_t at(uint8_t pos) const { return packet[pos]; }
uint8_t size(void) const { return packet.size; }
- void clear(void) { packet.clear(); }
+ void clear(void) { state = ADAPTER_MESSAGE_STATE_UNKNOWN; packet.clear(); }
void shift(uint8_t iShiftBy) { packet.shift(iShiftBy); }
void push_back(uint8_t add) { packet.push_back(add); }
cec_adapter_messagecode message(void) const { return packet.size >= 1 ? (cec_adapter_messagecode) (packet.at(0) & ~(MSGCODE_FRAME_EOM | MSGCODE_FRAME_ACK)) : MSGCODE_NOTHING; }
cec_logical_address destination(void) const { return packet.size >= 2 ? (cec_logical_address) (packet.at(1) & 0xF) : CECDEVICE_UNKNOWN; };
void push_escaped(int16_t byte);
- cec_datapacket packet;
- CMutex mutex;
- CCondition condition;
+ cec_datapacket packet;
+ cec_adapter_message_state state;
+ CMutex mutex;
+ CCondition condition;
private:
CCECAdapterMessage &operator =(const CCECAdapterMessage &msg);
if (!m_communication || !m_communication->Write(output))
return bReturn;
else
+ {
output->condition.Wait(&output->mutex);
+ if (output->state != ADAPTER_MESSAGE_STATE_SENT)
+ {
+ m_controller->AddLog(CEC_LOG_ERROR, "command was not sent");
+ return bReturn;
+ }
+ }
}
if (bWaitForAck)