Skip to content

Commit

Permalink
Update demos for embassy-net
Browse files Browse the repository at this point in the history
Removes some duplication between cyw43 vs w5500
  • Loading branch information
mkj committed Nov 29, 2024
1 parent 2f5e510 commit b1d2c83
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 180 deletions.
116 changes: 33 additions & 83 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion embassy/demos/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sunset = { path = "../../.." }
sunset-sshwire-derive = { path = "../../../sshwire-derive" }

embassy-sync = { version = "0.5" }
embassy-net = { version = "0.4", features = ["tcp", "dhcpv4", "medium-ethernet", "log"] }
embassy-net = { version = "0.5", features = ["tcp", "dhcpv4", "medium-ethernet", "log"] }
embassy-net-driver = { version = "0.2" }
embassy-futures = { version = "0.1" }
embassy-time = { version = "0.3" }
Expand Down
18 changes: 9 additions & 9 deletions embassy/demos/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ where
fn enc_ip4config(v: &Option<StaticConfigV4>, s: &mut dyn SSHSink) -> WireResult<()> {
v.is_some().enc(s)?;
if let Some(v) = v {
v.address.address().0.enc(s)?;
v.address.address().to_bits().enc(s)?;
v.address.prefix_len().enc(s)?;
// to [u8; 4]
let gw = v.gateway.map(|a| a.0);
// to u32
let gw = v.gateway.map(|a| a.to_bits());
enc_option(&gw, s)?;
}
Ok(())
Expand All @@ -171,15 +171,15 @@ where
{
let opt = bool::dec(s)?;
opt.then(|| {
let ad: [u8; 4] = SSHDecode::dec(s)?;
let ad = Ipv4Address::from_bytes(&ad);
let ad: u32 = SSHDecode::dec(s)?;
let ad = Ipv4Address::from_bits(ad);
let prefix = SSHDecode::dec(s)?;
if prefix > 32 {
// emabassy panics, so test it here
return Err(WireError::PacketWrong)
}
let gw: Option<[u8; 4]> = dec_option(s)?;
let gateway = gw.map(|gw| Ipv4Address::from_bytes(&gw));
let gw: Option<u32> = dec_option(s)?;
let gateway = gw.map(|gw| Ipv4Address::from_bits(gw));
Ok(StaticConfigV4 {
address: Ipv4Cidr::new(ad, prefix),
gateway,
Expand Down Expand Up @@ -364,8 +364,8 @@ mod tests {
),
mac: [6, 2, 3, 4, 5, 6],
ip4_static: Some(embassy_net::StaticConfigV4 {
address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address([44,33,22,11]), 8),
gateway: Some(embassy_net::Ipv4Address([1,2,3,4])),
address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address::new(44,33,22,11), 8),
gateway: Some(embassy_net::Ipv4Address::new(1,2,3,4)),
// no dns servers. may need changing later?
dns_servers: heapless::Vec::new(),
}),
Expand Down
3 changes: 1 addition & 2 deletions embassy/demos/common/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use log::{debug, error, info, log, trace, warn};

use embassy_net::tcp::TcpSocket;
use embassy_net::Stack;
use embassy_net_driver::Driver;
use embassy_futures::select::{select, Either};

use embedded_io_async::Write;
Expand All @@ -17,7 +16,7 @@ use sunset_embassy::{SSHServer, SunsetMutex};
use crate::SSHConfig;

// common entry point
pub async fn listener<D: Driver, S: DemoServer>(stack: &'static Stack<D>,
pub async fn listener<S: DemoServer>(stack: Stack<'_>,
config: &SunsetMutex<SSHConfig>,
init: S::Init) -> ! {
// TODO: buffer size?
Expand Down
2 changes: 1 addition & 1 deletion embassy/demos/picow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ embassy-executor = { version = "0.5", features = [
"task-arena-size-131072"] }
embassy-time = { version = "0.3", features = [] }
embassy-rp = { version = "0.1", features = ["unstable-pac", "time-driver"] }
embassy-net = { version = "0.4", features = ["tcp", "dhcpv4", "medium-ethernet", "log"] }
embassy-net = { version = "0.5", features = ["tcp", "dhcpv4", "medium-ethernet", "log"] }
embassy-net-driver = { version = "0.2" }
embassy-usb-driver = { version = "0.1" }
embassy-sync = { version = "0.5" }
Expand Down
Loading

0 comments on commit b1d2c83

Please sign in to comment.