aquarium_control/thermal/
ventilation_channels.rs1use crate::launch::channels::{AquaChannelError, AquaReceiver, AquaSender};
10use crate::utilities::channel_content::InternalCommand;
11use std::fmt;
12
13pub struct VentilationChannels {
15 pub tx_ventilation_to_relay_manager: AquaSender<InternalCommand>,
17
18 pub rx_ventilation_from_relay_manager: AquaReceiver<bool>,
20
21 pub tx_ventilation_to_signal_handler: AquaSender<bool>,
23
24 pub rx_ventilation_from_signal_handler: AquaReceiver<InternalCommand>,
26
27 pub tx_ventilation_to_schedule_check: AquaSender<InternalCommand>,
29
30 pub rx_ventilation_from_schedule_check: AquaReceiver<bool>,
32
33 pub rx_ventilation_from_messaging_opt: Option<AquaReceiver<InternalCommand>>,
35}
36
37impl VentilationChannels {
38 pub fn send_to_relay_manager(
40 &mut self,
41 command: InternalCommand,
42 ) -> Result<(), AquaChannelError> {
43 self.tx_ventilation_to_relay_manager.send(command)
44 }
45
46 pub fn receive_from_relay_manager(&mut self) -> Result<bool, AquaChannelError> {
48 self.rx_ventilation_from_relay_manager.recv()
49 }
50
51 pub fn send_to_schedule_check(
53 &mut self,
54 command: InternalCommand,
55 ) -> Result<(), AquaChannelError> {
56 self.tx_ventilation_to_schedule_check.send(command)
57 }
58
59 pub fn receive_from_schedule_check(&mut self) -> Result<bool, AquaChannelError> {
61 self.rx_ventilation_from_schedule_check.recv()
62 }
63
64 pub fn send_to_signal_handler(&mut self, status: bool) -> Result<(), AquaChannelError> {
66 self.tx_ventilation_to_signal_handler.send(status)
67 }
68}
69
70#[cfg(feature = "debug_channels")]
71impl fmt::Display for VentilationChannels {
72 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
73 writeln!(f, "=== VentilationChannels ===")?;
74 writeln!(
75 f,
76 "tx_ventilation_to_relay_manager: {}",
77 self.tx_ventilation_to_relay_manager.count
78 )?;
79 writeln!(
80 f,
81 "rx_ventilation_from_relay_manager: {}",
82 self.rx_ventilation_from_relay_manager.count
83 )?;
84 writeln!(
85 f,
86 "tx_ventilation_to_signal_handler: {}",
87 self.tx_ventilation_to_signal_handler.count
88 )?;
89 writeln!(
90 f,
91 "rx_ventilation_from_signal_handler: {}",
92 self.rx_ventilation_from_signal_handler.count
93 )?;
94 writeln!(
95 f,
96 "tx_ventilation_to_schedule_check: {}",
97 self.tx_ventilation_to_schedule_check.count
98 )?;
99 writeln!(
100 f,
101 "rx_ventilation_from_schedule_check: {}",
102 self.rx_ventilation_from_schedule_check.count
103 )?;
104 write!(
105 f,
106 "rx_ventilation_from_messaging_opt: {}",
107 self.rx_ventilation_from_messaging_opt
108 .as_ref()
109 .unwrap()
110 .count
111 )
112 }
113}
114
115#[cfg(not(feature = "debug_channels"))]
116impl fmt::Display for VentilationChannels {
117 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
118 write!(
119 f,
120 "Channel counters are not active. Use --features \"debug_channels\" to enable them."
121 )
122 }
123}