* @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;
};
};
}
}
-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();
/* 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();
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;
+}
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);
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
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, ...);
* @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
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;
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())
{
}
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)
bool CUSBCECAdapterCommunication::GetConfiguration(libcec_configuration *configuration)
{
+ configuration->iFirmwareVersion = m_iFirmwareVersion;
if (m_iFirmwareVersion < 2)
return false;
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;
}
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());
}
}