From: Lars Op den Kamp Date: Sat, 5 Nov 2011 12:11:33 +0000 (+0100) Subject: cec: added PollDevice()/cec_poll_device() X-Git-Tag: upstream/2.2.0~1^2~113 X-Git-Url: https://git.piment-noir.org/?p=deb_libcec.git;a=commitdiff_plain;h=57f45e6c93ae094071e8a2f3f3786d4f26265a1d cec: added PollDevice()/cec_poll_device() --- diff --git a/include/cec.h b/include/cec.h index 19bc4d3..c1aad1c 100644 --- a/include/cec.h +++ b/include/cec.h @@ -164,6 +164,11 @@ namespace CEC * @see cec_get_device_power_status */ virtual cec_power_status GetDevicePowerStatus(cec_logical_address iAddress) = 0; + + /*! + * @see cec_poll_device + */ + virtual bool PollDevice(cec_logical_address iAddress) = 0; }; }; diff --git a/include/cecc.h b/include/cecc.h index e1c2942..8a06956 100644 --- a/include/cecc.h +++ b/include/cecc.h @@ -271,6 +271,17 @@ extern DECLSPEC CEC::cec_power_status cec_get_device_power_status(CEC::cec_logic extern DECLSPEC cec_power_status cec_get_device_power_status(cec_logical_address iLogicalAddress); #endif +/*! + * @brief Sends a POLL message to a device. + * @param iAddress The device to send the message to. + * @return True if the POLL was acked, false otherwise. + */ +#ifdef __cplusplus +extern DECLSPEC int cec_poll_device(CEC::cec_logical_address iLogicalAddress); +#else +extern DECLSPEC int cec_poll_device(cec_logical_address iLogicalAddress); +#endif + #ifdef __cplusplus }; #endif diff --git a/include/cectypes.h b/include/cectypes.h index 3879a61..9481a1f 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -526,7 +526,8 @@ typedef enum cec_opcode CEC_OPCODE_SET_SYSTEM_AUDIO_MODE = 0x72, CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST = 0x70, CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS = 0x7E, - CEC_OPCODE_SET_AUDIO_RATE = 0x9A + CEC_OPCODE_SET_AUDIO_RATE = 0x9A, + CEC_OPCODE_NONE = 0xFD /* when this opcode is set, no opcode will be sent to the device. this is one of the reserved numbers */ } cec_opcode; typedef enum cec_log_level @@ -671,10 +672,13 @@ typedef struct cec_command static void format(cec_command &command, cec_logical_address initiator, cec_logical_address destination, cec_opcode opcode) { command.clear(); - command.initiator = initiator; - command.destination = destination; - command.opcode = opcode; - command.opcode_set = 1; + command.initiator = initiator; + command.destination = destination; + if (opcode != CEC_OPCODE_NONE) + { + command.opcode = opcode; + command.opcode_set = 1; + } } void push_back(uint8_t data) diff --git a/src/lib/AdapterCommunication.cpp b/src/lib/AdapterCommunication.cpp index 6614783..9b4490b 100644 --- a/src/lib/AdapterCommunication.cpp +++ b/src/lib/AdapterCommunication.cpp @@ -56,29 +56,32 @@ CCECAdapterMessage::CCECAdapterMessage(const cec_command &command) // add source and destination push_back(MSGSTART); - push_escaped(MSGCODE_TRANSMIT); + push_escaped(command.opcode_set == 0 ? (uint8_t)MSGCODE_TRANSMIT_EOM : (uint8_t)MSGCODE_TRANSMIT); push_back(((uint8_t)command.initiator << 4) + (uint8_t)command.destination); push_back(MSGEND); // add opcode - push_back(MSGSTART); - push_escaped(command.parameters.empty() ? (uint8_t)MSGCODE_TRANSMIT_EOM : (uint8_t)MSGCODE_TRANSMIT); - push_back((uint8_t) command.opcode); - push_back(MSGEND); - - // add parameters - for (int8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) + if (command.opcode_set == 1) { push_back(MSGSTART); + push_escaped(command.parameters.empty() ? (uint8_t)MSGCODE_TRANSMIT_EOM : (uint8_t)MSGCODE_TRANSMIT); + push_back((uint8_t) command.opcode); + push_back(MSGEND); - if (iPtr == command.parameters.size - 1) - push_escaped( MSGCODE_TRANSMIT_EOM); - else - push_escaped(MSGCODE_TRANSMIT); + // add parameters + for (int8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) + { + push_back(MSGSTART); - push_escaped(command.parameters[iPtr]); + if (iPtr == command.parameters.size - 1) + push_escaped( MSGCODE_TRANSMIT_EOM); + else + push_escaped(MSGCODE_TRANSMIT); - push_back(MSGEND); + push_escaped(command.parameters[iPtr]); + + push_back(MSGEND); + } } // set timeout diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index f781b6f..49b3bd2 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -156,7 +156,9 @@ bool CCECProcessor::SetInactiveView(void) void CCECProcessor::LogOutput(const cec_command &data) { CStdString strTx; - strTx.Format("<< %02x:%02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination, (uint8_t)data.opcode); + strTx.Format("<< %02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination); + if (data.opcode_set) + strTx.AppendFormat(":%02x", (uint8_t)data.opcode); for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++) strTx.AppendFormat(":%02x", data.parameters[iPtr]); @@ -200,6 +202,13 @@ bool CCECProcessor::SwitchMonitoring(bool bEnable) return SetAckMask(0x1 << (uint8_t)m_iLogicalAddress); } +bool CCECProcessor::PollDevice(cec_logical_address iAddress) +{ + if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress]) + return m_busDevices[iAddress]->PollDevice(); + return false; +} + cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress) { return m_busDevices[iAddress]->GetCecVersion(); diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index d865167..ea61365 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -68,6 +68,7 @@ namespace CEC virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress); virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress); virtual bool SwitchMonitoring(bool bEnable); + virtual bool PollDevice(cec_logical_address iAddress); virtual bool Transmit(const cec_command &data); virtual bool Transmit(CCECAdapterMessage *output); diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 95e2a2e..aff5776 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -215,6 +215,13 @@ cec_power_status CLibCEC::GetDevicePowerStatus(cec_logical_address iAddress) return CEC_POWER_STATUS_UNKNOWN; } +bool CLibCEC::PollDevice(cec_logical_address iAddress) +{ + if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST) + return m_cec->PollDevice(iAddress); + return false; +} + void CLibCEC::AddLog(cec_log_level level, const string &strMessage) { if (m_cec) diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index 0b43aa4..bd3ca60 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -78,6 +78,7 @@ namespace CEC 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 bool PollDevice(cec_logical_address iAddress); //@} virtual void AddLog(cec_log_level level, const std::string &strMessage); diff --git a/src/lib/LibCECC.cpp b/src/lib/LibCECC.cpp index a3be5f3..09b40db 100644 --- a/src/lib/LibCECC.cpp +++ b/src/lib/LibCECC.cpp @@ -222,4 +222,11 @@ cec_power_status cec_get_device_power_status(cec_logical_address iLogicalAddress return CEC_POWER_STATUS_UNKNOWN; } +int cec_poll_device(cec_logical_address iLogicalAddress) +{ + if (cec_parser) + return cec_parser->PollDevice(iLogicalAddress); + return -1; +} + //@} diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 0678ce3..5a56dc4 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -433,3 +433,20 @@ cec_power_status CCECBusDevice::GetPowerStatus(bool bRefresh /* = true */) return m_powerStatus; } + +bool CCECBusDevice::PollDevice(void) +{ + bool bReturn(false); + + CStdString strLog; + strLog.Format("<< sending POLL from device %1x to device %1x", (int8_t)GetMyLogicalAddress(), m_iLogicalAddress); + AddLog(CEC_LOG_DEBUG, strLog); + + cec_command command; + cec_command::format(command, GetMyLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_NONE); + CLockObject lock(&m_mutex); + + bReturn = m_processor->Transmit(command); + AddLog(CEC_LOG_DEBUG, bReturn ? ">> POLL sent" : ">> POLL not sent"); + return bReturn; +} diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index 5971f58..278c038 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -58,6 +58,7 @@ namespace CEC virtual cec_version GetCecVersion(bool bRefresh = true); virtual cec_menu_language & GetMenuLanguage(bool bRefresh = true); virtual cec_power_status GetPowerStatus(bool bRefresh = true); + virtual bool PollDevice(void); virtual bool PowerOn(void); virtual bool Standby(void); diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index 8efffed..0481829 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -230,6 +230,9 @@ void show_console_help(void) "pow {addr} get the power status of the specified device." << endl << "[pow 0] get the power status of the TV" << endl << endl << + "poll {addr} poll the specified device." << endl << + "[poll 0] sends a poll message to the TV" << endl << + endl << "[mon] {1|0} enable or disable CEC bus monitoring." << endl << "[log] {1 - 31} change the log level. see cectypes.h for values." << endl << "[ping] send a ping command to the CEC adapter." << endl << @@ -451,6 +454,22 @@ int main (int argc, char *argv[]) cout << "invalid destination" << endl; } } + else if (command == "poll") + { + string strValue; + uint8_t iValue = 0; + if (GetWord(input, strValue) && HexStrToInt(strValue, iValue) && iValue <= 0xF) + { + if (parser->PollDevice((cec_logical_address) iValue)) + cout << "POLL message sent" << endl; + else + cout << "POLL message not sent" << endl; + } + else + { + cout << "invalid destination" << endl; + } + } else if (command == "la") { string strvalue;