Skip to content

Commit

Permalink
feat(fdr): add FMGCs to FDR
Browse files Browse the repository at this point in the history
  • Loading branch information
lukecologne authored and aguther committed Jul 31, 2024
1 parent 8b9b1ea commit 472d86c
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 17 deletions.
18 changes: 17 additions & 1 deletion fbw-a32nx/src/wasm/fbw_a320/src/FlightDataRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ void FlightDataRecorder::initialize() {
std::cout << "WASM: Flight Data Recorder Configuration : Interface Version = " << INTERFACE_VERSION << std::endl;
}

void FlightDataRecorder::update(const EngineData& engineData, const AdditionalData& additionalData) {
void FlightDataRecorder::update(const EngineData& engineData,
const AdditionalData& additionalData,
const fmgc_outputs& fmgc1,
const fmgc_outputs& fmgc2) {
// check if enabled
if (!isEnabled) {
return;
Expand All @@ -49,6 +52,19 @@ void FlightDataRecorder::update(const EngineData& engineData, const AdditionalDa
// write data to file
fileStream->write((char*)(&engineData), sizeof(engineData));
fileStream->write((char*)(&additionalData), sizeof(additionalData));
writeFmgc(fmgc1);
writeFmgc(fmgc2);
}

void FlightDataRecorder::writeFmgc(const fmgc_outputs& fmgc) {
std::cout << std::format("Test {}: {}\n", "Sus", &fmgc);

fileStream->write((char*)(&fmgc.logic), sizeof(fmgc.logic));
fileStream->write((char*)(&fmgc.ap_fd_logic), sizeof(fmgc.ap_fd_logic));
fileStream->write((char*)(&fmgc.ap_fd_outer_loops), sizeof(fmgc.ap_fd_outer_loops));
fileStream->write((char*)(&fmgc.athr), sizeof(fmgc.athr));
fileStream->write((char*)(&fmgc.discrete_outputs), sizeof(fmgc.discrete_outputs));
fileStream->write((char*)(&fmgc.bus_outputs), sizeof(fmgc.bus_outputs));
}

void FlightDataRecorder::terminate() {
Expand Down
7 changes: 5 additions & 2 deletions fbw-a32nx/src/wasm/fbw_a320/src/FlightDataRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

#include "AdditionalData.h"
#include "EngineData.h"
#include "FmgcComputer_types.h"
#include "zfstream.h"

class FlightDataRecorder {
public:
// IMPORTANT: this constant needs to increased with every interface change
const uint64_t INTERFACE_VERSION = 25;
const uint64_t INTERFACE_VERSION = 26;

void initialize();

void update(const EngineData& engineData, const AdditionalData& additionalData);
void update(const EngineData& engineData, const AdditionalData& additionalData, const fmgc_outputs& fmgc1, const fmgc_outputs& fmgc2);

void terminate();

Expand All @@ -31,4 +32,6 @@ class FlightDataRecorder {
std::string getFlightDataRecorderFilename();

void cleanUpFlightDataRecorderFiles();

void writeFmgc(const fmgc_outputs& fmgc);
};
2 changes: 1 addition & 1 deletion fbw-a32nx/src/wasm/fbw_a320/src/FlyByWireInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ bool FlyByWireInterface::update(double sampleTime) {
// do not further process when active pause is on
if (!simConnectInterface.isSimInActivePause()) {
// update flight data recorder
flightDataRecorder.update(engineData, additionalData);
flightDataRecorder.update(engineData, additionalData, fmgcs[0].getDebugOutputs(), fmgcs[1].getDebugOutputs());
}

// if default AP is on -> disconnect it
Expand Down
4 changes: 4 additions & 0 deletions fbw-a32nx/src/wasm/fbw_a320/src/fmgc/Fmgc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,7 @@ base_fmgc_bus_outputs Fmgc::getBusOutputs() {

return output;
}

const fmgc_outputs& Fmgc::getDebugOutputs() const {
return fmgcComputer.getExternalOutputs().out;
}
2 changes: 2 additions & 0 deletions fbw-a32nx/src/wasm/fbw_a320/src/fmgc/Fmgc.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Fmgc {

base_fmgc_discrete_outputs getDiscreteOutputs();

const fmgc_outputs& getDebugOutputs() const;

FmgcComputer::ExternalInputs_FmgcComputer_T modelInputs = {};

private:
Expand Down
39 changes: 30 additions & 9 deletions tools/fdr2csv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use bytemuck::AnyBitPattern;
use clap::Parser;
use csv::WriterBuilder;
use flate2::bufread::GzDecoder;
use headers::{ap_raw_output, ap_sm_output, athr_out, AdditionalData, EngineData};
use headers::{
ap_raw_output, base_fmgc_ap_fd_logic_outputs, base_fmgc_athr_outputs, base_fmgc_bus_outputs,
base_fmgc_discrete_outputs, base_fmgc_logic_outputs, AdditionalData, EngineData,
};
use serde::Serialize;
use std::{
fs::{File, OpenOptions},
Expand Down Expand Up @@ -37,7 +40,7 @@ struct Args {
get_input_file_version: bool,
}

const INTERFACE_VERSION: u64 = 25;
const INTERFACE_VERSION: u64 = 26;

// Read number of bytes specified by the size of T from the binary file
fn read_bytes<T: AnyBitPattern>(reader: &mut impl Read) -> Result<T, Error> {
Expand All @@ -58,21 +61,39 @@ fn read_bytes<T: AnyBitPattern>(reader: &mut impl Read) -> Result<T, Error> {
// A single FDR record
#[derive(Serialize, Default)]
struct FdrData {
ap_sm: ap_sm_output,
ap_law: ap_raw_output,
athr: athr_out,
engine: EngineData,
data: AdditionalData,
fmgc1_data: FmgcData,
fmgc2_data: FmgcData,
}

#[derive(Serialize, Default)]
struct FmgcData {
logic: base_fmgc_logic_outputs,
ap_fd_logic: base_fmgc_ap_fd_logic_outputs,
ap_fd_outer_loops: ap_raw_output,
athr: base_fmgc_athr_outputs,
discrete_outputs: base_fmgc_discrete_outputs,
bus_outputs: base_fmgc_bus_outputs,
}

// These are helper functions to read in a whole FDR record.
fn read_record(reader: &mut impl Read) -> Result<FdrData, Error> {
Ok(FdrData {
ap_sm: read_bytes::<ap_sm_output>(reader)?,
ap_law: read_bytes::<ap_raw_output>(reader)?,
athr: read_bytes::<athr_out>(reader)?,
engine: read_bytes::<EngineData>(reader)?,
data: read_bytes::<AdditionalData>(reader)?,
fmgc1_data: read_fmgc(reader)?,
fmgc2_data: read_fmgc(reader)?,
})
}

fn read_fmgc(reader: &mut impl Read) -> Result<FmgcData, Error> {
Ok(FmgcData {
logic: read_bytes::<base_fmgc_logic_outputs>(reader)?,
ap_fd_logic: read_bytes::<base_fmgc_ap_fd_logic_outputs>(reader)?,
ap_fd_outer_loops: read_bytes::<ap_raw_output>(reader)?,
athr: read_bytes::<base_fmgc_athr_outputs>(reader)?,
discrete_outputs: read_bytes::<base_fmgc_discrete_outputs>(reader)?,
bus_outputs: read_bytes::<base_fmgc_bus_outputs>(reader)?,
})
}

Expand Down
6 changes: 2 additions & 4 deletions tools/fdr2csv/wrapper.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "../../fbw-a32nx/src/wasm/fbw_a320/src/EngineData.h"
#include "../../fbw-a32nx/src/wasm/fbw_a320/src/AdditionalData.h"
#include "../../fbw-a32nx/src/wasm/fbw_a320/src/model/AutopilotLaws_types.h"
#include "../../fbw-a32nx/src/wasm/fbw_a320/src/model/AutopilotStateMachine_types.h"
#include "../../fbw-a32nx/src/wasm/fbw_a320/src/model/Autothrust_types.h"
#include "../../fbw-a32nx/src/wasm/fbw_a320/src/EngineData.h"
#include "../../fbw-a32nx/src/wasm/fbw_a320/src/model/FmgcComputer_types.h"

0 comments on commit 472d86c

Please sign in to comment.