Skip to content

Commit

Permalink
Merge pull request #69 from talbotmcinnis/InformationOverride
Browse files Browse the repository at this point in the history
Information override
  • Loading branch information
rkusa committed Oct 27, 2020
2 parents a8f8c01 + 5e00658 commit acb492e
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ build:
test:
cargo test --workspace --exclude datis

test_debug:
cargo test -- --nocapture

release:
cargo build --release --package datis
powershell copy target/release/datis.dll mod/Mods/services/DATIS/bin/
Expand Down
5 changes: 4 additions & 1 deletion 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}]
ATIS {Airfield} {ATIS Frequency}[, TRAFFIC {TRAFFIC Frequency}][, VOICE {VOICE NAME}, INFO {OVERRIDE INFO LETTER}]
```

Your choice for `{VOICE NAME}` depicts which cloud provider is used for a particular ATIS station.
Expand All @@ -113,6 +113,8 @@ Available voices are:

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.

Examples:

```
Expand All @@ -123,6 +125,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
```

![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 @@ -86,6 +86,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
runways: vec![String::from("09"), String::from("26")],
traffic_freq: None,
info_ltr_offset: 0,
info_ltr_override: None,
}),
};
let mut datis = Datis::new(vec![station])?;
Expand Down
38 changes: 37 additions & 1 deletion crates/datis-core/src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct StationConfig {
pub atis: u64,
pub traffic: Option<u64>,
pub tts: Option<TextToSpeechProvider>,
pub info_ltr_override: Option<char>,
}

pub fn extract_atis_station_frequencies(situation: &str) -> HashMap<String, StationConfig> {
Expand All @@ -28,6 +29,7 @@ pub fn extract_atis_station_frequencies(situation: &str) -> HashMap<String, Stat
atis: freq,
traffic: None,
tts: None,
info_ltr_override: None,
},
)
})
Expand All @@ -50,11 +52,12 @@ pub fn extract_atis_station_frequencies(situation: &str) -> HashMap<String, Stat

pub fn extract_atis_station_config(config: &str) -> Option<StationConfig> {
let re = RegexBuilder::new(
r"^ATIS ([a-zA-Z- ]+) ([1-3]\d{2}(\.\d{1,3})?)(,[ ]?TRAFFIC ([1-3]\d{2}(\.\d{1,3})?))?(,[ ]?VOICE ([a-zA-Z-:]+))?$",
r"^ATIS ([a-zA-Z- ]+) ([1-3]\d{2}(\.\d{1,3})?)(,[ ]?TRAFFIC ([1-3]\d{2}(\.\d{1,3})?))?(,[ ]?VOICE ([a-zA-Z-:]+))?(,[ ]?INFO ([a-zA-Z]))?$",
)
.case_insensitive(true)
.build()
.unwrap();

re.captures(config).map(|caps| {
let name = caps.get(1).unwrap().as_str();
let atis_freq = caps.get(2).unwrap().as_str();
Expand All @@ -65,11 +68,15 @@ pub fn extract_atis_station_config(config: &str) -> Option<StationConfig> {
let tts = caps
.get(8)
.and_then(|s| TextToSpeechProvider::from_str(s.as_str()).ok());
let info_ltr = caps
.get(10)
.map(|ilo| ((ilo.as_str()).chars().next().unwrap().to_ascii_uppercase()) as char);
StationConfig {
name: name.to_string(),
atis: atis_freq,
traffic: traffic_freq,
tts,
info_ltr_override: info_ltr,
}
})
}
Expand All @@ -93,6 +100,7 @@ pub fn extract_carrier_station_config(config: &str) -> Option<StationConfig> {
atis: atis_freq,
traffic: None,
tts,
info_ltr_override: None
}
})
}
Expand Down Expand Up @@ -182,6 +190,7 @@ mod test {
atis: 251_000_000,
traffic: None,
tts: None,
info_ltr_override: None,
}
),
(
Expand All @@ -191,6 +200,7 @@ mod test {
atis: 131_500_000,
traffic: Some(255_000_000),
tts: None,
info_ltr_override: None,
}
),
(
Expand All @@ -200,6 +210,7 @@ mod test {
atis: 145_000_000,
traffic: None,
tts: None,
info_ltr_override: None,
}
)
]
Expand All @@ -217,6 +228,7 @@ mod test {
atis: 251_000_000,
traffic: None,
tts: None,
info_ltr_override: None,
})
);

Expand All @@ -227,6 +239,7 @@ mod test {
atis: 251_000_000,
traffic: None,
tts: None,
info_ltr_override: None,
})
);

Expand All @@ -237,6 +250,7 @@ mod test {
atis: 251_000_000,
traffic: None,
tts: None,
info_ltr_override: None,
})
);

Expand All @@ -247,6 +261,20 @@ mod test {
atis: 251_000_000,
traffic: Some(123_450_000),
tts: None,
info_ltr_override: None,
})
);

assert_eq!(
extract_atis_station_config("ATIS Kutaisi 251.000, TRAFFIC 123.45, VOICE en-US-Standard-E, INFO Q"),
Some(StationConfig {
name: "Kutaisi".to_string(),
atis: 251_000_000,
traffic: Some(123_450_000),
tts: Some(TextToSpeechProvider::GoogleCloud {
voice: gcloud::VoiceKind::StandardE
}),
info_ltr_override: Some('Q')
})
);

Expand All @@ -261,6 +289,7 @@ mod test {
tts: Some(TextToSpeechProvider::GoogleCloud {
voice: gcloud::VoiceKind::StandardE
}),
info_ltr_override: None,
})
);

Expand All @@ -273,6 +302,7 @@ mod test {
tts: Some(TextToSpeechProvider::GoogleCloud {
voice: gcloud::VoiceKind::StandardE
}),
info_ltr_override: None,
})
);

Expand All @@ -283,6 +313,7 @@ mod test {
atis: 131_400_000,
traffic: None,
tts: None,
info_ltr_override: None,
})
);
}
Expand All @@ -296,6 +327,7 @@ mod test {
atis: 251_000_000,
traffic: None,
tts: None,
info_ltr_override: None,
})
);

Expand All @@ -306,6 +338,7 @@ mod test {
atis: 131_400_000,
traffic: None,
tts: None,
info_ltr_override: None,
})
);

Expand All @@ -318,6 +351,7 @@ mod test {
tts: Some(TextToSpeechProvider::GoogleCloud {
voice: gcloud::VoiceKind::StandardE
}),
info_ltr_override: None,
})
);
}
Expand All @@ -333,6 +367,7 @@ mod test {
tts: Some(TextToSpeechProvider::GoogleCloud {
voice: gcloud::VoiceKind::StandardD
}),
info_ltr_override: None,
})
);

Expand All @@ -345,6 +380,7 @@ mod test {
tts: Some(TextToSpeechProvider::AmazonWebServices {
voice: aws::VoiceKind::Brian
}),
info_ltr_override: None,
})
);
}
Expand Down
41 changes: 36 additions & 5 deletions crates/datis-core/src/station.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct Station {
pub name: String,
pub freq: u64,
pub tts: TextToSpeechProvider,
pub transmitter: Transmitter,
pub transmitter: Transmitter,
#[cfg(feature = "rpc")]
pub rpc: Option<crate::rpc::MissionRpc>,
}
Expand All @@ -28,6 +28,7 @@ pub struct Airfield {
pub runways: Vec<String>,
pub traffic_freq: Option<u64>,
pub info_ltr_offset: usize,
pub info_ltr_override: Option<char>,
}

#[derive(Debug, PartialEq, Clone)]
Expand All @@ -52,6 +53,7 @@ pub struct WeatherTransmitter {
pub unit_id: u32,
pub unit_name: String,
pub info_ltr_offset: usize,
pub info_ltr_override: Option<char>,
}

pub struct Report {
Expand Down Expand Up @@ -241,10 +243,12 @@ impl Airfield {
let _break = if spoken { "\n" } else { "" };
#[cfg(test)]
let _break = if spoken { "| " } else { "" };

let information_letter = phonetic_alphabet::lookup(self.info_ltr_offset + report_nr);

let mut report = if spoken { SPEAK_START_TAG } else { "" }.to_string();

let information_num = if let Some(ltr_override) = self.info_ltr_override {(ltr_override.to_ascii_uppercase() as usize)-65} else {self.info_ltr_offset + report_nr};
let information_letter = phonetic_alphabet::lookup(information_num);

report += &format!(
"This is {} information {}. {}",
self.name, information_letter, _break
Expand Down Expand Up @@ -436,7 +440,8 @@ impl WeatherTransmitter {
#[cfg(test)]
let _break = if spoken { "| " } else { "" };

let information_letter = phonetic_alphabet::lookup(self.info_ltr_offset + report_nr);
let information_num = if let Some(ltr_override) = self.info_ltr_override {(ltr_override.to_ascii_uppercase() as usize)-65} else {self.info_ltr_offset + report_nr};
let information_letter = phonetic_alphabet::lookup(information_num);
let mut report = if spoken { SPEAK_START_TAG } else { "" }.to_string();

report += &format!(
Expand Down Expand Up @@ -580,6 +585,7 @@ mod test {
runways: vec![String::from("04"), String::from("22R")],
traffic_freq: None,
info_ltr_offset: 0,
info_ltr_override: None
};

assert_eq!(airfield.get_active_runway(0.0), Some("04"));
Expand All @@ -604,6 +610,7 @@ mod test {
runways: vec![String::from("04"), String::from("22")],
traffic_freq: Some(249_500_000),
info_ltr_offset: 0,
info_ltr_override: None
}),
};

Expand All @@ -624,6 +631,7 @@ mod test {
runways: vec![String::from("04"), String::from("22")],
traffic_freq: Some(249_500_000),
info_ltr_offset: 15, // Should be "Papa"
info_ltr_override: None
}),
};

Expand All @@ -632,6 +640,28 @@ mod test {
assert_eq!(report.textual, "This is Kutaisi information Papa. Runway in use is 04. Wind 006 at 5 knots. Temperature 22 celcius. ALTIMETER 2997. Traffic frequency 249.5. REMARKS. 1015 hectopascal. QFE 2997 or 1015. End information Papa.");
}

#[tokio::test]
async fn test_report_with_info_letter_override() {
let station = Station {
name: String::from("Kutaisi"),
freq: 251_000_000,
tts: TextToSpeechProvider::default(),
transmitter: Transmitter::Airfield(Airfield {
name: String::from("Kutaisi"),
position: Position::default(),
runways: vec![String::from("04"), String::from("22")],
traffic_freq: Some(249_500_000),
info_ltr_offset: 15,
info_ltr_override: Some('Q'),
}),
rpc: None,
};

let report = station.generate_report(26).await.unwrap().unwrap();
assert_eq!(report.spoken, "<speak version=\"1.0\" xml:lang=\"en-US\">\nThis is Kutaisi information Quebec. | Runway in use is ZERO 4. | Wind ZERO ZERO 6 at 5 knots. | Temperature 2 2 celcius. | ALTIMETER 2 NINER NINER 7. | Traffic frequency 2 4 NINER DECIMAL 5. | REMARKS. | 1 ZERO 1 5 hectopascal. | QFE 2 NINER NINER 7 or 1 ZERO 1 5. | End information Papa.\n</speak>");
assert_eq!(report.textual, "This is Kutaisi information Quebec. Runway in use is 04. Wind 006 at 5 knots. Temperature 22 celcius. ALTIMETER 2997. Traffic frequency 249.5. REMARKS. 1015 hectopascal. QFE 2997 or 1015. End information Papa.");
}

#[test]
fn test_phonetic_alpha_lookup() {
assert_eq!(phonetic_alphabet::lookup(0), "Alpha");
Expand Down Expand Up @@ -730,7 +760,8 @@ mod test {
position: Some(Position::default()),
unit_id: 42,
unit_name: "Weather Post".to_string(),
info_ltr_offset: 15, // Should be "Papa"
info_ltr_offset: 15, // Should be "Papa",
info_ltr_override: None
}),
};

Expand Down
3 changes: 3 additions & 0 deletions crates/datis-module/src/mission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub fn extract(lua: &Lua) -> Result<Info, mlua::Error> {
runways,
traffic_freq: None,
info_ltr_offset: rng.gen_range(0, 25),
info_ltr_override: None,
},
);
}
Expand Down Expand Up @@ -235,6 +236,7 @@ pub fn extract(lua: &Lua) -> Result<Info, mlua::Error> {
extract_atis_station_config(&mission_unit.name).and_then(|config| {
airfields.remove(&config.name).map(|mut airfield| {
airfield.traffic_freq = config.traffic;
airfield.info_ltr_override = config.info_ltr_override;
airfield.position.x = mission_unit.x;
airfield.position.y = mission_unit.y;
airfield.position.alt = mission_unit.alt;
Expand Down Expand Up @@ -356,6 +358,7 @@ pub fn extract(lua: &Lua) -> Result<Info, mlua::Error> {
unit_id: mission_unit.id,
unit_name: mission_unit.name.clone(),
info_ltr_offset: rng.gen_range(0, 25),
info_ltr_override: None
}),
rpc: Some(rpc.clone()),
})
Expand Down

0 comments on commit acb492e

Please sign in to comment.