remote_id/data/
location.rs

1use core::time::Duration;
2
3pub const MESSAGE_TYPE: u8 = 1;
4
5#[allow(non_camel_case_types)]
6#[derive(Debug, Copy, Clone, PartialEq)]
7pub enum VerticalAccuracy {
8    /// >=150 m or Unknown
9    Unknown,
10    LessThan_150_m,
11    LessThan_45_m,
12    LessThan_25_m,
13    LessThan_10_m,
14    LessThan_3_m,
15    LessThan_1_m,
16}
17
18impl From<u8> for VerticalAccuracy {
19    fn from(value: u8) -> Self {
20        match value {
21            0 => Self::Unknown,
22            1 => Self::LessThan_150_m,
23            2 => Self::LessThan_45_m,
24            3 => Self::LessThan_25_m,
25            4 => Self::LessThan_10_m,
26            5 => Self::LessThan_3_m,
27            6 => Self::LessThan_1_m,
28            7..=u8::MAX => Self::Unknown,
29        }
30    }
31}
32
33impl From<VerticalAccuracy> for u8 {
34    fn from(val: VerticalAccuracy) -> Self {
35        match val {
36            VerticalAccuracy::Unknown => 0,
37            VerticalAccuracy::LessThan_150_m => 1,
38            VerticalAccuracy::LessThan_45_m => 2,
39            VerticalAccuracy::LessThan_25_m => 3,
40            VerticalAccuracy::LessThan_10_m => 4,
41            VerticalAccuracy::LessThan_3_m => 5,
42            VerticalAccuracy::LessThan_1_m => 6,
43        }
44    }
45}
46
47#[allow(non_camel_case_types)]
48#[derive(Debug, Copy, Clone, PartialEq)]
49pub enum HorizontalAccuracy {
50    /// >= 18.52 km (10 NM) or Unknown
51    Unknown,
52    /// <18.52 km
53    LessThan_10_NM,
54    /// <7.408 km
55    LessThan_4_NM,
56    /// <3.704 km
57    LessThan_2_NM,
58    /// <1852 m
59    LessThan_1_NM,
60    /// <926 m
61    LessThan_half_NM,
62    /// <555.6 m
63    LessThan_third_NM,
64    /// <185.2 m
65    LessThan_tenth_NM,
66    /// <92.6 m
67    LessThan_twentieth_NM,
68    /// <30 m
69    LessThan_30_m,
70    ///  <10 m
71    LessThan_10_m,
72    ///  <3 m
73    LessThan_3_m,
74    ///  <1 m
75    LessThan_1_m,
76}
77
78impl From<u8> for HorizontalAccuracy {
79    fn from(value: u8) -> Self {
80        match value {
81            0 => Self::Unknown,
82            1 => Self::LessThan_10_NM,
83            2 => Self::LessThan_4_NM,
84            3 => Self::LessThan_2_NM,
85            4 => Self::LessThan_1_NM,
86            5 => Self::LessThan_half_NM,
87            6 => Self::LessThan_third_NM,
88            7 => Self::LessThan_tenth_NM,
89            8 => Self::LessThan_twentieth_NM,
90            9 => Self::LessThan_30_m,
91            10 => Self::LessThan_10_m,
92            11 => Self::LessThan_3_m,
93            12 => Self::LessThan_1_m,
94            13..=u8::MAX => Self::Unknown,
95        }
96    }
97}
98
99impl From<HorizontalAccuracy> for u8 {
100    fn from(val: HorizontalAccuracy) -> Self {
101        match val {
102            HorizontalAccuracy::Unknown => 0,
103            HorizontalAccuracy::LessThan_10_NM => 1,
104            HorizontalAccuracy::LessThan_4_NM => 2,
105            HorizontalAccuracy::LessThan_2_NM => 3,
106            HorizontalAccuracy::LessThan_1_NM => 4,
107            HorizontalAccuracy::LessThan_half_NM => 5,
108            HorizontalAccuracy::LessThan_third_NM => 6,
109            HorizontalAccuracy::LessThan_tenth_NM => 7,
110            HorizontalAccuracy::LessThan_twentieth_NM => 8,
111            HorizontalAccuracy::LessThan_30_m => 9,
112            HorizontalAccuracy::LessThan_10_m => 10,
113            HorizontalAccuracy::LessThan_3_m => 11,
114            HorizontalAccuracy::LessThan_1_m => 12,
115        }
116    }
117}
118
119#[allow(non_camel_case_types)]
120#[derive(Debug, Copy, Clone, PartialEq)]
121pub enum SpeedAccuracy {
122    /// >=10 m/s or Unknown
123    Unknown,
124    /// <10 m/s
125    LessThan_10_mps,
126    /// <3 m/s
127    LessThan_3_mps,
128    /// <1 m/s
129    LessThan_1_mps,
130    /// <0.3 m/s
131    LessThan_third_mps,
132}
133
134impl From<u8> for SpeedAccuracy {
135    fn from(value: u8) -> Self {
136        match value {
137            0 => Self::Unknown,
138            1 => Self::LessThan_10_mps,
139            2 => Self::LessThan_3_mps,
140            3 => Self::LessThan_1_mps,
141            4 => Self::LessThan_third_mps,
142            5..=u8::MAX => Self::Unknown,
143        }
144    }
145}
146
147impl From<SpeedAccuracy> for u8 {
148    fn from(val: SpeedAccuracy) -> Self {
149        match val {
150            SpeedAccuracy::Unknown => 0,
151            SpeedAccuracy::LessThan_10_mps => 1,
152            SpeedAccuracy::LessThan_3_mps => 2,
153            SpeedAccuracy::LessThan_1_mps => 3,
154            SpeedAccuracy::LessThan_third_mps => 4,
155        }
156    }
157}
158
159#[derive(Debug, Clone, PartialEq)]
160pub struct Location {
161    pub operational_status: OperationalStatus,
162    pub height_type: HeightType,
163    // pub ew_direction_segment: EastWestDirectionSegment,
164    /// Speed Multiplier enables speeds up to 254.25 m/s. Only use 1 when speed exceeds 63.75 m/s and add 63.75.
165    // pub speed_multiplier: f32,
166    pub speed: f32,
167    pub vertical_speed: f32,
168    pub pressure_altitude: f32,
169    pub geodetic_altitude: f32,
170    /// Direction expressed as the route course measured clockwise from true north.
171    pub track_direction: u16,
172    pub horizontal_accuracy: HorizontalAccuracy,
173    pub vertical_accuracy: VerticalAccuracy,
174    pub latidute: f32,
175    pub longitude: f32,
176    pub height: f32,
177    pub baro_altitude_accuracy: VerticalAccuracy,
178    pub speed_accuracy: SpeedAccuracy,
179    pub timestamp: f32,
180    pub timestamp_accuracy: Option<Duration>,
181}
182
183#[derive(Debug, Copy, Clone, PartialEq)]
184pub enum OperationalStatus {
185    Undeclared,
186    Ground,
187    Airborne,
188    Emergency,
189    RemoteIdSystemFailure,
190}
191
192impl From<u8> for OperationalStatus {
193    fn from(value: u8) -> Self {
194        match value {
195            1 => OperationalStatus::Ground,
196            2 => OperationalStatus::Airborne,
197            3 => OperationalStatus::Emergency,
198            4 => OperationalStatus::RemoteIdSystemFailure,
199
200            _ => OperationalStatus::Undeclared,
201        }
202    }
203}
204
205impl From<OperationalStatus> for u8 {
206    fn from(val: OperationalStatus) -> Self {
207        match val {
208            OperationalStatus::Ground => 1,
209            OperationalStatus::Airborne => 2,
210            OperationalStatus::Emergency => 3,
211            OperationalStatus::RemoteIdSystemFailure => 4,
212
213            OperationalStatus::Undeclared => 0,
214        }
215    }
216}
217
218#[derive(Debug, Copy, Clone, PartialEq)]
219pub enum HeightType {
220    AboveTakeoff,
221    AboveGroundLevel,
222}
223
224impl From<u8> for HeightType {
225    fn from(value: u8) -> Self {
226        match value {
227            0 => HeightType::AboveTakeoff,
228            1 => HeightType::AboveGroundLevel,
229
230            _ => HeightType::AboveTakeoff,
231        }
232    }
233}
234
235impl From<HeightType> for u8 {
236    fn from(val: HeightType) -> Self {
237        match val {
238            HeightType::AboveTakeoff => 0,
239            HeightType::AboveGroundLevel => 1,
240        }
241    }
242}
243
244// #[derive(Debug, Copy, Clone, PartialEq)]
245// pub enum EastWestDirectionSegment {
246//     LowerThan180 = 0,
247//     GreaterOrEqual180 = 1,
248// }
249
250// impl From<u8> for EastWestDirectionSegment {
251//     fn from(value: u8) -> Self {
252//         match value {
253//             0 => EastWestDirectionSegment::LowerThan180,
254//             1 => EastWestDirectionSegment::GreaterOrEqual180,
255
256//             _ => EastWestDirectionSegment::LowerThan180,
257//         }
258//     }
259// }
260
261// impl Into<u8> for EastWestDirectionSegment {
262//     fn into(self) -> u8 {
263//         match self {
264//             EastWestDirectionSegment::LowerThan180 => 0,
265//             EastWestDirectionSegment::GreaterOrEqual180 => 1,
266//         }
267//     }
268// }