Rise
The Vieneo Province
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 "../GridProperties.h"
10 #include "../Sound.h"
11 
12 class Module
13 {
14  Module();
15 
16 protected:
17  Bus* bus;
18 
19 public:
20  Module(Bus* prmBus)
21  {
22  bus = prmBus;
23  };
24 
25  virtual void FrameMove(float fElapsedTime) = 0;
26 
27  // Polymorphism gotcha - if this isn't here then std::vector embedded in derived classes don't clean up!
29  // My theory is that they won't inherit a public destructor if one isn't declared in the base class
30  virtual ~Module() = default;;
31 };
32 
33 // Forward definitions for the modules are below
34 
35 // Ground Proximity Warning System
36 class Gpws : public Module
37 {
38  Logger* logger = nullptr;
39 
40  float secsincelast = 0.0f;
41  float oldradioaltitude = 0.0f;
42  bool mode3active = false;
43  float mode3altitude = 0.0f;
44  Reference oldReference = REF_ACLMODE;
45  float oldIndicatedAirspeedKms = FLT_MAX;
46  float oldWindSpeedMs = 0.0f;
47 
48 public:
49  Gpws(Bus* prmBus, Logger* prmLogger);
50  void FrameMove(float fElapsedTime) override;
51 };
52 
54 //class Tcas : public Module
55 //{
56 //private:
57 // float secsincelast = 0;
58 // int testProgress = 0;
59 //
60 //public:
61 // explicit Tcas(Bus* prmBus);
62 // void FrameMove(float fElapsedTime) override;
63 //};
64 
65 // Voice Messaging Unit
66 class Vmu : public Module
67 {
68  Logger* logger = nullptr;
69  Sound* sound = nullptr;
70 
71  float holdForSeconds = 0;
72  bool powered = false;
73  float secondsPowered = 0.0f;
75 
76 public:
77  Vmu(Bus* prmBus, Logger* prmLogger, Sound* prmSound);
78  void FrameMove(float fElapsedTime) override;
79 };
80 
82 //class Fcs : public Module
83 //{
84 //private:
85 // struct Location
86 // {
87 // bool priorityButtonDown = false;
88 // float priorityHeldDownSec = 0.0f;
89 // };
90 //
91 // std::vector<Location> locations;
92 //
93 // int ControlPriorityLocation = -1;
94 // bool ControlPriorityLatched = false;
95 //
96 // std::vector<Devices::Joystick*> flightControls;
97 //
98 // DWORD* fcsFaultPtr = nullptr;
99 // float* fcsGetFloatPtr = nullptr;
100 //
101 //public:
102 // Fcs(Bus* prmBus, int joysticks);
103 // void Initialize(Devices::Joystick* prmFlightControl);
104 // void ConnectComponent(std::string name, std::string guid);
105 // void FrameMove(float fElapsedTime) override;
106 //};
107 //
109 //class Fadec : public Module
110 //{
111 //private:
112 // std::vector<Devices::Joystick*> flightControls;
113 // Devices::Bass* bass = nullptr;
114 //
115 // bool engineStart = false;
116 // bool engineRun = false;
117 // bool engineLit = false;
118 // float lightOffTimer = 0.0f;
119 // float ignitionTimer = 0.0f;
120 // bool engineStopError = false;
121 // float engineStopTimer = 0.0f;
122 //
123 // DWORD* fadecFaultPtr = nullptr;
124 // float* fadecGetFloatPtr = nullptr;
125 // float* starterSetFloatPtr = nullptr;
126 // float* starterGetFloatPtr = nullptr;
127 // float* N2SetFloatPtr = nullptr;
128 // float* N2GetFloatPtr = nullptr;
129 // DWORD* N1FaultPtr = nullptr;
130 // float* N1SetFloatPtr = nullptr;
131 // float* ignitionSetFloatPtr = nullptr;
132 // float* ignitionGetFloatPtr = nullptr;
133 // float* combustionSetFloatPtr = nullptr;
134 // float* ITTSetFloatPtr = nullptr;
135 //
136 //public:
137 // int soundDevice = -1; // config sets the device id first
138 // int joystickAxis = 0;
139 // int engineOrdinal = 0;
140 // std::string prefix = "Left";
141 //
142 // Fadec(Bus* prmBus, int prmSoundDevice, int prmAxis, int prmOrdinal, std::string prmPrefix);
143 // void Initialize(Devices::Joystick* prmFlightControl, Devices::Bass* prmBass);
144 // void ConnectComponent(std::string name, std::string guid);
145 // void FrameMove(float fElapsedTime) override;
146 //};
147 
148 // Crew Alerting System
149 class Cas : public Module
150 {
151  std::vector<Message> messages;
152 
153  float secsincelast = -2.0f; // 2 second power up delay
154  int evaluating = 0;
155  bool inhibit = false;
156  float weightOffWheelsTime = 0.0f;
157  float weightOnWheelsTime = 0.0f;
158  float below400Time = 0.0f;
159  WCHAR temporaryMessage[99];
160 
161  Logger* logger = nullptr;
162  Sound* sound = nullptr;
163 
164  void AcknowledgeAllMessages() const;
165  bool IsMessageOnStack(std::wstring text, MessageLevel level, bool renew) const;
166  bool RemoveMessage(const std::wstring& text, bool onlyIfAcknowledged = false) const;
167  bool AddMessage(const std::wstring& text, MessageLevel level, bool renew);
168 
169 public:
170  Cas(Bus* prmBus, Logger* prmLogger, Sound* prmSound);
171  void FrameMove(float fElapsedTime) override;
172 };
173 
174 // Ice Detector
175 class IceDetector : public Module
176 {
177  Logger* logger = nullptr;
178 
179  float heatOnTime = 0.0f;
180  float heatOffTime = 0.0f;
181 
182 public:
183  IceDetector(Bus* prmBus, Logger* prmLogger);
184  void FrameMove(float fElapsedTime) override;
185 };
186 
187 // Radio Tuning Unit
188 //class Rtu : public Module
189 //{
190 //private:
191 // Logger* logger;
192 //public:
193 // Rtu(Bus* prmBus, Logger* prmLogger);
194 // void FrameMove(float fElapsedTime) override;
195 //};
196 //
198 //class Mcu : public Module
199 //{
200 //private:
201 // int sequencer = 0;
202 // // 0 is off, safe
203 // // 1 is caution lights on, wait 5 seconds
204 // // 2 is motion power on, wait 5 seconds
205 // // 3 is load mid-level, wait 5 seconds
206 // // 4 is motion running, watch emer stop
207 // // 5 is load mid-level, wait 5 seconds
208 // // 6 is load off-level, wait 5 seconds
209 // // 7 is motion power off, wait 5 seconds
210 // // 8 is caution lights off
211 // float timer = 0.0f;
212 // int testmode = 0;
213 // float* emergencyStopGetPtr = nullptr;
214 //
215 // struct SSnap
216 // {
217 // float fl, fr, bl, br;
218 // };
219 //
220 // SSnap Locations[11];
221 // SSnap current;
222 //
223 // Logger* logger;
224 //
225 //public:
226 // Mcu(Bus* prmBus, Logger* prmLogger);
227 // void FrameMove(float fElapsedTime) override;
228 //};
229 //
231 //class Pfd : public Module
232 //{
233 //private:
234 // Logger* logger;
235 //
236 // struct SLight
237 // {
238 // std::string command;
239 // bool currentState, requestedState;
240 // int strategy; // 0=off, 1=blink, 2=solid
241 // } lights[10];
242 //
243 // float timer = 0.0f;
244 //public:
245 // Pfd(Bus* prmBus, Logger* prmLogger);
246 // void FrameMove(float fElapsedTime) override;
247 //};
248 //
250 //class Afcs : public Module
251 //{
252 //private:
253 // Logger* logger;
254 // Bus* bus;
255 // float oldDesiredVsi = 0.0f;
256 // const float PitchAggression = 2.0f; // agressiveness for pitch on autopilot (2 is standard)
257 // const float RollAggression = 2.0f; // agressiveness for roll on autopilot (1 is standard)
258 // const float Vs1 = 0.030f; // kms for speeds
259 // bool rightSide = true;
260 // float oldRollAttitude = 0.0f;
261 // float oldPitchAttitude = 0.0f;
262 //
263 //public:
264 // Afcs(Bus* prmBus, Logger* prmLogger);
265 // void FrameMove(float fElapsedTime) override;
266 //
267 // Afcs& operator=(const Afcs&)
268 // {
269 // return *this;
270 // }
271 //};
272 //
274 //class Ase : public Module
275 //{
276 //public:
277 // struct SVoice
278 // {
279 // std::string eid;
280 // std::string lid;
281 // std::string vid;
282 // std::string fxtype;
283 // std::string fxlevel;
284 // };
285 //
286 // struct SVocalware
287 // {
288 // std::string acc;
289 // std::string api;
290 // std::string secret;
291 // std::vector<SVoice> voices;
292 // };
293 //
294 //private:
295 // UINT currentStep = 0;
296 // int subStep = 0;
297 // bool scenarioLoaded = false;
298 // float occupantControlAuthority = 0.0f;
299 // HSTREAM stream = 0;
300 //
301 // struct SCommand
302 // {
303 // std::string vmu;
304 // UINT voice = 0;
305 //
306 // std::string name;
307 //
308 // union
309 // {
310 // int ivalue;
311 // float fvalue;
312 // bool bvalue;
313 // char svalue[64]; /// @todo union doesn't allow std::string, see note below about emailBody
314 // };
315 //
316 // std::string jump;
317 //
318 // std::string wait;
319 // float timeout = 600.0f;
320 // float timeoutLeft;
321 // std::string timeoutStep;
322 // DWORD conditionsMet;
323 //
324 // std::string help;
325 // std::string element;
326 // };
327 //
328 // struct SStep
329 // {
330 // std::string name;
331 // std::vector<SCommand> commands;
332 // };
333 //
334 // std::vector<SStep> steps;
335 //
336 //
337 // Bus* bus;
338 // Logger* logger;
339 // Devices::Bass* bass = nullptr;
340 // SVocalware vocalware;
341 //
342 // void Ase::LoadScenario(std::string path);
343 // bool Ase::GenerateTextToSpeech(std::string url, UINT voice, std::string outputPath);
344 // UINT Ase::FindStep(std::string stepName);
345 // void Ase::AdvanceToNextStep();
346 //
347 //public:
348 // int soundDevice = -1; // config sets the device id first
349 // Ase(Bus* prmBus, Logger* prmLogger, int prmSoundDevice, SVocalware vocalware);
350 // void Initialize(Devices::Bass* prmBass);
351 // void FrameMove(float fElapsedTime) override;
352 //};
353 //
355 //class Fms : public Module
356 //{
357 //private:
358 // Logger* logger;
359 // Bus* bus;
360 //
361 //public:
362 // Fms(Bus* prmBus, Logger* prmLogger);
363 // void FrameMove(float fElapsedTime) override;
364 //};
365 //
367 //class Fdr : public Module
368 //{
369 //private:
370 // Logger* logger;
371 // Bus* bus;
372 // float secSinceLast = 0.0f;
373 // int fdrfile;
374 //
375 //public:
376 // Fdr(Bus* prmBus, Logger* prmLogger);
377 // void FrameMove(float fElapsedTime) override;
378 // ~Fdr();
379 //};
380 //
382 //class Door : public Module
383 //{
384 //private:
385 // Logger* logger;
386 // Bus* bus;
387 //
388 // bool open = false;
389 // float timeSinceLast = 0.0f;
390 //
391 // float* sensorPsi = nullptr;
392 // float* doorSensor = nullptr;
393 // float* compressorOn = nullptr;
394 //
395 // float dutyTime = 0.0f;
396 //
397 //public:
398 // Door(Bus* prmBus, Logger* prmLogger);
399 // void FrameMove(float fElapsedTime) override;
400 // ~Door();
401 //};
402 //
404 //class Logo : public Module
405 //{
406 //private:
407 // Logger* logger;
408 // Bus* bus;
409 // float latitude = 0.0f, longitude = 0.0f, altitudeFeet = 0.0f, zenithDegrees = 0.0f;
410 // float timeSinceLast = 60.0f;
411 //
412 // float* sunrise = nullptr;
413 // float* sunset = nullptr;
414 // float* status = nullptr;
415 //
416 // time_t t = 0;
417 // tm* lt = nullptr;
418 // TIME_ZONE_INFORMATION tz;
419 // Library::Solar solar;
420 // CTime cTime;
421 //
422 //public:
423 // Logo(Bus* prmBus, Logger* prmLogger, float prmLatitude, float prmLongitude, float prmAltitudeFeet, float prmZenithDegrees);
424 // void FrameMove(float fElapsedTime) override;
425 // ~Logo();
426 //};
427 
428 class MarkerBeacons : public Module
429 {
430  Logger* logger = nullptr;
431  Sound* sound = nullptr;
432 
433  Bus::MarkerBeaconTypes checking = Bus::MarkerBeaconTypes::None;
435 
436  void Check(const D3DXVECTOR3& marker) const;
437 
438 public:
439  MarkerBeacons(Bus* prmBus, Logger* prmLogger, Sound* prmSound, GridProperties* prmGridProperties);
440  void FrameMove(float fElapsedTime) override;
441 };
442 
443 class TCAS : public Module
444 {
445  Logger* logger = nullptr;
446  D3DXMATRIX* matrixView = nullptr;
447 
448  Bus::TcasEnum tcasmode = Bus::TcasEnum::Clear_Of_Conflict;
449  float secsincelast = 0.0f;
450  float coctime = 0.0f;
451  float advanceframe = 0.0f;
452  float olddistance[MAX_SCAN];
453 
454 public:
455  TCAS(Bus* prmBus, Logger* prmLogger, D3DXMATRIX* prmMatrixView);
456  void FrameMove(float fElapsedTime) override;
457 };
void FrameMove(float fElapsedTime) override
Definition: TCAS.cpp:11
bool inhibit
Definition: Module.h:155
Definition: Sound.h:276
MarkerBeaconTypes
(29) Marker beacon passage;
Definition: Bus.h:139
D3DXMATRIX * matrixView
Definition: Module.h:446
Sound * sound
Definition: Module.h:69
Bus::TcasEnum tcasmode
Definition: Module.h:448
float oldradioaltitude
Definition: Module.h:41
Definition: Logger.h:9
TCAS(Bus *prmBus, Logger *prmLogger, D3DXMATRIX *prmMatrixView)
Definition: TCAS.cpp:3
MarkerBeacons(Bus *prmBus, Logger *prmLogger, Sound *prmSound, GridProperties *prmGridProperties)
Definition: Module.h:443
bool powered
Definition: Module.h:72
Definition: Module.h:149
MessageLevel
Definition: Message.h:5
void FrameMove(float fElapsedTime) override
Definition: IceDetector.cpp:12
void FrameMove(float fElapsedTime) override
Definition: VMU.cpp:3
int evaluating
Definition: Module.h:154
float below400Time
Definition: Module.h:158
void FrameMove(float fElapsedTime) override
void FrameMove(float fElapsedTime) override
Definition: GPWS.cpp:34
Module(Bus *prmBus)
Definition: Module.h:20
void FrameMove(float fElapsedTime) override
Definition: CAS.cpp:10
float secsincelast
Definition: Module.h:40
Gpws(Bus *prmBus, Logger *prmLogger)
Definition: GPWS.cpp:29
bool IsMessageOnStack(std::wstring text, MessageLevel level, bool renew) const
Definition: CAS.cpp:340
Logger * logger
Definition: Module.h:68
float coctime
Definition: Module.h:450
TcasEnum
Definition: Bus.h:243
Definition: Bus.h:16
float heatOnTime
Definition: Module.h:179
Logger * logger
Definition: Module.h:445
float weightOnWheelsTime
Definition: Module.h:157
virtual void FrameMove(float fElapsedTime)=0
WCHAR temporaryMessage[99]
Definition: Module.h:159
bool mode3active
Definition: Module.h:42
float advanceframe
Definition: Module.h:451
float oldWindSpeedMs
Definition: Module.h:46
float weightOffWheelsTime
Definition: Module.h:156
Definition: Module.h:36
Reference oldReference
Definition: Module.h:44
float holdForSeconds
Definition: Module.h:71
Definition: Module.h:12
std::vector< Message > messages
Definition: Module.h:151
Bus::MarkerBeaconTypes checking
Definition: Module.h:433
Definition: Module.h:66
float olddistance[MAX_SCAN]
Definition: Module.h:452
float mode3altitude
Definition: Module.h:43
Sound * sound
Definition: Module.h:162
bool AddMessage(const std::wstring &text, MessageLevel level, bool renew)
Definition: CAS.cpp:376
bool RemoveMessage(const std::wstring &text, bool onlyIfAcknowledged=false) const
Definition: CAS.cpp:360
Vmu(Bus *prmBus, Logger *prmLogger, Sound *prmSound)
Definition: VMU.cpp:165
IceDetector(Bus *prmBus, Logger *prmLogger)
Definition: IceDetector.cpp:3
Bus * bus
Definition: Module.h:17
float secsincelast
Definition: Module.h:449
float secondsPowered
Definition: Module.h:73
float oldIndicatedAirspeedKms
Definition: Module.h:45
int testMode
Definition: Module.h:74
Cas(Bus *prmBus, Logger *prmLogger, Sound *prmSound)
Definition: CAS.cpp:4
Logger * logger
Definition: Module.h:38
Logger * logger
Definition: Module.h:430
float secsincelast
Definition: Module.h:153
virtual ~Module()=default
void AcknowledgeAllMessages() const
Definition: CAS.cpp:331
GridProperties * gridProperties
Definition: Module.h:434
Logger * logger
Definition: Module.h:177
Sound * sound
Definition: Module.h:431
void Check(const D3DXVECTOR3 &marker) const
Logger * logger
Definition: Module.h:161
float heatOffTime
Definition: Module.h:180