From 46e23d1da1d9b25f9c8fcc22f5f84677e932b0c9 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Mon, 30 Dec 2024 14:09:43 +1100 Subject: [PATCH] ccs: actually follow primary! please be careful --- .../src/controller.rs | 13 +++++---- charge-controller-supervisor/src/main.rs | 3 --- charge-controller-supervisor/src/tristar.rs | 27 +++++++------------ 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/charge-controller-supervisor/src/controller.rs b/charge-controller-supervisor/src/controller.rs index 557cf0c..f6148cf 100644 --- a/charge-controller-supervisor/src/controller.rs +++ b/charge-controller-supervisor/src/controller.rs @@ -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)); } diff --git a/charge-controller-supervisor/src/main.rs b/charge-controller-supervisor/src/main.rs index 53c75c9..11ce634 100644 --- a/charge-controller-supervisor/src/main.rs +++ b/charge-controller-supervisor/src/main.rs @@ -65,9 +65,6 @@ async fn run() -> eyre::Result<()> { } } -static IS_PRINTING_TARGETS: std::sync::LazyLock = - 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 diff --git a/charge-controller-supervisor/src/tristar.rs b/charge-controller-supervisor/src/tristar.rs index 44cffd8..d9bb6ff 100644 --- a/charge-controller-supervisor/src/tristar.rs +++ b/charge-controller-supervisor/src/tristar.rs @@ -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)) } }