diff --git a/fbw-a32nx/src/systems/fmgc/src/flightplanning/new/plans/BaseFlightPlan.ts b/fbw-a32nx/src/systems/fmgc/src/flightplanning/new/plans/BaseFlightPlan.ts index 1800f30a311..9bf75a807c0 100644 --- a/fbw-a32nx/src/systems/fmgc/src/flightplanning/new/plans/BaseFlightPlan.ts +++ b/fbw-a32nx/src/systems/fmgc/src/flightplanning/new/plans/BaseFlightPlan.ts @@ -1365,6 +1365,11 @@ export abstract class BaseFlightPlan

, notify = true): void { diff --git a/fbw-a32nx/src/systems/fmgc/src/flightplanning/new/uplink/CoRouteUplinkAdapter.ts b/fbw-a32nx/src/systems/fmgc/src/flightplanning/new/uplink/CoRouteUplinkAdapter.ts index 8d2e77fffdf..ce0a8d6bd77 100644 --- a/fbw-a32nx/src/systems/fmgc/src/flightplanning/new/uplink/CoRouteUplinkAdapter.ts +++ b/fbw-a32nx/src/systems/fmgc/src/flightplanning/new/uplink/CoRouteUplinkAdapter.ts @@ -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...`, diff --git a/fbw-a32nx/src/systems/fmgc/src/flightplanning/new/uplink/SimBriefUplinkAdapter.ts b/fbw-a32nx/src/systems/fmgc/src/flightplanning/new/uplink/SimBriefUplinkAdapter.ts index eb651b77d46..861b568d62e 100644 --- a/fbw-a32nx/src/systems/fmgc/src/flightplanning/new/uplink/SimBriefUplinkAdapter.ts +++ b/fbw-a32nx/src/systems/fmgc/src/flightplanning/new/uplink/SimBriefUplinkAdapter.ts @@ -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], @@ -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...`,