pub struct Network {
pub tcp: TcpSession,
pub udp: UdpChannel,
pub server_ip: IpAddr,
}Expand description
A connected FCI session: the command socket, the state socket, and the server’s IP.
Fields§
§tcp: TcpSessionTCP command channel.
udp: UdpChannelUDP state/command channel.
server_ip: IpAddrIP address the command socket is connected to.
Implementations§
Source§impl Network
impl Network
Sourcepub fn connect(
host: &str,
tcp_port: u16,
layout: HeaderLayout,
) -> FrankaResult<Network>
pub fn connect( host: &str, tcp_port: u16, layout: HeaderLayout, ) -> FrankaResult<Network>
Connects to host and binds the UDP socket, exactly like franka::Network’s
constructor. host may be "host" or "host:port"; an explicit port overrides
tcp_port.
layout selects the 12-byte robot or the 10-byte gripper header for TCP framing.
Sourcepub fn connect_with_timeouts(
host: &str,
tcp_port: u16,
layout: HeaderLayout,
tcp_timeout: Duration,
udp_timeout: Duration,
) -> FrankaResult<Network>
pub fn connect_with_timeouts( host: &str, tcp_port: u16, layout: HeaderLayout, tcp_timeout: Duration, udp_timeout: Duration, ) -> FrankaResult<Network>
Network::connect with explicit timeouts (libfranka’s tcp_timeout / udp_timeout).
Sourcepub fn udp_peer(&self) -> Option<SocketAddr>
pub fn udp_peer(&self) -> Option<SocketAddr>
Source address of the last state datagram, i.e. where robot commands must be sent.
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 state datagram as a T if one is already queued, without blocking.
Pass-through to UdpChannel::try_receive_struct that additionally shuts the command
socket down when the receive fails at the network level, mirroring the
tcp_socket_.shutdown() in libfranka’s udpBlockingReceiveUnsafe catch block
(network.h:146). A size mismatch is not a network failure — libfranka’s
ProtocolException is thrown inside the try and is not caught by that handler — so
the socket stays up in that case, exactly as in the C++.
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 state datagram arrives and returns it as a T.
Pass-through to UdpChannel::blocking_receive_struct with the same
shut-down-the-TCP-socket-on-network-failure behaviour as
Network::try_receive_struct. A receive timeout counts as a network failure, which is
what makes the next TCP command fail fast instead of blocking on a dead session.
Sourcepub fn try_receive_bytes(&self, buf: &mut [u8]) -> FrankaResult<Option<usize>>
pub fn try_receive_bytes(&self, buf: &mut [u8]) -> FrankaResult<Option<usize>>
Reads one datagram into buf if one is already queued, without blocking, and returns how
many bytes it held.
Byte-slice counterpart of Network::try_receive_struct, with the same
shut-down-the-TCP-socket-on-network-failure behaviour. The length check is the caller’s
job: the version-aware state reader in crate::robot passes a buffer sized for the
largest supported RobotState and compares the returned length against the negotiated
version’s size, so a datagram of the other version is rejected instead of being silently
truncated.
Sourcepub fn blocking_receive_bytes(&self, buf: &mut [u8]) -> FrankaResult<usize>
pub fn blocking_receive_bytes(&self, buf: &mut [u8]) -> FrankaResult<usize>
Blocks until a datagram arrives, reads it into buf and returns its length.
Byte-slice counterpart of Network::blocking_receive_struct; see
Network::try_receive_bytes for why the length check is left to the caller.
Sourcepub fn send_udp(&self, data: &[u8]) -> FrankaResult<()>
pub fn send_udp(&self, data: &[u8]) -> FrankaResult<()>
Sends a robot command to the address the last state came from.
Fails before the first state has been received, which cannot happen in a control loop:
libfranka’s udp_server_address_ is likewise only valid after the first
receiveFrom.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Network
impl RefUnwindSafe for Network
impl Send for Network
impl Sync for Network
impl Unpin for Network
impl UnsafeUnpin for Network
impl UnwindSafe for Network
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.