Fixed commented issues.

This commit is contained in:
Gustav Toft 2024-04-10 09:07:20 +02:00
parent a373633d0d
commit 6663be0b36
4 changed files with 13 additions and 71 deletions

12
.vscode/settings.json vendored
View File

@ -10,24 +10,24 @@
"rust-analyzer.cargo.noDefaultFeatures": true, "rust-analyzer.cargo.noDefaultFeatures": true,
"rust-analyzer.showUnlinkedFileNotification": false, "rust-analyzer.showUnlinkedFileNotification": false,
// uncomment the target of your chip. // 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": "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.target": "thumbv8m.main-none-eabihf",
"rust-analyzer.cargo.features": [ /* "rust-analyzer.cargo.features": [
"stm32f103c8", "stm32f103c8",
"time-driver-any", "time-driver-any",
"unstable-pac", "unstable-pac",
"exti", "exti",
], ], */
"rust-analyzer.linkedProjects": [ "rust-analyzer.linkedProjects": [
// Uncomment ONE line for the chip you want to work on. // Uncomment ONE line for the chip you want to work on.
// This makes rust-analyzer work on the example crate and all its dependencies. // 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/nrf52840-rtic/Cargo.toml",
// "examples/nrf5340/Cargo.toml", // "examples/nrf5340/Cargo.toml",
// "examples/nrf-rtos-trace/Cargo.toml", // "examples/nrf-rtos-trace/Cargo.toml",
// "examples/rp/Cargo.toml", "examples/rp/Cargo.toml",
// "examples/std/Cargo.toml", // "examples/std/Cargo.toml",
// "examples/stm32c0/Cargo.toml", // "examples/stm32c0/Cargo.toml",
// "examples/stm32f0/Cargo.toml", // "examples/stm32f0/Cargo.toml",

View File

@ -15,13 +15,13 @@ pub(crate) mod fmt;
mod device; mod device;
#[cfg(feature = "dns")] #[cfg(feature = "dns")]
pub mod dns; pub mod dns;
#[cfg(feature = "raw")]
pub mod raw;
#[cfg(feature = "tcp")] #[cfg(feature = "tcp")]
pub mod tcp; pub mod tcp;
mod time; mod time;
#[cfg(feature = "udp")] #[cfg(feature = "udp")]
pub mod udp; pub mod udp;
#[cfg(feature = "raw")]
pub mod raw;
use core::cell::RefCell; use core::cell::RefCell;
use core::future::{poll_fn, Future}; use core::future::{poll_fn, Future};

View File

@ -13,28 +13,6 @@ use smoltcp::wire::{IpProtocol, IpVersion};
use crate::{SocketStack, Stack}; 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`]. /// Error returned by [`RawSocket::recv`] and [`RawSocket::send`].
#[derive(PartialEq, Eq, Clone, Copy, Debug)] #[derive(PartialEq, Eq, Clone, Copy, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
@ -87,42 +65,6 @@ impl<'a> RawSocket<'a> {
res res
} }
/// Bind the socket to a local endpoint.
///
/// How to handle this in RawSocket? no need for bind?
///
/* pub fn bind<T>(&mut self, endpoint: T) -> Result<(), BindError>
where
T: Into<IpListenEndpoint>,
{
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<R>(&self, f: impl FnOnce(&raw::Socket, &Interface) -> R) -> R {
let s = &*self.stack.borrow();
let socket = s.sockets.get::<raw::Socket>(self.handle);
f(socket, &s.iface)
}
fn with_mut<R>(&self, f: impl FnOnce(&mut raw::Socket, &mut Interface) -> R) -> R {
let s = &mut *self.stack.borrow_mut();
let socket = s.sockets.get_mut::<raw::Socket>(self.handle);
let res = f(socket, &mut s.iface);
s.waker.wake();
res
} */
/// Receive a datagram. /// Receive a datagram.
/// ///
/// This method will wait until a datagram is received. /// This method will wait until a datagram is received.
@ -149,7 +91,7 @@ impl<'a> RawSocket<'a> {
/// Send a datagram. /// Send a datagram.
/// ///
/// This method will wait until the datagram has been sent.` /// This method will wait until the datagram has been sent.`
pub async fn send<T>(&self, buf: &[u8]) -> Result<(), SendError> { pub async fn send<T>(&self, buf: &[u8]) -> Result<(), raw::SendError> {
poll_fn(move |cx| self.poll_send(buf, cx)).await 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` /// 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. /// 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<Result<(), SendError>>{ pub fn poll_send(&self, buf: &[u8], cx: &mut Context<'_>) -> Poll<Result<(), raw::SendError>> {
self.with_mut(|s, _| match s.send_slice(buf) { self.with_mut(|s, _| match s.send_slice(buf) {
// Entire datagram has been sent // Entire datagram has been sent
Ok(()) => Poll::Ready(Ok(())), Ok(()) => Poll::Ready(Ok(())),