Skip to main content

Network

Struct Network 

Source
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: TcpSession

TCP command channel.

§udp: UdpChannel

UDP state/command channel.

§server_ip: IpAddr

IP address the command socket is connected to.

Implementations§

Source§

impl Network

Source

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.

Source

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).

Source

pub fn udp_peer(&self) -> Option<SocketAddr>

Source address of the last state datagram, i.e. where robot commands must be sent.

Source

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++.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl Debug for Network

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.