Allowing target to be runtime configurable
This commit is contained in:
parent
b5fdb31a02
commit
92c84a6bfe
@ -18,7 +18,7 @@ use stabilizer::{
|
||||
DigitalInput0, DigitalInput1, AFE0, AFE1,
|
||||
},
|
||||
net::{
|
||||
data_stream::BlockGenerator,
|
||||
data_stream::{BlockGenerator, StreamTarget},
|
||||
miniconf::Miniconf,
|
||||
serde::Deserialize,
|
||||
telemetry::{Telemetry, TelemetryBuffer},
|
||||
@ -38,6 +38,7 @@ pub struct Settings {
|
||||
allow_hold: bool,
|
||||
force_hold: bool,
|
||||
telemetry_period: u16,
|
||||
stream_target: StreamTarget,
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
@ -57,6 +58,8 @@ impl Default for Settings {
|
||||
force_hold: false,
|
||||
// The default telemetry period in seconds.
|
||||
telemetry_period: 10,
|
||||
|
||||
stream_target: StreamTarget::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -92,10 +95,12 @@ const APP: () = {
|
||||
stabilizer.net.mac_address,
|
||||
);
|
||||
|
||||
// TODO: Remove unwrap.
|
||||
let remote: smoltcp_nal::embedded_nal::SocketAddr =
|
||||
"10.35.16.10:1111".parse().unwrap();
|
||||
let generator = network.enable_streaming(remote.into());
|
||||
let generator = {
|
||||
use smoltcp_nal::embedded_nal::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
let remote =
|
||||
SocketAddr::new(IpAddr::V4(Ipv4Addr::unspecified()), 0);
|
||||
network.enable_streaming(remote.into())
|
||||
};
|
||||
|
||||
// Spawn a settings update for default settings.
|
||||
c.spawn.settings_update().unwrap();
|
||||
@ -229,6 +234,9 @@ const APP: () = {
|
||||
// Update AFEs
|
||||
c.resources.afes.0.set_gain(settings.afe[0]);
|
||||
c.resources.afes.1.set_gain(settings.afe[1]);
|
||||
|
||||
let target = settings.stream_target.into();
|
||||
c.resources.network.direct_stream(target);
|
||||
}
|
||||
|
||||
#[task(priority = 1, resources=[network, settings, telemetry], schedule=[telemetry])]
|
||||
|
@ -1,6 +1,8 @@
|
||||
use core::borrow::BorrowMut;
|
||||
use heapless::spsc::{Consumer, Producer, Queue};
|
||||
use smoltcp_nal::embedded_nal::{SocketAddr, UdpClientStack};
|
||||
use miniconf::MiniconfAtomic;
|
||||
use serde::Deserialize;
|
||||
use smoltcp_nal::embedded_nal::{IpAddr, Ipv4Addr, SocketAddr, UdpClientStack};
|
||||
|
||||
use super::NetworkReference;
|
||||
use crate::hardware::design_parameters::SAMPLE_BUFFER_SIZE;
|
||||
@ -14,6 +16,32 @@ const BLOCK_BUFFER_SIZE: usize = 30;
|
||||
|
||||
const SUBSAMPLE_RATE: usize = 1;
|
||||
|
||||
#[derive(Copy, Clone, Debug, MiniconfAtomic, Deserialize)]
|
||||
pub struct StreamTarget {
|
||||
pub ip: [u8; 4],
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
impl Default for StreamTarget {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
ip: [0; 4],
|
||||
port: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<SocketAddr> for StreamTarget {
|
||||
fn into(self) -> SocketAddr {
|
||||
SocketAddr::new(
|
||||
IpAddr::V4(Ipv4Addr::new(
|
||||
self.ip[0], self.ip[1], self.ip[2], self.ip[3],
|
||||
)),
|
||||
self.port,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn setup_streaming(
|
||||
stack: NetworkReference,
|
||||
) -> (BlockGenerator, DataStream) {
|
||||
@ -208,6 +236,15 @@ impl DataStream {
|
||||
self.close();
|
||||
}
|
||||
|
||||
// If the remote address is unspecified, just close the existing socket.
|
||||
if remote.ip().is_unspecified() {
|
||||
if self.socket.is_some() {
|
||||
self.close();
|
||||
}
|
||||
|
||||
return Err(());
|
||||
}
|
||||
|
||||
let mut socket = self.stack.socket().map_err(|err| match err {
|
||||
<NetworkReference as UdpClientStack>::Error::NoIpAddress => (),
|
||||
_ => (),
|
||||
|
Loading…
Reference in New Issue
Block a user