From: Lars Op den Kamp Date: Sun, 24 Feb 2013 11:40:26 +0000 (+0100) Subject: added DetectAdapters() method, that returns all device information for detected adapt... X-Git-Tag: upstream/2.2.0~1^2~6^2~10 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e7fd53c8e125db215629cdc557c45e2e875d02cc;p=deb_libcec.git added DetectAdapters() method, that returns all device information for detected adapters, not just the com port --- diff --git a/include/cec.h b/include/cec.h index 0245033..8570220 100644 --- a/include/cec.h +++ b/include/cec.h @@ -72,6 +72,7 @@ namespace CEC virtual void Close(void) = 0; /*! + * @deprecated Use DetectAdapters() instead * @brief Try to find all connected CEC adapters. * @param deviceList The vector to store device descriptors in. * @param iBufSize The size of the deviceList buffer. @@ -446,6 +447,16 @@ namespace CEC * @return The current audio status, or cec_audio_status if unknown. */ virtual uint8_t AudioStatus(void) = 0; + + /*! + * @brief Try to find all connected CEC adapters. + * @param deviceList The vector to store device descriptors in. + * @param iBufSize The size of the deviceList buffer. + * @param strDevicePath Optional device path. Only adds device descriptors that match the given device path. + * @return The number of devices that were found, or -1 when an error occured. + */ + virtual int8_t DetectAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL) = 0; + }; }; diff --git a/include/cecc.h b/include/cecc.h index 074a348..878c5ac 100644 --- a/include/cecc.h +++ b/include/cecc.h @@ -284,6 +284,12 @@ extern DECLSPEC uint8_t cec_audio_unmute(void); extern DECLSPEC uint8_t cec_audio_get_status(void); +#ifdef __cplusplus +extern DECLSPEC int8_t cec_detect_adapters(CEC::cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath); +#else +extern DECLSPEC int8_t cec_detect_adapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath); +#endif + #ifdef __cplusplus }; #endif diff --git a/include/cectypes.h b/include/cectypes.h index 7b39f84..002ff97 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -883,6 +883,18 @@ typedef struct cec_adapter char comm[1024]; /**< the name of the com port */ } cec_adapter; +typedef struct cec_adapter_descriptor +{ + char strComPath[1024]; /**< the path to the com port */ + char strComName[1024]; /**< the name of the com port */ + uint16_t iVendorId; + uint16_t iProductId; + uint16_t iFirmwareVersion; + uint16_t iPhysicalAddress; + uint32_t iFirmwareBuildDate; + cec_adapter_type adapterType; +} cec_adapter_descriptor; + typedef struct cec_datapacket { uint8_t data[100]; /**< the actual data */ diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 707b8eb..3be1c36 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -623,6 +623,8 @@ bool CCECProcessor::GetDeviceInformation(const char *strPort, libcec_configurati config->iFirmwareBuildDate = m_communication->GetFirmwareBuildDate(); config->adapterType = m_communication->GetAdapterType(); + Close(); + return true; } diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index a27ad9d..fa21953 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -559,3 +559,18 @@ uint8_t CLibCEC::AudioStatus(void) { return m_client ? m_client->AudioStatus() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN; } + +int8_t CLibCEC::DetectAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */) +{ + int8_t iAdaptersFound = CAdapterFactory(this).DetectAdapters(deviceList, iBufSize, strDevicePath); + for (int8_t iPtr = 0; iPtr < iAdaptersFound; iPtr++) + { + libcec_configuration config; + GetDeviceInformation(deviceList[iPtr].strComName, &config); + deviceList[iPtr].iFirmwareVersion = config.iFirmwareVersion; + deviceList[iPtr].iPhysicalAddress = config.iPhysicalAddress; + deviceList[iPtr].iFirmwareBuildDate = config.iFirmwareBuildDate; + deviceList[iPtr].adapterType = config.adapterType; + } + return iAdaptersFound; +} diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index f65b818..2f3ba51 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -52,6 +52,7 @@ namespace CEC void Close(void); bool EnableCallbacks(void *cbParam, ICECCallbacks *callbacks); int8_t FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL); + int8_t DetectAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL); bool PingAdapter(void); bool StartBootloader(void); diff --git a/src/lib/LibCECC.cpp b/src/lib/LibCECC.cpp index 433bef7..05e324a 100644 --- a/src/lib/LibCECC.cpp +++ b/src/lib/LibCECC.cpp @@ -408,4 +408,11 @@ uint8_t cec_audio_get_status(void) return cec_parser ? cec_parser->AudioStatus() : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN; } +int8_t cec_detect_adapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */) +{ + if (cec_parser) + return cec_parser->DetectAdapters(deviceList, iBufSize, strDevicePath); + return -1; +} + //@} diff --git a/src/lib/adapter/AdapterFactory.cpp b/src/lib/adapter/AdapterFactory.cpp index 02b6200..1596cfd 100644 --- a/src/lib/adapter/AdapterFactory.cpp +++ b/src/lib/adapter/AdapterFactory.cpp @@ -56,6 +56,18 @@ using namespace std; using namespace CEC; int8_t CAdapterFactory::FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */) +{ + cec_adapter_descriptor devices[iBufSize]; + int8_t iReturn = DetectAdapters(devices, iBufSize, strDevicePath); + for (int8_t iPtr = 0; iPtr < iReturn; iPtr++) + { + strncpy(deviceList[iPtr].comm, devices[iPtr].strComName, sizeof(deviceList[iPtr].comm)); + strncpy(deviceList[iPtr].path, devices[iPtr].strComPath, sizeof(deviceList[iPtr].path)); + } + return iReturn; +} + +int8_t CAdapterFactory::DetectAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */) { int8_t iAdaptersFound(0); @@ -75,8 +87,11 @@ int8_t CAdapterFactory::FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, if (iAdaptersFound < iBufSize && CRPiCECAdapterDetection::FindAdapter() && (!strDevicePath || !strcmp(strDevicePath, CEC_RPI_VIRTUAL_COM))) { - snprintf(deviceList[iAdaptersFound].path, 1024, CEC_RPI_VIRTUAL_PATH); - snprintf(deviceList[iAdaptersFound++].comm, 1024, CEC_RPI_VIRTUAL_COM); + snprintf(deviceList[iAdaptersFound].strComPath, sizeof(deviceList[iAdaptersFound].strComPath), CEC_RPI_VIRTUAL_PATH); + snprintf(deviceList[iAdaptersFound].strComName, sizeof(deviceList[iAdaptersFound].strComName), CEC_RPI_VIRTUAL_COM); + deviceList[iAdaptersFound].iVendorId = RPI_ADAPTER_VID; + deviceList[iAdaptersFound].iProductId = RPI_ADAPTER_PID; + iAdaptersFound++; } #endif @@ -84,8 +99,11 @@ int8_t CAdapterFactory::FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, if (iAdaptersFound < iBufSize && CTDA995xCECAdapterDetection::FindAdapter() && (!strDevicePath || !strcmp(strDevicePath, CEC_TDA995x_VIRTUAL_COM))) { - snprintf(deviceList[iAdaptersFound].path, 1024, CEC_TDA995x_PATH); - snprintf(deviceList[iAdaptersFound++].comm, 1024, CEC_TDA995x_VIRTUAL_COM); + snprintf(deviceList[iAdaptersFound].path, sizeof(deviceList[iAdaptersFound].strComPath), CEC_TDA995x_PATH); + snprintf(deviceList[iAdaptersFound].comm, sizeof(deviceList[iAdaptersFound].strComName), CEC_TDA995x_VIRTUAL_COM); + deviceList[iAdaptersFound].iVendorId = TDA995X_ADAPTER_VID; + deviceList[iAdaptersFound].iProductId = TDA995X_ADAPTER_PID; + iAdaptersFound++; } #endif diff --git a/src/lib/adapter/AdapterFactory.h b/src/lib/adapter/AdapterFactory.h index d8a1360..4cab3d1 100644 --- a/src/lib/adapter/AdapterFactory.h +++ b/src/lib/adapter/AdapterFactory.h @@ -47,6 +47,7 @@ namespace CEC virtual ~CAdapterFactory(void) {}; int8_t FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL); + int8_t DetectAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL); IAdapterCommunication *GetInstance(const char *strPort, uint16_t iBaudRate = CEC_SERIAL_DEFAULT_BAUDRATE); static void InitVideoStandalone(void); diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.cpp b/src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.cpp index 433a3d3..1331d7c 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.cpp +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.cpp @@ -202,7 +202,7 @@ static bool FindComPortForComposite(const char* strLocation, char* strPortName, } #endif -uint8_t CUSBCECAdapterDetection::FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */) +uint8_t CUSBCECAdapterDetection::FindAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */) { uint8_t iFound(0); @@ -262,10 +262,12 @@ uint8_t CUSBCECAdapterDetection::FindAdapters(cec_adapter *deviceList, uint8_t i if (!strDevicePath || !strcmp(bsdPath, strDevicePath)) { // on darwin, the device path is the same as the comm path. - if (iFound == 0 || strcmp(deviceList[iFound-1].comm, bsdPath)) + if (iFound == 0 || strcmp(deviceList[iFound-1].strComName, bsdPath)) { - snprintf(deviceList[iFound].path, sizeof(deviceList[iFound].path), "%s", bsdPath); - snprintf(deviceList[iFound].comm, sizeof(deviceList[iFound].path), "%s", bsdPath); + snprintf(deviceList[iFound].strComPath, sizeof(deviceList[iFound].strComPath), "%s", bsdPath); + snprintf(deviceList[iFound].strComName, sizeof(deviceList[iFound].strComName), "%s", bsdPath); + deviceList[iFound].iVendorId = iVendor; + deviceList[iFound].iProductId = iProduct; iFound++; } } @@ -312,10 +314,12 @@ uint8_t CUSBCECAdapterDetection::FindAdapters(cec_adapter *deviceList, uint8_t i if (!strDevicePath || !strcmp(strPath.c_str(), strDevicePath)) { CStdString strComm(strPath); - if (FindComPort(strComm) && (iFound == 0 || strcmp(deviceList[iFound-1].comm, strComm.c_str()))) + if (FindComPort(strComm) && (iFound == 0 || strcmp(deviceList[iFound-1].strComName, strComm.c_str()))) { - snprintf(deviceList[iFound].path, sizeof(deviceList[iFound].path), "%s", strPath.c_str()); - snprintf(deviceList[iFound].comm, sizeof(deviceList[iFound].path), "%s", strComm.c_str()); + snprintf(deviceList[iFound].strComPath, sizeof(deviceList[iFound].strComPath), "%s", strPath.c_str()); + snprintf(deviceList[iFound].strComName, sizeof(deviceList[iFound].strComName), "%s", strComm.c_str()); + deviceList[iFound].iVendorId = iVendor; + deviceList[iFound].iProductId = iProduct; iFound++; } } @@ -408,15 +412,19 @@ uint8_t CUSBCECAdapterDetection::FindAdapters(cec_adapter *deviceList, uint8_t i // the 1002 pid indicates a composite device, that needs special treatment char strId[512]; CM_Get_Device_ID(devInfoData.DevInst, strId, 512, 0); - if (FindComPortForComposite(strId, deviceList[iFound].comm, sizeof(deviceList[iFound].comm))) + if (FindComPortForComposite(strId, deviceList[iFound].strComName, sizeof(deviceList[iFound].strComName))) { - snprintf(deviceList[iFound].path, sizeof(deviceList[iFound].path), "%s", devicedetailData->DevicePath); + snprintf(deviceList[iFound].strComPath, sizeof(deviceList[iFound].strComPath), "%s", devicedetailData->DevicePath); + deviceList[iFound].iVendorId = iVendor; + deviceList[iFound].iProductId = iProduct; iFound++; } } - else if (GetComPortFromHandle(hDevHandle, &devInfoData, deviceList[iFound].comm, sizeof(deviceList[iFound].comm))) + else if (GetComPortFromHandle(hDevHandle, &devInfoData, deviceList[iFound].strComName, sizeof(deviceList[iFound].strComName))) { - snprintf(deviceList[iFound].path, sizeof(deviceList[iFound].path), "%s", devicedetailData->DevicePath); + snprintf(deviceList[iFound].strComPath, sizeof(deviceList[iFound].strComPath), "%s", devicedetailData->DevicePath); + deviceList[iFound].iVendorId = iVendor; + deviceList[iFound].iProductId = iProduct; iFound++; } } @@ -431,8 +439,10 @@ uint8_t CUSBCECAdapterDetection::FindAdapters(cec_adapter *deviceList, uint8_t i continue; if (!access(devicePath, 0)) { - snprintf(deviceList[iFound].path, sizeof(deviceList[iFound].path), "%s", devicePath); - snprintf(deviceList[iFound].comm, sizeof(deviceList[iFound].path), "%s", devicePath); + snprintf(deviceList[iFound].strComPath, sizeof(deviceList[iFound].strComPath), "%s", devicePath); + snprintf(deviceList[iFound].strComName, sizeof(deviceList[iFound].strComName), "%s", devicePath); + deviceList[iFound].iVendorId = CEC_VID; + deviceList[iFound].iProductId = CEC_VID; iFound++; } } diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.h b/src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.h index 37478b9..5640881 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.h +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterDetection.h @@ -40,7 +40,7 @@ namespace CEC class CUSBCECAdapterDetection { public: - static uint8_t FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL); + static uint8_t FindAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL); static bool CanAutodetect(void); }; }; diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index c608292..df565b5 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -197,45 +197,41 @@ int CecAlert(void *UNUSED(cbParam), const libcec_alert type, const libcec_parame void ListDevices(ICECAdapter *parser) { - cec_adapter *devices = new cec_adapter[10]; - int8_t iDevicesFound = parser->FindAdapters(devices, 10, NULL); + cec_adapter_descriptor devices[10]; + int8_t iDevicesFound = parser->DetectAdapters(devices, 10, NULL); if (iDevicesFound <= 0) { PrintToStdOut("Found devices: NONE"); } else { - CStdString strDeviceInfo; - strDeviceInfo.Format("Found devices: %d\n\n", iDevicesFound); + PrintToStdOut("Found devices: %d\n", iDevicesFound); for (int8_t iDevicePtr = 0; iDevicePtr < iDevicesFound; iDevicePtr++) { - strDeviceInfo.AppendFormat("device: %d\ncom port: %s\n", iDevicePtr + 1, devices[iDevicePtr].comm); - libcec_configuration config; - config.Clear(); + PrintToStdOut("device: %d", iDevicePtr + 1); + PrintToStdOut("com port: %s", devices[iDevicePtr].strComName); + PrintToStdOut("vendor id: %04x", devices[iDevicePtr].iVendorId); + PrintToStdOut("product id: %04x", devices[iDevicePtr].iProductId); + PrintToStdOut("firmware version: %d", devices[iDevicePtr].iFirmwareVersion); - if (!parser->GetDeviceInformation(devices[iDevicePtr].comm, &config)) - PrintToStdOut("WARNING: unable to open the device on port %s", devices[iDevicePtr].comm); - else + if (devices[iDevicePtr].iFirmwareBuildDate != CEC_FW_BUILD_UNKNOWN) { - strDeviceInfo.AppendFormat("firmware version: %d\n", config.iFirmwareVersion); - - if (config.iFirmwareBuildDate != CEC_FW_BUILD_UNKNOWN) - { - time_t buildTime = (time_t)config.iFirmwareBuildDate; - strDeviceInfo.AppendFormat("firmware build date: %s", asctime(gmtime(&buildTime))); - strDeviceInfo = strDeviceInfo.Left(strDeviceInfo.length() > 1 ? (unsigned)(strDeviceInfo.length() - 1) : 0); // strip \n added by asctime - strDeviceInfo.append(" +0000\n"); - } + time_t buildTime = (time_t)devices[iDevicePtr].iFirmwareBuildDate; + CStdString strDeviceInfo; + strDeviceInfo.AppendFormat("firmware build date: %s", asctime(gmtime(&buildTime))); + strDeviceInfo = strDeviceInfo.Left(strDeviceInfo.length() > 1 ? (unsigned)(strDeviceInfo.length() - 1) : 0); // strip \n added by asctime + strDeviceInfo.append(" +0000"); + PrintToStdOut(strDeviceInfo.c_str()); + } - if (config.adapterType != ADAPTERTYPE_UNKNOWN) - { - strDeviceInfo.AppendFormat("type: %s\n", parser->ToString(config.adapterType)); - } + if (devices[iDevicePtr].adapterType != ADAPTERTYPE_UNKNOWN) + { + PrintToStdOut("type: %s", parser->ToString(devices[iDevicePtr].adapterType)); } - strDeviceInfo.append("\n"); + + PrintToStdOut(""); } - PrintToStdOut(strDeviceInfo.c_str()); } }