1
2#include "../Modules/Module.h"
3#include <iostream>
4#include <memory>
5#include <cstdlib>
6#include <limits>
7
14static int checks = 0;
15static std::vector<SOUNDS> played, stopped;
18static float glideslopeVolume = 1;
19static void Check(bool value, const char* message)
20{
21 ++checks;
22 if (!value) { std::cerr << "FAIL: " << message << '\n'; std::exit(1); }
23}
31{
33 played.push_back(sound); return sound == missingRecording ? 0.f : (sound == extendedRecording ? 4.5f : 1.f);
34}
37
38
40#include "GpwsWindshearScene.h"
41
42static Severity Patch(
Predictor& predictor,
float x,
float y,
float width,
float height,
43 float altitude, bool obstacle = false, bool coverage = false)
44{
45 const Point a{x-width/2,y-height/2,altitude}, b{x+width/2,y-height/2,altitude};
46 const Point c{x+width/2,y+height/2,altitude}, d{x-width/2,y+height/2,altitude};
47 Point first[] = {a,b,c}, second[] = {a,c,d};
48 return Max(predictor.
Scan(first,obstacle,coverage),predictor.
Scan(second,obstacle,coverage));
49}
51{
54 Check(Patch(p,0,4.5f,.03f,.01f,1) ==
Severity::Caution,
"level flight sees ridge 45 seconds ahead");
55 Check(Patch(p,0,2.5f,.03f,.01f,1) ==
Severity::Warning,
"level flight sees ridge 25 seconds ahead");
56 Check(Patch(p,0,7,.03f,.01f,1) ==
Severity::None,
"outside horizon does not alert");
57 Check(Patch(p,0,-1,.03f,.01f,2) ==
Severity::None,
"terrain behind aircraft does not alert");
58 Check(Patch(p,3,2,.03f,.01f,2) ==
Severity::None,
"off-track city does not alert");
59 Check(Patch(p,.25f,2.043f,.001f,.001f,1,
true) ==
Severity::Warning,
"one-meter tower between steps inside corridor is detected");
60 Check(Patch(p,0,2,.01f,.01f,.4f,
true) ==
Severity::None,
"low building cleared safely");
61 Check(Patch(p,0,4.5f,.01f,.01f,1,
true) ==
Severity::Caution,
"obstacle has its own predictive caution");
63 Check(Patch(descending,0,2.5f,.02f,.02f,.6f) ==
Severity::Warning,
"descending toward terrain below current altitude");
65 Check(Patch(climbing,0,2.5f,.02f,.02f,1) ==
Severity::None,
"adequate climb clears ridge");
67 const auto turnPoint = turning.segments[24].start;
68 Check(Patch(turning,turnPoint.x,turnPoint.y,.02f,.02f,1) ==
Severity::Warning,
"turn projects corridor into new flight path");
69 Check(Patch(p,turnPoint.x,turnPoint.y,.02f,.02f,1) ==
Severity::None,
"turn hazard was outside straight corridor");
71 Check(Patch(fast,0,4.5f,.02f,.02f,1) ==
Severity::Warning,
"ground speed changes caution to warning");
72
73
74 Predictor full(f); Patch(full,0,6,5,12,0,
false,
true);
75 Check(full.Covered(),"complete terrain covers entire corridor");
76 Predictor gap(f); Patch(gap,0,2,5,4,0,
false,
true); Patch(gap,0,9,5,6,0,
false,
true);
77 Check(!gap.Covered(),"missing terrain strip remains unknown");
79 Check(!limited.Covered(),"range cap reports limited coverage at extreme speed");
81 Check(hover.segments.empty(),"hover never invents forward velocity");
82 Point invalid[] = {{0,1,1},{1,1,std::numeric_limits<float>::quiet_NaN()},{1,2,1}};
83 Check(p.Scan(invalid,
false) ==
Severity::None,
"invalid geometry does not produce arbitrary threats");
84}
85static void Approaches()
86{
90 Check(Patch(approach,0,1.5f,.1f,.1f,0) ==
Severity::None,
"flat selected runway approach is quiet");
91 Check(Patch(approach,0,1.4f,.1f,.1f,.07f) ==
Severity::Warning,
"hill on landing approach remains protected");
92 Check(Patch(approach,0,1.4f,.01f,.01f,.1f,
true) ==
Severity::Warning,
"gear down does not inhibit tower warning");
94 Check(Patch(noDestination,0,2.5f,.1f,.1f,0) ==
Severity::Caution,
"unselected landing surface is not silently exempted");
95}
96static void ColorsAndState()
97{
98 Check(
Color(1,1,0,
false,
Severity::None) == 0xff8c8200,
"same altitude uses relative yellow");
100 Check(
Color(.86f,1,0,
true,
Severity::None) == 0xff168438,
"gear-down clearance band narrows");
101 Check(
Color(1.4f,1,0,
false,
Severity::None) == 0xffd8bb00,
"higher terrain has denser yellow shade");
105 Check(
Color(0,1,0,
false,
Severity::None,
false) == 0xffb030b0,
"missing data is magenta not low terrain");
106 Check(
Color(.7f,1,-.01f,
false,
Severity::None) == 0xff8c8200,
"descent anticipates lost height");
108 Check(!state.
ObstacleAlert(),
"guide priority selects terrain for equal-severity threats");
110 Check(!state.
ObstacleAlert(),
"earlier terrain wins equal severity");
112 Check(!state.
ObstacleAlert(),
"earlier obstacle does not reorder equal-severity guide priority");
117 Check(state.
ObstacleAlert(),
"obstacle warning label outranks terrain caution");
118 Check(!
Allowed(
true,
false,
true,1) &&
Allowed(
false,
false,
true,1),
"simulator admission gate and real-world admission");
119 Check(!
Allowed(
false,
true,
true,1) && !
Allowed(
false,
false,
false,1) && !
Allowed(
false,
false,
true,0),
"ground vehicle landing and power inhibit");
120}
121struct Fixture
122{
123 Logger logger;
124 std::unique_ptr<Bus> bus = std::make_unique<Bus>(&logger);
125 std::unique_ptr<Sound> sound = std::make_unique<Sound>(nullptr);
126 Gpws gpws{bus.get(),&logger};
127 Vmu vmu{bus.get(),&logger,sound.get()};
128 Fixture()
129 {
133 bus->RadioAltitudeKm = 2; bus->VerticalSpeedKms = 0; bus->WPtargetC = 0;
134 vmu.
FrameMove(2); bus->vmuHold = 0; played.clear(); stopped.clear();
135 }
136 void Threat(Severity terrain, Severity obstacle)
137 { bus->GPWS.terrain.enabled = true; bus->GPWS.terrain.terrain = terrain; bus->GPWS.terrain.obstacle = obstacle; bus->GPWS.terrain.terrainTime = 40; bus->GPWS.terrain.obstacleTime = 45; }
139};
140static void AudioAndLifecycle()
141{
142 Fixture f;
147 f.Step(.95f);
149 f.Step(2.1f);
150 Check(played.back() ==
SOUND_TA_PULLUP,
"persistent predictive warning repeats plain pull up");
151 Command stale; stale.
name =
"GPWSObstacleObstacle"; stale.
sValue =
"GPWSTerrain";
153 f.bus->commandStream.push_back(stale);
155 Check(!f.bus->GPWS.terrain.enabled && !f.bus->GPWS.IsTerrainAlert(),"simulator entry clears predictive state");
156 Check(f.bus->commandStream.empty() && stopped.back() ==
SOUND_TA_PULLUP,
"simulator entry cancels queued and playing look-ahead audio");
158 Check(played.size() == count,"simulator exit does not replay an old alert");
162 Check(!f.bus->GPWS.terrain.enabled && !f.bus->GPWS.IsTerrainAlert() && stopped.back() ==
SOUND_GPWSTERRAINTERRAIN,
"power loss clears display queue and audio");
165 Check(f.bus->GPWS.Alert ==
Bus::Gpws::Mode1_Pull_Up && !f.bus->GPWS.IsTerrainAlert(),
"reactive pull-up retains higher priority");
166 f.bus->RadioAltitudeKm = 2; f.bus->VerticalSpeedKms = 0;
g_bAboveClouds =
true;
171 Check(f.bus->GPWS.terrain.enabled && f.bus->GPWS.terrain.Alert() ==
Severity::None,
"landing clears threats while retaining terrain display");
172
173 {
174 Fixture f;
177 Check(played.back() ==
SOUND_TA_PULLUP,
"missing obstacle warning uses plain predictive Pull Up");
180 Check(played.back() ==
SOUND_TA_CAUTION_TERRAIN && f.bus->vmuHold <= 0,
"missing caution remains silent without substitute voice");
182
184 wrong.
ivalues[1] =
int(f.bus->GPWS.terrainRevision);
185 f.bus->commandStream.push_back(wrong); count = played.size(); f.vmu.FrameMove(.1f);
186 Check(f.bus->commandStream.empty() && played.size() == count,"invalid injected alert is discarded");
187 }
188}
189static void SeparateWarningRecordings()
190{
191 for (bool obstacle : {false,true})
192 {
193 Fixture f;
195 extendedRecording = prefix;
197 f.Step(); f.Step(2.1f);
198 Check(played == std::vector<SOUNDS>{prefix} && stopped.empty(), "queued Pull Up waits for the complete long warning preface");
199 f.Step(2.5f);
200 Check(played == std::vector<SOUNDS>({prefix,
SOUND_TA_PULLUP}) && stopped.empty(),
"separate plain Pull Up follows terrain or obstacle without a combined file");
201 f.Step(2.1f);
204 }
205 {
208 Check(played.back() ==
SOUND_GPWSPULLUP && f.bus->vmuHold > 0,
"voice sets awaiting plain Pull Up retain their existing warning recording");
210 }
211 {
212 Fixture f;
213 Command command; command.
name =
"GPWSPullUp"; f.bus->commandStream.push_back(command); f.vmu.FrameMove(.1f);
214 Check(played == std::vector<SOUNDS>{
SOUND_GPWSPULLUP},
"ordinary reactive Pull Up keeps the existing whoop recording");
215 f.vmu.FrameMove(1.1f);
216 command.
name =
"GPWSTerrain"; f.bus->commandStream.push_back(command); f.vmu.FrameMove(.1f);
217 Check(played.back() ==
SOUND_GPWSTERRAIN,
"single Terrain command uses its independent recording");
218 }
219 for (bool obstacle : {false,true})
220 {
223 f.Step(); f.Step(2.1f);
224 Check(played == std::vector<SOUNDS>{extendedRecording} && stopped.empty(), "complete doubled caution recording is played once per announcement");
225 f.Step(5.f);
226 Check(played == std::vector<SOUNDS>({extendedRecording,extendedRecording}), "doubled caution file repeats at the existing seven-second cadence");
228 }
229}
230static void CommonDispatch()
231{
232 Fixture f;
234 Check(f.bus->GPWS.Alert == alert && f.bus->commandStream.size() == 1,"one selected GPWS alert queues one command");
235 const auto& c = f.bus->commandStream.front();
236 Check(c.name == name && c.priority == priority && c.ttl == 2 &&
237 c.ivalues[0] == alert && unsigned(c.ivalues[1]) == f.bus->GPWS.terrainRevision,
238 "common switch uses named command, selected alert priority and cancellation revision");
239 };
246 f.bus->commandStream.clear(); f.gpws.FrameMove(1.9f);
247 Check(f.bus->commandStream.empty(),"persistent warning waits for two-second interval");
248 f.gpws.FrameMove(.2f);
250 f.gpws.FrameMove(10);
251 Check(f.bus->commandStream.size() == 1,"pending predictive speech is not duplicated");
254 f.bus->commandStream.clear(); f.gpws.FrameMove(6.9f);
255 Check(f.bus->commandStream.empty(),"caution waits for seven-second interval");
256 f.gpws.FrameMove(.2f);
260 f.vmu.FrameMove(.1f);
263 Check(stopped.empty() && f.bus->vmuHold > 0 && f.bus->commandStream.empty(),"hazard clearance removes queued speech but finishes the active phrase");
264
265
266 Command altitude; altitude.
name =
"GPWSMode6FiveHundred";
267 f.bus->commandStream.push_back(altitude);
269 Check(f.bus->commandStream.size() == 1 && f.bus->commandStream.front().name == altitude.
name,
270 "legacy one-shot callout survives alert clearance");
271 f.vmu.FrameMove(2);
272 Check(played.back() ==
SOUND_GPWSFIVEHUNDRED,
"legacy altitude callout still uses normal VMU dispatch");
273
274
275 Command injected; injected.
name =
"GPWSObstacleObstacle";
277 const auto count = played.size(); f.vmu.FrameMove(2);
278 Check(f.bus->commandStream.empty() && played.size() == count,"untagged predictive phrase cannot play in simulator");
279}
280static void UninterruptedSpeech()
281{
282 Fixture f;
283 for (int i = 0; i < 20; ++i)
284 {
286 else { f.bus->GPWS.terrain.Clear(); f.bus->GPWS.terrain.enabled = true; }
287 f.Step(.05f);
288 }
289 Check(played.size() == 1 && stopped.empty(),"coverage flicker cannot restart a caution mid-word or bypass its cadence");
291 Check(played.size() == 2 && stopped.empty(),"persistent caution can repeat after its normal interval");
292 f.bus->GPWS.terrain.Clear(); f.bus->GPWS.terrain.enabled = true;
293 f.Step(2);
294 played.clear(); stopped.clear();
295 Command fifty; fifty.
name =
"GPWSMode6Fifty"; f.bus->commandStream.push_back(fifty); f.vmu.FrameMove(.1f);
296 Check(played.back() ==
SOUND_GPWSFIFTY,
"normal altitude callout begins");
298 Check(played.size() == 1 && stopped.empty(),"new terrain warning cannot cut an altitude callout mid-word");
299 f.Step(1);
301 {
302 Fixture descent;
303 descent.bus->RadioAltitudeKm = .016f; descent.gpws.FrameMove(2);
304 descent.bus->commandStream.clear();
305 descent.bus->RadioAltitudeKm = .014f; descent.Step(1);
306 descent.bus->RadioAltitudeKm = .008f; descent.Step(1);
307 descent.bus->RadioAltitudeKm = .005f; descent.Step(1);
309 "fast altitude crossings skip forty without truncating fifty, thirty or twenty");
310 }
311}
312static void StableCategoryPriority()
313{
314 Fixture f;
315 for (int i = 0; i < 150; ++i)
316 {
318 f.bus->GPWS.terrain.terrainTime = 39;
319 f.bus->GPWS.terrain.obstacleTime = i%2 ? 39.001f : 38.999f;
320 f.Step(.1f);
322 "near-equal encounter times cannot chatter the map or selected caution");
323 }
324 Check(played.size() == 3 && std::all_of(played.begin(),played.end(),[](
SOUNDS sound) { return sound == SOUND_TA_CAUTION_TERRAIN; }) && stopped.empty(),
325 "jittering threats preserve three intact terrain phrases on the seven-second cadence");
328 "higher obstacle severity takes priority immediately");
331 "obstacle caution is selected immediately when terrain clears");
332}
333static void ManualAuditRegressions()
334{
336 "Mode 4A ramps from 500 ft and caps at 1000 ft instead of using 1000 ft as a minimum");
338 "Mode 4B ramps from 245 ft and caps at 1000 ft");
340 "available TAD disables Mode 4 speed expansion");
344 Check(std::fabs(history.
Update(5,.2f,.3048f)-.05f) < .00001f,
"MTC starts at zero and integrates elapsed time");
345 Check(std::fabs(history.
Update(10,.2f,.3048f)-.15f) < .00001f,
"MTC reaches 75 percent of 15 second average");
346 Check(std::fabs(history.
Update(15,.01f,.3048f)-.15f) < .00001f,
"MTC cannot fall with decreasing terrain clearance");
349 "ground declutter hides airport surface while higher mountains remain red");
351 "runway display declutter cannot hide a detected threat");
353 "runway declutter is a vertical band, not a blanket hiding of everything below runway height");
354 {
357 f.bus->RadioAltitudeKm = .1f; f.bus->VerticalSpeedKms = -.1f;
358 f.bus->RollAttitudeRadians = 1.5f; f.Step(4);
359 Check(f.bus->GPWS.terrain.enabled && !f.bus->GPWS.IsTerrainAlert() && played.empty(),
360 "ground state preserves terrain awareness with no predictive or reactive flight warnings");
361 }
362 {
364 f.gpws.FrameMove(.01f);
365 Check(f.bus->GPWS.Alert ==
Bus::Gpws::Reset,
"first radio sample cannot invent a closure rate");
366 g_bAboveClouds =
true; f.bus->VerticalSpeedKms = -.03f; f.gpws.FrameMove(2);
369 }
370 {
372 f.bus->RadioAltitudeKm = .08f; f.bus->VerticalSpeedKms = -.001f;
373 f.bus->LocalizerDeviationRadians = 0; f.bus->GlideslopeDeviationRadians =
RiseMath::ToRadian(-.8f);
374 f.gpws.FrameMove(4);
376 f.bus->GlideslopeDeviationRadians = 0; f.gpws.FrameMove(.1f);
377 Check(f.bus->GPWS.Alert ==
Bus::Gpws::Reset,
"hard glideslope alert clears when deviation recovers");
378 f.bus->GPWS.mode5cancelled = true; f.bus->RadioAltitudeKm = .7f; f.gpws.FrameMove(.1f);
379 Check(f.bus->GPWS.mode5cancelled,"glideslope cancel remains above 2000 ft until touchdown");
380 f.bus->GPWS.mode5cancelled = true; f.bus->RadioAltitudeKm = .008f; f.gpws.FrameMove(.1f);
381 Check(f.bus->GPWS.mode5cancelled,"glideslope cancel remains below 30 ft until touchdown");
382 }
383 {
384 Fixture f; f.bus->RadioAltitudeKm = .007f; f.bus->RollAttitudeRadians =
RiseMath::ToRadian(20.f);
385 f.gpws.FrameMove(2);
388 f.bus->AFCS.AutopilotEngaged = true; f.gpws.FrameMove(2);
389 Check(f.bus->GPWS.Alert ==
Bus::Gpws::Mode6_Bank_Angle,
"autopilot bank protection retains its reduced limit within the flight envelope");
390 }
391 {
392 Fixture f; f.bus->RadioAltitudeKm = .065f; f.gpws.FrameMove(2); f.bus->commandStream.clear();
393 f.bus->RadioAltitudeKm = .059f; f.gpws.FrameMove(1);
395 f.bus->commandStream.clear(); f.bus->RadioAltitudeKm = .065f; f.gpws.FrameMove(1);
396 f.bus->RadioAltitudeKm = .059f; f.gpws.FrameMove(1);
398 }
399 {
400 Fixture f;
playerships[0].
geardown =
true; f.bus->RadioAltitudeKm = .02f; f.gpws.FrameMove(2);
401 f.bus->commandStream.clear(); f.bus->vmuHold = 2;
402 f.bus->RadioAltitudeKm = .014f; f.gpws.FrameMove(.1f);
403 f.bus->RadioAltitudeKm = .008f; f.gpws.FrameMove(.1f);
404 Check(f.bus->commandStream.size() == 1 && f.bus->commandStream.front().name == "GPWSMode6Thirty" &&
405 f.bus->commandStream.front().priority == 112,"latest crossed altitude replaces obsolete queued height without losing priority");
406 }
407 {
409 f.bus->RadioAltitudeKm = .2f; f.bus->VerticalSpeedKms = -.003f;
410 f.bus->LocalizerDeviationRadians = 0; f.bus->GlideslopeDeviationRadians =
RiseMath::ToRadian(-.5f);
411 f.Step();
412 Check(played.back() ==
SOUND_GPWSGLIDESLOPE && glideslopeVolume == .5f,
"soft glideslope uses half volume");
413 const auto count = played.size(); f.Step(4);
414 Check(played.size() == count,"unchanged soft glideslope deviation does not repeat on a timer");
416 Check(played.size() == count+1,"20 percent deeper soft deviation produces another phrase");
417
418
419 f.bus->RadioAltitudeKm = .08f; f.bus->GlideslopeDeviationRadians =
RiseMath::ToRadian(-.8f); f.Step(40); f.Step(2);
421 "hard glideslope restores normal volume after higher-priority altitude callout");
422 f.bus->GlideslopeDeviationRadians = 0; f.gpws.FrameMove(.1f);
423 Check(std::none_of(f.bus->commandStream.begin(),f.bus->commandStream.end(),[](
const Command& c) {
424 return c.sValue == "GPWSReactive";
425 }),"recovered reactive warning cannot remain queued for later playback");
426 }
427 {
428 Fixture f; f.bus->RadioAltitudeKm = .75f; f.bus->RollAttitudeRadians =
RiseMath::ToRadian(60.f);
429 f.Step(); const auto count = played.size(); f.Step(3);
430 Check(played.size() == count,"unchanged excessive bank produces one advisory");
433 Check(played.size() == count+3,"second 20 percent bank increase makes advisory continuous");
434 const auto after = played.size(); f.bus->RollAttitudeRadians =
RiseMath::ToRadian(60.f); f.Step(3);
435 Check(played.size() == after,"reducing bank below continuous threshold stops repetition");
436 }
437 {
439 f.gpws.FrameMove(1); f.bus->RadioAltitudeKm = .1f; f.gpws.FrameMove(1);
442 f.bus->RadioAltitudeKm = .1f; f.gpws.FrameMove(1);
443 Check(f.bus->GPWS.Alert ==
Bus::Gpws::Mode2b_Pull_Up,
"Mode 2B can warn with gear up when landing-flap input selects it");
444 }
445 {
446 Fixture f; f.bus->IndicatedAirspeedKms = .1f; f.bus->RadioAltitudeKm = .2f;
447 f.gpws.FrameMove(1);
448 Check(f.bus->GPWS.Alert ==
Bus::Gpws::Reset,
"Mode 4A does not warn throughout an incorrectly flattened 1000 ft envelope");
449 f.bus->RadioAltitudeKm = .16f; f.gpws.FrameMove(10);
452 f.gpws.FrameMove(1);
453 Check(f.bus->GPWS.Alert ==
Bus::Gpws::Reset,
"TAD availability narrows Mode 4 envelope without muting it entirely");
454 }
455 {
457 f.bus->RadioAltitudeKm = 0; f.gpws.FrameMove(1);
459 f.bus->RadioAltitudeKm = .2f; f.bus->VerticalSpeedKms = .01f; f.gpws.FrameMove(15);
460
461 playerships[0].
mslKm = .31f; f.bus->RadioAltitudeKm = .14f; f.gpws.FrameMove(15);
463 playerships[0].
mslKm = .29f; f.bus->RadioAltitudeKm = .25f; f.bus->VerticalSpeedKms = -.002f;
464 f.gpws.FrameMove(5);
466 f.bus->VerticalSpeedKms = .002f; f.gpws.FrameMove(1);
468 }
469 const auto destinationClosure = [](float rangeKm, float heightKm) {
471 f.bus->waypoint.resize(1); auto& runway = f.bus->waypoint[0];
472 runway.type = 2; runway.heading = 0; runway.length = 2;
475 f.bus->GPWS.terrain.enabled = f.bus->GPWS.terrain.terrainComplete = f.bus->GPWS.terrain.obstaclesComplete = true;
476 f.bus->RadioAltitudeKm = .3f; f.gpws.FrameMove(1);
477 f.bus->RadioAltitudeKm = .2f; f.gpws.FrameMove(1);
478 return f.bus->GPWS.Alert;
479 };
481 "destination airport vicinity selects Mode 2B without gear, flaps or ILS capture");
483 "outside 10 nm destination vicinity retains Mode 2A");
485 "more than 3500 ft above destination retains Mode 2A despite nearby range");
486}
487
488static void BankAltitudeEnvelope()
489{
490
491 for (bool autopilot : {false,true})
492 for (float radioKm : {.761999f,.762f,.762001f,1.5f,12.192f})
493 for (float sign : {-1.f,1.f})
494 {
496 f.bus->RadioAltitudeKm = radioKm; f.bus->AFCS.AutopilotEngaged = autopilot;
498 f.Step();
500 "40-degree bank selects Autoflyte only, including 40000 ft AGL over a high field");
501 Check(autopilot ? played.size() == 1 && played.back() ==
SOUND_GPWSBANKANGLE : played.empty(),
502 "manual and Autoflyte bank profiles reach the normal VMU path");
505 "manual 55-degree bank protection remains above the former ceiling");
506 }
507 {
510 f.gpws.FrameMove(.1f); Check(f.bus->commandStream.empty(),"manual 40-degree bank is quiet");
511 f.bus->AFCS.AutopilotEngaged = true; f.gpws.FrameMove(.1f);
512 Check(f.bus->commandStream.size() == 1 && f.bus->commandStream.front().name == "GPWSBankAngle",
513 "engaging Autoflyte immediately applies the 33-degree profile");
514 f.bus->AFCS.AutopilotEngaged = false; f.gpws.FrameMove(.1f); f.vmu.FrameMove(6);
515 Check(played.empty() && f.bus->commandStream.empty(),"disengaging Autoflyte expires its queued advisory");
516 }
517 for (bool autopilot : {false,true})
518 for (float height : {40.f,100.f,900.f})
519 for (float roll : {-89.f,89.f})
520 for (float mach : {0.f,20.f})
521 {
523 f.bus->AFCS.AutopilotEngaged = autopilot; f.bus->Mach = mach;
524 f.bus->AirDensityScalar = 1;
526 f.Step(); f.Step(3);
527 Check(f.bus->GPWS.Alert ==
Bus::Gpws::Reset && played.empty() && f.bus->commandStream.empty(),
528 "thin-air coast, hypersonic entry and 900 km orbit cannot announce bank angle");
529 }
530 {
532 Check(envelope.
Allows(2,.01001f,4.99f),
"normal flight remains eligible above thin-air and below hypersonic thresholds");
533 Check(!envelope.
Allows(2,.01f,0),
"one-percent density suspends even stationary suborbital coast");
534 Check(!envelope.
Allows(2,.01999f,0),
"thin-air hysteresis prevents chattering");
535 Check(envelope.
Allows(2,.02f,4),
"two-percent density and Mach 4 rearm together");
536 Check(!envelope.
Allows(2,.2f,5),
"hypersonic flight suspends bank advisories in denser air");
537 Check(!envelope.
Allows(2,.2f,4.01f),
"hypersonic hysteresis holds during initial deceleration");
538 Check(envelope.
Allows(2,.2f,4),
"return to Mach 4 rearms normal bank profiles");
539 Check(!envelope.
Allows(.762001f,0,20) && envelope.
Allows(.762f,0,20),
540 "near-ground protection overrides the spaceflight gate at 762 m inclusive");
541 const float nan = std::numeric_limits<float>::quiet_NaN();
542 Check(!envelope.
Allows(nan,.2f,0) && !envelope.
Allows(2,nan,0),
"invalid admission inputs do not create bank warnings");
543 Check(envelope.
Allows(.75f,nan,nan),
"valid near-ground radio height does not depend on density or Mach");
544 }
545 {
548 f.gpws.FrameMove(.1f);
549 Check(f.bus->commandStream.size() == 1,"bank warning can wait behind an existing phrase");
550 playerships[0].
mslKm = 40; f.bus->RadioAltitudeKm = 40; f.gpws.FrameMove(.1f); f.vmu.FrameMove(6);
551 Check(played.empty() && f.bus->commandStream.empty(),"spaceflight entry removes queued bank audio");
553 Check(played.empty(),"re-entry retains thin-air hysteresis");
554 playerships[0].
mslKm = 25; f.bus->RadioAltitudeKm = 25; f.bus->Mach = 6; f.Step();
555 Check(played.empty(),"denser hypersonic re-entry still inhibits the jet bank advisory");
556 f.bus->Mach = 4; f.Step();
557 Check(played.size() == 1 && played.back() ==
SOUND_GPWSBANKANGLE,
"slower atmospheric re-entry rearms the advisory");
558 f.bus->Mach = 5; f.Step();
559 Check(stopped.empty() && f.bus->vmuHold > 0 && played.size() == 1,
560 "spaceflight transition lets an active phrase finish without interruption");
561 f.Step(3); Check(played.size() == 1 && f.bus->commandStream.empty(),"no stale repeats survive spaceflight entry");
562 playerships[0].
mslKm = 10.275f; f.bus->RadioAltitudeKm = .75f; f.bus->Mach = 20; f.Step();
564 "near-ground recovery overrides a latched high-speed exclusion");
565 }
566 for (int reset : {0,1,2})
567 {
570 playerships[0].
mslKm = 32; f.bus->RadioAltitudeKm = 32; f.gpws.FrameMove(.1f);
571 Check(f.bus->GPWS.Alert ==
Bus::Gpws::Reset,
"transition band retains the previous spaceflight state");
575 f.gpws.FrameMove(.1f);
576 Check(f.bus->GPWS.Alert ==
Bus::Gpws::Mode6_Bank_Angle,
"ground, power and vehicle reset cannot retain stale spaceflight hysteresis");
577 }
578 for (float height : {.001f,.002f,.75f})
579 {
580 Fixture f;
playerships[0].
mslKm = 9.525f+height; f.bus->RadioAltitudeKm = height;
581 f.bus->IndicatedAirspeedKms = f.bus->TrueAirspeedKms = f.bus->Mach = 0;
584 "zero-IAS VTOL retains the five-foot minimum and near-ground bank protection");
586 }
587 {
588 Fixture f; f.bus->RadioAltitudeKm = 25;
playerships[0].
mslKm = 25; f.bus->Mach = 6;
591 "spaceflight bank exclusion cannot inhibit a separate predictive terrain warning");
594 "spaceflight bank exclusion cannot inhibit a separate obstacle warning");
595 }
596}
597
598#include "GpwsControlsTests.h"
599#include "GpwsWindshearTests.h"
600#include "ModuleSchedulerTests.h"
601#include "GpwsPredictiveWindshearTests.h"
602#include "TerrainAlertStabilityTests.h"
604{
605 TerrainAlertStabilityRegressions();
606 Geometry(); Approaches(); ColorsAndState(); AudioAndLifecycle(); SeparateWarningRecordings(); CommonDispatch(); UninterruptedSpeech(); StableCategoryPriority();
607 ManualAuditRegressions(); BankAltitudeEnvelope(); ControlsAndCompletion(); WindshearRegressions(); ModuleSchedulingRegressions(); PredictiveWindshearRegressions();
608 std::cout << "PASS: " << checks << " terrain/obstacle, map, priority and lifecycle checks\n";
609}
SCRIPT_CONTROL SCRIPT_STATE const void int
@ SOUND_TA_CAUTION_OBSTACLE
@ SOUND_TA_OBSTACLE_WARNING
@ SOUND_GPWSTERRAINTERRAIN
@ SOUND_TA_CAUTION_TERRAIN
void UpdateTerrainAwareness(float seconds)
void FrameMove(float fElapsedTime) override
void Log(const char *msg, Level level=Info, int errorCode=0)
void Stop(SOUNDS soundEnum) const
std::vector< std::string > sound_path
float Play(SOUNDS soundEnum, float volume=1.0f)
void PlayEx(SOUNDS soundEnum, bool loop, float volume=1.0f, float frequencyMod=1.0f, float pan=0.0f, bool restart=true, bool fromOutside=false, bool partOfHull=false)
Sound(GameClass *gameptr)
Severity Scan(const Point(&triangle)[3], bool obstacle, bool coverage=false, float *firstThreatTime=nullptr)
void FrameMove(float fElapsedTime) override
s_network_objects playerships[MAX_SCAN]
float FlapFloor(float speedKms, bool terrainAvailable)
float BankLimit(float radioKm, bool autopilot)
float GearFloor(float speedKms, bool terrainAvailable)
Path Geometry(const Input &, const Request &r, const ArrivalPreview &gate)
Severity Max(Severity a, Severity b)
uint32_t Color(float terrainKm, float altitudeKm, float verticalKms, bool gearDown, Severity severity, bool known=true, float displayRunwayKm=-100, bool onGround=false)
bool NeedsPrediction(float altitudeKm, float verticalKms, bool active)
bool Allowed(bool simulator, bool groundVehicle, bool airborne, float power)
bool Allows(float radioKm, float densityRatio, float mach)
float Update(float dt, float radioKm, float limitKm)
std::vector< FlapSetting > flapSettings
float turnRadiansPerSecond
bool ObstacleAlert() const
RiseMath::Vector3 position