cec: added the firmware version to cec-client's -l / --list-devices command. bugzid...
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 23 Mar 2012 10:52:10 +0000 (11:52 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 23 Mar 2012 10:52:10 +0000 (11:52 +0100)
include/cec.h
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/LibCEC.cpp
src/lib/LibCEC.h
src/lib/adapter/AdapterCommunication.h
src/lib/adapter/USBCECAdapterCommunication.cpp
src/lib/adapter/USBCECAdapterCommunication.h
src/testclient/main.cpp

index 0332088906e72a0a5c254ec42b023251aa02e00e..20e103b87806b966e403b22e7d06381c2f2b4592 100644 (file)
@@ -424,6 +424,15 @@ namespace CEC
      * @return true when libCEC is the active source on the bus, false otherwise.
      */
     virtual bool IsLibCECActiveSource(void) = 0;
+
+    /*!
+     * @brief Get information about the given device
+     * @param strPort The port to which the device is connected
+     * @param config The device configuration
+     * @param iTimeoutMs The timeout in milliseconds
+     * @return True when the device was found, false otherwise
+     */
+    virtual bool GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs = 10000) = 0;
   };
 };
 
index 5000e047b81d824f2ad39302fbbf529ee85dd3f1..4685132619bba76bc243da41281dd9ab1c88b4fb 100644 (file)
@@ -157,7 +157,7 @@ void CCECProcessor::Close(void)
   }
 }
 
-bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs)
+bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening /* = true */)
 {
   bool bReturn(false);
   Close();
@@ -184,7 +184,7 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint
 
   /* open a new connection */
   unsigned iConnectTry(0);
-  while (timeout.TimeLeft() > 0 && (bReturn = m_communication->Open(this, (timeout.TimeLeft() / CEC_CONNECT_TRIES))) == false)
+  while (timeout.TimeLeft() > 0 && (bReturn = m_communication->Open(this, (timeout.TimeLeft() / CEC_CONNECT_TRIES), false, bStartListening)) == false)
   {
     CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry);
     m_communication->Close();
@@ -1682,3 +1682,15 @@ void CCECProcessor::RescanActiveDevices(void)
   for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
     m_busDevices[iPtr]->GetStatus(true);
 }
+
+bool CCECProcessor::GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs /* = 10000 */)
+{
+  if (!OpenConnection(strPort, 38400, iTimeoutMs, false))
+    return false;
+
+  config->iFirmwareVersion = m_communication->GetFirmwareVersion();
+  config->iPhysicalAddress = m_communication->GetPhysicalAddress();
+
+  delete m_communication;
+  return true;
+}
index d2808443c34bbba3e5d2903670d7cc38e06661d0..41f3fde8ed224d7ff93d9b2919d1c7bbf5feca33 100644 (file)
@@ -142,11 +142,13 @@ namespace CEC
       virtual void HandlePoll(cec_logical_address initiator, cec_logical_address destination);
       virtual bool HandleReceiveFailed(cec_logical_address initiator);
 
+      virtual bool GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs = 10000);
+
       CCECBusDevice *  m_busDevices[16];
       PLATFORM::CMutex m_transmitMutex;
 
   private:
-      bool OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs);
+      bool OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening = true);
       bool Initialise(void);
       void SetInitialised(bool bSetTo = true);
       void CreateBusDevices(void);
index dd8624aeb13b38506385d14078286f8c0ae1a6b5..03962e2ce0907616cd2bbd0531bf5ffba9371e30 100644 (file)
@@ -705,3 +705,11 @@ uint16_t CLibCEC::GetMaskForType(cec_device_type type)
       return 0;
   }
 }
+
+bool CLibCEC::GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs /* = 10000 */)
+{
+  if (m_cec->IsRunning())
+    return false;
+  
+  return m_cec->GetDeviceInformation(strPort, config, iTimeoutMs);
+}
\ No newline at end of file
index b8c8667d67ab9bd8b50d4b374d4e8243af53e823..2dca04019fad0f05d6fa65a03b1bf40cee61ec34 100644 (file)
@@ -125,6 +125,8 @@ namespace CEC
       static cec_device_type GetType(cec_logical_address address);
       static uint16_t GetMaskForType(cec_logical_address address);
       static uint16_t GetMaskForType(cec_device_type type);
+
+      virtual bool GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs = 10000);
     //@}
 
       static void AddLog(const cec_log_level level, const char *strFormat, ...);
index 400b32151e10fc8a51d4cb5c305cb3d9d0333b2b..98f55e61588911ad5c70c1f3da2b6cb1d188db27 100644 (file)
@@ -71,9 +71,10 @@ namespace CEC
      * @param cb The callback struct. if set to NULL, the Read() method has to be used to read commands. if set, OnCommandReceived() will be called for each command that was received
      * @param iTimeoutMs Connection timeout in ms
      * @param bSkipChecks Skips all initial checks of the adapter, and starts the reader/writer threads directly after connecting.
+     * @param bStartListening Start a listener thread when true. False to just open a connection, read the device info, and close the connection.
      * @return True when connected, false otherwise
      */
-    virtual bool Open(IAdapterCommunicationCallback *cb, uint32_t iTimeoutMs = 10000, bool bSkipChecks = false) = 0;
+    virtual bool Open(IAdapterCommunicationCallback *cb, uint32_t iTimeoutMs = 10000, bool bSkipChecks = false, bool bStartListening = true) = 0;
 
     /*!
      * @brief Close an open connection
index 99086ce94f54dbbc4e88cc692437e2e210fca0dd..d6f10d91a4a15a7d52e3809d504258a5568937b6 100644 (file)
@@ -133,7 +133,7 @@ bool CUSBCECAdapterCommunication::CheckAdapter(uint32_t iTimeoutMs /* = 10000 */
   return bReturn;
 }
 
-bool CUSBCECAdapterCommunication::Open(IAdapterCommunicationCallback *cb, uint32_t iTimeoutMs /* = 10000 */, bool bSkipChecks /* = false */)
+bool CUSBCECAdapterCommunication::Open(IAdapterCommunicationCallback *cb, uint32_t iTimeoutMs /* = 10000 */, bool bSkipChecks /* = false */, bool bStartListening /* = true */)
 {
   uint64_t iNow = GetTimeMs();
   uint64_t iTimeout = iNow + iTimeoutMs;
@@ -200,10 +200,10 @@ bool CUSBCECAdapterCommunication::Open(IAdapterCommunicationCallback *cb, uint32
   if (!bSkipChecks && !CheckAdapter())
   {
     CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter failed to pass basic checks");
-    Close();
+    delete m_port;
     return false;
   }
-  else
+  else if (bStartListening)
   {
     if (CreateThread())
     {
@@ -212,12 +212,16 @@ bool CUSBCECAdapterCommunication::Open(IAdapterCommunicationCallback *cb, uint32
     }
     else
     {
-      Close();
+      delete m_port;
       CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a communication thread");
     }
   }
+  else
+  {
+    delete m_port;
+  }
 
-  return false;
+  return true;
 }
 
 void CUSBCECAdapterCommunication::Close(void)
@@ -534,6 +538,7 @@ bool CUSBCECAdapterCommunication::PersistConfiguration(libcec_configuration *con
 
 bool CUSBCECAdapterCommunication::GetConfiguration(libcec_configuration *configuration)
 {
+  configuration->iFirmwareVersion = m_iFirmwareVersion;
   if (m_iFirmwareVersion < 2)
     return false;
 
index 5db5a1a0674310a9b4fe94a9fc517fe211eea94f..4e7944eb5eb04964ed8c4f071b5d16cc41e1e30d 100644 (file)
@@ -69,7 +69,7 @@ namespace CEC
     CUSBCECAdapterCommunication(CCECProcessor *processor, const char *strPort, uint16_t iBaudRate = 38400);
     virtual ~CUSBCECAdapterCommunication() {};
 
-    virtual bool Open(IAdapterCommunicationCallback *cb, uint32_t iTimeoutMs = 10000, bool bSkipChecks = false);
+    virtual bool Open(IAdapterCommunicationCallback *cb, uint32_t iTimeoutMs = 10000, bool bSkipChecks = false, bool bStartListening = true);
     virtual void Close(void);
     virtual bool IsOpen(void);
     virtual CStdString GetError(void) const;
index d915545dbe726371d59f0dc9890f58e51d0f55f4..c9a74d7b0364eac3162a9d7ca12fc09af97e0da2 100644 (file)
@@ -194,9 +194,22 @@ void ListDevices(ICECAdapter *parser)
   }
   else
   {
-    PrintToStdOut("Found devices: %d\n", iDevicesFound);
+    CStdString strDeviceInfo;
+    strDeviceInfo.Format("Found devices: %d\n\n", iDevicesFound);
+
     for (int8_t iDevicePtr = 0; iDevicePtr < iDevicesFound; iDevicePtr++)
-      PrintToStdOut("device:        %d\npath:          %s\ncom port:      %s\n", iDevicePtr + 1, devices[iDevicePtr].path, devices[iDevicePtr].comm);
+    {
+      strDeviceInfo.AppendFormat("device:             %d\ncom port:           %s\n", iDevicePtr + 1, devices[iDevicePtr].comm);
+      libcec_configuration config;
+      config.Clear();
+
+      if (!parser->GetDeviceInformation(devices[iDevicePtr].comm, &config))
+        PrintToStdOut("WARNING: unable to open the device on port %s", devices[iDevicePtr].comm);
+      else
+        strDeviceInfo.AppendFormat("firmware version:   %d\n", config.iFirmwareVersion);
+    }
+
+    PrintToStdOut(strDeviceInfo.c_str());
   }
 }