33 write_sem_(0),
37 {
38 if (std::filesystem::exists(
dev_path) ==
false)
39 {
40 XR_LOG_ERROR(
"Cannot find UART device: %s",
dev_path);
41 ASSERT(false);
42 }
43
44 device_path_ = GetByPathForTTY(
dev_path);
45
47 if (fd_ < 0)
48 {
49 XR_LOG_ERROR("Cannot open UART device: %s", device_path_.c_str());
50 ASSERT(false);
51 }
52 else
53 {
54 XR_LOG_PASS("Open UART device: %s", device_path_.c_str());
55 }
56
58 .parity = parity,
59 .data_bits = data_bits,
60 .stop_bits = stop_bits};
61
63
66
67 rx_thread_.
Create<LinuxUART *>(
68 this, [](LinuxUART *
self) {
self->RxLoop(); },
"rx_uart", 8192,
70
71 tx_thread_.
Create<LinuxUART *>(
72 this, [](LinuxUART *
self) {
self->TxLoop(); },
"tx_uart", 8192,
74 }
ErrorCode SetConfig(UART::Configuration config) override
设置 UART 配置 / Sets the UART configuration
@ REALTIME
实时优先级 Realtime priority
void Create(ArgType arg, void(*function)(ArgType arg), const char *name, size_t stack_depth, Thread::Priority priority)
创建新线程 Creates a new thread
UART(size_t rx_queue_size, size_t rx_buffer_size, size_t tx_queue_size, size_t tx_buffer_size)
UART 构造函数 / UART constructor.
WritePort write_port_
写入端口 / Write port
ReadPort read_port_
读取端口 / Read port
ErrorCode(* ReadFun)(ReadPort &port)
Function pointer type for read operations.
ErrorCode(* WriteFun)(WritePort &port)
Function pointer type for write operations.
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值
uint32_t baudrate
波特率 / Baud rate