X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2FCECProcessor.cpp;h=60ad2e3c26804ca306d2932b816708ef401d8146;hb=a6d4fc2833d504007cd43eb0069ad2c6ed57d83b;hp=6757f8ad33abedf2e4364c7f62e12b5f0a7b9fdb;hpb=88f45c9b0ef4f03bf78ad3abc8996c0dcc95010b;p=deb_libcec.git diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 6757f8a..60ad2e3 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -47,6 +47,10 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm m_communication(serComm), m_controller(controller) { + for (uint8_t iPtr = 0; iPtr < 16; iPtr++) + m_vendorIds[iPtr] = CEC_VENDOR_UNKNOWN; + for (uint8_t iPtr = 0; iPtr < 16; iPtr++) + m_vendorClasses[iPtr] = (uint8_t) 0; } CCECProcessor::~CCECProcessor(void) @@ -237,10 +241,25 @@ bool CCECProcessor::TransmitFormatted(const cec_frame &data, bool bWaitForAck /* if (!m_communication || !m_communication->Write(data)) return false; - if (bWaitForAck && !WaitForAck()) + if (bWaitForAck) { - m_controller->AddLog(CEC_LOG_DEBUG, "did not receive ACK"); - return false; + uint64_t now = GetTimeMs(); + uint64_t target = now + 1000; + bool bError(false); + bool bGotAck(false); + + while (!bGotAck && now < target) + { + bGotAck = WaitForAck(&bError, (uint64_t) (target - now)); + now = GetTimeMs(); + + if (bError && now < target) + { + m_controller->AddLog(CEC_LOG_ERROR, "retransmitting previous frame"); + if (!m_communication->Write(data)) + return false; + } + } } return true; @@ -348,7 +367,7 @@ void CCECProcessor::BroadcastActiveSource(void) cec_frame frame; frame.clear(); - m_controller->AddLog(CEC_LOG_NOTICE, "broadcasting active source"); + m_controller->AddLog(CEC_LOG_NOTICE, "<< broadcasting active source"); frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST)); frame.push_back((uint8_t) CEC_OPCODE_ACTIVE_SOURCE); frame.push_back((uint8_t) ((m_physicaladdress >> 8) & 0xFF)); @@ -361,10 +380,10 @@ uint8_t CCECProcessor::GetSourceDestination(cec_logical_address destination /* = return ((uint8_t)m_iLogicalAddress << 4) + (uint8_t)destination; } -bool CCECProcessor::WaitForAck(uint32_t iTimeout /* = 1000 */) +bool CCECProcessor::WaitForAck(bool *bError, uint32_t iTimeout /* = 1000 */) { bool bGotAck(false); - bool bError(false); + *bError = false; int64_t iNow = GetTimeMs(); int64_t iTargetTime = iNow + (uint64_t) iTimeout; @@ -390,27 +409,27 @@ bool CCECProcessor::WaitForAck(uint32_t iTimeout /* = 1000 */) break; case MSGCODE_RECEIVE_FAILED: m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_RECEIVE_FAILED"); - bError = true; + *bError = true; break; case MSGCODE_COMMAND_REJECTED: m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_COMMAND_REJECTED"); - bError = true; + *bError = true; break; case MSGCODE_TRANSMIT_FAILED_LINE: m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_LINE"); - bError = true; + *bError = true; break; case MSGCODE_TRANSMIT_FAILED_ACK: m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_ACK"); - bError = true; + *bError = true; break; case MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA: m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA"); - bError = true; + *bError = true; break; case MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE: m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE"); - bError = true; + *bError = true; break; default: m_frameBuffer.Push(msg); @@ -494,6 +513,26 @@ bool CCECProcessor::ParseMessage(cec_frame &msg) return bReturn; } +void CCECProcessor::ParseVendorId(cec_logical_address device, cec_frame data) +{ + if (data.size < 3) + { + m_controller->AddLog(CEC_LOG_WARNING, "invalid vendor ID received"); + return; + } + + uint64_t iVendorId = ((uint64_t)data.data[0] << 3) + + ((uint64_t)data.data[1] << 2) + + (uint64_t)data.data[2]; + + m_vendorIds[(uint8_t)device] = iVendorId; + m_vendorClasses[(uint8_t)device] = data.size >= 4 ? data.data[3] : 0; + + CStdString strLog; + strLog.Format("device %d: vendor = %s (%lld) class = %2x", (uint8_t)device, CECVendorIdToString(m_vendorIds[(uint8_t)device]), iVendorId, m_vendorClasses[(uint8_t)device]); + m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str()); +} + void CCECProcessor::ParseCurrentFrame(cec_frame &frame) { uint8_t initiator = frame.data[0] >> 4; @@ -520,7 +559,6 @@ void CCECProcessor::ParseCurrentFrame(cec_frame &frame) { case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: ReportPhysicalAddress(); - SetActiveView(); break; case CEC_OPCODE_GIVE_OSD_NAME: ReportOSDName((cec_logical_address)initiator); @@ -528,11 +566,17 @@ void CCECProcessor::ParseCurrentFrame(cec_frame &frame) case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: ReportVendorID((cec_logical_address)initiator); break; + case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: + frame.shift(2); + ParseVendorId((cec_logical_address)initiator, frame); + TransmitAbort((cec_logical_address)initiator, CEC_OPCODE_VENDOR_COMMAND_WITH_ID); + break; case CEC_OPCODE_MENU_REQUEST: ReportMenuState((cec_logical_address)initiator); break; case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: ReportPowerState((cec_logical_address)initiator); + SetActiveView(); break; case CEC_OPCODE_GET_CEC_VERSION: ReportCECVersion((cec_logical_address)initiator); @@ -550,9 +594,8 @@ void CCECProcessor::ParseCurrentFrame(cec_frame &frame) m_controller->AddKey(); break; default: - cec_frame params = frame; - params.shift(2); - m_controller->AddCommand((cec_logical_address) initiator, (cec_logical_address) destination, opCode, ¶ms); + frame.shift(2); + m_controller->AddCommand((cec_logical_address) initiator, (cec_logical_address) destination, opCode, &frame); break; } } @@ -579,7 +622,7 @@ void CCECProcessor::ParseCurrentFrame(cec_frame &frame) else { cec_frame params = frame; - params.shift(2); + frame.shift(2); m_controller->AddCommand((cec_logical_address) initiator, (cec_logical_address) destination, opCode, ¶ms); } }