Skip to content

Commit 5aa8418

Browse files
Merge pull request #9 from NikolasK-source/main
Release v0.2.0
2 parents 28bc065 + 6a9739e commit 5aa8418

15 files changed

+547
-31
lines changed

.github/workflows/clang-format.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: clang-format Check
2+
on: [push, pull_request]
3+
jobs:
4+
formatting-check:
5+
name: Formatting Check
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v2
9+
- name: Run clang-format style check for C/C++/Protobuf programs.
10+
uses: jidicula/clang-format-action@v4.8.0
11+
with:
12+
clang-format-version: '14'
13+
check-path: 'src'
14+

.github/workflows/cmake.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: CMake
2+
3+
on:
4+
push:
5+
branches: [ "main", "development" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
11+
BUILD_TYPE: Release
12+
13+
jobs:
14+
build:
15+
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
16+
# You can convert this to a matrix build if you need cross-platform coverage.
17+
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- name: Init submodules
24+
run: git submodule init
25+
26+
- name: Update submodules
27+
run: git submodule update
28+
29+
- name: Configure CMake
30+
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
31+
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
32+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF
33+
34+
- name: Build
35+
# Build your program with the given configuration
36+
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
37+
38+
- name: Test
39+
working-directory: ${{github.workspace}}/build
40+
# Execute tests defined by the CMake configuration.
41+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
42+
run: ctest -C ${{env.BUILD_TYPE}}
43+

.github/workflows/codeql-analysis.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ "main", "development" ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ "main" ]
20+
schedule:
21+
- cron: '32 20 * * 0'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: [ 'cpp' ]
36+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
38+
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v3
42+
43+
# Initializes the CodeQL tools for scanning.
44+
- name: Initialize CodeQL
45+
uses: github/codeql-action/init@v2
46+
with:
47+
languages: ${{ matrix.language }}
48+
# If you wish to specify custom queries, you can do so here or in a config file.
49+
# By default, queries listed here will override any specified in a config file.
50+
# Prefix the list here with "+" to use these queries and those in the config file.
51+
52+
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
53+
# queries: security-extended,security-and-quality
54+
55+
56+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
57+
# If this step fails, then you should remove it and run the build manually (see below)
58+
# - name: Autobuild
59+
# uses: github/codeql-action/autobuild@v2
60+
61+
# ℹ️ Command-line programs to run using the OS shell.
62+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
63+
64+
# If the Autobuild fails above, remove it and uncomment the following three lines.
65+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
66+
67+
- run: |
68+
echo "Run, Build Application using cmake"
69+
git submodule init
70+
git submodule update
71+
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF
72+
cmake --build ${{github.workspace}}/build --config Release
73+
74+
- name: Perform CodeQL Analysis
75+
uses: github/codeql-action/analyze@v2

.github/workflows/flatpak_release.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
on:
2+
push:
3+
branches: [release]
4+
name: Flatpak_release
5+
jobs:
6+
flatpak:
7+
name: "Flatpak"
8+
runs-on: ubuntu-latest
9+
container:
10+
image: bilelmoussaoui/flatpak-github-actions:freedesktop-21.08
11+
options: --privileged
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: bilelmoussaoui/flatpak-github-actions/flatpak-builder@v4
15+
name: "Build"
16+
with:
17+
bundle: modbus-rtu-client-shm.flatpak
18+
manifest-path: network.koesling.modbus-rtu-client-shm.yml
19+
cache-key: flatpak-builder-${{ github.sha }}

.github/workflows/flatpak_test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
on:
2+
push:
3+
branches: [ "main", "development" ]
4+
pull_request:
5+
name: Flatpak_test
6+
jobs:
7+
flatpak:
8+
name: "Flatpak"
9+
runs-on: ubuntu-latest
10+
container:
11+
image: bilelmoussaoui/flatpak-github-actions:freedesktop-21.08
12+
options: --privileged
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Git config
17+
run: git config --global --add safe.directory /__w/modbus_rtu_client_shm/modbus_rtu_client_shm
18+
19+
- name: Init submodules
20+
run: git submodule init
21+
22+
- name: Update submodules
23+
run: git submodule update
24+
25+
- uses: bilelmoussaoui/flatpak-github-actions/flatpak-builder@v4
26+
name: "Build"
27+
with:
28+
bundle: test_modbus-tcp-client-shm.flatpak
29+
manifest-path: network.koesling.test-modbus-rtu-client-shm.yml
30+
cache-key: flatpak-builder-${{ github.sha }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,6 @@ modules.order
465465
Module.symvers
466466
Mkfile.old
467467
dkms.conf
468+
469+
!network.koesling.modbus-rtu-client-shm.yml
470+

CMakeLists.txt

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

66
# project
7-
project(Modbus_RTU_client_shm LANGUAGES CXX VERSION 0.1.3)
7+
project(Modbus_RTU_client_shm LANGUAGES CXX VERSION 0.2.0)
88

99
# settings
10-
set(Target "Modbus_RTU_client_shm") # Executable name (without file extension!)
10+
set(Target "modbus-rtu-client-shm") # Executable name (without file extension!)
1111
set(STANDARD 17) # C++ Standard
1212
set(ARCHITECTURE "native") # CPU architecture to optimize for (only relevant if OPTIMIZE_FOR_ARCHITECTURE is ON)
1313

@@ -41,6 +41,7 @@ endif()
4141

4242
# add executable
4343
add_executable(${Target})
44+
install(TARGETS ${Target})
4445

4546
# set source and libraries directory
4647
add_subdirectory("src")
@@ -53,9 +54,11 @@ set_target_properties(${Target} PROPERTIES
5354
CXX_EXTENSIONS ${COMPILER_EXTENSIONS}
5455
)
5556

56-
# project version and name
57+
# compiler definitions
5758
target_compile_definitions(${Target} PUBLIC "PROJECT_VERSION=\"${CMAKE_PROJECT_VERSION}\"")
5859
target_compile_definitions(${Target} PUBLIC "PROJECT_NAME=\"${CMAKE_PROJECT_NAME}\"")
60+
target_compile_definitions(${Target} PUBLIC "COMPILER_INFO=\"${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}\"")
61+
target_compile_definitions(${Target} PUBLIC "SYSTEM_INFO=\"${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION} ${CMAKE_HOST_SYSTEM_PROCESSOR}\"")
5962

6063
# options that are valid for gcc and clang
6164
function(commonopts)

docs/index.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,132 @@
22

33
This project is a simple command line based Modbus TCP client for POSIX compatible operating systems that stores the
44
content of its registers in shared memory.
5+
6+
## Basic operating principle
7+
8+
The client creates four shared memories.
9+
One for each register type:
10+
- Discrete Output Coils (DO)
11+
- Discrete Input Coils (DI)
12+
- Discrete Output Registers (AO)
13+
- Discrete Input Registers (AI)
14+
15+
All registers are initialized with 0 at the beginning.
16+
The Modbus master reads and writes directly the values from these shared memories.
17+
18+
The actual functionality of the client is realized by applications that read data from or write data to the shared memory.
19+
20+
The coils (DI, DO) use one byte per value, but only the least significant bit is used.
21+
The registers (AI, AO) use 10 bit per value. The user is responsible for handling the endianness.
22+
23+
## Use the Application
24+
The application requires a serial device (```--device```) and a client id (```--id```) as arguments. All other arguments are optional.
25+
26+
By using the command line argument ```--monitor``` all incoming and outgoing packets are printed on stdout.
27+
This option should be used carefully, as it generates large amounts of output depending on the masters polling cycle and the number of used registers.
28+
29+
The client creates four shared memories and names them ```modbus_DO```, ```modbus_DI```, ```modbus_AO``` and ```modbus_AI``` by default.
30+
The prefix modbus_ can be changed via the argument ```--name-prefix```.
31+
The suffixes for the register type (DO, DI, AO, AI) cannot be changed and will always be appended to the prefix.
32+
33+
By default, the client starts with the maximum possible number of modbus registers (65536 per register type).
34+
The number of registers can be changed using the ```--xx-registers``` (replace xx with the register type) command line arguments.
35+
36+
### Examples
37+
38+
Connect as device with id ```1``` using serial device ```/dev/ttyS0```:
39+
```
40+
modbus-rtu-client-shm -d /dev/ttyS0 -i 1
41+
```
42+
43+
44+
Connect as device with id ```1``` using serial device ```/dev/ttyS0``` with a baud rate of ```115200``` and a odd parity bit:
45+
```
46+
modbus-rtu-client-shm -d /dev/ttyS0 -i 1 -b 115200 -p O
47+
```
48+
49+
Connect as device with id ```1``` using serial device ```/dev/ttyS0``` and enforce rs232 mode:
50+
```
51+
modbus-rtu-client-shm -d /dev/ttyS0 -i 1 --rs232
52+
```
53+
54+
## Using the Flatpak package
55+
The flatpak package can be installed via the .flatpak file.
56+
This can be downloaded from the GitHub [projects release page](https://github.com/NikolasK-source/modbus_rtu_client_shm/releases):
57+
58+
```
59+
flatpak install --user modbus-rtu-client-shm.flatpak
60+
```
61+
62+
The application is then executed as follows:
63+
```
64+
flatpak run network.koesling.modbus-rtu-client-shm
65+
```
66+
67+
To enable calling with ```modbus-rtu-client-shm``` [this script](https://gist.github.com/NikolasK-source/7586b3b2e9808e63dd3f111310eacc03) can be used.
68+
In order to be executable everywhere, the path in which the script is placed must be in the ```PATH``` environment variable.
69+
70+
71+
## Build from Source
72+
73+
The following packages are required for building the application:
74+
- cmake
75+
- clang or gcc
76+
77+
Additionally, the following packages are required to build the modbus library:
78+
- autoconf
79+
- automake
80+
- libtool
81+
82+
83+
Use the following commands to build the application:
84+
```
85+
git clone --recursive https://github.com/NikolasK-source/modbus_rtu_client_shm.git
86+
cd modbus_rtu_client_shm
87+
mkdir build
88+
cmake -B build . -DCMAKE_BUILD_TYPE=Release -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF
89+
cmake --build build
90+
```
91+
92+
The binary is located in the build directory.
93+
94+
95+
## Links to related projects
96+
97+
### General Shared Memory Tools
98+
- [Shared Memory Dump](https://nikolask-source.github.io/dump_shm/)
99+
- [Shared Memory Write](https://nikolask-source.github.io/write_shm/)
100+
- [Shared Memory Random](https://nikolask-source.github.io/shared_mem_random/)
101+
102+
### Modbus Clients
103+
- [RTU](https://nikolask-source.github.io/modbus_rtu_client_shm/)
104+
- [TCP](https://nikolask-source.github.io/modbus_tcp_client_shm/)
105+
106+
### Modbus Shared Memory Tools
107+
- [STDIN to Modbus](https://nikolask-source.github.io/stdin_to_modbus_shm/)
108+
- [Float converter](https://nikolask-source.github.io/modbus_conv_float/)
109+
110+
111+
## License
112+
113+
MIT License
114+
115+
Copyright (c) 2021-2022 Nikolas Koesling
116+
117+
Permission is hereby granted, free of charge, to any person obtaining a copy
118+
of this software and associated documentation files (the "Software"), to deal
119+
in the Software without restriction, including without limitation the rights
120+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
121+
copies of the Software, and to permit persons to whom the Software is
122+
furnished to do so, subject to the following conditions:
123+
124+
The above copyright notice and this permission notice shall be included in all
125+
copies or substantial portions of the Software.
126+
127+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
128+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
129+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
130+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
131+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
132+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
133+
SOFTWARE.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
id: network.koesling.modbus-rtu-client-shm
2+
runtime: org.freedesktop.Platform
3+
runtime-version: '21.08'
4+
sdk: org.freedesktop.Sdk
5+
command: modbus-rtu-client-shm
6+
finish-args:
7+
- --device=shm
8+
- --share=network
9+
- --device=all
10+
modules:
11+
- name: Modbus_RTU_client_shm
12+
buildsystem: simple
13+
build-commands:
14+
# build
15+
- mkdir build
16+
- cmake -B build . -DCMAKE_BUILD_TYPE=Release -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF
17+
- cmake --build build
18+
19+
# install
20+
- install -D -m 755 -t ${FLATPAK_DEST}/bin build/modbus-rtu-client-shm
21+
sources:
22+
- type: git
23+
branch: release
24+
url: https://github.com/NikolasK-source/modbus_rtu_client_shm.git
25+

0 commit comments

Comments
 (0)