Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/GpwsControlsTests.h

Source at documentation-generation time. See Test catalog for fixture associations.

1#include "../GpwsDisplay.h"
2static void ControlsAndCompletion()
3{
4 using G = Bus::Gpws;
5 const auto command = [](Fixture& f, const char* name, bool value = false, int number = 0, float scalar = 0) {
6 Command c; c.name = name; c.bValue = value; c.ivalues[0] = number; c.fValue = scalar;
7 f.bus->commandStream.push_back(c); f.gpws.FrameMove(.1f);
8 };
9 {
10 Fixture f; f.Threat(Severity::Warning,Severity::None); f.Step();
11 command(f,"GPWSInhibit",true); f.vmu.FrameMove(.1f);
12 Check(f.bus->GPWS.inhibited && !f.bus->GPWS.IsTerrainAlert() && f.bus->GPWS.terrain.enabled,
13 "master inhibit stops hazard alerts but retains terrain data");
14 Check(!stopped.empty(),"explicit inhibit can stop a hazard recording");
15 command(f,"GPWSInhibit",true); Check(f.bus->GPWS.inhibited,"explicit inhibit set is idempotent");
16 command(f,"GPWSInhibit",false); Check(!f.bus->GPWS.inhibited,"explicit inhibit reset works");
17 command(f,"GPWSInhibitToggle"); Check(f.bus->GPWS.inhibited,"toggle command changes inhibit state");
18 ++playerships[0].vehicleId; f.Step(); Check(!f.bus->GPWS.inhibited,"vehicle change resets crew inhibit");
19 Command delayed; delayed.name="GPWSInhibit"; delayed.bValue=true; delayed.delay=3;
20 f.bus->commandStream.push_back(delayed); ourcockpit.power=0; f.gpws.FrameMove(.1f);
21 Check(!f.bus->GPWS.inhibited && std::any_of(f.bus->commandStream.begin(),f.bus->commandStream.end(),[](const Command& c){return c.name=="GPWSInhibit";}),
22 "delayed control is not consumed or discarded by an unpowered sensor reset");
23 }
24 {
25 Fixture f; playerships[0].geardown=true;
26 f.bus->RadioAltitudeKm=.1f; f.bus->VerticalSpeedKms=-.03f; f.Step();
27 Check(f.bus->GPWS.Alert==G::Mode1_Pull_Up,"basic reactive protection remains active");
28 command(f,"GPWSTestGsCancel"); Check(f.bus->GPWS.mode5cancelled && !f.bus->GPWS.testLevel,"combined control cancels GS in flight without starting self-test");
29 f.bus->RadioAltitudeKm=.7f; f.gpws.FrameMove(.1f); Check(f.bus->GPWS.mode5cancelled,"GS cancel survives climb above 2000 feet until touchdown");
30 f.bus->RadioAltitudeKm=.008f; f.gpws.FrameMove(.1f); Check(f.bus->GPWS.mode5cancelled,"GS cancel survives final approach below 30 feet");
31 command(f,"GPWSTestGsCancel"); Check(f.bus->GPWS.mode5cancelled,"repeated cancel press is idempotent");
32 playerships[0].reference=REF_ONGROUND; ourcockpit.power=0; f.gpws.FrameMove(0);
33 Check(!f.bus->GPWS.mode5cancelled,"touchdown clears GS cancel even with power off and zero timestep");
35 command(f,"GPWSTestGsCancel"); Check(f.bus->GPWS.testLevel==1 && !f.bus->GPWS.mode5cancelled,"same control starts test on ground");
36 command(f,"GPWSTestGsCancel"); Check(!f.bus->GPWS.testLevel,"same control cancels an active ground test");
37 command(f,"GPWSDecisionHeight",false,0,.045f); Check(f.bus->GPWS.decisionHeightKm==.045f,"DH uses float payload in km");
38 command(f,"GPWSDecisionHeight",false,0,std::numeric_limits<float>::quiet_NaN()); Check(f.bus->GPWS.decisionHeightKm==.045f,"invalid DH cannot poison thresholds");
39 command(f,"GPWSCalloutMask",false,0x12); Check(f.bus->GPWS.calloutMask==0x12,"installation callout menu accepts bit mask");
40 command(f,"GPWS500Mode",false,2); Check(f.bus->GPWS.fiveHundredMode==2,"500 Above Field is selectable");
41 }
42 {
43 Fixture f;
44 for(float gain : {.25f,1.f,0.f,-1.f,std::numeric_limits<float>::infinity(),std::numeric_limits<float>::quiet_NaN()})
45 {
46 Command c; c.name="GPWSGlideslope"; c.fValue=gain; f.bus->commandStream.push_back(c); f.bus->vmuHold=0; f.vmu.FrameMove(.1f);
47 Check(glideslopeVolume==(std::isfinite(gain)&&gain>0?gain:1.f),"VMU honors scalar gain and legacy/invalid defaults");
48 }
49 f.bus->GPWS.Alert=G::Mode5b_Glideslope;
50 Command twice; twice.name="GPWSGlideslope"; twice.sValue="GPWSReactive"; twice.ivalues[0]=G::Mode5b_Glideslope; twice.ivalues[1]=2;
51 f.bus->commandStream.push_back(twice); f.bus->vmuHold=0; const auto before=played.size(); f.vmu.FrameMove(.1f);
52 f.vmu.FrameMove(.5f); Check(played.size()==before+1,"hard G/S second phrase cannot interrupt first");
53 f.vmu.FrameMove(.6f); Check(played.size()==before+2,"hard G/S sequences two full clips");
54 }
55 {
56 Fixture f;
57 command(f,"GPWSTest",true); Check(!f.bus->GPWS.testLevel && f.bus->GPWS.testMessageSeconds>0,"self test rejected in flight with feedback");
58 playerships[0].reference=REF_ONGROUND; f.bus->RadioAltitudeKm=0; command(f,"GPWSTest",true);
59 Check(f.bus->GPWS.testLevel==1,"ground test starts via Boolean command");
60 bool caution=false,warning=false,pattern=false;
61 for(int i=0;i<400 && f.bus->GPWS.testLevel;++i) {
62 f.Step(.1f); caution|=f.bus->GPWS.cautionLamp; warning|=f.bus->GPWS.warningLamp; pattern|=f.bus->GPWS.testPattern;
63 }
64 Check(!f.bus->GPWS.testLevel && caution && warning && pattern,"functional test exercises both lamps and terrain pattern then ends");
65 Check(std::count(played.begin(),played.end(),SOUND_GPWSGLIDESLOPE)==1 &&
66 std::count(played.begin(),played.end(),SOUND_GPWSPULLUP)==2 && std::count(played.begin(),played.end(),SOUND_GPWSTERRAINTERRAIN)==1,
67 "functional self test sends complete expected phrases through VMU");
68 for(int level=2;level<=6;++level) {
69 command(f,"GPWSTest",true,level);
70 Check(f.bus->GPWS.testLevel==level && !f.bus->GPWS.testLines.empty(),"diagnostic test level reports current data");
71 }
72 command(f,"GPWSTest",false); Check(!f.bus->GPWS.testLevel && !f.bus->GPWS.testPattern,"explicit false cancels test and pattern");
73 command(f,"GPWSTestToggle"); Check(f.bus->GPWS.testLevel==1,"toggle starts default level one");
74 playerships[0].reference=REF_APNMODE; f.Step(); Check(!f.bus->GPWS.testLevel,"liftoff cancels self test before operational evaluation");
75 playerships[0].reference=REF_ONGROUND; command(f,"GPWSTest",true); ourcockpit.power=0; f.Step();
76 Check(!f.bus->GPWS.testLevel && !f.bus->GPWS.warningLamp && !f.bus->GPWS.cautionLamp,"power loss clears test and lamps");
77 }
78 {
79 Fixture f; f.bus->GPWS.radioAltitudeValid=false; f.Step();
80 Check((f.bus->GPWS.faults&1) && !f.bus->GPWS.faultHistory.empty(),"invalid radio height supplies fault and history");
81 f.bus->GPWS.radioAltitudeValid=true; f.bus->GPWS.positionValid=false; f.Step();
82 Check((f.bus->GPWS.faults&4) && !(f.bus->GPWS.faults&1),"individual input faults recover independently");
83 }
84 {
86 for (float height : {0.f,-.0002f,-.001f})
87 {
88 f.bus->RadioAltitudeKm=height; f.Step();
89 Check(!(f.bus->GPWS.faults&3),"signed gear-calibrated ground clearance is not a failed GPWS input");
90 Check(f.bus->RadioAltitudeKm==height,"GPWS preserves the signed radio-height sample");
91 Check(!*f.bus->GPWS.AlertText() && !f.bus->GPWS.warningLamp && !f.bus->GPWS.cautionLamp && played.empty(),"parked aircraft has no hazard alert or audio");
92 }
93 f.bus->GPWS.radioAltitudeValid=false; f.Step();
94 Check(f.bus->GPWS.faults&1,"explicit radio-height failure remains visible on ground");
95 f.bus->GPWS.radioAltitudeValid=true;
96 f.bus->RadioAltitudeKm=std::numeric_limits<float>::quiet_NaN(); f.Step();
97 Check(f.bus->GPWS.faults&1,"nonfinite radio height remains a fault on ground");
98 f.bus->RadioAltitudeKm=0; f.bus->GPWS.airDataValid=false; f.Step();
99 Check((f.bus->GPWS.faults&3)==2,"air-data failure remains visible on ground while recovered radio fault clears");
100 f.bus->GPWS.airDataValid=true; f.Step();
101 Check(!(f.bus->GPWS.faults&3),"healthy ground inputs clear the live INOP indication");
102 }
103 {
104 Fixture f; auto& g=f.bus->GPWS;
105 g.terrain.enabled=g.terrain.terrainComplete=g.terrain.obstaclesComplete=true;
106 auto& below=g.terrain.cells[31*TerrainAwareness::GridSize+31];
107 below.valid=true; below.topKm=0;
108 playerships[0].mslKm=.915f; f.bus->RadioAltitudeKm=0;
110 Check(!(g.faults&1),"terrain beneath an elevated landing pad does not fail the parked radio altimeter");
111 playerships[0].reference=REF_APNMODE; f.Step();
112 Check(g.faults&1,"airborne terrain/radio reasonableness monitor remains active");
113 playerships[0].mslKm=0; f.bus->RadioAltitudeKm=-.0002f; f.Step();
114 Check(!(g.faults&1),"signed near-ground radio height remains valid during liftoff");
115 }
116 {
117 Fixture f; f.bus->MapScaleInnerRingKm=40;
118 Check(!f.bus->GPWS.TerrainDisplayActive(),"normal map is the default");
119 f.Threat(Severity::Caution,Severity::None); f.Step();
120 Check(f.bus->GPWS.TerrainDisplayActive() && f.bus->MapScaleInnerRingKm==10.f,"terrain caution selects the supported 10 km inner / 20 km outer range");
121 f.Threat(Severity::None,Severity::Warning); f.Step();
122 Check(f.bus->MapScaleInnerRingKm==10.f,"obstacle escalation does not overwrite saved map range");
123 f.Threat(Severity::None,Severity::None); f.Step();
124 Check(!f.bus->GPWS.TerrainDisplayActive() && f.bus->MapScaleInnerRingKm==40,"clearing hazard restores normal map and original range");
125 f.bus->MapScaleInnerRingKm=80; f.Threat(Severity::Warning,Severity::None); f.Step();
126 command(f,"GPWSInhibit",true);
127 Check(!f.bus->GPWS.TerrainDisplayActive() && f.bus->MapScaleInnerRingKm==80,"inhibit restores map range");
128 command(f,"GPWSInhibit",false); f.Threat(Severity::Warning,Severity::None); f.Step();
129 ourcockpit.power=0; f.Step();
130 Check(!f.bus->GPWS.TerrainDisplayActive() && f.bus->MapScaleInnerRingKm==80,"power loss restores range on early return");
131 }
132 {
133 Fixture f; f.gpws.FrameMove(.1f);
134 const std::wstring gs=L"GS CANCEL", inhibit=L"GPWS INHIBIT";
136 Cas cas(f.bus.get(),&f.logger,f.sound.get());
137 const auto scan=[&] { for(int frame=0;frame<33;++frame)cas.FrameMove(.1f); };
138 cas.FrameMove(2); scan(); played.clear();
139 f.bus->GPWS.mode5cancelled=f.bus->GPWS.inhibited=true;
140 scan();
141 const auto has=[&](const std::wstring& text) { return std::any_of(f.bus->messages.begin(),f.bus->messages.end(),[&](const Message& m) {
142 return m.text==text && m.level==MessageLevel::Status;
143 }); };
144 Check(has(gs) && has(inhibit),"GPWS inhibit and GS cancel are CAS status messages");
145 Check(played.empty(),"GPWS status messages do not issue a master-caution sound");
146 playerships[0].reference=REF_ONGROUND; f.gpws.FrameMove(0); scan();
147 Check(!has(gs) && has(inhibit),"CAS scan removes GS cancel after GPWS clears it on touchdown");
148 f.bus->GPWS.inhibited=false; scan();
149 Check(!has(inhibit),"CAS clears inhibit when selected off");
150 }
151 Check(GpwsBehavior::TerrainFloor(.4f,false,true)==0,"TCF high-integrity bias protects legitimate touchdown");
152 Check(std::fabs(GpwsBehavior::TerrainFloor(20,false,true)-400*GpwsBehavior::FootKm)<.000001f,"TCF middle plateau is 400 feet");
153 Check(std::fabs(GpwsBehavior::TerrainFloor(40,false,true)-700*GpwsBehavior::FootKm)<.000001f,"TCF distant floor is 700 feet");
154 Check(GpwsBehavior::TerrainFloor(1,true,true)>=245*GpwsBehavior::FootKm,"TCF adjacent-runway minimum is 245 feet");
155 Check(GpwsBehavior::RunwayFieldFloor(.5f*1.852f,true)<-99 && GpwsBehavior::RunwayFieldFloor(5.01f*1.852f,true)<-99,"RFCF bounded inner and outer ranges");
156 Check(std::fabs(GpwsBehavior::RunwayFieldFloor(2*1.852f,true)-300*GpwsBehavior::FootKm)<.000001f,"RFCF reaches 300 feet at two nm with high-integrity runway");
157 Check(GpwsBehavior::GlideslopeThreshold(.02f,true)>2 && GpwsBehavior::GlideslopeThreshold(.05f,true)==2,"near-ground G/S desensitization");
158 {
159 Fixture f; playerships[0].geardown=true; f.bus->GPWS.calloutMask=0;
160 playerships[0].position={radiusC+.1f,0,0}; playerships[0].mslKm=.1f; f.bus->RadioAltitudeKm=.1f;
161 Swaypoint r{}; r.type=2; r.heading=0; r.length=2; r.elevationKm=.2f; r.location={radiusC+.2f,0,3.704f};
162 f.bus->waypoint={r}; f.Step();
163 Check(f.bus->GPWS.Alert==G::TCF_Too_Low_Terrain,"RFCF catches flight below an elevated runway despite valid radio clearance");
164 const auto n=played.size(); f.Step(3); Check(played.size()==n,"constant floor penetration is not periodically repeated");
165 playerships[0].mslKm=.079f; f.Step(3); Check(played.size()==n+1,"20 percent further geometric altitude loss repeats floor warning");
166 command(f,"GPWSInhibit",true); Check(f.bus->GPWS.Alert!=G::TCF_Too_Low_Terrain,"master inhibit suppresses TCF/RFCF");
167 }
168 {
169 using namespace GpwsDisplay;
170 const auto style=[](float top,bool peak,float low,float high,Severity hazard=Severity::None) {return Relative(top,10,0,false,hazard,true,-100,false,peak,low,high);};
171 Check(style(3,true,1,3).density==0 && style(1,true,1,3).density==1 && style(2,true,1,3).density==2,"Peaks highest/middle/lowest bands use solid/dense/sparse green");
172 Check(style(3,false,1,3).color==0xff000000,"non-Peaks leaves distant low terrain black");
173 Check(style(3,true,1,3,Severity::Warning).color==0xffff2020,"threat overrides Peaks band");
174 Check(Relative(10,10,0,false,Severity::None,true,-100,false,false,0,11).density==1,"relative yellow is sparse");
175 Check(Relative(11,10,0,false,Severity::None,true,-100,false,false,0,11).density==2,"higher relative red is dense");
176 }
177}
@ REF_APNMODE
Definition ServerTypes.h:42
@ REF_ONGROUND
Definition ServerTypes.h:43
@ SOUND_GPWSPULLUP
Definition Sound.h:45
@ SOUND_GPWSGLIDESLOPE
Definition Sound.h:51
@ SOUND_GPWSTERRAINTERRAIN
Definition Sound.h:46
Definition Module.h:204
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
Scockpit ourcockpit
Definition globals.cpp:114
#define radiusC
Definition globals.h:87
float TerrainFloor(float endRangeKm, bool besideRunway, bool highIntegrity)
constexpr float FootKm
float RunwayFieldFloor(float endRangeKm, bool highIntegrity)
float GlideslopeThreshold(float radioKm, bool hard)
Style Relative(float height, float altitude, float vertical, bool gear, TerrainAwareness::Severity threat, bool known, float runway, bool ground, bool peaks, float lowest, float highest, bool water=false)
Definition GpwsDisplay.h:12
constexpr int GridSize
std::string sValue
Definition Command.h:20
float fValue
Definition Command.h:25
bool bValue
Definition Command.h:22
int ivalues[2]
Definition Command.h:21
std::string name
Definition Command.h:11
float delay
Definition Command.h:8
char yawdamper
char thrustaug
float power
Definition globals.h:599
SVesselDC vdat
Definition globals.h:664
float elevationKm
short heading
unsigned char type
float length
RiseMath::Vector3 location
RiseMath::Vector3 position
Definition globals.h:511
unsigned short vehicleId
Definition globals.h:537