Skip to content

Commit

Permalink
feat(a380x/fms): nav db swap to reset fms (flybywiresim#8950)
Browse files Browse the repository at this point in the history
* fix(a380x/fms): nav database effectivity

* feat(a380x/fms): nav database swap
  • Loading branch information
tracernz authored Oct 4, 2024
1 parent cc6b696 commit 9415799
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -995,4 +995,15 @@ export class FlightManagementComputer implements FmcInterface {
tryGoInApproachPhase(): void {
this.flightPhaseManager.tryGoInApproachPhase();
}

async swapNavDatabase(): Promise<void> {
// FIXME reset ATSU when it is added to A380X
// this.atsu.resetAtisAutoUpdate();
await this.flightPlanService.reset();
this.initSimVars();
this.deleteAllStoredWaypoints();
this.clearLatestFmsErrorMessage();
this.mfdReference?.uiService.navigateTo('fms/data/status');
this.navigation.resetState();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ export interface FmcInterface extends FlightPhaseManagerProxyInterface, DataInte
*/
deleteAllStoredWaypoints(): void;

swapNavDatabase(): Promise<void>;

/** in kilograms */
getLandingWeight(): number | null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: GPL-3.0

import { ClockEvents, FSComponent, Subject, VNode } from '@microsoft/msfs-sdk';

import './MfdFmsDataStatus.scss';
import { AbstractMfdPageProps } from 'instruments/src/MFD/MFD';
import { Footer } from 'instruments/src/MFD/pages/common/Footer';

Expand All @@ -13,20 +11,36 @@ import { TopTabNavigator, TopTabNavigatorPage } from 'instruments/src/MFD/pages/
import { Button } from 'instruments/src/MFD/pages/common/Button';
import { AirlineModifiableInformation } from '@shared/AirlineModifiableInformation';
import { NavigationDatabaseService } from '@fmgc/index';
import { DatabaseIdent } from '@flybywiresim/fbw-sdk';
import { ConfirmationDialog } from '../../common/ConfirmationDialog';

import './MfdFmsDataStatus.scss';

interface MfdFmsDataStatusProps extends AbstractMfdPageProps {}

const months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
const monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
const DB_MONTHS: Record<string, string> = {
'01': 'JAN',
'02': 'FEB',
'03': 'MAR',
'04': 'APR',
'05': 'MAY',
'06': 'JUN',
'07': 'JUL',
'08': 'AUG',
'09': 'SEP',
'10': 'OCT',
'11': 'NOV',
'12': 'DEC',
};

export class MfdFmsDataStatus extends FmsPage<MfdFmsDataStatusProps> {
private selectedPageIndex = Subject.create<number>(0);

private navDatabase = Subject.create('FBW2301001');
private navDatabase = Subject.create('');

private activeDatabase = Subject.create('30DEC-27JAN');
private activeDatabase = Subject.create('');

private secondDatabase = Subject.create('27JAN-24FEB');
private secondDatabase = Subject.create('');

private storedWaypoints = Subject.create('00');

Expand All @@ -38,18 +52,19 @@ export class MfdFmsDataStatus extends FmsPage<MfdFmsDataStatusProps> {

private deleteStoredElementsDisabled = Subject.create(true);

private readonly isSwapConfirmVisible = Subject.create(false);

protected onNewData() {
NavigationDatabaseService.activeDatabase.getDatabaseIdent().then((db) => {
const from = new Date(db.effectiveFrom);
const to = new Date(db.effectiveTo);
this.activeDatabase.set(`${from.getDay()}${months[from.getMonth()]}-${to.getDay()}${months[to.getMonth()]}`);
NavigationDatabaseService.activeDatabase.getDatabaseIdent().then((dbCycle) => {
const navCycleDates = dbCycle === null ? '' : MfdFmsDataStatus.calculateActiveDate(dbCycle);
const navSerial =
dbCycle === null ? '' : `${dbCycle.provider.substring(0, 2).toUpperCase()}${dbCycle.airacCycle}0001`;

this.activeDatabase.set(navCycleDates);
this.secondDatabase.set(navCycleDates);
this.navDatabase.set(navSerial);
});

const date = this.props.fmcService.master?.fmgc.getNavDataDateRange();
if (date) {
this.secondDatabase.set(this.calculateSecDate(date));
}

const storedElements = this.props.fmcService.master?.getDataManager()?.numberOfStoredElements();
if (storedElements) {
this.storedWaypoints.set(storedElements.waypoints.toFixed(0).padStart(2, '0'));
Expand Down Expand Up @@ -84,63 +99,13 @@ export class MfdFmsDataStatus extends FmsPage<MfdFmsDataStatusProps> {
);
}

private findNewMonthIndex(index: number) {
if (index === 0) {
return 11;
}
return index - 1;
}

private lessThan10(num: number) {
if (num < 10) {
return `0${num}`;
}
return num;
}

private calculateActiveDate(date: string): string {
if (date.length === 13) {
const startMonth = date.slice(0, 3);
const startDay = date.slice(3, 5);

const endMonth = date.slice(5, 8);
const endDay = date.slice(8, 10);

return `${startDay}${startMonth}-${endDay}${endMonth}`;
}
return date;
}

private calculateSecDate(date: string): string {
if (date.length === 13) {
const primStartMonth = date.slice(0, 3);
const primStartDay = Number(date.slice(3, 5));

const primStartMonthIndex = months.findIndex((item) => item === primStartMonth);

if (primStartMonthIndex === -1) {
return 'ERR';
}

let newEndMonth = primStartMonth;
let newEndDay = primStartDay - 1;
private static calculateActiveDate(dbIdent: DatabaseIdent): string {
const effDay = dbIdent.effectiveFrom.substring(8);
const effMonth = dbIdent.effectiveFrom.substring(5, 7);
const expDay = dbIdent.effectiveTo.substring(8);
const expMonth = dbIdent.effectiveTo.substring(5, 7);

let newStartDay = newEndDay - 27;
let newStartMonth = primStartMonth;

if (newEndDay === 0) {
newEndMonth = months[this.findNewMonthIndex(primStartMonthIndex)];
newEndDay = monthLength[this.findNewMonthIndex(primStartMonthIndex)];
}

if (newStartDay <= 0) {
newStartMonth = months[this.findNewMonthIndex(primStartMonthIndex)];
newStartDay = monthLength[this.findNewMonthIndex(primStartMonthIndex)] + newStartDay;
}

return `${this.lessThan10(newStartDay)}${newStartMonth}-${this.lessThan10(newEndDay)}${newEndMonth}`;
}
return 'ERR';
return `${effDay}${DB_MONTHS[effMonth]}-${expDay}${DB_MONTHS[expMonth]}`;
}

render(): VNode {
Expand All @@ -152,7 +117,10 @@ export class MfdFmsDataStatus extends FmsPage<MfdFmsDataStatusProps> {
<TopTabNavigator
pageTitles={Subject.create(['ACFT STATUS', 'FMS P/N'])}
selectedPageIndex={this.selectedPageIndex}
pageChangeCallback={(val) => this.selectedPageIndex.set(val)}
pageChangeCallback={(val) => {
this.selectedPageIndex.set(val);
this.isSwapConfirmVisible.set(false);
}}
selectedTabTextColor="white"
tabBarSlantedEdgeAngle={25}
>
Expand Down Expand Up @@ -196,6 +164,21 @@ export class MfdFmsDataStatus extends FmsPage<MfdFmsDataStatusProps> {
</div>
</div>
<div class="mfd-data-status-second-section">
<div style="position: relative; display: flex; justify-content: center; width: 100%;">
<ConfirmationDialog
visible={this.isSwapConfirmVisible}
cancelAction={() => {
this.isSwapConfirmVisible.set(false);
}}
confirmAction={() => {
this.props.fmcService.master?.swapNavDatabase();
this.isSwapConfirmVisible.set(false);
}}
contentContainerStyle="width: 325px; height: 165px; transform: translateX(-50%);"
>
SWAP&nbsp;?
</ConfirmationDialog>
</div>
<div style="margin-bottom: 15px;">
<span class="mfd-label" style="margin-right: 25px;">
NAV DATABASE
Expand All @@ -221,8 +204,7 @@ export class MfdFmsDataStatus extends FmsPage<MfdFmsDataStatusProps> {
<span style="display: flex; align-items: center; justify-content: center;">*</span>
</div>,
)}
onClick={() => {}}
disabled={Subject.create(true)}
onClick={() => this.isSwapConfirmVisible.set(true)}
/>
</div>
<div style="padding: 15px; display: flex; flex-direction: column;">
Expand Down

0 comments on commit 9415799

Please sign in to comment.