bms_sm/
flight_data.rs

1mod bits;
2use std::fmt::Debug;
3
4pub use bits::*;
5
6use crate::MemoryFile;
7
8#[repr(C)]
9#[derive(Default)]
10pub struct Line([[u8; 26]; 5]);
11
12impl Debug for Line {
13    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14        let mut ret = String::new();
15
16        for line in &self.0 {
17            ret += &String::from_utf8_lossy(line);
18            ret += "\n";
19        }
20
21        write!(f, "{}", ret.trim_end_matches('\n'))
22    }
23}
24
25#[repr(C)]
26#[derive(Debug)]
27pub struct FlightData {
28    pub x: f32,           // Ownship North (Ft)
29    pub y: f32,           // Ownship East (Ft)
30    pub z: f32, // Ownship Down (Ft) --- NOTE: use FlightData2 AAUZ for barometric altitude!
31    pub x_dot: f32, // Ownship North Rate (ft/sec)
32    pub y_dot: f32, // Ownship East Rate (ft/sec)
33    pub z_dot: f32, // Ownship Down Rate (ft/sec)
34    pub alpha: f32, // Ownship AOA (Degrees)
35    pub beta: f32, // Ownship Beta (Degrees)
36    pub gamma: f32, // Ownship Gamma (Radians)
37    pub pitch: f32, // Ownship Pitch (Radians)
38    pub roll: f32, // Ownship Pitch (Radians)
39    pub yaw: f32, // Ownship Pitch (Radians)
40    pub mach: f32, // Ownship Mach number
41    pub kias: f32, // Ownship Indicated Airspeed (Knots)
42    pub vt: f32, // Ownship True Airspeed (Ft/Sec)
43    pub gs: f32, // Ownship Normal Gs
44    pub wind_offset: f32, // Wind delta to FPM (Radians)
45    pub nozzle_pos: f32, // Ownship engine nozzle percent open (0-100)
46    //pub nozzlePos2: f32,   // MOVED TO FlightData2! Ownship engine nozzle2 percent open (0-100)
47    pub internal_fuel: f32, // Ownship internal fuel (Lbs)
48    pub external_fuel: f32, // Ownship external fuel (Lbs)
49    pub fuel_flow: f32,     // Ownship fuel flow (Lbs/Hour)
50    pub rpm: f32,           // Ownship engine rpm (Percent 0-103)
51    //pub rpm2: f32,         // MOVED TO FlightData2! Ownship engine rpm2 (Percent 0-103)
52    pub ftit: f32, // Ownship Forward Turbine Inlet Temp (Degrees C)
53    //pub ftit2: f32,        // MOVED TO FlightData2! Ownship Forward Turbine Inlet Temp2 (Degrees C)
54    pub gear_pos: f32,     // Ownship Gear position 0 = up, 1 = down: f32,
55    pub speed_brake: f32,  // Ownship speed brake position 0 = closed, 1 = 60 Degrees open
56    pub epu_fuel: f32,     // Ownship EPU fuel (Percent 0-100)
57    pub oil_pressure: f32, // Ownship Oil Pressure (Percent 0-100)
58    //pub oilPressure2: f32, // MOVED TO FlightData2! Ownship Oil Pressure2 (Percent 0-100)
59    pub light_bits: LightBits, // Cockpit Indicator Lights, one bit per bulb. See enum
60
61    // These are inputs. Use them carefully
62    // NB: these do not work when TrackIR device is enabled
63    // NB2: launch falcon with the '-head' command line parameter to activate !
64    pub head_pitch: f32, // Head pitch offset from design eye (radians)
65    pub head_roll: f32,  // Head roll offset from design eye (radians)
66    pub head_yaw: f32,   // Head yaw offset from design eye (radians)
67
68    // new lights
69    pub light_bits2: LightBits2, // Cockpit Indicator Lights, one bit per bulb. See enum
70    pub light_bits3: LightBits3, // Cockpit Indicator Lights, one bit per bulb. See enum
71
72    // chaff/flare
73    pub chaff_count: f32, // Number of Chaff left
74    pub flare_count: f32, // Number of Flare left
75
76    // landing gear
77    pub nose_gear_pos: f32, // Position of the nose landinggear: f32, caution: full down values defined in dat files
78    pub left_gear_pos: f32, // Position of the left landinggear: f32, caution: full down values defined in dat files
79    pub right_gear_pos: f32, // Position of the right landinggear: f32, caution: full down values defined in dat files
80
81    // ADI values
82    pub adi_ils_hor_pos: f32, // Position of horizontal ILS bar
83    pub adi_ils_ver_pos: f32, // Position of vertical ILS bar
84
85    // HSI states
86    pub course_state: i32,  // HSI_STA_CRS_STATE
87    pub heading_state: i32, // HSI_STA_HDG_STATE
88    pub total_states: i32,  // HSI_STA_TOTAL_STATES: i32, never set
89
90    // HSI values
91    pub course_deviation: f32,     // HSI_VAL_CRS_DEVIATION
92    pub desired_course: f32,       // HSI_VAL_DESIRED_CRS
93    pub distance_to_beacon: f32,   // HSI_VAL_DISTANCE_TO_BEACON
94    pub bearing_to_beacon: f32,    // HSI_VAL_BEARING_TO_BEACON
95    pub current_heading: f32,      // HSI_VAL_CURRENT_HEADING
96    pub desired_heading: f32,      // HSI_VAL_DESIRED_HEADING
97    pub deviation_limit: f32,      // HSI_VAL_DEV_LIMIT
98    pub half_deviation_limit: f32, // HSI_VAL_HALF_DEV_LIMIT
99    pub localizer_course: f32,     // HSI_VAL_LOCALIZER_CRS
100    pub airbase_x: f32,            // HSI_VAL_AIRBASE_X
101    pub airbase_y: f32,            // HSI_VAL_AIRBASE_Y
102    pub total_values: f32,         // HSI_VAL_TOTAL_VALUES: f32, never set
103
104    pub trim_pitch: f32, // Value of trim in pitch axis, -0.5 to +0.5
105    pub trim_roll: f32,  // Value of trim in roll axis, -0.5 to +0.5
106    pub trim_yaw: f32,   // Value of trim in yaw axis, -0.5 to +0.5
107
108    // HSI flags
109    pub hsi_bits: HsiBits, // HSI flags
110
111    //DED Lines
112    pub dedlines: Line, // [5][26]: char,  //25 usable chars
113    pub invert: Line,   // [5][26]: char,    //25 usable chars
114
115    //PFL Lines
116    pub pfllines: Line,  //25 usable chars
117    pub pflinvert: Line, //25 usable chars
118
119    //TacanChannel
120    pub ufc_tchan: i32,
121    pub aux_tchan: i32,
122
123    // RWR
124    pub rwr_object_count: i32,
125    pub rwr_symbol: [i32; 40],
126    pub bearing: [f32; 40],
127    pub missile_activity: [u32; 40],
128    pub missile_launch: [u32; 40],
129    pub selected: [u32; 40],
130    pub lethality: [f32; 40],
131    pub new_detection: [u32; 40],
132
133    //fuel values
134    pub fwd: f32,
135    pub aft: f32,
136    pub total: f32,
137
138    pub version_num: i32, // Version of FlightData mem area
139
140    // New values added here for header file compatibility but not implemented
141    // in this version of the code at present.
142    pub head_x: f32, // Head X offset from design eye (feet)
143    pub head_y: f32, // Head Y offset from design eye (feet)
144    pub head_z: f32, // Head Z offset from design eye (feet)
145
146    pub main_power: i32, // Main Power switch state, 0=down, 1=middle, 2=up
147}
148
149impl Default for FlightData {
150    fn default() -> Self {
151        Self {
152            x: Default::default(),
153            y: Default::default(),
154            z: Default::default(),
155            x_dot: Default::default(),
156            y_dot: Default::default(),
157            z_dot: Default::default(),
158            alpha: Default::default(),
159            beta: Default::default(),
160            gamma: Default::default(),
161            pitch: Default::default(),
162            roll: Default::default(),
163            yaw: Default::default(),
164            mach: Default::default(),
165            kias: Default::default(),
166            vt: Default::default(),
167            gs: Default::default(),
168            wind_offset: Default::default(),
169            nozzle_pos: Default::default(),
170            internal_fuel: Default::default(),
171            external_fuel: Default::default(),
172            fuel_flow: Default::default(),
173            rpm: Default::default(),
174            ftit: Default::default(),
175            gear_pos: Default::default(),
176            speed_brake: Default::default(),
177            epu_fuel: Default::default(),
178            oil_pressure: Default::default(),
179            light_bits: Default::default(),
180            head_pitch: Default::default(),
181            head_roll: Default::default(),
182            head_yaw: Default::default(),
183            light_bits2: Default::default(),
184            light_bits3: Default::default(),
185            chaff_count: Default::default(),
186            flare_count: Default::default(),
187            nose_gear_pos: Default::default(),
188            left_gear_pos: Default::default(),
189            right_gear_pos: Default::default(),
190            adi_ils_hor_pos: Default::default(),
191            adi_ils_ver_pos: Default::default(),
192            course_state: Default::default(),
193            heading_state: Default::default(),
194            total_states: Default::default(),
195            course_deviation: Default::default(),
196            desired_course: Default::default(),
197            distance_to_beacon: Default::default(),
198            bearing_to_beacon: Default::default(),
199            current_heading: Default::default(),
200            desired_heading: Default::default(),
201            deviation_limit: Default::default(),
202            half_deviation_limit: Default::default(),
203            localizer_course: Default::default(),
204            airbase_x: Default::default(),
205            airbase_y: Default::default(),
206            total_values: Default::default(),
207            trim_pitch: Default::default(),
208            trim_roll: Default::default(),
209            trim_yaw: Default::default(),
210            hsi_bits: Default::default(),
211            dedlines: Default::default(),
212            invert: Default::default(),
213            pfllines: Default::default(),
214            pflinvert: Default::default(),
215            ufc_tchan: Default::default(),
216            aux_tchan: Default::default(),
217            rwr_object_count: Default::default(),
218            rwr_symbol: [0; 40],
219            bearing: [0.0; 40],
220            missile_activity: [0; 40],
221            missile_launch: [0; 40],
222            selected: [0; 40],
223            lethality: [0.0; 40],
224            new_detection: [0; 40],
225            fwd: Default::default(),
226            aft: Default::default(),
227            total: Default::default(),
228            version_num: Default::default(),
229            head_x: Default::default(),
230            head_y: Default::default(),
231            head_z: Default::default(),
232            main_power: Default::default(),
233        }
234    }
235}
236
237unsafe impl Send for FlightData {}
238unsafe impl Sync for FlightData {}
239
240impl FlightData {
241    pub fn new<'a>() -> Result<MemoryFile<'a, Self>, Box<dyn std::error::Error + Send + Sync>> {
242        let file = unsafe { MemoryFile::<'a, Self>::new("FalconSharedMemoryArea")? };
243        Ok(file)
244    }
245}