diff --git a/api/icsneo/icsneo.cpp b/api/icsneo/icsneo.cpp index dc911d3..021ab52 100644 --- a/api/icsneo/icsneo.cpp +++ b/api/icsneo/icsneo.cpp @@ -53,6 +53,21 @@ ICSNEO_API icsneo_error_t icsneo_error_code(icsneo_error_t error_code, const cha return icsneo_error_success; } +ICSNEO_API icsneo_error_t icsneo_device_type_from_type(icsneo_devicetype_t device_type, const char* value, uint32_t* value_length) { + if (!value || !value_length) { + return icsneo_error_invalid_parameters; + } + + auto device_type_str = DeviceType::getGenericProductName(device_type); + // Find the minimum length of the device type string and set value_length + auto min_length = std::minmax(static_cast(device_type_str.length()), *value_length).first; + *value_length = min_length; + // Copy the string into value + strncpy(const_cast(value), device_type_str.c_str(), min_length); + + return icsneo_error_success; +} + ICSNEO_API icsneo_error_t icsneo_find(icsneo_device_t** devices, uint32_t* devices_count, void* reserved) { if (!devices || !devices_count) { return icsneo_error_invalid_parameters; diff --git a/include/icsneo/icsneo.h b/include/icsneo/icsneo.h index dbeae3a..7bfd94b 100644 --- a/include/icsneo/icsneo.h +++ b/include/icsneo/icsneo.h @@ -75,6 +75,16 @@ typedef uint32_t icsneo_error_t; */ ICSNEO_API icsneo_error_t icsneo_error_code(icsneo_error_t error_code, const char* value, uint32_t* value_length); +/** @brief Get the device type string for a icsneo_devicetype_t. + * + * @param[in] icsneo_devicetype_t device_type The device type to get the description of. + * @param[out] const char* value Pointer to a buffer to copy the description into. Null terminated. + * @param[in,out] uint32_t* value_length Size of the value buffer. Modified with the length of the description. + * + * @return icsneo_error_t icsneo_error_success if successful, icsneo_error_invalid_parameters otherwise. + */ +ICSNEO_API icsneo_error_t icsneo_device_type_from_type(icsneo_devicetype_t device_type, const char* value, uint32_t* value_length); + /** @brief Find all hardware attached to the system. * * @param[out] icsneo_device_t array of devices to be filled with found devices.