aboutsummaryrefslogtreecommitdiff
path: root/examples/std/src/bin/net_udp.rs
diff options
context:
space:
mode:
authorQuentin Smith <[email protected]>2023-07-17 21:31:43 -0400
committerQuentin Smith <[email protected]>2023-07-17 21:31:43 -0400
commit6f02403184eb7fb7990fb88fc9df9c4328a690a3 (patch)
tree748f510e190bb2724750507a6e69ed1a8e08cb20 /examples/std/src/bin/net_udp.rs
parentd896f80405aa8963877049ed999e4aba25d6e2bb (diff)
parent6b5df4523aa1c4902f02e803450ae4b418e0e3ca (diff)
Merge remote-tracking branch 'origin/main' into nrf-pdm
Diffstat (limited to 'examples/std/src/bin/net_udp.rs')
-rw-r--r--examples/std/src/bin/net_udp.rs23
1 files changed, 7 insertions, 16 deletions
diff --git a/examples/std/src/bin/net_udp.rs b/examples/std/src/bin/net_udp.rs
index 392a97f0d..3fc46156c 100644
--- a/examples/std/src/bin/net_udp.rs
+++ b/examples/std/src/bin/net_udp.rs
@@ -2,26 +2,17 @@
2 2
3use clap::Parser; 3use clap::Parser;
4use embassy_executor::{Executor, Spawner}; 4use embassy_executor::{Executor, Spawner};
5use embassy_net::udp::UdpSocket; 5use embassy_net::udp::{PacketMetadata, UdpSocket};
6use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, PacketMetadata, Stack, StackResources}; 6use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources};
7use heapless::Vec; 7use heapless::Vec;
8use log::*; 8use log::*;
9use rand_core::{OsRng, RngCore}; 9use rand_core::{OsRng, RngCore};
10use static_cell::StaticCell; 10use static_cell::{make_static, StaticCell};
11 11
12#[path = "../tuntap.rs"] 12#[path = "../tuntap.rs"]
13mod tuntap; 13mod tuntap;
14 14
15use crate::tuntap::TunTapDevice; 15use crate::tuntap::TunTapDevice;
16
17macro_rules! singleton {
18 ($val:expr) => {{
19 type T = impl Sized;
20 static STATIC_CELL: StaticCell<T> = StaticCell::new();
21 STATIC_CELL.init_with(move || $val)
22 }};
23}
24
25#[derive(Parser)] 16#[derive(Parser)]
26#[clap(version = "1.0")] 17#[clap(version = "1.0")]
27struct Opts { 18struct Opts {
@@ -47,13 +38,13 @@ async fn main_task(spawner: Spawner) {
47 38
48 // Choose between dhcp or static ip 39 // Choose between dhcp or static ip
49 let config = if opts.static_ip { 40 let config = if opts.static_ip {
50 ConfigStrategy::Static(embassy_net::Config { 41 Config::ipv4_static(embassy_net::StaticConfigV4 {
51 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), 42 address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
52 dns_servers: Vec::new(), 43 dns_servers: Vec::new(),
53 gateway: Some(Ipv4Address::new(192, 168, 69, 1)), 44 gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
54 }) 45 })
55 } else { 46 } else {
56 ConfigStrategy::Dhcp 47 Config::dhcpv4(Default::default())
57 }; 48 };
58 49
59 // Generate random seed 50 // Generate random seed
@@ -62,10 +53,10 @@ async fn main_task(spawner: Spawner) {
62 let seed = u64::from_le_bytes(seed); 53 let seed = u64::from_le_bytes(seed);
63 54
64 // Init network stack 55 // Init network stack
65 let stack = &*singleton!(Stack::new( 56 let stack = &*make_static!(Stack::new(
66 device, 57 device,
67 config, 58 config,
68 singleton!(StackResources::<1, 2, 8>::new()), 59 make_static!(StackResources::<3>::new()),
69 seed 60 seed
70 )); 61 ));
71 62