Skip to content

Commit

Permalink
feat(a380x/mfd): generate tmpy on spd lim change
Browse files Browse the repository at this point in the history
  • Loading branch information
BravoMike99 committed Feb 12, 2025
1 parent 838c7ab commit c9b8974
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import { FlightPlan } from '@fmgc/flightplanning/plans/FlightPlan';
import { FlightPlanIndex } from '@fmgc/flightplanning/FlightPlanManager';
import { AltitudeConstraint } from '@fmgc/flightplanning/data/constraint';
import { ReadonlyFlightPlan } from '@fmgc/flightplanning/plans/ReadonlyFlightPlan';
import { FlightPlanPerformanceData } from '@fmgc/flightplanning/plans/performance/FlightPlanPerformanceData';
import {
FlightPlanPerformanceData,
SpeedLimitType,
} from '@fmgc/flightplanning/plans/performance/FlightPlanPerformanceData';
import { FlightPlanLeg } from '@fmgc/flightplanning/legs/FlightPlanLeg';

/**
Expand Down Expand Up @@ -300,6 +303,22 @@ export interface FlightPlanInterface<P extends FlightPlanPerformanceData = Fligh
planIndex: number,
): Promise<void>;

setPilotEntrySpeedLimitAltitude(
type: SpeedLimitType,
value: number,
planIndex: FlightPlanIndex,
alternate: boolean,
): void;

setPilotEntrySpeedLimitSpeed(
type: SpeedLimitType,
value: number,
planIndex: FlightPlanIndex,
alternate: boolean,
): void;

deleteSpeedLimit(type: SpeedLimitType, planIndex: FlightPlanIndex, alternate: boolean): void;

// TODO do not pass in waypoint object (rpc)
isWaypointInUse(waypoint: Waypoint): Promise<boolean>;

Expand Down
108 changes: 107 additions & 1 deletion fbw-a32nx/src/systems/fmgc/src/flightplanning/FlightPlanService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import { FlightPlanLegDefinition } from '@fmgc/flightplanning/legs/FlightPlanLeg
import { FlightPlanInterface } from '@fmgc/flightplanning/FlightPlanInterface';
import { AltitudeConstraint } from '@fmgc/flightplanning/data/constraint';
import { CopyOptions } from '@fmgc/flightplanning/plans/CloningOptions';
import { FlightPlanPerformanceData } from '@fmgc/flightplanning/plans/performance/FlightPlanPerformanceData';
import {
DefaultPerformanceData,
FlightPlanPerformanceData,
SpeedLimitType,
} from '@fmgc/flightplanning/plans/performance/FlightPlanPerformanceData';

export class FlightPlanService<P extends FlightPlanPerformanceData = FlightPlanPerformanceData>
implements FlightPlanInterface<P>
Expand Down Expand Up @@ -574,6 +578,108 @@ export class FlightPlanService<P extends FlightPlanPerformanceData = FlightPlanP
plan.editFixInfoEntry(index, callback);
}

async setPilotEntrySpeedLimitAltitude(
type: SpeedLimitType,
value: number,
planIndex = FlightPlanIndex.Active,
alternate = false,
) {
const finalIndex = this.config.TMPY_ON_CONSTRAINT_EDIT ? this.prepareDestructiveModification(planIndex) : planIndex;

const plan = this.flightPlanManager.get(finalIndex);

const performanceDataSpeedKey = this.getSpeedLimitPerformanceDataKey(type, alternate);

if (plan.performanceData[performanceDataSpeedKey] === null) {
plan.setPerformanceData(
performanceDataSpeedKey,
type === SpeedLimitType.CLB
? DefaultPerformanceData.ClimbSpeedLimitSpeed
: DefaultPerformanceData.DescentSpeedLimitSpeed,
);
}

plan.setPerformanceData(this.getSpeedLimitAltitudePerformanceDataKey(type, alternate), value);
plan.setPerformanceData(this.getSpeedLimitPilotEntryPerformanceDataKey(type, alternate), true);

plan.incrementVersion();
}

async setPilotEntrySpeedLimitSpeed(
type: SpeedLimitType,
value: number,
planIndex = FlightPlanIndex.Active,
alternate = false,
) {
const finalIndex = this.config.TMPY_ON_CONSTRAINT_EDIT ? this.prepareDestructiveModification(planIndex) : planIndex;

const plan = this.flightPlanManager.get(finalIndex);

const performanceDataAltitudeKey = this.getSpeedLimitAltitudePerformanceDataKey(type, alternate);

if (plan.performanceData[performanceDataAltitudeKey] === null) {
plan.setPerformanceData(
performanceDataAltitudeKey,
type === SpeedLimitType.CLB
? DefaultPerformanceData.ClimbSpeedLimitAltitude
: DefaultPerformanceData.DescentSpeedLimitAltitude,
);
}

plan.setPerformanceData(this.getSpeedLimitPerformanceDataKey(type, alternate), value);
plan.setPerformanceData(this.getSpeedLimitPilotEntryPerformanceDataKey(type, alternate), true);

plan.incrementVersion();
}

async deleteSpeedLimit(type: SpeedLimitType, planIndex = FlightPlanIndex.Active, alternate = false) {
const finalIndex = this.config.TMPY_ON_CONSTRAINT_EDIT ? this.prepareDestructiveModification(planIndex) : planIndex;

const plan = this.flightPlanManager.get(finalIndex);

const speedLimitSpeedKey = this.getSpeedLimitPerformanceDataKey(type, alternate);

const altitudeSpeedLimitKey = this.getSpeedLimitAltitudePerformanceDataKey(type, alternate);

const pilotEnteredKey = this.getSpeedLimitPilotEntryPerformanceDataKey(type, alternate);

plan.setPerformanceData(speedLimitSpeedKey, null);
plan.setPerformanceData(altitudeSpeedLimitKey, null);
plan.setPerformanceData(pilotEnteredKey, null);

plan.incrementVersion();
}

private getSpeedLimitPerformanceDataKey(type: SpeedLimitType, alternate: boolean) {
return type === SpeedLimitType.CLB
? alternate
? 'alternateClimbSpeedLimitSpeed'
: 'climbSpeedLimitSpeed'
: alternate
? 'alternateDescentSpeedLimitSpeed'
: 'descentSpeedLimitSpeed';
}

private getSpeedLimitAltitudePerformanceDataKey(type: SpeedLimitType, alternate: boolean) {
return type === SpeedLimitType.CLB
? alternate
? 'alternateClimbSpeedLimitAltitude'
: 'climbSpeedLimitAltitude'
: alternate
? 'alternateDescentSpeedLimitAltitude'
: 'descentSpeedLimitAltitude';
}

private getSpeedLimitPilotEntryPerformanceDataKey(type: SpeedLimitType, alternate: boolean) {
return type === SpeedLimitType.CLB
? alternate
? 'isAlternateClimbSpeedLimitPilotEntered'
: 'isClimbSpeedLimitPilotEntered'
: alternate
? 'isAlternateDescentSpeedLimitPilotEntered'
: 'isDescentSpeedLimitPilotEntered';
}

get activeLegIndex(): number {
return this.active.activeLegIndex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,8 @@ export class DefaultPerformanceData {

static readonly DescentSpeedLimitAltitude = 10_000;
}

export enum SpeedLimitType {
CLB,
DES,
}
1 change: 0 additions & 1 deletion fbw-a380x/src/systems/instruments/src/MFD/FMC/fmgc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { Arinc429Word, Runway, Units } from '@flybywiresim/fbw-sdk';
import { Feet } from 'msfs-geo';
import { AirlineModifiableInformation } from '@shared/AirlineModifiableInformation';
import { minGw } from '@shared/PerformanceConstants';
import { DefaultPerformanceData } from '@fmgc/flightplanning/plans/performance/FlightPlanPerformanceData';

export enum TakeoffPowerSetting {
TOGA = 0,
Expand Down
Loading

0 comments on commit c9b8974

Please sign in to comment.