1#pragma once
2#include "../Modules/OrbitEntryAudio.h"
3#include "../Modules/LandingGearStatus.h"
4
5void EntryReadinessTests()
6{
7 auto in=BillEntryFixture();Request r;r.entryOrigin=true;r.passTime=PassTime::Manual;r.arrivalEpoch=in.now+2400;
8 const auto ready=Solve(in,r);
9 Check(ready.plan.valid&&!ready.plan.planningOnly&&ready.status==L"ENTRY READY","clean entry is consistently ready");
10 const wchar_t* reasons[]={L"CONFIG LANDING GEAR",L"CONFIG FLAPS",L"CONFIG SPOILERS",L"CONFIG AIRFRAME ICE",L"CONFIG CARGO BAY"};
11 for(int fault=0;fault<5;++fault) {
12 auto bad=in;
13 bad.entryVehicle.configuration=EntryPhysics::Configuration(fault==0?1:0,fault==1?1:0,fault==2?.1:0,0,fault==3?1:0,fault==4);
14 bad.entryVehicle.clean=false;
15 auto preview=Solve(bad,r);
16 Check(preview.plan.valid&&preview.plan.planningOnly&&preview.plan.executionBlock==reasons[fault],"feasible route retains specific configuration inhibit");
17 Check(preview.status==reasons[fault]&&EntryEngagementBlock(preview)==reasons[fault],"preview and key engagement gate use same reason");
18 Executor ex;auto g=ex.Begin(bad,r,preview);
19 Check(g.phase==Phase::Abort&&!g.valid&&!g.attitude&&!g.thrust&&g.status==L"DOR: "+std::wstring(reasons[fault]),"refused entry names the configuration fault");
20 BusState display;display.request=r;display.snapshot=preview;display.clock=in.now;
21 for(bool refused:{false,true}) {
22 display.guidance=refused?g:Guidance{};
23 bool specific=false;
24 for(const auto& label:Readouts(display,Rows(r,Mode::Return,true),0,false)) {
25 Check(label.text!=L"ARM DOR TO EXECUTE","blocked entry cannot invite execution");
26 if(label.text.find(reasons[fault])!=std::wstring::npos) {
27 specific=true;Check(label.color!=Green,"configuration inhibit is never green");
28 if(refused&&label.y==278) Check(label.color==Red,"entry refusal stays visible in red");
29 }
30 Check(label.x+label.text.size()*5<=420&&label.y<=304,"readiness labels fit instrument");
31 }
32 Check(specific,"specific configuration reason is displayed");
33 }
34 Check(ex.Begin(in,r,ready).valid,"clean entry can arm before in-flight configuration change");
35 g=ex.Step(bad,r);
36 Check(!ex.Active()&&!g.thrust&&!g.attitude&&g.phase==Phase::Abort&&g.status==L"DOR: "+std::wstring(reasons[fault]),"active entry stops control and names the configuration change");
37 EntryPhysics::RefreshReadiness(in,preview.plan);
38 Check(!preview.plan.planningOnly&&preview.plan.executionBlock.empty()&&preview.plan.surface.reason==L"ENTRY READY","configuration recovery needs no route solve");
39 Check(!ex.Step(in,r).valid&&!ex.Active(),"configuration recovery does not automatically re-engage DOR");
40 Check(ex.Begin(in,r,preview).valid,"pilot can explicitly re-engage after restoring configuration");
41 }
42 auto bad=in;bad.entryVehicle.airAge=.5;
43 Check(std::wstring(EntryPhysics::InvalidReason(bad))==L"ENTRY AIR DATA STALE","stale air data is distinguished from configuration");
44 bad=in;bad.entryVehicle.aftC=NAN;
45 Check(std::wstring(EntryPhysics::InvalidReason(bad))==L"ENTRY THERMAL DATA","invalid thermal data is actionable");
46 bad=in;bad.entryVehicle.airIas=-.01;
47 Check(EntryPhysics::Valid(bad),"signed or zero orbital IAS does not impose an aircraft-envelope gate");
48 for(double gear:{.01,.5,1.0,double(NAN)})
49 Check(EntryPhysics::Configuration(gear,0,0,0,0,false)==EntryConfig::Gear,"transit or invalid gear state is blocked");
50 Check(EntryPhysics::Configuration(0,0,0,.1,0,false)==EntryConfig::Spoilers,"flight spoiler also blocks entry");
51 for(int strut=0;strut<3;++strut) {
52 for(int health=-128;health<=128;++health) {
53 int gearHealth[]={127,127,127};gearHealth[strut]=health;
55 "shared gear disagreement preserves CAS's existing component condition");
56 const bool known=health==-1||(health>=64&&health<=127);
57 for(double extent:{0.0,.5,1.0,double(NAN)}) {
59 Check((EntryPhysics::Configuration(confirmed,0,0,0,0,false)==EntryConfig::Clean)==(known&&extent==0),
60 "entry requires confirmed retraction; absent struts are not failed struts");
61 }
62 }
63 int gearHealth[]={127,127,127};gearHealth[strut]=63;
65 auto failed=in;
66 failed.entryVehicle.configuration=EntryPhysics::Configuration(unconfirmed,0,0,0,0,false);
67 failed.entryVehicle.clean=failed.entryVehicle.configuration==EntryConfig::Clean;
68 auto blocked=ready;EntryPhysics::RefreshReadiness(failed,blocked.plan);
69 blocked.status=blocked.plan.surface.reason;
70 Check(blocked.plan.valid&&blocked.plan.planningOnly&&
EntryEngagementBlock(blocked)==L
"CONFIG LANDING GEAR",
71 "gear disagreement keeps route preview but inhibits entry with existing text");
72 Executor ex;auto g=ex.Begin(failed,r,blocked);
73 Check(g.phase==Phase::Abort&&!g.thrust&&!g.attitude&&g.status==L"DOR: CONFIG LANDING GEAR",
74 "each failed strut prevents engagement even with gear animation fully retracted");
75 BusState warning;warning.request=r;warning.snapshot=blocked;warning.guidance=g;
78 "gear disagreement keeps queued configuration callout valid");
79 for(
const auto& label:
Readouts(warning,
Rows(r,Mode::Return,
true),0,
false)) {
80 Check(label.text!=L"ARM DOR TO EXECUTE","gear disagreement cannot invite execution");
81 Check(label.text.find(L"GEAR DISAGREE")==std::wstring::npos,"DOR retains existing configuration text");
82 }
83 for(double h:{937.0,99.0,30.0}) {
84 Check(ex.Begin(in,r,ready).valid,"clean entry arms before gear status is lost");
85 failed.own.r=
Unit(in.own.r)*(in.radius+h);
86 g=ex.Step(failed,r);
87 Check(!ex.Active()&&!g.thrust&&!g.attitude&&g.status==L"DOR: CONFIG LANDING GEAR",
88 "loss of confirmed gear status aborts entry both in orbit and in atmosphere");
89 }
90 gearHealth[strut]=64;
92 Check(!
EntryGearCalloutValid(call,warning,42,
true,repaired),
"restored gear confirmation cancels queued voice");
93 EntryPhysics::RefreshReadiness(in,blocked.plan);
94 Check(!blocked.plan.planningOnly&&!ex.Step(in,r).valid&&!ex.Active(),
95 "restored confirmation clears inhibit without automatically restarting entry");
96 }
97 bad=in;bad.dockedAtStation=true;bad.freeFlight=false;
98 auto preview=ready;EntryPhysics::RefreshReadiness(bad,preview.plan);
99 Check(preview.plan.planningOnly&&
EntryEngagementBlock(preview)==L
"UNDOCK TO EXECUTE",
"actual attachment permits planning but prevents arming");
101 EntryPhysics::RefreshReadiness(bad,preview.plan);
102 Check(!preview.plan.planningOnly,"station smoothing bubble does not prevent entry engagement");
103 for(double h:{0.0,7.4,30.0,99.9,100.0,937.0}) {
104 bad=in;bad.own.r=
Unit(in.own.r)*(in.radius+h);
105 Check((EntryPhysics::StartBlock(bad)!=nullptr)==(h<100),"entry start threshold is separate from clean ongoing control");
106 Check(EntryPhysics::Valid(bad),"ongoing entry remains valid below the starting altitude");
107 }
108 BusState data;data.request=r;data.snapshot=ready;
109 data.guidance.phase=Phase::Abort;data.guidance.status=L"DOR: CONFIG LANDING GEAR";
116 Check(
EntryGearRefusal(data),
"unresolved configuration refusal remains visible");
118 Check(data.guidance.phase==Phase::Off&&!data.guidance.valid&&data.guidance.status.empty(),"retracted configuration clears stale refusal without engaging control");
119 data.guidance.phase=Phase::Abort;data.guidance.status=L"DOR: CONFIG LANDING GEAR";
120 ++data.request.revision;
122 data.request=r;data.guidance={};
123 for(auto phase:{Phase::Off,Phase::Wait,Phase::Depart,Phase::Coast,Phase::Complete}) {
124 data.guidance.phase=phase;
125 Check(!
EntryGearCalloutValid(call,data,42,
true,1),
"normal ground, ascent, orbit and completed handoff do not trigger entry config speech");
126 }
127 data.guidance.entryHandoff=true;data.speedHoldValid=true;
128 for(
const auto& label:
Readouts(data,
Rows(r,Mode::Return,
true),0,
false))
129 Check(label.text!=L"CONFIG LANDING GEAR","post-entry aircraft-mode gear use has no DOR inhibit");
130}
constexpr bool Disagrees(int left, int right, int nose)
double ConfirmedExtent(double extent, int left, int right, int nose)
bool FreeFlightReference(int reference, bool docked, int firstStation, int stationCount)
bool EntryGearCalloutValid(const Command &c, const BusState &data, int vehicle, bool powered, double gear)
std::wstring EntryEngagementBlock(const Snapshot &s)
bool EntryGearRefusal(const BusState &data)
std::vector< Row > Rows(const Request &r, Mode mode, bool entry=false, bool ascent=false, bool recordingAllowed=false)
std::vector< Label > Readouts(const BusState &data, const std::vector< Row > &rows, int uiRow, bool dorActive, bool showKeys=true)
Command EntryGearCallout(const BusState &data, int vehicle)
void ClearResolvedEntryConfigRefusal(BusState &data, bool clean)