From 8a4e33c8df11cac1da983aece8e673febb91cc60 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Tue, 20 Nov 2018 10:41:42 -0500 Subject: [PATCH] Allow version and supported devices to be printed at runtime --- CMakeLists.txt | 1 + api/icsneocpp/icsneocpp.cpp | 4 ++++ api/icsneocpp/version.cpp | 11 +++++++++++ device/devicefinder.cpp | 5 +++++ include/icsneo/api/version.h | 14 +++++++++++++- include/icsneo/device/devicetype.h | 2 +- include/icsneo/icsneocpp.h | 1 + 7 files changed, 36 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b49a158..13b3e9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,7 @@ execute_process( COMMAND git describe --abbrev=6 --dirty --always --tags WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE GIT_DESCRIBE + ERROR_VARIABLE GIT_DESCRIBE OUTPUT_STRIP_TRAILING_WHITESPACE ) configure_file(api/icsneocpp/buildinfo.h.template ${CMAKE_CURRENT_BINARY_DIR}/generated/buildinfo.h) diff --git a/api/icsneocpp/icsneocpp.cpp b/api/icsneocpp/icsneocpp.cpp index dfa2d00..139f5c8 100644 --- a/api/icsneocpp/icsneocpp.cpp +++ b/api/icsneocpp/icsneocpp.cpp @@ -7,6 +7,10 @@ std::vector> icsneo::FindAllDevices() { return DeviceFinder::FindAll(); } +std::vector icsneo::GetSupportedDevices() { + return DeviceFinder::GetSupportedDevices(); +} + size_t icsneo::ErrorCount(ErrorFilter filter) { return ErrorManager::GetInstance().count(filter); } diff --git a/api/icsneocpp/version.cpp b/api/icsneocpp/version.cpp index d7f1fa4..e896b92 100644 --- a/api/icsneocpp/version.cpp +++ b/api/icsneocpp/version.cpp @@ -12,4 +12,15 @@ neoversion_t icsneo::GetVersion(void) { version.buildBranch = GIT_BRANCH; version.buildTag = GIT_DESCRIBE; return version; +} + +std::ostream& operator<<(std::ostream& os, const neoversion_t& version) { + os << 'v' << version.major << '.' << version.minor << '.' << version.patch; + if(version.metadata[0] != '\0') + os << '+' << version.metadata; + if(std::string(version.buildBranch) != "master") + os << ' ' << version.buildBranch << " @"; + if(version.buildTag[0] != 'v') + os << ' ' << version.buildTag; + return os; } \ No newline at end of file diff --git a/device/devicefinder.cpp b/device/devicefinder.cpp index 58ea684..3807809 100644 --- a/device/devicefinder.cpp +++ b/device/devicefinder.cpp @@ -3,6 +3,7 @@ using namespace icsneo; +static bool supportedDevicesCached = false; static std::vector supportedDevices = { #ifdef __NEOOBD2PRO_H_ @@ -156,5 +157,9 @@ std::vector> DeviceFinder::FindAll() { } const std::vector& DeviceFinder::GetSupportedDevices() { + if(!supportedDevicesCached) { + supportedDevices.erase(std::unique(supportedDevices.begin(), supportedDevices.end()), supportedDevices.end()); + supportedDevicesCached = true; + } return supportedDevices; } \ No newline at end of file diff --git a/include/icsneo/api/version.h b/include/icsneo/api/version.h index 877749f..1bb0cc2 100644 --- a/include/icsneo/api/version.h +++ b/include/icsneo/api/version.h @@ -3,7 +3,14 @@ #include -typedef struct { +#ifdef __cplusplus +#include +#define NEOVERSION_DEFINE_BEGIN struct neoversion_t { +#else +#define NEOVERSION_DEFINE_BEGIN typedef struct { +#endif + +NEOVERSION_DEFINE_BEGIN uint16_t major; uint16_t minor; uint16_t patch; @@ -11,7 +18,12 @@ typedef struct { const char* buildBranch; const char* buildTag; char reserved[32]; +#ifdef __cplusplus + friend std::ostream& operator<<(std::ostream& os, const neoversion_t& version); +}; +#else } neoversion_t; +#endif #ifdef __cplusplus namespace icsneo { diff --git a/include/icsneo/device/devicetype.h b/include/icsneo/device/devicetype.h index 5a90c1e..dd1ff36 100644 --- a/include/icsneo/device/devicetype.h +++ b/include/icsneo/device/devicetype.h @@ -135,7 +135,7 @@ public: case VividCAN: return "VividCAN"; case OBD2_SIM: - return "neoOBD2-SIM"; + return "neoOBD2 SIM"; case DONT_REUSE0: case DONT_REUSE1: case DONT_REUSE2: diff --git a/include/icsneo/icsneocpp.h b/include/icsneo/icsneocpp.h index 0003a39..75fc432 100644 --- a/include/icsneo/icsneocpp.h +++ b/include/icsneo/icsneocpp.h @@ -11,6 +11,7 @@ namespace icsneo { std::vector> FindAllDevices(); +std::vector GetSupportedDevices(); size_t ErrorCount(ErrorFilter filter = ErrorFilter()); std::vector GetErrors(ErrorFilter filter, size_t max = 0);