From 6dfe921375b746dab058c1f1c3a8263fbd409d3d Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Thu, 29 Sep 2011 17:44:15 +0200 Subject: [PATCH] cec: fixed setting the ackmask. deprecated SetAckMask()/cec_set_ack_mask(). use SetLogicalAddress()/cec_set_logical_address() instead. add 'la' command to the testclient to set the logical address of the cec adapter --- include/CECExports.h | 2 +- include/CECExportsC.h | 18 +++++++++++++++--- include/CECExportsCpp.h | 9 +++++++-- src/lib/CECParser.cpp | 29 ++++++++++++++++++----------- src/lib/CECParser.h | 3 ++- src/lib/CECParserC.cpp | 11 +++++++++-- src/testclient/main.cpp | 14 +++++++++++--- 7 files changed, 63 insertions(+), 23 deletions(-) diff --git a/include/CECExports.h b/include/CECExports.h index c257570..ad1eb96 100644 --- a/include/CECExports.h +++ b/include/CECExports.h @@ -55,7 +55,7 @@ extern "C" { namespace CEC { #endif - #define CEC_MIN_VERSION 1 + #define CEC_MIN_VERSION 2 #define CEC_LIB_VERSION 2 #define CEC_SETTLE_DOWN_TIME 1000 diff --git a/include/CECExportsC.h b/include/CECExportsC.h index 79409b7..6fa4dbe 100644 --- a/include/CECExportsC.h +++ b/include/CECExportsC.h @@ -159,11 +159,23 @@ extern DECLSPEC bool cec_transmit(const cec_frame &data, bool bWaitForAck = true #endif /*! - * @brief Set the ack mask for the CEC adapter. - * @param ackmask The new ack mask. + * @brief Set the logical address of the CEC adapter. + * @param iLogicalAddress The cec adapter's logical address. + * @return True when the logical address was set succesfully, false otherwise. + */ +#ifdef __cplusplus +extern DECLSPEC bool cec_set_logical_address(CEC::cec_logical_address iLogicalAddress); +#else +extern DECLSPEC bool cec_set_logical_address(cec_logical_address myAddress, cec_logical_address targetAddress); +#endif + +/*! + * @deprecated Use cec_set_logical_address() instead. + * @brief Set the ack mask of the CEC adapter. + * @param iMask The cec adapter's ack mask. * @return True when the ack mask was sent succesfully, false otherwise. */ -extern DECLSPEC bool cec_set_ack_mask(uint16_t ackmask); +extern DECLSPEC bool cec_set_ack_mask(uint16_t iMask); /*! * @return Get the minimal version of libcec that this version of libcec can interface with. diff --git a/include/CECExportsCpp.h b/include/CECExportsCpp.h index b49b1ab..996ec7f 100644 --- a/include/CECExportsCpp.h +++ b/include/CECExportsCpp.h @@ -97,9 +97,14 @@ namespace CEC virtual bool Transmit(const cec_frame &data, bool bWaitForAck = true, int64_t iTimeout = (int64_t) 5000) = 0; /*! - * @see cec_set_ack_mask + * @see cec_set_logical_address */ - virtual bool SetAckMask(cec_logical_address ackmask) = 0; + virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress) = 0; + + /*! + * @deprecated use SetLogicalAddress() instead + */ + virtual bool SetAckMask(uint16_t iMask) = 0; /*! * @see cec_get_min_version diff --git a/src/lib/CECParser.cpp b/src/lib/CECParser.cpp index af86abe..8b89aa6 100644 --- a/src/lib/CECParser.cpp +++ b/src/lib/CECParser.cpp @@ -90,7 +90,7 @@ bool CCECParser::Open(const char *strPort, int iTimeoutMs /* = 10000 */) m_serialport->Read(buff, sizeof(buff), CEC_SETTLE_DOWN_TIME); if (bReturn) - bReturn = SetAckMask(m_iLogicalAddress); + bReturn = SetLogicalAddress(m_iLogicalAddress); if (!bReturn) { @@ -796,27 +796,34 @@ void CCECParser::CheckKeypressTimeout(int64_t now) } } -bool CCECParser::SetAckMask(cec_logical_address ackmask) +bool CCECParser::SetLogicalAddress(cec_logical_address iLogicalAddress) { CStdString strLog; - strLog.Format("setting ackmask to %d", (uint16_t) ackmask); + strLog.Format("setting logical address to %d", iLogicalAddress); AddLog(CEC_LOG_NOTICE, strLog.c_str()); + m_iLogicalAddress = iLogicalAddress; + return SetAckMask(0x1 << (uint8_t)m_iLogicalAddress); +} + +bool CCECParser::SetAckMask(uint16_t iMask) +{ + CStdString strLog; + strLog.Format("setting ackmask to %2x", iMask); + AddLog(CEC_LOG_DEBUG, strLog.c_str()); + cec_frame output; - m_iLogicalAddress = ackmask; - output.push_back(MSGSTART); + output.push_back(MSGSTART); PushEscaped(output, MSGCODE_SET_ACK_MASK); - PushEscaped(output, (uint8_t) ackmask >> 8); - PushEscaped(output, (uint8_t) ackmask << 2); - + PushEscaped(output, iMask >> 8); + PushEscaped(output, iMask); output.push_back(MSGEND); if (m_serialport->Write(output) == -1) { - CStdString strDebug; - strDebug.Format("error writing to serial port: %s", m_serialport->GetError().c_str()); - AddLog(CEC_LOG_ERROR, strDebug); + strLog.Format("error writing to serial port: %s", m_serialport->GetError().c_str()); + AddLog(CEC_LOG_ERROR, strLog); return false; } diff --git a/src/lib/CECParser.h b/src/lib/CECParser.h index 6f0caa4..f257fe1 100644 --- a/src/lib/CECParser.h +++ b/src/lib/CECParser.h @@ -63,7 +63,8 @@ namespace CEC virtual bool GetNextLogMessage(cec_log_message *message); virtual bool GetNextKeypress(cec_keypress *key); virtual bool Transmit(const cec_frame &data, bool bWaitForAck = true, int64_t iTimeout = (int64_t) 5000); - virtual bool SetAckMask(cec_logical_address ackmask); + virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress); + virtual bool SetAckMask(uint16_t iMask); virtual int GetMinVersion(void); virtual int GetLibVersion(void); //@} diff --git a/src/lib/CECParserC.cpp b/src/lib/CECParserC.cpp index 1aae849..4b6a1ef 100644 --- a/src/lib/CECParserC.cpp +++ b/src/lib/CECParserC.cpp @@ -131,10 +131,17 @@ bool cec_transmit(const CEC::cec_frame &data, bool bWaitForAck /* = true */, int return false; } -bool cec_set_ack_mask(uint16_t ackmask) +bool cec_set_logical_address(cec_logical_address iLogicalAddress) { if (cec_parser) - return cec_parser->SetAckMask((cec_logical_address) ackmask); + return cec_parser->SetLogicalAddress(iLogicalAddress); + return false; +} + +bool cec_set_ack_mask(uint16_t iMask) +{ + if (cec_parser) + return cec_parser->SetAckMask(iMask); return false; } diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index 0edf5cd..bfbec5e 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -42,7 +42,7 @@ using namespace CEC; using namespace std; -#define CEC_TEST_CLIENT_VERSION 1 +#define CEC_TEST_CLIENT_VERSION 2 void flush_log(ICECDevice *cecParser) { @@ -203,10 +203,18 @@ int main (int argc, char *argv[]) { string strvalue; int ackmask; - vector bytes; if (GetWord(input, strvalue) && HexStrToInt(strvalue, ackmask)) { - parser->SetAckMask((cec_logical_address) ackmask); + parser->SetAckMask(ackmask); + } + } + else if (command == "la") + { + string strvalue; + int iLogicalAddress; + if (GetWord(input, strvalue)) + { + parser->SetLogicalAddress((cec_logical_address) atoi(strvalue.c_str())); } } else if (command == "ping") -- 2.34.1