v1.9.9-pre-24: ccs: tristar: parse serial
All checks were successful
Build and release .deb / Release (push) Successful in 55s

This commit is contained in:
Alex Janka 2025-01-10 15:38:12 +11:00
parent 21f3a176ab
commit ae9091c95e
3 changed files with 28 additions and 12 deletions

4
Cargo.lock generated
View file

@ -239,7 +239,7 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]] [[package]]
name = "charge-controller-supervisor" name = "charge-controller-supervisor"
version = "1.9.9-pre-23" version = "1.9.9-pre-24"
dependencies = [ dependencies = [
"chrono", "chrono",
"clap", "clap",
@ -2203,7 +2203,7 @@ dependencies = [
[[package]] [[package]]
name = "tesla-charge-controller" name = "tesla-charge-controller"
version = "1.9.9-pre-23" version = "1.9.9-pre-24"
dependencies = [ dependencies = [
"chrono", "chrono",
"clap", "clap",

View file

@ -4,7 +4,7 @@ default-members = ["charge-controller-supervisor"]
resolver = "2" resolver = "2"
[workspace.package] [workspace.package]
version = "1.9.9-pre-23" version = "1.9.9-pre-24"
[workspace.lints.clippy] [workspace.lints.clippy]
pedantic = "warn" pedantic = "warn"

View file

@ -106,7 +106,7 @@ impl ModbusTimeout {
Ok(r??) Ok(r??)
} }
} }
#[derive(Debug, Clone, Copy, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TristarSettings { pub struct TristarSettings {
network: Option<NetworkSettings>, network: Option<NetworkSettings>,
charge: ChargeSettings, charge: ChargeSettings,
@ -154,7 +154,7 @@ impl NetworkSettings {
} }
} }
#[derive(Debug, Clone, Copy, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChargeSettings { pub struct ChargeSettings {
absorption_voltage: f64, absorption_voltage: f64,
float_voltage: f64, float_voltage: f64,
@ -191,7 +191,7 @@ pub struct LedThresholds {
yellowred_to_red: f64, yellowred_to_red: f64,
} }
#[derive(Debug, Clone, Copy, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReadOnly { pub struct ReadOnly {
hourmeter: u32, hourmeter: u32,
charge_ah_resetable: f64, charge_ah_resetable: f64,
@ -203,11 +203,18 @@ pub struct ReadOnly {
va_max: f64, va_max: f64,
days_since_last_equalize: u16, days_since_last_equalize: u16,
battery_service_timer_days: u16, battery_service_timer_days: u16,
serial: u64, serial: Serial,
model: Model, model: Model,
hardware_version: u16, hardware_version: u16,
} }
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Serial {
Valid(String),
Invalid(u64),
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum Model { pub enum Model {
Tristar45A, Tristar45A,
@ -325,11 +332,20 @@ impl ChargeSettings {
let s2 = get(buf, TristarEepromAddress::Eserial2)?; let s2 = get(buf, TristarEepromAddress::Eserial2)?;
let s3 = get(buf, TristarEepromAddress::Eserial3)?; let s3 = get(buf, TristarEepromAddress::Eserial3)?;
let mut serial = [0; 8];
serial[0..2].copy_from_slice(&s0.to_le_bytes());
serial[2..4].copy_from_slice(&s1.to_le_bytes());
serial[4..6].copy_from_slice(&s2.to_le_bytes());
serial[6..8].copy_from_slice(&s3.to_le_bytes());
if let Ok(v) = std::str::from_utf8(&serial) {
Serial::Valid(v.to_string())
} else {
let mut serial = u64::from(s0); let mut serial = u64::from(s0);
serial |= u64::from(s1) << 16; serial |= u64::from(s1) << 16;
serial |= u64::from(s2) << 32; serial |= u64::from(s2) << 32;
serial |= u64::from(s3) << 48; serial |= u64::from(s3) << 48;
serial Serial::Invalid(serial)
}
}; };
let model = if get(buf, TristarEepromAddress::Emodel)? == 0 { let model = if get(buf, TristarEepromAddress::Emodel)? == 0 {