Skip to content

Commit

Permalink
Merge pull request #1 from NikolasK-source/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
NikolasK-source authored Aug 2, 2022
2 parents 947a0e2 + 7200007 commit b8ba536
Show file tree
Hide file tree
Showing 10 changed files with 619 additions and 30 deletions.
2 changes: 1 addition & 1 deletion 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 1.0.2)
project(Modbus_TCP_client_shm LANGUAGES CXX VERSION 1.0.3)

# settings
set(Target "Modbus_TCP_client_shm") # Executable name (without file extension!)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Nikolas Koesling
Copyright (c) 2021-2022 Nikolas Koesling

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
target_sources(${Target} PRIVATE main.cpp)
target_sources(${Target} PRIVATE modbus_shm.cpp)
target_sources(${Target} PRIVATE Modbus_TCP_Slave.cpp)
target_sources(${Target} PRIVATE license.cpp)


# ---------------------------------------- header files (*.jpp, *.h, ...) ----------------------------------------------
# ======================================================================================================================
target_sources(${Target} PRIVATE modbus_shm.hpp)
target_sources(${Target} PRIVATE Modbus_TCP_Slave.hpp)
target_sources(${Target} PRIVATE license.hpp)



Expand Down
5 changes: 5 additions & 0 deletions src/Modbus_TCP_Slave.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright (C) 2021-2022 Nikolas Koesling <[email protected]>.
* This program is free software. You can redistribute it and/or modify it under the terms of the MIT License.
*/

#include "Modbus_TCP_Slave.hpp"

#include <stdexcept>
Expand Down
9 changes: 7 additions & 2 deletions src/Modbus_TCP_Slave.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright (C) 2021-2022 Nikolas Koesling <[email protected]>.
* This program is free software. You can redistribute it and/or modify it under the terms of the MIT License.
*/

#pragma once

#include <modbus/modbus.h>
Expand All @@ -9,7 +14,7 @@ namespace TCP {
//! Modbus TCP slave
class Slave {
private:
modbus_t * modbus; //!< modbus object (see libmodbus library)
modbus_t *modbus; //!< modbus object (see libmodbus library)
modbus_mapping_t *mapping; //!< modbus data object (see libmodbus library)
bool delete_mapping; //!< indicates whether the mapping object was created by this instance
int socket = -1; //!< socket of the modbus connection
Expand All @@ -23,7 +28,7 @@ class Slave {
*/
explicit Slave(const std::string &ip = "0.0.0.0",
short unsigned int port = 502,
modbus_mapping_t * mapping = nullptr);
modbus_mapping_t *mapping = nullptr);

/*! \brief destroy the modbus slave
*
Expand Down
563 changes: 563 additions & 0 deletions src/license.cpp

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/license.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (C) 2022 Nikolas Koesling <[email protected]>.
* This program is free software. You can redistribute it and/or modify it under the terms of the MIT License.
*/

#pragma once

#include <ostream>

/**
* \brief print licences
* @param o output stream used to print licenses
*/
void print_licenses(std::ostream &o);
39 changes: 15 additions & 24 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright (C) 2021-2022 Nikolas Koesling <[email protected]>.
* This program is free software. You can redistribute it and/or modify it under the terms of the MIT License.
*/

#include <csignal>
#include <cxxopts.hpp>
#include <filesystem>
Expand All @@ -7,6 +12,7 @@
#include <unistd.h>

#include "Modbus_TCP_Slave.hpp"
#include "license.hpp"
#include "modbus_shm.hpp"

//! terminate flag
Expand Down Expand Up @@ -83,7 +89,9 @@ int main(int argc, char **argv) {
("h,help",
"print usage")
("version",
"print version information");
"print version information")
("license",
"show licences");
// clang-format on

// parse arguments
Expand Down Expand Up @@ -111,29 +119,6 @@ int main(int argc, char **argv) {
std::cout << "This application uses the following libraries:" << std::endl;
std::cout << " - cxxopts by jarro2783 (https://github.com/jarro2783/cxxopts)" << std::endl;
std::cout << " - libmodbus by Stéphane Raimbault (https://github.com/stephane/libmodbus)" << std::endl;
std::cout << std::endl;
std::cout << std::endl;
std::cout << "MIT License:" << std::endl;
std::cout << std::endl;
std::cout << "Copyright (c) 2021 Nikolas Koesling" << std::endl;
std::cout << std::endl;
std::cout << "Permission is hereby granted, free of charge, to any person obtaining a copy" << std::endl;
std::cout << "of this software and associated documentation files (the \"Software\"), to deal" << std::endl;
std::cout << "in the Software without restriction, including without limitation the rights" << std::endl;
std::cout << "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell" << std::endl;
std::cout << "copies of the Software, and to permit persons to whom the Software is" << std::endl;
std::cout << "furnished to do so, subject to the following conditions:" << std::endl;
std::cout << std::endl;
std::cout << "The above copyright notice and this permission notice shall be included in all" << std::endl;
std::cout << "copies or substantial portions of the Software." << std::endl;
std::cout << std::endl;
std::cout << "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR" << std::endl;
std::cout << "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY," << std::endl;
std::cout << "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE" << std::endl;
std::cout << "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER" << std::endl;
std::cout << "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM," << std::endl;
std::cout << "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE" << std::endl;
std::cout << "SOFTWARE." << std::endl;
exit(EX_OK);
}

Expand All @@ -143,6 +128,12 @@ int main(int argc, char **argv) {
exit(EX_OK);
}

// print licenses
if (args.count("license")) {
print_licenses(std::cout);
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
6 changes: 5 additions & 1 deletion src/modbus_shm.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/*
* Copyright (C) 2021-2022 Nikolas Koesling <[email protected]>.
* This program is free software. You can redistribute it and/or modify it under the terms of the MIT License.
*/

#include "modbus_shm.hpp"

#include <fcntl.h>
#include <iostream>
#include <stdexcept>
#include <sys/mman.h>
#include <system_error>
Expand Down
7 changes: 6 additions & 1 deletion src/modbus_shm.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright (C) 2021-2022 Nikolas Koesling <[email protected]>.
* This program is free software. You can redistribute it and/or modify it under the terms of the MIT License.
*/

#pragma once

#include "modbus/modbus.h"
Expand All @@ -21,7 +26,7 @@ class Shm_Mapping {
std::string name = std::string(); //!< name of the object
int fd = -1; //!< file descriptor
std::size_t size; //!< size in bytes
void * addr = nullptr; //!< mapped address
void *addr = nullptr; //!< mapped address
};

//! modbus lib storage object
Expand Down

0 comments on commit b8ba536

Please sign in to comment.