Skip to content

Commit

Permalink
fix(fms): fix uplink crash for airway terminations not on airways (#8704
Browse files Browse the repository at this point in the history
)

* Fix uplink crash

* Cancel airway entry

* Match `CoRouteUplinkAdapter` to `SimBriefUplinkAdapter`

---------

Co-authored-by: alepouna <98479040+alepouna@users.noreply.github.com>
  • Loading branch information
BlueberryKing and alepouna committed Jul 10, 2024
1 parent de2903c commit 2cdf866
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,11 @@ export abstract class BaseFlightPlan<P extends FlightPlanPerformanceData = Fligh
segment.insertAfter(indexInSegment, { isDiscontinuity: true });

this.incrementVersion();

// Make sure we don't have a TF leg after the disco
this.adjustIFLegs();

this.incrementVersion();
}

editLegDefinition(index: number, changes: Partial<FlightPlanLegDefinition>, notify = true): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,48 @@ export class CoRouteUplinkAdapter {
fixes.length > 1 ? pickFix(fixes, chunk.locationHint) : fixes[0],
FlightPlanIndex.Uplink,
);
await flightPlanService.insertDiscontinuityAfter(insertHead, FlightPlanIndex.Uplink);

insertHead += 2;
if (plan.elementAt(insertHead).isDiscontinuity === false) {
// It's possible we already have a disco here, if the start of the airway was not found
await flightPlanService.insertDiscontinuityAfter(insertHead, FlightPlanIndex.Uplink);
insertHead++;
}

insertHead++;
break;
}

const tailAirway = plan.pendingAirways.elements[plan.pendingAirways.elements.length - 1].airway;

plan.pendingAirways.thenTo(pickAirwayFix(tailAirway, fixes));
const airwayFix = pickAirwayFix(tailAirway, fixes);
if (airwayFix) {
plan.pendingAirways.thenTo(airwayFix);

ensureAirwaysFinalized();
} else {
// Fixes with the name of the airway termination are found but they're not on that airway
console.warn(
`[CoRouteUplinkAdapter](uplinkFlightPlanFromCoRoute) Airway termination ${chunk.ident} not found on airway ${tailAirway.ident}.`,
);

// We cancel the airway entry and add the termination as a fix
plan.pendingAirways = undefined;

await flightPlanService.nextWaypoint(
insertHead,
fixes.length > 1 ? pickFix(fixes, chunk.locationHint) : fixes[0],
FlightPlanIndex.Uplink,
);

ensureAirwaysFinalized();
if (plan.elementAt(insertHead).isDiscontinuity === false) {
// It's possible we already have a disco here, if the start of the airway was not found
await flightPlanService.insertDiscontinuityAfter(insertHead, FlightPlanIndex.Uplink);
insertHead++;
}

insertHead++;
break;
}
} else {
console.warn(
`[CoRouteUplinkAdapter](uplinkFlightPlanFromCoRoute) Found no fixes for "airwayTermination" chunk: ${chunk.ident}. Cancelling airway entry...`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,12 @@ export class SimBriefUplinkAdapter {

if (fixes.length > 0) {
if (!plan.pendingAirways) {
// If we have a termination but never started an airway entry (for example if we could not find the airway in the database),
// we add the termination fix with a disco in between
console.warn(
`[SimBriefUplinkAdapter](uplinkFlightPlanFromSimbrief) Found no pending airways for "airwayTermination" chunk.`,
`[SimBriefUplinkAdapter](uplinkFlightPlanFromSimbrief) Found no pending airways for "airwayTermination" chunk. Inserting discontinuity before ${chunk.ident}`,
);

// If we have a termination but never started an airway entry (for example if we could not find the airway in the database),
// just add the termination as a fix
await flightPlanService.nextWaypoint(
insertHead,
fixes.length > 1 ? pickFix(fixes, chunk.locationHint) : fixes[0],
Expand All @@ -420,9 +420,35 @@ export class SimBriefUplinkAdapter {

const tailAirway = plan.pendingAirways.elements[plan.pendingAirways.elements.length - 1].airway;

plan.pendingAirways.thenTo(pickAirwayFix(tailAirway, fixes));
const airwayFix = pickAirwayFix(tailAirway, fixes);
if (airwayFix) {
plan.pendingAirways.thenTo(airwayFix);

ensureAirwaysFinalized();
} else {
// Fixes with the name of the airway termination are found but they're not on that airway
console.warn(
`[SimBriefUplinkAdapter](uplinkFlightPlanFromSimbrief) Airway termination ${chunk.ident} not found on airway ${tailAirway.ident}.`,
);

// We cancel the airway entry and add the termination as a fix
plan.pendingAirways = undefined;

ensureAirwaysFinalized();
await flightPlanService.nextWaypoint(
insertHead,
fixes.length > 1 ? pickFix(fixes, chunk.locationHint) : fixes[0],
FlightPlanIndex.Uplink,
);

if (plan.elementAt(insertHead).isDiscontinuity === false) {
// It's possible we already have a disco here, if the start of the airway was not found
await flightPlanService.insertDiscontinuityAfter(insertHead, FlightPlanIndex.Uplink);
insertHead++;
}

insertHead++;
break;
}
} else {
console.warn(
`[SimBriefUplinkAdapter](uplinkFlightPlanFromSimbrief) Found no fixes for "airwayTermination" chunk: ${chunk.ident}. Cancelling airway entry...`,
Expand Down

0 comments on commit 2cdf866

Please sign in to comment.