Skip to content

Commit 8fe1d35

Browse files
version 0.1.0
1 parent 8110ea0 commit 8fe1d35

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.13.4 FATAL_ERROR)
44
# ======================================================================================================================
55

66
# project
7-
project(Modbus_RTU_client_shm LANGUAGES CXX VERSION 0.0.1)
7+
project(Modbus_RTU_client_shm LANGUAGES CXX VERSION 0.1.0)
88

99
# settings
1010
set(Target "Modbus_RTU_client_shm") # Executable name (without file extension!)
@@ -24,8 +24,6 @@ option(OPTIMIZE_FOR_ARCHITECTURE "enable optimizations for specified architectur
2424
option(LTO_ENABLED "enable interprocedural and link time optimizations" ON)
2525
option(COMPILER_EXTENSIONS "enable compiler specific C++ extensions" OFF)
2626

27-
28-
2927
# ======================================================================================================================
3028
# ======================================================================================================================
3129

@@ -55,6 +53,10 @@ set_target_properties(${Target} PROPERTIES
5553
CXX_EXTENSIONS ${COMPILER_EXTENSIONS}
5654
)
5755

56+
# project version and name
57+
target_compile_definitions(${Target} PUBLIC "PROJECT_VERSION=\"${CMAKE_PROJECT_VERSION}\"")
58+
target_compile_definitions(${Target} PUBLIC "PROJECT_NAME=\"${CMAKE_PROJECT_NAME}\"")
59+
5860
# options that are valid for gcc and clang
5961
function(commonopts)
6062
# more debugging information

src/Modbus_RTU_Slave.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Slave::Slave(const std::string &device,
1616
int baud,
1717
bool rs232,
1818
bool rs485,
19-
modbus_mapping_t * mapping) {
19+
modbus_mapping_t *mapping) {
2020
// create modbus object
2121
modbus = modbus_new_rtu(device.c_str(), baud, parity, data_bits, stop_bits);
2222
if (modbus == nullptr) {

src/Modbus_RTU_Slave.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace RTU {
99
//! Modbus RTU slave
1010
class Slave {
1111
private:
12-
modbus_t * modbus; //!< modbus object (see libmodbus library)
12+
modbus_t *modbus; //!< modbus object (see libmodbus library)
1313
modbus_mapping_t *mapping; //!< modbus data object (see libmodbus library)
1414
bool delete_mapping; //!< indicates whether the mapping object was created by this instance
1515

@@ -34,7 +34,7 @@ class Slave {
3434
int baud,
3535
bool rs232,
3636
bool rs485,
37-
modbus_mapping_t * mapping = nullptr);
37+
modbus_mapping_t *mapping = nullptr);
3838

3939
/*! \brief destroy the modbus slave
4040
*

src/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ int main(int argc, char **argv) {
7272
"ai-registers", "number of analog input registers", cxxopts::value<std::size_t>()->default_value("65536"));
7373
options.add_options()("m,monitor", "output all incoming and outgoing packets to stdout");
7474
options.add_options()("h,help", "print usage");
75+
options.add_options()("version", "print version information");
7576
// clang-format on
7677

7778
// parse arguments
@@ -125,6 +126,12 @@ int main(int argc, char **argv) {
125126
exit(EX_OK);
126127
}
127128

129+
// print version
130+
if (args.count("version")) {
131+
std::cout << PROJECT_NAME << ' ' << PROJECT_VERSION << std::endl;
132+
exit(EX_OK);
133+
}
134+
128135
// check arguments
129136
if (args["do-registers"].as<std::size_t>() > 0x10000) {
130137
std::cerr << "to many do_registers (maximum: 65536)." << std::endl;

src/modbus_shm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Shm_Mapping::Shm_Mapping(std::size_t nb_bits,
4343
shm_data[AI].name = prefix + "AI";
4444

4545
// create and map shm objects
46-
for (std::size_t i = 0; i < reg_index_t::__SIZE__; ++i) {
46+
for (std::size_t i = 0; i < reg_index_t::REG_COUNT; ++i) {
4747
auto &shm = shm_data[i];
4848

4949
// create shm object
@@ -76,7 +76,7 @@ Shm_Mapping::Shm_Mapping(std::size_t nb_bits,
7676

7777
Shm_Mapping::~Shm_Mapping() {
7878
// unmap and delete shm objects
79-
for (std::size_t i = 0; i < reg_index_t::__SIZE__; ++i) {
79+
for (std::size_t i = 0; i < reg_index_t::REG_COUNT; ++i) {
8080
auto &shm = shm_data[i];
8181
if (shm.addr) {
8282
if (munmap(shm.addr, shm.size)) { perror(("Failed to unmap shared memory '" + shm.name + '\'').c_str()); }

src/modbus_shm.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ namespace shm {
1414
*/
1515
class Shm_Mapping {
1616
private:
17-
enum reg_index_t : std::size_t { DO, DI, AO, AI, __SIZE__ };
17+
enum reg_index_t : std::size_t { DO, DI, AO, AI, REG_COUNT };
1818

1919
//! data for a shared memory object
2020
struct shm_data_t {
2121
std::string name = std::string(); //!< name of the object
2222
int fd = -1; //!< file descriptor
2323
std::size_t size; //!< size in bytes
24-
void * addr = nullptr; //!< mapped address
24+
void *addr = nullptr; //!< mapped address
2525
};
2626

2727
//! modbus lib storage object
2828
modbus_mapping_t mapping {};
2929

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

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

0 commit comments

Comments
 (0)