aboutsummaryrefslogtreecommitdiff
path: root/embassy-net
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-01-10 14:06:15 +0100
committerDario Nieuwenhuis <[email protected]>2024-01-10 14:06:15 +0100
commit01b0af5a84409a13264d799a8156bb965ad7989f (patch)
treebe6018abc7ac2924bf4793a6e49d016110ac4280 /embassy-net
parent0027a76bb61f19fcae1fe588ba3ff62660d7f7e3 (diff)
net: add packet-trace feature.
Diffstat (limited to 'embassy-net')
-rw-r--r--embassy-net/Cargo.toml3
-rw-r--r--embassy-net/src/device.rs13
2 files changed, 14 insertions, 2 deletions
diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml
index 67f0bd028..864956616 100644
--- a/embassy-net/Cargo.toml
+++ b/embassy-net/Cargo.toml
@@ -28,6 +28,9 @@ std = []
28## Enable defmt 28## Enable defmt
29defmt = ["dep:defmt", "smoltcp/defmt", "embassy-net-driver/defmt", "heapless/defmt-03"] 29defmt = ["dep:defmt", "smoltcp/defmt", "embassy-net-driver/defmt", "heapless/defmt-03"]
30 30
31## Trace all raw received and transmitted packets using defmt or log.
32packet-trace = []
33
31#! Many of the following feature flags are re-exports of smoltcp feature flags. See 34#! Many of the following feature flags are re-exports of smoltcp feature flags. See
32#! the [smoltcp feature flag documentation](https://github.com/smoltcp-rs/smoltcp#feature-flags) 35#! the [smoltcp feature flag documentation](https://github.com/smoltcp-rs/smoltcp#feature-flags)
33#! for more details 36#! for more details
diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs
index 54a0c47e8..3b1d3c47c 100644
--- a/embassy-net/src/device.rs
+++ b/embassy-net/src/device.rs
@@ -76,7 +76,11 @@ where
76 where 76 where
77 F: FnOnce(&mut [u8]) -> R, 77 F: FnOnce(&mut [u8]) -> R,
78 { 78 {
79 self.0.consume(|buf| f(buf)) 79 self.0.consume(|buf| {
80 #[cfg(feature = "packet-trace")]
81 trace!("rx: {:?}", buf);
82 f(buf)
83 })
80 } 84 }
81} 85}
82 86
@@ -92,6 +96,11 @@ where
92 where 96 where
93 F: FnOnce(&mut [u8]) -> R, 97 F: FnOnce(&mut [u8]) -> R,
94 { 98 {
95 self.0.consume(len, |buf| f(buf)) 99 self.0.consume(len, |buf| {
100 let r = f(buf);
101 #[cfg(feature = "packet-trace")]
102 trace!("tx: {:?}", buf);
103 r
104 })
96 } 105 }
97} 106}