Unwrapping enqueue
This commit is contained in:
parent
3ce93b8fcd
commit
97911c55f9
|
@ -38,7 +38,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b9a69a963b70ddacfcd382524f72a4576f359af9334b3bf48a79566590bb8bfa"
|
checksum = "b9a69a963b70ddacfcd382524f72a4576f359af9334b3bf48a79566590bb8bfa"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitrate",
|
"bitrate",
|
||||||
"cortex-m 0.7.2",
|
"cortex-m 0.6.7",
|
||||||
"embedded-hal",
|
"embedded-hal",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -778,7 +778,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smoltcp-nal"
|
name = "smoltcp-nal"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/nal-update#65d94c4ab9e06d2e5c48547a0c9cd6836591e355"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"embedded-nal",
|
"embedded-nal",
|
||||||
"heapless 0.7.1",
|
"heapless 0.7.1",
|
||||||
|
@ -828,7 +827,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8b672c837e0ee8158ecc7fce0f9a948dd0693a9c588338e728d14b73307a0b7d"
|
checksum = "8b672c837e0ee8158ecc7fce0f9a948dd0693a9c588338e728d14b73307a0b7d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bare-metal 0.2.5",
|
"bare-metal 0.2.5",
|
||||||
"cortex-m 0.7.2",
|
"cortex-m 0.6.7",
|
||||||
"cortex-m-rt",
|
"cortex-m-rt",
|
||||||
"vcell",
|
"vcell",
|
||||||
]
|
]
|
||||||
|
|
|
@ -7,8 +7,6 @@ use stm32h7xx_hal::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
const NUM_SOCKETS: usize = 5;
|
|
||||||
|
|
||||||
use smoltcp_nal::smoltcp;
|
use smoltcp_nal::smoltcp;
|
||||||
|
|
||||||
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
||||||
|
@ -19,13 +17,18 @@ use super::{
|
||||||
DigitalInput0, DigitalInput1, EthernetPhy, NetworkStack, AFE0, AFE1,
|
DigitalInput0, DigitalInput1, EthernetPhy, NetworkStack, AFE0, AFE1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const NUM_TCP_SOCKETS: usize = 5;
|
||||||
|
const NUM_UDP_SOCKETS: usize = 1;
|
||||||
|
const NUM_SOCKETS: usize = NUM_UDP_SOCKETS + NUM_TCP_SOCKETS;
|
||||||
|
|
||||||
pub struct NetStorage {
|
pub struct NetStorage {
|
||||||
pub ip_addrs: [smoltcp::wire::IpCidr; 1],
|
pub ip_addrs: [smoltcp::wire::IpCidr; 1],
|
||||||
|
|
||||||
// Note: There is an additional socket set item required for the DHCP socket.
|
// Note: There is an additional socket set item required for the DHCP socket.
|
||||||
pub sockets:
|
pub sockets:
|
||||||
[Option<smoltcp::socket::SocketSetItem<'static>>; NUM_SOCKETS + 1],
|
[Option<smoltcp::socket::SocketSetItem<'static>>; NUM_SOCKETS + 1],
|
||||||
pub socket_storage: [SocketStorage; NUM_SOCKETS],
|
pub tcp_socket_storage: [TcpSocketStorage; NUM_TCP_SOCKETS],
|
||||||
|
pub udp_socket_storage: [UdpSocketStorage; NUM_UDP_SOCKETS],
|
||||||
pub neighbor_cache:
|
pub neighbor_cache:
|
||||||
[Option<(smoltcp::wire::IpAddress, smoltcp::iface::Neighbor)>; 8],
|
[Option<(smoltcp::wire::IpAddress, smoltcp::iface::Neighbor)>; 8],
|
||||||
pub routes_cache:
|
pub routes_cache:
|
||||||
|
@ -37,17 +40,35 @@ pub struct NetStorage {
|
||||||
pub dhcp_rx_storage: [u8; 600],
|
pub dhcp_rx_storage: [u8; 600],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
pub struct UdpSocketStorage {
|
||||||
pub struct SocketStorage {
|
|
||||||
rx_storage: [u8; 1024],
|
rx_storage: [u8; 1024],
|
||||||
tx_storage: [u8; 1024 * 3],
|
tx_storage: [u8; 1024],
|
||||||
|
tx_metadata: [smoltcp::storage::PacketMetadata<smoltcp::wire::IpEndpoint>; 10],
|
||||||
|
rx_metadata: [smoltcp::storage::PacketMetadata<smoltcp::wire::IpEndpoint>; 10],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SocketStorage {
|
impl UdpSocketStorage {
|
||||||
const fn new() -> Self {
|
const fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
rx_storage: [0; 1024],
|
rx_storage: [0; 1024],
|
||||||
tx_storage: [0; 1024 * 3],
|
tx_storage: [0; 1024],
|
||||||
|
tx_metadata: [smoltcp::storage::PacketMetadata::<smoltcp::wire::IpEndpoint>::EMPTY; 10],
|
||||||
|
rx_metadata: [smoltcp::storage::PacketMetadata::<smoltcp::wire::IpEndpoint>::EMPTY; 10],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub struct TcpSocketStorage {
|
||||||
|
rx_storage: [u8; 1024],
|
||||||
|
tx_storage: [u8; 1024],
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TcpSocketStorage {
|
||||||
|
const fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
rx_storage: [0; 1024],
|
||||||
|
tx_storage: [0; 1024],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,8 +82,9 @@ impl NetStorage {
|
||||||
)],
|
)],
|
||||||
neighbor_cache: [None; 8],
|
neighbor_cache: [None; 8],
|
||||||
routes_cache: [None; 8],
|
routes_cache: [None; 8],
|
||||||
sockets: [None, None, None, None, None, None],
|
sockets: [None, None, None, None, None, None, None],
|
||||||
socket_storage: [SocketStorage::new(); NUM_SOCKETS],
|
tcp_socket_storage: [TcpSocketStorage::new(); NUM_TCP_SOCKETS],
|
||||||
|
udp_socket_storage: [UdpSocketStorage::new(); NUM_UDP_SOCKETS],
|
||||||
dhcp_tx_storage: [0; 600],
|
dhcp_tx_storage: [0; 600],
|
||||||
dhcp_rx_storage: [0; 600],
|
dhcp_rx_storage: [0; 600],
|
||||||
dhcp_rx_metadata: [smoltcp::socket::RawPacketMetadata::EMPTY; 1],
|
dhcp_rx_metadata: [smoltcp::socket::RawPacketMetadata::EMPTY; 1],
|
||||||
|
@ -594,7 +616,7 @@ pub fn setup(
|
||||||
let mut sockets =
|
let mut sockets =
|
||||||
smoltcp::socket::SocketSet::new(&mut store.sockets[..]);
|
smoltcp::socket::SocketSet::new(&mut store.sockets[..]);
|
||||||
|
|
||||||
for storage in store.socket_storage.iter_mut() {
|
for storage in store.tcp_socket_storage[..].iter_mut() {
|
||||||
let tcp_socket = {
|
let tcp_socket = {
|
||||||
let rx_buffer = smoltcp::socket::TcpSocketBuffer::new(
|
let rx_buffer = smoltcp::socket::TcpSocketBuffer::new(
|
||||||
&mut storage.rx_storage[..],
|
&mut storage.rx_storage[..],
|
||||||
|
@ -608,6 +630,22 @@ pub fn setup(
|
||||||
sockets.add(tcp_socket);
|
sockets.add(tcp_socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for storage in store.udp_socket_storage[..].iter_mut() {
|
||||||
|
let udp_socket = {
|
||||||
|
let rx_buffer = smoltcp::socket::UdpSocketBuffer::new(
|
||||||
|
&mut storage.rx_metadata[..],
|
||||||
|
&mut storage.rx_storage[..],
|
||||||
|
);
|
||||||
|
let tx_buffer = smoltcp::socket::UdpSocketBuffer::new(
|
||||||
|
&mut storage.tx_metadata[..],
|
||||||
|
&mut storage.tx_storage[..],
|
||||||
|
);
|
||||||
|
|
||||||
|
smoltcp::socket::UdpSocket::new(rx_buffer, tx_buffer)
|
||||||
|
};
|
||||||
|
sockets.add(udp_socket);
|
||||||
|
}
|
||||||
|
|
||||||
sockets
|
sockets
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use heapless::{
|
||||||
spsc::{Consumer, Producer, Queue},
|
spsc::{Consumer, Producer, Queue},
|
||||||
Vec,
|
Vec,
|
||||||
};
|
};
|
||||||
use smoltcp_nal::embedded_nal::{SocketAddr, TcpClientStack};
|
use smoltcp_nal::embedded_nal::{SocketAddr, UdpClientStack};
|
||||||
|
|
||||||
use super::NetworkReference;
|
use super::NetworkReference;
|
||||||
use crate::hardware::design_parameters::SAMPLE_BUFFER_SIZE;
|
use crate::hardware::design_parameters::SAMPLE_BUFFER_SIZE;
|
||||||
|
@ -66,7 +66,7 @@ impl BlockGenerator {
|
||||||
|
|
||||||
pub struct DataStream {
|
pub struct DataStream {
|
||||||
stack: NetworkReference,
|
stack: NetworkReference,
|
||||||
socket: Option<<NetworkReference as TcpClientStack>::TcpSocket>,
|
socket: Option<<NetworkReference as UdpClientStack>::UdpSocket>,
|
||||||
queue: Consumer<'static, AdcDacData, BlockBufferSize>,
|
queue: Consumer<'static, AdcDacData, BlockBufferSize>,
|
||||||
remote: Option<SocketAddr>,
|
remote: Option<SocketAddr>,
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ impl DataStream {
|
||||||
self.stack
|
self.stack
|
||||||
.socket()
|
.socket()
|
||||||
.map_err(|err| match err {
|
.map_err(|err| match err {
|
||||||
<NetworkReference as TcpClientStack>::Error::NoIpAddress => (),
|
<NetworkReference as UdpClientStack>::Error::NoIpAddress => (),
|
||||||
_ => ()
|
_ => ()
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -154,22 +154,6 @@ impl DataStream {
|
||||||
self.remote = Some(remote);
|
self.remote = Some(remote);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn manage_reconnection(&mut self) {
|
|
||||||
if self.socket.is_none() || self.remote.is_none() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut socket = self.socket.borrow_mut().unwrap();
|
|
||||||
let connected = match self.stack.is_connected(&mut socket) {
|
|
||||||
Ok(connected) => connected,
|
|
||||||
_ => return,
|
|
||||||
};
|
|
||||||
|
|
||||||
if !connected {
|
|
||||||
self.stack.connect(&mut socket, self.remote.unwrap()).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn process(&mut self) -> bool {
|
pub fn process(&mut self) -> bool {
|
||||||
// If there's no socket available, try to connect to our remote.
|
// If there's no socket available, try to connect to our remote.
|
||||||
if self.socket.is_none() && self.remote.is_some() {
|
if self.socket.is_none() && self.remote.is_some() {
|
||||||
|
@ -185,7 +169,7 @@ impl DataStream {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut handle = self.socket.borrow_mut().unwrap();
|
let mut handle = self.socket.borrow_mut().unwrap();
|
||||||
let capacity = self.stack.lock(|stack| stack.get_remaining_send_buffer(handle)).unwrap();
|
let capacity = self.stack.lock(|stack| stack.get_remaining_send_buffer(handle.handle)).unwrap();
|
||||||
|
|
||||||
// TODO: Clean up magic numbers.
|
// TODO: Clean up magic numbers.
|
||||||
if capacity < 72 {
|
if capacity < 72 {
|
||||||
|
@ -198,9 +182,6 @@ impl DataStream {
|
||||||
|
|
||||||
if let Some(data) = self.queue.dequeue() {
|
if let Some(data) = self.queue.dequeue() {
|
||||||
|
|
||||||
// Reconnect the socket if we're no longer connected.
|
|
||||||
self.manage_reconnection();
|
|
||||||
|
|
||||||
let block = DataBlock {
|
let block = DataBlock {
|
||||||
adcs: data.adcs,
|
adcs: data.adcs,
|
||||||
dacs: data.dacs,
|
dacs: data.dacs,
|
||||||
|
@ -213,14 +194,7 @@ impl DataStream {
|
||||||
|
|
||||||
// Transmit the data block.
|
// Transmit the data block.
|
||||||
// TODO: Should we measure how many packets get dropped as telemetry?
|
// TODO: Should we measure how many packets get dropped as telemetry?
|
||||||
match self.stack.send(&mut handle, &data) {
|
self.stack.send(&mut handle, &data).ok();
|
||||||
Ok(len) => {
|
|
||||||
if len != data.len() {
|
|
||||||
log::error!("Short message: {} {}", len, data.len());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.queue.ready()
|
self.queue.ready()
|
||||||
|
|
Loading…
Reference in New Issue