Added inactive UP socket state, added run-time socket ownership checking, added register addresses to sockets

This commit is contained in:
Jonah Dahlquist 2019-09-04 13:37:59 -05:00 committed by Jonah Dahlquist
commit b82bb92ead
4 changed files with 184 additions and 18 deletions

View file

@ -53,9 +53,16 @@ impl<SpiBus: ActiveBus, NetworkImpl: Network> W5500<SpiBus, NetworkImpl> {
pub fn open_udp_socket<'a, SocketImpl: Socket>(
&self,
socket: &'a mut SocketImpl,
) -> UdpSocket<'a, SocketImpl> {
// TODO compare socket to sockets list
UdpSocket::new(socket)
) -> Result<UdpSocket<'a, SpiBus, NetworkImpl, SocketImpl>, ForeignSocketError> {
if socket.is_owned_by(self.sockets) {
Ok(UdpSocket::new(self.bus, self.network, self.sockets, socket))
} else {
Err(ForeignSocketError {})
}
}
pub fn release(self) -> (SpiBus, NetworkImpl, OwnedSockets) {
(self.bus, self.network, self.sockets)
}
}
@ -74,3 +81,5 @@ impl<Spi: FullDuplex<u8>, NetworkImpl: Network> W5500<ActiveThreeWire<Spi>, Netw
(InactiveW5500::new(bus, self.network, self.sockets), spi)
}
}
pub struct ForeignSocketError {}