Finished UDP socket init

This commit is contained in:
Jonah Dahlquist 2019-09-05 20:39:21 -05:00 committed by Jonah Dahlquist
commit 36df284dca
5 changed files with 84 additions and 63 deletions

View file

@ -17,7 +17,7 @@ impl<'a, SocketImpl: Socket> InactiveUdpSocket<'a, SocketImpl> {
pub fn activate<SpiBus: ActiveBus, NetworkImpl: Network>(self, w5500: W5500<SpiBus, NetworkImpl>) -> Result<UdpSocket<'a, SpiBus, NetworkImpl, SocketImpl>, ForeignSocketError> {
let (bus, network, sockets) = w5500.release();
if self.socket.is_owned_by(&sockets) {
Ok(UdpSocket::new(bus, network, sockets, self.socket))
Ok(UdpSocket { bus, network, sockets, socket: self.socket })
} else {
Err(ForeignSocketError {})
}

View file

@ -6,6 +6,7 @@ use crate::socket::Socket;
use crate::w5500::W5500;
use crate::udp::inactive_udp_socket::InactiveUdpSocket;
use crate::socket::OwnedSockets;
use register::socketn;
pub struct UdpSocket<'a, SpiBus: ActiveBus, NetworkImpl: Network, SocketImpl: Socket> {
bus: SpiBus,
@ -16,19 +17,12 @@ pub struct UdpSocket<'a, SpiBus: ActiveBus, NetworkImpl: Network, SocketImpl: So
}
impl<'a, SpiBus: ActiveBus, NetworkImpl: Network, SocketImpl: Socket> UdpSocket<'a, SpiBus, NetworkImpl, SocketImpl> {
pub fn new(bus: SpiBus, network: NetworkImpl, sockets: OwnedSockets, socket: &'a mut SocketImpl) -> Self {
// TODO setup socket in UDP mode
// self.0.reset_interrupt(socket, Interrupt::SendOk)?;
// self.0.write_u16(socket.at(SocketRegister::LocalPort), port)?;
// self.0.write_to(
// socket.at(SocketRegister::Mode),
// &[
// Protocol::UDP as u8, // Socket Mode Register
// SocketCommand::Open as u8, // Socket Command Register
// ],
// )?;
pub fn new(port: u16, mut bus: SpiBus, network: NetworkImpl, sockets: OwnedSockets, socket: &'a mut SocketImpl) -> Result<Self, SpiBus::Error> {
socket.reset_interrupt(&mut bus, socketn::Interrupt::SendOk)?;
socket.set_source_port(&mut bus, port)?;
socket.set_mode(&mut bus, socketn::Protocol::Udp)?;
UdpSocket { bus, network, sockets, socket }
Ok(UdpSocket { bus, network, sockets, socket })
}
pub fn deactivate(self) -> (InactiveUdpSocket<'a, SocketImpl>, W5500<SpiBus, NetworkImpl>) {