fix temperature, log unknown chargestate value
All checks were successful
Build .deb on release / Build-Deb (push) Successful in 1m53s

This commit is contained in:
Alex Janka 2024-01-28 11:15:17 +11:00
parent 65e86c2359
commit b1de54501c
3 changed files with 33 additions and 8 deletions

19
Cargo.lock generated
View file

@ -485,6 +485,12 @@ dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "crunchy"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
[[package]]
name = "crypto-common"
version = "0.1.6"
@ -849,6 +855,16 @@ dependencies = [
"tracing",
]
[[package]]
name = "half"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc52e53916c08643f1b56ec082790d1e86a32e58dc5268f897f313fbae7b4872"
dependencies = [
"cfg-if 1.0.0",
"crunchy",
]
[[package]]
name = "hashbrown"
version = "0.14.3"
@ -2538,11 +2554,12 @@ dependencies = [
[[package]]
name = "tesla-charge-controller"
version = "1.1.0"
version = "1.1.1"
dependencies = [
"chrono",
"clap 4.4.11",
"env_logger 0.10.1",
"half",
"if_chain",
"include_dir",
"lazy_static 1.4.0",

View file

@ -1,6 +1,6 @@
[package]
name = "tesla-charge-controller"
version = "1.1.0"
version = "1.1.1"
edition = "2021"
license = "MITNFA"
description = "Controls Tesla charge rate based on solar charge data"
@ -31,3 +31,4 @@ libmodbus-rs = "0.8.3"
if_chain = "1.0.2"
notify-debouncer-mini = { version = "0.4.1", default-features = false }
lazy_static = "1.4"
half = "2.3"

View file

@ -1,7 +1,10 @@
use libmodbus_rs::{Modbus, ModbusClient, ModbusRTU};
use prometheus::core::{AtomicI64, GenericGauge};
use crate::{charge_controllers::gauges::*, errors::TristarError};
use crate::{
charge_controllers::gauges::*,
errors::{PrintErrors, TristarError},
};
const DEVICE_ID: u8 = 0x01;
const RAM_DATA_SIZE: u16 = 0x005B;
@ -51,7 +54,7 @@ pub struct TristarState {
battery_voltage: f64,
target_voltage: f64,
input_current: f64,
battery_temp: u16,
battery_temp: f64,
charge_state: ChargeState,
tristar_input_voltage: f64,
tristar_charge_current: f64,
@ -68,7 +71,7 @@ impl TristarState {
battery_voltage: scaling.get_voltage(ram[TristarRamAddress::AdcVbFMed]),
target_voltage: scaling.get_voltage(ram[TristarRamAddress::VbRef]),
input_current: scaling.get_current(ram[TristarRamAddress::AdcIaFShadow]),
battery_temp: ram[TristarRamAddress::Tbatt],
battery_temp: half::f16::from_bits(ram[TristarRamAddress::Tbatt]).to_f64() * 512.,
charge_state: ChargeState::from(ram[TristarRamAddress::ChargeState]),
tristar_input_voltage: scaling.get_voltage(ram[TristarRamAddress::AdcVaF]),
tristar_charge_current: scaling.get_current(ram[TristarRamAddress::AdcIbFShadow]),
@ -115,7 +118,10 @@ impl From<u16> for ChargeState {
7 => Self::Float,
8 => Self::Equalize,
9 => Self::Slave,
_ => Self::Unknown,
_ => {
log::info!("Unknown chargestate value: {value}");
Self::Unknown
}
}
}
}
@ -245,8 +251,9 @@ impl Tristar {
}
pub fn refresh(&mut self) {
if let Ok(new_state) = self
if let Some(new_state) = self
.get_data()
.some_or_print_with("reading tristar state")
.map(|scaling| TristarState::from_ram(scaling, &self.data_in))
{
BATTERY_VOLTAGE
@ -260,7 +267,7 @@ impl Tristar {
.set(new_state.input_current);
BATTERY_TEMP
.with_label_values(&[&self.port_name])
.set(new_state.battery_temp.into());
.set(new_state.battery_temp);
TRISTAR_INPUT_VOLTAGE
.with_label_values(&[&self.port_name])
.set(new_state.tristar_input_voltage);