Rise
The Vieneo Province
Loading...
Searching...
No Matches
Module.h
Go to the documentation of this file.
1#pragma once
2
3// @brief Abstract base class for modules
4// By definition, instruments don't do any of the work (they don't modify bus values)
5// If you have something that takes data like VSI and AGL and then triggers GPWS messages on the bus then that would be in a module
6// It is a computer but not on the component level, it only has access to bus values from other modules
7
8#include "../Bus.h"
9#include "../Sound.h"
10#include "../TcasAudio.h"
11#include "../GpwsBehavior.h"
13
14class Viewscreen;
15
16class Module
17{
19
20protected:
22
23public:
24 Module(Bus* prmBus)
25 {
26 bus = prmBus;
27 };
28
29 // Largest actual frame delta in this scheduled turn; zero for direct callers.
30 float maxFrameSeconds = 0;
31 virtual void FrameMove(float fElapsedTime) = 0;
32
33 // Polymorphism gotcha - if this isn't here then std::vector embedded in derived classes don't clean up!
35 // My theory is that they won't inherit a public destructor if one isn't declared in the base class
36 virtual ~Module() = default;
37};
38
39// Forward definitions for the modules are below
40
41// Ground Proximity Warning System
42class Gpws : public Module
43{
44 Logger* logger = nullptr;
47 bool terrainTrackValid = false;
49 uint64_t terrainDataRevision = 0;
52 void UpdateTerrainAwareness(float seconds);
53 void ScanTerrainAwareness(float seconds);
55 void Evaluate(float seconds);
56 bool terrainRangeActive = false;
57 float previousMapRange = 20;
58
59 float secsincelast = 0.0f;
60 float oldradioaltitude = 0.0f;
61 bool mode3active = false;
62 float mode3altitude = 0.0f;
64 float oldIndicatedAirspeedKms = FLT_MAX;
67 void UpdatePredictiveWindshear(float seconds);
69 bool mode5bactive = false;
70 bool mode6pr = true; // to inhibit on load
71 bool mode6retardArmed = false; // to inhibit on load
72 float groundclose = 0.0f;
73 float oldRadioAltitudeKm = 0.0f;
74 bool reactiveReady = false, takeoffPhase = false;
77 unsigned altitudeCallouts = 0;
82 unsigned bankAnnouncements = 0;
83 int testVehicle = -1;
85 float lastFloorRadio = FLT_MAX, lastFloorGeo = FLT_MAX;
88 bool mode2WasWarning = false, floorValid = false;
89 void ProcessControls(bool powered, bool airborne);
90 bool UpdateSelfTest(float seconds, bool powered, bool airborne);
91 void UpdateFaults();
92 float ClearanceFloor();
93
94public:
95 Gpws(Bus* prmBus, Logger* prmLogger, Viewscreen* prmViewscreen = nullptr);
96 void FrameMove(float fElapsedTime) override;
97};
98
100//class Tcas : public Module
101//{
102//private:
103// float secsincelast = 0;
104// int testProgress = 0;
105//
106//public:
107// explicit Tcas(Bus* prmBus);
108// void FrameMove(float fElapsedTime) override;
109//};
110
111// Voice Messaging Unit
112class Vmu : public Module
113{
114 Logger* logger = nullptr;
115 Sound* sound = nullptr;
116
117 bool powered = false;
118 float secondsPowered = 0.0f;
122 bool playingTerrain = false;
124 bool playingTcasTest = false;
125 bool playingVmuTest = false;
126 bool playingGpwsTest = false;
127 bool playingGpwsHazard = false;
129
130public:
131 Vmu(Bus* prmBus, Logger* prmLogger, Sound* prmSound);
132 void FrameMove(float fElapsedTime) override;
133};
134
136//class Fcs : public Module
137//{
138//private:
139// struct Location
140// {
141// bool priorityButtonDown = false;
142// float priorityHeldDownSec = 0.0f;
143// };
144//
145// std::vector<Location> locations;
146//
147// int ControlPriorityLocation = -1;
148// bool ControlPriorityLatched = false;
149//
150// std::vector<Devices::Joystick*> flightControls;
151//
152// DWORD* fcsFaultPtr = nullptr;
153// float* fcsGetFloatPtr = nullptr;
154//
155//public:
156// Fcs(Bus* prmBus, int joysticks);
157// void Initialize(Devices::Joystick* prmFlightControl);
158// void ConnectComponent(std::string name, std::string guid);
159// void FrameMove(float fElapsedTime) override;
160//};
161//
163//class Fadec : public Module
164//{
165//private:
166// std::vector<Devices::Joystick*> flightControls;
167// Devices::Bass* bass = nullptr;
168//
169// bool engineStart = false;
170// bool engineRun = false;
171// bool engineLit = false;
172// float lightOffTimer = 0.0f;
173// float ignitionTimer = 0.0f;
174// bool engineStopError = false;
175// float engineStopTimer = 0.0f;
176//
177// DWORD* fadecFaultPtr = nullptr;
178// float* fadecGetFloatPtr = nullptr;
179// float* starterSetFloatPtr = nullptr;
180// float* starterGetFloatPtr = nullptr;
181// float* N2SetFloatPtr = nullptr;
182// float* N2GetFloatPtr = nullptr;
183// DWORD* N1FaultPtr = nullptr;
184// float* N1SetFloatPtr = nullptr;
185// float* ignitionSetFloatPtr = nullptr;
186// float* ignitionGetFloatPtr = nullptr;
187// float* combustionSetFloatPtr = nullptr;
188// float* ITTSetFloatPtr = nullptr;
189//
190//public:
191// int soundDevice = -1; // config sets the device id first
192// int joystickAxis = 0;
193// int engineOrdinal = 0;
194// std::string prefix = "Left";
195//
196// Fadec(Bus* prmBus, int prmSoundDevice, int prmAxis, int prmOrdinal, std::string prmPrefix);
197// void Initialize(Devices::Joystick* prmFlightControl, Devices::Bass* prmBass);
198// void ConnectComponent(std::string name, std::string guid);
199// void FrameMove(float fElapsedTime) override;
200//};
201
202// Crew Alerting System
203class Cas : public Module
204{
205 std::vector<Message> messages;
206
207 float secsincelast = -2.0f; // 2 second power up delay
208 int evaluating = 0;
209 bool inhibit = false;
211 float weightOnWheelsTime = 0.0f;
212 float below400Time = 0.0f;
214
215 Logger* logger = nullptr;
216 Sound* sound = nullptr;
217
218 void AcknowledgeAllMessages() const;
219 bool IsMessageOnStack(std::wstring text, MessageLevel level, bool renew) const;
220 bool RemoveMessage(const std::wstring& text, bool onlyIfAcknowledged = false) const;
221 bool AddMessage(const std::wstring& text, MessageLevel level, bool renew);
222
223public:
224 Cas(Bus* prmBus, Logger* prmLogger, Sound* prmSound);
225 void FrameMove(float fElapsedTime) override;
226};
227
228// Ice Detector
229class IceDetector : public Module
230{
231 Logger* logger = nullptr;
232
233 float heatOnTime = 0.0f;
234 float heatOffTime = 0.0f;
235
236public:
237 IceDetector(Bus* prmBus, Logger* prmLogger);
238 void FrameMove(float fElapsedTime) override;
239};
240
241// Radio Tuning Unit
242//class Rtu : public Module
243//{
244//private:
245// Logger* logger;
246//public:
247// Rtu(Bus* prmBus, Logger* prmLogger);
248// void FrameMove(float fElapsedTime) override;
249//};
250//
252//class Mcu : public Module
253//{
254//private:
255// int sequencer = 0;
256// // 0 is off, safe
257// // 1 is caution lights on, wait 5 seconds
258// // 2 is motion power on, wait 5 seconds
259// // 3 is load mid-level, wait 5 seconds
260// // 4 is motion running, watch emer stop
261// // 5 is load mid-level, wait 5 seconds
262// // 6 is load off-level, wait 5 seconds
263// // 7 is motion power off, wait 5 seconds
264// // 8 is caution lights off
265// float timer = 0.0f;
266// int testmode = 0;
267// float* emergencyStopGetPtr = nullptr;
268//
269// struct SSnap
270// {
271// float fl, fr, bl, br;
272// };
273//
274// SSnap Locations[11];
275// SSnap current;
276//
277// Logger* logger;
278//
279//public:
280// Mcu(Bus* prmBus, Logger* prmLogger);
281// void FrameMove(float fElapsedTime) override;
282//};
283//
285//class Pfd : public Module
286//{
287//private:
288// Logger* logger;
289//
290// struct SLight
291// {
292// std::string command;
293// bool currentState, requestedState;
294// int strategy; // 0=off, 1=blink, 2=solid
295// } lights[10];
296//
297// float timer = 0.0f;
298//public:
299// Pfd(Bus* prmBus, Logger* prmLogger);
300// void FrameMove(float fElapsedTime) override;
301//};
302//
304//class Afcs : public Module
305//{
306//private:
307// Logger* logger;
308// Bus* bus;
309// float oldDesiredVsi = 0.0f;
310// const float PitchAggression = 2.0f; // agressiveness for pitch on autopilot (2 is standard)
311// const float RollAggression = 2.0f; // agressiveness for roll on autopilot (1 is standard)
312// const float Vs1 = 0.030f; // kms for speeds
313// bool rightSide = true;
314// float oldRollAttitude = 0.0f;
315// float oldPitchAttitude = 0.0f;
316//
317//public:
318// Afcs(Bus* prmBus, Logger* prmLogger);
319// void FrameMove(float fElapsedTime) override;
320//
321// Afcs& operator=(const Afcs&)
322// {
323// return *this;
324// }
325//};
326//
328//class Ase : public Module
329//{
330//public:
331// struct SVoice
332// {
333// std::string eid;
334// std::string lid;
335// std::string vid;
336// std::string fxtype;
337// std::string fxlevel;
338// };
339//
340// struct SVocalware
341// {
342// std::string acc;
343// std::string api;
344// std::string secret;
345// std::vector<SVoice> voices;
346// };
347//
348//private:
349// UINT currentStep = 0;
350// int subStep = 0;
351// bool scenarioLoaded = false;
352// float occupantControlAuthority = 0.0f;
353// HSTREAM stream = 0;
354//
355// struct SCommand
356// {
357// std::string vmu;
358// UINT voice = 0;
359//
360// std::string name;
361//
362// union
363// {
364// int ivalue;
365// float fvalue;
366// bool bvalue;
367// char svalue[64]; /// @todo union doesn't allow std::string, see note below about emailBody
368// };
369//
370// std::string jump;
371//
372// std::string wait;
373// float timeout = 600.0f;
374// float timeoutLeft;
375// std::string timeoutStep;
376// DWORD conditionsMet;
377//
378// std::string help;
379// std::string element;
380// };
381//
382// struct SStep
383// {
384// std::string name;
385// std::vector<SCommand> commands;
386// };
387//
388// std::vector<SStep> steps;
389//
390//
391// Bus* bus;
392// Logger* logger;
393// Devices::Bass* bass = nullptr;
394// SVocalware vocalware;
395//
396// void Ase::LoadScenario(std::string path);
397// bool Ase::GenerateTextToSpeech(std::string url, UINT voice, std::string outputPath);
398// UINT Ase::FindStep(std::string stepName);
399// void Ase::AdvanceToNextStep();
400//
401//public:
402// int soundDevice = -1; // config sets the device id first
403// Ase(Bus* prmBus, Logger* prmLogger, int prmSoundDevice, SVocalware vocalware);
404// void Initialize(Devices::Bass* prmBass);
405// void FrameMove(float fElapsedTime) override;
406//};
407//
409//class Fms : public Module
410//{
411//private:
412// Logger* logger;
413// Bus* bus;
414//
415//public:
416// Fms(Bus* prmBus, Logger* prmLogger);
417// void FrameMove(float fElapsedTime) override;
418//};
419//
421//class Fdr : public Module
422//{
423//private:
424// Logger* logger;
425// Bus* bus;
426// float secSinceLast = 0.0f;
427// int fdrfile;
428//
429//public:
430// Fdr(Bus* prmBus, Logger* prmLogger);
431// void FrameMove(float fElapsedTime) override;
432// ~Fdr();
433//};
434//
436//class Door : public Module
437//{
438//private:
439// Logger* logger;
440// Bus* bus;
441//
442// bool open = false;
443// float timeSinceLast = 0.0f;
444//
445// float* sensorPsi = nullptr;
446// float* doorSensor = nullptr;
447// float* compressorOn = nullptr;
448//
449// float dutyTime = 0.0f;
450//
451//public:
452// Door(Bus* prmBus, Logger* prmLogger);
453// void FrameMove(float fElapsedTime) override;
454// ~Door();
455//};
456//
458//class Logo : public Module
459//{
460//private:
461// Logger* logger;
462// Bus* bus;
463// float latitude = 0.0f, longitude = 0.0f, altitudeFeet = 0.0f, zenithDegrees = 0.0f;
464// float timeSinceLast = 60.0f;
465//
466// float* sunrise = nullptr;
467// float* sunset = nullptr;
468// float* status = nullptr;
469//
470// time_t t = 0;
471// tm* lt = nullptr;
472// TIME_ZONE_INFORMATION tz;
473// Library::Solar solar;
474// CTime cTime;
475//
476//public:
477// Logo(Bus* prmBus, Logger* prmLogger, float prmLatitude, float prmLongitude, float prmAltitudeFeet, float prmZenithDegrees);
478// void FrameMove(float fElapsedTime) override;
479// ~Logo();
480//};
481
482class MarkerBeacons : public Module
483{
484 Logger* logger = nullptr;
485 Sound* sound = nullptr;
486
488
489 void Check(const RiseMath::Vector3& marker) const;
490
491public:
492 MarkerBeacons(Bus* prmBus, Logger* prmLogger, Sound* prmSound);
493 void FrameMove(float fElapsedTime) override;
494};
495
496class TCAS : public Module
497{
498 Logger* logger = nullptr;
499 struct Track
500 {
501 bool valid = false;
502 unsigned short vehicleId = 0;
504 float altitude = 0.0f;
507 float advanceframe = 0.0f;
508 float advisoryAge = 0.0f;
509 float reactionDelay = 5.0f;
510 int sense = 0;
511 int threatId = -1;
512 bool positiveIssued = false;
513 bool weakened = false;
516 void ResetAdvisory();
517 void SetAdvisory(Bus::TcasEnum mode, int target, float rate = 0.0f, bool crossing = false);
518
519public:
520 TCAS(Bus* prmBus, Logger* prmLogger, RiseMath::Matrix* prmMatrixView);
521 void FrameMove(float fElapsedTime) override;
522};
MessageLevel
Definition Message.h:6
#define MAX_SCAN
Reference
Definition ServerTypes.h:40
@ REF_ACLMODE
Definition ServerTypes.h:44
SOUNDS
Definition Sound.h:23
@ SOUND_AURALUNITOKAY
Definition Sound.h:114
@ SOUND_NONE
Definition Sound.h:24
Definition Bus.h:20
TcasEnum
Definition Bus.h:322
@ Clear_Of_Conflict
Definition Bus.h:323
MarkerBeaconTypes
(29) Marker beacon passage;
Definition Bus.h:163
@ None
Definition Bus.h:164
bool IsMessageOnStack(std::wstring text, MessageLevel level, bool renew) const
Definition CAS.cpp:511
Logger * logger
Definition Module.h:215
WCHAR temporaryMessage[99]
Definition Module.h:213
Sound * sound
Definition Module.h:216
Cas(Bus *prmBus, Logger *prmLogger, Sound *prmSound)
Definition CAS.cpp:5
float weightOnWheelsTime
Definition Module.h:211
float secsincelast
Definition Module.h:207
void FrameMove(float fElapsedTime) override
Definition CAS.cpp:11
std::vector< Message > messages
Definition Module.h:205
float weightOffWheelsTime
Definition Module.h:210
bool AddMessage(const std::wstring &text, MessageLevel level, bool renew)
Definition CAS.cpp:547
void AcknowledgeAllMessages() const
Definition CAS.cpp:502
int evaluating
Definition Module.h:208
bool RemoveMessage(const std::wstring &text, bool onlyIfAcknowledged=false) const
Definition CAS.cpp:531
bool inhibit
Definition Module.h:209
float below400Time
Definition Module.h:212
GpwsPredictiveWindshear::Detector predictiveWindshear
Definition Module.h:66
Gpws(Bus *prmBus, Logger *prmLogger, Viewscreen *prmViewscreen=nullptr)
Definition GPWS.cpp:47
GpwsWindshear::Detector windshear
Definition Module.h:65
uint64_t terrainDataRevision
Definition Module.h:49
int testVehicle
Definition Module.h:83
bool mode3active
Definition Module.h:61
float testSeconds
Definition Module.h:84
void UpdateTerrainAwareness(float seconds)
bool terrainTrackValid
Definition Module.h:47
GpwsBehavior::ClearanceHistory clearanceHistory
Definition Module.h:78
bool floorValid
Definition Module.h:88
void Evaluate(float seconds)
Definition GPWS.cpp:68
float fieldCalloutHeight
Definition Module.h:86
unsigned bankAnnouncements
Definition Module.h:82
void UpdatePredictiveWindshear(float seconds)
float previousFieldHeight
Definition Module.h:86
bool terrainRangeActive
Definition Module.h:56
float ClearanceFloor()
float takeoffSeconds
Definition Module.h:76
float mode2LatchSeconds
Definition Module.h:84
GpwsBehavior::BankFlightEnvelope bankFlightEnvelope
Definition Module.h:79
bool mode6retardArmed
Definition Module.h:71
float previousMapRange
Definition Module.h:57
bool mode6pr
Definition Module.h:70
Viewscreen * viewscreen
Definition Module.h:45
unsigned altitudeCallouts
Definition Module.h:77
unsigned previousFaults
Definition Module.h:87
int reactiveVehicle
Definition Module.h:75
void ProcessControls(bool powered, bool airborne)
float lastFloorHeight
Definition Module.h:86
float predictiveWindVoiceSeconds
Definition Module.h:68
float terrainVoiceSeconds
Definition Module.h:50
float mode2LatchAltitude
Definition Module.h:84
float lastFloorGeo
Definition Module.h:85
bool mode5bactive
Definition Module.h:69
float secsincelast
Definition Module.h:59
RiseMath::Vector3 oldTerrainForward
Definition Module.h:46
float oldRadioAltitudeKm
Definition Module.h:73
float oldradioaltitude
Definition Module.h:60
bool UpdateSelfTest(float seconds, bool powered, bool airborne)
float lastDeclutterValue
Definition Module.h:81
float previousVerticalKms
Definition Module.h:76
bool takeoffPhase
Definition Module.h:74
TerrainAwareness::AlertStability terrainStability
Definition Module.h:54
Reference oldReference
Definition Module.h:63
void ScanTerrainAwareness(float seconds)
bool reactiveReady
Definition Module.h:74
void UpdateFaults()
float lastFloorRadio
Definition Module.h:85
float mode3altitude
Definition Module.h:62
unsigned mode3Announcements
Definition Module.h:87
Bus::Gpws::GpwsEnum lastTerrainVoice
Definition Module.h:51
bool mode2WasWarning
Definition Module.h:88
float oldIndicatedAirspeedKms
Definition Module.h:64
void FrameMove(float fElapsedTime) override
Definition GPWS.cpp:52
Logger * logger
Definition Module.h:44
int terrainVehicle
Definition Module.h:48
float groundclose
Definition Module.h:72
Bus::Gpws::GpwsEnum lastDeclutterAlert
Definition Module.h:80
float lastAltitudeLoss
Definition Module.h:86
unsigned previousDiscretes
Definition Module.h:87
float heatOffTime
Definition Module.h:234
Logger * logger
Definition Module.h:231
void FrameMove(float fElapsedTime) override
float heatOnTime
Definition Module.h:233
IceDetector(Bus *prmBus, Logger *prmLogger)
MarkerBeacons(Bus *prmBus, Logger *prmLogger, Sound *prmSound)
Logger * logger
Definition Module.h:484
void Check(const RiseMath::Vector3 &marker) const
Sound * sound
Definition Module.h:485
Bus::MarkerBeaconTypes oldPlaying
Definition Module.h:487
void FrameMove(float fElapsedTime) override
virtual ~Module()=default
Module(Bus *prmBus)
Definition Module.h:24
virtual void FrameMove(float fElapsedTime)=0
Bus * bus
Definition Module.h:21
float maxFrameSeconds
Definition Module.h:30
Definition Sound.h:369
int testVehicleId
Definition Module.h:515
TcasAudio::TestSequence testSequence
Definition Module.h:514
float advanceframe
Definition Module.h:507
void FrameMove(float fElapsedTime) override
Definition TCAS.cpp:156
int sense
Definition Module.h:510
void ResetAdvisory()
Definition TCAS.cpp:95
float advisoryAge
Definition Module.h:508
struct TCAS::Track tracks[MAX_SCAN]
Logger * logger
Definition Module.h:498
float reactionDelay
Definition Module.h:509
int threatId
Definition Module.h:511
bool weakened
Definition Module.h:513
Bus::TcasEnum tcasmode
Definition Module.h:506
void SetAdvisory(Bus::TcasEnum mode, int target, float rate=0.0f, bool crossing=false)
Definition TCAS.cpp:112
bool positiveIssued
Definition Module.h:512
TCAS(Bus *prmBus, Logger *prmLogger, RiseMath::Matrix *prmMatrixView)
Definition TCAS.cpp:90
bool playingGpwsHazard
Definition Module.h:127
Vmu(Bus *prmBus, Logger *prmLogger, Sound *prmSound)
Definition VMU.cpp:308
bool playingPredictiveWind
Definition Module.h:123
int playingVehicle
Definition Module.h:128
bool powered
Definition Module.h:117
void FrameMove(float fElapsedTime) override
Definition VMU.cpp:5
bool playingTcasTest
Definition Module.h:124
bool playingVmuTest
Definition Module.h:125
SOUNDS playingVoice
Definition Module.h:121
bool playingGpwsTest
Definition Module.h:126
bool playingTerrain
Definition Module.h:122
float secondsPowered
Definition Module.h:118
SOUNDS playingTcas
Definition Module.h:120
Logger * logger
Definition Module.h:114
Sound * sound
Definition Module.h:115
SOUNDS testMode
Definition Module.h:119
GpwsEnum
Definition Bus.h:189
@ NoAlert
Definition Bus.h:190
float altitude
Definition Module.h:504
RiseMath::Vector3 relative
Definition Module.h:503
unsigned short vehicleId
Definition Module.h:502
bool valid
Definition Module.h:501