Renaming variables, moving broker parsing
This commit is contained in:
parent
d2b184e8e9
commit
c4c3593bae
|
@ -40,7 +40,6 @@ use stabilizer::{
|
||||||
adc::{Adc0Input, Adc1Input, AdcCode},
|
adc::{Adc0Input, Adc1Input, AdcCode},
|
||||||
afe::Gain,
|
afe::Gain,
|
||||||
dac::{Dac0Output, Dac1Output, DacCode},
|
dac::{Dac0Output, Dac1Output, DacCode},
|
||||||
design_parameters::DEFAULT_MQTT_BROKER,
|
|
||||||
embedded_hal::digital::v2::InputPin,
|
embedded_hal::digital::v2::InputPin,
|
||||||
hal,
|
hal,
|
||||||
signal_generator::{self, SignalGenerator},
|
signal_generator::{self, SignalGenerator},
|
||||||
|
@ -48,6 +47,7 @@ use stabilizer::{
|
||||||
DigitalInput0, DigitalInput1, AFE0, AFE1,
|
DigitalInput0, DigitalInput1, AFE0, AFE1,
|
||||||
},
|
},
|
||||||
net::{
|
net::{
|
||||||
|
self,
|
||||||
data_stream::{FrameGenerator, StreamFormat, StreamTarget},
|
data_stream::{FrameGenerator, StreamFormat, StreamTarget},
|
||||||
miniconf::Miniconf,
|
miniconf::Miniconf,
|
||||||
serde::Deserialize,
|
serde::Deserialize,
|
||||||
|
@ -62,7 +62,7 @@ const SCALE: f32 = i16::MAX as _;
|
||||||
const IIR_CASCADE_LENGTH: usize = 1;
|
const IIR_CASCADE_LENGTH: usize = 1;
|
||||||
|
|
||||||
// The number of samples in each batch process
|
// The number of samples in each batch process
|
||||||
const SAMPLE_BUFFER_SIZE: usize = 8;
|
const BATCH_SIZE: usize = 8;
|
||||||
|
|
||||||
// The logarithm of the number of 100MHz timer ticks between each sample. With a value of 2^7 =
|
// The logarithm of the number of 100MHz timer ticks between each sample. With a value of 2^7 =
|
||||||
// 128, there is 1.28uS per sample, corresponding to a sampling frequency of 781.25 KHz.
|
// 128, there is 1.28uS per sample, corresponding to a sampling frequency of 781.25 KHz.
|
||||||
|
@ -190,7 +190,7 @@ const APP: () = {
|
||||||
let (mut stabilizer, _pounder) = hardware::setup::setup(
|
let (mut stabilizer, _pounder) = hardware::setup::setup(
|
||||||
c.core,
|
c.core,
|
||||||
c.device,
|
c.device,
|
||||||
SAMPLE_BUFFER_SIZE,
|
BATCH_SIZE,
|
||||||
1 << SAMPLE_TICKS_LOG2,
|
1 << SAMPLE_TICKS_LOG2,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -200,27 +200,11 @@ const APP: () = {
|
||||||
stabilizer.cycle_counter,
|
stabilizer.cycle_counter,
|
||||||
env!("CARGO_BIN_NAME"),
|
env!("CARGO_BIN_NAME"),
|
||||||
stabilizer.net.mac_address,
|
stabilizer.net.mac_address,
|
||||||
option_env!("BROKER")
|
net::parse_or_default_broker(option_env!("BROKER")),
|
||||||
.and_then(|data| {
|
|
||||||
data.parse::<minimq::embedded_nal::IpAddr>().map_or_else(
|
|
||||||
|err| {
|
|
||||||
log::error!(
|
|
||||||
"{:?}: Failed to parse broker IP ({:?}) - Falling back to default",
|
|
||||||
err,
|
|
||||||
data
|
|
||||||
);
|
|
||||||
None
|
|
||||||
},
|
|
||||||
|ip| Some(ip),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.unwrap_or(DEFAULT_MQTT_BROKER.into()),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let generator = network.configure_streaming(
|
let generator = network
|
||||||
StreamFormat::AdcDacData,
|
.configure_streaming(StreamFormat::AdcDacData, BATCH_SIZE as u8);
|
||||||
SAMPLE_BUFFER_SIZE as u8,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Spawn a settings update for default settings.
|
// Spawn a settings update for default settings.
|
||||||
c.spawn.settings_update().unwrap();
|
c.spawn.settings_update().unwrap();
|
||||||
|
@ -338,7 +322,7 @@ const APP: () = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stream the data.
|
// Stream the data.
|
||||||
const N: usize = SAMPLE_BUFFER_SIZE * core::mem::size_of::<u16>();
|
const N: usize = BATCH_SIZE * core::mem::size_of::<u16>();
|
||||||
generator.add::<_, { N * 4 }>(|buf| {
|
generator.add::<_, { N * 4 }>(|buf| {
|
||||||
for (data, buf) in adc_samples
|
for (data, buf) in adc_samples
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -42,7 +42,6 @@ use stabilizer::{
|
||||||
adc::{Adc0Input, Adc1Input, AdcCode},
|
adc::{Adc0Input, Adc1Input, AdcCode},
|
||||||
afe::Gain,
|
afe::Gain,
|
||||||
dac::{Dac0Output, Dac1Output, DacCode},
|
dac::{Dac0Output, Dac1Output, DacCode},
|
||||||
design_parameters::DEFAULT_MQTT_BROKER,
|
|
||||||
embedded_hal::digital::v2::InputPin,
|
embedded_hal::digital::v2::InputPin,
|
||||||
hal,
|
hal,
|
||||||
input_stamper::InputStamper,
|
input_stamper::InputStamper,
|
||||||
|
@ -51,6 +50,7 @@ use stabilizer::{
|
||||||
DigitalInput0, DigitalInput1, AFE0, AFE1,
|
DigitalInput0, DigitalInput1, AFE0, AFE1,
|
||||||
},
|
},
|
||||||
net::{
|
net::{
|
||||||
|
self,
|
||||||
data_stream::{FrameGenerator, StreamFormat, StreamTarget},
|
data_stream::{FrameGenerator, StreamFormat, StreamTarget},
|
||||||
miniconf::Miniconf,
|
miniconf::Miniconf,
|
||||||
serde::Deserialize,
|
serde::Deserialize,
|
||||||
|
@ -61,7 +61,7 @@ use stabilizer::{
|
||||||
|
|
||||||
// The logarithm of the number of samples in each batch process. This corresponds with 2^3 samples
|
// The logarithm of the number of samples in each batch process. This corresponds with 2^3 samples
|
||||||
// per batch = 8 samples
|
// per batch = 8 samples
|
||||||
const SAMPLE_BUFFER_SIZE_LOG2: u8 = 3;
|
const BATCH_SIZE_SIZE_LOG2: u8 = 3;
|
||||||
|
|
||||||
// The logarithm of the number of 100MHz timer ticks between each sample. This corresponds with a
|
// The logarithm of the number of 100MHz timer ticks between each sample. This corresponds with a
|
||||||
// sampling period of 2^7 = 128 ticks. At 100MHz, 10ns per tick, this corresponds to a sampling
|
// sampling period of 2^7 = 128 ticks. At 100MHz, 10ns per tick, this corresponds to a sampling
|
||||||
|
@ -231,7 +231,7 @@ const APP: () = {
|
||||||
let (mut stabilizer, _pounder) = hardware::setup::setup(
|
let (mut stabilizer, _pounder) = hardware::setup::setup(
|
||||||
c.core,
|
c.core,
|
||||||
c.device,
|
c.device,
|
||||||
1 << SAMPLE_BUFFER_SIZE_LOG2,
|
1 << BATCH_SIZE_SIZE_LOG2,
|
||||||
1 << ADC_SAMPLE_TICKS_LOG2,
|
1 << ADC_SAMPLE_TICKS_LOG2,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -241,31 +241,17 @@ const APP: () = {
|
||||||
stabilizer.cycle_counter,
|
stabilizer.cycle_counter,
|
||||||
env!("CARGO_BIN_NAME"),
|
env!("CARGO_BIN_NAME"),
|
||||||
stabilizer.net.mac_address,
|
stabilizer.net.mac_address,
|
||||||
option_env!("BROKER")
|
net::parse_or_default_broker(option_env!("BROKER")),
|
||||||
.and_then(|data| {
|
|
||||||
data.parse::<minimq::embedded_nal::IpAddr>().map_or_else(
|
|
||||||
|err| {
|
|
||||||
log::error!(
|
|
||||||
"{:?}: Failed to parse broker IP ({:?}) - Falling back to default",
|
|
||||||
err,
|
|
||||||
data
|
|
||||||
);
|
|
||||||
None
|
|
||||||
},
|
|
||||||
|ip| Some(ip),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.unwrap_or(DEFAULT_MQTT_BROKER.into()),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let generator = network.configure_streaming(
|
let generator = network.configure_streaming(
|
||||||
StreamFormat::AdcDacData,
|
StreamFormat::AdcDacData,
|
||||||
1u8 << SAMPLE_BUFFER_SIZE_LOG2,
|
1u8 << BATCH_SIZE_SIZE_LOG2,
|
||||||
);
|
);
|
||||||
|
|
||||||
let settings = Settings::default();
|
let settings = Settings::default();
|
||||||
|
|
||||||
let pll = RPLL::new(ADC_SAMPLE_TICKS_LOG2 + SAMPLE_BUFFER_SIZE_LOG2);
|
let pll = RPLL::new(ADC_SAMPLE_TICKS_LOG2 + BATCH_SIZE_SIZE_LOG2);
|
||||||
|
|
||||||
// Spawn a settings and telemetry update for default settings.
|
// Spawn a settings and telemetry update for default settings.
|
||||||
c.spawn.settings_update().unwrap();
|
c.spawn.settings_update().unwrap();
|
||||||
|
@ -291,7 +277,7 @@ const APP: () = {
|
||||||
|
|
||||||
let signal_config = {
|
let signal_config = {
|
||||||
let frequency_tuning_word =
|
let frequency_tuning_word =
|
||||||
(1u64 << (32 - SAMPLE_BUFFER_SIZE_LOG2)) as u32;
|
(1u64 << (32 - BATCH_SIZE_SIZE_LOG2)) as u32;
|
||||||
|
|
||||||
signal_generator::Config {
|
signal_generator::Config {
|
||||||
// Same frequency as batch size.
|
// Same frequency as batch size.
|
||||||
|
@ -358,11 +344,11 @@ const APP: () = {
|
||||||
settings.pll_tc[0],
|
settings.pll_tc[0],
|
||||||
settings.pll_tc[1],
|
settings.pll_tc[1],
|
||||||
);
|
);
|
||||||
(pll_phase, (pll_frequency >> SAMPLE_BUFFER_SIZE_LOG2) as i32)
|
(pll_phase, (pll_frequency >> BATCH_SIZE_SIZE_LOG2) as i32)
|
||||||
}
|
}
|
||||||
LockinMode::Internal => {
|
LockinMode::Internal => {
|
||||||
// Reference phase and frequency are known.
|
// Reference phase and frequency are known.
|
||||||
(1i32 << 30, 1i32 << (32 - SAMPLE_BUFFER_SIZE_LOG2))
|
(1i32 << 30, 1i32 << (32 - BATCH_SIZE_SIZE_LOG2))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -417,7 +403,7 @@ const APP: () = {
|
||||||
|
|
||||||
// Stream the data.
|
// Stream the data.
|
||||||
const N: usize =
|
const N: usize =
|
||||||
(1 << SAMPLE_BUFFER_SIZE_LOG2) * core::mem::size_of::<u16>();
|
(1 << BATCH_SIZE_SIZE_LOG2) * core::mem::size_of::<u16>();
|
||||||
generator.add::<_, { N * 4 }>(|buf| {
|
generator.add::<_, { N * 4 }>(|buf| {
|
||||||
for (data, buf) in adc_samples
|
for (data, buf) in adc_samples
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -44,6 +44,3 @@ pub const DDS_SYNC_CLK_DIV: u8 = 4;
|
||||||
pub const MAX_SAMPLE_BUFFER_SIZE: usize = 32;
|
pub const MAX_SAMPLE_BUFFER_SIZE: usize = 32;
|
||||||
|
|
||||||
pub type SampleBuffer = [u16; MAX_SAMPLE_BUFFER_SIZE];
|
pub type SampleBuffer = [u16; MAX_SAMPLE_BUFFER_SIZE];
|
||||||
|
|
||||||
/// The default MQTT broker IP address if unspecified.
|
|
||||||
pub const DEFAULT_MQTT_BROKER: [u8; 4] = [10, 34, 16, 10];
|
|
||||||
|
|
|
@ -33,6 +33,9 @@ use smoltcp_nal::embedded_nal::SocketAddr;
|
||||||
|
|
||||||
pub type NetworkReference = shared::NetworkStackProxy<'static, NetworkStack>;
|
pub type NetworkReference = shared::NetworkStackProxy<'static, NetworkStack>;
|
||||||
|
|
||||||
|
/// The default MQTT broker IP address if unspecified.
|
||||||
|
pub const DEFAULT_MQTT_BROKER: [u8; 4] = [10, 34, 16, 10];
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq)]
|
#[derive(Copy, Clone, PartialEq)]
|
||||||
pub enum UpdateState {
|
pub enum UpdateState {
|
||||||
NoChange,
|
NoChange,
|
||||||
|
@ -205,3 +208,30 @@ pub fn get_device_prefix(
|
||||||
|
|
||||||
prefix
|
prefix
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Determine the broker IP address
|
||||||
|
///
|
||||||
|
/// # Note
|
||||||
|
/// If the broker IP is unspecified or unparseable, the default IP is returned.
|
||||||
|
///
|
||||||
|
/// # Args
|
||||||
|
/// * `input` - The optionally-specified command-line broker IP address as a string.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
/// The broker IP address.
|
||||||
|
pub fn parse_or_default_broker(input: Option<&str>) -> IpAddr {
|
||||||
|
input.and_then(|data| {
|
||||||
|
data.parse::<minimq::embedded_nal::IpAddr>().map_or_else(
|
||||||
|
|err| {
|
||||||
|
log::error!(
|
||||||
|
"{:?}: Failed to parse broker IP ({:?}) - Falling back to default",
|
||||||
|
err,
|
||||||
|
data
|
||||||
|
);
|
||||||
|
None
|
||||||
|
},
|
||||||
|
Some,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|| DEFAULT_MQTT_BROKER.into())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue