mirror of
https://github.com/BotChain-Robots/control.git
synced 2026-03-10 00:32:26 +01:00
RPC call (#2)
This commit is contained in:
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