Adding WIP updates for telemetry
This commit is contained in:
parent
4888f18f88
commit
06b328ff52
|
@ -708,6 +708,16 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shared-bus"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "78b60428415b23ed3f0e3abc776e10e548cf2cbb4288e73d5d181a02b5a90b95"
|
||||||
|
dependencies = [
|
||||||
|
"cortex-m 0.6.7",
|
||||||
|
"embedded-hal",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smoltcp"
|
name = "smoltcp"
|
||||||
version = "0.7.1"
|
version = "0.7.1"
|
||||||
|
@ -753,6 +763,7 @@ dependencies = [
|
||||||
"panic-semihosting",
|
"panic-semihosting",
|
||||||
"paste",
|
"paste",
|
||||||
"serde",
|
"serde",
|
||||||
|
"shared-bus",
|
||||||
"smoltcp-nal",
|
"smoltcp-nal",
|
||||||
"stm32h7xx-hal",
|
"stm32h7xx-hal",
|
||||||
]
|
]
|
||||||
|
|
|
@ -45,6 +45,7 @@ dsp = { path = "dsp" }
|
||||||
ad9959 = { path = "ad9959" }
|
ad9959 = { path = "ad9959" }
|
||||||
generic-array = "0.14"
|
generic-array = "0.14"
|
||||||
miniconf = "0.1.0"
|
miniconf = "0.1.0"
|
||||||
|
shared-bus = {version = "0.2.2", features = ["cortex-m"] }
|
||||||
|
|
||||||
[dependencies.mcp23017]
|
[dependencies.mcp23017]
|
||||||
git = "https://github.com/mrd0ll4r/mcp23017.git"
|
git = "https://github.com/mrd0ll4r/mcp23017.git"
|
||||||
|
|
|
@ -13,7 +13,7 @@ use hardware::{
|
||||||
DigitalInput1, InputPin, SystemTimer, AFE0, AFE1,
|
DigitalInput1, InputPin, SystemTimer, AFE0, AFE1,
|
||||||
};
|
};
|
||||||
|
|
||||||
use net::{Action, MqttInterface};
|
use net::{UpdateState, MiniconfClient, NetworkProcessor};
|
||||||
|
|
||||||
const SCALE: f32 = i16::MAX as _;
|
const SCALE: f32 = i16::MAX as _;
|
||||||
|
|
||||||
|
@ -49,6 +49,11 @@ impl Default for Settings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct NetworkUsers {
|
||||||
|
miniconf: MiniconfClient<Settings>,
|
||||||
|
processor: NetworkProcessor,
|
||||||
|
}
|
||||||
|
|
||||||
#[rtic::app(device = stm32h7xx_hal::stm32, peripherals = true, monotonic = stabilizer::hardware::SystemTimer)]
|
#[rtic::app(device = stm32h7xx_hal::stm32, peripherals = true, monotonic = stabilizer::hardware::SystemTimer)]
|
||||||
const APP: () = {
|
const APP: () = {
|
||||||
struct Resources {
|
struct Resources {
|
||||||
|
@ -56,8 +61,8 @@ const APP: () = {
|
||||||
digital_inputs: (DigitalInput0, DigitalInput1),
|
digital_inputs: (DigitalInput0, DigitalInput1),
|
||||||
adcs: (Adc0Input, Adc1Input),
|
adcs: (Adc0Input, Adc1Input),
|
||||||
dacs: (Dac0Output, Dac1Output),
|
dacs: (Dac0Output, Dac1Output),
|
||||||
mqtt: MqttInterface<Settings>,
|
network: NetworkUsers,
|
||||||
telemetry: net::TelemetryBuffer,
|
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
|
|
||||||
#[init([[[0.; 5]; IIR_CASCADE_LENGTH]; 2])]
|
#[init([[[0.; 5]; IIR_CASCADE_LENGTH]; 2])]
|
||||||
|
@ -69,17 +74,32 @@ const APP: () = {
|
||||||
// Configure the microcontroller
|
// Configure the microcontroller
|
||||||
let (mut stabilizer, _pounder) = hardware::setup(c.core, c.device);
|
let (mut stabilizer, _pounder) = hardware::setup(c.core, c.device);
|
||||||
|
|
||||||
let mqtt = MqttInterface::new(
|
let network = {
|
||||||
stabilizer.net.stack,
|
let stack_manager = cortex_m::singleton!(: NetworkManager = NetworkManager::new(stabilizer.net.stack)).unwrap();
|
||||||
|
|
||||||
|
let processor = NetworkProcessor::new(
|
||||||
|
stack_manager.acquire_stack(),
|
||||||
|
stabilizer.net.phy,
|
||||||
|
stabilizer.cycle_counter,
|
||||||
|
);
|
||||||
|
|
||||||
|
let settings = MqttInterface::new(
|
||||||
|
stack_manager.acquire_stack(),
|
||||||
"",
|
"",
|
||||||
&net::get_device_prefix(
|
&net::get_device_prefix(
|
||||||
env!("CARGO_BIN_NAME"),
|
env!("CARGO_BIN_NAME"),
|
||||||
stabilizer.net.mac_address,
|
stabilizer.net.mac_address,
|
||||||
),
|
),
|
||||||
stabilizer.net.phy,
|
|
||||||
stabilizer.cycle_counter,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO: Add telemetry client
|
||||||
|
|
||||||
|
NetworkUsers {
|
||||||
|
miniconf: settings,
|
||||||
|
processor,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Spawn a settings update for default settings.
|
// Spawn a settings update for default settings.
|
||||||
c.spawn.settings_update().unwrap();
|
c.spawn.settings_update().unwrap();
|
||||||
c.spawn.telemetry().unwrap();
|
c.spawn.telemetry().unwrap();
|
||||||
|
@ -93,11 +113,12 @@ const APP: () = {
|
||||||
// Start sampling ADCs.
|
// Start sampling ADCs.
|
||||||
stabilizer.adc_dac_timer.start();
|
stabilizer.adc_dac_timer.start();
|
||||||
|
|
||||||
|
|
||||||
init::LateResources {
|
init::LateResources {
|
||||||
afes: stabilizer.afes,
|
afes: stabilizer.afes,
|
||||||
adcs: stabilizer.adcs,
|
adcs: stabilizer.adcs,
|
||||||
dacs: stabilizer.dacs,
|
dacs: stabilizer.dacs,
|
||||||
mqtt,
|
network,
|
||||||
digital_inputs: stabilizer.digital_inputs,
|
digital_inputs: stabilizer.digital_inputs,
|
||||||
telemetry: net::TelemetryBuffer::default(),
|
telemetry: net::TelemetryBuffer::default(),
|
||||||
settings: Settings::default(),
|
settings: Settings::default(),
|
||||||
|
@ -168,23 +189,25 @@ const APP: () = {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle(resources=[mqtt], spawn=[settings_update])]
|
#[idle(resources=[network], spawn=[settings_update])]
|
||||||
fn idle(mut c: idle::Context) -> ! {
|
fn idle(mut c: idle::Context) -> ! {
|
||||||
loop {
|
loop {
|
||||||
match c.resources.mqtt.lock(|mqtt| mqtt.update()) {
|
// Update the smoltcp network stack.
|
||||||
Some(Action::Sleep) => cortex_m::asm::wfi(),
|
let poll_result = c.resources.network.lock(|network| network.processor.poll());
|
||||||
Some(Action::UpdateSettings) => {
|
|
||||||
|
// Service the MQTT configuration client.
|
||||||
|
if c.resources.miniconf_client.lock(|client| client.update()) == UpdateStatus::Updated {
|
||||||
c.spawn.settings_update().unwrap()
|
c.spawn.settings_update().unwrap()
|
||||||
}
|
} else if poll_result == UpdateStatus::NoChange {
|
||||||
_ => {}
|
cortex_m::asm::wfi();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(priority = 1, resources=[mqtt, afes, settings])]
|
#[task(priority = 1, resources=[network, afes, settings])]
|
||||||
fn settings_update(mut c: settings_update::Context) {
|
fn settings_update(mut c: settings_update::Context) {
|
||||||
// Update the IIR channels.
|
// Update the IIR channels.
|
||||||
let settings = c.resources.mqtt.settings();
|
let settings = c.resources.network.miniconf.settings();
|
||||||
c.resources.settings.lock(|current| *current = *settings);
|
c.resources.settings.lock(|current| *current = *settings);
|
||||||
|
|
||||||
// Update AFEs
|
// Update AFEs
|
||||||
|
@ -192,15 +215,17 @@ const APP: () = {
|
||||||
c.resources.afes.1.set_gain(settings.afe[1]);
|
c.resources.afes.1.set_gain(settings.afe[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(priority = 1, resources=[mqtt, settings, telemetry], schedule=[telemetry])]
|
#[task(priority = 1, resources=[network, settings, telemetry], schedule=[telemetry])]
|
||||||
fn telemetry(mut c: telemetry::Context) {
|
fn telemetry(mut c: telemetry::Context) {
|
||||||
let telemetry =
|
let telemetry =
|
||||||
c.resources.telemetry.lock(|telemetry| telemetry.clone());
|
c.resources.telemetry.lock(|telemetry| telemetry.clone());
|
||||||
|
|
||||||
let gains = c.resources.settings.lock(|settings| settings.afe.clone());
|
let gains = c.resources.settings.lock(|settings| settings.afe.clone());
|
||||||
c.resources
|
|
||||||
.mqtt
|
// TODO: Publish telemetry through the telemetry client here.
|
||||||
.publish_telemetry(&telemetry.to_telemetry(gains[0], gains[1]));
|
//c.resources
|
||||||
|
// .mqtt
|
||||||
|
// .publish_telemetry(&telemetry.to_telemetry(gains[0], gains[1]));
|
||||||
|
|
||||||
let telemetry_period = c
|
let telemetry_period = c
|
||||||
.resources
|
.resources
|
||||||
|
|
Loading…
Reference in New Issue