ccs: tristar: parse alarms, faults and flags
This commit is contained in:
parent
ae9091c95e
commit
12bc89ede6
3 changed files with 93 additions and 9 deletions
19
Cargo.lock
generated
19
Cargo.lock
generated
|
@ -185,9 +185,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
|||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.6.0"
|
||||
version = "2.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
||||
checksum = "1be3f42a67d6d345ecd59f675f3f012d6974981560836e938c22b424b85ce1be"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
@ -241,6 +241,7 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
|||
name = "charge-controller-supervisor"
|
||||
version = "1.9.9-pre-24"
|
||||
dependencies = [
|
||||
"bitflags 2.7.0",
|
||||
"chrono",
|
||||
"clap",
|
||||
"env_logger",
|
||||
|
@ -381,7 +382,7 @@ version = "0.4.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b035a542cf7abf01f2e3c4d5a7acbaebfefe120ae4efc7bde3df98186e4b8af7"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"bitflags 2.7.0",
|
||||
"proc-macro2",
|
||||
"proc-macro2-diagnostics",
|
||||
"quote",
|
||||
|
@ -1169,7 +1170,7 @@ version = "0.1.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"bitflags 2.7.0",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
]
|
||||
|
@ -1360,7 +1361,7 @@ version = "7.0.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c533b4c39709f9ba5005d8002048266593c1cfaf3c5f0739d5b8ab0c6c504009"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"bitflags 2.7.0",
|
||||
"filetime",
|
||||
"fsevent-sys",
|
||||
"inotify",
|
||||
|
@ -1675,7 +1676,7 @@ version = "0.5.8"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"bitflags 2.7.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1888,7 +1889,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94"
|
||||
dependencies = [
|
||||
"base64 0.21.7",
|
||||
"bitflags 2.6.0",
|
||||
"bitflags 2.7.0",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
]
|
||||
|
@ -1911,7 +1912,7 @@ version = "0.38.42"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"bitflags 2.7.0",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
|
@ -2053,7 +2054,7 @@ version = "4.6.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "779e2977f0cc2ff39708fef48f96f3768ac8ddd8c6caaaab82e83bd240ef99b2"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"bitflags 2.7.0",
|
||||
"cfg-if",
|
||||
"core-foundation",
|
||||
"core-foundation-sys",
|
||||
|
|
|
@ -12,6 +12,7 @@ systemd-units = { enable = false }
|
|||
depends = ""
|
||||
|
||||
[dependencies]
|
||||
bitflags = { version = "2.7.0", features = ["serde"] }
|
||||
chrono = "0.4.39"
|
||||
clap = { version = "4.5.23", features = ["derive"] }
|
||||
env_logger = "0.11.6"
|
||||
|
|
|
@ -421,6 +421,11 @@ pub struct TristarState {
|
|||
pub tristar_open_circuit_voltage: f64,
|
||||
pub daily_charge_amp_hours: f64,
|
||||
pub daily_charge_watt_hours: f64,
|
||||
pub alarms: Alarms,
|
||||
pub faults: Faults,
|
||||
pub alarms_daily: Alarms,
|
||||
pub faults_daily: Faults,
|
||||
pub flags_daily: DailyFlags,
|
||||
}
|
||||
|
||||
fn signed(val: u16) -> i16 {
|
||||
|
@ -450,10 +455,87 @@ impl TristarState {
|
|||
tristar_open_circuit_voltage: scaling.get_voltage(ram[TristarRamAddress::SweepVoc]),
|
||||
daily_charge_amp_hours: f64::from(ram[TristarRamAddress::AhcDaily]) * 0.1,
|
||||
daily_charge_watt_hours: f64::from(ram[TristarRamAddress::WhcDaily]),
|
||||
alarms: Alarms::from_words(
|
||||
ram[TristarRamAddress::AlarmLo],
|
||||
ram[TristarRamAddress::AlarmHi],
|
||||
),
|
||||
faults: Faults::from_bits_retain(ram[TristarRamAddress::Fault]),
|
||||
alarms_daily: Alarms::from_words(
|
||||
ram[TristarRamAddress::AlarmDailyLo],
|
||||
ram[TristarRamAddress::AlarmDailyHi],
|
||||
),
|
||||
faults_daily: Faults::from_bits_retain(ram[TristarRamAddress::FaultDaily]),
|
||||
flags_daily: DailyFlags::from_bits_retain(ram[TristarRamAddress::FlagsDaily]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bitflags::bitflags! {
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
pub struct Faults: u16 {
|
||||
const Overcurrent = 1;
|
||||
const FETsShorted = 1 << 1;
|
||||
const SoftwareBug = 1 << 2;
|
||||
const BatteryHVD = 1 << 3;
|
||||
const ArrayHVD = 1 << 4;
|
||||
const SettingsSwitchChanged = 1 << 5;
|
||||
const CustomSettingsEdit = 1 << 6;
|
||||
const RTSShorted = 1 << 7;
|
||||
const RTSDisconnected = 1 << 8;
|
||||
const EEPROMRetryLimit = 1 << 9;
|
||||
const Reserved = 1 << 10;
|
||||
const SlaveControlTimeout = 1 << 11;
|
||||
const Fault13 = 1 << 12;
|
||||
const Fault14 = 1 << 13;
|
||||
const Fault15 = 1 << 14;
|
||||
const Fault16 = 1 << 15;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
pub struct Alarms: u32 {
|
||||
const RTSOpen = 1;
|
||||
const RTSShorted = 1 << 1;
|
||||
const RTSDisconnected = 1 << 2;
|
||||
const HeatsinkTempSensorOpen = 1 << 3;
|
||||
const HeatsinkTempSensorShorted = 1 << 4;
|
||||
const HighTemperatureCurrentLimit = 1 << 5;
|
||||
const CurrentLimit = 1 << 6;
|
||||
const CurrentOffset = 1 << 7;
|
||||
const BatterySenseOutOfRange = 1 << 8;
|
||||
const BatterySenseDisconnected = 1 << 9;
|
||||
const Uncalibrated = 1 << 10;
|
||||
const RTSMiswire = 1 << 11;
|
||||
const HighVoltageDisconnect = 1 << 12;
|
||||
const Undefined = 1 << 13;
|
||||
const SystemMiswire = 1 << 14;
|
||||
const MOSFETOpen = 1 << 15;
|
||||
const P12VoltageOff = 1 << 16;
|
||||
const HighInputVoltageCurrentLimit = 1 << 17;
|
||||
const ADCInputMax = 1 << 18;
|
||||
const ControllerWasReset = 1 << 19;
|
||||
const Alarm21 = 1 << 20;
|
||||
const Alarm22 = 1 << 21;
|
||||
const Alarm23 = 1 << 22;
|
||||
const Alarm24 = 1 << 23;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
pub struct DailyFlags: u16 {
|
||||
const ResetDetected = 1;
|
||||
const EqualizeTriggered = 1 << 1;
|
||||
const EnteredFloat = 1 << 2;
|
||||
const AlarmOccurred = 1 << 3;
|
||||
const FaultOccurred = 1 << 4;
|
||||
}
|
||||
}
|
||||
|
||||
impl Alarms {
|
||||
const fn from_words(low: u16, high: u16) -> Self {
|
||||
let val = (low as u32) | ((high as u32) << 16);
|
||||
Self::from_bits_retain(val)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
pub enum ChargeState {
|
||||
Start,
|
||||
|
|
Loading…
Add table
Reference in a new issue