Track overcurrent issues during pump operation
- Added `overcurrent_ma` field to pump results for capturing overcurrent data. - Enhanced pumping logic to record and propagate overcurrent issues per plant. - Updated `PumpState` and `PlantState` to handle overcurrent errors.
This commit is contained in:
@@ -51,16 +51,27 @@ pub enum PumpError {
|
||||
failed_attempts: usize,
|
||||
max_allowed_failures: usize,
|
||||
},
|
||||
OverCurrent {
|
||||
current_ma: u16,
|
||||
max_allowed_ma: u16,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct PumpState {
|
||||
consecutive_pump_count: u32,
|
||||
previous_pump: Option<DateTime<Utc>>,
|
||||
pub overcurrent_error: Option<u16>,
|
||||
}
|
||||
|
||||
impl PumpState {
|
||||
fn is_err(&self, plant_config: &PlantConfig) -> Option<PumpError> {
|
||||
if let Some(current_ma) = self.overcurrent_error {
|
||||
return Some(PumpError::OverCurrent {
|
||||
current_ma,
|
||||
max_allowed_ma: plant_config.max_pump_current_ma,
|
||||
});
|
||||
}
|
||||
if self.consecutive_pump_count > plant_config.max_consecutive_pump_count as u32 {
|
||||
Some(PumpError::PumpNotWorking {
|
||||
failed_attempts: self.consecutive_pump_count as usize,
|
||||
@@ -172,6 +183,7 @@ impl PlantState {
|
||||
pump: PumpState {
|
||||
consecutive_pump_count,
|
||||
previous_pump,
|
||||
overcurrent_error: None,
|
||||
},
|
||||
sensor_a_firmware_build_minutes: a_builds[plant_id],
|
||||
sensor_b_firmware_build_minutes: b_builds[plant_id],
|
||||
|
||||
Reference in New Issue
Block a user