From 34f438a558aec43c537fa08b6fa72a57c280eb7e Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Fri, 4 Feb 2022 09:06:48 +0100 Subject: [PATCH] Fixing status reporting to include channel state --- src/hardware/rf_channel.rs | 40 +++++++++++++++++++++----------------- src/main.rs | 7 ++++--- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/hardware/rf_channel.rs b/src/hardware/rf_channel.rs index 72317dab..c6068ee4 100644 --- a/src/hardware/rf_channel.rs +++ b/src/hardware/rf_channel.rs @@ -270,6 +270,7 @@ pub struct ChannelStatus { input_power: f32, reflected_power: f32, output_power: f32, + state: sm::States, } /// Represents a means of interacting with an RF output channel. @@ -574,24 +575,6 @@ impl RfChannel { self.settings.settings().bias_voltage } - /// Get the channel status. - pub fn get_status(&mut self, adc: &mut hal::adc::Adc) -> ChannelStatus { - let power_measurements = self.get_supply_measurements(); - - ChannelStatus { - reflected_overdrive: self.pins.reflected_overdrive.is_high().unwrap(), - output_overdrive: self.pins.output_overdrive.is_high().unwrap(), - alert: self.pins.alert.is_low().unwrap(), - temperature: self.get_temperature(), - p28v_current: power_measurements.i_p28v0ch, - p5v_current: power_measurements.i_p5v0ch, - p5v_voltage: power_measurements.v_p5v0mp, - input_power: self.get_input_power(), - output_power: self.get_output_power(adc), - reflected_power: self.get_reflected_power(adc), - } - } - pub fn settings(&self) -> &ChannelSettings { self.settings.settings() } @@ -896,4 +879,25 @@ impl sm::StateMachine { Ok(()) } + + /// Get status information about the channel. + pub fn get_status(&mut self, adc: &mut hal::adc::Adc) -> ChannelStatus { + let channel = self.context_mut(); + + let power_measurements = channel.get_supply_measurements(); + + ChannelStatus { + reflected_overdrive: channel.pins.reflected_overdrive.is_high().unwrap(), + output_overdrive: channel.pins.output_overdrive.is_high().unwrap(), + alert: channel.pins.alert.is_low().unwrap(), + temperature: channel.get_temperature(), + p28v_current: power_measurements.i_p28v0ch, + p5v_current: power_measurements.i_p5v0ch, + p5v_voltage: power_measurements.v_p5v0mp, + input_power: channel.get_input_power(), + output_power: channel.get_output_power(adc), + reflected_power: channel.get_reflected_power(adc), + state: *self.state(), + } + } } diff --git a/src/main.rs b/src/main.rs index d98aa35e..94b7a823 100644 --- a/src/main.rs +++ b/src/main.rs @@ -196,9 +196,10 @@ const APP: () = { // And broadcast the measured data over the telemetry interface. for idx in Channel::into_enum_iter() { c.resources.main_bus.lock(|main_bus| { - main_bus.channels.channel_mut(idx).map(|(ch, adc)| { - control.report_telemetry(idx, &ch.context_mut().get_status(adc)) - }) + main_bus + .channels + .channel_mut(idx) + .map(|(ch, adc)| control.report_telemetry(idx, &ch.get_status(adc))) }); }