simconnect_sdk/domain/facilities.rs
1use crate::bindings;
2
3/// Facility Type. The simulation keeps a facilities cache of all the airports, waypoints, NDB and VOR stations within a certain radius of the user aircraft.
4/// They can be requested using [`crate::SimConnect::subscribe_to_facilities`] or [`crate::SimConnect::request_facilities_list`].
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub enum FacilityType {
7 Airport,
8 Waypoint,
9 NDB,
10 VOR,
11}
12
13impl From<FacilityType> for i32 {
14 fn from(facility_type: FacilityType) -> Self {
15 match facility_type {
16 FacilityType::Airport => {
17 bindings::SIMCONNECT_FACILITY_LIST_TYPE_SIMCONNECT_FACILITY_LIST_TYPE_AIRPORT
18 }
19 FacilityType::Waypoint => {
20 bindings::SIMCONNECT_FACILITY_LIST_TYPE_SIMCONNECT_FACILITY_LIST_TYPE_WAYPOINT
21 }
22 FacilityType::NDB => {
23 bindings::SIMCONNECT_FACILITY_LIST_TYPE_SIMCONNECT_FACILITY_LIST_TYPE_NDB
24 }
25 FacilityType::VOR => {
26 bindings::SIMCONNECT_FACILITY_LIST_TYPE_SIMCONNECT_FACILITY_LIST_TYPE_VOR
27 }
28 }
29 }
30}
31
32impl FacilityType {
33 pub fn to_type_name(&self) -> String {
34 match self {
35 FacilityType::Airport => std::any::type_name::<Airport>(),
36 FacilityType::Waypoint => std::any::type_name::<Waypoint>(),
37 FacilityType::NDB => std::any::type_name::<NDB>(),
38 FacilityType::VOR => std::any::type_name::<VOR>(),
39 }
40 .into()
41 }
42}
43
44/// Information on a single airport in the facilities cache.
45#[derive(Debug, Clone)]
46pub struct Airport {
47 /// ICAO of the facility.
48 pub icao: String,
49 /// Latitude of the airport in facility.
50 pub lat: f64,
51 /// Longitude of the airport in facility.
52 pub lon: f64,
53 /// Altitude of the facility in meters.
54 pub alt: f64,
55}
56
57/// Information on a single waypoint in the facilities cache.
58#[derive(Debug, Clone)]
59pub struct Waypoint {
60 /// ICAO of the facility.
61 pub icao: String,
62 /// Latitude of the airport in facility.
63 pub lat: f64,
64 /// Longitude of the airport in facility.
65 pub lon: f64,
66 /// Altitude of the facility in meters.
67 pub alt: f64,
68 /// The magnetic variation of the waypoint in degrees.
69 pub mag_var: f32,
70}
71
72/// Information on a single NDB station in the facilities cache.
73#[derive(Debug, Clone)]
74pub struct NDB {
75 /// ICAO of the facility.
76 pub icao: String,
77 /// Latitude of the airport in facility.
78 pub lat: f64,
79 /// Longitude of the airport in facility.
80 pub lon: f64,
81 /// Altitude of the facility in meters.
82 pub alt: f64,
83 /// The magnetic variation of the waypoint in degrees.
84 pub mag_var: f32,
85 /// Frequency of the station in Hz.
86 pub frequency: u32,
87}
88
89/// Information on a single VOR station in the facilities cache.
90#[derive(Debug, Clone)]
91pub struct VOR {
92 /// ICAO of the facility.
93 pub icao: String,
94 /// Latitude of the airport in facility.
95 pub lat: f64,
96 /// Longitude of the airport in facility.
97 pub lon: f64,
98 /// Altitude of the facility in meters.
99 pub alt: f64,
100 /// The magnetic variation of the waypoint in degrees.
101 pub mag_var: f32,
102 /// True if the station has a NAV transmitter, and if so, `glide_lat`, `glide_lon` and `glide_alt` contain valid data.
103 pub has_nav_signal: bool,
104 /// True if the station transmits an ILS localizer angle, and if so `localizer` contains valid data.
105 pub has_localizer: bool,
106 /// True if the station transmits an ILS approach angle, and if so `glide_slope_angle` contains valid data.
107 pub has_glide_slope: bool,
108 /// True if the station transmits a DME signal, and if so the inherited DME fFrequency contains valid data.
109 pub has_dme: bool,
110 /// The ILS localizer angle in degrees.
111 pub localizer: Option<f32>,
112 /// The latitude of the glide slope transmitter in degrees.
113 pub glide_lat: Option<f64>,
114 /// The longitude of the glide slope transmitter in degrees.
115 pub glide_lon: Option<f64>,
116 /// The altitude of the glide slope transmitter in degrees.
117 pub glide_alt: Option<f64>,
118 /// The ILS approach angle in degrees.
119 pub glide_slope_angle: Option<f32>,
120 /// Frequency of the station in Hz.
121 pub frequency: Option<u32>,
122}