Skip to main content

PiperBuilder

Struct PiperBuilder 

Source
pub struct PiperBuilder { /* private fields */ }
Expand description

Client 层 Piper Builder

提供链式 API 创建 Piper<Standby> 实例,自动处理平台差异和适配器选择。

§示例

use piper_client::PiperBuilder;
use std::time::Duration;

// 使用默认配置(推荐)
let robot = PiperBuilder::new().build()?;

// 指定接口
let robot = PiperBuilder::new()
    .interface("can0")
    .build()?;

// 完整配置
let robot = PiperBuilder::new()
    .interface("can0")
    .baud_rate(1_000_000)
    .timeout(Duration::from_secs(5))
    .build()?;

// 使用守护进程
let robot = PiperBuilder::new()
    .with_daemon("/tmp/gs_usb_daemon.sock")
    .build()?;

Implementations§

Source§

impl PiperBuilder

Source

pub fn new() -> Self

创建新的 Builder

Source

pub fn interface(self, interface: impl Into<String>) -> Self

设置 CAN 接口名称或设备序列号

  • Linux: “can0”/“can1” 等 SocketCAN 接口名,或设备序列号(使用 GS-USB)
  • macOS/Windows: GS-USB 设备序列号
  • 如果为 None,使用平台默认值(Linux: “can0”, 其他: 自动选择)
Source

pub fn baud_rate(self, baud_rate: u32) -> Self

设置 CAN 波特率(默认: 1_000_000)

Source

pub fn timeout(self, timeout: Duration) -> Self

设置连接超时(默认: 5 秒)

Source

pub fn with_daemon(self, daemon_addr: impl Into<String>) -> Self

使用守护进程模式

当启用守护进程模式时,interface 参数会被忽略(守护进程模式优先级最高)。

§参数
  • daemon_addr: 守护进程地址
    • UDS 路径(如 “/tmp/gs_usb_daemon.sock”)
    • UDP 地址(如 “127.0.0.1:8888”)
§注意

守护进程模式会忽略 interface 参数,因为设备选择由守护进程管理。

Source

pub fn build(self) -> Result<Piper<Standby>>

构建 Piper<Standby> 实例

§注意
  • 当启用 Daemon 模式时,interface 参数会被忽略(Daemon 模式优先级最高)
  • Interface 为 None 时,Linux 平台默认使用 “can0”,其他平台自动选择第一个 GS-USB 设备

Trait Implementations§

Source§

impl Default for PiperBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more