ccs: actually follow primary! please be careful

This commit is contained in:
Alex Janka 2024-12-30 14:09:43 +11:00
parent 296e1d0ccf
commit 46e23d1da1
3 changed files with 16 additions and 27 deletions

View file

@ -72,13 +72,12 @@ impl Controller {
let data = self.inner.refresh().await?;
if let Some(tx) = self.voltage_tx.as_mut() {
if *crate::IS_PRINTING_TARGETS {
log::error!(
"tristar {}: primary: sending target voltage {}",
self.name,
data.target_voltage
);
}
log::debug!(
"tristar {}: primary: sending target voltage {}",
self.name,
data.target_voltage
);
tx.send_to_all(VoltageCommand::Set(data.target_voltage));
}

View file

@ -65,9 +65,6 @@ async fn run() -> eyre::Result<()> {
}
}
static IS_PRINTING_TARGETS: std::sync::LazyLock<bool> =
std::sync::LazyLock::new(|| std::env::var("SECONDARIES_PRINT_TARGET").is_ok());
async fn watch(args: Args) -> eyre::Result<()> {
let config: config::Config = serde_json::from_reader(std::fs::File::open(args.config)?)?;
if config

View file

@ -1,5 +1,5 @@
use prometheus::core::{AtomicI64, GenericGauge};
use tokio_modbus::client::Reader;
use tokio_modbus::client::{Reader, Writer};
use crate::gauges::{
BATTERY_TEMP, BATTERY_VOLTAGE, CHARGE_STATE, HEATSINK_TEMP, INPUT_CURRENT, TARGET_VOLTAGE,
@ -328,15 +328,15 @@ impl Tristar {
pub async fn set_target_voltage(&mut self, target_voltage: f64) -> eyre::Result<()> {
let scaled_voltage: u16 = self.scale_voltage(target_voltage)?;
// self.modbus
// .write_single_register(TristarRamAddress::VbRefSlave as u16, scaled_voltage)
// .await??;
if *crate::IS_PRINTING_TARGETS {
log::error!(
"tristar {} being set to voltage {target_voltage} (scaled: {scaled_voltage:#X?})",
self.friendly_name
);
}
self.modbus
.write_single_register(TristarRamAddress::VbRefSlave as u16, scaled_voltage)
.await??;
log::debug!(
"tristar {} being set to voltage {target_voltage} (scaled: {scaled_voltage:#X?})",
self.friendly_name
);
Ok(())
}
@ -352,13 +352,6 @@ impl Tristar {
.modbus
.read_holding_registers(0x0000, RAM_DATA_SIZE + 1)
.await??;
if *crate::IS_PRINTING_TARGETS {
log::error!(
"tristar {}: target voltage raw {:#X?}",
self.friendly_name,
data[TristarRamAddress::VbRef as usize]
)
}
Ok(TristarState::from_ram(&data))
}
}