Read telemetry
This commit is contained in:
parent
7e334b81ac
commit
dc729b3f10
1 changed files with 25 additions and 25 deletions
50
src/lib.rs
50
src/lib.rs
|
@ -1,36 +1,36 @@
|
||||||
|
mod additional_rfactor;
|
||||||
#[allow(warnings)]
|
#[allow(warnings)]
|
||||||
mod rfactor_structs;
|
mod rfactor_structs;
|
||||||
|
|
||||||
use std::{fs::File, path::Path};
|
use std::{fs::File, path::Path};
|
||||||
|
|
||||||
|
use additional_rfactor::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use memmap2::Mmap;
|
use memmap2::Mmap;
|
||||||
|
use rfactor_structs::TelemInfoV01;
|
||||||
const MM_TELEMETRY_FILE_NAME: &str = "$rFactor2SMMP_Telemetry$";
|
|
||||||
const MM_SCORING_FILE_NAME: &str = "$rFactor2SMMP_Scoring$";
|
|
||||||
const MM_RULES_FILE_NAME: &str = "$rFactor2SMMP_Rules$";
|
|
||||||
const MM_FORCE_FEEDBACK_FILE_NAME: &str = "$rFactor2SMMP_ForceFeedback$";
|
|
||||||
const MM_GRAPHICS_FILE_NAME: &str = "$rFactor2SMMP_Graphics$";
|
|
||||||
const MM_PITINFO_FILE_NAME: &str = "$rFactor2SMMP_PitInfo$";
|
|
||||||
const MM_WEATHER_FILE_NAME: &str = "$rFactor2SMMP_Weather$";
|
|
||||||
const MM_EXTENDED_FILE_NAME: &str = "$rFactor2SMMP_Extended$";
|
|
||||||
|
|
||||||
const MM_HWCONTROL_FILE_NAME: &str = "$rFactor2SMMP_HWControl$";
|
|
||||||
const MM_HWCONTROL_LAYOUT_VERSION: u32 = 1;
|
|
||||||
|
|
||||||
const MM_WEATHER_CONTROL_FILE_NAME: &str = "$rFactor2SMMP_WeatherControl$";
|
|
||||||
const MM_WEATHER_CONTROL_LAYOUT_VERSION: u32 = 1;
|
|
||||||
|
|
||||||
const MM_RULES_CONTROL_FILE_NAME: &str = "$rFactor2SMMP_RulesControl$";
|
|
||||||
const MM_RULES_CONTROL_LAYOUT_VERSION: u32 = 1;
|
|
||||||
|
|
||||||
const MM_PLUGIN_CONTROL_FILE_NAME: &str = "$rFactor2SMMP_PluginControl$";
|
|
||||||
|
|
||||||
const RFACTOR_SHM_FILE: &str = "/dev/shm";
|
const RFACTOR_SHM_FILE: &str = "/dev/shm";
|
||||||
|
|
||||||
pub fn test_read() -> Result<()> {
|
pub struct TelemetryReader {
|
||||||
let file = File::open(Path::new(RFACTOR_SHM_FILE).join(MM_TELEMETRY_FILE_NAME))?;
|
_telemetry_file: File,
|
||||||
let mmap = unsafe { Mmap::map(&file)? };
|
shm: Mmap,
|
||||||
|
}
|
||||||
Ok(())
|
|
||||||
|
impl TelemetryReader {
|
||||||
|
pub fn new() -> Result<Self> {
|
||||||
|
let file = File::open(Path::new(RFACTOR_SHM_FILE).join(MM_TELEMETRY_FILE_NAME))?;
|
||||||
|
let mmap = unsafe { Mmap::map(&file)? };
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
_telemetry_file: file,
|
||||||
|
shm: mmap,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn query_telemetry(&self) -> Result<Vec<TelemInfoV01>> {
|
||||||
|
let telemetry = rF2Telemetry::try_from(&self.shm[0..rF2Telemetry::SIZE])?;
|
||||||
|
let vehicles = telemetry.vehicles();
|
||||||
|
|
||||||
|
Ok(vehicles.to_vec())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue