Finished UDP socket init
This commit is contained in:
parent
65a9552816
commit
36df284dca
5 changed files with 84 additions and 63 deletions
13
src/w5500.rs
13
src/w5500.rs
|
|
@ -52,12 +52,14 @@ impl<SpiBus: ActiveBus, NetworkImpl: Network> W5500<SpiBus, NetworkImpl> {
|
|||
|
||||
pub fn open_udp_socket<'a, SocketImpl: Socket>(
|
||||
self,
|
||||
port: u16,
|
||||
socket: &'a mut SocketImpl,
|
||||
) -> Result<UdpSocket<'a, SpiBus, NetworkImpl, SocketImpl>, ForeignSocketError> {
|
||||
) -> Result<UdpSocket<'a, SpiBus, NetworkImpl, SocketImpl>, OpenSocketError<SpiBus::Error>> {
|
||||
if socket.is_owned_by(&self.sockets) {
|
||||
Ok(UdpSocket::new(self.bus, self.network, self.sockets, socket))
|
||||
UdpSocket::new(port, self.bus, self.network, self.sockets, socket)
|
||||
.map_err(|e| OpenSocketError::BusError(e))
|
||||
} else {
|
||||
Err(ForeignSocketError {})
|
||||
Err(OpenSocketError::ForeignSocketError)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -82,4 +84,9 @@ impl<Spi: FullDuplex<u8>, NetworkImpl: Network> W5500<ActiveThreeWire<Spi>, Netw
|
|||
}
|
||||
}
|
||||
|
||||
pub enum OpenSocketError<BusError> {
|
||||
ForeignSocketError,
|
||||
BusError(BusError),
|
||||
}
|
||||
|
||||
pub struct ForeignSocketError {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue