cec: added GetActiveDevices()/cec_get_active_devices(), IsActiveDevice()/cec_is_activ...
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 25 Nov 2011 11:32:28 +0000 (12:32 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 25 Nov 2011 11:32:28 +0000 (12:32 +0100)
include/cec.h
include/cecc.h
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/LibCEC.cpp
src/lib/LibCEC.h
src/lib/LibCECC.cpp
src/testclient/main.cpp

index 7a306dddc82f37d4d26e8c68132af1c638f61e9a..2e47abde32cb17ff4a13f89e4d787e3470eda31a 100644 (file)
@@ -243,6 +243,25 @@ namespace CEC
      * @return True if the POLL was acked, false otherwise.
      */
     virtual bool PollDevice(cec_logical_address iAddress) = 0;
+
+    /*!
+     * @return The devices that are active on the bus and not handled by libcec.
+     */
+    virtual cec_logical_addresses GetActiveDevices(void) = 0;
+
+    /*!
+     * @brief Check whether a device is active on the bus.
+     * @param iAddress The address to check.
+     * @return True when active, false otherwise.
+     */
+    virtual bool IsActiveDevice(cec_logical_address iAddress) = 0;
+
+    /*!
+     * @brief Check whether a device of the given type is active on the bus.
+     * @param type The type to check.
+     * @return True when active, false otherwise.
+     */
+    virtual bool IsActiveDeviceType(cec_device_type type) = 0;
   };
 };
 
index 0b0f2fecbc3cc5a6bcf5cbd2c6a2d305135bb461..c6446622c1598e506e0e8dcb721f1dc2ce224de3 100644 (file)
@@ -167,6 +167,24 @@ extern DECLSPEC int cec_poll_device(CEC::cec_logical_address iLogicalAddress);
 extern DECLSPEC int cec_poll_device(cec_logical_address iLogicalAddress);
 #endif
 
+#ifdef __cplusplus
+extern DECLSPEC CEC::cec_logical_addresses cec_get_active_devices(void);
+#else
+extern DECLSPEC cec_logical_addresses cec_get_active_devices(void);
+#endif
+
+#ifdef __cplusplus
+extern DECLSPEC int cec_is_active_device(CEC::cec_logical_address iAddress);
+#else
+extern DECLSPEC int cec_is_active_device(cec_logical_address iAddress);
+#endif
+
+#ifdef __cplusplus
+extern DECLSPEC int cec_is_active_device_type(CEC::cec_device_type type);
+#else
+extern DECLSPEC int cec_is_active_device_type(cec_device_type type);
+#endif
+
 #ifdef __cplusplus
 };
 #endif
index c7d4de26e5578fcbcaeab02e4249fcfab0c0e1b3..dfd0cc1cb1b64a4bdd9e330aba2453a2ee597fa1 100644 (file)
@@ -647,6 +647,31 @@ void CCECProcessor::ParseCommand(cec_command &command)
     m_busDevices[(uint8_t)command.initiator]->HandleCommand(command);
 }
 
+cec_logical_addresses CCECProcessor::GetActiveDevices(void)
+{
+  cec_logical_addresses addresses;
+  for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
+  {
+    if (m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
+      addresses.Set((cec_logical_address) iPtr);
+  }
+  return addresses;
+}
+
+bool CCECProcessor::IsActiveDevice(cec_logical_address address)
+{
+  return m_busDevices[address]->GetStatus() == CEC_DEVICE_STATUS_PRESENT;
+}
+
+bool CCECProcessor::IsActiveDeviceType(cec_device_type type)
+{
+  cec_logical_addresses activeDevices = GetActiveDevices();
+  for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
+    if (activeDevices.IsSet((cec_logical_address) iPtr) && m_busDevices[iPtr]->GetType() == type)
+      return true;
+  return false;
+}
+
 uint16_t CCECProcessor::GetPhysicalAddress(void) const
 {
   if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary])
index e7832d822d50d8364e7dffdb47d745b9ab7884bb..58bba6b3ffa2a9993666a4ce3d6dd9548c638e5b 100644 (file)
@@ -66,7 +66,10 @@ namespace CEC
       virtual cec_power_status      GetDevicePowerStatus(cec_logical_address iAddress);
       virtual cec_logical_address   GetLogicalAddress(void) const { return m_logicalAddresses.primary; }
       virtual cec_logical_addresses GetLogicalAddresses(void) const { return m_logicalAddresses; }
+      virtual cec_logical_addresses GetActiveDevices(void);
       virtual bool                  HasLogicalAddress(cec_logical_address address) const { return m_logicalAddresses.IsSet(address); }
+      virtual bool                  IsActiveDevice(cec_logical_address address);
+      virtual bool                  IsActiveDeviceType(cec_device_type type);
       virtual uint16_t              GetPhysicalAddress(void) const;
 
       virtual bool SetActiveView(void);
index c0675622e32db807817195d61f9270b02d66cf2f..3b4765134d9fdfd0f1de53f3f87532865480bcab 100644 (file)
@@ -253,6 +253,28 @@ bool CLibCEC::PollDevice(cec_logical_address iAddress)
   return false;
 }
 
+cec_logical_addresses CLibCEC::GetActiveDevices(void)
+{
+  cec_logical_addresses addresses;
+  if (m_cec)
+    addresses = m_cec->GetActiveDevices();
+  return addresses;
+}
+
+bool CLibCEC::IsActiveDevice(cec_logical_address iAddress)
+{
+  if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST)
+    return m_cec->IsActiveDevice(iAddress);
+  return false;
+}
+
+bool CLibCEC::IsActiveDeviceType(cec_device_type type)
+{
+  if (m_cec && type >= CEC_DEVICE_TYPE_TV && type <= CEC_DEVICE_TYPE_AUDIO_SYSTEM)
+    return m_cec->IsActiveDeviceType(type);
+  return false;
+}
+
 void CLibCEC::AddLog(cec_log_level level, const string &strMessage)
 {
   if (m_cec)
index 7a69c96b66da525e9cdc90673effacc3da03337c..b6948e49d42b9ef4e02c7dfd657f99a193bd00dc 100644 (file)
@@ -84,6 +84,9 @@ namespace CEC
       virtual uint64_t GetDeviceVendorId(cec_logical_address iAddress);
       virtual cec_power_status GetDevicePowerStatus(cec_logical_address iAddress);
       virtual bool PollDevice(cec_logical_address iAddress);
+      virtual cec_logical_addresses GetActiveDevices(void);
+      virtual bool IsActiveDevice(cec_logical_address iAddress);
+      virtual bool IsActiveDeviceType(cec_device_type type);
     //@}
 
       virtual void AddLog(cec_log_level level, const std::string &strMessage);
index c95741c2356d930be974fe677db0636d5aa6fbea..ec703f2d69ba6c178fb3365f012b8d91977c1195 100644 (file)
@@ -238,7 +238,29 @@ cec_power_status cec_get_device_power_status(cec_logical_address iLogicalAddress
 int cec_poll_device(cec_logical_address iLogicalAddress)
 {
   if (cec_parser)
-    return cec_parser->PollDevice(iLogicalAddress);
+    return cec_parser->PollDevice(iLogicalAddress) ? 1 : 0;
+  return -1;
+}
+
+cec_logical_addresses cec_get_active_devices(void)
+{
+  cec_logical_addresses addresses;
+  if (cec_parser)
+    addresses = cec_parser->GetActiveDevices();
+  return addresses;
+}
+
+int cec_is_active_device(cec_logical_address iAddress)
+{
+  if (cec_parser)
+    return cec_parser->IsActiveDevice(iAddress) ? 1 : 0;
+  return -1;
+}
+
+int cec_is_active_device_type(cec_device_type type)
+{
+  if (cec_parser)
+    return cec_parser->IsActiveDeviceType(type) ? 1 : 0;
   return -1;
 }
 
index 73d69905186d177d6193b0d6c98f280ad6634aa5..dbb62e70804825094853973f43425cc44d54139b 100644 (file)
@@ -223,38 +223,19 @@ void ShowHelpConsole(void)
   endl <<
   "tx {bytes}                transfer bytes over the CEC line." << endl <<
   "txn {bytes}               transfer bytes but don't wait for transmission ACK." << endl <<
-  "[tx 40 00 FF 11 22 33]    sends bytes 0x40 0x00 0xFF 0x11 0x22 0x33" << endl <<
-  endl <<
   "on {address}              power on the device with the given logical address." << endl <<
-  "[on 5]                    power on a connected audio system" << endl <<
-  endl <<
   "standby {address}         put the device with the given address in standby mode." << endl <<
-  "[standby 0]               powers off the TV" << endl <<
-  endl <<
   "la {logical_address}      change the logical address of the CEC adapter." << endl <<
-  "[la 4]                    logical address 4" << endl <<
-  endl <<
   "pa {physical_address}     change the physical address of the CEC adapter." << endl <<
-  "[pa 10 00]                physical address 1.0.0.0" << endl <<
-  endl <<
   "osd {addr} {string}       set OSD message on the specified device." << endl <<
-  "[osd 0 Test Message]      displays 'Test Message' on the TV" << endl <<
-  endl <<
   "ver {addr}                get the CEC version of the specified device." << endl <<
-  "[ver 0]                   get the CEC version of the TV" << endl <<
-  endl <<
   "ven {addr}                get the vendor ID of the specified device." << endl <<
-  "[ven 0]                   get the vendor ID of the TV" << endl <<
-  endl <<
   "lang {addr}               get the menu language of the specified device." << endl <<
-  "[lang 0]                  get the menu language of the TV" << endl <<
-  endl <<
   "pow {addr}                get the power status of the specified device." << endl <<
-  "[pow 0]                   get the power status of the TV" << endl <<
-  endl <<
   "poll {addr}               poll the specified device." << endl <<
-  "[poll 0]                  sends a poll message to the TV" << endl <<
-  endl <<
+  "lad                       lists active devices on the bus" << endl <<
+  "ad {addr}                 checks whether the specified device is active." << endl <<
+  "at {type}                 checks whether the specified device type is active." << endl <<
   "[mon] {1|0}               enable or disable CEC bus monitoring." << endl <<
   "[log] {1 - 31}            change the log level. see cectypes.h for values." << endl <<
   "[ping]                    send a ping command to the CEC adapter." << endl <<
@@ -709,6 +690,41 @@ int main (int argc, char *argv[])
             }
           }
         }
+        else if (command == "lad")
+        {
+          cout << "listing active devices:" << endl;
+          cec_logical_addresses addresses = parser->GetActiveDevices();
+          for (unsigned iPtr = 0; iPtr < 16; iPtr++)
+            if (addresses[iPtr])
+              cout << "logical address " << iPtr << endl;
+        }
+        else if (command == "ad")
+        {
+          CStdString strDev;
+          if (GetWord(input, strDev))
+          {
+            int iDev = atoi(strDev);
+            if (iDev >= 0 && iDev < 15)
+              cout << "logical address " << iDev << " is " << (parser->IsActiveDevice((cec_logical_address)iDev) ? "active" : "not active") << endl;
+          }
+        }
+        else if (command == "at")
+        {
+          CStdString strType;
+          if (GetWord(input, strType))
+          {
+            cec_device_type type = CEC_DEVICE_TYPE_TV;
+            if (strType.Equals("a"))
+              type = CEC_DEVICE_TYPE_AUDIO_SYSTEM;
+            else if (strType.Equals("p"))
+              type = CEC_DEVICE_TYPE_PLAYBACK_DEVICE;
+            else if (strType.Equals("r"))
+              type = CEC_DEVICE_TYPE_RECORDING_DEVICE;
+            else if (strType.Equals("t"))
+              type = CEC_DEVICE_TYPE_TUNER;
+            cout << "device " << type << " is " << (parser->IsActiveDeviceType(type) ? "active" : "not active") << endl;
+          }
+        }
         else if (command == "r")
         {
           cout << "closing the connection" << endl;