Struct embassy_net::Stack
source · pub struct Stack<D: Driver> { /* private fields */ }
Expand description
A network stack.
This is the main entry point for the network stack.
Implementations§
source§impl<D: Driver> Stack<D>
impl<D: Driver> Stack<D>
sourcepub fn new<const SOCK: usize>(
device: D,
config: Config,
resources: &'static mut StackResources<SOCK>,
random_seed: u64
) -> Self
pub fn new<const SOCK: usize>( device: D, config: Config, resources: &'static mut StackResources<SOCK>, random_seed: u64 ) -> Self
Create a new network stack.
sourcepub fn hardware_address(&self) -> HardwareAddress
pub fn hardware_address(&self) -> HardwareAddress
Get the hardware address of the network interface.
sourcepub fn is_link_up(&self) -> bool
pub fn is_link_up(&self) -> bool
Get whether the link is up.
sourcepub fn is_config_up(&self) -> bool
pub fn is_config_up(&self) -> bool
Get whether the network stack has a valid IP configuration. This is true if the network stack has a static IP configuration or if DHCP has completed
sourcepub async fn wait_config_up(&self)
pub async fn wait_config_up(&self)
Wait for the network stack to obtain a valid IP configuration.
§Notes:
-
Ensure
Stack::run
has been called before using this function. -
This function may never return (e.g. if no configuration is obtained through DHCP). The caller is supposed to handle a timeout for this case.
§Example
let config = embassy_net::Config::dhcpv4(Default::default());
static RESOURCES: StaticCell<embassy_net::StackResources<2> = StaticCell::new();
static STACK: StaticCell<embassy_net::Stack> = StaticCell::new();
let stack = &*STACK.init(embassy_net::Stack::new(
device,
config,
RESOURCES.init(embassy_net::StackResources::new()),
seed
));
// Launch network task that runs `stack.run().await`
spawner.spawn(net_task(stack)).unwrap();
// Wait for DHCP config
stack.wait_config_up().await;
// use the network stack
// ...
sourcepub fn config_v4(&self) -> Option<StaticConfigV4>
pub fn config_v4(&self) -> Option<StaticConfigV4>
Get the current IPv4 configuration.
If using DHCP, this will be None if DHCP hasn’t been able to acquire an IP address, or Some if it has.
sourcepub fn config_v6(&self) -> Option<StaticConfigV6>
pub fn config_v6(&self) -> Option<StaticConfigV6>
Get the current IPv6 configuration.
sourcepub fn set_config_v4(&self, config: ConfigV4)
pub fn set_config_v4(&self, config: ConfigV4)
Set the IPv4 configuration.
sourcepub fn set_config_v6(&self, config: ConfigV6)
pub fn set_config_v6(&self, config: ConfigV6)
Set the IPv6 configuration.
source§impl<D: Driver> Stack<D>
impl<D: Driver> Stack<D>
sourcepub async fn join_multicast_group<T>(
&self,
addr: T
) -> Result<bool, MulticastError>
pub async fn join_multicast_group<T>( &self, addr: T ) -> Result<bool, MulticastError>
Join a multicast group.
sourcepub fn poll_join_multicast_group<T>(
&self,
addr: T,
cx: &mut Context<'_>
) -> Poll<Result<bool, MulticastError>>
pub fn poll_join_multicast_group<T>( &self, addr: T, cx: &mut Context<'_> ) -> Poll<Result<bool, MulticastError>>
Join a multicast group.
When the send queue is full, this method will return Poll::Pending
and register the current task to be notified when the queue has space available.
sourcepub async fn leave_multicast_group<T>(
&self,
addr: T
) -> Result<bool, MulticastError>
pub async fn leave_multicast_group<T>( &self, addr: T ) -> Result<bool, MulticastError>
Leave a multicast group.
sourcepub fn poll_leave_multicast_group<T>(
&self,
addr: T,
cx: &mut Context<'_>
) -> Poll<Result<bool, MulticastError>>
pub fn poll_leave_multicast_group<T>( &self, addr: T, cx: &mut Context<'_> ) -> Poll<Result<bool, MulticastError>>
Leave a multicast group.
When the send queue is full, this method will return Poll::Pending
and register the current task to be notified when the queue has space available.
sourcepub fn has_multicast_group<T: Into<IpAddress>>(&self, addr: T) -> bool
pub fn has_multicast_group<T: Into<IpAddress>>(&self, addr: T) -> bool
Get whether the network stack has joined the given multicast group.