Add unsubscribe to facilities
This commit is contained in:
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -317,9 +317,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.46"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b"
|
||||
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
@@ -11,8 +11,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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)?;
|
||||
// After the connection is successfully open
|
||||
|
||||
// We request the existing list of airports in the facilities cache
|
||||
client.request_facilities_list(FacilityType::Airport)?;
|
||||
|
||||
// We subscribe to the current list and future additions of waypoints, NDBs and VORs
|
||||
client.subscribe_to_facilities(FacilityType::Waypoint)?;
|
||||
client.subscribe_to_facilities(FacilityType::NDB)?;
|
||||
client.subscribe_to_facilities(FacilityType::VOR)?;
|
||||
@@ -22,6 +26,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// The returned list is quite large, so we look for a particular record
|
||||
if record.icao == "EGSC" {
|
||||
println!("{record:?}");
|
||||
// we've got the entry we're interesting in - we can unsubscribe now
|
||||
client.unsubscribe_to_facilities(FacilityType::Airport)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +36,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// The returned list is quite large, so we look for a particular record
|
||||
if record.icao == "BRAIN" {
|
||||
println!("{record:?}");
|
||||
// we've got the entry we're interesting in - we can unsubscribe now
|
||||
client.unsubscribe_to_facilities(FacilityType::Waypoint)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,6 +46,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// The returned list is quite large, so we look for a particular record
|
||||
if record.icao == "CAM" {
|
||||
println!("{record:?}");
|
||||
// we've got the entry we're interesting in - we can unsubscribe now
|
||||
client.unsubscribe_to_facilities(FacilityType::NDB)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,6 +56,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// The returned list is quite large, so we look for a particular record
|
||||
if record.icao == "LON" {
|
||||
println!("{record:?}");
|
||||
// we've got the entry we're interesting in - we can unsubscribe now
|
||||
client.unsubscribe_to_facilities(FacilityType::VOR)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ fn main() {
|
||||
.allowlist_function("SimConnect_AddToDataDefinition")
|
||||
.allowlist_function("SimConnect_RequestDataOnSimObject")
|
||||
.allowlist_function("SimConnect_SubscribeToFacilities")
|
||||
.allowlist_function("SimConnect_UnsubscribeToFacilities")
|
||||
.allowlist_function("SimConnect_RequestFacilitiesList")
|
||||
.allowlist_type("SIMCONNECT_RECV")
|
||||
.allowlist_type("SIMCONNECT_RECV_ID")
|
||||
|
@@ -12,6 +12,9 @@ pub enum SimConnectError {
|
||||
/// Object already registered with the client instance.
|
||||
#[error("Object `{0}` has already been registered")]
|
||||
ObjectAlreadyRegistered(String),
|
||||
/// Object already registered with the client instance.
|
||||
#[error("Object `{0}` has not been registered")]
|
||||
ObjectNotRegistered(String),
|
||||
/// Object mismatch.
|
||||
#[error("Tried to convert object of type {actual} to {expected}")]
|
||||
ObjectMismatch { actual: String, expected: String },
|
||||
|
@@ -1,9 +1,8 @@
|
||||
use std::ffi::c_void;
|
||||
use std::{collections::HashMap, ffi::c_void};
|
||||
|
||||
use crate::{
|
||||
as_c_string, bindings, helpers::fixed_c_str_to_string, ok_if_fail, success, Airport, Condition,
|
||||
DataType, Event, FacilityType, Notification, NotificationGroup, Object, Period,
|
||||
SimConnectError, SimConnectObjectExt, Waypoint, NDB, VOR,
|
||||
as_c_string, bindings, helpers::fixed_c_str_to_string, ok_if_fail, success, Airport, Event,
|
||||
Notification, Object, SimConnectError, Waypoint, NDB, VOR,
|
||||
};
|
||||
|
||||
/// SimConnect SDK Client.
|
||||
@@ -60,8 +59,9 @@ use crate::{
|
||||
/// ```
|
||||
#[derive(Debug)]
|
||||
pub struct SimConnect {
|
||||
handle: std::ptr::NonNull<c_void>,
|
||||
registered_objects: Vec<String>,
|
||||
pub(super) handle: std::ptr::NonNull<c_void>,
|
||||
pub(super) next_request_id: u32,
|
||||
pub(super) registered_objects: HashMap<String, u32>,
|
||||
}
|
||||
|
||||
impl SimConnect {
|
||||
@@ -87,177 +87,11 @@ impl SimConnect {
|
||||
"SimConnect_Open returned null pointer on success".to_string(),
|
||||
)
|
||||
})?,
|
||||
registered_objects: Vec::new(),
|
||||
next_request_id: 0,
|
||||
registered_objects: HashMap::new(),
|
||||
})
|
||||
}
|
||||
|
||||
// Register an object with SimConnect by assigning it an unique interval `request_id` and then calling the [`crate::SimConnectObjectExt::register`] method on the struct.
|
||||
#[tracing::instrument(name = "SimConnect::register_object")]
|
||||
pub fn register_object<T: SimConnectObjectExt>(&mut self) -> Result<u32, SimConnectError> {
|
||||
let type_name: String = std::any::type_name::<T>().into();
|
||||
|
||||
let id = self.register_request_id(type_name)?;
|
||||
|
||||
T::register(self, id)?;
|
||||
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
/// Associates a client defined event with a Microsoft Flight Simulator event name.
|
||||
///
|
||||
/// WIP
|
||||
#[tracing::instrument(name = "SimConnect::register_event")]
|
||||
pub fn register_event(
|
||||
&self,
|
||||
event: Event,
|
||||
notification_group: NotificationGroup,
|
||||
) -> Result<(), SimConnectError> {
|
||||
success!(unsafe {
|
||||
bindings::SimConnect_MapClientEventToSimEvent(
|
||||
self.handle.as_ptr(),
|
||||
event as u32,
|
||||
event.into_c_char(),
|
||||
)
|
||||
});
|
||||
|
||||
success!(unsafe {
|
||||
bindings::SimConnect_AddClientEventToNotificationGroup(
|
||||
self.handle.as_ptr(),
|
||||
notification_group as u32,
|
||||
event as u32,
|
||||
0,
|
||||
)
|
||||
});
|
||||
|
||||
success!(unsafe {
|
||||
bindings::SimConnect_SetNotificationGroupPriority(
|
||||
self.handle.as_ptr(),
|
||||
notification_group as u32,
|
||||
1,
|
||||
)
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Add a Microsoft Flight Simulator simulation variable name to a client defined object definition.
|
||||
///
|
||||
/// # Remarks
|
||||
/// The [`crate::SimConnectObject`] macro will automatically call this method for you.
|
||||
#[tracing::instrument(name = "SimConnect::add_to_data_definition")]
|
||||
pub fn add_to_data_definition(
|
||||
&self,
|
||||
request_id: u32,
|
||||
datum_name: &str,
|
||||
units_name: &str,
|
||||
data_type: DataType,
|
||||
) -> Result<(), SimConnectError> {
|
||||
let c_type = match data_type {
|
||||
DataType::Float64 => bindings::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64,
|
||||
DataType::Bool => bindings::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_INT32,
|
||||
};
|
||||
|
||||
unsafe {
|
||||
success!(bindings::SimConnect_AddToDataDefinition(
|
||||
self.handle.as_ptr(),
|
||||
request_id,
|
||||
as_c_string!(datum_name),
|
||||
as_c_string!(units_name),
|
||||
c_type,
|
||||
0.0,
|
||||
u32::MAX,
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Request when the SimConnect client is to receive data values for a specific object.
|
||||
///
|
||||
/// # Remarks
|
||||
/// The [`crate::SimConnectObject`] macro will automatically call this method for you.
|
||||
///
|
||||
/// It is possible to change the period of a request, by re-sending the [`crate::SimConnect::request_data_on_sim_object`] call with the same `request_id` parameters, but with a new `period`.
|
||||
/// The one exception to this is the new period cannot be [`crate::Period::Once`], in this case a request with a new `request_id` should be sent.
|
||||
#[tracing::instrument(name = "SimConnect::request_data_on_sim_object")]
|
||||
pub fn request_data_on_sim_object(
|
||||
&self,
|
||||
request_id: u32,
|
||||
period: Period,
|
||||
condition: Condition,
|
||||
interval: u32,
|
||||
) -> Result<(), SimConnectError> {
|
||||
unsafe {
|
||||
success!(bindings::SimConnect_RequestDataOnSimObject(
|
||||
self.handle.as_ptr(),
|
||||
request_id,
|
||||
request_id,
|
||||
request_id,
|
||||
period.into(),
|
||||
condition.into(),
|
||||
0,
|
||||
interval,
|
||||
0,
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Request notifications when a facility of a certain type is added to the facilities cache.
|
||||
///
|
||||
/// When this function is first called, a full list from the cache will be sent, thereafter just the additions will be transmitted.
|
||||
/// No notification is given when a facility is removed from the cache.
|
||||
/// To terminate these notifications use the [`crate::SimConnect::unsubscribe_to_facilities`] function.
|
||||
///
|
||||
/// # Remarks
|
||||
/// The simulation keeps a facilities cache of all the airports, waypoints, NDB and VOR stations within a certain radius of the user aircraft.
|
||||
/// This radius varies depending on where the aircraft is in the world, but is at least large enough to encompass the whole of the reality bubble for airports and waypoints, and can be over 200 miles for VOR and NDB stations.
|
||||
/// As the user aircraft moves facilities will be added to, and removed from, the cache. However, in the interests pf performance, hysteresis is built into the system.
|
||||
#[tracing::instrument(name = "SimConnect::subscribe_to_facilities")]
|
||||
pub fn subscribe_to_facilities(
|
||||
&mut self,
|
||||
facility_type: FacilityType,
|
||||
) -> Result<(), SimConnectError> {
|
||||
let type_name = facility_type.to_type_name();
|
||||
let request_id = self.register_request_id(type_name)?;
|
||||
|
||||
unsafe {
|
||||
success!(bindings::SimConnect_SubscribeToFacilities(
|
||||
self.handle.as_ptr(),
|
||||
facility_type.into(),
|
||||
request_id,
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Request a list of all the facilities of a given type currently held in the facilities cache.
|
||||
///
|
||||
/// # Remarks
|
||||
/// The simulation keeps a facilities cache of all the airports, waypoints, NDB and VOR stations within a certain radius of the user aircraft.
|
||||
/// This radius varies depending on where the aircraft is in the world, but is at least large enough to encompass the whole of the reality bubble for airports and waypoints, and can be over 200 miles for VOR and NDB stations.
|
||||
/// As the user aircraft moves facilities will be added to, and removed from, the cache. However, in the interests pf performance, hysteresis is built into the system.
|
||||
#[tracing::instrument(name = "SimConnect::request_facilities_list")]
|
||||
pub fn request_facilities_list(
|
||||
&mut self,
|
||||
facility_type: FacilityType,
|
||||
) -> Result<(), SimConnectError> {
|
||||
let type_name = facility_type.to_type_name();
|
||||
let request_id = self.register_request_id(type_name)?;
|
||||
|
||||
unsafe {
|
||||
success!(bindings::SimConnect_RequestFacilitiesList(
|
||||
self.handle.as_ptr(),
|
||||
facility_type.into(),
|
||||
request_id,
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Receive the next SimConnect message.
|
||||
///
|
||||
/// # Remarks
|
||||
@@ -295,12 +129,12 @@ impl SimConnect {
|
||||
)
|
||||
};
|
||||
|
||||
let object_type = self.registered_objects.get(event.dwDefineID as usize);
|
||||
let type_name = self.get_type_name_by_request_id(event.dwDefineID);
|
||||
|
||||
match object_type {
|
||||
Some(object_type) => {
|
||||
match type_name {
|
||||
Some(type_name) => {
|
||||
let data = Object {
|
||||
type_name: object_type.clone(),
|
||||
type_name,
|
||||
data_addr: std::ptr::addr_of!(event.dwData),
|
||||
};
|
||||
|
||||
@@ -464,26 +298,41 @@ impl SimConnect {
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Register a request id in the internal state so that the user doesn't have to manually manage requests ids.
|
||||
#[tracing::instrument(name = "SimConnect::register_request_id")]
|
||||
fn register_request_id(&mut self, type_name: String) -> Result<u32, SimConnectError> {
|
||||
if self.registered_objects.contains(&type_name) {
|
||||
/// Register a Request ID in the internal state so that the user doesn't have to manually manage Request IDs.
|
||||
#[tracing::instrument(name = "SimConnect::new_request_id")]
|
||||
pub(super) fn new_request_id(&mut self, type_name: String) -> Result<u32, SimConnectError> {
|
||||
if self.registered_objects.contains_key(&type_name) {
|
||||
return Err(SimConnectError::ObjectAlreadyRegistered(type_name));
|
||||
}
|
||||
|
||||
self.registered_objects.push(type_name.clone());
|
||||
let mut request_id = self.next_request_id;
|
||||
self.next_request_id += 1;
|
||||
|
||||
// using the index for now because we don't unregister objects, yet
|
||||
let id = self
|
||||
.registered_objects
|
||||
// when `next_request_id` overflows some ids might still be in use
|
||||
// so we need to find the next available one
|
||||
while self.registered_objects.values().any(|id| *id == request_id) {
|
||||
request_id = self.next_request_id;
|
||||
self.next_request_id += 1;
|
||||
}
|
||||
|
||||
self.registered_objects.insert(type_name, request_id);
|
||||
|
||||
Ok(request_id)
|
||||
}
|
||||
|
||||
/// Unregister a Request ID in the internal state so that the user doesn't have to manually manage Request IDs.
|
||||
#[tracing::instrument(name = "SimConnect::unregister_request_id_by_type_name")]
|
||||
pub(super) fn unregister_request_id_by_type_name(&mut self, type_name: String) {
|
||||
self.registered_objects.remove(&type_name);
|
||||
}
|
||||
|
||||
/// Get the Type Name of a Request ID.
|
||||
#[tracing::instrument(name = "SimConnect::get_request_id_by_type_name")]
|
||||
pub(super) fn get_type_name_by_request_id(&self, request_id: u32) -> Option<String> {
|
||||
self.registered_objects
|
||||
.iter()
|
||||
.position(|p| p == &type_name)
|
||||
.ok_or_else(|| {
|
||||
SimConnectError::UnexpectedError("failed to find registered event".to_string())
|
||||
})?;
|
||||
let id = u32::try_from(id)?;
|
||||
|
||||
Ok(id)
|
||||
.find(|(_, v)| **v == request_id)
|
||||
.map(|(k, _)| k.clone())
|
||||
}
|
||||
}
|
||||
|
40
simconnect-sdk/src/simconnect/events.rs
Normal file
40
simconnect-sdk/src/simconnect/events.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use crate::{bindings, success, Event, NotificationGroup, SimConnect, SimConnectError};
|
||||
|
||||
impl SimConnect {
|
||||
/// Associates a client defined event with a Microsoft Flight Simulator event name.
|
||||
///
|
||||
/// WIP
|
||||
#[tracing::instrument(name = "SimConnect::register_event")]
|
||||
pub fn register_event(
|
||||
&self,
|
||||
event: Event,
|
||||
notification_group: NotificationGroup,
|
||||
) -> Result<(), SimConnectError> {
|
||||
success!(unsafe {
|
||||
bindings::SimConnect_MapClientEventToSimEvent(
|
||||
self.handle.as_ptr(),
|
||||
event as u32,
|
||||
event.into_c_char(),
|
||||
)
|
||||
});
|
||||
|
||||
success!(unsafe {
|
||||
bindings::SimConnect_AddClientEventToNotificationGroup(
|
||||
self.handle.as_ptr(),
|
||||
notification_group as u32,
|
||||
event as u32,
|
||||
0,
|
||||
)
|
||||
});
|
||||
|
||||
success!(unsafe {
|
||||
bindings::SimConnect_SetNotificationGroupPriority(
|
||||
self.handle.as_ptr(),
|
||||
notification_group as u32,
|
||||
1,
|
||||
)
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
86
simconnect-sdk/src/simconnect/facilities.rs
Normal file
86
simconnect-sdk/src/simconnect/facilities.rs
Normal file
@@ -0,0 +1,86 @@
|
||||
use crate::{bindings, success, FacilityType, SimConnect, SimConnectError};
|
||||
|
||||
impl SimConnect {
|
||||
/// Request a list of all the facilities of a given type currently held in the facilities cache.
|
||||
///
|
||||
/// # Errors
|
||||
/// - [`crate::SimConnectError::ObjectAlreadyRegistered`] -- Only one request or subscription per facility type is allowed. If you wish to create a new one, unsubscribe first using [`crate::SimConnect::unsubscribe_to_facilities`].
|
||||
///
|
||||
/// # Remarks
|
||||
/// The simulation keeps a facilities cache of all the airports, waypoints, NDB and VOR stations within a certain radius of the user aircraft.
|
||||
/// This radius varies depending on where the aircraft is in the world, but is at least large enough to encompass the whole of the reality bubble for airports and waypoints, and can be over 200 miles for VOR and NDB stations.
|
||||
/// As the user aircraft moves facilities will be added to, and removed from, the cache. However, in the interests pf performance, hysteresis is built into the system.
|
||||
#[tracing::instrument(name = "SimConnect::request_facilities_list")]
|
||||
pub fn request_facilities_list(
|
||||
&mut self,
|
||||
facility_type: FacilityType,
|
||||
) -> Result<(), SimConnectError> {
|
||||
let type_name = facility_type.to_type_name();
|
||||
let request_id = self.new_request_id(type_name)?;
|
||||
|
||||
unsafe {
|
||||
success!(bindings::SimConnect_RequestFacilitiesList(
|
||||
self.handle.as_ptr(),
|
||||
facility_type.into(),
|
||||
request_id,
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Request notifications when a facility of a certain type is added to the facilities cache.
|
||||
///
|
||||
/// When this function is first called, a full list from the cache will be sent, thereafter just the additions will be transmitted.
|
||||
/// No notification is given when a facility is removed from the cache.
|
||||
/// To terminate these notifications use the [`crate::SimConnect::unsubscribe_to_facilities`] function.
|
||||
///
|
||||
/// # Errors
|
||||
/// - [`crate::SimConnectError::ObjectAlreadyRegistered`] -- Only one subscription or request per facility type is allowed. If you wish to create a new one, unsubscribe first using [`crate::SimConnect::unsubscribe_to_facilities`].
|
||||
///
|
||||
/// # Remarks
|
||||
/// The simulation keeps a facilities cache of all the airports, waypoints, NDB and VOR stations within a certain radius of the user aircraft.
|
||||
/// This radius varies depending on where the aircraft is in the world, but is at least large enough to encompass the whole of the reality bubble for airports and waypoints, and can be over 200 miles for VOR and NDB stations.
|
||||
/// As the user aircraft moves facilities will be added to, and removed from, the cache. However, in the interests pf performance, hysteresis is built into the system.
|
||||
#[tracing::instrument(name = "SimConnect::subscribe_to_facilities")]
|
||||
pub fn subscribe_to_facilities(
|
||||
&mut self,
|
||||
facility_type: FacilityType,
|
||||
) -> Result<(), SimConnectError> {
|
||||
let type_name = facility_type.to_type_name();
|
||||
let request_id = self.new_request_id(type_name)?;
|
||||
|
||||
unsafe {
|
||||
success!(bindings::SimConnect_SubscribeToFacilities(
|
||||
self.handle.as_ptr(),
|
||||
facility_type.into(),
|
||||
request_id,
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Request that notifications of additions to the facilities cache are not longer sent.
|
||||
///
|
||||
/// # Remarks
|
||||
/// This is used to terminate notifications generated by the [`crate::SimConnect::request_facilities_list`] or [`crate::SimConnect::subscribe_to_facilities`] functions.
|
||||
#[tracing::instrument(name = "SimConnect::unsubscribe_to_facilities")]
|
||||
pub fn unsubscribe_to_facilities(
|
||||
&mut self,
|
||||
facility_type: FacilityType,
|
||||
) -> Result<(), SimConnectError> {
|
||||
let type_name = facility_type.to_type_name();
|
||||
|
||||
unsafe {
|
||||
success!(bindings::SimConnect_UnsubscribeToFacilities(
|
||||
self.handle.as_ptr(),
|
||||
facility_type.into(),
|
||||
));
|
||||
}
|
||||
|
||||
self.unregister_request_id_by_type_name(type_name);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
9
simconnect-sdk/src/simconnect/mod.rs
Normal file
9
simconnect-sdk/src/simconnect/mod.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
mod base;
|
||||
mod events;
|
||||
mod facilities;
|
||||
mod objects;
|
||||
|
||||
pub use base::*;
|
||||
pub use events::*;
|
||||
pub use facilities::*;
|
||||
pub use objects::*;
|
82
simconnect-sdk/src/simconnect/objects.rs
Normal file
82
simconnect-sdk/src/simconnect/objects.rs
Normal file
@@ -0,0 +1,82 @@
|
||||
use crate::{
|
||||
as_c_string, bindings, success, Condition, DataType, Period, SimConnect, SimConnectError,
|
||||
SimConnectObjectExt,
|
||||
};
|
||||
|
||||
impl SimConnect {
|
||||
// Register an object with SimConnect by assigning it an unique interval `request_id` and then calling the [`crate::SimConnectObjectExt::register`] method on the struct.
|
||||
#[tracing::instrument(name = "SimConnect::register_object")]
|
||||
pub fn register_object<T: SimConnectObjectExt>(&mut self) -> Result<u32, SimConnectError> {
|
||||
let type_name: String = std::any::type_name::<T>().into();
|
||||
|
||||
let id = self.new_request_id(type_name)?;
|
||||
|
||||
T::register(self, id)?;
|
||||
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
/// Add a Microsoft Flight Simulator simulation variable name to a client defined object definition.
|
||||
///
|
||||
/// # Remarks
|
||||
/// The [`crate::SimConnectObject`] macro will automatically call this method for you.
|
||||
#[tracing::instrument(name = "SimConnect::add_to_data_definition")]
|
||||
pub fn add_to_data_definition(
|
||||
&self,
|
||||
request_id: u32,
|
||||
datum_name: &str,
|
||||
units_name: &str,
|
||||
data_type: DataType,
|
||||
) -> Result<(), SimConnectError> {
|
||||
let c_type = match data_type {
|
||||
DataType::Float64 => bindings::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64,
|
||||
DataType::Bool => bindings::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_INT32,
|
||||
};
|
||||
|
||||
unsafe {
|
||||
success!(bindings::SimConnect_AddToDataDefinition(
|
||||
self.handle.as_ptr(),
|
||||
request_id,
|
||||
as_c_string!(datum_name),
|
||||
as_c_string!(units_name),
|
||||
c_type,
|
||||
0.0,
|
||||
u32::MAX,
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Request when the SimConnect client is to receive data values for a specific object.
|
||||
///
|
||||
/// # Remarks
|
||||
/// The [`crate::SimConnectObject`] macro will automatically call this method for you.
|
||||
///
|
||||
/// It is possible to change the period of a request, by re-sending the [`crate::SimConnect::request_data_on_sim_object`] call with the same `request_id` parameters, but with a new `period`.
|
||||
/// The one exception to this is the new period cannot be [`crate::Period::Once`], in this case a request with a new `request_id` should be sent.
|
||||
#[tracing::instrument(name = "SimConnect::request_data_on_sim_object")]
|
||||
pub fn request_data_on_sim_object(
|
||||
&self,
|
||||
request_id: u32,
|
||||
period: Period,
|
||||
condition: Condition,
|
||||
interval: u32,
|
||||
) -> Result<(), SimConnectError> {
|
||||
unsafe {
|
||||
success!(bindings::SimConnect_RequestDataOnSimObject(
|
||||
self.handle.as_ptr(),
|
||||
request_id,
|
||||
request_id,
|
||||
request_id,
|
||||
period.into(),
|
||||
condition.into(),
|
||||
0,
|
||||
interval,
|
||||
0,
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user