Skip to content

Commit

Permalink
version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolasK-source committed Aug 1, 2022
1 parent a06ecb6 commit d0f2959
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
Expand All @@ -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)



# ======================================================================================================================
# ======================================================================================================================

Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<std::size_t>() > 0x10000) {
std::cerr << "to many do_registers (maximum: 65536)." << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions src/modbus_shm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()); }
Expand Down
4 changes: 2 additions & 2 deletions src/modbus_shm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -28,7 +28,7 @@ class Shm_Mapping {
modbus_mapping_t mapping {};

//! info for all shared memory objects
std::array<shm_data_t, reg_index_t::__SIZE__> shm_data;
std::array<shm_data_t, reg_index_t::REG_COUNT> shm_data;

public:
/*! \brief creates a new modbus_mapping_t. Like modbus_mapping_new(), but creates shared memory objects to store its
Expand Down

0 comments on commit d0f2959

Please sign in to comment.