From 6663be0b36a078893b0ef3f3f869b17adf62ca30 Mon Sep 17 00:00:00 2001 From: Gustav Toft Date: Wed, 10 Apr 2024 09:07:20 +0200 Subject: [PATCH] Fixed commented issues. --- .vscode/settings.json | 12 ++++---- embassy-net/Cargo.toml | 4 +-- embassy-net/src/lib.rs | 4 +-- embassy-net/src/raw.rs | 64 ++---------------------------------------- 4 files changed, 13 insertions(+), 71 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 0c195a13b..343331950 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,24 +10,24 @@ "rust-analyzer.cargo.noDefaultFeatures": true, "rust-analyzer.showUnlinkedFileNotification": false, // uncomment the target of your chip. - //"rust-analyzer.cargo.target": "thumbv6m-none-eabi", + "rust-analyzer.cargo.target": "thumbv6m-none-eabi", //"rust-analyzer.cargo.target": "thumbv7m-none-eabi", - "rust-analyzer.cargo.target": "thumbv7em-none-eabi", + //"rust-analyzer.cargo.target": "thumbv7em-none-eabi", //"rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf", - "rust-analyzer.cargo.features": [ + /* "rust-analyzer.cargo.features": [ "stm32f103c8", "time-driver-any", "unstable-pac", "exti", - ], + ], */ "rust-analyzer.linkedProjects": [ // Uncomment ONE line for the chip you want to work on. // This makes rust-analyzer work on the example crate and all its dependencies. - "embassy-stm32/Cargo.toml", + // "embassy-stm32/Cargo.toml", // "examples/nrf52840-rtic/Cargo.toml", // "examples/nrf5340/Cargo.toml", // "examples/nrf-rtos-trace/Cargo.toml", - // "examples/rp/Cargo.toml", + "examples/rp/Cargo.toml", // "examples/std/Cargo.toml", // "examples/stm32c0/Cargo.toml", // "examples/stm32f0/Cargo.toml", diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index 47faaa205..ee7289ad8 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml @@ -16,11 +16,11 @@ categories = [ [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-v$VERSION/embassy-net/src/" src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-net/src/" -features = ["defmt", "tcp", "udp","raw", "dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip", "medium-ieee802154", "igmp", "dhcpv4-hostname"] +features = ["defmt", "tcp", "udp", "raw", "dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip", "medium-ieee802154", "igmp", "dhcpv4-hostname"] target = "thumbv7em-none-eabi" [package.metadata.docs.rs] -features = ["defmt", "tcp", "udp", "raw","dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip", "medium-ieee802154", "igmp", "dhcpv4-hostname"] +features = ["defmt", "tcp", "udp", "raw", "dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip", "medium-ieee802154", "igmp", "dhcpv4-hostname"] [features] default = [] diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index 05c8aec7b..86ced1ded 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs @@ -15,13 +15,13 @@ pub(crate) mod fmt; mod device; #[cfg(feature = "dns")] pub mod dns; +#[cfg(feature = "raw")] +pub mod raw; #[cfg(feature = "tcp")] pub mod tcp; mod time; #[cfg(feature = "udp")] pub mod udp; -#[cfg(feature = "raw")] -pub mod raw; use core::cell::RefCell; use core::future::{poll_fn, Future}; diff --git a/embassy-net/src/raw.rs b/embassy-net/src/raw.rs index a0e458fff..ad8d69853 100644 --- a/embassy-net/src/raw.rs +++ b/embassy-net/src/raw.rs @@ -13,28 +13,6 @@ use smoltcp::wire::{IpProtocol, IpVersion}; use crate::{SocketStack, Stack}; - -/// Unrelavent for RawSocket? -/* /// Error returned by [`RawSocket::bind`]. -#[derive(PartialEq, Eq, Clone, Copy, Debug)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum BindError { - /// The socket was already open. - InvalidState, - /// No route to host. - NoRoute, -} */ - -/// Error returned by [`RawSocket::recv_from`] and [`RawSocket::send_to`]. -#[derive(PartialEq, Eq, Clone, Copy, Debug)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum SendError { - /// No route to host. - NoRoute, - /// Socket not bound to an outgoing port. - SocketNotBound, -} - /// Error returned by [`RawSocket::recv`] and [`RawSocket::send`]. #[derive(PartialEq, Eq, Clone, Copy, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -87,42 +65,6 @@ impl<'a> RawSocket<'a> { res } - /// Bind the socket to a local endpoint. - /// - /// How to handle this in RawSocket? no need for bind? - /// - /* pub fn bind(&mut self, endpoint: T) -> Result<(), BindError> - where - T: Into, - { - let mut endpoint = endpoint.into(); - - if endpoint.port == 0 { - // If user didn't specify port allocate a dynamic port. - endpoint.port = self.stack.borrow_mut().get_local_port(); - } - - match self.with_mut(|s, _| s.bind(endpoint)) { - Ok(()) => Ok(()), - Err(raw::BindError::InvalidState) => Err(BindError::InvalidState), - Err(raw::BindError::Unaddressable) => Err(BindError::NoRoute), - } - } - - fn with(&self, f: impl FnOnce(&raw::Socket, &Interface) -> R) -> R { - let s = &*self.stack.borrow(); - let socket = s.sockets.get::(self.handle); - f(socket, &s.iface) - } - - fn with_mut(&self, f: impl FnOnce(&mut raw::Socket, &mut Interface) -> R) -> R { - let s = &mut *self.stack.borrow_mut(); - let socket = s.sockets.get_mut::(self.handle); - let res = f(socket, &mut s.iface); - s.waker.wake(); - res - } */ - /// Receive a datagram. /// /// This method will wait until a datagram is received. @@ -149,7 +91,7 @@ impl<'a> RawSocket<'a> { /// Send a datagram. /// /// This method will wait until the datagram has been sent.` - pub async fn send(&self, buf: &[u8]) -> Result<(), SendError> { + pub async fn send(&self, buf: &[u8]) -> Result<(), raw::SendError> { poll_fn(move |cx| self.poll_send(buf, cx)).await } @@ -159,7 +101,7 @@ impl<'a> RawSocket<'a> { /// /// When the socket's send buffer is full, this method will return `Poll::Pending` /// and register the current task to be notified when the buffer has space available. - pub fn poll_send(&self, buf: &[u8], cx: &mut Context<'_>) -> Poll>{ + pub fn poll_send(&self, buf: &[u8], cx: &mut Context<'_>) -> Poll> { self.with_mut(|s, _| match s.send_slice(buf) { // Entire datagram has been sent Ok(()) => Poll::Ready(Ok(())), @@ -169,7 +111,7 @@ impl<'a> RawSocket<'a> { } }) } - } +} impl Drop for RawSocket<'_> { fn drop(&mut self) {