-
-void CCECParser::PushEscaped(cec_frame &vec, uint8_t byte)
-{
- if (byte >= MSGESC && byte != MSGSTART)
- {
- vec.push_back(MSGESC);
- vec.push_back(byte - ESCOFFSET);
- }
- else
- {
- vec.push_back(byte);
- }
-}
-
-void CCECParser::CheckKeypressTimeout(int64_t now)
-{
- if (m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN && now - m_buttontime > CEC_BUTTON_TIMEOUT)
- {
- AddKey();
- m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN;
- }
-}
-
-bool CCECParser::SetLogicalAddress(cec_logical_address iLogicalAddress)
-{
- CStdString strLog;
- 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;
-
- output.push_back(MSGSTART);
- PushEscaped(output, MSGCODE_SET_ACK_MASK);
- PushEscaped(output, iMask >> 8);
- PushEscaped(output, (uint8_t)iMask);
- output.push_back(MSGEND);
-
- if (!m_communication->Write(output))
- {
- AddLog(CEC_LOG_ERROR, "could not set the ackmask");
- return false;
- }
-
- return true;
-}
-
-void CCECParser::AddLog(cec_log_level level, const string &strMessage)
-{
- cec_log_message message;
- message.level = level;
- message.message.assign(strMessage.c_str());
- m_logBuffer.Push(message);
-}
-
-void CCECParser::AddKey(void)
-{
- if (m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN)
- {
- cec_keypress key;
- key.duration = (unsigned int) (GetTimeMs() - m_buttontime);
- key.keycode = m_iCurrentButton;
- m_keyBuffer.Push(key);
- m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN;
- m_buttontime = 0;
- }
-}
-
-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;
- if (m_commandBuffer.Push(command))
- {
- CStdString strDebug;
- strDebug.Format("stored command '%d' in the command buffer. buffer size = %d", opcode, m_commandBuffer.Size());
- AddLog(CEC_LOG_DEBUG, strDebug);
- }
- else
- {
- AddLog(CEC_LOG_WARNING, "command buffer is full");
- }
-}
-
-int CCECParser::GetMinVersion(void)
-{
- return CEC_MIN_VERSION;
-}
-
-int CCECParser::GetLibVersion(void)
-{
- return CEC_LIB_VERSION;
-}
-
-int CCECParser::FindDevices(std::vector<cec_device> &deviceList, const char *strDevicePath /* = NULL */)
-{
- CStdString strDebug;
- if (strDevicePath)
- strDebug.Format("trying to autodetect the com port for device path '%s'", strDevicePath);
- else
- strDebug.Format("trying to autodetect all CEC adapters");
- AddLog(CEC_LOG_DEBUG, strDebug);
-
- 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 */)
-{
- return static_cast< void* > (new CCECParser(strDeviceName, iLogicalAddress, iPhysicalAddress));
-}