std_rs/device_support/
epid_soft_callback.rs1use epics_base_rs::error::CaResult;
2use epics_base_rs::server::device_support::{DeviceReadOutcome, DeviceSupport};
3use epics_base_rs::server::record::{ProcessAction, Record};
4use epics_base_rs::types::EpicsValue;
5
6use crate::records::epid::EpidRecord;
7
8pub struct EpidSoftCallbackDeviceSupport {
23 triggered: bool,
25}
26
27impl Default for EpidSoftCallbackDeviceSupport {
28 fn default() -> Self {
29 Self::new()
30 }
31}
32
33impl EpidSoftCallbackDeviceSupport {
34 pub fn new() -> Self {
35 Self { triggered: false }
36 }
37}
38
39impl DeviceSupport for EpidSoftCallbackDeviceSupport {
40 fn dtyp(&self) -> &str {
41 "Epid Async Soft"
42 }
43
44 fn read(&mut self, record: &mut dyn Record) -> CaResult<DeviceReadOutcome> {
45 let epid = record
46 .as_any_mut()
47 .and_then(|a| a.downcast_mut::<EpidRecord>())
48 .expect("EpidSoftCallbackDeviceSupport requires an EpidRecord");
49
50 if !self.triggered {
51 if !epid.trig.is_empty() {
53 let actions = vec![
54 ProcessAction::WriteDbLink {
55 link_field: "TRIG",
56 value: EpicsValue::Double(epid.tval),
57 },
58 ProcessAction::ReprocessAfter(std::time::Duration::from_millis(1)),
60 ];
61 self.triggered = true;
62 return Ok(DeviceReadOutcome::computed_with(actions));
63 }
64 }
66
67 self.triggered = false;
69 super::epid_soft::EpidSoftDeviceSupport::do_pid(epid);
70 Ok(DeviceReadOutcome::computed())
71 }
72
73 fn write(&mut self, _record: &mut dyn Record) -> CaResult<()> {
74 Ok(())
75 }
76}