From d844a116d5f82693d28b317be9cacb41dc7da9a2 Mon Sep 17 00:00:00 2001 From: Jonah Dahlquist Date: Tue, 19 Jan 2021 13:06:25 -0800 Subject: [PATCH] Updated to latest embedded-nal --- Cargo.toml | 2 +- src/udp.rs | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c9f162d..c8bd57e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,6 @@ edition = "2018" [dependencies] byteorder = { version = "1.3.4", default-features = false } embedded-hal = "0.2.4" -embedded-nal = "0.2.0" +embedded-nal = { git = "https://github.com/rust-embedded-community/embedded-nal.git", rev = "0bc4d77" } bit_field = "0.10.1" nb = "1.0.0" diff --git a/src/udp.rs b/src/udp.rs index 266788a..c17ff6a 100644 --- a/src/udp.rs +++ b/src/udp.rs @@ -4,7 +4,7 @@ use crate::interface::Interface; use crate::register::socketn; use crate::socket::Socket; use core::fmt::Debug; -use embedded_nal::{nb, IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4, UdpClient, UdpServer}; +use embedded_nal::{nb, IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4, UdpClientStack, UdpFullStack}; pub struct UdpSocket { socket: Socket, @@ -178,7 +178,7 @@ impl From> for nb::Error { } } -impl UdpClient for Interface +impl UdpClientStack for Interface where SpiBus: ActiveBus, HostImpl: Host, @@ -186,7 +186,7 @@ where type UdpSocket = UdpSocket; type Error = UdpSocketError; - fn socket(&self) -> Result { + fn socket(&mut self) -> Result { let mut device = self.device.borrow_mut(); if let Some(socket) = device.take_socket() { Ok(UdpSocket::new(socket)) @@ -195,7 +195,11 @@ where } } - fn connect(&self, socket: &mut Self::UdpSocket, remote: SocketAddr) -> Result<(), Self::Error> { + fn connect( + &mut self, + socket: &mut Self::UdpSocket, + remote: SocketAddr, + ) -> Result<(), Self::Error> { let mut device = self.device.borrow_mut(); if let SocketAddr::V4(remote) = remote { // TODO find a random port @@ -206,18 +210,18 @@ where Err(Self::Error::UnsupportedAddress) } } - fn send(&self, socket: &mut Self::UdpSocket, buffer: &[u8]) -> nb::Result<(), Self::Error> { + fn send(&mut self, socket: &mut Self::UdpSocket, buffer: &[u8]) -> nb::Result<(), Self::Error> { socket.send(&mut self.device.borrow_mut().bus, buffer)?; Ok(()) } fn receive( - &self, + &mut self, socket: &mut Self::UdpSocket, buffer: &mut [u8], ) -> nb::Result<(usize, SocketAddr), Self::Error> { Ok(socket.receive(&mut self.device.borrow_mut().bus, buffer)?) } - fn close(&self, socket: Self::UdpSocket) -> Result<(), Self::Error> { + fn close(&mut self, socket: Self::UdpSocket) -> Result<(), Self::Error> { let mut device = self.device.borrow_mut(); socket.close(&mut device.bus)?; device.release_socket(socket.socket); @@ -225,18 +229,18 @@ where } } -impl UdpServer for Interface +impl UdpFullStack for Interface where SpiBus: ActiveBus, HostImpl: Host, { - fn bind(&self, socket: &mut Self::UdpSocket, local_port: u16) -> Result<(), Self::Error> { + fn bind(&mut self, socket: &mut Self::UdpSocket, local_port: u16) -> Result<(), Self::Error> { let mut device = self.device.borrow_mut(); socket.open(&mut device.bus, local_port)?; Ok(()) } fn send_to( - &self, + &mut self, socket: &mut Self::UdpSocket, remote: SocketAddr, buffer: &[u8],