aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorskkeye <[email protected]>2025-02-09 02:11:15 -0500
committerUlf Lilleengen <[email protected]>2025-02-13 10:27:30 +0100
commitbdb1b812135b7cb22f65009242d5b61712e8e9d7 (patch)
treed0b0af875006b05eb38bf54408fb9feff745a2cc
parent38b5f8bd0afd9669e638b8d83210427d2d372a96 (diff)
fix: nightly fmt
-rw-r--r--embassy-net/src/icmp.rs33
-rw-r--r--embassy-net/src/lib.rs4
-rw-r--r--examples/rp/src/bin/ethernet_w5500_icmp.rs25
-rw-r--r--examples/rp/src/bin/ethernet_w5500_icmp_ping.rs4
4 files changed, 34 insertions, 32 deletions
diff --git a/embassy-net/src/icmp.rs b/embassy-net/src/icmp.rs
index 4cce5db50..ba206a465 100644
--- a/embassy-net/src/icmp.rs
+++ b/embassy-net/src/icmp.rs
@@ -252,24 +252,24 @@ impl Drop for IcmpSocket<'_> {
252 252
253pub mod ping { 253pub mod ping {
254 //! Ping utilities. 254 //! Ping utilities.
255 //! 255 //!
256 //! This module allows for an easy ICMP Echo message interface used to 256 //! This module allows for an easy ICMP Echo message interface used to
257 //! ping devices with an [ICMP Socket](IcmpSocket). 257 //! ping devices with an [ICMP Socket](IcmpSocket).
258 //! 258 //!
259 //! ## Usage 259 //! ## Usage
260 //! 260 //!
261 //! ``` 261 //! ```
262 //! use core::net::Ipv4Addr; 262 //! use core::net::Ipv4Addr;
263 //! use core::str::FromStr; 263 //! use core::str::FromStr;
264 //! 264 //!
265 //! use embassy_net::icmp::ping::{PingManager, PingParams}; 265 //! use embassy_net::icmp::ping::{PingManager, PingParams};
266 //! use embassy_net::icmp::PacketMetadata; 266 //! use embassy_net::icmp::PacketMetadata;
267 //! 267 //!
268 //! let mut rx_buffer = [0; 256]; 268 //! let mut rx_buffer = [0; 256];
269 //! let mut tx_buffer = [0; 256]; 269 //! let mut tx_buffer = [0; 256];
270 //! let mut rx_meta = [PacketMetadata::EMPTY]; 270 //! let mut rx_meta = [PacketMetadata::EMPTY];
271 //! let mut tx_meta = [PacketMetadata::EMPTY]; 271 //! let mut tx_meta = [PacketMetadata::EMPTY];
272 //! 272 //!
273 //! let mut ping_manager = PingManager::new(stack, &mut rx_meta, &mut rx_buffer, &mut tx_meta, &mut tx_buffer); 273 //! let mut ping_manager = PingManager::new(stack, &mut rx_meta, &mut rx_buffer, &mut tx_meta, &mut tx_buffer);
274 //! let addr = "192.168.8.1"; 274 //! let addr = "192.168.8.1";
275 //! let mut ping_params = PingParams::new(Ipv4Addr::from_str(addr).unwrap()); 275 //! let mut ping_params = PingParams::new(Ipv4Addr::from_str(addr).unwrap());
@@ -280,16 +280,18 @@ pub mod ping {
280 //! }; 280 //! };
281 //! ``` 281 //! ```
282 282
283 use super::*;
284 use core::net::{IpAddr, Ipv6Addr}; 283 use core::net::{IpAddr, Ipv6Addr};
284
285 use embassy_time::{Duration, Instant, Timer, WithTimeout}; 285 use embassy_time::{Duration, Instant, Timer, WithTimeout};
286 286
287 use super::*;
288
287 /// Error returned by [`ping()`](PingManager::ping). 289 /// Error returned by [`ping()`](PingManager::ping).
288 #[derive(PartialEq, Eq, Clone, Copy, Debug)] 290 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
289 #[cfg_attr(feature = "defmt", derive(defmt::Format))] 291 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
290 pub enum PingError { 292 pub enum PingError {
291 /// The target did not respond. 293 /// The target did not respond.
292 /// 294 ///
293 /// The packet was sent but the Reply packet has not been recieved 295 /// The packet was sent but the Reply packet has not been recieved
294 /// in the timeout set by [`set_timeout()`](PingParams::set_timeout). 296 /// in the timeout set by [`set_timeout()`](PingParams::set_timeout).
295 DestinationHostUnreachable, 297 DestinationHostUnreachable,
@@ -339,7 +341,7 @@ pub mod ping {
339 impl<'d> PingManager<'d> { 341 impl<'d> PingManager<'d> {
340 /// Creates a new instance of [`PingManager`] with a [`Stack`] instance 342 /// Creates a new instance of [`PingManager`] with a [`Stack`] instance
341 /// and the buffers used for RX and TX. 343 /// and the buffers used for RX and TX.
342 /// 344 ///
343 /// **note**: This does not yet creates the ICMP socket. 345 /// **note**: This does not yet creates the ICMP socket.
344 pub fn new( 346 pub fn new(
345 stack: Stack<'d>, 347 stack: Stack<'d>,
@@ -387,7 +389,7 @@ pub mod ping {
387 // Make sure each ping takes at least 1 second to respect standards 389 // Make sure each ping takes at least 1 second to respect standards
388 let rate_limit_start = Instant::now(); 390 let rate_limit_start = Instant::now();
389 391
390 // make a single ping 392 // make a single ping
391 // - shorts out errors 393 // - shorts out errors
392 // - select the ip version 394 // - select the ip version
393 let ping_duration = match params.target().unwrap() { 395 let ping_duration = match params.target().unwrap() {
@@ -564,7 +566,6 @@ pub mod ping {
564 } 566 }
565 } 567 }
566 568
567
568 /// Parameters for configuring the ping operation. 569 /// Parameters for configuring the ping operation.
569 /// 570 ///
570 /// This struct provides various configuration options for performing ICMP ping operations, 571 /// This struct provides various configuration options for performing ICMP ping operations,
@@ -653,7 +654,7 @@ pub mod ping {
653 } 654 }
654 655
655 /// Sets the hop limit that will be used by the socket with [`set_hop_limit()`](IcmpSocket::set_hop_limit). 656 /// Sets the hop limit that will be used by the socket with [`set_hop_limit()`](IcmpSocket::set_hop_limit).
656 /// 657 ///
657 /// **Note**: A hop limit of [`Some(0)`](Some()) is equivalent to a hop limit of [`None`]. 658 /// **Note**: A hop limit of [`Some(0)`](Some()) is equivalent to a hop limit of [`None`].
658 pub fn set_hop_limit(&mut self, hop_limit: Option<u8>) -> &mut Self { 659 pub fn set_hop_limit(&mut self, hop_limit: Option<u8>) -> &mut Self {
659 let mut hop_limit = hop_limit; 660 let mut hop_limit = hop_limit;
@@ -669,9 +670,9 @@ pub mod ping {
669 self.hop_limit 670 self.hop_limit
670 } 671 }
671 672
672 /// Sets the count used for specifying the number of pings done on one 673 /// Sets the count used for specifying the number of pings done on one
673 /// [`ping()`](PingManager::ping) call. 674 /// [`ping()`](PingManager::ping) call.
674 /// 675 ///
675 /// **Note**: A count of 0 will be set as 1. 676 /// **Note**: A count of 0 will be set as 1.
676 pub fn set_count(&mut self, count: u16) -> &mut Self { 677 pub fn set_count(&mut self, count: u16) -> &mut Self {
677 let mut count = count; 678 let mut count = count;
@@ -682,7 +683,7 @@ pub mod ping {
682 self 683 self
683 } 684 }
684 685
685 /// Retrieve the count used for specifying the number of pings done on one 686 /// Retrieve the count used for specifying the number of pings done on one
686 /// [`ping()`](PingManager::ping) call. 687 /// [`ping()`](PingManager::ping) call.
687 pub fn count(&self) -> u16 { 688 pub fn count(&self) -> u16 {
688 self.count 689 self.count
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs
index 1bb112252..693a39ed5 100644
--- a/embassy-net/src/lib.rs
+++ b/embassy-net/src/lib.rs
@@ -15,6 +15,8 @@ pub(crate) mod fmt;
15#[cfg(feature = "dns")] 15#[cfg(feature = "dns")]
16pub mod dns; 16pub mod dns;
17mod driver_util; 17mod driver_util;
18#[cfg(feature = "icmp")]
19pub mod icmp;
18#[cfg(feature = "raw")] 20#[cfg(feature = "raw")]
19pub mod raw; 21pub mod raw;
20#[cfg(feature = "tcp")] 22#[cfg(feature = "tcp")]
@@ -22,8 +24,6 @@ pub mod tcp;
22mod time; 24mod time;
23#[cfg(feature = "udp")] 25#[cfg(feature = "udp")]
24pub mod udp; 26pub mod udp;
25#[cfg(feature = "icmp")]
26pub mod icmp;
27 27
28use core::cell::RefCell; 28use core::cell::RefCell;
29use core::future::{poll_fn, Future}; 29use core::future::{poll_fn, Future};
diff --git a/examples/rp/src/bin/ethernet_w5500_icmp.rs b/examples/rp/src/bin/ethernet_w5500_icmp.rs
index a07cdf88d..5f336b579 100644
--- a/examples/rp/src/bin/ethernet_w5500_icmp.rs
+++ b/examples/rp/src/bin/ethernet_w5500_icmp.rs
@@ -1,5 +1,5 @@
1//! This example implements an echo (ping) with an ICMP Socket and using defmt to report the results. 1//! This example implements an echo (ping) with an ICMP Socket and using defmt to report the results.
2//! 2//!
3//! Although there is a better way to execute pings using the child module ping of the icmp module, 3//! Although there is a better way to execute pings using the child module ping of the icmp module,
4//! this example allows for other icmp messages like `Destination unreachable` to be sent aswell. 4//! this example allows for other icmp messages like `Destination unreachable` to be sent aswell.
5//! 5//!
@@ -106,16 +106,12 @@ async fn main(spawner: Spawner) {
106 106
107 // Send the packet and store the starting instant to mesure latency later 107 // Send the packet and store the starting instant to mesure latency later
108 let start = socket 108 let start = socket
109 .send_to_with( 109 .send_to_with(icmp_repr.buffer_len(), cfg.gateway.unwrap(), |buf| {
110 icmp_repr.buffer_len(), 110 // Create and populate the packet buffer allocated by `send_to_with`
111 cfg.gateway.unwrap(), 111 let mut icmp_packet = Icmpv4Packet::new_unchecked(buf);
112 |buf| { 112 icmp_repr.emit(&mut icmp_packet, &ChecksumCapabilities::default());
113 // Create and populate the packet buffer allocated by `send_to_with` 113 Instant::now() // Return the instant where the packet was sent
114 let mut icmp_packet = Icmpv4Packet::new_unchecked(buf); 114 })
115 icmp_repr.emit(&mut icmp_packet, &ChecksumCapabilities::default());
116 Instant::now() // Return the instant where the packet was sent
117 },
118 )
119 .await 115 .await
120 .unwrap(); 116 .unwrap();
121 117
@@ -123,7 +119,12 @@ async fn main(spawner: Spawner) {
123 socket 119 socket
124 .recv_with(|(buf, addr)| { 120 .recv_with(|(buf, addr)| {
125 let packet = Icmpv4Packet::new_checked(buf).unwrap(); 121 let packet = Icmpv4Packet::new_checked(buf).unwrap();
126 info!("Recieved {:?} from {} in {}ms", packet.data(), addr, start.elapsed().as_millis()); 122 info!(
123 "Recieved {:?} from {} in {}ms",
124 packet.data(),
125 addr,
126 start.elapsed().as_millis()
127 );
127 }) 128 })
128 .await 129 .await
129 .unwrap(); 130 .unwrap();
diff --git a/examples/rp/src/bin/ethernet_w5500_icmp_ping.rs b/examples/rp/src/bin/ethernet_w5500_icmp_ping.rs
index 0d83e3831..0724311f9 100644
--- a/examples/rp/src/bin/ethernet_w5500_icmp_ping.rs
+++ b/examples/rp/src/bin/ethernet_w5500_icmp_ping.rs
@@ -100,7 +100,7 @@ async fn main(spawner: Spawner) {
100 // Create the ping manager instance 100 // Create the ping manager instance
101 let mut ping_manager = PingManager::new(stack, &mut rx_meta, &mut rx_buffer, &mut tx_meta, &mut tx_buffer); 101 let mut ping_manager = PingManager::new(stack, &mut rx_meta, &mut rx_buffer, &mut tx_meta, &mut tx_buffer);
102 let addr = "192.168.8.1"; // Address to ping to 102 let addr = "192.168.8.1"; // Address to ping to
103 // Create the PingParams with the target address 103 // Create the PingParams with the target address
104 let mut ping_params = PingParams::new(Ipv4Addr::from_str(addr).unwrap()); 104 let mut ping_params = PingParams::new(Ipv4Addr::from_str(addr).unwrap());
105 // (optional) Set custom properties of the ping 105 // (optional) Set custom properties of the ping
106 ping_params.set_payload(b"Hello, Ping!"); // custom payload 106 ping_params.set_payload(b"Hello, Ping!"); // custom payload
@@ -118,7 +118,7 @@ async fn main(spawner: Spawner) {
118 Ok(time) => { 118 Ok(time) => {
119 info!("{} is online\n- latency: {}ms\n", ip_addr, time.as_millis()); 119 info!("{} is online\n- latency: {}ms\n", ip_addr, time.as_millis());
120 total_online_hosts += 1; 120 total_online_hosts += 1;
121 }, 121 }
122 _ => continue, 122 _ => continue,
123 } 123 }
124 } 124 }