main: remove all plain-text responses

pull/20/head
Astro 2020-09-30 23:53:13 +02:00
parent 026dd1ed9c
commit 438da74721
1 changed files with 20 additions and 75 deletions

View File

@ -27,7 +27,6 @@ use smoltcp::{
wire::EthernetAddress, wire::EthernetAddress,
}; };
use uom::{ use uom::{
fmt::DisplayStyle::Abbreviation,
si::{ si::{
f64::{ f64::{
ElectricCurrent, ElectricCurrent,
@ -202,11 +201,11 @@ fn main() -> ! {
Ok(SessionInput::Command(command)) => match command { Ok(SessionInput::Command(command)) => match command {
Command::Quit => Command::Quit =>
socket.close(), socket.close(),
Command::Reporting(reporting) => { Command::Reporting(_reporting) => {
let _ = writeln!(socket, "report={}", if reporting { "on" } else { "off" }); // handled by session
} }
Command::Show(ShowCommand::Reporting) => { Command::Show(ShowCommand::Reporting) => {
let _ = writeln!(socket, "report={}", if session.reporting() { "on" } else { "off" }); let _ = writeln!(socket, "{{ \"report\": {:?} }}", session.reporting());
} }
Command::Show(ShowCommand::Input) => { Command::Show(ShowCommand::Input) => {
for channel in 0..CHANNELS { for channel in 0..CHANNELS {
@ -260,8 +259,6 @@ fn main() -> ! {
Command::PwmPid { channel } => { Command::PwmPid { channel } => {
channels.channel_state(channel).pid_engaged = true; channels.channel_state(channel).pid_engaged = true;
leds.g3.on(); leds.g3.on();
let _ = writeln!(socket, "channel {}: PID enabled to control PWM", channel
);
} }
Command::Pwm { channel, pin, value } => { Command::Pwm { channel, pin, value } => {
match pin { match pin {
@ -269,44 +266,20 @@ fn main() -> ! {
channels.channel_state(channel).pid_engaged = false; channels.channel_state(channel).pid_engaged = false;
leds.g3.off(); leds.g3.off();
let current = ElectricCurrent::new::<ampere>(value); let current = ElectricCurrent::new::<ampere>(value);
let (current, max) = channels.set_i(channel, current); channels.set_i(channel, current);
channels.power_up(channel); channels.power_up(channel);
let _ = writeln!(
socket, "channel {}: i_set DAC output set to {:.3} / {:.3}",
channel,
current.into_format_args(ampere, Abbreviation),
max.into_format_args(ampere, Abbreviation),
);
} }
PwmPin::MaxV => { PwmPin::MaxV => {
let voltage = ElectricPotential::new::<volt>(value); let voltage = ElectricPotential::new::<volt>(value);
let (voltage, max) = channels.set_max_v(channel, voltage); channels.set_max_v(channel, voltage);
let _ = writeln!(
socket, "channel {}: max_v set to {:.3} / {:.3}",
channel,
voltage.into_format_args(volt, Abbreviation),
max.into_format_args(volt, Abbreviation),
);
} }
PwmPin::MaxIPos => { PwmPin::MaxIPos => {
let current = ElectricCurrent::new::<ampere>(value); let current = ElectricCurrent::new::<ampere>(value);
let (current, max) = channels.set_max_i_pos(channel, current); channels.set_max_i_pos(channel, current);
let _ = writeln!(
socket, "channel {}: max_i_pos set to {:.3} / {:.3}",
channel,
current.into_format_args(ampere, Abbreviation),
max.into_format_args(ampere, Abbreviation),
);
} }
PwmPin::MaxINeg => { PwmPin::MaxINeg => {
let current = ElectricCurrent::new::<ampere>(value); let current = ElectricCurrent::new::<ampere>(value);
let (current, max) = channels.set_max_i_neg(channel, current); channels.set_max_i_neg(channel, current);
let _ = writeln!(
socket, "channel {}: max_i_neg set to {:.3} / {:.3}",
channel,
current.into_format_args(ampere, Abbreviation),
max.into_format_args(ampere, Abbreviation),
);
} }
} }
} }
@ -316,15 +289,6 @@ fn main() -> ! {
state.center = center; state.center = center;
if !state.pid_engaged { if !state.pid_engaged {
channels.set_i(channel, i_tec); channels.set_i(channel, i_tec);
let _ = writeln!(
socket, "channel {}: center point updated, output readjusted for {:.3}",
channel, i_tec.into_format_args(ampere, Abbreviation),
);
} else {
let _ = writeln!(
socket, "channel {}: center point updated",
channel,
);
} }
} }
Command::Pid { channel, parameter, value } => { Command::Pid { channel, parameter, value } => {
@ -351,7 +315,6 @@ fn main() -> ! {
IntegralMax => IntegralMax =>
pid.parameters.integral_max = value as f32, pid.parameters.integral_max = value as f32,
} }
let _ = writeln!(socket, "PID parameter updated");
} }
Command::SteinhartHart { channel, parameter, value } => { Command::SteinhartHart { channel, parameter, value } => {
let sh = &mut channels.channel_state(channel).sh; let sh = &mut channels.channel_state(channel).sh;
@ -361,50 +324,33 @@ fn main() -> ! {
B => sh.b = value, B => sh.b = value,
R0 => sh.r0 = ElectricalResistance::new::<ohm>(value), R0 => sh.r0 = ElectricalResistance::new::<ohm>(value),
} }
let _ = writeln!(socket, "Steinhart-Hart equation parameter updated");
} }
Command::PostFilter { channel, rate: None } => { Command::PostFilter { channel, rate: None } => {
channels.adc.set_postfilter(channel as u8, None).unwrap(); channels.adc.set_postfilter(channel as u8, None).unwrap();
let _ = writeln!(
socket, "channel {}: postfilter disabled",
channel
);
} }
Command::PostFilter { channel, rate: Some(rate) } => { Command::PostFilter { channel, rate: Some(rate) } => {
let filter = ad7172::PostFilter::closest(rate); let filter = ad7172::PostFilter::closest(rate);
match filter { match filter {
Some(filter) => { Some(filter) =>
channels.adc.set_postfilter(channel as u8, Some(filter)).unwrap(); channels.adc.set_postfilter(channel as u8, Some(filter)).unwrap(),
let _ = writeln!( None =>
socket, "channel {}: postfilter set to {:.2} SPS", error!("unable to choose postfilter for rate {:.3}", rate),
channel, filter.output_rate().unwrap()
);
}
None => {
let _ = writeln!(socket, "Unable to choose postfilter");
}
} }
} }
Command::Load => { Command::Load => {
match Config::load(&mut eeprom) { match Config::load(&mut eeprom) {
Ok(config) => { Ok(config) =>
config.apply(&mut channels); config.apply(&mut channels),
let _ = writeln!(socket, "Config loaded from EEPROM."); Err(e) =>
} error!("unable to load eeprom config: {:?}", e),
Err(e) => {
let _ = writeln!(socket, "Error: {:?}", e);
}
} }
} }
Command::Save => { Command::Save => {
let config = Config::new(&mut channels); let config = Config::new(&mut channels);
match config.save(&mut eeprom) { match config.save(&mut eeprom) {
Ok(()) => { Ok(()) => {},
let _ = writeln!(socket, "Config saved to EEPROM."); Err(e) =>
} error!("unable to save eeprom config: {:?}", e),
Err(e) => {
let _ = writeln!(socket, "Error saving config: {:?}", e);
}
} }
} }
Command::Reset => { Command::Reset => {
@ -415,9 +361,8 @@ fn main() -> ! {
SCB::sys_reset(); SCB::sys_reset();
} }
} }
Ok(SessionInput::Error(e)) => { Ok(SessionInput::Error(e)) =>
let _ = writeln!(socket, "Command error: {:?}", e); error!("session input: {:?}", e),
}
Err(_) => Err(_) =>
socket.close(), socket.close(),
} }