modbus_relay/config/types/
rts_type.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Default, Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
4#[serde(rename_all = "lowercase")]
5pub enum RtsType {
6    /// RTS disabled
7    None,
8    /// RTS = High during transmission
9    Up,
10    /// RTS = LOW during transmission
11    #[default]
12    Down,
13}
14
15impl RtsType {
16    pub fn to_signal_level(&self, is_transmitting: bool) -> bool {
17        match self {
18            RtsType::None => false,
19            RtsType::Up => is_transmitting,
20            RtsType::Down => !is_transmitting,
21        }
22    }
23}
24
25impl std::fmt::Display for RtsType {
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        match self {
28            RtsType::None => write!(f, "none"),
29            RtsType::Up => write!(f, "up"),
30            RtsType::Down => write!(f, "down"),
31        }
32    }
33}