From e41b06f9e1fc5c8af372eabf338dbb691ee7ac4c Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Mon, 31 Oct 2011 20:35:58 +0100 Subject: [PATCH] cec: cleaned up logging --- src/lib/AdapterCommunication.cpp | 112 +++++++++++++++++++++++++++++++ src/lib/AdapterCommunication.h | 3 + src/lib/CECProcessor.cpp | 108 ++--------------------------- src/lib/CECProcessor.h | 42 ++++++------ 4 files changed, 142 insertions(+), 123 deletions(-) diff --git a/src/lib/AdapterCommunication.cpp b/src/lib/AdapterCommunication.cpp index 0fee28b..9d62afe 100644 --- a/src/lib/AdapterCommunication.cpp +++ b/src/lib/AdapterCommunication.cpp @@ -89,6 +89,118 @@ CCECAdapterMessage &CCECAdapterMessage::operator =(const CCECAdapterMessage &msg return *this; } +CStdString CCECAdapterMessage::ToString(void) const +{ + CStdString strMsg; + switch (message()) + { + case MSGCODE_NOTHING: + strMsg = "NOTHING"; + break; + case MSGCODE_PING: + strMsg = "PING"; + break; + case MSGCODE_TIMEOUT_ERROR: + case MSGCODE_HIGH_ERROR: + case MSGCODE_LOW_ERROR: + { + if (message() == MSGCODE_TIMEOUT_ERROR) + strMsg = "TIMEOUT"; + else if (message() == MSGCODE_HIGH_ERROR) + strMsg = "HIGH_ERROR"; + else + strMsg = "LOW_ERROR"; + + int iLine = (size() >= 3) ? (at(1) << 8) | at(2) : 0; + uint32_t iTime = (size() >= 7) ? (at(3) << 24) | (at(4) << 16) | (at(5) << 8) | at(6) : 0; + strMsg.AppendFormat(" line:%i", iLine); + strMsg.AppendFormat(" time:%u", iTime); + } + break; + case MSGCODE_FRAME_START: + strMsg = "FRAME_START"; + if (size() >= 2) + strMsg.AppendFormat(" initiator:%1x destination:%1x ack:%s %s", initiator(), destination(), ack() ? "high" : "low", eom() ? "eom" : ""); + break; + case MSGCODE_FRAME_DATA: + strMsg = "FRAME_DATA"; + if (size() >= 2) + strMsg.AppendFormat(" %02x %s", at(1), eom() ? "eom" : ""); + break; + case MSGCODE_RECEIVE_FAILED: + strMsg = "RECEIVE_FAILED"; + break; + case MSGCODE_COMMAND_ACCEPTED: + strMsg = "COMMAND_ACCEPTED"; + break; + case MSGCODE_COMMAND_REJECTED: + strMsg = "COMMAND_REJECTED"; + break; + case MSGCODE_SET_ACK_MASK: + strMsg = "SET_ACK_MASK"; + break; + case MSGCODE_TRANSMIT: + strMsg = "TRANSMIT"; + break; + case MSGCODE_TRANSMIT_EOM: + strMsg = "TRANSMIT_EOM"; + break; + case MSGCODE_TRANSMIT_IDLETIME: + strMsg = "TRANSMIT_IDLETIME"; + break; + case MSGCODE_TRANSMIT_ACK_POLARITY: + strMsg = "TRANSMIT_ACK_POLARITY"; + break; + case MSGCODE_TRANSMIT_LINE_TIMEOUT: + strMsg = "TRANSMIT_LINE_TIMEOUT"; + break; + case MSGCODE_TRANSMIT_SUCCEEDED: + strMsg = "TRANSMIT_SUCCEEDED"; + break; + case MSGCODE_TRANSMIT_FAILED_LINE: + strMsg = "TRANSMIT_FAILED_LINE"; + break; + case MSGCODE_TRANSMIT_FAILED_ACK: + strMsg = "TRANSMIT_FAILED_ACK"; + break; + case MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA: + strMsg = "TRANSMIT_FAILED_TIMEOUT_DATA"; + break; + case MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE: + strMsg = "TRANSMIT_FAILED_TIMEOUT_LINE"; + break; + case MSGCODE_FIRMWARE_VERSION: + strMsg = "FIRMWARE_VERSION"; + break; + case MSGCODE_START_BOOTLOADER: + strMsg = "START_BOOTLOADER"; + break; + case MSGCODE_FRAME_EOM: + strMsg = "FRAME_EOM"; + break; + case MSGCODE_FRAME_ACK: + strMsg = "FRAME_ACK"; + break; + } + + return strMsg; +} + +bool CCECAdapterMessage::is_error(void) const +{ + cec_adapter_messagecode code = message(); + return (code == MSGCODE_TIMEOUT_ERROR || + code == MSGCODE_HIGH_ERROR || + code == MSGCODE_LOW_ERROR || + code == MSGCODE_RECEIVE_FAILED || + code == MSGCODE_COMMAND_REJECTED || + code == MSGCODE_TRANSMIT_LINE_TIMEOUT || + code == MSGCODE_TRANSMIT_FAILED_LINE || + code == MSGCODE_TRANSMIT_FAILED_ACK || + code == MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA || + code == MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE); +} + void CCECAdapterMessage::push_escaped(int16_t byte) { if (byte >= MSGESC && byte != MSGSTART) diff --git a/src/lib/AdapterCommunication.h b/src/lib/AdapterCommunication.h index 73b3bd2..91e5ee6 100644 --- a/src/lib/AdapterCommunication.h +++ b/src/lib/AdapterCommunication.h @@ -34,6 +34,7 @@ #include #include "platform/threads.h" #include "util/buffer.h" +#include "util/StdString.h" #include #include #include @@ -56,6 +57,7 @@ namespace CEC CCECAdapterMessage(void) { clear(); } CCECAdapterMessage(const cec_command &command); CCECAdapterMessage &operator =(const CCECAdapterMessage &msg); + CStdString ToString(void) const; bool empty(void) const { return packet.empty(); } uint8_t operator[](uint8_t pos) const { return packet[pos]; } @@ -69,6 +71,7 @@ namespace CEC bool ack(void) const { return packet.size >= 1 ? (packet.at(0) & MSGCODE_FRAME_ACK) != 0 : false; } cec_logical_address initiator(void) const { return packet.size >= 2 ? (cec_logical_address) (packet.at(1) >> 4) : CECDEVICE_UNKNOWN; }; cec_logical_address destination(void) const { return packet.size >= 2 ? (cec_logical_address) (packet.at(1) & 0xF) : CECDEVICE_UNKNOWN; }; + bool is_error(void) const; void push_escaped(int16_t byte); cec_datapacket packet; diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index f0f951e..19984f0 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -305,64 +305,21 @@ bool CCECProcessor::WaitForAck(bool *bError, uint8_t iLength, uint32_t iTimeout continue; } + *bError = msg.is_error(); + m_controller->AddLog(msg.is_error() ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString()); + switch(msg.message()) { - case MSGCODE_TIMEOUT_ERROR: - case MSGCODE_HIGH_ERROR: - case MSGCODE_LOW_ERROR: - { - CStdString logStr; - if (msg.message() == MSGCODE_TIMEOUT_ERROR) - logStr = "MSGCODE_TIMEOUT"; - else if (msg.message() == MSGCODE_HIGH_ERROR) - logStr = "MSGCODE_HIGH_ERROR"; - else - logStr = "MSGCODE_LOW_ERROR"; - - int iLine = (msg.size() >= 3) ? (msg[1] << 8) | (msg[2]) : 0; - uint32_t iTime = (msg.size() >= 7) ? (msg[3] << 24) | (msg[4] << 16) | (msg[5] << 8) | (msg[6]) : 0; - logStr.AppendFormat(" line:%i", iLine); - logStr.AppendFormat(" time:%u", iTime); - m_controller->AddLog(CEC_LOG_WARNING, logStr.c_str()); - *bError = true; - } - break; case MSGCODE_COMMAND_ACCEPTED: - m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_COMMAND_ACCEPTED"); iPacketsLeft--; break; case MSGCODE_TRANSMIT_SUCCEEDED: - m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_TRANSMIT_SUCCEEDED"); bTransmitSucceeded = (iPacketsLeft == 0); *bError = !bTransmitSucceeded; break; - case MSGCODE_RECEIVE_FAILED: - m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_RECEIVE_FAILED"); - *bError = true; - break; - case MSGCODE_COMMAND_REJECTED: - m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_COMMAND_REJECTED"); - *bError = true; - break; - case MSGCODE_TRANSMIT_FAILED_LINE: - m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_LINE"); - *bError = true; - break; - case MSGCODE_TRANSMIT_FAILED_ACK: - m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_ACK"); - *bError = true; - break; - case MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA: - m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA"); - *bError = true; - break; - case MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE: - m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE"); - *bError = true; - break; default: CStdString strLog; - strLog.Format("received unexpected reply '%2x'", msg.message()); + strLog.Format("received unexpected reply '%1x' instead of ack", msg.message()); m_controller->AddLog(CEC_LOG_WARNING, strLog); *bError = true; break; @@ -381,85 +338,32 @@ bool CCECProcessor::ParseMessage(const CCECAdapterMessage &msg) if (msg.empty()) return bEom; - CStdString logStr; + m_controller->AddLog(msg.is_error() ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString()); switch(msg.message()) { - case MSGCODE_NOTHING: - m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_NOTHING"); - break; - case MSGCODE_TIMEOUT_ERROR: - case MSGCODE_HIGH_ERROR: - case MSGCODE_LOW_ERROR: - { - if (msg.message() == MSGCODE_TIMEOUT_ERROR) - logStr = "MSGCODE_TIMEOUT"; - else if (msg.message() == MSGCODE_HIGH_ERROR) - logStr = "MSGCODE_HIGH_ERROR"; - else - logStr = "MSGCODE_LOW_ERROR"; - - int iLine = (msg.size() >= 3) ? (msg[1] << 8) | (msg[2]) : 0; - uint32_t iTime = (msg.size() >= 7) ? (msg[3] << 24) | (msg[4] << 16) | (msg[5] << 8) | (msg[6]) : 0; - logStr.AppendFormat(" line:%i", iLine); - logStr.AppendFormat(" time:%u", iTime); - m_controller->AddLog(CEC_LOG_WARNING, logStr.c_str()); - } - break; case MSGCODE_FRAME_START: { - logStr = "MSGCODE_FRAME_START"; m_currentframe.clear(); if (msg.size() >= 2) { - logStr.AppendFormat(" initiator:%1x destination:%1x ack:%s %s", msg.initiator(), msg.destination(), msg.ack() ? "high" : "low", msg.eom() ? "eom" : ""); m_currentframe.initiator = msg.initiator(); m_currentframe.destination = msg.destination(); m_currentframe.ack = msg.ack(); m_currentframe.eom = msg.eom(); } - m_controller->AddLog(CEC_LOG_DEBUG, logStr.c_str()); } break; case MSGCODE_FRAME_DATA: { - logStr = "MSGCODE_FRAME_DATA"; if (msg.size() >= 2) { - uint8_t iData = msg[1]; - logStr.AppendFormat(" %02x", iData); - m_currentframe.push_back(iData); + m_currentframe.push_back(msg[1]); m_currentframe.eom = msg.eom(); } - m_controller->AddLog(CEC_LOG_DEBUG, logStr.c_str()); - bEom = msg.eom(); } break; - case MSGCODE_COMMAND_ACCEPTED: - m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_COMMAND_ACCEPTED"); - break; - case MSGCODE_TRANSMIT_SUCCEEDED: - m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_TRANSMIT_SUCCEEDED"); - break; - case MSGCODE_RECEIVE_FAILED: - m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_RECEIVE_FAILED"); - break; - case MSGCODE_COMMAND_REJECTED: - m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_COMMAND_REJECTED"); - break; - case MSGCODE_TRANSMIT_FAILED_LINE: - m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_LINE"); - break; - case MSGCODE_TRANSMIT_FAILED_ACK: - m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_ACK"); - break; - case MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA: - m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA"); - break; - case MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE: - m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE"); - break; default: break; } diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index fa5d6fe..2d5c312 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -53,46 +53,46 @@ namespace CEC virtual ~CCECProcessor(void); virtual bool Start(void); - void *Process(void); + virtual void *Process(void); + + virtual cec_version GetDeviceCecVersion(cec_logical_address iAddress); + virtual bool GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language); + virtual const std::string & GetDeviceName(void) { return m_strDeviceName; } + virtual uint64_t GetDeviceVendorId(cec_logical_address iAddress); + virtual cec_power_status GetDevicePowerStatus(cec_logical_address iAddress); + virtual cec_logical_address GetLogicalAddress(void) const { return m_iLogicalAddress; } + virtual uint16_t GetPhysicalAddress(void) const; virtual bool SetActiveView(void); virtual bool SetInactiveView(void); - virtual bool Transmit(const cec_command &data); virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress = CECDEVICE_UNKNOWN); virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress); virtual bool SwitchMonitoring(bool bEnable); - virtual cec_version GetDeviceCecVersion(cec_logical_address iAddress); - virtual bool GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language); - virtual uint64_t GetDeviceVendorId(cec_logical_address iAddress); - virtual cec_power_status GetDevicePowerStatus(cec_logical_address iAddress); - virtual cec_logical_address GetLogicalAddress(void) const { return m_iLogicalAddress; } - virtual uint16_t GetPhysicalAddress(void) const; - virtual const std::string &GetDeviceName(void) { return m_strDeviceName; } + virtual bool Transmit(const cec_command &data); + virtual void TransmitAbort(cec_logical_address address, cec_opcode opcode, ECecAbortReason reason = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE); virtual void SetCurrentButton(cec_user_control_code iButtonCode); virtual void AddCommand(const cec_command &command); virtual void AddKey(void); virtual void AddLog(cec_log_level level, const CStdString &strMessage); - virtual void TransmitAbort(cec_logical_address address, cec_opcode opcode, ECecAbortReason reason = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE); - CCECBusDevice *m_busDevices[16]; - private: + private: void LogOutput(const cec_command &data); bool WaitForAck(bool *bError, uint8_t iLength, uint32_t iTimeout = 1000); bool ParseMessage(const CCECAdapterMessage &msg); void ParseCommand(cec_command &command); - cec_command m_currentframe; - cec_logical_address m_iLogicalAddress; - std::string m_strDeviceName; - CMutex m_mutex; - CCondition m_startCondition; - CAdapterCommunication *m_communication; - CLibCEC *m_controller; - bool m_bMonitor; - bool m_bLogicalAddressSet; + cec_command m_currentframe; + cec_logical_address m_iLogicalAddress; + std::string m_strDeviceName; + CMutex m_mutex; + CCondition m_startCondition; + CAdapterCommunication *m_communication; + CLibCEC *m_controller; + bool m_bMonitor; + bool m_bLogicalAddressSet; }; }; -- 2.34.1