mirror of
https://github.com/BotChain-Robots/control.git
synced 2026-03-09 16:22:26 +01:00
RPC call
This commit is contained in:
12
.clang-format
Normal file
12
.clang-format
Normal file
@@ -0,0 +1,12 @@
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 4
|
||||
UseTab: Never
|
||||
ColumnLimit: 100
|
||||
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MaxEmptyLinesToKeep: 2
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
ReflowComments: false
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -49,3 +49,4 @@ CMakeCache.txt
|
||||
/CMakeFiles
|
||||
/examples/display/build
|
||||
*.log
|
||||
/examples/rpc_call/build
|
||||
|
||||
@@ -39,7 +39,7 @@ class MyLibraryConan(ConanFile):
|
||||
|
||||
def requirements(self):
|
||||
self.requires("flatbuffers/24.12.23")
|
||||
self.requires("librpc/1.1.6")
|
||||
self.requires("librpc/1.1.7")
|
||||
self.requires("eigen/3.4.1")
|
||||
self.requires("spdlog/1.16.0")
|
||||
self.requires("sentry-native/0.12.2")
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
libcontrol/1.0.0
|
||||
flatbuffers/24.12.23
|
||||
spdlog/1.16.0
|
||||
librpc/1.1.6
|
||||
librpc/1.1.7
|
||||
|
||||
[generators]
|
||||
CMakeDeps
|
||||
|
||||
19
examples/rpc_call/CMakeLists.txt
Normal file
19
examples/rpc_call/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
project(RpcCallExample)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(libcontrol REQUIRED)
|
||||
find_package(spdlog REQUIRED)
|
||||
find_package(librpc REQUIRED)
|
||||
|
||||
add_executable(RpcCallExample main.cpp)
|
||||
|
||||
target_link_libraries(RpcCallExample
|
||||
PRIVATE
|
||||
libcontrol::libcontrol
|
||||
spdlog::spdlog
|
||||
librpc::librpc
|
||||
)
|
||||
9
examples/rpc_call/CMakeUserPresets.json
Normal file
9
examples/rpc_call/CMakeUserPresets.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"version": 4,
|
||||
"vendor": {
|
||||
"conan": {}
|
||||
},
|
||||
"include": [
|
||||
"build/CMakePresets.json"
|
||||
]
|
||||
}
|
||||
10
examples/rpc_call/README.md
Normal file
10
examples/rpc_call/README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# RPC Call Example
|
||||
|
||||
## Compiling
|
||||
```
|
||||
conan install . --build=missing --output-folder=build -s build_type=Release
|
||||
cmake -S . -B "build" -DCMAKE_TOOLCHAIN_FILE="build/conan_toolchain.cmake" -DCMAKE_BUILD_TYPE="Release"
|
||||
cmake --build "./build" --config "Release"
|
||||
|
||||
./build/RpcCallExample
|
||||
```
|
||||
3
examples/rpc_call/build.sh
Executable file
3
examples/rpc_call/build.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
conan install . --build=missing --output-folder=build -s build_type=Release
|
||||
cmake -S . -B "build" -DCMAKE_TOOLCHAIN_FILE="build/conan_toolchain.cmake" -DCMAKE_BUILD_TYPE="Release"
|
||||
cmake --build "./build" --config "Release"
|
||||
9
examples/rpc_call/conanfile.txt
Normal file
9
examples/rpc_call/conanfile.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
[requires]
|
||||
libcontrol/1.0.0
|
||||
flatbuffers/24.12.23
|
||||
spdlog/1.16.0
|
||||
librpc/1.1.7
|
||||
|
||||
[generators]
|
||||
CMakeDeps
|
||||
CMakeToolchain
|
||||
40
examples/rpc_call/main.cpp
Normal file
40
examples/rpc_call/main.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "libcontrol.h"
|
||||
|
||||
int main() {
|
||||
|
||||
const auto messaging_interface = std::make_unique<MessagingInterface>();
|
||||
|
||||
const auto modules =
|
||||
messaging_interface->find_connected_modules(std::chrono::seconds(3));
|
||||
|
||||
std::cout << "Found " << modules.size() << " modules" << std::endl;
|
||||
|
||||
for (const auto module : modules) {
|
||||
std::cout << "Found ID " << (int)module << std::endl;
|
||||
}
|
||||
|
||||
const auto function_tag = 100;
|
||||
const auto module = 98;
|
||||
std::string msg = "Hello world!";
|
||||
std::vector<uint8_t> parameters(msg.begin(), msg.end());
|
||||
auto maybe_return_value =
|
||||
messaging_interface->remote_call(function_tag, module, parameters);
|
||||
|
||||
if (maybe_return_value) {
|
||||
auto return_value = std::move(*maybe_return_value);
|
||||
std::cout << "Got return value " << (char *)return_value->data()
|
||||
<< std::endl;
|
||||
} else {
|
||||
std::cout << "Function call time out" << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user