Skip to content

Commit

Permalink
Merge pull request #767 from quartiq/miniconf
Browse files Browse the repository at this point in the history
new miniconf (trait split)
  • Loading branch information
jordens authored Sep 6, 2023
2 parents 6481db6 + 4ceb75b commit b2f11b4
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 82 deletions.
9 changes: 3 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ lm75 = "0.2"
enum-iterator = "1.4.1"
rand_xorshift = "0.3.0"
rand_core = "0.6.4"
minimq = "0.7"
miniconf = "0.8"
smoltcp-nal = { version = "0.4", features = ["shared-stack"]}
minimq = { git = "https://github.com/quartiq/minimq" } # "0.8"
# Keep this synced with the miniconf version in py/setup.py
miniconf = { git = "https://github.com/quartiq/miniconf.git" } # "0.9"
smoltcp-nal = { version = "0.4.1", features = ["shared-stack"]}

[dependencies.stm32h7xx-hal]
git = "https://github.com/stm32-rs/stm32h7xx-hal"
Expand Down
20 changes: 10 additions & 10 deletions hitl/loopback.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ async def test_loopback(miniconf, telemetry_queue, set_point, gain=1, channel=0)
print(f'Testing loopback for Vout = {set_point:.2f}, Gain = x{gain}')
print('---------------------------------')
# Configure the AFE and IIRs to output at the set point
await miniconf.command(f'afe/{channel}', f'G{gain}', retain=False)
await miniconf.command(f'iir_ch/{channel}/0', static_iir_output(set_point), retain=False)
await miniconf.set(f'/afe/{channel}', f'G{gain}', retain=False)
await miniconf.set(f'/iir_ch/{channel}/0', static_iir_output(set_point), retain=False)

# Configure signal generators to not affect the test.
await miniconf.command('signal_generator/0/amplitude', 0, retain=False)
await miniconf.set('/signal_generator/0/amplitude', 0, retain=False)

# Wait for telemetry to update.
await asyncio.sleep(5.0)
Expand Down Expand Up @@ -86,21 +86,21 @@ async def test():
""" The actual testing being completed. """
tele = await Telemetry.create(args.prefix, args.broker)

interface = await Miniconf.create(args.prefix, args.broker)
miniconf = await Miniconf.create(args.prefix, args.broker)

# Disable IIR holds and configure the telemetry rate.
await interface.command('allow_hold', False, retain=False)
await interface.command('force_hold', False, retain=False)
await interface.command('telemetry_period', 1, retain=False)
await miniconf.set('/allow_hold', False, retain=False)
await miniconf.set('/force_hold', False, retain=False)
await miniconf.set('/telemetry_period', 1, retain=False)

# Test loopback with a static 1V output of the DACs.
await test_loopback(interface, tele.queue, 1.0)
await test_loopback(miniconf, tele.queue, 1.0)

# Repeat test with AFE = 2x
await test_loopback(interface, tele.queue, 1.0, gain=2)
await test_loopback(miniconf, tele.queue, 1.0, gain=2)

# Test with 0V output
await test_loopback(interface, tele.queue, 0.0)
await test_loopback(miniconf, tele.queue, 0.0)

sys.exit(asyncio.run(test()))

Expand Down
3 changes: 2 additions & 1 deletion hitl/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ sleep 30
ping -c 5 -w 20 stabilizer-hitl

# Test the MQTT interface. This uses the default broker "mqtt"
python3 -m miniconf $PREFIX afe/0='"G2"'
python3 -m miniconf $PREFIX --list
python3 -m miniconf $PREFIX /afe/0='"G2"'
python3 -m stabilizer.iir_coefficients -p $PREFIX -c 0 -v pid --Ki 10 --Kp 1

# Test the ADC/DACs connected via loopback.
Expand Down
8 changes: 4 additions & 4 deletions hitl/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ async def _main():
local_ip = get_local_ip(args.broker)

logger.info("Starting stream")
await conf.command(
"stream_target", {"ip": local_ip, "port": args.port}, retain=False)
await conf.set(
"/stream_target", {"ip": local_ip, "port": args.port}, retain=False)

try:
logger.info("Testing stream reception")
Expand All @@ -44,8 +44,8 @@ async def _main():
raise RuntimeError("High frame loss", loss)
finally:
logger.info("Stopping stream")
await conf.command(
"stream_target", {"ip": [0, 0, 0, 0], "port": 0}, retain=False)
await conf.set(
"/stream_target", {"ip": [0, 0, 0, 0], "port": 0}, retain=False)

logger.info("Draining queue")
await asyncio.sleep(.1)
Expand Down
3 changes: 2 additions & 1 deletion py/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"scipy",
"matplotlib",
"gmqtt",
"miniconf-mqtt@git+https://github.com/quartiq/[email protected]#subdirectory=py/miniconf-mqtt",
# Keep this synced with the miniconf version in Cargo.toml
"miniconf-mqtt@git+https://github.com/quartiq/miniconf@main#subdirectory=py/miniconf-mqtt",
],
)
2 changes: 1 addition & 1 deletion py/stabilizer/iir_coefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ async def configure():

# Set the filter coefficients.
# Note: In the future, we will need to Handle higher-order cascades.
await interface.command(f"iir_ch/{args.channel}/0", {
await interface.set(f"/iir_ch/{args.channel}/0", {
"ba": coefficients,
"y_min": stabilizer.voltage_to_machine_units(args.y_min),
"y_max": stabilizer.voltage_to_machine_units(args.y_max),
Expand Down
15 changes: 6 additions & 9 deletions src/bin/dual-iir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use stabilizer::{
},
net::{
data_stream::{FrameGenerator, StreamFormat, StreamTarget},
miniconf::Miniconf,
miniconf::Tree,
telemetry::{Telemetry, TelemetryBuffer},
NetworkState, NetworkUsers,
},
Expand All @@ -71,7 +71,7 @@ const SAMPLE_TICKS: u32 = 1 << SAMPLE_TICKS_LOG2;
const SAMPLE_PERIOD: f32 =
SAMPLE_TICKS as f32 * hardware::design_parameters::TIMER_PERIOD;

#[derive(Clone, Copy, Debug, Miniconf)]
#[derive(Clone, Copy, Debug, Tree)]
pub struct Settings {
/// Configure the Analog Front End (AFE) gain.
///
Expand All @@ -82,7 +82,7 @@ pub struct Settings {
///
/// # Value
/// Any of the variants of [Gain] enclosed in double quotes.
#[miniconf(defer)]
#[tree]
afe: [Gain; 2],

/// Configure the IIR filter parameters.
Expand All @@ -95,7 +95,7 @@ pub struct Settings {
///
/// # Value
/// See [iir::IIR#miniconf]
#[miniconf(defer(2))]
#[tree(depth(2))]
iir_ch: [[iir::IIR<f32>; IIR_CASCADE_LENGTH]; 2],

/// Specified true if DI1 should be used as a "hold" input.
Expand Down Expand Up @@ -143,7 +143,7 @@ pub struct Settings {
///
/// # Value
/// See [signal_generator::BasicConfig#miniconf]
#[miniconf(defer(2))]
#[tree(depth(2))]
signal_generator: [signal_generator::BasicConfig; 2],
}

Expand Down Expand Up @@ -220,10 +220,7 @@ mod app {
clock,
env!("CARGO_BIN_NAME"),
stabilizer.net.mac_address,
option_env!("BROKER")
.unwrap_or("10.34.16.1")
.parse()
.unwrap(),
option_env!("BROKER").unwrap_or("mqtt"),
);

let generator = network.configure_streaming(StreamFormat::AdcDacData);
Expand Down
13 changes: 5 additions & 8 deletions src/bin/lockin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use stabilizer::{
},
net::{
data_stream::{FrameGenerator, StreamFormat, StreamTarget},
miniconf::Miniconf,
miniconf::Tree,
serde::{Deserialize, Serialize},
telemetry::{Telemetry, TelemetryBuffer},
NetworkState, NetworkUsers,
Expand Down Expand Up @@ -97,7 +97,7 @@ enum LockinMode {
External,
}

#[derive(Copy, Clone, Debug, Miniconf)]
#[derive(Copy, Clone, Debug, Tree)]
pub struct Settings {
/// Configure the Analog Front End (AFE) gain.
///
Expand All @@ -108,7 +108,7 @@ pub struct Settings {
///
/// # Value
/// Any of the variants of [Gain] enclosed in double quotes.
#[miniconf(defer)]
#[tree]
afe: [Gain; 2],

/// Specifies the operational mode of the lockin.
Expand Down Expand Up @@ -168,7 +168,7 @@ pub struct Settings {
///
/// # Value
/// One of the variants of [Conf] enclosed in double quotes.
#[miniconf(defer)]
#[tree]
output_conf: [Conf; 2],

/// Specifies the telemetry output period in seconds.
Expand Down Expand Up @@ -260,10 +260,7 @@ mod app {
clock,
env!("CARGO_BIN_NAME"),
stabilizer.net.mac_address,
option_env!("BROKER")
.unwrap_or("10.34.16.1")
.parse()
.unwrap(),
option_env!("BROKER").unwrap_or("mqtt"),
);

let generator = network.configure_streaming(StreamFormat::AdcDacData);
Expand Down
14 changes: 11 additions & 3 deletions src/hardware/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ const NUM_SOCKETS: usize = NUM_UDP_SOCKETS + NUM_TCP_SOCKETS;
pub struct NetStorage {
pub ip_addrs: [smoltcp::wire::IpCidr; 1],

// Note: There is an additional socket set item required for the DHCP socket.
pub sockets: [smoltcp::iface::SocketStorage<'static>; NUM_SOCKETS + 1],
// Note: There is an additional socket set item required for the DHCP and DNS sockets
// respectively.
pub sockets: [smoltcp::iface::SocketStorage<'static>; NUM_SOCKETS + 2],
pub tcp_socket_storage: [TcpSocketStorage; NUM_TCP_SOCKETS],
pub udp_socket_storage: [UdpSocketStorage; NUM_UDP_SOCKETS],
pub dns_storage: [Option<smoltcp::socket::dns::DnsQuery>; 1],
}

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -79,9 +81,10 @@ impl Default for NetStorage {
ip_addrs: [smoltcp::wire::IpCidr::Ipv6(
smoltcp::wire::Ipv6Cidr::SOLICITED_NODE_PREFIX,
)],
sockets: [smoltcp::iface::SocketStorage::EMPTY; NUM_SOCKETS + 1],
sockets: [smoltcp::iface::SocketStorage::EMPTY; NUM_SOCKETS + 2],
tcp_socket_storage: [TcpSocketStorage::new(); NUM_TCP_SOCKETS],
udp_socket_storage: [UdpSocketStorage::new(); NUM_UDP_SOCKETS],
dns_storage: [None; 1],
}
}
}
Expand Down Expand Up @@ -696,6 +699,11 @@ pub fn setup(
sockets.add(smoltcp::socket::dhcpv4::Socket::new());
}

sockets.add(smoltcp::socket::dns::Socket::new(
&[],
&mut store.dns_storage[..],
));

for storage in store.udp_socket_storage[..].iter_mut() {
let udp_socket = {
let rx_buffer = smoltcp::socket::udp::PacketBuffer::new(
Expand Down
6 changes: 3 additions & 3 deletions src/hardware/signal_generator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use miniconf::Miniconf;
use miniconf::Tree;
use rand_core::{RngCore, SeedableRng};
use rand_xorshift::XorShiftRng;
use serde::{Deserialize, Serialize};
Expand All @@ -14,13 +14,13 @@ pub enum Signal {

/// Basic configuration for a generated signal.
///
/// # Miniconf
/// # Miniconf Tree
/// `{"signal": <signal>, "frequency", 1000.0, "symmetry": 0.5, "amplitude": 1.0}`
///
/// Where `<signal>` may be any of [Signal] variants, `frequency` specifies the signal frequency
/// in Hertz, `symmetry` specifies the normalized signal symmetry which ranges from 0 - 1.0, and
/// `amplitude` specifies the signal amplitude in Volts.
#[derive(Copy, Clone, Debug, Miniconf)]
#[derive(Copy, Clone, Debug, Tree)]
pub struct BasicConfig {
/// The signal type that should be generated. See [Signal] variants.
pub signal: Signal,
Expand Down
Loading

0 comments on commit b2f11b4

Please sign in to comment.