net: add packet-trace feature.

This commit is contained in:
Dario Nieuwenhuis 2024-01-10 14:06:15 +01:00
parent 0027a76bb6
commit 01b0af5a84
3 changed files with 15 additions and 3 deletions

2
ci.sh
View file

@ -35,7 +35,7 @@ cargo batch \
--- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features arch-riscv32,executor-thread,integrated-timers \
--- build --release --manifest-path embassy-sync/Cargo.toml --target thumbv6m-none-eabi --features defmt \
--- build --release --manifest-path embassy-time/Cargo.toml --target thumbv6m-none-eabi --features defmt,defmt-timestamp-uptime,generic-queue-8,mock-driver \
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,medium-ethernet \
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,medium-ethernet,packet-trace \
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,igmp,medium-ethernet \
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet \
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,dhcpv4-hostname \

View file

@ -28,6 +28,9 @@ std = []
## Enable defmt
defmt = ["dep:defmt", "smoltcp/defmt", "embassy-net-driver/defmt", "heapless/defmt-03"]
## Trace all raw received and transmitted packets using defmt or log.
packet-trace = []
#! Many of the following feature flags are re-exports of smoltcp feature flags. See
#! the [smoltcp feature flag documentation](https://github.com/smoltcp-rs/smoltcp#feature-flags)
#! for more details

View file

@ -76,7 +76,11 @@ where
where
F: FnOnce(&mut [u8]) -> R,
{
self.0.consume(|buf| f(buf))
self.0.consume(|buf| {
#[cfg(feature = "packet-trace")]
trace!("rx: {:?}", buf);
f(buf)
})
}
}
@ -92,6 +96,11 @@ where
where
F: FnOnce(&mut [u8]) -> R,
{
self.0.consume(len, |buf| f(buf))
self.0.consume(len, |buf| {
let r = f(buf);
#[cfg(feature = "packet-trace")]
trace!("tx: {:?}", buf);
r
})
}
}