cec: more magic numbers. use the default CEC timeout of 1000ms instead of 2000ms...
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 27 Apr 2012 19:33:32 +0000 (21:33 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 27 Apr 2012 22:33:18 +0000 (00:33 +0200)
20 files changed:
include/cectypes.h
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/adapter/USBCECAdapterCommands.cpp
src/lib/adapter/USBCECAdapterCommunication.cpp
src/lib/devices/CECAudioSystem.cpp
src/lib/devices/CECAudioSystem.h
src/lib/devices/CECBusDevice.cpp
src/lib/devices/CECBusDevice.h
src/lib/devices/CECPlaybackDevice.cpp
src/lib/devices/CECPlaybackDevice.h
src/lib/devices/CECRecordingDevice.cpp
src/lib/devices/CECRecordingDevice.h
src/lib/devices/CECTV.cpp
src/lib/devices/CECTV.h
src/lib/devices/CECTuner.cpp
src/lib/devices/CECTuner.h
src/lib/implementations/CECCommandHandler.cpp
src/lib/implementations/CECCommandHandler.h
src/testclient/main.cpp

index b596113f883f2e7d438ffde129820d06a101ca4e..ca065c606051ade2507c39ab669db40004d4a308 100644 (file)
@@ -72,9 +72,11 @@ namespace CEC {
 #define CEC_BUTTON_TIMEOUT           500
 #define CEC_POWER_STATE_REFRESH_TIME 30000
 #define CEC_FW_VERSION_UNKNOWN       0xFFFF
+#define CEC_FW_BUILD_UNKNOWN         0
 #define CEC_CONNECT_TRIES            3
 
 #define CEC_PHYSICAL_ADDRESS_TV      0
+#define CEC_MIN_PHYSICAL_ADDRESS     0x1000
 #define CEC_MAX_PHYSICAL_ADDRESS     0xFFFE
 #define CEC_INVALID_PHYSICAL_ADDRESS 0xFFFF
 
@@ -84,6 +86,7 @@ namespace CEC {
 
 #define CEC_MIN_HDMI_PORTNUMBER      1
 #define CEC_MAX_HDMI_PORTNUMBER      15
+#define CEC_HDMI_PORTNUMBER_NONE     0
 
 #define CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE      1
 #define CEC_DEFAULT_SETTING_ACTIVATE_SOURCE           1
@@ -94,13 +97,12 @@ namespace CEC {
 #define CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE      1
 #define CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY 1
 #define CEC_DEFAULT_DEVICE_LANGUAGE                   "eng"
-#define CEC_DEFAULT_FIRMWARE_BUILD_DATE               0
 #define CEC_DEFAULT_SETTING_AUTODETECT_ADDRESS        1
 #define CEC_DEFAULT_SETTING_GET_SETTINGS_FROM_ROM     0
 
 #define CEC_DEFAULT_TRANSMIT_RETRY_WAIT 500
 #define CEC_DEFAULT_TRANSMIT_TIMEOUT    1000
-#define CEC_DEFAULT_TRANSMIT_WAIT       2000
+#define CEC_DEFAULT_TRANSMIT_WAIT       1000
 #define CEC_DEFAULT_TRANSMIT_RETRIES    1
 
 #define CEC_DEFAULT_CONNECT_TIMEOUT     10000
@@ -1268,7 +1270,7 @@ typedef struct libcec_configuration
    */
   void Clear(void)
   {
-    iPhysicalAddress =                0;
+    iPhysicalAddress =                CEC_PHYSICAL_ADDRESS_TV;
     baseDevice = (cec_logical_address)CEC_DEFAULT_BASE_DEVICE;
     iHDMIPort =                       CEC_DEFAULT_HDMI_PORT;
     tvVendor =              (uint64_t)CEC_VENDOR_UNKNOWN;
@@ -1285,7 +1287,7 @@ typedef struct libcec_configuration
     iFirmwareVersion =                CEC_FW_VERSION_UNKNOWN;
     bPowerOffDevicesOnStandby =       CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY;
     memcpy(strDeviceLanguage,         CEC_DEFAULT_DEVICE_LANGUAGE, 3);
-    iFirmwareBuildDate =              CEC_DEFAULT_FIRMWARE_BUILD_DATE;
+    iFirmwareBuildDate =              CEC_FW_BUILD_UNKNOWN;
 
     memset(strDeviceName, 0, 13);
     deviceTypes.clear();
index 0199b32ce44a540c8ce33b2c27623ee96126fe3f..41780face9b69fb4731851c7485af1138603c2c1 100644 (file)
@@ -96,34 +96,34 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, con
 
 void CCECProcessor::CreateBusDevices(void)
 {
-  for (int iPtr = 0; iPtr < 16; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
   {
     switch(iPtr)
     {
     case CECDEVICE_AUDIOSYSTEM:
-      m_busDevices[iPtr] = new CCECAudioSystem(this, (cec_logical_address) iPtr, CEC_INVALID_PHYSICAL_ADDRESS);
+      m_busDevices[iPtr] = new CCECAudioSystem(this, (cec_logical_address) iPtr);
       break;
     case CECDEVICE_PLAYBACKDEVICE1:
     case CECDEVICE_PLAYBACKDEVICE2:
     case CECDEVICE_PLAYBACKDEVICE3:
-      m_busDevices[iPtr] = new CCECPlaybackDevice(this, (cec_logical_address) iPtr, CEC_INVALID_PHYSICAL_ADDRESS);
+      m_busDevices[iPtr] = new CCECPlaybackDevice(this, (cec_logical_address) iPtr);
       break;
     case CECDEVICE_RECORDINGDEVICE1:
     case CECDEVICE_RECORDINGDEVICE2:
     case CECDEVICE_RECORDINGDEVICE3:
-      m_busDevices[iPtr] = new CCECRecordingDevice(this, (cec_logical_address) iPtr, CEC_INVALID_PHYSICAL_ADDRESS);
+      m_busDevices[iPtr] = new CCECRecordingDevice(this, (cec_logical_address) iPtr);
       break;
     case CECDEVICE_TUNER1:
     case CECDEVICE_TUNER2:
     case CECDEVICE_TUNER3:
     case CECDEVICE_TUNER4:
-      m_busDevices[iPtr] = new CCECTuner(this, (cec_logical_address) iPtr, CEC_INVALID_PHYSICAL_ADDRESS);
+      m_busDevices[iPtr] = new CCECTuner(this, (cec_logical_address) iPtr);
       break;
     case CECDEVICE_TV:
-      m_busDevices[iPtr] = new CCECTV(this, (cec_logical_address) iPtr, CEC_PHYSICAL_ADDRESS_TV);
+      m_busDevices[iPtr] = new CCECTV(this, (cec_logical_address) iPtr);
       break;
     default:
-      m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, CEC_INVALID_PHYSICAL_ADDRESS);
+      m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr);
       break;
     }
   }
@@ -133,7 +133,7 @@ CCECProcessor::~CCECProcessor(void)
 {
   Close();
 
-  for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
   {
     delete m_busDevices[iPtr];
     m_busDevices[iPtr] = NULL;
@@ -193,7 +193,7 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint
     m_configuration.iFirmwareBuildDate = m_communication->GetFirmwareBuildDate();
     CStdString strLog;
     strLog.Format("connected to the CEC adapter. libCEC version = %s, client version = %s, firmware version = %d", ToString((cec_server_version)m_configuration.serverVersion), ToString((cec_client_version)m_configuration.clientVersion), m_configuration.iFirmwareVersion);
-    if (m_configuration.iFirmwareBuildDate != CEC_DEFAULT_FIRMWARE_BUILD_DATE)
+    if (m_configuration.iFirmwareBuildDate != CEC_FW_BUILD_UNKNOWN)
     {
       time_t buildTime = (time_t)m_configuration.iFirmwareBuildDate;
       strLog.AppendFormat(", firmware build date: %s", asctime(gmtime(&buildTime)));
@@ -212,7 +212,7 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint
     CLockObject lock(m_mutex);
     if (!config.deviceTypes.IsEmpty())
       m_configuration.deviceTypes = config.deviceTypes;
-    if (config.iPhysicalAddress > 0)
+    if (IsValidPhysicalAddress(config.iPhysicalAddress))
       m_configuration.iPhysicalAddress = config.iPhysicalAddress;
     snprintf(m_configuration.strDeviceName, 13, "%s", config.strDeviceName);
   }
@@ -259,7 +259,7 @@ bool CCECProcessor::Initialise(void)
     memcpy(language.language, m_configuration.strDeviceLanguage, 3);
     language.language[3] = 0;
 
-    for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+    for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
     {
       if (m_configuration.logicalAddresses[iPtr])
       {
@@ -272,16 +272,17 @@ bool CCECProcessor::Initialise(void)
   /* get the vendor id from the TV, so we are using the correct handler */
   m_busDevices[CECDEVICE_TV]->GetVendorId();
 
-  if (m_configuration.iPhysicalAddress != 0)
+  if (IsValidPhysicalAddress(m_configuration.iPhysicalAddress))
   {
-    CLibCEC::AddLog(CEC_LOG_NOTICE, "setting the physical address to %4x", m_configuration.iPhysicalAddress);
+    CLibCEC::AddLog(CEC_LOG_NOTICE, "setting the physical address to %04X", m_configuration.iPhysicalAddress);
     m_busDevices[m_configuration.logicalAddresses.primary]->m_iPhysicalAddress = m_configuration.iPhysicalAddress;
     if ((bReturn = m_busDevices[m_configuration.logicalAddresses.primary]->TransmitPhysicalAddress()) == false)
-      CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set the physical address to %4x", m_configuration.iPhysicalAddress);
+      CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set the physical address to %04X", m_configuration.iPhysicalAddress);
   }
-  else if (m_configuration.iPhysicalAddress == 0 && (bReturn = SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort, true)) == false)
+  else
   {
-    CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set HDMI port %d on %s (%x)", m_configuration.iHDMIPort, ToString(m_configuration.baseDevice), (uint8_t)m_configuration.baseDevice);
+    if (!SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort, true))
+      CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set HDMI port %d on %s (%x)", m_configuration.iHDMIPort, ToString(m_configuration.baseDevice), (uint8_t)m_configuration.baseDevice);
     bReturn = true;
   }
 
@@ -377,7 +378,7 @@ bool CCECProcessor::ChangeDeviceType(cec_device_type from, cec_device_type to)
   CCECBusDevice *previousDevice = GetDeviceByType(from);
   m_configuration.logicalAddresses.primary = CECDEVICE_UNKNOWN;
 
-  for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
+  for (uint8_t iPtr = 0; iPtr < 5; iPtr++)
   {
     if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
       continue;
@@ -449,7 +450,7 @@ bool CCECProcessor::FindLogicalAddresses(void)
     return false;
   }
 
-  for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
+  for (uint8_t iPtr = 0; iPtr < 5; iPtr++)
   {
     if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
       continue;
@@ -476,7 +477,7 @@ void CCECProcessor::ReplaceHandlers(void)
 {
   if (!IsInitialised())
     return;
-  for (uint8_t iPtr = 0; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
     m_busDevices[iPtr]->ReplaceHandler(m_bInitialised);
 }
 
@@ -519,7 +520,7 @@ bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RE
 
   if (type != CEC_DEVICE_TYPE_RESERVED)
   {
-    for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
+    for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
     {
       if (m_configuration.logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type)
       {
@@ -530,7 +531,7 @@ bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RE
   }
 
   m_busDevices[addr]->SetActiveSource();
-  if (m_busDevices[addr]->GetPhysicalAddress() != CEC_INVALID_PHYSICAL_ADDRESS)
+  if (IsValidPhysicalAddress(m_busDevices[addr]->GetPhysicalAddress()))
     bReturn = m_busDevices[addr]->ActivateSource();
 
   return bReturn;
@@ -617,7 +618,7 @@ bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort,
   {
     CLockObject lock(m_mutex);
     m_configuration.baseDevice = iBaseDevice;
-    m_configuration.iHDMIPort = iPort;
+    m_configuration.iHDMIPort  = iPort;
   }
 
   if (!IsRunning() && !bForce)
@@ -656,7 +657,7 @@ bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort,
 
 bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress)
 {
-  for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
   {
     if (m_busDevices[iPtr]->GetPhysicalAddress() == iPhysicalAddress)
       return true;
@@ -702,7 +703,7 @@ bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
 
 bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */)
 {
-  for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
   {
     if (m_configuration.logicalAddresses[iPtr])
       m_busDevices[iPtr]->SetMenuState(state);
@@ -724,12 +725,12 @@ bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress, bool bSendUpda
   {
     CLockObject lock(m_mutex);
     m_configuration.iPhysicalAddress = iPhysicalAddress;
-    CLibCEC::AddLog(CEC_LOG_DEBUG, "setting physical address to '%4x'", iPhysicalAddress);
+    CLibCEC::AddLog(CEC_LOG_DEBUG, "setting physical address to '%04X'", iPhysicalAddress);
 
     if (!m_configuration.logicalAddresses.IsEmpty())
     {
       bool bWasActiveSource(false);
-      for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
+      for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
         if (m_configuration.logicalAddresses[iPtr])
         {
           bWasActiveSource |= m_busDevices[iPtr]->IsActiveSource();
@@ -744,7 +745,7 @@ bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress, bool bSendUpda
     }
   }
 
-  for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
     if (sendUpdatesTo[iPtr])
       m_busDevices[iPtr]->TransmitPhysicalAddress();
 
@@ -794,7 +795,7 @@ bool CCECProcessor::PollDevice(cec_logical_address iAddress)
 
 uint8_t CCECProcessor::VolumeUp(bool bSendRelease /* = true */)
 {
-  uint8_t status = 0;
+  uint8_t status(CEC_AUDIO_VOLUME_STATUS_UNKNOWN);
   if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
     status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp(bSendRelease);
 
@@ -803,7 +804,7 @@ uint8_t CCECProcessor::VolumeUp(bool bSendRelease /* = true */)
 
 uint8_t CCECProcessor::VolumeDown(bool bSendRelease /* = true */)
 {
-  uint8_t status = 0;
+  uint8_t status(CEC_AUDIO_VOLUME_STATUS_UNKNOWN);
   if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
     status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown(bSendRelease);
 
@@ -812,7 +813,7 @@ uint8_t CCECProcessor::VolumeDown(bool bSendRelease /* = true */)
 
 uint8_t CCECProcessor::MuteAudio(bool bSendRelease /* = true */)
 {
-  uint8_t status = 0;
+  uint8_t status(CEC_AUDIO_VOLUME_STATUS_UNKNOWN);
   if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
     status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio(bSendRelease);
 
@@ -823,12 +824,8 @@ CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddre
 {
   CCECBusDevice *device(NULL);
 
-  // invalid PA
-  if (iPhysicalAddress == CEC_INVALID_PHYSICAL_ADDRESS)
-    return device;
-
   // check each device until we found a match
-  for (unsigned int iPtr = 0; !device && iPtr < 16; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; !device && iPtr < CECDEVICE_BROADCAST; iPtr++)
   {
     if (m_busDevices[iPtr]->GetPhysicalAddress(bSuppressUpdate) == iPhysicalAddress)
       device = m_busDevices[iPtr];
@@ -841,7 +838,7 @@ CCECBusDevice *CCECProcessor::GetDeviceByType(cec_device_type type) const
 {
   CCECBusDevice *device = NULL;
 
-  for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
   {
     if (m_busDevices[iPtr]->m_type == type && m_configuration.logicalAddresses[iPtr])
     {
@@ -918,7 +915,7 @@ cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddres
 
 cec_logical_address CCECProcessor::GetActiveSource(bool bRequestActiveSource /* = true */)
 {
-  for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
   {
     if (m_busDevices[iPtr]->IsActiveSource())
       return (cec_logical_address)iPtr;
@@ -1014,7 +1011,7 @@ cec_logical_addresses CCECProcessor::GetActiveDevices(void)
 {
   cec_logical_addresses addresses;
   addresses.Clear();
-  for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
   {
     if (m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
       addresses.Set((cec_logical_address) iPtr);
@@ -1029,7 +1026,7 @@ bool CCECProcessor::IsPresentDevice(cec_logical_address address)
 
 bool CCECProcessor::IsPresentDeviceType(cec_device_type type)
 {
-  for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
   {
     if (m_busDevices[iPtr]->GetType() == type && m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
       return true;
@@ -1064,12 +1061,12 @@ bool CCECProcessor::EnablePhysicalAddressDetection(void)
 {
   CLibCEC::AddLog(CEC_LOG_WARNING, "deprecated method %s called", __FUNCTION__);
   uint16_t iPhysicalAddress = m_communication->GetPhysicalAddress();
-  if (iPhysicalAddress != 0)
+  if (IsValidPhysicalAddress(iPhysicalAddress))
   {
     m_configuration.bAutodetectAddress = 1;
-    m_configuration.iPhysicalAddress = iPhysicalAddress;
-    m_configuration.baseDevice = CECDEVICE_UNKNOWN;
-    m_configuration.iHDMIPort = 0;
+    m_configuration.iPhysicalAddress   = iPhysicalAddress;
+    m_configuration.baseDevice         = CECDEVICE_UNKNOWN;
+    m_configuration.iHDMIPort          = CEC_HDMI_PORTNUMBER_NONE;
     return SetPhysicalAddress(iPhysicalAddress);
   }
   return false;
@@ -1080,7 +1077,7 @@ bool CCECProcessor::StandbyDevices(cec_logical_address address /* = CECDEVICE_BR
   if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0)
   {
     bool bReturn(true);
-    for (uint8_t iPtr = 0; iPtr <= 0xF; iPtr++)
+    for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
     {
       if (m_configuration.powerOffDevices[iPtr])
       {
@@ -1099,7 +1096,7 @@ bool CCECProcessor::PowerOnDevices(cec_logical_address address /* = CECDEVICE_BR
   if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0)
   {
     bool bReturn(true);
-    for (uint8_t iPtr = 0; iPtr <= 0xF; iPtr++)
+    for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
     {
       if (m_configuration.wakeDevices[iPtr])
       {
@@ -1275,6 +1272,8 @@ const char *CCECProcessor::ToString(const cec_deck_info status)
     return "info index search reverse";
   case CEC_DECK_INFO_OTHER_STATUS:
     return "other";
+  case CEC_DECK_INFO_OTHER_STATUS_LG:
+    return "LG other";
   default:
     return "unknown";
   }
@@ -1587,34 +1586,34 @@ bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration)
   if (IsRunning() && configuration->bAutodetectAddress == 1)
   {
     uint16_t iPhysicalAddress = m_communication->GetPhysicalAddress();
-    if (iPhysicalAddress != 0)
+    if (IsValidPhysicalAddress(iPhysicalAddress))
     {
       if (IsRunning())
-        CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - autodetected physical address '%4x'", __FUNCTION__, iPhysicalAddress);
+        CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - autodetected physical address '%04X'", __FUNCTION__, iPhysicalAddress);
       else
-        CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using physical address '%x'", __FUNCTION__, iPhysicalAddress);
+        CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using physical address '%04X'", __FUNCTION__, iPhysicalAddress);
       bPhysicalAddressChanged = (m_configuration.iPhysicalAddress != iPhysicalAddress);
       m_configuration.iPhysicalAddress = iPhysicalAddress;
-      m_configuration.iHDMIPort = 0;
-      m_configuration.baseDevice = CECDEVICE_UNKNOWN;
-      bPhysicalAutodetected = true;
+      m_configuration.iHDMIPort        = CEC_HDMI_PORTNUMBER_NONE;
+      m_configuration.baseDevice       = CECDEVICE_UNKNOWN;
+      bPhysicalAutodetected            = true;
     }
   }
 
   // physical address
   if (!bPhysicalAutodetected)
   {
-    if (configuration->iPhysicalAddress != 0)
-      bPhysicalAddressChanged = IsRunning() && m_configuration.iPhysicalAddress != configuration->iPhysicalAddress;
+    uint16_t iPhysicalAddress(IsValidPhysicalAddress(configuration->iPhysicalAddress) ? configuration->iPhysicalAddress : CEC_PHYSICAL_ADDRESS_TV);
+    bPhysicalAddressChanged = IsRunning() && m_configuration.iPhysicalAddress != iPhysicalAddress;
     if (bPhysicalAddressChanged)
     {
-      CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - physical address '%x'", __FUNCTION__, configuration->iPhysicalAddress);
-      m_configuration.iPhysicalAddress = configuration->iPhysicalAddress;
+      CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - physical address '%04X'", __FUNCTION__, iPhysicalAddress);
+      m_configuration.iPhysicalAddress = iPhysicalAddress;
     }
   }
 
   bool bHdmiPortChanged(false);
-  if (!bPhysicalAutodetected && !bPhysicalAddressChanged)
+  if (!IsValidPhysicalAddress(m_configuration.iPhysicalAddress))
   {
     // base device
     bHdmiPortChanged = IsRunning() && m_configuration.baseDevice != configuration->baseDevice;
@@ -1626,11 +1625,11 @@ bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration)
     CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using HDMI port '%d'", __FUNCTION__, configuration->iHDMIPort);
     m_configuration.iHDMIPort = configuration->iHDMIPort;
   }
-  else
+  else if (IsValidPhysicalAddress(m_configuration.iPhysicalAddress))
   {
     CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - resetting HDMI port and base device to defaults", __FUNCTION__);
     m_configuration.baseDevice = CECDEVICE_UNKNOWN;
-    m_configuration.iHDMIPort  = 0;
+    m_configuration.iHDMIPort  = CEC_HDMI_PORTNUMBER_NONE;
   }
 
   bReinit = bPhysicalAddressChanged || bHdmiPortChanged || bDeviceTypeChanged;
@@ -1698,9 +1697,9 @@ bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration)
   {
     if (bDeviceTypeChanged)
       return ChangeDeviceType(oldPrimaryType, m_configuration.deviceTypes[0]);
-    else if (bPhysicalAddressChanged)
+    else if (IsValidPhysicalAddress(m_configuration.iPhysicalAddress))
       return SetPhysicalAddress(m_configuration.iPhysicalAddress);
-    else
+    else if (m_configuration.baseDevice != CECDEVICE_UNKNOWN && m_configuration.iHDMIPort != CEC_HDMI_PORTNUMBER_NONE)
       return SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort);
   }
   else if (m_configuration.bActivateSource == 1 && IsRunning() && !IsActiveSource(m_configuration.logicalAddresses.primary))
@@ -1770,7 +1769,7 @@ bool CCECProcessor::PersistConfiguration(libcec_configuration *configuration)
 
 void CCECProcessor::RescanActiveDevices(void)
 {
-  for (unsigned int iPtr = 0; iPtr < CECDEVICE_BROADCAST; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
     m_busDevices[iPtr]->GetStatus(true);
 }
 
@@ -1789,7 +1788,13 @@ bool CCECProcessor::GetDeviceInformation(const char *strPort, libcec_configurati
 bool CCECProcessor::TransmitPendingActiveSourceCommands(void)
 {
   bool bReturn(true);
-  for (unsigned int iPtr = 0; iPtr < CECDEVICE_BROADCAST; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
     bReturn &= m_busDevices[iPtr]->TransmitPendingActiveSourceCommands();
   return bReturn;
 }
+
+bool CCECProcessor::IsValidPhysicalAddress(uint16_t iPhysicalAddress)
+{
+  return iPhysicalAddress >= CEC_MIN_PHYSICAL_ADDRESS &&
+         iPhysicalAddress <= CEC_MAX_PHYSICAL_ADDRESS;
+}
index c93d8fefff47c3f95417c83adb7c2b4f8a779e2c..3986862fe719f3f2730c56bd5cb1840cd700d4af 100644 (file)
@@ -177,6 +177,8 @@ namespace CEC
       const char *ToString(const cec_client_version version);
       const char *ToString(const cec_server_version version);
 
+      static bool IsValidPhysicalAddress(uint16_t iPhysicalAddress);
+
       bool Transmit(const cec_command &data);
       void TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE);
 
index 5989bc9f49667db231ad704be123114b9b3272e3..0374dbee60b19f662f693a6bbf430d57a93f1f28 100644 (file)
@@ -44,7 +44,7 @@ CUSBCECAdapterCommands::CUSBCECAdapterCommands(CUSBCECAdapterCommunication *comm
     m_settingCecVersion(CEC_VERSION_UNKNOWN),
     m_iSettingLAMask(0),
     m_bNeedsWrite(false),
-    m_iBuildDate(0)
+    m_iBuildDate(CEC_FW_BUILD_UNKNOWN)
 {
   m_persistedConfiguration.Clear();
 }
@@ -123,7 +123,7 @@ bool CUSBCECAdapterCommands::RequestSettingCECVersion(void)
 
 uint32_t CUSBCECAdapterCommands::RequestBuildDate(void)
 {
-  if (m_iBuildDate == 0)
+  if (m_iBuildDate == CEC_FW_BUILD_UNKNOWN)
   {
     CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting firmware build date");
 
index 3b8d2a39275c4f847f7da6cfe7f03dfc6ca18be1..6a4a0b99b99171cce2621406afdd4309163025c1 100644 (file)
@@ -54,7 +54,7 @@ CUSBCECAdapterCommunication::CUSBCECAdapterCommunication(IAdapterCommunicationCa
     m_commands(NULL),
     m_adapterMessageQueue(NULL)
 {
-  for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
+  for (unsigned int iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
     m_bWaitingForAck[iPtr] = false;
   m_port = new CSerialPort(strPort, iBaudRate);
 }
index 6d1d94827a50972c02f1c45c380952d6ab099dea..7e33597a7a974b0dbd0b778465a97540033f4f7d 100644 (file)
@@ -40,7 +40,7 @@ using namespace PLATFORM;
 
 #define ToString(p) m_processor->ToString(p)
 
-CCECAudioSystem::CCECAudioSystem(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = 0 */) :
+CCECAudioSystem::CCECAudioSystem(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = CEC_INVALID_PHYSICAL_ADDRESS */) :
     CCECBusDevice(processor, address, iPhysicalAddress),
     m_systemAudioStatus(CEC_SYSTEM_AUDIO_STATUS_ON),
     m_audioStatus(CEC_AUDIO_MUTE_STATUS_MASK)
index b171a09e44de06f88e4053cb4d2dbfb9db6b711a..a340ad88ce8541d302ab1ad1fdb9e6c8554493a8 100644 (file)
@@ -38,7 +38,7 @@ namespace CEC
   class CCECAudioSystem : public CCECBusDevice
   {
   public:
-    CCECAudioSystem(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = 0);
+    CCECAudioSystem(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = CEC_INVALID_PHYSICAL_ADDRESS);
     virtual ~CCECAudioSystem(void) {};
 
     bool SetAudioStatus(uint8_t status);
index 8f02ac7e28bf9ad725cf5179a4ef43ec447e271e..141180dd74c4f4022f30ffaf5f19a1ac7340fb1a 100644 (file)
@@ -44,7 +44,7 @@ using namespace PLATFORM;
 
 #define ToString(p) m_processor->ToString(p)
 
-CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress) :
+CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress /* = CEC_INVALID_PHYSICAL_ADDRESS */) :
   m_type                  (CEC_DEVICE_TYPE_RESERVED),
   m_iPhysicalAddress      (iPhysicalAddress),
   m_iStreamPath           (CEC_INVALID_PHYSICAL_ADDRESS),
index 687186f50678eeba50d087b2e9489bc1430f1efa..95b1bad34155c40b07d10420fc834d4d8cafea3b 100644 (file)
@@ -46,7 +46,7 @@ namespace CEC
     friend class CCECProcessor;
 
   public:
-    CCECBusDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = 0);
+    CCECBusDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = CEC_INVALID_PHYSICAL_ADDRESS);
     virtual ~CCECBusDevice(void);
 
     virtual bool HandleCommand(const cec_command &command);
index 3e255bf553d81db931fd4152c2f820f44cd5b261..522b88f49a572d3042794e1be1e4ac3b452bb2a7 100644 (file)
@@ -40,7 +40,7 @@ using namespace PLATFORM;
 
 #define ToString(p) m_processor->ToString(p)
 
-CCECPlaybackDevice::CCECPlaybackDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = 0 */) :
+CCECPlaybackDevice::CCECPlaybackDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = CEC_INVALID_PHYSICAL_ADDRESS */) :
     CCECBusDevice(processor, address, iPhysicalAddress),
     m_deckStatus(CEC_DECK_INFO_STOP),
     m_deckControlMode(CEC_DECK_CONTROL_MODE_STOP)
index f8a24a19170d870d6ac750d1c9cfad5250309c66..414f8478517562b71366d592fdc5f60222827aaf 100644 (file)
@@ -38,7 +38,7 @@ namespace CEC
   class CCECPlaybackDevice : public CCECBusDevice
   {
   public:
-    CCECPlaybackDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = 0);
+    CCECPlaybackDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = CEC_INVALID_PHYSICAL_ADDRESS);
     virtual ~CCECPlaybackDevice(void) {};
 
     cec_deck_info GetDeckStatus(void);
index 5639bc8dc920d29c057b46b3f541d039b60b908b..c5f4535af4254b7b83028e63b011c5138bb5b154 100644 (file)
@@ -34,7 +34,7 @@
 
 using namespace CEC;
 
-CCECRecordingDevice::CCECRecordingDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = 0 */) :
+CCECRecordingDevice::CCECRecordingDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = CEC_INVALID_PHYSICAL_ADDRESS */) :
     CCECBusDevice(processor, address, iPhysicalAddress),
     m_playbackDevice(processor, address, iPhysicalAddress),
     m_tuner(processor, address, iPhysicalAddress)
index cb6571513135d8d72c9db772b0faba840fc36e7f..f64b95b357a88683691fc6a9dcaf8004effa4a5d 100644 (file)
@@ -40,7 +40,7 @@ namespace CEC
   class CCECRecordingDevice : public CCECBusDevice
   {
   public:
-    CCECRecordingDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = 0);
+    CCECRecordingDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = CEC_INVALID_PHYSICAL_ADDRESS);
     virtual ~CCECRecordingDevice(void) {};
 
     /* playback device methods */
index 27df9b600869b9b53294824c626bb61fb3f2fed1..5c2e909f26296ed7f8972c02e43e6640480afc08 100644 (file)
@@ -34,8 +34,8 @@
 
 using namespace CEC;
 
-CCECTV::CCECTV(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = 0 */) :
-    CCECBusDevice(processor, address, iPhysicalAddress)
+CCECTV::CCECTV(CCECProcessor *processor, cec_logical_address address) :
+    CCECBusDevice(processor, address, CEC_PHYSICAL_ADDRESS_TV)
 {
-  m_type          = CEC_DEVICE_TYPE_TV;
+  m_type = CEC_DEVICE_TYPE_TV;
 }
index a90169e43f165baba663133d25f173177ca410f1..e712e96b8818f9eedf1b3d6cf03705dfe7df254a 100644 (file)
@@ -38,7 +38,7 @@ namespace CEC
   class CCECTV : public CCECBusDevice
   {
   public:
-    CCECTV(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = 0);
+    CCECTV(CCECProcessor *processor, cec_logical_address address);
     virtual ~CCECTV(void) {};
   };
 }
index b5de867d9e8a968fe4aeb644ce572ac5ca2330c5..feb35e4b5bd92834c3099efcbac1b92ee7637409 100644 (file)
@@ -34,7 +34,7 @@
 
 using namespace CEC;
 
-CCECTuner::CCECTuner(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = 0 */) :
+CCECTuner::CCECTuner(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress /* = CEC_INVALID_PHYSICAL_ADDRESS */) :
     CCECBusDevice(processor, address, iPhysicalAddress)
 {
   m_type          = CEC_DEVICE_TYPE_TUNER;
index 2cf2ed2f6cbae0774782707483811ea1ee3b24fa..ad65efdf65ae729a0740ac7b4eeecdc9435d7976 100644 (file)
@@ -38,7 +38,7 @@ namespace CEC
   class CCECTuner : public CCECBusDevice
   {
   public:
-    CCECTuner(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = 0);
+    CCECTuner(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = CEC_INVALID_PHYSICAL_ADDRESS);
     virtual ~CCECTuner(void) {};
   };
 }
index dc8c70f34deeefb5f8c150e142fc0d30001d302a..449c589e27154805350ab8dee9cbb06204bd2f40 100644 (file)
@@ -682,7 +682,7 @@ size_t CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const
   size_t iReturn(0);
 
   cec_logical_addresses addresses = m_processor->GetLogicalAddresses();
-  for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+  for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++)
   {
     if (addresses[iPtr])
     {
index be1f6436ad8f64636c346c9a20a7966bdf13d0be..24f62658b9009c419e07d057a923cc4aa5a6faaa 100644 (file)
@@ -77,7 +77,7 @@ namespace CEC
       m_waitingFor.clear();
     }
 
-    bool Wait(cec_opcode opcode, uint32_t iTimeout = 2000)
+    bool Wait(cec_opcode opcode, uint32_t iTimeout = CEC_DEFAULT_TRANSMIT_WAIT)
     {
       CResponse *response = GetEvent(opcode);
       return response ? response->Wait(iTimeout) : false;
index 2fa510e0bcc15310eaeff0d108c4efeefe6cf479..39b7ff47df5ca8e761aa3235adc7feffc9db02e9 100644 (file)
@@ -214,7 +214,7 @@ void ListDevices(ICECAdapter *parser)
       {
         strDeviceInfo.AppendFormat("firmware version:    %d\n", config.iFirmwareVersion);
 
-        if (config.iFirmwareBuildDate != CEC_DEFAULT_FIRMWARE_BUILD_DATE)
+        if (config.iFirmwareBuildDate != CEC_FW_BUILD_UNKNOWN)
         {
           time_t buildTime = (time_t)config.iFirmwareBuildDate;
           strDeviceInfo.AppendFormat("firmware build date: %s", asctime(gmtime(&buildTime)));