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

Allow options in briefing txt #78

Closed
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Add a static unit per ATIS station to the mission, e.g. a communication tower (t
(`{}` denotes a part that has to be replaced with a proper value and `[]` denotes an optional part)

```
ATIS {Airfield} {ATIS Frequency}[, TRAFFIC {TRAFFIC Frequency}][, VOICE {VOICE NAME}, INFO {OVERRIDE INFO LETTER}]
ATIS {Airfield} {ATIS Frequency}[, TRAFFIC {TRAFFIC Frequency}][, VOICE {VOICE NAME}][, INFO {OVERRIDE INFO LETTER}][, ACTIVE {ACTIVE RUNWAY OVERRIDE}]
```

Your choice for `{VOICE NAME}` depicts which cloud provider is used for a particular ATIS station.
Expand All @@ -115,6 +115,8 @@ The default can be changed in the DCS SPECIAL settings for DATIS.

`OVERRIDE INFO LETTER` Allows you to override the dynamic rotating selection of the ATIS information letter in your mission requires a specific and constant value.

`ACTIVE RUNWAY OVERRIDE` can be used if the SPINS for the airfield differ from the prevailing winds and you want to override the calculated active runway.

Examples:

```
Expand All @@ -125,7 +127,7 @@ ATIS Kutaisi 251.000, TRAFFIC 252.000, VOICE en-US-Standard-E
ATIS Kutaisi 251.000, TRAFFIC 252.000, VOICE GC:en-US-Wavenet-B
ATIS Kutaisi 251.000, TRAFFIC 252.000, VOICE AWS:Nicole
ATIS Kutaisi 251.000, TRAFFIC 252.000, VOICE WIN
ATIS Kutaisi 251.000, TRAFFIC 252.000, INFO Q
ATIS Kutaisi 251.000, TRAFFIC 252.000, INFO Q, ACTIVE 21L
```

![Example](./docs/static.jpg)
Expand Down
1 change: 1 addition & 0 deletions crates/datis-cmd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
traffic_freq: None,
info_ltr_offset: 0,
info_ltr_override: None,
active_rwy_override: None,
}),
};
let mut datis = Datis::new(vec![station])?;
Expand Down
107 changes: 87 additions & 20 deletions crates/datis-core/src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,26 @@ pub struct StationConfig {
pub traffic: Option<u64>,
pub tts: Option<TextToSpeechProvider>,
pub info_ltr_override: Option<char>,
pub active_rwy_override: Option<String>,
}

pub fn extract_atis_station_frequencies(situation: &str) -> HashMap<String, StationConfig> {
// extract ATIS stations and frequencies
let re = Regex::new(r"ATIS ([a-zA-Z- ]+) ([1-3]\d{2}(\.\d{1,3})?)").unwrap();
pub fn extract_stationc_config_from_mission_description(
situation: &str,
) -> HashMap<String, StationConfig> {
// extract ATIS stations from mission description
let re = Regex::new(r"(ATIS .*)").unwrap();
let mut stations: HashMap<String, StationConfig> = re
.captures_iter(situation)
.map(|caps| {
let name = caps.get(1).unwrap().as_str().to_string();
let freq = caps.get(2).unwrap().as_str();
let freq = (f32::from_str(freq).unwrap() * 1_000_000.0) as u64;
(
name.clone(),
StationConfig {
name,
atis: freq,
traffic: None,
tts: None,
info_ltr_override: None,
},
)
let atis_line = caps.get(1).unwrap().as_str();
let station = extract_atis_station_config(atis_line);
station
})
.flatten()
.map(|station| (station.name.clone(), station))
.collect();

// Some "legacy" functionality which allowed specifyin TRAFFIC options on separate lines
// extract optional traffic frequencies
let re = Regex::new(r"TRAFFIC ([a-zA-Z-]+) ([1-3]\d{2}(\.\d{1,3})?)").unwrap();
for caps in re.captures_iter(situation) {
Expand Down Expand Up @@ -64,6 +60,7 @@ pub fn extract_atis_station_config(config: &str) -> Option<StationConfig> {
let mut traffic_freq: Option<u64> = None;
let mut tts: Option<TextToSpeechProvider> = None;
let mut info_ltr_override = None;
let mut active_rwy_override = None;

let rex_option = RegexBuilder::new(r"([^ ]*) (.*)")
.case_insensitive(true)
Expand Down Expand Up @@ -97,6 +94,11 @@ pub fn extract_atis_station_config(config: &str) -> Option<StationConfig> {
Some(param.as_str().chars().next().unwrap().to_ascii_uppercase())
});
}
"ACTIVE" => {
active_rwy_override = caps
.get(2)
.map_or(None, |param| Some(param.as_str().into()));
}
_ => {
log::warn!("Unsupported ATIS station option {}", option_key);
}
Expand All @@ -109,6 +111,7 @@ pub fn extract_atis_station_config(config: &str) -> Option<StationConfig> {
traffic: traffic_freq,
tts,
info_ltr_override: info_ltr_override,
active_rwy_override: active_rwy_override,
};

Some(result)
Expand Down Expand Up @@ -159,6 +162,7 @@ pub fn extract_carrier_station_config(config: &str) -> Option<StationConfig> {
traffic: None,
tts,
info_ltr_override: info_ltr_override,
active_rwy_override: None,
};

Some(result)
Expand Down Expand Up @@ -266,8 +270,8 @@ mod test {
use crate::tts::{aws, gcloud, TextToSpeechProvider};

#[test]
fn test_mission_situation_extraction() {
let freqs = extract_atis_station_frequencies(
fn test_mission_descriptiopn_extraction() {
let freqs = extract_stationc_config_from_mission_description(
r#"
ATIS Mineralnye Vody 251.000
ATIS Batumi 131.5
Expand All @@ -288,6 +292,7 @@ mod test {
traffic: None,
tts: None,
info_ltr_override: None,
active_rwy_override: None,
}
),
(
Expand All @@ -298,6 +303,7 @@ mod test {
traffic: Some(255_000_000),
tts: None,
info_ltr_override: None,
active_rwy_override: None,
}
),
(
Expand All @@ -308,6 +314,7 @@ mod test {
traffic: None,
tts: None,
info_ltr_override: None,
active_rwy_override: None,
}
)
]
Expand All @@ -316,6 +323,35 @@ mod test {
);
}

#[test]
fn test_advanced_mission_descriptiopn_extraction() {
let freqs = extract_stationc_config_from_mission_description(
r#"Welcome to my mission!
It's not a real mission, but rather a chance to test the mission extraction
logic in datis!

ATIS Batumi 131.5, INFO T, ACTIVE 12
"#,
);

assert_eq!(
freqs,
vec![(
"Batumi".to_string(),
StationConfig {
name: "Batumi".to_string(),
atis: 131_500_000,
traffic: None,
tts: None,
info_ltr_override: Some('T'),
active_rwy_override: Some("12".to_string()),
}
)]
.into_iter()
.collect()
);
}

#[test]
fn test_atis_config_extraction() {
assert_eq!(
Expand All @@ -326,6 +362,7 @@ mod test {
traffic: None,
tts: None,
info_ltr_override: None,
active_rwy_override: None,
})
);

Expand All @@ -337,6 +374,7 @@ mod test {
traffic: None,
tts: None,
info_ltr_override: None,
active_rwy_override: None,
})
);

Expand All @@ -348,6 +386,7 @@ mod test {
traffic: None,
tts: None,
info_ltr_override: None,
active_rwy_override: None,
})
);

Expand All @@ -359,6 +398,7 @@ mod test {
traffic: Some(123_450_000),
tts: None,
info_ltr_override: None,
active_rwy_override: None,
})
);

Expand All @@ -373,7 +413,8 @@ mod test {
tts: Some(TextToSpeechProvider::GoogleCloud {
voice: gcloud::VoiceKind::StandardE
}),
info_ltr_override: Some('Q')
info_ltr_override: Some('Q'),
active_rwy_override: None,
})
);

Expand All @@ -389,6 +430,7 @@ mod test {
voice: gcloud::VoiceKind::StandardE
}),
info_ltr_override: None,
active_rwy_override: None,
})
);

Expand All @@ -402,6 +444,7 @@ mod test {
voice: gcloud::VoiceKind::StandardE
}),
info_ltr_override: None,
active_rwy_override: None,
})
);

Expand All @@ -413,6 +456,7 @@ mod test {
traffic: None,
tts: None,
info_ltr_override: None,
active_rwy_override: None,
})
);

Expand All @@ -425,6 +469,7 @@ mod test {
traffic: None,
tts: None,
info_ltr_override: None,
active_rwy_override: None,
})
);

Expand All @@ -437,6 +482,7 @@ mod test {
traffic: None,
tts: None,
info_ltr_override: None,
active_rwy_override: None,
})
);
}
Expand All @@ -451,6 +497,7 @@ mod test {
traffic: None,
tts: None,
info_ltr_override: None,
active_rwy_override: None,
})
);

Expand All @@ -462,6 +509,7 @@ mod test {
traffic: None,
tts: None,
info_ltr_override: None,
active_rwy_override: None,
})
);

Expand All @@ -475,6 +523,7 @@ mod test {
voice: gcloud::VoiceKind::StandardE
}),
info_ltr_override: None,
active_rwy_override: None,
})
);
}
Expand All @@ -491,6 +540,7 @@ mod test {
voice: gcloud::VoiceKind::StandardD
}),
info_ltr_override: None,
active_rwy_override: None,
})
);

Expand All @@ -504,6 +554,7 @@ mod test {
voice: aws::VoiceKind::Brian
}),
info_ltr_override: None,
active_rwy_override: None,
})
);
}
Expand All @@ -523,12 +574,13 @@ mod test {
voice: gcloud::VoiceKind::StandardE
}),
info_ltr_override: None,
active_rwy_override: None,
})
);
}

#[test]
fn test_complete_garbge() {
fn test_complete_garbage() {
assert_eq!(
extract_atis_station_config("not an atis station at all"),
None
Expand All @@ -550,6 +602,21 @@ mod test {
);
}

#[test]
fn test_active_rwy_override() {
assert_eq!(
extract_atis_station_config("ATIS Kutaisi 131.400, ACTIVE 21L"),
Some(StationConfig {
name: "Kutaisi".to_string(),
atis: 131_400_000,
traffic: None,
tts: None,
info_ltr_override: None,
active_rwy_override: Some("21L".to_string()),
})
);
}

#[test]
fn test_broadcast_config_extraction() {
assert_eq!(
Expand Down
9 changes: 9 additions & 0 deletions crates/datis-core/src/station.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct Airfield {
pub traffic_freq: Option<u64>,
pub info_ltr_offset: usize,
pub info_ltr_override: Option<char>,
pub active_rwy_override: Option<String>,
}

#[derive(Debug, PartialEq, Clone)]
Expand Down Expand Up @@ -215,6 +216,10 @@ impl Station {

impl Airfield {
fn get_active_runway(&self, wind_dir: f64) -> Option<&str> {
if let Some(rwy_override) = &self.active_rwy_override {
return Some(rwy_override);
}

let lr: &[_] = &['L', 'R'];
for rwy in &self.runways {
let rwy = rwy.trim_matches(lr);
Expand Down Expand Up @@ -594,6 +599,7 @@ mod test {
traffic_freq: None,
info_ltr_offset: 0,
info_ltr_override: None,
active_rwy_override: None,
};

assert_eq!(airfield.get_active_runway(0.0), Some("04"));
Expand All @@ -619,6 +625,7 @@ mod test {
traffic_freq: Some(249_500_000),
info_ltr_offset: 0,
info_ltr_override: None,
active_rwy_override: None,
}),
};

Expand All @@ -640,6 +647,7 @@ mod test {
traffic_freq: Some(249_500_000),
info_ltr_offset: 15, // Should be "Papa"
info_ltr_override: None,
active_rwy_override: None,
}),
};

Expand All @@ -661,6 +669,7 @@ mod test {
traffic_freq: Some(249_500_000),
info_ltr_offset: 15,
info_ltr_override: Some('Q'),
active_rwy_override: None,
}),
};

Expand Down
Loading