X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2FCECParser.cpp;h=97fbcd370b3542831ee2a67d41bade1068be92d0;hb=fac23b028a858e6c8e4773b8a1670b4f96c96ce7;hp=af86abe0d83ab98b4a6eaa2802ab0f8bb3f9825d;hpb=df7339c665f732faedee7c1d3cde816cc41e3302;p=deb_libcec.git diff --git a/src/lib/CECParser.cpp b/src/lib/CECParser.cpp index af86abe..97fbcd3 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) { @@ -255,9 +255,14 @@ bool CCECParser::GetNextKeypress(cec_keypress *key) { return m_keyBuffer.Pop(*key); } + +bool CCECParser::GetNextCommand(cec_command *command) +{ + return m_commandBuffer.Pop(*command); +} //@} -void CCECParser::TransmitAbort(cec_logical_address address, ECecOpcode opcode, ECecAbortReason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */) +void CCECParser::TransmitAbort(cec_logical_address address, cec_opcode opcode, ECecAbortReason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */) { AddLog(CEC_LOG_DEBUG, "transmitting abort message"); cec_frame frame; @@ -692,7 +697,7 @@ void CCECParser::ParseCurrentFrame(void) return; vector tx; - ECecOpcode opCode = (ECecOpcode) m_currentframe[1]; + cec_opcode opCode = (cec_opcode) m_currentframe[1]; if (destination == (uint16_t) m_iLogicalAddress) { switch(opCode) @@ -732,6 +737,9 @@ void CCECParser::ParseCurrentFrame(void) AddKey(); break; default: + cec_frame params = m_currentframe; + params.erase(params.begin(), params.begin() + 2); + AddCommand((cec_logical_address) initiator, (cec_logical_address) destination, opCode, ¶ms); break; } } @@ -796,27 +804,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, (uint8_t)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; } @@ -844,6 +859,17 @@ void CCECParser::AddKey(void) } } +void CCECParser::AddCommand(cec_logical_address source, cec_logical_address destination, cec_opcode opcode, cec_frame *parameters) +{ + cec_command command; + command.source = source; + command.destination = destination; + command.opcode = opcode; + if (parameters) + command.parameters = *parameters; + m_commandBuffer.Push(command); +} + int CCECParser::GetMinVersion(void) { return CEC_MIN_VERSION; @@ -866,7 +892,7 @@ int CCECParser::FindDevices(std::vector &deviceList, const char *str return CCECDetect::FindDevices(deviceList, strDevicePath); } -DECLSPEC void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress /* = CEC::CECDEVICE_PLAYBACKDEVICE1 */, int iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) +DECLSPEC void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress /*= CEC::CECDEVICE_PLAYBACKDEVICE1 */, int iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) { return static_cast< void* > (new CCECParser(strDeviceName, iLogicalAddress, iPhysicalAddress)); }