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.
* @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;
+
};
};
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
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 */
config->iFirmwareBuildDate = m_communication->GetFirmwareBuildDate();
config->adapterType = m_communication->GetAdapterType();
+ Close();
+
return true;
}
{
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;
+}
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);
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;
+}
+
//@}
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);
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
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
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);
}
#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);
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++;
}
}
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++;
}
}
// 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++;
}
}
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++;
}
}
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);
};
};
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());
}
}