diff --git a/CMakeLists.txt b/CMakeLists.txt index fa44c87..8dbaa4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.13.4 FATAL_ERROR) # ====================================================================================================================== # project -project(Modbus_TCP_client_shm LANGUAGES CXX VERSION 0.0.1) +project(Modbus_TCP_client_shm LANGUAGES CXX VERSION 1.0.0) # settings set(Target "Modbus_TCP_client_shm") # Executable name (without file extension!) @@ -24,8 +24,6 @@ option(OPTIMIZE_FOR_ARCHITECTURE "enable optimizations for specified architectur option(LTO_ENABLED "enable interprocedural and link time optimizations" ON) option(COMPILER_EXTENSIONS "enable compiler specific C++ extensions" OFF) - - # ====================================================================================================================== # ====================================================================================================================== @@ -55,6 +53,10 @@ set_target_properties(${Target} PROPERTIES CXX_EXTENSIONS ${COMPILER_EXTENSIONS} ) +# project version and name +target_compile_definitions(${Target} PUBLIC "PROJECT_VERSION=\"${CMAKE_PROJECT_VERSION}\"") +target_compile_definitions(${Target} PUBLIC "PROJECT_NAME=\"${CMAKE_PROJECT_NAME}\"") + # options that are valid for gcc and clang function(commonopts) # more debugging information diff --git a/src/main.cpp b/src/main.cpp index 84aba3a..5b02b03 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -81,7 +81,9 @@ int main(int argc, char **argv) { ("r,reconnect", "do not terminate if Master disconnects.") ("h,help", - "print usage"); + "print usage") + ("version", + "print version information"); // clang-format on // parse arguments @@ -135,6 +137,12 @@ int main(int argc, char **argv) { exit(EX_OK); } + // print usage + if (args.count("version")) { + std::cout << PROJECT_NAME << ' ' << PROJECT_VERSION << std::endl; + exit(EX_OK); + } + // check arguments if (args["do-registers"].as() > 0x10000) { std::cerr << "to many do_registers (maximum: 65536)." << std::endl; diff --git a/src/modbus_shm.cpp b/src/modbus_shm.cpp index 291c704..53df5b0 100644 --- a/src/modbus_shm.cpp +++ b/src/modbus_shm.cpp @@ -43,7 +43,7 @@ Shm_Mapping::Shm_Mapping(std::size_t nb_bits, shm_data[AI].name = prefix + "AI"; // create and map shm objects - for (std::size_t i = 0; i < reg_index_t::__SIZE__; ++i) { + for (std::size_t i = 0; i < reg_index_t::REG_COUNT; ++i) { auto &shm = shm_data[i]; // create shm object @@ -76,7 +76,7 @@ Shm_Mapping::Shm_Mapping(std::size_t nb_bits, Shm_Mapping::~Shm_Mapping() { // unmap and delete shm objects - for (std::size_t i = 0; i < reg_index_t::__SIZE__; ++i) { + for (std::size_t i = 0; i < reg_index_t::REG_COUNT; ++i) { auto &shm = shm_data[i]; if (shm.addr) { if (munmap(shm.addr, shm.size)) { perror(("Failed to unmap shared memory '" + shm.name + '\'').c_str()); } diff --git a/src/modbus_shm.hpp b/src/modbus_shm.hpp index 5c49fc4..4e2e3d7 100644 --- a/src/modbus_shm.hpp +++ b/src/modbus_shm.hpp @@ -14,7 +14,7 @@ namespace shm { */ class Shm_Mapping { private: - enum reg_index_t : std::size_t { DO, DI, AO, AI, __SIZE__ }; + enum reg_index_t : std::size_t { DO, DI, AO, AI, REG_COUNT }; //! data for a shared memory object struct shm_data_t { @@ -28,7 +28,7 @@ class Shm_Mapping { modbus_mapping_t mapping {}; //! info for all shared memory objects - std::array shm_data; + std::array shm_data; public: /*! \brief creates a new modbus_mapping_t. Like modbus_mapping_new(), but creates shared memory objects to store its