|
|
|
@ -13,6 +13,7 @@ const VALVE_TERMINAL_IDENT_NUMBER: u16 = 0x0a35;
|
|
|
|
pub struct ValveTerminal {
|
|
|
|
pub struct ValveTerminal {
|
|
|
|
peripheral: dp::PeripheralHandle,
|
|
|
|
peripheral: dp::PeripheralHandle,
|
|
|
|
address: profirust::Address,
|
|
|
|
address: profirust::Address,
|
|
|
|
|
|
|
|
error: bool,
|
|
|
|
valve_states: [bool; 8],
|
|
|
|
valve_states: [bool; 8],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -68,6 +69,7 @@ impl ValveTerminal {
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
peripheral: handle,
|
|
|
|
peripheral: handle,
|
|
|
|
address: default_address,
|
|
|
|
address: default_address,
|
|
|
|
|
|
|
|
error: false,
|
|
|
|
valve_states: [false; 8],
|
|
|
|
valve_states: [false; 8],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -90,6 +92,8 @@ impl ValveTerminal {
|
|
|
|
peripheral.reset_address(address);
|
|
|
|
peripheral.reset_address(address);
|
|
|
|
peripheral.pi_q_mut().fill(0u8);
|
|
|
|
peripheral.pi_q_mut().fill(0u8);
|
|
|
|
self.valve_states = [false; 8];
|
|
|
|
self.valve_states = [false; 8];
|
|
|
|
|
|
|
|
self.error = false;
|
|
|
|
|
|
|
|
self.address = address;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -100,7 +104,48 @@ impl ValveTerminal {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn error(&self) -> bool {
|
|
|
|
|
|
|
|
self.error
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn update(&mut self, dp_master: &mut dp::DpMaster, events: &dp::DpEvents) {
|
|
|
|
pub fn update(&mut self, dp_master: &mut dp::DpMaster, events: &dp::DpEvents) {
|
|
|
|
|
|
|
|
if let Some((handle, event)) = events.peripheral {
|
|
|
|
|
|
|
|
if handle.address() == self.address {
|
|
|
|
|
|
|
|
match event {
|
|
|
|
|
|
|
|
dp::PeripheralEvent::Configured => {
|
|
|
|
|
|
|
|
log::info!("Ventilinsel #{} erfolgreich parametriert!", self.address);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
dp::PeripheralEvent::ConfigError => {
|
|
|
|
|
|
|
|
self.error = true;
|
|
|
|
|
|
|
|
log::warn!(
|
|
|
|
|
|
|
|
"Fehler beim Konfigurieren der Ventilinsel #{}.",
|
|
|
|
|
|
|
|
self.address
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
dp::PeripheralEvent::ParameterError => {
|
|
|
|
|
|
|
|
self.error = true;
|
|
|
|
|
|
|
|
log::warn!(
|
|
|
|
|
|
|
|
"Fehler beim Parametrieren der Ventilinsel #{}.",
|
|
|
|
|
|
|
|
self.address
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
dp::PeripheralEvent::Diagnostics => {
|
|
|
|
|
|
|
|
let peripheral = dp_master.get_mut(self.peripheral);
|
|
|
|
|
|
|
|
let diagnostics = peripheral.last_diagnostics().unwrap();
|
|
|
|
|
|
|
|
log::info!(
|
|
|
|
|
|
|
|
"Diagnostics von Ventilinsel #{} gemeldet: {:#?}",
|
|
|
|
|
|
|
|
self.address,
|
|
|
|
|
|
|
|
diagnostics
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
dp::PeripheralEvent::Offline => {
|
|
|
|
|
|
|
|
log::info!("Ventilinsel #{} antwortet nicht mehr.", self.address);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_ => (),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let peripheral = dp_master.get_mut(self.peripheral);
|
|
|
|
let peripheral = dp_master.get_mut(self.peripheral);
|
|
|
|
if peripheral.is_running() && events.cycle_completed {
|
|
|
|
if peripheral.is_running() && events.cycle_completed {
|
|
|
|
let pi_q = peripheral.pi_q_mut();
|
|
|
|
let pi_q = peripheral.pi_q_mut();
|
|
|
|
|