-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ómar Högni Guðmarsson
committed
Aug 10, 2023
1 parent
5180f4a
commit bddc954
Showing
9 changed files
with
172 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: build | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
name: 'build' | ||
runs-on: ${{matrix.os}} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-22.04, macos-11.0, windows-latest] | ||
build_type: [debug, release] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Restore artifacts, or setup vcpkg | ||
uses: lukka/run-vcpkg@v11 | ||
with: | ||
vcpkgGitCommitId: 'fbc868ee5e12e3e81f464104be246ec06553c274' | ||
vcpkgJsonGlob: 'vcpkg.json' | ||
- name: build with cmake | ||
uses: lukka/run-cmake@v10 | ||
with: | ||
buildPreset: 'build-ci' | ||
buildPresetAdditionalArgs: "['--config ${{matrix.build_type}}']" | ||
testPreset: 'test-ci' | ||
testPresetAdditionalArgs: "['--config ${{matrix.build_type}}']" | ||
configurePreset: 'conf-ci' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
vcpkg-sys* | ||
build | ||
build*/ | ||
cmake-build* | ||
.idea | ||
vcpkg/ | ||
.vscode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"version": 6, | ||
"configurePresets": [ | ||
{ | ||
"name": "conf-ci", | ||
"generator": "Ninja", | ||
"cacheVariables": { | ||
"BUILD_SHARED_LIBS": "ON", | ||
"CMAKE_TOOLCHAIN_FILE": "${GITHUB_WORKSPACE}/vcpkg/scripts/buildsystems/vcpkg.cmake" | ||
} | ||
} | ||
], | ||
"buildPresets": [ | ||
{ | ||
"name": "build-ci", | ||
"configurePreset": "conf-ci" | ||
} | ||
], | ||
"testPresets": [ | ||
{ | ||
"name": "test-ci", | ||
"hidden": true, | ||
"output": {"outputOnFailure": true}, | ||
"execution": {"noTestsAction": "error", "stopOnFailure": true} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
enable_testing() | ||
|
||
find_package(ut CONFIG REQUIRED) | ||
add_executable(serialization serialization.cpp) | ||
|
||
target_link_libraries(serialization PRIVATE Boost::ut modbus) | ||
|
||
add_test(NAME serialization COMMAND serialization) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <array> | ||
|
||
#include <boost/ut.hpp> | ||
#include <modbus/tcp.hpp> | ||
|
||
void print_bytes(std::span<uint8_t> data){ | ||
for (auto& k : data) { | ||
std::cout << static_cast<int>(k) << " "; | ||
} | ||
std::cout << std::endl; | ||
} | ||
|
||
int main(){ | ||
using boost::ut::operator""_test; | ||
using boost::ut::expect; | ||
|
||
"Modbus tcp header serialize/deserialize"_test = []() { | ||
using modbus::tcp_mbap; | ||
tcp_mbap header; | ||
auto bytes = std::array<uint8_t, tcp_mbap::size>{0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x01}; | ||
auto hd = tcp_mbap::from_bytes(bytes); | ||
|
||
expect(hd.transaction == 1); | ||
expect(hd.protocol == 0); | ||
expect(hd.length == 6); | ||
expect(hd.unit == 1); | ||
|
||
auto buffer = hd.to_bytes(); | ||
print_bytes(buffer); | ||
print_bytes(bytes); | ||
for (size_t i = 0; i < buffer.size(); i++) | ||
expect(buffer[i] == bytes[i]); | ||
}; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "modbus", | ||
"version": "0.0.1", | ||
"description": "Modbus protocol implementation, based on boost asio", | ||
"dependencies": [ | ||
"boost-asio", | ||
"bext-ut" | ||
] | ||
} |