Add the ability to enumerate supported devices
parent
f05f96822e
commit
8ef2260fbe
|
|
@ -8,6 +8,7 @@
|
|||
#include "icsneo/icsneocpp.h"
|
||||
#include "icsneo/platform/dynamiclib.h"
|
||||
#include "icsneo/api/errormanager.h"
|
||||
#include "icsneo/device/devicefinder.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
|
@ -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);
|
||||
|
|
@ -460,3 +484,29 @@ 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;
|
||||
}
|
||||
|
|
@ -3,6 +3,78 @@
|
|||
|
||||
using namespace icsneo;
|
||||
|
||||
static std::vector<DeviceType> 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<std::shared_ptr<Device>> DeviceFinder::FindAll() {
|
||||
std::vector<std::shared_ptr<Device>> foundDevices;
|
||||
std::vector<std::vector<std::shared_ptr<Device>>> findResults;
|
||||
|
|
@ -82,3 +154,7 @@ std::vector<std::shared_ptr<Device>> DeviceFinder::FindAll() {
|
|||
|
||||
return foundDevices;
|
||||
}
|
||||
|
||||
const std::vector<DeviceType>& DeviceFinder::GetSupportedDevices() {
|
||||
return supportedDevices;
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
#define __DEVICEFINDER_H_
|
||||
|
||||
#include "icsneo/device/device.h"
|
||||
#include "icsneo/device/devicetype.h"
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
|
|
@ -10,6 +11,7 @@ namespace icsneo {
|
|||
class DeviceFinder {
|
||||
public:
|
||||
static std::vector<std::shared_ptr<Device>> FindAll();
|
||||
static const std::vector<DeviceType>& GetSupportedDevices();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@ public:
|
|||
os << type.toString().c_str();
|
||||
return os;
|
||||
}
|
||||
operator devicetype_t() const { return getDeviceType(); }
|
||||
|
||||
private:
|
||||
DeviceType::Enum value;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue