Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #1

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
02eb6b3
first version
ClausKlein Mar 9, 2025
ebeb90a
clang-format all files
ClausKlein Mar 9, 2025
b6691f2
add rrcp_client
ClausKlein Mar 9, 2025
5f7ad12
fix clang-tidy warnings
ClausKlein Mar 9, 2025
f54030f
sort includes
ClausKlein Mar 9, 2025
f5fb98a
Add timer example
ClausKlein Mar 9, 2025
186c3bc
Add GNUmakefile for test
ClausKlein Mar 11, 2025
d70909c
Trim comments and WS
ClausKlein Mar 11, 2025
c3c965e
Use msg length as hex
ClausKlein Mar 12, 2025
7f0f101
Add esc test
ClausKlein Mar 12, 2025
d7fc083
The final cut
ClausKlein Mar 12, 2025
e87ef0a
Cleanup
ClausKlein Mar 12, 2025
1520c96
Prevent more clang-tidy warnings
ClausKlein Mar 12, 2025
a88110a
Fix misc_include_cleaner warnings
ClausKlein Mar 12, 2025
4807b10
Finish the simplest rrcp client
ClausKlein Mar 12, 2025
939c09c
Add async_tcp_echo_client.cpp
ClausKlein Mar 13, 2025
b46c0e2
Prevent more clang-tidy warnings
ClausKlein Mar 13, 2025
6a2fa78
Now it works fine
ClausKlein Mar 13, 2025
678e99a
Modernize timer example
ClausKlein Mar 14, 2025
c2314c7
Modernize async_tcp_client example
ClausKlein Mar 14, 2025
a655022
Add gcovr config files
ClausKlein Mar 14, 2025
337a352
Fix more clang-tidy warnings
ClausKlein Mar 14, 2025
35addf6
Use a write message queue
ClausKlein Mar 14, 2025
d724ccd
Use enable_shared_from_this<>
ClausKlein Mar 15, 2025
2584f7c
Prevent more clang-tidy warnings
ClausKlein Mar 16, 2025
00f89a5
Try to fix heartbeat handling
ClausKlein Mar 16, 2025
4bc35b9
Add signal handler to async server
ClausKlein Mar 16, 2025
baa04bb
Add Signal and error handling
ClausKlein Mar 16, 2025
93f3383
Cleanup the code
ClausKlein Mar 16, 2025
4e30d6c
Modernize rrcp_helper
ClausKlein Mar 16, 2025
e4b1a82
Modernize and format the code again
ClausKlein Mar 16, 2025
a171a77
Add rrcp_async_tcp_client.cpp
ClausKlein Mar 16, 2025
ad0a22c
The final cut
ClausKlein Mar 17, 2025
f5b917c
Add more ctests
ClausKlein Mar 17, 2025
4fd771f
Prevent runtime_error exections
ClausKlein Mar 18, 2025
796d3d0
Use a write msg queue
ClausKlein Mar 18, 2025
bf8e59a
Reorder the test data set
ClausKlein Mar 18, 2025
0088fe6
Add Base64 encoding
ClausKlein Mar 18, 2025
2ed3e66
Add more base64 tests
ClausKlein Mar 19, 2025
78dc2c7
Add even more tests
ClausKlein Mar 19, 2025
889a54e
Change base64 tests according to RFC
ClausKlein Mar 20, 2025
03229b0
Add examples too
ClausKlein Mar 20, 2025
d67e4ad
Fix format in Readme
ClausKlein Mar 20, 2025
798db5b
Move base64 reference docu into tests
ClausKlein Mar 20, 2025
4bd1aa2
Changes after review
ClausKlein Mar 20, 2025
a34e2d3
Merge branch 'feature/tests-without-queue' into develop
ClausKlein Mar 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add GNUmakefile for test
ClausKlein committed Mar 14, 2025
commit 186c3bc703c364c82c9ccf1d7086ce0a0736c7cf
26 changes: 26 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Standard stuff

.SUFFIXES:

MAKEFLAGS+= --no-builtin-rules
MAKEFLAGS+= --warn-undefined-variables

.PHONY: all format test lint

all: build
ninja -C build

build: CMakeLists.txt
cmake -S . -B $@

lint: build
run-clang-tidy -p build -check='-*,readability-use-std-min-max,misc-include-cleaner' -fix rrcp_*.cpp

test: all
-killall blocking_tcp_echo_server
build/blocking_tcp_echo_server 8000 &
cat rrcp.txt | build/rrcp_client localhost 8000

format: .clang-format
git ls-files ::*.cpp ::*.hpp | xargs clang-format -i
gersemi -i CMakeLists.txt
22 changes: 22 additions & 0 deletions rrcp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// GET-request TU SET-request TU GET-request TU:
GFRQ;MOD SFRQ10000000;MOD13;BW80000 GFRQ;MOD
// GET-response TU SET-response TU GET-response TU:
gFRQ18000000;MOD12 s5BW gFRQ18000000;MOD12
// NOTE:
// There is an error within the BW command, the complete SET-request TU is cancelled.
// The GET-request TU is replied by the corresponding GET-response TU.
M:WF.FF.Main 123456 T Octet 1 // without Logical Address:
M:WF.FF.Main 123456 t
M:Bit L:1 123456 G Octet
M:Audio SOctet // without optionl parts
M:Radio SString"\rhallo\tworld\n"
M:Log SStruct1,-1,3.14 // multiple parameters
M:MultilCmd S Octet 1;Long-1;String"hallo world\n";Struct 1,+1,+3.14 // multiple commands's
M:Test 123456 S FREQ123456;MOD12;LOGIN"user","pasword" G FREQ;MOD;STATUS // multiple TU
M:Test gFREQ180000;MOD12 s5BW gFREQ180000;MOD12;STATUS"Running" // TU partly failed
M:eRADIO S FREQUENCY 123456789
E:12 // MU error
M:RADIO T FREQUENCY 1
M:RADIO t
M:RADIO d FREQUENCY 123456789 // trap data
M:Utility S Binary #36:AAECAwQFBgcICQoLDA0OD8KAwoHDvsO/Cg== // bas64 encoded binary data
10 changes: 8 additions & 2 deletions rrcp_client.cpp
Original file line number Diff line number Diff line change
@@ -14,10 +14,11 @@
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/post.hpp>
#include <boost/asio/read.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/asio/write.hpp>
#include <boost/system/error_code.hpp>
#include <boost/system/detail/error_code.hpp>
#include <chrono>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <exception>
#include <iostream>
@@ -153,15 +154,20 @@ int main(int argc, char* argv[])

std::thread t([&io_context]() { io_context.run(); });

std::this_thread::sleep_for(std::chrono::seconds(1));
int i{};
char line[rrcp_message::max_msg_length + 1];
while (std::cin.getline(line, rrcp_message::max_msg_length + 1))
{
std::cout << ++i << line << '\n';

rrcp_message msg;
msg.body_length(std::strlen(line));
std::memcpy(msg.body(), line, msg.body_length());
msg.encode_header();
c.write(msg);
}
std::this_thread::sleep_for(std::chrono::seconds(1));

c.close();
t.join();
3 changes: 3 additions & 0 deletions rrcp_helper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "rrcp_helper.hpp"

#include <cstddef>
#include <string>

constexpr const char ESC = 0x1B;
constexpr const char REPLACE_LF = 0x01;
constexpr const char REPLACE_CR = 0x02;
30 changes: 17 additions & 13 deletions rrcp_message.hpp
Original file line number Diff line number Diff line change
@@ -11,9 +11,11 @@
#ifndef RRCP_MESSAGE_HPP
#define RRCP_MESSAGE_HPP

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>

class rrcp_message
{
@@ -23,32 +25,34 @@ class rrcp_message

rrcp_message() {}

[[nodiscard]] const char* data() const { return data_; }
[[nodiscard]] const char* data() const { return data_.data(); }

char* data() { return data_; }
char* data() { return data_.data(); }

[[nodiscard]] std::size_t length() const
{
return header_length + msg_length_;
}

[[nodiscard]] const char* body() const { return data_ + header_length; }
[[nodiscard]] const char* body() const
{
return data_.data() + header_length;
}

char* body() { return data_ + header_length; }
char* body() { return data_.data() + header_length; }

[[nodiscard]] std::size_t body_length() const { return msg_length_; }

void body_length(std::size_t new_length)
{
msg_length_ = new_length;
if (msg_length_ > max_msg_length) msg_length_ = max_msg_length;
msg_length_ = std::min(msg_length_, max_msg_length);
}

bool decode_header()
{
char header[header_length + 1] = "";
std::strncat(header, data_, header_length);
msg_length_ = std::atoi(header);
std::string header(data_.data(), header_length);
msg_length_ = std::stoi(header);
if (msg_length_ > max_msg_length)
{
msg_length_ = 0;
@@ -59,14 +63,14 @@ class rrcp_message

void encode_header()
{
char header[header_length + 1] = "";
std::snprintf(
header, header_length + 1, "%4d", static_cast< int >(msg_length_));
std::memcpy(data_, header, header_length);
std::array< char, header_length + 1 > header;
std::snprintf(header.data(), header_length + 1, "%4d",
static_cast< int >(msg_length_));
std::memcpy(data_.data(), header.data(), header_length);
}

private:
char data_[header_length + max_msg_length];
std::array< char, header_length + max_msg_length > data_;
std::size_t msg_length_{0};
};