Skip to content

Commit e0fd3c0

Browse files
committed
feat: library version detection
This is intended to allow wrappers around the library to determine dynamically which features are supported. Unfortunately, since this was not available from the start, it does mean that they will have to check for the existence of this function to begin with.
1 parent d4a609b commit e0fd3c0

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ set_target_properties(absscpi PROPERTIES
9898

9999
target_compile_features(absscpi PUBLIC cxx_std_20)
100100

101+
target_compile_definitions(absscpi PRIVATE
102+
"ABSSCPI_VERSION=((${PROJECT_VERSION_MAJOR}* 10000)+(${PROJECT_VERSION_MINOR}*100)+(${PROJECT_VERSION_PATCH}))"
103+
)
104+
101105
if(MSVC)
102106
target_compile_options(absscpi PRIVATE /W3)
103107
else()

include/bci/abs/CInterface.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,18 @@ typedef struct AbsSerialDiscoveryResult {
189189
} AbsSerialDiscoveryResult;
190190
/** @} */
191191

192+
/**
193+
* @brief Get the version of the SCPI library as an unsigned base 10 integer.
194+
* For example, version 1.2.3 would return 10203.
195+
*
196+
* This is intended to be used to check for the existence of certain
197+
* functionality based on library version, particularly in wrappers (such as
198+
* Python).
199+
*
200+
* @return The library version.
201+
*/
202+
unsigned int AbsScpiClient_Version();
203+
192204
/**
193205
* @brief Get an error message to describe an error code returned by the driver.
194206
*

include/bci/abs/ScpiClient.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ namespace bci::abs {
5353
*/
5454
class ScpiClient {
5555
public:
56+
/**
57+
* @brief Get the library version as a decimal integer. For example, version
58+
* 1.3.2 would return 10302.
59+
*
60+
* @return Library version.
61+
*/
62+
static unsigned int Version() noexcept;
63+
5664
/// Default CTOR.
5765
ScpiClient() noexcept;
5866

src/CInterface.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ inline constexpr std::string_view CharsView(const char (&str)[kLen]) {
8787
return std::string_view(str, ::strnlen(str, kLen));
8888
}
8989

90+
unsigned int AbsScpiClient_Version() {
91+
return ABSSCPI_VERSION;
92+
}
93+
9094
const char* AbsScpiClient_ErrorMessage(int error) {
9195
return bci::abs::ErrorMessage(static_cast<bci::abs::ErrorCode>(error));
9296
}

src/ScpiClient.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ static constexpr unsigned int kWriteTimeoutMs = 10;
2222
using util::Err;
2323
using ec = ErrorCode;
2424

25+
unsigned int ScpiClient::Version() noexcept {
26+
return ABSSCPI_VERSION;
27+
}
28+
2529
ScpiClient::ScpiClient() noexcept : ScpiClient(nullptr) {}
2630

2731
ScpiClient::ScpiClient(std::shared_ptr<drivers::CommDriver> driver) noexcept

0 commit comments

Comments
 (0)