Avionics
Dropship Simulator
Module.h
Go to the documentation of this file.
1 #include "..\Bass.h"
6 #include "..\Joystick.h"
7 #include "Watch.h"
8 #include "../Library/Solar.h"
9 #include <atltime.h>
10 
11 class Module
12 {
13 private:
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 
30  virtual ~Module()
31  {
32  };
33 };
34 
36 
38 class Gpws : public Module
39 {
40 private:
41  float secsincelast = 0;
42 
43 public:
44  explicit Gpws(Bus* prmBus);
45  void FrameMove(float fElapsedTime) override;
46 };
47 
49 class Tcas : public Module
50 {
51 private:
52  float secsincelast = 0;
53  int testProgress = 0;
54 
55 public:
56  explicit Tcas(Bus* prmBus);
57  void FrameMove(float fElapsedTime) override;
58 };
59 
61 class Vmu : public Module
62 {
63 private:
64  Devices::Bass* bass = nullptr; // then initialize wires up the device pointer
65  float secsincelast = 0; // TimeSinceAuralWarning was static back in the Viewscreen days
66 
67  float* vmuGetFloatPtr = nullptr;
68  bool powered = false;
69  float secondsPowered = 0.0f;
70 
71 public:
72  int soundDevice = -1; // config sets the device id first
73 
74  Vmu(Bus* prmBus, int bassLocation, float* prmGetFloatPtr);
75  void Initialize(Devices::Bass* prmBass);
76  void FrameMove(float fElapsedTime) override;
77 };
78 
80 class Fcs : public Module
81 {
82 private:
83  struct Location
84  {
85  bool priorityButtonDown = false;
86  float priorityHeldDownSec = 0.0f;
87  };
88 
89  std::vector<Location> locations;
90 
92  bool ControlPriorityLatched = false;
93 
94  std::vector<Devices::Joystick*> flightControls;
95 
96  DWORD* fcsFaultPtr = nullptr;
97  float* fcsGetFloatPtr = nullptr;
98 
99 public:
100  Fcs(Bus* prmBus, int joysticks);
101  void Initialize(Devices::Joystick* prmFlightControl);
102  void ConnectComponent(std::string name, std::string guid);
103  void FrameMove(float fElapsedTime) override;
104 };
105 
107 class Fadec : public Module
108 {
109 private:
110  std::vector<Devices::Joystick*> flightControls;
111  Devices::Bass* bass = nullptr;
112 
113  bool engineStart = false;
114  bool engineRun = false;
115  bool engineLit = false;
116  float lightOffTimer = 0.0f;
117  float ignitionTimer = 0.0f;
118  bool engineStopError = false;
119  float engineStopTimer = 0.0f;
120 
121  DWORD* fadecFaultPtr = nullptr;
122  float* fadecGetFloatPtr = nullptr;
123  float* starterSetFloatPtr = nullptr;
124  float* starterGetFloatPtr = nullptr;
125  float* N2SetFloatPtr = nullptr;
126  float* N2GetFloatPtr = nullptr;
127  DWORD* N1FaultPtr = nullptr;
128  float* N1SetFloatPtr = nullptr;
129  float* ignitionSetFloatPtr = nullptr;
130  float* ignitionGetFloatPtr = nullptr;
131  float* combustionSetFloatPtr = nullptr;
132  float* ITTSetFloatPtr = nullptr;
133 
134 public:
135  int soundDevice = -1; // config sets the device id first
136  int joystickAxis = 0;
137  int engineOrdinal = 0;
138  std::string prefix = "Left";
139 
140  Fadec(Bus* prmBus, int prmSoundDevice, int prmAxis, int prmOrdinal, std::string prmPrefix);
141  void Initialize(Devices::Joystick* prmFlightControl, Devices::Bass* prmBass);
142  void ConnectComponent(std::string name, std::string guid);
143  void FrameMove(float fElapsedTime) override;
144 };
145 
147 class Cas : public Module
148 {
149 private:
150  std::vector<Message> messages;
151  bool MessageFlashState = false;
152 
153  float secsincelast = -2.0f;
154  float secsincereset = 0.0f;
155  Logger* logger = nullptr;
156  std::vector<Watch> watches;
157 
158  float* casGetFloatPtr = nullptr;
159  bool powered = false;
160 
161  void AcknowledgeAllMessages() const;
163  bool IsMessageOnStack(std::wstring text, bool renew) const;
164  bool RemoveMessage(std::wstring text) const;
165  void AddMessage(std::wstring text, MessageLevel level, bool sendEmail);
166 
167 public:
168 
169  Cas(Bus* prmBus, Logger* prmLogger, std::vector<Watch> watches, float* prmCasGetFloatPtr);
170  void FrameMove(float fElapsedTime) override;
171 };
172 
174 class Rtu : public Module
175 {
176 private:
178 public:
179  Rtu(Bus* prmBus, Logger* prmLogger);
180  void FrameMove(float fElapsedTime) override;
181 };
182 
184 class Mcu : public Module
185 {
186 private:
187  int sequencer = 0;
188  // 0 is off, safe
189  // 1 is caution lights on, wait 5 seconds
190  // 2 is motion power on, wait 5 seconds
191  // 3 is load mid-level, wait 5 seconds
192  // 4 is motion running, watch emer stop
193  // 5 is load mid-level, wait 5 seconds
194  // 6 is load off-level, wait 5 seconds
195  // 7 is motion power off, wait 5 seconds
196  // 8 is caution lights off
197  float timer = 0.0f;
198  int testmode = 0;
199  float* emergencyStopGetPtr = nullptr;
200 
201  struct SSnap
202  {
203  float fl, fr, bl, br;
204  };
205 
208 
210 
211 public:
212  Mcu(Bus* prmBus, Logger* prmLogger);
213  void FrameMove(float fElapsedTime) override;
214 };
215 
217 class Pfd : public Module
218 {
219 private:
221 
222  struct SLight
223  {
224  std::string command;
226  int strategy; // 0=off, 1=blink, 2=solid
227  } lights[10];
228 
229  float timer = 0.0f;
230 public:
231  Pfd(Bus* prmBus, Logger* prmLogger);
232  void FrameMove(float fElapsedTime) override;
233 };
234 
236 class Afcs : public Module
237 {
238 private:
241  float oldDesiredVsi = 0.0f;
242  const float PitchAggression = 2.0f; // agressiveness for pitch on autopilot (2 is standard)
243  const float RollAggression = 2.0f; // agressiveness for roll on autopilot (1 is standard)
244  const float Vs1 = 0.030f; // kms for speeds
245  bool rightSide = true;
246  float oldRollAttitude = 0.0f;
247  float oldPitchAttitude = 0.0f;
248 
249 public:
250  Afcs(Bus* prmBus, Logger* prmLogger);
251  void FrameMove(float fElapsedTime) override;
252 
253  Afcs& operator=(const Afcs&)
254  {
255  return *this;
256  }
257 };
258 
260 class Ase : public Module
261 {
262 public:
263  struct SVoice
264  {
265  std::string eid;
266  std::string lid;
267  std::string vid;
268  std::string fxtype;
269  std::string fxlevel;
270  };
271 
272  struct SVocalware
273  {
274  std::string acc;
275  std::string api;
276  std::string secret;
277  std::vector<SVoice> voices;
278  };
279 
280 private:
281  UINT currentStep = 0;
282  int subStep = 0;
283  bool scenarioLoaded = false;
285  HSTREAM stream = 0;
286 
287  struct SCommand
288  {
289  std::string vmu;
290  UINT voice = 0;
291 
292  std::string name;
293 
294  union
295  {
296  int ivalue;
297  float fvalue;
298  bool bvalue;
299  char svalue[64];
300  };
301 
302  std::string jump;
303 
304  std::string wait;
305  float timeout = 600.0f;
306  float timeoutLeft;
307  std::string timeoutStep;
309 
310  std::string help;
311  std::string element;
312  };
313 
314  struct SStep
315  {
316  std::string name;
317  std::vector<SCommand> commands;
318  };
319 
320  std::vector<SStep> steps;
321 
322 
325  Devices::Bass* bass = nullptr;
327 
328  void Ase::LoadScenario(std::string path);
329  bool Ase::GenerateTextToSpeech(std::string url, UINT voice, std::string outputPath);
330  UINT Ase::FindStep(std::string stepName);
331  void Ase::AdvanceToNextStep();
332 
333 public:
334  int soundDevice = -1; // config sets the device id first
335  Ase(Bus* prmBus, Logger* prmLogger, int prmSoundDevice, SVocalware vocalware);
336  void Initialize(Devices::Bass* prmBass);
337  void FrameMove(float fElapsedTime) override;
338 };
339 
341 class Fms : public Module
342 {
343 private:
346 
347 public:
348  Fms(Bus* prmBus, Logger* prmLogger);
349  void FrameMove(float fElapsedTime) override;
350 };
351 
353 class Fdr : public Module
354 {
355 private:
358  float secSinceLast = 0.0f;
359  int fdrfile;
360 
361 public:
362  Fdr(Bus* prmBus, Logger* prmLogger);
363  void FrameMove(float fElapsedTime) override;
364  ~Fdr();
365 };
366 
368 class Door : public Module
369 {
370 private:
373 
374  bool open = false;
375  float timeSinceLast = 0.0f;
376 
377  float* sensorPsi = nullptr;
378  float* doorSensor = nullptr;
379  float* compressorOn = nullptr;
380 
381  float dutyTime = 0.0f;
382 
383 public:
384  Door(Bus* prmBus, Logger* prmLogger);
385  void FrameMove(float fElapsedTime) override;
386  ~Door();
387 };
388 
390 class Logo : public Module
391 {
392 private:
395  float latitude = 0.0f, longitude = 0.0f, altitudeFeet = 0.0f, zenithDegrees = 0.0f;
396  float timeSinceLast = 60.0f;
397 
398  float* sunrise = nullptr;
399  float* sunset = nullptr;
400  float* status = nullptr;
401 
402  time_t t = 0;
403  struct tm* lt = nullptr;
404  TIME_ZONE_INFORMATION tz;
406  CTime cTime;
407 
408 public:
409  Logo(Bus* prmBus, Logger* prmLogger, float prmLatitude, float prmLongitude, float prmAltitudeFeet, float prmZenithDegrees);
410  void FrameMove(float fElapsedTime) override;
411  ~Logo();
412 };
int testmode
Definition: Module.h:198
Devices::Bass * bass
Definition: Module.h:111
std::vector< Location > locations
Definition: Module.h:89
float occupantControlAuthority
Definition: Module.h:284
Flight Management System.
Definition: Module.h:341
const float Vs1
Definition: Module.h:244
const float PitchAggression
Definition: Module.h:242
void FrameMove(float fElapsedTime) override
Definition: PFD.cpp:37
void UnacknowledgeAllMessages()
Definition: CAS.cpp:265
std::string wait
Definition: Module.h:304
bool rightSide
Definition: Module.h:245
void FrameMove(float fElapsedTime) override
http://aviation.stackexchange.com/questions/1959/how-are-turbine-engines-started
Definition: FADEC.cpp:5
Rtu(Bus *prmBus, Logger *prmLogger)
Definition: RTU.cpp:3
int ControlPriorityLocation
Definition: Module.h:91
const float RollAggression
Definition: Module.h:243
bool currentState
Definition: Module.h:225
float * compressorOn
Definition: Module.h:379
void ConnectComponent(std::string name, std::string guid)
Definition: FCS.cpp:290
bool requestedState
Definition: Module.h:225
Pfd(Bus *prmBus, Logger *prmLogger)
Definition: PFD.cpp:3
Library::Solar solar
Definition: Module.h:405
float * emergencyStopGetPtr
Definition: Module.h:199
float oldRollAttitude
Definition: Module.h:246
~Door()
Definition: Door.cpp:113
Flight Control System.
Definition: Module.h:80
float secsincelast
Definition: Module.h:52
CTime cTime
Definition: Module.h:406
~Logo()
Definition: Logo.cpp:55
bool engineRun
Definition: Module.h:114
~Fdr()
Definition: FDR.cpp:134
std::string lid
Definition: Module.h:266
Definition: Logger.h:5
bool GenerateTextToSpeech(std::string url, UINT voice, std::string outputPath)
Definition: ASE.cpp:316
int soundDevice
Definition: Module.h:334
std::string prefix
Definition: Module.h:138
float timeoutLeft
Definition: Module.h:306
Automatic Flight Control System.
Definition: Module.h:236
float * vmuGetFloatPtr
Definition: Module.h:67
float oldDesiredVsi
Definition: Module.h:241
UINT FindStep(std::string stepName)
Definition: ASE.cpp:474
void FrameMove(float fElapsedTime) override
Definition: RTU.cpp:8
Cas(Bus *prmBus, Logger *prmLogger, std::vector< Watch > watches, float *prmCasGetFloatPtr)
Definition: CAS.cpp:162
Door(Bus *prmBus, Logger *prmLogger)
Definition: Door.cpp:3
bool powered
Definition: Module.h:68
float * ignitionSetFloatPtr
Definition: Module.h:129
std::string element
Definition: Module.h:311
float * ITTSetFloatPtr
Definition: Module.h:132
void FrameMove(float fElapsedTime) override
Definition: FCS.cpp:4
std::string vid
Definition: Module.h:267
Crew Alerting System.
Definition: Module.h:147
std::vector< Devices::Joystick * > flightControls
Definition: Module.h:94
std::vector< SCommand > commands
Definition: Module.h:317
DWORD * N1FaultPtr
Definition: Module.h:127
void FrameMove(float fElapsedTime) override
Definition: VMU.cpp:3
Primary Flight Display.
Definition: Module.h:217
float secSinceLast
Definition: Module.h:358
CUSTOM## Logo module
Definition: Module.h:390
Radio Tuning Unit.
Definition: Module.h:174
void FrameMove(float fElapsedTime) override
Definition: GPWS.cpp:33
float priorityHeldDownSec
Definition: Module.h:86
bool IsMessageOnStack(std::wstring text, bool renew) const
Definition: CAS.cpp:178
float longitude
Definition: Module.h:395
Module(Bus *prmBus)
Definition: Module.h:20
void FrameMove(float fElapsedTime) override
Definition: Door.cpp:16
bool engineStopError
Definition: Module.h:118
TIME_ZONE_INFORMATION tz
Definition: Module.h:404
float * fcsGetFloatPtr
Definition: Module.h:97
int joystickAxis
Definition: Module.h:136
void FrameMove(float fElapsedTime) override
Definition: CAS.cpp:6
Fadec(Bus *prmBus, int prmSoundDevice, int prmAxis, int prmOrdinal, std::string prmPrefix)
Definition: FADEC.cpp:363
float secsincelast
Definition: Module.h:41
float * status
Definition: Module.h:400
float ignitionTimer
Definition: Module.h:117
Adaptive Scenario Engine.
Definition: Module.h:260
Fcs(Bus *prmBus, int joysticks)
Definition: FCS.cpp:279
bool engineLit
Definition: Module.h:115
Afcs & operator=(const Afcs &)
Definition: Module.h:253
bool open
Definition: Module.h:374
UINT currentStep
Definition: Module.h:281
Traffic Collision Avoidance System.
Definition: Module.h:49
std::string fxlevel
Definition: Module.h:269
int subStep
Definition: Module.h:282
float timer
Definition: Module.h:197
bool bvalue
Definition: Module.h:298
std::string vmu
Definition: Module.h:289
Definition: Bus.h:12
time_t t
Definition: Module.h:402
float * N1SetFloatPtr
Definition: Module.h:128
Bus * bus
Definition: Module.h:372
bool ControlPriorityLatched
Definition: Module.h:92
Ase(Bus *prmBus, Logger *prmLogger, int prmSoundDevice, SVocalware vocalware)
Definition: ASE.cpp:15
Flight Data Recorder.
Definition: Module.h:353
virtual void FrameMove(float fElapsedTime)=0
std::vector< Watch > watches
Definition: Module.h:156
std::string command
Definition: Module.h:224
float * starterSetFloatPtr
Definition: Module.h:123
std::string help
Definition: Module.h:310
void Initialize(Devices::Joystick *prmFlightControl, Devices::Bass *prmBass)
Definition: FADEC.cpp:373
void ConnectComponent(std::string name, std::string guid)
Definition: FADEC.cpp:381
bool RemoveMessage(std::wstring text) const
Definition: CAS.cpp:201
float zenithDegrees
Definition: Module.h:395
CUSTOM## Door module
Definition: Module.h:368
float * doorSensor
Definition: Module.h:378
Bus * bus
Definition: Module.h:394
SSnap current
Definition: Module.h:207
std::vector< SVoice > voices
Definition: Module.h:277
DWORD * fadecFaultPtr
Definition: Module.h:121
Full Authority Digital Engine Control.
Definition: Module.h:107
bool MessageFlashState
Definition: Module.h:151
Afcs(Bus *prmBus, Logger *prmLogger)
Definition: AFCS.cpp:4
Forward definitions for the modules are below.
Definition: Module.h:38
DWORD * fcsFaultPtr
Definition: Module.h:96
void FrameMove(float fElapsedTime) override
Definition: AFCS.cpp:10
Abstract base class for modules By definition, instruments don&#39;t do any of the work (they don&#39;t modif...
Definition: Module.h:11
std::vector< Message > messages
Definition: Module.h:150
void FrameMove(float fElapsedTime) override
Definition: FDR.cpp:27
Fdr(Bus *prmBus, Logger *prmLogger)
Definition: FDR.cpp:6
float latitude
Definition: Module.h:395
float timeSinceLast
Definition: Module.h:396
Mcu(Bus *prmBus, Logger *prmLogger)
Definition: MCU.cpp:8
bool engineStart
Definition: Module.h:113
void FrameMove(float fElapsedTime) override
Definition: ASE.cpp:34
Tcas(Bus *prmBus)
Definition: TCAS.cpp:3
Logger * logger
Definition: Module.h:239
DWORD conditionsMet
Definition: Module.h:308
float * starterGetFloatPtr
Definition: Module.h:124
int fdrfile
Definition: Module.h:359
float engineStopTimer
Definition: Module.h:119
Logger * logger
Definition: Module.h:393
float * casGetFloatPtr
Definition: Module.h:158
Voice Messaging Unit.
Definition: Module.h:61
std::string secret
Definition: Module.h:276
float altitudeFeet
Definition: Module.h:395
float fl
Definition: Module.h:203
Logger * logger
Definition: Module.h:324
float * fadecGetFloatPtr
Definition: Module.h:122
struct Pfd::SLight lights[10]
Bus * bus
Definition: Module.h:357
Logger * logger
Definition: Module.h:209
HSTREAM stream
Definition: Module.h:285
float secsincelast
Definition: Module.h:65
Fms(Bus *prmBus, Logger *prmLogger)
Definition: FMS.cpp:3
Bus * bus
Definition: Module.h:17
void FrameMove(float fElapsedTime) override
Definition: FMS.cpp:9
float timer
Definition: Module.h:229
void AdvanceToNextStep()
Definition: ASE.cpp:282
Vmu(Bus *prmBus, int bassLocation, float *prmGetFloatPtr)
Definition: VMU.cpp:174
Logger * logger
Definition: Module.h:344
Bus * bus
Definition: Module.h:240
UINT voice
Definition: Module.h:290
float * N2GetFloatPtr
Definition: Module.h:126
float secondsPowered
Definition: Module.h:69
void Initialize(Devices::Joystick *prmFlightControl)
Definition: FCS.cpp:285
float fr
Definition: Module.h:203
Logger * logger
Definition: Module.h:371
void FrameMove(float fElapsedTime) override
Definition: Logo.cpp:24
Devices::Bass * bass
Definition: Module.h:64
float dutyTime
Definition: Module.h:381
bool powered
Definition: Module.h:159
float * N2SetFloatPtr
Definition: Module.h:125
SVocalware vocalware
Definition: Module.h:326
void FrameMove(float fElapsedTime) override
Definition: MCU.cpp:30
std::string eid
Definition: Module.h:265
float timeout
Definition: Module.h:305
Logger * logger
Definition: Module.h:177
std::string timeoutStep
Definition: Module.h:307
SSnap Locations[11]
Definition: Module.h:206
float * combustionSetFloatPtr
Definition: Module.h:131
float br
Definition: Module.h:203
Logo(Bus *prmBus, Logger *prmLogger, float prmLatitude, float prmLongitude, float prmAltitudeFeet, float prmZenithDegrees)
Definition: Logo.cpp:4
std::string name
Definition: Module.h:316
float timeSinceLast
Definition: Module.h:375
Motion Control Unit.
Definition: Module.h:184
char svalue[64]
Definition: Module.h:299
virtual ~Module()
Definition: Module.h:30
float * sensorPsi
Definition: Module.h:377
int soundDevice
Definition: Module.h:135
void Initialize(Devices::Bass *prmBass)
Definition: ASE.cpp:23
float * sunset
Definition: Module.h:399
void AddMessage(std::wstring text, MessageLevel level, bool sendEmail)
Definition: CAS.cpp:217
int testProgress
Definition: Module.h:53
std::string jump
Definition: Module.h:302
std::string acc
Definition: Module.h:274
void Initialize(Devices::Bass *prmBass)
Definition: VMU.cpp:182
std::vector< SStep > steps
Definition: Module.h:320
float secsincelast
Definition: Module.h:153
void LoadScenario(std::string path)
Definition: ASE.cpp:347
Bus * bus
Definition: Module.h:345
float bl
Definition: Module.h:203
float fvalue
Definition: Module.h:297
void FrameMove(float fElapsedTime) override
Definition: TCAS.cpp:7
float secsincereset
2 second power up delay
Definition: Module.h:154
Logger * logger
Definition: Module.h:356
float oldPitchAttitude
Definition: Module.h:247
int soundDevice
Definition: Module.h:72
bool priorityButtonDown
Definition: Module.h:85
std::string api
Definition: Module.h:275
int sequencer
Definition: Module.h:187
std::vector< Devices::Joystick * > flightControls
Definition: Module.h:110
std::vector< Devices::Joystick > joysticks
Definition: Avionics.cpp:32
Gpws(Bus *prmBus)
Definition: GPWS.cpp:29
float * ignitionGetFloatPtr
Definition: Module.h:130
int engineOrdinal
Definition: Module.h:137
struct tm * lt
Definition: Module.h:403
int ivalue
Definition: Module.h:296
int strategy
Definition: Module.h:226
Devices::Bass * bass
Definition: Module.h:325
void AcknowledgeAllMessages() const
Definition: CAS.cpp:169
std::string name
Definition: Module.h:292
float * sunrise
Definition: Module.h:398
bool scenarioLoaded
Definition: Module.h:283
float lightOffTimer
Definition: Module.h:116
MessageLevel
Definition: Message.h:5
std::string fxtype
Definition: Module.h:268
Logger * logger
Definition: Module.h:220
Logger * logger
2 second application start delay
Definition: Module.h:155
Bus * bus
Definition: Module.h:323