GKD.RoboCtrl
RoboMaster Linux 电控:异步 IO、设备驱动与机器人控制
载入中...
搜索中...
未找到
udp.h
浏览该文件的文档.
1
6#pragma once
7#include <asio.hpp>
8#include <format>
9#include <string_view>
10#include <span>
11#include <string>
12
13#include "core/async.hpp"
14#include "io/base.hpp"
15#include "core/logger.h"
16#include "io/write_queue.hpp"
17
18namespace roboctrl::io{
19
23class udp : public bare_io_base{
24public:
28 struct info_type{
29 using key_type = std::string;
30 using owner_type = udp;
31
32 std::string key_;
33 std::string address;
34 std::uint16_t port;
35
36 const std::string& key()const{
37 return key_;
38 }
39 };
40
44 udp(info_type info);
45
47 void start();
48
53
58
60 inline std::string desc()const{
61 return std::format("udp socket ({} to {}:{})",info_.key_,info_.address,info_.port);
62 }
63
64private:
65 asio::ip::udp::socket socket_;
66 write_queue write_queue_;
67 info_type info_;
68 std::array<std::byte,65536> buffer_;
69 bool started_ {false};
70};
71
72static_assert(bare_io<udp>);
73}
异步任务上下文组件。
UDP 通信端点。
Definition udp.h:23
awaitable< void > task()
接收循环任务。
Definition udp.cpp:37
std::string desc() const
返回 UDP 端点描述。
Definition udp.h:60
awaitable< void > send(byte_span data)
异步发送一段字节数据。
Definition udp.cpp:32
void start()
启动 UDP 接收协程;重复调用不会重复启动。
Definition udp.cpp:24
将同一异步流上的写操作串行化。
IO的基础组件。
std::span< const std::byte > byte_span
只读 byte span。
Definition base.hpp:45
用于日志输出的组件。
asio::awaitable< T > awaitable
协程任务类型。
Definition async.hpp:46
UDP 初始化参数。
Definition udp.h:28