Skip to content

Commit

Permalink
Merge pull request #3 from NikolasK-source/main
Browse files Browse the repository at this point in the history
Release 1.1.0
  • Loading branch information
NikolasK-source authored Aug 9, 2022
2 parents 2077f47 + 6101326 commit b93c5cf
Show file tree
Hide file tree
Showing 18 changed files with 578 additions and 51 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: clang-format Check
on: [push, pull_request]
jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run clang-format style check for C/C++/Protobuf programs.
uses: jidicula/[email protected]
with:
clang-format-version: '14'
check-path: 'src'

43 changes: 43 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CMake

on:
push:
branches: [ "main", "development" ]
pull_request:
branches: [ "main" ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Init submodules
run: git submodule init

- name: Update submodules
run: git submodule update

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

# - name: Test
# working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
# run: ctest -C ${{env.BUILD_TYPE}}

75 changes: 75 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "main", "development" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '32 20 * * 0'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'cpp' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# 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
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
# - name: Autobuild
# uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

- run: |
echo "Run, Build Application using cmake"
git submodule init
git submodule update
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF
cmake --build ${{github.workspace}}/build --config Release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
19 changes: 19 additions & 0 deletions .github/workflows/flatpak_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
on:
push:
branches: [release]
name: Flatpak_release
jobs:
flatpak:
name: "Flatpak"
runs-on: ubuntu-latest
container:
image: bilelmoussaoui/flatpak-github-actions:freedesktop-21.08
options: --privileged
steps:
- uses: actions/checkout@v2
- uses: bilelmoussaoui/flatpak-github-actions/flatpak-builder@v4
name: "Build"
with:
bundle: modbus-tcp-client-shm.flatpak
manifest-path: network.koesling.modbus-tcp-client-shm.yml
cache-key: flatpak-builder-${{ github.sha }}
30 changes: 30 additions & 0 deletions .github/workflows/flatpak_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on:
push:
branches: [ "main", "development" ]
pull_request:
name: Flatpak_test
jobs:
flatpak:
name: "Flatpak"
runs-on: ubuntu-latest
container:
image: bilelmoussaoui/flatpak-github-actions:freedesktop-21.08
options: --privileged
steps:
- uses: actions/checkout@v2

- name: Git config
run: git config --global --add safe.directory /__w/modbus_tcp_client_shm/modbus_tcp_client_shm

- name: Init submodules
run: git submodule init

- name: Update submodules
run: git submodule update

- uses: bilelmoussaoui/flatpak-github-actions/flatpak-builder@v4
name: "Build"
with:
bundle: test_modbus-tcp-client-shm.flatpak
manifest-path: network.koesling.test-modbus-tcp-client-shm.yml
cache-key: flatpak-builder-${{ github.sha }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -466,4 +466,4 @@ Module.symvers
Mkfile.old
dkms.conf

!network.koesling.modbus_tcp_client_shm.yml
!network.koesling.modbus-tcp-client-shm.yml
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "libs/cxxopts"]
path = libs/cxxopts
url = https://github.com/NikolasK-source/cxxopts.git
url = https://github.com/NikolasK-source/cxxopts.git
[submodule "libs/libmodbus"]
path = libs/libmodbus
url = https://github.com/stephane/libmodbus
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.3)
project(Modbus_TCP_client_shm LANGUAGES CXX VERSION 1.1.0)

# settings
set(Target "Modbus_TCP_client_shm") # Executable name (without file extension!)
Expand Down
83 changes: 82 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Shared Memory Modbus TCP Client

This project is a simple command line based Modbus TCP client for POXIX compatible operating systems that stores the contents of its registers in shared memory.
This project is a simple command line based Modbus TCP client for POSIX compatible operating systems that stores the contents of its registers in shared memory.


## Basic operating principle

Expand Down Expand Up @@ -29,6 +30,29 @@ This option should be used carefully, as it generates large amounts of output de

The ```--reconnect``` option can be used to specify that the application is not terminated when the master disconnects, but waits for a new connection.

The client creates four shared memories and names them ```modbus_DO```, ```modbus_DI```, ```modbus_AO``` and ```modbus_AI``` by default.
The prefix modbus_ can be changed via the argument ```--name-prefix```.
The suffixes for the register type (DO, DI, AO, AI) cannot be changed and will always be appended to the prefix.

By default, the client starts with the maximum possible number of modbus registers (65536 per register type).
The number of registers can be changed using the ```--xx-registers``` (replace xx with the register type) command line arguments.

### Examples
Start client and listen to all incoming connections on the modbus standard port:
```
modbus-tcp-client-shm
```

Start client and listen to all incoming connections on port 10000 and wait for a new connection if the connection is lost:
```
modbus-tcp-client-shm -p 10000 -r
```

Start client and listen to incoming connections on ip 127.0.0.1 on port 10000:
```
modbus-tcp-client-shm -p 10000 -i 127.0.0.1
```

### Use privileged ports
Ports below 1024 cannot be used by standard users.
Therefore, the default modbus port (502) cannot be used without further action.
Expand All @@ -53,6 +77,22 @@ setcap 'cap_net_bind_service=+ep' /path/to/binary
```


## Using the Flatpak package
The flatpak package can be installed via the .flatpak file.
This can be downloaded from the GitHub [projects release page](https://github.com/NikolasK-source/modbus_tcp_client_shm/releases):

```
flatpak install --user modbus-tcp-client-shm.flatpak
```

The application is then executed as follows:
```
flatpak run network.koesling.modbus-tcp-client-shm
```

To enable calling with ```modbus-tcp-client-shm``` [this script](https://gist.github.com/NikolasK-source/f0ef53fe4be7922901a1543e3cce8a97) can be used.
In order to be executable everywhere, the path in which the script is placed must be in the ```PATH``` environment variable.


## Build from Source

Expand All @@ -76,3 +116,44 @@ cmake --build build
```

The binary is located in the build directory.


## Links to related projects

### General Shared Memory Tools
- [Shared Memory Dump](https://nikolask-source.github.io/dump_shm/)
- [Shared Memory Write](https://nikolask-source.github.io/write_shm/)
- [Shared Memory Random](https://nikolask-source.github.io/shared_mem_random/)

### Modbus Clients
- [RTU](https://nikolask-source.github.io/modbus_rtu_client_shm/)
- [TCP](https://nikolask-source.github.io/modbus_tcp_client_shm/)

### Modbus Shared Memory Tools
- [STDIN to Modbus](https://nikolask-source.github.io/stdin_to_modbus_shm/)
- [Float converter](https://nikolask-source.github.io/modbus_conv_float/)


## License

MIT License

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
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion libs/libmodbus
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
id: network.koesling.modbus_tcp_client_shm
id: network.koesling.modbus-tcp-client-shm
runtime: org.freedesktop.Platform
runtime-version: '21.08'
sdk: org.freedesktop.Sdk
Expand Down
25 changes: 25 additions & 0 deletions network.koesling.test-modbus-tcp-client-shm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
id: network.koesling.test-modbus-tcp-client-shm
runtime: org.freedesktop.Platform
runtime-version: '21.08'
sdk: org.freedesktop.Sdk
command: Modbus_TCP_client_shm
finish-args:
- --device=shm
- --share=network
modules:
- name: Modbus_TCP_client_shm
buildsystem: simple
build-commands:
# build
- mkdir build
- cmake -B build . -DCMAKE_BUILD_TYPE=Release -DCLANG_FORMAT=OFF -DCOMPILER_WARNINGS=OFF
- cmake --build build

# install
- mkdir -p "${FLATPAK_DEST}/bin"
- cp build/Modbus_TCP_client_shm ${FLATPAK_DEST}/bin
- ls -lah ${FLATPAK_DEST}
sources:
- type: dir
path: .

Loading

0 comments on commit b93c5cf

Please sign in to comment.