Updated to latest embedded-nal
This commit is contained in:
parent
9a057190a8
commit
d844a116d5
2 changed files with 15 additions and 11 deletions
|
|
@ -13,6 +13,6 @@ edition = "2018"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
byteorder = { version = "1.3.4", default-features = false }
|
byteorder = { version = "1.3.4", default-features = false }
|
||||||
embedded-hal = "0.2.4"
|
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"
|
bit_field = "0.10.1"
|
||||||
nb = "1.0.0"
|
nb = "1.0.0"
|
||||||
|
|
|
||||||
24
src/udp.rs
24
src/udp.rs
|
|
@ -4,7 +4,7 @@ use crate::interface::Interface;
|
||||||
use crate::register::socketn;
|
use crate::register::socketn;
|
||||||
use crate::socket::Socket;
|
use crate::socket::Socket;
|
||||||
use core::fmt::Debug;
|
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 {
|
pub struct UdpSocket {
|
||||||
socket: Socket,
|
socket: Socket,
|
||||||
|
|
@ -178,7 +178,7 @@ impl<E: Debug> From<NbError<E>> for nb::Error<E> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<SpiBus, HostImpl> UdpClient for Interface<SpiBus, HostImpl>
|
impl<SpiBus, HostImpl> UdpClientStack for Interface<SpiBus, HostImpl>
|
||||||
where
|
where
|
||||||
SpiBus: ActiveBus,
|
SpiBus: ActiveBus,
|
||||||
HostImpl: Host,
|
HostImpl: Host,
|
||||||
|
|
@ -186,7 +186,7 @@ where
|
||||||
type UdpSocket = UdpSocket;
|
type UdpSocket = UdpSocket;
|
||||||
type Error = UdpSocketError<SpiBus::Error>;
|
type Error = UdpSocketError<SpiBus::Error>;
|
||||||
|
|
||||||
fn socket(&self) -> Result<Self::UdpSocket, Self::Error> {
|
fn socket(&mut self) -> Result<Self::UdpSocket, Self::Error> {
|
||||||
let mut device = self.device.borrow_mut();
|
let mut device = self.device.borrow_mut();
|
||||||
if let Some(socket) = device.take_socket() {
|
if let Some(socket) = device.take_socket() {
|
||||||
Ok(UdpSocket::new(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();
|
let mut device = self.device.borrow_mut();
|
||||||
if let SocketAddr::V4(remote) = remote {
|
if let SocketAddr::V4(remote) = remote {
|
||||||
// TODO find a random port
|
// TODO find a random port
|
||||||
|
|
@ -206,18 +210,18 @@ where
|
||||||
Err(Self::Error::UnsupportedAddress)
|
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)?;
|
socket.send(&mut self.device.borrow_mut().bus, buffer)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn receive(
|
fn receive(
|
||||||
&self,
|
&mut self,
|
||||||
socket: &mut Self::UdpSocket,
|
socket: &mut Self::UdpSocket,
|
||||||
buffer: &mut [u8],
|
buffer: &mut [u8],
|
||||||
) -> nb::Result<(usize, SocketAddr), Self::Error> {
|
) -> nb::Result<(usize, SocketAddr), Self::Error> {
|
||||||
Ok(socket.receive(&mut self.device.borrow_mut().bus, buffer)?)
|
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();
|
let mut device = self.device.borrow_mut();
|
||||||
socket.close(&mut device.bus)?;
|
socket.close(&mut device.bus)?;
|
||||||
device.release_socket(socket.socket);
|
device.release_socket(socket.socket);
|
||||||
|
|
@ -225,18 +229,18 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<SpiBus, HostImpl> UdpServer for Interface<SpiBus, HostImpl>
|
impl<SpiBus, HostImpl> UdpFullStack for Interface<SpiBus, HostImpl>
|
||||||
where
|
where
|
||||||
SpiBus: ActiveBus,
|
SpiBus: ActiveBus,
|
||||||
HostImpl: Host,
|
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();
|
let mut device = self.device.borrow_mut();
|
||||||
socket.open(&mut device.bus, local_port)?;
|
socket.open(&mut device.bus, local_port)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn send_to(
|
fn send_to(
|
||||||
&self,
|
&mut self,
|
||||||
socket: &mut Self::UdpSocket,
|
socket: &mut Self::UdpSocket,
|
||||||
remote: SocketAddr,
|
remote: SocketAddr,
|
||||||
buffer: &[u8],
|
buffer: &[u8],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue