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

32-Bit SimConnect Support (32-bit Prepar3D) #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 8 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,17 @@ loop {
```
### Remarks
I have not tested every single function from the api. If you find an error, feel free to make an issue or a pull request.

### 32-Bit Support

It is possible to build & target 32-bit versions of Prepar3D (All other 32-bit flight sims should be possible but I have not tested those).

Requirements:

- [32-bit Clang (tested with 11.0.1)](https://github.com/llvm/llvm-project/releases/tag/llvmorg-11.0.1)
- 32-bit windows rust target. Run `rustup target add stable-i686-pc-windows-msvc`
- Visual Studio 2012 Command Prompt. Should be available if you install Visual Studio 2013. [Available here](https://visualstudio.microsoft.com/vs/older-downloads/)
- Building:
- From VS2012 Command Prompt, run `cargo +stable-i686-pc-windows-msvc build`
- Running:
- From VS2012 Command Prompt, run `cargo +stable-i686-pc-windows-msvc run`
Binary file modified SimConnect.dll
Binary file not shown.
Binary file added SimConnect.dll.64bit
Binary file not shown.
6 changes: 5 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ use std::{env, path::PathBuf};

fn main() {
println!("cargo:rustc-link-search=libsrc/lib");
println!("cargo:rustc-link-lib=static=ltod");
println!("cargo:rustc-link-lib=static=SimConnect");
println!("cargo:rustc-link-lib=static=user32");
println!("cargo:rustc-link-lib=static=ole32");
println!("cargo:rustc-link-lib=static=shell32");

let bindings = bindgen::Builder::default()
.header("libsrc/include/SimConnect.hpp")
Expand Down Expand Up @@ -203,4 +207,4 @@ fn main() {
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
}
Binary file modified libsrc/lib/SimConnect.lib
Binary file not shown.
Binary file added libsrc/lib/SimConnect.lib.64bit
Binary file not shown.
Binary file added libsrc/lib/ltod.lib
Binary file not shown.
Binary file added libsrc/lib/ole32.lib
Binary file not shown.
Binary file added libsrc/lib/shell32.lib
Binary file not shown.
Binary file added libsrc/lib/user32.lib
Binary file not shown.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,4 +482,4 @@ impl Drop for SimConnector {
self.close();
}
}
}
}
41 changes: 41 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use simconnect;
use std::time::Duration;
use std::thread::sleep;
use std::mem::transmute_copy;

struct DataStruct {
lat: f64,
lon: f64,
alt: f64,
}

pub fn main() {
let mut conn = simconnect::SimConnector::new();
conn.connect("Simple Program"); // Intialize connection with SimConnect
conn.add_data_definition(0, "PLANE LATITUDE", "Degrees", simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64, u32::MAX); // Assign a sim variable to a client defined id
conn.add_data_definition(0, "PLANE LONGITUDE", "Degrees", simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64, u32::MAX);
conn.add_data_definition(0, "PLANE ALTITUDE", "Feet", simconnect::SIMCONNECT_DATATYPE_SIMCONNECT_DATATYPE_FLOAT64, u32::MAX); //define_id, units, data_type, datum_id
conn.request_data_on_sim_object(0, 0, 0, simconnect::SIMCONNECT_PERIOD_SIMCONNECT_PERIOD_SIM_FRAME, 0, 0, 0, 0); //request_id, define_id, object_id (user), period, falgs, origin, interval, limit - tells simconnect to send data for the defined id and on the user aircraft

loop {
match conn.get_next_message() {
Ok(simconnect::DispatchResult::SimobjectData(data)) => {
unsafe {
match data.dwDefineID {
0 => {
let sim_data: DataStruct = transmute_copy(&data.dwData);
println!("{:?} {:?} {:?}", sim_data.lat, sim_data.lon, sim_data.alt);
},
_ => ()
}
}
},
Err(e) => {
eprintln!("Error was received: {}", e);
},
_ => ()
}

sleep(Duration::from_millis(16)); // Will use up lots of CPU if this is not included, as get_next_message() is non-blocking
}
}