blackbox_log/opt/rustwide/workdir/src/generated/
disabled_fields.rs

1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2/// All disabled field groups in a Betaflight log.
3///
4/// See [`FlagSet`][crate::units::FlagSet] and [`FieldGroup`].
5#[allow(unused_qualifications)]
6pub struct DisabledFields {
7    firmware: crate::headers::InternalFirmware,
8    raw: ::bitvec::array::BitArray<u32, ::bitvec::order::Lsb0>,
9}
10#[allow(unused_qualifications, clippy::cast_possible_truncation)]
11impl DisabledFields {
12    pub(crate) fn new(raw: u32, firmware: crate::headers::InternalFirmware) -> Self {
13        Self {
14            firmware,
15            raw: ::bitvec::array::BitArray::new(raw),
16        }
17    }
18
19    fn iter(&self) -> impl Iterator<Item = <Self as crate::units::FlagSet>::Flag> + '_ {
20        self.raw
21            .iter_ones()
22            .filter_map(|bit| <FieldGroup>::from_bit(bit as u32, self.firmware))
23    }
24}
25#[allow(unused_qualifications, clippy::cast_possible_truncation)]
26impl crate::units::FlagSet for DisabledFields {
27    type Flag = FieldGroup;
28
29    fn is_set(&self, flag: Self::Flag) -> bool {
30        flag.to_bit(self.firmware)
31            .map_or(false, |bit| self.raw[bit as usize])
32    }
33
34    fn as_names(&self) -> ::alloc::vec::Vec<&'static str> {
35        self.iter()
36            .map(|flag| <FieldGroup as crate::units::Flag>::as_name(&flag))
37            .collect()
38    }
39}
40#[allow(unused_qualifications)]
41impl ::core::fmt::Display for DisabledFields {
42    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
43        let names = <Self as crate::units::FlagSet>::as_names(self);
44        f.write_str(&names.join("|"))
45    }
46}
47#[cfg(feature = "_serde")]
48#[allow(clippy::cast_possible_truncation)]
49impl ::serde::Serialize for DisabledFields {
50    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
51    where
52        S: serde::Serializer,
53    {
54        use serde::ser::SerializeSeq;
55        let mut seq = serializer.serialize_seq(None)?;
56        for flag in self.iter() {
57            seq.serialize_element(&flag)?;
58        }
59        seq.end()
60    }
61}
62#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
63#[cfg_attr(feature = "_serde", derive(serde::Serialize))]
64/// A set of fields that can be disabled in Betaflight logs.
65///
66/// See [`Flag`][crate::units::Flag].
67#[non_exhaustive]
68pub enum FieldGroup {
69    /// `ACC`
70    Acc,
71    /// `ALTITUDE`
72    Altitude,
73    /// `BATTERY`
74    Battery,
75    /// `DEBUG_LOG`
76    DebugLog,
77    /// `GPS`
78    Gps,
79    /// `GYRO`
80    Gyro,
81    /// `GYROUNFILT`
82    GyroUnfiltered,
83    /// `MAG`
84    Mag,
85    /// `MOTOR`
86    Motor,
87    /// `PID`
88    Pid,
89    /// `RC_COMMANDS`
90    RcCommands,
91    /// `RPM`
92    Rpm,
93    /// `RSSI`
94    Rssi,
95    /// `SETPOINT`
96    Setpoint,
97}
98#[allow(unused_qualifications)]
99impl crate::units::Flag for FieldGroup {
100    fn as_name(&self) -> &'static str {
101        match self {
102            Self::Acc => "ACC",
103            Self::Altitude => "ALTITUDE",
104            Self::Battery => "BATTERY",
105            Self::DebugLog => "DEBUG_LOG",
106            Self::Gps => "GPS",
107            Self::Gyro => "GYRO",
108            Self::GyroUnfiltered => "GYROUNFILT",
109            Self::Mag => "MAG",
110            Self::Motor => "MOTOR",
111            Self::Pid => "PID",
112            Self::RcCommands => "RC_COMMANDS",
113            Self::Rpm => "RPM",
114            Self::Rssi => "RSSI",
115            Self::Setpoint => "SETPOINT",
116        }
117    }
118}
119#[allow(unused_qualifications)]
120impl ::core::fmt::Display for FieldGroup {
121    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
122        let s = <Self as crate::units::Flag>::as_name(self);
123        f.write_str(s)
124    }
125}
126#[allow(
127    unused_qualifications,
128    clippy::enum_glob_use,
129    clippy::match_same_arms,
130    clippy::unseparated_literal_suffix
131)]
132impl FieldGroup {
133    const fn from_bit(bit: u32, fw: crate::headers::InternalFirmware) -> Option<Self> {
134        use crate::headers::InternalFirmware::*;
135        match (bit, fw) {
136            (0u32, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(Self::Pid),
137            (1u32, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(Self::RcCommands),
138            (2u32, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(Self::Setpoint),
139            (3u32, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(Self::Battery),
140            (4u32, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(Self::Mag),
141            (5u32, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(Self::Altitude),
142            (6u32, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(Self::Rssi),
143            (7u32, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(Self::Gyro),
144            (8u32, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(Self::Acc),
145            (9u32, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(Self::DebugLog),
146            (10u32, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(Self::Motor),
147            (11u32, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(Self::Gps),
148            (12u32, Betaflight4_5) => Some(Self::Rpm),
149            (13u32, Betaflight4_5) => Some(Self::GyroUnfiltered),
150            _ => None,
151        }
152    }
153
154    const fn to_bit(self, fw: crate::headers::InternalFirmware) -> Option<u32> {
155        use crate::headers::InternalFirmware::*;
156        match (self, fw) {
157            (Self::Pid, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(0u32),
158            (Self::RcCommands, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(1u32),
159            (Self::Setpoint, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(2u32),
160            (Self::Battery, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(3u32),
161            (Self::Mag, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(4u32),
162            (Self::Altitude, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(5u32),
163            (Self::Rssi, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(6u32),
164            (Self::Gyro, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(7u32),
165            (Self::Acc, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(8u32),
166            (Self::DebugLog, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(9u32),
167            (Self::Motor, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(10u32),
168            (Self::Gps, Betaflight4_3 | Betaflight4_4 | Betaflight4_5) => Some(11u32),
169            (Self::Rpm, Betaflight4_5) => Some(12u32),
170            (Self::GyroUnfiltered, Betaflight4_5) => Some(13u32),
171            _ => None,
172        }
173    }
174}