Adding WIP updates
This commit is contained in:
parent
aaef0e9913
commit
3ce93b8fcd
|
@ -9,7 +9,6 @@ use stm32h7xx_hal::{
|
||||||
|
|
||||||
const NUM_SOCKETS: usize = 5;
|
const NUM_SOCKETS: usize = 5;
|
||||||
|
|
||||||
use heapless::{consts, Vec};
|
|
||||||
use smoltcp_nal::smoltcp;
|
use smoltcp_nal::smoltcp;
|
||||||
|
|
||||||
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
||||||
|
@ -41,14 +40,14 @@ pub struct NetStorage {
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct SocketStorage {
|
pub struct SocketStorage {
|
||||||
rx_storage: [u8; 1024],
|
rx_storage: [u8; 1024],
|
||||||
tx_storage: [u8; 1024],
|
tx_storage: [u8; 1024 * 3],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SocketStorage {
|
impl SocketStorage {
|
||||||
const fn new() -> Self {
|
const fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
rx_storage: [0; 1024],
|
rx_storage: [0; 1024],
|
||||||
tx_storage: [0; 1024],
|
tx_storage: [0; 1024 * 3],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,6 +180,8 @@ pub fn setup(
|
||||||
let gpiof = device.GPIOF.split(ccdr.peripheral.GPIOF);
|
let gpiof = device.GPIOF.split(ccdr.peripheral.GPIOF);
|
||||||
let mut gpiog = device.GPIOG.split(ccdr.peripheral.GPIOG);
|
let mut gpiog = device.GPIOG.split(ccdr.peripheral.GPIOG);
|
||||||
|
|
||||||
|
let _uart_tx = gpiod.pd8.into_push_pull_output().set_speed(hal::gpio::Speed::VeryHigh);
|
||||||
|
|
||||||
let dma_streams =
|
let dma_streams =
|
||||||
hal::dma::dma::StreamsTuple::new(device.DMA1, ccdr.peripheral.DMA1);
|
hal::dma::dma::StreamsTuple::new(device.DMA1, ccdr.peripheral.DMA1);
|
||||||
|
|
||||||
|
@ -589,12 +590,10 @@ pub fn setup(
|
||||||
.routes(routes)
|
.routes(routes)
|
||||||
.finalize();
|
.finalize();
|
||||||
|
|
||||||
let (mut sockets, handles) = {
|
let mut sockets = {
|
||||||
let mut sockets =
|
let mut sockets =
|
||||||
smoltcp::socket::SocketSet::new(&mut store.sockets[..]);
|
smoltcp::socket::SocketSet::new(&mut store.sockets[..]);
|
||||||
|
|
||||||
let mut handles: Vec<smoltcp::socket::SocketHandle, consts::U64> =
|
|
||||||
Vec::new();
|
|
||||||
for storage in store.socket_storage.iter_mut() {
|
for storage in store.socket_storage.iter_mut() {
|
||||||
let tcp_socket = {
|
let tcp_socket = {
|
||||||
let rx_buffer = smoltcp::socket::TcpSocketBuffer::new(
|
let rx_buffer = smoltcp::socket::TcpSocketBuffer::new(
|
||||||
|
@ -606,12 +605,10 @@ pub fn setup(
|
||||||
|
|
||||||
smoltcp::socket::TcpSocket::new(rx_buffer, tx_buffer)
|
smoltcp::socket::TcpSocket::new(rx_buffer, tx_buffer)
|
||||||
};
|
};
|
||||||
let handle = sockets.add(tcp_socket);
|
sockets.add(tcp_socket);
|
||||||
|
|
||||||
handles.push(handle).unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(sockets, handles)
|
sockets
|
||||||
};
|
};
|
||||||
|
|
||||||
let dhcp_client = {
|
let dhcp_client = {
|
||||||
|
@ -647,7 +644,6 @@ pub fn setup(
|
||||||
let mut stack = smoltcp_nal::NetworkStack::new(
|
let mut stack = smoltcp_nal::NetworkStack::new(
|
||||||
interface,
|
interface,
|
||||||
sockets,
|
sockets,
|
||||||
&handles,
|
|
||||||
Some(dhcp_client),
|
Some(dhcp_client),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use heapless::{
|
||||||
spsc::{Consumer, Producer, Queue},
|
spsc::{Consumer, Producer, Queue},
|
||||||
Vec,
|
Vec,
|
||||||
};
|
};
|
||||||
use smoltcp_nal::{smoltcp, embedded_nal::{Mode, SocketAddr, TcpStack}};
|
use smoltcp_nal::embedded_nal::{SocketAddr, TcpClientStack};
|
||||||
|
|
||||||
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 TcpStack>::TcpSocket>,
|
socket: Option<<NetworkReference as TcpClientStack>::TcpSocket>,
|
||||||
queue: Consumer<'static, AdcDacData, BlockBufferSize>,
|
queue: Consumer<'static, AdcDacData, BlockBufferSize>,
|
||||||
remote: Option<SocketAddr>,
|
remote: Option<SocketAddr>,
|
||||||
}
|
}
|
||||||
|
@ -122,18 +122,18 @@ impl DataStream {
|
||||||
self.close();
|
self.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
let socket =
|
let mut socket =
|
||||||
self.stack
|
self.stack
|
||||||
.open(Mode::NonBlocking)
|
.socket()
|
||||||
.map_err(|err| match err {
|
.map_err(|err| match err {
|
||||||
<NetworkReference as TcpStack>::Error::NoIpAddress => (),
|
<NetworkReference as TcpClientStack>::Error::NoIpAddress => (),
|
||||||
_ => ()
|
_ => ()
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
// TODO: How should we handle a connection failure?
|
// TODO: How should we handle a connection failure?
|
||||||
let socket = self.stack.connect(socket, remote).unwrap();
|
self.stack.connect(&mut socket, remote).unwrap();
|
||||||
|
|
||||||
//log::info!("Stream connecting to {:?}", remote);
|
log::info!("Stream connecting to {:?}", remote);
|
||||||
|
|
||||||
// Note(unwrap): The socket will be empty before we replace it.
|
// Note(unwrap): The socket will be empty before we replace it.
|
||||||
self.socket.replace(socket);
|
self.socket.replace(socket);
|
||||||
|
@ -166,7 +166,7 @@ impl DataStream {
|
||||||
};
|
};
|
||||||
|
|
||||||
if !connected {
|
if !connected {
|
||||||
self.socket.replace(self.stack.connect(socket, self.remote.unwrap()).unwrap());
|
self.stack.connect(&mut socket, self.remote.unwrap()).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,12 +185,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| {
|
|
||||||
let mut all_sockets = stack.sockets.borrow_mut();
|
|
||||||
let socket: &mut smoltcp::socket::TcpSocket = &mut *all_sockets.get(handle);
|
|
||||||
socket.send_capacity() - socket.send_queue()
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO: Clean up magic numbers.
|
// TODO: Clean up magic numbers.
|
||||||
if capacity < 72 {
|
if capacity < 72 {
|
||||||
|
@ -218,7 +213,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.write(&mut handle, &data) {
|
match self.stack.send(&mut handle, &data) {
|
||||||
Ok(len) => {
|
Ok(len) => {
|
||||||
if len != data.len() {
|
if len != data.len() {
|
||||||
log::error!("Short message: {} {}", len, data.len());
|
log::error!("Short message: {} {}", len, data.len());
|
||||||
|
|
|
@ -69,6 +69,21 @@ where
|
||||||
forward! {close(socket: S::TcpSocket) -> Result<(), S::Error>}
|
forward! {close(socket: S::TcpSocket) -> Result<(), S::Error>}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, S> embedded_nal::UdpClientStack for NetworkStackProxy<'a, S>
|
||||||
|
where
|
||||||
|
S: embedded_nal::UdpClientStack,
|
||||||
|
{
|
||||||
|
type UdpSocket = S::UdpSocket;
|
||||||
|
type Error = S::Error;
|
||||||
|
|
||||||
|
forward! {socket() -> Result<S::UdpSocket, S::Error>}
|
||||||
|
forward! {connect(socket: &mut S::UdpSocket, remote: embedded_nal::SocketAddr) -> Result<(), S::Error>}
|
||||||
|
|
||||||
|
forward! {send(socket: &mut S::UdpSocket, buffer: &[u8]) -> embedded_nal::nb::Result<(), S::Error>}
|
||||||
|
forward! {receive(socket: &mut S::UdpSocket, buffer: &mut [u8]) -> embedded_nal::nb::Result<(usize, embedded_nal::SocketAddr), S::Error>}
|
||||||
|
forward! {close(socket: S::UdpSocket) -> Result<(), S::Error>}
|
||||||
|
}
|
||||||
|
|
||||||
impl NetworkManager {
|
impl NetworkManager {
|
||||||
/// Construct a new manager for a shared network stack
|
/// Construct a new manager for a shared network stack
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue