pub struct UdpChannel { /* private fields */ }Expand description
The client’s UDP socket for robot states and robot commands.
Neither UdpChannel::try_receive nor UdpChannel::send allocates, so both are safe to
call from a 1 kHz control loop.
Implementations§
Source§impl UdpChannel
impl UdpChannel
Sourcepub fn bind(timeout: Duration) -> FrankaResult<UdpChannel>
pub fn bind(timeout: Duration) -> FrankaResult<UdpChannel>
Binds 0.0.0.0:0 and sets the receive timeout, as franka::Network’s constructor does.
Sourcepub fn port(&self) -> u16
pub fn port(&self) -> u16
The local port, which is announced to the server in the Connect request.
Sourcepub fn peer(&self) -> Option<SocketAddr>
pub fn peer(&self) -> Option<SocketAddr>
Source address of the last received datagram, if any.
Sourcepub fn try_receive(&self, buf: &mut [u8]) -> FrankaResult<Option<usize>>
pub fn try_receive(&self, buf: &mut [u8]) -> FrankaResult<Option<usize>>
Reads one datagram if one is already queued, without blocking and without allocating.
Uses recvfrom(2) with MSG_DONTWAIT rather than toggling O_NONBLOCK around every
call, so a 1 kHz control loop performs exactly one syscall per poll. Returns Ok(None)
when no datagram is waiting (libfranka’s udpReceive returning false).
§Note
This raw byte API does not check the datagram length. libfranka’s
udpBlockingReceiveUnsafe rejects bytes_received != sizeof(T) with
ProtocolException("libfranka: incorrect object size") (network.h:140-142); here that
is the caller’s job. Parsing a short datagram against a full-size buffer would silently
read stale bytes, so prefer UdpChannel::try_receive_struct, which performs the
check.
Sourcepub fn blocking_receive(&self, buf: &mut [u8]) -> FrankaResult<usize>
pub fn blocking_receive(&self, buf: &mut [u8]) -> FrankaResult<usize>
Blocks until a datagram arrives or the receive timeout expires.
A timeout is reported as Network("libfranka: UDP receive: Timeout"), which is the text
libfranka produces from "libfranka: UDP receive: "s + Poco::TimeoutException::what().
§Note
Like UdpChannel::try_receive, this raw byte API does not check the datagram length;
use UdpChannel::blocking_receive_struct to get libfranka’s
"libfranka: incorrect object size" check.
Sourcepub fn try_receive_struct<T>(&self) -> FrankaResult<Option<T>>where
T: FromBytes + IntoBytes + Immutable + KnownLayout,
pub fn try_receive_struct<T>(&self) -> FrankaResult<Option<T>>where
T: FromBytes + IntoBytes + Immutable + KnownLayout,
Reads one datagram as a T if one is already queued, without blocking.
Typed counterpart of UdpChannel::try_receive and the port of
Network::udpReceive<T> (network.h:117-125): the datagram is read into a T-sized
stack buffer (no allocation, so this is control-loop safe) and its length must be
exactly size_of::<T>(), otherwise
Protocol("libfranka: incorrect object size") is returned (network.h:140-142).
A datagram longer than size_of::<T>() is truncated by recvfrom and therefore looks
like an exact-size read — the same blind spot libfranka has.
Sourcepub fn blocking_receive_struct<T>(&self) -> FrankaResult<T>where
T: FromBytes + IntoBytes + Immutable + KnownLayout,
pub fn blocking_receive_struct<T>(&self) -> FrankaResult<T>where
T: FromBytes + IntoBytes + Immutable + KnownLayout,
Blocks until a datagram arrives and returns it as a T.
Typed counterpart of UdpChannel::blocking_receive and the port of
Network::udpBlockingReceive<T> (network.h:128-132), including the
Protocol("libfranka: incorrect object size") check on the datagram length.
Sourcepub fn send(&self, addr: SocketAddr, data: &[u8]) -> FrankaResult<()>
pub fn send(&self, addr: SocketAddr, data: &[u8]) -> FrankaResult<()>
Sends data to addr, which is normally UdpChannel::peer.
A short write is reported as Network("libfranka: could not send UDP data"), matching
udpSend.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for UdpChannel
impl RefUnwindSafe for UdpChannel
impl Send for UdpChannel
impl Sync for UdpChannel
impl Unpin for UdpChannel
impl UnsafeUnpin for UdpChannel
impl UnwindSafe for UdpChannel
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.