X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fadapter%2FUSBCECAdapterCommands.cpp;h=bdc24126f7a2b2099205d07b7a58ee2385a14e14;hb=c0152c0940ee81c79150dbafafd6621f576c3ccb;hp=cea0561e7a44f9f9f6c96ea69825674a72d74429;hpb=e35aa7baab13fbfafe20e1c6d9242d2f95c2ba8c;p=deb_libcec.git diff --git a/src/lib/adapter/USBCECAdapterCommands.cpp b/src/lib/adapter/USBCECAdapterCommands.cpp index cea0561..bdc2412 100644 --- a/src/lib/adapter/USBCECAdapterCommands.cpp +++ b/src/lib/adapter/USBCECAdapterCommands.cpp @@ -37,13 +37,17 @@ using namespace CEC; using namespace PLATFORM; +#define LIB_CEC m_comm->m_callback->GetLib() +#define ToString(p) LIB_CEC->ToString(p) + CUSBCECAdapterCommands::CUSBCECAdapterCommands(CUSBCECAdapterCommunication *comm) : m_comm(comm), m_bSettingsRetrieved(false), m_bSettingAutoEnabled(false), m_settingCecVersion(CEC_VERSION_UNKNOWN), m_iSettingLAMask(0), - m_bNeedsWrite(false) + m_bNeedsWrite(false), + m_iBuildDate(CEC_FW_BUILD_UNKNOWN) { m_persistedConfiguration.Clear(); } @@ -72,20 +76,20 @@ uint16_t CUSBCECAdapterCommands::RequestFirmwareVersion(void) while (m_persistedConfiguration.iFirmwareVersion == CEC_FW_VERSION_UNKNOWN && iFwVersionTry++ < 3) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting the firmware version"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting the firmware version"); cec_datapacket response = RequestSetting(MSGCODE_FIRMWARE_VERSION); if (response.size == 2) m_persistedConfiguration.iFirmwareVersion = (response[0] << 8 | response[1]); else { - CLibCEC::AddLog(CEC_LOG_WARNING, "the adapter did not respond with a correct firmware version (try %d)", iFwVersionTry); + LIB_CEC->AddLog(CEC_LOG_WARNING, "the adapter did not respond with a correct firmware version (try %d)", iFwVersionTry); CEvent::Sleep(500); } } if (m_persistedConfiguration.iFirmwareVersion == CEC_FW_VERSION_UNKNOWN) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "defaulting to firmware version 1"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "defaulting to firmware version 1"); m_persistedConfiguration.iFirmwareVersion = 1; } @@ -94,12 +98,13 @@ uint16_t CUSBCECAdapterCommands::RequestFirmwareVersion(void) bool CUSBCECAdapterCommands::RequestSettingAutoEnabled(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting autonomous mode setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting autonomous mode setting"); cec_datapacket response = RequestSetting(MSGCODE_GET_AUTO_ENABLED); if (response.size == 1) { m_bSettingAutoEnabled = response[0] == 1; + LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted autonomous mode setting: '%s'", m_bSettingAutoEnabled ? "enabled" : "disabled"); return true; } return false; @@ -107,25 +112,40 @@ bool CUSBCECAdapterCommands::RequestSettingAutoEnabled(void) bool CUSBCECAdapterCommands::RequestSettingCECVersion(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting CEC version setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting CEC version setting"); cec_datapacket response = RequestSetting(MSGCODE_GET_HDMI_VERSION); if (response.size == 1) { m_settingCecVersion = (cec_version)response[0]; + LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted CEC version setting: '%s'", ToString(m_settingCecVersion)); return true; } return false; } +uint32_t CUSBCECAdapterCommands::RequestBuildDate(void) +{ + if (m_iBuildDate == CEC_FW_BUILD_UNKNOWN) + { + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting firmware build date"); + + cec_datapacket response = RequestSetting(MSGCODE_GET_BUILDDATE); + if (response.size == 4) + m_iBuildDate = (uint32_t)response[0] << 24 | (uint32_t)response[1] << 16 | (uint32_t)response[2] << 8 | (uint32_t)response[3]; + } + return m_iBuildDate; +} + bool CUSBCECAdapterCommands::RequestSettingDefaultLogicalAddress(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting default logical address setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting default logical address setting"); cec_datapacket response = RequestSetting(MSGCODE_GET_DEFAULT_LOGICAL_ADDRESS); if (response.size == 1) { m_persistedConfiguration.logicalAddresses.primary = (cec_logical_address)response[0]; + LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted logical address setting: '%s'", ToString(m_persistedConfiguration.logicalAddresses.primary)); return true; } return false; @@ -133,28 +153,29 @@ bool CUSBCECAdapterCommands::RequestSettingDefaultLogicalAddress(void) bool CUSBCECAdapterCommands::RequestSettingDeviceType(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting device type setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting device type setting"); m_persistedConfiguration.deviceTypes.Clear(); cec_datapacket response = RequestSetting(MSGCODE_GET_DEVICE_TYPE); if (response.size == 1) { m_persistedConfiguration.deviceTypes.Add((cec_device_type)response[0]); - CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted device type setting %s", CLibCEC::GetInstance()->ToString((cec_device_type)response[0])); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted device type setting: '%s'", ToString((cec_device_type)response[0])); return true; } - CLibCEC::AddLog(CEC_LOG_DEBUG, "no persisted device type setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "no persisted device type setting"); return false; } bool CUSBCECAdapterCommands::RequestSettingLogicalAddressMask(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting logical address mask setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting logical address mask setting"); cec_datapacket response = RequestSetting(MSGCODE_GET_LOGICAL_ADDRESS_MASK); if (response.size == 2) { m_iSettingLAMask = ((uint16_t)response[0] << 8) | ((uint16_t)response[1]); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted logical address mask setting: '%x'", m_iSettingLAMask); return true; } return false; @@ -162,13 +183,13 @@ bool CUSBCECAdapterCommands::RequestSettingLogicalAddressMask(void) bool CUSBCECAdapterCommands::RequestSettingOSDName(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting OSD name setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting OSD name setting"); memset(m_persistedConfiguration.strDeviceName, 0, 13); cec_datapacket response = RequestSetting(MSGCODE_GET_OSD_NAME); if (response.size == 0) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "no persisted device name setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "no persisted device name setting"); return false; } @@ -178,22 +199,22 @@ bool CUSBCECAdapterCommands::RequestSettingOSDName(void) buf[response.size] = 0; snprintf(m_persistedConfiguration.strDeviceName, 13, "%s", buf); - CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted device name setting %s", buf); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted device name setting: '%s'", buf); return true; } bool CUSBCECAdapterCommands::RequestSettingPhysicalAddress(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting physical address setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "requesting physical address setting"); cec_datapacket response = RequestSetting(MSGCODE_GET_PHYSICAL_ADDRESS); if (response.size == 2) { m_persistedConfiguration.iPhysicalAddress = ((uint16_t)response[0] << 8) | ((uint16_t)response[1]); - CLibCEC::AddLog(CEC_LOG_DEBUG, "using persisted physical address setting %4x", m_persistedConfiguration.iPhysicalAddress); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "using persisted physical address setting: '%4x'", m_persistedConfiguration.iPhysicalAddress); return true; } - CLibCEC::AddLog(CEC_LOG_DEBUG, "no persisted physical address setting"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "no persisted physical address setting"); return false; } @@ -204,12 +225,12 @@ bool CUSBCECAdapterCommands::SetSettingAutoEnabled(bool enabled) /* check whether this value was changed */ if (m_bSettingAutoEnabled == enabled) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "autonomous mode setting unchanged (%s)", enabled ? "on" : "off"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "autonomous mode setting unchanged (%s)", enabled ? "on" : "off"); return bReturn; } m_bNeedsWrite = true; - CLibCEC::AddLog(CEC_LOG_DEBUG, "turning autonomous mode %s", enabled ? "on" : "off"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "turning autonomous mode %s", enabled ? "on" : "off"); CCECAdapterMessage params; params.PushEscaped(enabled ? 1 : 0); @@ -230,12 +251,12 @@ bool CUSBCECAdapterCommands::SetSettingDeviceType(cec_device_type type) /* check whether this value was changed */ if (m_persistedConfiguration.deviceTypes.types[0] == type) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "device type setting unchanged (%X)", (uint8_t)type); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "device type setting unchanged (%X)", (uint8_t)type); return bReturn; } m_bNeedsWrite = true; - CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the device type to %X", (uint8_t)type); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the device type to %X (previous: %X)", (uint8_t)type, (uint8_t)m_persistedConfiguration.deviceTypes.types[0]); CCECAdapterMessage params; params.PushEscaped((uint8_t)type); @@ -253,12 +274,12 @@ bool CUSBCECAdapterCommands::SetSettingDefaultLogicalAddress(cec_logical_address /* check whether this value was changed */ if (m_persistedConfiguration.logicalAddresses.primary == address) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "logical address setting unchanged (%X)", (uint8_t)address); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "logical address setting unchanged (%X)", (uint8_t)address); return bReturn; } m_bNeedsWrite = true; - CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the default logical address to %X", (uint8_t)address); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the default logical address to %X (previous: %X)", (uint8_t)address, (uint8_t)m_persistedConfiguration.logicalAddresses.primary); CCECAdapterMessage params; params.PushEscaped((uint8_t)address); @@ -279,12 +300,12 @@ bool CUSBCECAdapterCommands::SetSettingLogicalAddressMask(uint16_t iMask) /* check whether this value was changed */ if (m_iSettingLAMask == iMask) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "logical address mask setting unchanged (%2X)", iMask); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "logical address mask setting unchanged (%2X)", iMask); return bReturn; } m_bNeedsWrite = true; - CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the logical address mask to %2X", iMask); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the logical address mask to %2X (previous: %2X)", iMask, m_iSettingLAMask); CCECAdapterMessage params; params.PushEscaped(iMask >> 8); @@ -306,12 +327,12 @@ bool CUSBCECAdapterCommands::SetSettingPhysicalAddress(uint16_t iPhysicalAddress /* check whether this value was changed */ if (m_persistedConfiguration.iPhysicalAddress == iPhysicalAddress) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "physical address setting unchanged (%04X)", iPhysicalAddress); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "physical address setting unchanged (%04X)", iPhysicalAddress); return bReturn; } m_bNeedsWrite = true; - CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the physical address to %04X", iPhysicalAddress); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the physical address to %04X (previous: %04X)", iPhysicalAddress, m_persistedConfiguration.iPhysicalAddress); CCECAdapterMessage params; params.PushEscaped(iPhysicalAddress >> 8); @@ -333,12 +354,12 @@ bool CUSBCECAdapterCommands::SetSettingCECVersion(cec_version version) /* check whether this value was changed */ if (m_settingCecVersion == version) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "CEC version setting unchanged (%s)", CLibCEC::GetInstance()->ToString(version)); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "CEC version setting unchanged (%s)", ToString(version)); return bReturn; } m_bNeedsWrite = true; - CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the CEC version to %s", CLibCEC::GetInstance()->ToString(version)); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the CEC version to %s (previous: %s)", ToString(version), ToString(m_settingCecVersion)); CCECAdapterMessage params; params.PushEscaped((uint8_t)version); @@ -359,11 +380,11 @@ bool CUSBCECAdapterCommands::SetSettingOSDName(const char *strOSDName) /* check whether this value was changed */ if (!strcmp(m_persistedConfiguration.strDeviceName, strOSDName)) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "OSD name setting unchanged (%s)", strOSDName); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "OSD name setting unchanged (%s)", strOSDName); return bReturn; } - CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the OSD name to %s", strOSDName); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the OSD name to %s (previous: %s)", strOSDName, m_persistedConfiguration.strDeviceName); CCECAdapterMessage params; for (size_t iPtr = 0; iPtr < strlen(strOSDName); iPtr++) @@ -383,7 +404,7 @@ bool CUSBCECAdapterCommands::WriteEEPROM(void) if (!m_bNeedsWrite) return true; - CLibCEC::AddLog(CEC_LOG_DEBUG, "writing settings in the EEPROM"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "writing settings in the EEPROM"); CCECAdapterMessage params; CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_WRITE_EEPROM, params); @@ -392,7 +413,7 @@ bool CUSBCECAdapterCommands::WriteEEPROM(void) return m_bNeedsWrite; } -bool CUSBCECAdapterCommands::PersistConfiguration(libcec_configuration *configuration) +bool CUSBCECAdapterCommands::PersistConfiguration(const libcec_configuration &configuration) { if (m_persistedConfiguration.iFirmwareVersion < 2) return false; @@ -402,12 +423,12 @@ bool CUSBCECAdapterCommands::PersistConfiguration(libcec_configuration *configur bool bReturn(true); bReturn &= SetSettingAutoEnabled(true); - bReturn &= SetSettingDeviceType(CLibCEC::GetType(configuration->logicalAddresses.primary)); - bReturn &= SetSettingDefaultLogicalAddress(configuration->logicalAddresses.primary); - bReturn &= SetSettingLogicalAddressMask(CLibCEC::GetMaskForType(configuration->logicalAddresses.primary)); - bReturn &= SetSettingPhysicalAddress(configuration->iPhysicalAddress); + bReturn &= SetSettingDeviceType(CLibCEC::GetType(configuration.logicalAddresses.primary)); + bReturn &= SetSettingDefaultLogicalAddress(configuration.logicalAddresses.primary); + bReturn &= SetSettingLogicalAddressMask(CLibCEC::GetMaskForType(configuration.logicalAddresses.primary)); + bReturn &= SetSettingPhysicalAddress(configuration.iPhysicalAddress); bReturn &= SetSettingCECVersion(CEC_VERSION_1_3A); - bReturn &= SetSettingOSDName(configuration->strDeviceName); + bReturn &= SetSettingOSDName(configuration.strDeviceName); bReturn &= WriteEEPROM(); return bReturn; } @@ -416,11 +437,12 @@ bool CUSBCECAdapterCommands::RequestSettings(void) { if (m_persistedConfiguration.iFirmwareVersion < 2) { + LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - firmware version %d does not have any eeprom settings", __FUNCTION__, m_persistedConfiguration.iFirmwareVersion); // settings can only be persisted with firmware v2+ return false; } - if (!m_bSettingsRetrieved) + if (m_bSettingsRetrieved) return true; bool bReturn(true); @@ -455,24 +477,24 @@ bool CUSBCECAdapterCommands::RequestSettings(void) return bReturn; } -bool CUSBCECAdapterCommands::GetConfiguration(libcec_configuration *configuration) +bool CUSBCECAdapterCommands::GetConfiguration(libcec_configuration &configuration) { // get the settings from the eeprom if needed if (!RequestSettings()) return false; // copy the settings - configuration->iFirmwareVersion = m_persistedConfiguration.iFirmwareVersion; - configuration->deviceTypes = m_persistedConfiguration.deviceTypes; - configuration->iPhysicalAddress = m_persistedConfiguration.iPhysicalAddress; - snprintf(configuration->strDeviceName, 13, "%s", m_persistedConfiguration.strDeviceName); + configuration.iFirmwareVersion = m_persistedConfiguration.iFirmwareVersion; + configuration.deviceTypes = m_persistedConfiguration.deviceTypes; + configuration.iPhysicalAddress = m_persistedConfiguration.iPhysicalAddress; + snprintf(configuration.strDeviceName, 13, "%s", m_persistedConfiguration.strDeviceName); return true; } bool CUSBCECAdapterCommands::PingAdapter(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "sending ping"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "sending ping"); CCECAdapterMessage params; CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_PING, params); @@ -483,7 +505,7 @@ bool CUSBCECAdapterCommands::PingAdapter(void) bool CUSBCECAdapterCommands::SetAckMask(uint16_t iMask) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "setting ackmask to %2x", iMask); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting ackmask to %2x", iMask); CCECAdapterMessage params; params.PushEscaped(iMask >> 8); @@ -496,7 +518,7 @@ bool CUSBCECAdapterCommands::SetAckMask(uint16_t iMask) bool CUSBCECAdapterCommands::StartBootloader(void) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "starting the bootloader"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "starting the bootloader"); CCECAdapterMessage params; CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_START_BOOTLOADER, params); @@ -507,7 +529,7 @@ bool CUSBCECAdapterCommands::StartBootloader(void) bool CUSBCECAdapterCommands::SetLineTimeout(uint8_t iTimeout) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "setting the line timeout to %d", iTimeout); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the line timeout to %d", iTimeout); CCECAdapterMessage params; params.PushEscaped(iTimeout); CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_TRANSMIT_IDLETIME, params); @@ -518,7 +540,7 @@ bool CUSBCECAdapterCommands::SetLineTimeout(uint8_t iTimeout) bool CUSBCECAdapterCommands::SetControlledMode(bool controlled) { - CLibCEC::AddLog(CEC_LOG_DEBUG, "turning controlled mode %s", controlled ? "on" : "off"); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "turning controlled mode %s", controlled ? "on" : "off"); CCECAdapterMessage params; params.PushEscaped(controlled ? 1 : 0);