pub struct PiperBuilder { /* private fields */ }Expand description
Piper Builder(链式构造)
使用 Builder 模式创建 Piper 实例,支持链式调用。
§Example
use piper_driver::{PiperBuilder, PipelineConfig};
// 使用默认配置
let piper = PiperBuilder::new()
.build()
.unwrap();
// 自定义波特率和 Pipeline 配置
let config = PipelineConfig {
receive_timeout_ms: 5,
frame_group_timeout_ms: 20,
velocity_buffer_timeout_us: 20_000,
};
let piper = PiperBuilder::new()
.baud_rate(500_000)
.pipeline_config(config)
.build()
.unwrap();Implementations§
Source§impl PiperBuilder
impl PiperBuilder
Sourcepub fn with_driver_type(self, driver_type: DriverType) -> Self
pub fn with_driver_type(self, driver_type: DriverType) -> Self
显式指定驱动类型(可选,默认 Auto)
§Example
use piper_driver::{PiperBuilder, DriverType};
// 强制使用 GS-USB
let piper = PiperBuilder::new()
.with_driver_type(DriverType::GsUsb)
.build()
.unwrap();Sourcepub fn interface(self, interface: impl Into<String>) -> Self
pub fn interface(self, interface: impl Into<String>) -> Self
设置 CAN 接口(可选,默认自动检测)
§注意
- Linux: 此参数可以是 SocketCAN 接口名称(如 “can0” 或 “vcan0”)或 GS-USB 设备序列号
- 如果接口名是 “can0”/“can1” 等,优先使用 SocketCAN(通过 Smart Default)
- 如果接口名是设备序列号或未提供,使用 GS-USB
- macOS/Windows (GS-USB): 此参数用作设备序列号,用于区分多个 GS-USB 设备
- 如果提供序列号,只打开匹配序列号的设备
- 如果不提供,自动选择第一个找到的设备
§Example
use piper_driver::PiperBuilder;
// 通过序列号指定设备
let piper = PiperBuilder::new()
.interface("ABC123456")
.build()
.unwrap();Sourcepub fn pipeline_config(self, config: PipelineConfig) -> Self
pub fn pipeline_config(self, config: PipelineConfig) -> Self
设置 Pipeline 配置(可选)
Sourcepub fn with_daemon(self, daemon_addr: impl Into<String>) -> Self
pub fn with_daemon(self, daemon_addr: impl Into<String>) -> Self
使用守护进程模式(可选)
当指定守护进程地址时,使用 GsUsbUdpAdapter 通过守护进程访问 GS-USB 设备。
这解决了 macOS 下 GS-USB 设备重连后无法正常工作的限制。
§参数
daemon_addr: 守护进程地址- UDS 路径(如 “/tmp/gs_usb_daemon.sock”)
- UDP 地址(如 “127.0.0.1:8888”)
§Example
use piper_driver::PiperBuilder;
// 使用 UDS 连接守护进程
let piper = PiperBuilder::new()
.with_daemon("/tmp/gs_usb_daemon.sock")
.build()
.unwrap();
// 使用 UDP 连接守护进程(用于跨机器调试)
let piper = PiperBuilder::new()
.with_daemon("127.0.0.1:8888")
.build()
.unwrap();Sourcepub fn build(self) -> Result<Piper, DriverError>
pub fn build(self) -> Result<Piper, DriverError>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PiperBuilder
impl RefUnwindSafe for PiperBuilder
impl Send for PiperBuilder
impl Sync for PiperBuilder
impl Unpin for PiperBuilder
impl UnwindSafe for PiperBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more