Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix reported QNH/QFE for current temperature #93

Merged
merged 1 commit into from
May 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions crates/datis-core/src/station.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,35 +164,35 @@ fn temperatur_report(weather: &WeatherInfo, spoken: bool) -> String {
)
}

fn altimeter_report(weather: &WeatherInfo, spoken: bool) -> String {
fn altimeter_report(weather: &WeatherInfo, alt: u32, spoken: bool) -> String {
format!(
"ALTIMETER {}. {}",
// inHg, but using 0.02953 instead of 0.0002953 since we don't want to speak the
// DECIMAL here
pronounce_number((weather.pressure_qnh * 0.02953).round(), spoken),
pronounce_number((weather.get_qnh(alt) * 0.02953).round(), spoken),
break_(spoken),
)
}

fn hectopascal_report(weather: &WeatherInfo, spoken: bool) -> String {
fn hectopascal_report(weather: &WeatherInfo, alt: u32, spoken: bool) -> String {
format!(
"{} hectopascal. {}",
pronounce_number((weather.pressure_qnh / 100.0).round(), spoken), // to hPA
pronounce_number((weather.get_qnh(alt) / 100.0).round(), spoken), // to hPA
break_(spoken),
)
}

fn qfe_report(weather: &WeatherInfo, spoken: bool) -> String {
fn qfe_report(weather: &WeatherInfo, alt: u32, spoken: bool) -> String {
format!(
"QFE {} {}or {}. {}",
pronounce_number((weather.pressure_qfe * 0.02953).round(), spoken), // to inHg
pronounce_number((weather.get_qfe(alt) * 0.02953).round(), spoken), // to inHg
if spoken {
// add break to make it easier to mentally process the different numbers
"<break time=\"500ms\" /> "
} else {
""
},
pronounce_number((weather.pressure_qfe / 100.0).round(), spoken), // to hPA
pronounce_number((weather.get_qfe(alt) / 100.0).round(), spoken), // to hPA
break_(spoken),
)
}
Expand Down Expand Up @@ -478,11 +478,11 @@ impl Airfield {
report += &weather_condition_report(weather, alt, spoken);
report += &visibility_report(weather, alt, spoken);
report += &temperatur_report(weather, spoken);
report += &altimeter_report(weather, spoken);
report += &altimeter_report(weather, alt, spoken);

report += &format!("REMARKS. {}", break_(spoken));
report += &hectopascal_report(weather, spoken);
report += &qfe_report(weather, spoken);
report += &hectopascal_report(weather, alt, spoken);
report += &qfe_report(weather, alt, spoken);

report += &format!("End information {}.", information_letter);

Expand Down Expand Up @@ -520,16 +520,16 @@ impl Carrier {
break_(spoken),
);

let alt = 21; // carrier deck alt in m

report += &format!(
"altimeter {}, {}",
// inHg, but using 0.02953 instead of 0.0002953 since we don't want to speak the
// DECIMAL here
pronounce_number((weather.pressure_qnh * 0.02953).round(), spoken),
pronounce_number((weather.get_qnh(alt) * 0.02953).round(), spoken),
break_(spoken),
);

let alt = 21; // carrier deck alt in m

// Case 1: daytime, ceiling >= 3000ft; visibility distance >= 5nm
// Case 2: daytime, ceiling >= 1000ft; visibility distance >= 5nm
// Case 3: nighttime or daytime, ceiling < 1000ft and visibility distance <= 5nm
Expand Down Expand Up @@ -611,11 +611,11 @@ impl WeatherTransmitter {
report += &weather_condition_report(weather, alt, spoken);
report += &visibility_report(weather, alt, spoken);
report += &temperatur_report(weather, spoken);
report += &altimeter_report(weather, spoken);
report += &altimeter_report(weather, alt, spoken);

report += &format!("REMARKS. {}", break_(spoken));
report += &hectopascal_report(weather, spoken);
report += &qfe_report(weather, spoken);
report += &format!("REMARKS. {}", break_(spoken),);
report += &hectopascal_report(weather, alt, spoken);
report += &qfe_report(weather, alt, spoken);

report += &format!("End information {}.", information_letter);

Expand Down
24 changes: 24 additions & 0 deletions crates/datis-core/src/weather.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ pub struct OldClouds {
}

impl WeatherInfo {
/// Get QNH correct for the current temperature (as far as possible in DCS)
pub fn get_qnh(&self, alt: u32) -> f64 {
self.pressure_qnh + self.pressure_correction(alt)
}

/// Get QFE correct for the current temperature (as far as possible in DCS)
pub fn get_qfe(&self, alt: u32) -> f64 {
self.pressure_qfe + self.pressure_correction(alt)
}

fn pressure_correction(&self, alt: u32) -> f64 {
let alt = m_to_ft(alt as f64);
let angels = alt / 1000.0;
// ISA at see level is 16 and not 15 in DCS, see
// https://forums.eagle.ru/topic/256057-altitude-qnh-error-bug/
let isa_at_alt = 16.0 - 1.98 * angels;
let isa_diff = self.temperature - isa_at_alt;
let palt_diff = 4.0 * isa_diff * angels;

// translate alt diff into a QNH diff
let qnh_diff = (palt_diff / 27.0) * 100.0;
qnh_diff
}

/// in m
pub fn get_visibility(&self, alt: u32) -> Option<u32> {
let clouds_vis = self.clouds.as_ref().and_then(|c| c.get_visibility(alt));
Expand Down