Add support for facilities
This commit is contained in:
@@ -8,20 +8,24 @@ license = "MIT"
|
||||
publish = false
|
||||
|
||||
[[bin]]
|
||||
name = "basic"
|
||||
path = "src/basic.rs"
|
||||
name = "data"
|
||||
path = "src/data.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "basic_with_tracing"
|
||||
path = "src/basic_with_tracing.rs"
|
||||
name = "data_with_tracing"
|
||||
path = "src/data_with_tracing.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "basic_without_macro"
|
||||
path = "src/basic_without_macro.rs"
|
||||
name = "data_without_macro"
|
||||
path = "src/data_without_macro.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "multiple_objects"
|
||||
path = "src/multiple_objects.rs"
|
||||
name = "data_multiple_objects"
|
||||
path = "src/data_multiple_objects.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "facilities"
|
||||
path = "src/facilities.rs"
|
||||
|
||||
[dependencies]
|
||||
tracing = "0.1"
|
||||
|
@@ -10,23 +10,29 @@ cd simconnect-sdk
|
||||
## Receiving data
|
||||
|
||||
```bash
|
||||
cargo run --bin basic
|
||||
cargo run --bin data
|
||||
```
|
||||
|
||||
## Using tracing
|
||||
## Receiving data using tracing
|
||||
|
||||
```bash
|
||||
RUST_LOG=info cargo run --bin basic_with_tracing
|
||||
RUST_LOG=info cargo run --bin data_with_tracing
|
||||
```
|
||||
|
||||
## Receiving data without the derive macro
|
||||
|
||||
```bash
|
||||
cargo run --bin basic_without_macro
|
||||
cargo run --bin data_without_macro
|
||||
```
|
||||
|
||||
## Multiple objects
|
||||
## Receiving data using multiple objects
|
||||
|
||||
```bash
|
||||
cargo run --bin multiple_objects
|
||||
cargo run --bin data_multiple_objects
|
||||
```
|
||||
|
||||
## Receiving facilities from cache
|
||||
|
||||
```bash
|
||||
cargo run --bin facilities
|
||||
```
|
||||
|
@@ -25,12 +25,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Some(Notification::Open) => {
|
||||
println!("Open");
|
||||
|
||||
// The struct must be registered after the connection is successfully open
|
||||
// After the connection is successfully open, we register the struct
|
||||
client.register_object::<GpsData>()?;
|
||||
}
|
||||
Some(Notification::Data(data)) => {
|
||||
Some(Notification::Object(data)) => {
|
||||
if let Ok(gps_data) = GpsData::try_from(&data) {
|
||||
println!("GPS Data: {gps_data:?}");
|
||||
println!("{gps_data:?}");
|
||||
}
|
||||
}
|
||||
_ => (),
|
@@ -33,19 +33,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Some(Notification::Open) => {
|
||||
println!("Open");
|
||||
|
||||
// The structs must be registered after the connection is successfully open
|
||||
// After the connection is successfully open, we register the structs
|
||||
client.register_object::<GpsData>()?;
|
||||
client.register_object::<OnGround>()?;
|
||||
}
|
||||
Some(Notification::Data(data)) => {
|
||||
Some(Notification::Object(data)) => {
|
||||
if let Ok(gps_data) = GpsData::try_from(&data) {
|
||||
println!("GPS Data: {gps_data:?}");
|
||||
// We've already got our object, there's no point in trying another in this iteration
|
||||
println!("{gps_data:?}");
|
||||
// We've already got our data, there's no point in trying another in this iteration
|
||||
continue;
|
||||
}
|
||||
if let Ok(on_ground) = OnGround::try_from(&data) {
|
||||
println!("On Ground data: {on_ground:?}");
|
||||
// We've already got our object, there's no point in trying another in this iteration
|
||||
println!("{on_ground:?}");
|
||||
// We've already got our data, there's no point in trying another in this iteration
|
||||
continue;
|
||||
}
|
||||
}
|
@@ -29,12 +29,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Some(Notification::Open) => {
|
||||
info!("Open");
|
||||
|
||||
// The struct must be registered after the connection is successfully open
|
||||
// After the connection is successfully open, we register the struct
|
||||
client.register_object::<GpsData>()?;
|
||||
}
|
||||
Some(Notification::Data(data)) => {
|
||||
Some(Notification::Object(data)) => {
|
||||
if let Ok(gps_data) = GpsData::try_from(&data) {
|
||||
info!("GPS Data: {gps_data:?}");
|
||||
info!("{gps_data:?}");
|
||||
}
|
||||
}
|
||||
_ => (),
|
@@ -1,7 +1,7 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use simconnect_sdk::{
|
||||
Condition, DataType, Notification, NotificationData, Period, SimConnect, SimConnectError,
|
||||
Condition, DataType, Notification, Object, Period, SimConnect, SimConnectError,
|
||||
SimConnectObjectExt,
|
||||
};
|
||||
|
||||
@@ -25,10 +25,10 @@ impl SimConnectObjectExt for GpsData {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&NotificationData> for GpsData {
|
||||
impl TryFrom<&Object> for GpsData {
|
||||
type Error = SimConnectError;
|
||||
|
||||
fn try_from(value: &NotificationData) -> Result<Self, Self::Error> {
|
||||
fn try_from(value: &Object) -> Result<Self, Self::Error> {
|
||||
value.try_transmute::<GpsData>()
|
||||
}
|
||||
}
|
||||
@@ -44,12 +44,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Some(Notification::Open) => {
|
||||
println!("Open");
|
||||
|
||||
// The struct must be registered after the connection is successfully open
|
||||
// After the connection is successfully open, we register the struct
|
||||
client.register_object::<GpsData>()?;
|
||||
}
|
||||
Some(Notification::Data(data)) => {
|
||||
Some(Notification::Object(data)) => {
|
||||
if let Ok(gps_data) = GpsData::try_from(&data) {
|
||||
println!("GPS Data: {gps_data:?}");
|
||||
println!("{gps_data:?}");
|
||||
}
|
||||
}
|
||||
_ => (),
|
64
examples/src/facilities.rs
Normal file
64
examples/src/facilities.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
use simconnect_sdk::{FacilityType, Notification, SimConnect};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let client = SimConnect::new("Simple Program");
|
||||
|
||||
match client {
|
||||
Ok(mut client) => loop {
|
||||
let notification = client.get_next_dispatch()?;
|
||||
|
||||
match notification {
|
||||
Some(Notification::Open) => {
|
||||
println!("Open");
|
||||
|
||||
// After the connection is successfully open, we subscribe to all facility types that we are interested in
|
||||
client.subscribe_to_facilities(FacilityType::Airport)?;
|
||||
client.subscribe_to_facilities(FacilityType::Waypoint)?;
|
||||
client.subscribe_to_facilities(FacilityType::NDB)?;
|
||||
client.subscribe_to_facilities(FacilityType::VOR)?;
|
||||
}
|
||||
Some(Notification::AirportList(data)) => {
|
||||
for record in data {
|
||||
// The returned list is quite large, so we look for a particular record
|
||||
if record.icao == "EGSC" {
|
||||
println!("{record:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(Notification::WaypointList(data)) => {
|
||||
for record in data {
|
||||
// The returned list is quite large, so we look for a particular record
|
||||
if record.icao == "BRAIN" {
|
||||
println!("{record:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(Notification::NdbList(data)) => {
|
||||
for record in data {
|
||||
// The returned list is quite large, so we look for a particular record
|
||||
if record.icao == "CAM" {
|
||||
println!("{record:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(Notification::VorList(data)) => {
|
||||
for record in data {
|
||||
// The returned list is quite large, so we look for a particular record
|
||||
if record.icao == "LON" {
|
||||
println!("{record:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
// sleep for about a frame to reduce CPU usage
|
||||
std::thread::sleep(std::time::Duration::from_millis(16));
|
||||
},
|
||||
Err(e) => {
|
||||
println!("Error: {e:?}")
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user