cec: add SetPhysicalAddress()/cec_set_physical_address() to the interface, so the...
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 14 Oct 2011 09:06:24 +0000 (11:06 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 14 Oct 2011 09:06:24 +0000 (11:06 +0200)
include/cec.h
include/cecc.h
include/cectypes.h
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/LibCEC.cpp
src/lib/LibCEC.h
src/lib/LibCECC.cpp

index 7afb0651dbb247e0eb6eeb774c80f5d2be7eb5f5..bf7a4735eb7840f3e9f486f5b4212e4d9d1a08b3 100644 (file)
@@ -103,7 +103,12 @@ namespace CEC
     /*!
      * @see cec_set_logical_address
      */
-    virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress) = 0;
+    virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1) = 0;
+
+    /*!
+     * @see cec_set_physical_address
+     */
+    virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS) = 0;
 
     /*!
      * @see cec_power_on_devices
index bfbe0ccba60b60838d5c0214f6010152fb07fe6d..43e79d836b0dc2ab22e9cf8a4c8f6d9f1416cb50 100644 (file)
@@ -185,16 +185,23 @@ extern DECLSPEC int cec_transmit(const cec_command &data, int bWaitForAck = 1);
 #endif
 
 /*!
- * @brief Set the logical address of the CEC adapter.
- * @param iLogicalAddress The cec adapter's logical address.
- * @return True when the logical address was set succesfully, false otherwise.
+ * @brief Change the logical address of the CEC adapter.
+ * @param iLogicalAddress The CEC adapter's new logical address.
+ * @return True when the logical address was set successfully, false otherwise.
  */
 #ifdef __cplusplus
-extern DECLSPEC int cec_set_logical_address(CEC::cec_logical_address iLogicalAddress);
+extern DECLSPEC int cec_set_logical_address(CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1);
 #else
 extern DECLSPEC int cec_set_logical_address(cec_logical_address myAddress, cec_logical_address targetAddress);
 #endif
 
+/*!
+ * @brief Change the physical address (HDMI port) of the CEC adapter.
+ * @param iPhysicalAddress The CEC adapter's new physical address.
+ * @brief True when the physical address was set successfully, false otherwise.
+ */
+extern DECLSPEC int cec_set_physical_address(uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
+
 #ifdef __cplusplus
 };
 #endif
index e5b7791306b887e03d623decbbd3cd80013482f8..f18d928a2a3e6a15b00604bce22db834e3290691 100644 (file)
@@ -693,7 +693,7 @@ typedef enum cec_vendor_id
   CEC_VENDOR_UNKNOWN = 0
 } vendor_id;
 
-//default physical address 1.0.0.0
+//default physical address 1.0.0.0, HDMI port 1
 #define CEC_DEFAULT_PHYSICAL_ADDRESS 0x1000
 #define MSGSTART                     0xFF
 #define MSGEND                       0xFE
index ae7d5fd16b93c1b7ecab70f2b8c784b8234f46b5..7ddf61297456c8942fae0582237f33cb7c1d10c0 100644 (file)
@@ -41,7 +41,7 @@ using namespace CEC;
 using namespace std;
 
 CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
-    m_physicaladdress(iPhysicalAddress),
+    m_iPhysicalAddress(iPhysicalAddress),
     m_iLogicalAddress(iLogicalAddress),
     m_strDeviceName(strDeviceName),
     m_communication(serComm),
@@ -158,8 +158,8 @@ bool CCECProcessor::SetActiveView(void)
 
   cec_command command;
   cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE);
-  command.parameters.push_back((m_physicaladdress >> 8) & 0xFF);
-  command.parameters.push_back(m_physicaladdress & 0xFF);
+  command.parameters.push_back((m_iPhysicalAddress >> 8) & 0xFF);
+  command.parameters.push_back(m_iPhysicalAddress & 0xFF);
 
   return Transmit(command);
 }
@@ -173,8 +173,8 @@ bool CCECProcessor::SetInactiveView(void)
 
   cec_command command;
   cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_INACTIVE_SOURCE);
-  command.parameters.push_back((m_physicaladdress >> 8) & 0xFF);
-  command.parameters.push_back(m_physicaladdress & 0xFF);
+  command.parameters.push_back((m_iPhysicalAddress >> 8) & 0xFF);
+  command.parameters.push_back(m_iPhysicalAddress & 0xFF);
 
   return Transmit(command);
 }
@@ -204,13 +204,23 @@ bool CCECProcessor::Transmit(const cec_command &data, bool bWaitForAck /* = true
 bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
 {
   CStdString strLog;
-  strLog.Format("<< setting logical address to %d", iLogicalAddress);
+  strLog.Format("<< setting logical address to %1x", iLogicalAddress);
   m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
 
   m_iLogicalAddress = iLogicalAddress;
   return m_communication && m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress);
 }
 
+bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress)
+{
+  CStdString strLog;
+  strLog.Format("<< setting physical address to %2x", iPhysicalAddress);
+  m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
+
+  m_iPhysicalAddress = iPhysicalAddress;
+  return SetActiveView();
+}
+
 bool CCECProcessor::TransmitFormatted(const cec_adapter_message &data, bool bWaitForAck /* = true */)
 {
   CLockObject lock(&m_mutex);
@@ -316,13 +326,13 @@ void CCECProcessor::ReportOSDName(cec_logical_address address /* = CECDEVICE_TV
 void CCECProcessor::ReportPhysicalAddress(void)
 {
   CStdString strLog;
-  strLog.Format("<< reporting physical address as %04x", m_physicaladdress);
+  strLog.Format("<< reporting physical address as %04x", m_iPhysicalAddress);
   m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
 
   cec_command command;
   cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS);
-  command.parameters.push_back((uint8_t) ((m_physicaladdress >> 8) & 0xFF));
-  command.parameters.push_back((uint8_t) (m_physicaladdress & 0xFF));
+  command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF));
+  command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF));
   command.parameters.push_back((uint8_t) (CEC_DEVICE_TYPE_PLAYBACK_DEVICE));
 
   Transmit(command);
@@ -334,8 +344,8 @@ void CCECProcessor::BroadcastActiveSource(void)
 
   cec_command command;
   cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE);
-  command.parameters.push_back((uint8_t) ((m_physicaladdress >> 8) & 0xFF));
-  command.parameters.push_back((uint8_t) (m_physicaladdress & 0xFF));
+  command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF));
+  command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF));
 
   Transmit(command);
 }
@@ -580,7 +590,7 @@ void CCECProcessor::ParseCommand(cec_command &command)
         int streamaddr = ((int)command.parameters[0] << 8) | ((int)command.parameters[1]);
         strLog.Format(">> %i requests stream path from physical address %04x", command.initiator, streamaddr);
         m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
-        if (streamaddr == m_physicaladdress)
+        if (streamaddr == m_iPhysicalAddress)
           BroadcastActiveSource();
       }
     }
index 8617257f30437a3236c32cd613a2a6a89ed997b6..43b7a30cae32d170893d1b4b1f20ae2285f38a4a 100644 (file)
@@ -58,6 +58,7 @@ namespace CEC
       virtual bool SetInactiveView(void);
       virtual bool Transmit(const cec_command &data, bool bWaitForAck = true);
       virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress);
+      virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress);
 
       static const char *CECVendorIdToString(const uint64_t iVendorId);
 
@@ -80,7 +81,7 @@ namespace CEC
       void ParseVendorId(cec_logical_address device, const cec_datapacket &data);
 
       cec_command                    m_currentframe;
-      uint16_t                       m_physicaladdress;
+      uint16_t                       m_iPhysicalAddress;
       cec_logical_address            m_iLogicalAddress;
       CecBuffer<cec_adapter_message> m_frameBuffer;
       std::string                    m_strDeviceName;
index 0c4b89de220d0a7ebff81bc0f4e5189d20a84718..78fca2d1a610c2528bfc7cd34096e0db9ea0fbfb 100644 (file)
@@ -168,6 +168,11 @@ bool CLibCEC::SetLogicalAddress(cec_logical_address iLogicalAddress)
   return m_cec ? m_cec->SetLogicalAddress(iLogicalAddress) : false;
 }
 
+bool CLibCEC::SetPhysicalAddress(uint16_t iPhysicalAddress)
+{
+  return m_cec ? m_cec->SetPhysicalAddress(iPhysicalAddress) : false;
+}
+
 bool CLibCEC::PowerOnDevices(cec_logical_address address /* = CECDEVICE_TV */)
 {
   return m_cec ? m_cec->PowerOnDevices(address) : false;
index 2ad32dafb64eb76dafb23bbbcea30a8d7f773c7a..2f80720a2ec4970eae1923fcf15e7578fdc688bd 100644 (file)
@@ -64,7 +64,8 @@ namespace CEC
       virtual bool GetNextCommand(cec_command *command);
 
       virtual bool Transmit(const cec_command &data, bool bWaitForAck = true);
-      virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress);
+      virtual bool SetLogicalAddress(cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1);
+      virtual bool SetPhysicalAddress(uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
 
       virtual bool PowerOnDevices(cec_logical_address address = CECDEVICE_TV);
       virtual bool StandbyDevices(cec_logical_address address = CECDEVICE_BROADCAST);
index 1c9ef4d3d8a68fa11027e830651d2c3ed5207bed..ccdd5b6a339b86762b2058db713ef0d7d6f16f70 100644 (file)
@@ -131,13 +131,20 @@ int cec_transmit(const CEC::cec_command &data, int bWaitForAck /* = true */)
   return -1;
 }
 
-int cec_set_logical_address(cec_logical_address iLogicalAddress)
+int cec_set_logical_address(cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */)
 {
   if (cec_parser)
     return cec_parser->SetLogicalAddress(iLogicalAddress) ? 1 : 0;
   return -1;
 }
 
+int cec_set_physical_address(uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
+{
+  if (cec_parser)
+    return cec_parser->SetPhysicalAddress(iPhysicalAddress) ? 1 : 0;
+  return -1;
+}
+
 int cec_power_on_devices(cec_logical_address address /* = CECDEVICE_TV */)
 {
   if (cec_parser)