Skip to content

Request Facility Data#39

Draft
joriskleiber wants to merge 2 commits intoflybywiresim:mainfrom
joriskleiber:dev
Draft

Request Facility Data#39
joriskleiber wants to merge 2 commits intoflybywiresim:mainfrom
joriskleiber:dev

Conversation

@joriskleiber
Copy link

This adds the functionality to request airport data as follows:

#[facility_definition("AIRPORT")]
struct AirportData {
    #[name = "N_JETWAYS"]
     jetway_count: i32,
     #[name = "N_RUNWAYS"]
     runway_count: i32,
     #[child_facility]
     taxi_paths: Vec<TaxiPathData>,
 }

 #[facility_definition("TAXI_PATH")]
 #[derive(Debug, Clone)]
 struct TaxiPathData {
     #[name = "TYPE"]
     taxiway_type: i32,
}
 
sim.add_facility_definition::<AirportData>();

let mut data: HashMap<SIMCONNECT_DATA_REQUEST_ID, AirportData> = HashMap::new();

...
     SimConnectRecv::FacilityData(e) => {
          let user_request_id = SIMCONNECT_DATA_REQUEST_ID(e.UserRequestId);
          let data_type: SIMCONNECT_FACILITY_DATA_TYPE = unsafe { mem::transmute(e.Type) };

          match data_type {
               SIMCONNECT_FACILITY_DATA_TYPE::SIMCONNECT_FACILITY_DATA_AIRPORT => {
                    let airport_data = e.into::<AirportData>(&simconnect).unwrap();
                    data.insert(user_request_id, airport_data);
               }

               SIMCONNECT_FACILITY_DATA_TYPE::SIMCONNECT_FACILITY_DATA_TAXI_PATH => {
                    let taxi_path = e.into::<TaxiPathData>(&simconnect).unwrap();

                    if let Some(airport) = data.get_mut(&user_request_id) {
                         airport.taxi_paths.push(taxi_path.clone());
                    }
               }    
 ...

Remaining tasks:

  • Ensure that each child_facility has a unique type.
  • Fix correct type checking for into().
  • Add example.

I will complete the remaining tasks on this draft when it is likely that this PR will be merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant