From: Lars Op den Kamp Date: Mon, 31 Oct 2011 19:55:59 +0000 (+0100) Subject: cec: show the command as string instead of int when an unexpected command was received. X-Git-Tag: upstream/2.2.0~1^2~149 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=b8c9190697f79d21df7207f1799654de9325c5a3;p=deb_libcec.git cec: show the command as string instead of int when an unexpected command was received. --- diff --git a/src/lib/AdapterCommunication.cpp b/src/lib/AdapterCommunication.cpp index 9d62afe..122565e 100644 --- a/src/lib/AdapterCommunication.cpp +++ b/src/lib/AdapterCommunication.cpp @@ -89,7 +89,7 @@ CCECAdapterMessage &CCECAdapterMessage::operator =(const CCECAdapterMessage &msg return *this; } -CStdString CCECAdapterMessage::ToString(void) const +CStdString CCECAdapterMessage::MessageCodeAsString(void) const { CStdString strMsg; switch (message()) @@ -101,31 +101,19 @@ CStdString CCECAdapterMessage::ToString(void) const strMsg = "PING"; break; case MSGCODE_TIMEOUT_ERROR: + strMsg = "TIMEOUT"; + break; case MSGCODE_HIGH_ERROR: + strMsg = "HIGH_ERROR"; + break; 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); - } + strMsg = "LOW_ERROR"; 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"; @@ -186,6 +174,38 @@ CStdString CCECAdapterMessage::ToString(void) const return strMsg; } +CStdString CCECAdapterMessage::ToString(void) const +{ + CStdString strMsg; + strMsg = MessageCodeAsString(); + + switch (message()) + { + case MSGCODE_TIMEOUT_ERROR: + case MSGCODE_HIGH_ERROR: + case MSGCODE_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: + if (size() >= 2) + strMsg.AppendFormat(" initiator:%1x destination:%1x ack:%s %s", initiator(), destination(), ack() ? "high" : "low", eom() ? "eom" : ""); + break; + case MSGCODE_FRAME_DATA: + if (size() >= 2) + strMsg.AppendFormat(" %02x %s", at(1), eom() ? "eom" : ""); + break; + default: + break; + } + + return strMsg; +} + bool CCECAdapterMessage::is_error(void) const { cec_adapter_messagecode code = message(); diff --git a/src/lib/AdapterCommunication.h b/src/lib/AdapterCommunication.h index 91e5ee6..21a775d 100644 --- a/src/lib/AdapterCommunication.h +++ b/src/lib/AdapterCommunication.h @@ -58,6 +58,7 @@ namespace CEC CCECAdapterMessage(const cec_command &command); CCECAdapterMessage &operator =(const CCECAdapterMessage &msg); CStdString ToString(void) const; + CStdString MessageCodeAsString(void) const; bool empty(void) const { return packet.empty(); } uint8_t operator[](uint8_t pos) const { return packet[pos]; } diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 3b6f6f2..5568d95 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -316,7 +316,7 @@ bool CCECProcessor::WaitForTransmitSucceeded(uint8_t iLength, uint32_t iTimeout break; default: CStdString strLog; - strLog.Format("received unexpected reply '%1x' instead of ack", msg.message()); + strLog.Format("received unexpected reply '%s' instead of ack", msg.MessageCodeAsString().c_str()); m_controller->AddLog(CEC_LOG_WARNING, strLog); bError = true; break;