From 8ef2260fbe697004c2ac175066fc95d532a19ae7 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Tue, 20 Nov 2018 09:42:25 -0500 Subject: [PATCH] Add the ability to enumerate supported devices --- api/icsneoc/icsneoc.cpp | 50 ++++++++++++++++++ device/devicefinder.cpp | 76 ++++++++++++++++++++++++++++ include/icsneo/device/devicefinder.h | 2 + include/icsneo/device/devicetype.h | 1 + include/icsneo/icsneoc.h | 43 ++++++++++++++++ 5 files changed, 172 insertions(+) diff --git a/api/icsneoc/icsneoc.cpp b/api/icsneoc/icsneoc.cpp index 8f9c7ab..3fc5cce 100644 --- a/api/icsneoc/icsneoc.cpp +++ b/api/icsneoc/icsneoc.cpp @@ -8,6 +8,7 @@ #include "icsneo/icsneocpp.h" #include "icsneo/platform/dynamiclib.h" #include "icsneo/api/errormanager.h" +#include "icsneo/device/devicefinder.h" #include #include #include @@ -269,6 +270,29 @@ bool icsneo_getProductName(const neodevice_t* device, char* str, size_t* maxLeng return true; } +bool icsneo_getProductNameForType(devicetype_t type, char* str, size_t* maxLength) { + // TAG String copy function + if(maxLength == nullptr) { + ErrorManager::GetInstance().add(APIError::RequiredParameterNull); + return false; + } + + std::string output = DeviceType(type).toString(); + + if(str == nullptr) { + *maxLength = output.length(); + return false; + } + + *maxLength = output.copy(str, *maxLength); + str[*maxLength] = '\0'; + + if(output.length() > *maxLength) + ErrorManager::GetInstance().add(APIError::OutputTruncated); + + return true; +} + bool icsneo_settingsRefresh(const neodevice_t* device) { if(!icsneo_isValidNeoDevice(device)) { ErrorManager::GetInstance().add(APIError::InvalidNeoDevice); @@ -459,4 +483,30 @@ void icsneo_setErrorLimit(size_t newLimit) { size_t icsneo_getErrorLimit(void) { return icsneo::GetErrorLimit(); +} + +bool icsneo_getSupportedDevices(devicetype_t* devices, size_t* count) { + if(count == nullptr) { + ErrorManager::GetInstance().add(APIError::RequiredParameterNull); + return false; + } + + auto supported = DeviceFinder::GetSupportedDevices(); + auto len = supported.size(); + + if(devices == nullptr) { + *count = len; + return false; + } + + if(*count < len) { + len = *count; + ErrorManager::GetInstance().add(APIError::OutputTruncated); + } + + for(size_t i = 0; i < len; i++) + devices[i] = supported[i]; + *count = len; + + return true; } \ No newline at end of file diff --git a/device/devicefinder.cpp b/device/devicefinder.cpp index a15ee74..58ea684 100644 --- a/device/devicefinder.cpp +++ b/device/devicefinder.cpp @@ -3,6 +3,78 @@ using namespace icsneo; +static std::vector supportedDevices = { + + #ifdef __NEOOBD2PRO_H_ + NeoOBD2PRO::DEVICE_TYPE, + #endif + + #ifdef __NEOOBD2SIM_H_ + NeoOBD2SIM::DEVICE_TYPE, + #endif + + #ifdef __NEOVIFIRE_H_ + NeoVIFIRE::DEVICE_TYPE, + #endif + + #ifdef __NEOVIFIRE2ETH_H_ + NeoVIFIRE2ETH::DEVICE_TYPE, + #endif + + #ifdef __NEOVIFIRE2USB_H_ + NeoVIFIRE2USB::DEVICE_TYPE, + #endif + + #ifdef __NEOVIION_H_ + NeoVIION::DEVICE_TYPE, + #endif + + #ifdef __NEOVIPLASMA_H_ + NeoVIPLASMA::DEVICE_TYPE, + #endif + + #ifdef __RADGALAXY_H_ + RADGalaxy::DEVICE_TYPE, + #endif + + #ifdef __RADSTAR2ETH_H_ + RADStar2ETH::DEVICE_TYPE, + #endif + + #ifdef __RADSTAR2USB_H_ + RADStar2USB::DEVICE_TYPE, + #endif + + #ifdef __RADSUPERMOON_H_ + RADSupermoon::DEVICE_TYPE, + #endif + + #ifdef __VALUECAN3_H_ + ValueCAN3::DEVICE_TYPE, + #endif + + #ifdef __VALUECAN4_1_H_ + ValueCAN4_1::DEVICE_TYPE, + #endif + + #ifdef __VALUECAN4_2_H_ + ValueCAN4_2::DEVICE_TYPE, + #endif + + #ifdef __VALUECAN4_2EL_H_ + ValueCAN4_2EL::DEVICE_TYPE, + #endif + + #ifdef __VALUECAN4_4_H_ + ValueCAN4_4::DEVICE_TYPE, + #endif + + #ifdef __VIVIDCAN_H_ + VividCAN::DEVICE_TYPE, + #endif + +}; + std::vector> DeviceFinder::FindAll() { std::vector> foundDevices; std::vector>> findResults; @@ -81,4 +153,8 @@ std::vector> DeviceFinder::FindAll() { } return foundDevices; +} + +const std::vector& DeviceFinder::GetSupportedDevices() { + return supportedDevices; } \ No newline at end of file diff --git a/include/icsneo/device/devicefinder.h b/include/icsneo/device/devicefinder.h index 56d1194..6bd37c2 100644 --- a/include/icsneo/device/devicefinder.h +++ b/include/icsneo/device/devicefinder.h @@ -2,6 +2,7 @@ #define __DEVICEFINDER_H_ #include "icsneo/device/device.h" +#include "icsneo/device/devicetype.h" #include #include @@ -10,6 +11,7 @@ namespace icsneo { class DeviceFinder { public: static std::vector> FindAll(); + static const std::vector& GetSupportedDevices(); }; } diff --git a/include/icsneo/device/devicetype.h b/include/icsneo/device/devicetype.h index c44b0e7..5a90c1e 100644 --- a/include/icsneo/device/devicetype.h +++ b/include/icsneo/device/devicetype.h @@ -155,6 +155,7 @@ public: os << type.toString().c_str(); return os; } + operator devicetype_t() const { return getDeviceType(); } private: DeviceType::Enum value; diff --git a/include/icsneo/icsneoc.h b/include/icsneo/icsneoc.h index 2cccc5c..0e64434 100644 --- a/include/icsneo/icsneoc.h +++ b/include/icsneo/icsneoc.h @@ -280,6 +280,30 @@ extern bool DLLExport icsneo_setPollingMessageLimit(const neodevice_t* device, s */ extern bool DLLExport icsneo_getProductName(const neodevice_t* device, char* str, size_t* maxLength); +/** + * \brief Get the friendly product name for a specified devicetype. + * \param[in] type A neodevice_t structure specifying the device to operate on. + * \param[out] str A pointer to a buffer where the string will be written. NULL can be passed, which will write a character count to maxLength. + * \param[inout] maxLength A pointer to a size_t which, prior to the call, + * holds the maximum number of characters to be written (so str must be of size maxLength + 1 to account for the NULL terminator), + * and after the call holds the number of characters written. + * \returns True if str was written to + * + * In the case of a neoVI FIRE 2, this function will write a string "neoVI FIRE 2" with a NULL terminator into str. + * + * The constant ICSNEO_DEVICETYPE_LONGEST_NAME is defined for the client application to create static buffers of the correct length. + * + * See also icsneo_describeDevice(). + * + * A query for length (`str == NULL`) will return false. + * icsneo_getLastError() should be checked to verify that the neodevice_t provided was valid. + * + * If the size provided is not large enough, the output will be truncated. + * An icsneo::APIError::OutputTruncatedError will be available in icsneo_getLastError() in this case. + * True will still be returned. + */ +extern bool DLLExport icsneo_getProductNameForType(devicetype_t type, char* str, size_t* maxLength); + /** * \brief Trigger a refresh of the settings structure for a specified device. * \param[in] device A pointer to the neodevice_t structure specifying the device to operate on. @@ -514,6 +538,25 @@ extern void DLLExport icsneo_setErrorLimit(size_t newLimit); */ extern size_t DLLExport icsneo_getErrorLimit(void); +/** + * \brief Get the devices supported by the current version of the API + * \param[out] devices A pointer to a buffer of devicetype_t structures which will be written to. + * NULL can be passed, which will write the current supported device count to count. + * \param[inout] count A pointer to a size_t which, prior to the call, + * holds the maximum number of devicetype_t structures to be written, + * and after the call holds the number of devicetype_t structures written. + * \returns True if devices was written to + * + * See icsneo_getProductNameForType() to get textual descriptions of each device. + * + * A query for length (`devices == NULL`) will return false. + * + * If the count provided is not large enough, the output will be truncated. + * An icsneo::APIError::OutputTruncatedError will be available in icsneo_getLastError() in this case. + * True will still be returned. + */ +extern bool DLLExport icsneo_getSupportedDevices(devicetype_t* devices, size_t* count); + #ifdef __cplusplus } // extern "C" #endif