Avionics
Dropship Simulator
Door.cpp
Go to the documentation of this file.
1 #include "../Module.h"
2 
3 Door::Door(Bus* prmBus, Logger* prmLogger) : Module(prmBus)
4 {
5  logger = prmLogger;
6  bus = prmBus;
7 
8  sensorPsi = bus->GetComponentCurrentStatePtr("0E1C068F-F901-4C1A-AC12-10F53E894579");
9  doorSensor = bus->GetComponentSetStatePtr("721A5FED-C5F2-427A-A563-12E69FA9ADA9");
10  compressorOn = bus->GetComponentSetStatePtr("19FC85CC-9EB3-4B4E-A4E1-95D02B9E787A");
11 
12  // make sure compressor is off
13  *compressorOn = 0.0f;
14 }
15 
16 void Door::FrameMove(float fElapsed)
17 {
18  timeSinceLast += fElapsed;
19 
20  for (UINT i = 0; i < bus->commandStream.size(); i++)
21  {
22  Command command = bus->commandStream.at(i);
23  if (command.delay != 0.0f) continue;
24 
25  bool processed = false;
26  if ((command.name == "Open Door Request" || (command.name == "Door Toggle Request" && !open)) && timeSinceLast >= 3.5f)
27  {
28  processed = true;
29  *doorSensor = 1.0f; // door sensor
30  open = true;
31  timeSinceLast = 0.0f;
32  Command newCommand;
33  newCommand.name = "Open Door";
34  newCommand.ivalue = 1;
35  bus->commandStream.push_back(newCommand);
36  newCommand.name = "Open Door";
37  newCommand.ivalue = 0;
38  newCommand.delay = 3.0f;
39  bus->commandStream.push_back(newCommand);
40 
41  newCommand.name = "StartRecord";
42  newCommand.ivalue = 0;
43  newCommand.delay = 3.0f;
44  bus->commandStream.push_back(newCommand);
45  }
46  else if ((command.name == "Close Door Request" || (command.name == "Door Toggle Request" && open)) && timeSinceLast >= 3.5f)
47  {
48  processed = true;
49  *doorSensor = 0.0f; // door sensor
50  timeSinceLast = 0.0f;
51  open = false;
52  Command newCommand;
53  newCommand.name = "Close Door";
54  newCommand.ivalue = 1;
55  bus->commandStream.push_back(newCommand);
56  newCommand.name = "Close Door";
57  newCommand.ivalue = 0;
58  newCommand.delay = 3.0f;
59  bus->commandStream.push_back(newCommand);
60 
61  newCommand.name = "StopRecord";
62  newCommand.ivalue = 0;
63  newCommand.delay = 3.0f;
64  bus->commandStream.push_back(newCommand);
65  }
66  else if (command.name == "Compressor Power Request")
67  {
68  processed = true;
69  *compressorOn = command.fvalue;
70  }
71  if (processed)
72  {
73  bus->commandStream.erase(bus->commandStream.begin() + i);
74  break;
75  }
76  }
77 
78 #pragma region Backup Compressor
79  // 10 minute duty cycle tracking (error report)
80  if (*compressorOn == 1.0f)
81  {
82  dutyTime += fElapsed;
83  if (dutyTime >= 300.0f) // 600 is 10 minutes... we are doing half that to save the compressor
84  {
85  *compressorOn = 0.0f;
86  logger->Log("Devices::Door Compressor Maximum Duty Cycle Reached (5 Min)", Logger::Warn);
87  }
88  }
89  else
90  {
91  dutyTime -= fElapsed;
92  if (dutyTime < 0.0f)
93  dutyTime = 0.0f;
94  }
95 
96  //if (*sensorPsi < 60.0f && bus->PlatformMotionSequencer == 0)
97  //{
98  // if (dutyTime == 0.0f) // only start after full cool-down period
99  // {
100  // compressorOn = true;
101  // logger->Log("Devices::Door Compressor Engaged", Logger::Error);
102  // }
103  //}
104 
105  if (*compressorOn == 1.0f && *sensorPsi >= 60.0f)
106  {
107  *compressorOn = 0.0f;
108  logger->Log("Devices::Door Compressor Maximum Pressure Reached", Logger::Warn);
109  }
110 #pragma endregion
111 }
112 
114 {
115  // make sure compressor is off
116  *compressorOn = 0.0f;
117 }
float fvalue
Definition: Command.h:22
float * compressorOn
Definition: Module.h:379
~Door()
Definition: Door.cpp:113
std::vector< Command > commandStream
Definition: Bus.h:20
Definition: Logger.h:5
Door(Bus *prmBus, Logger *prmLogger)
Definition: Door.cpp:3
void FrameMove(float fElapsedTime) override
Definition: Door.cpp:16
bool open
Definition: Module.h:374
Definition: Bus.h:12
std::string name
command name
Definition: Command.h:11
Bus * bus
Definition: Module.h:372
float * doorSensor
Definition: Module.h:378
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
Definition: Command.h:5
void Log(const char *msg, Level level=Info, int errorCode=0)
These have to be in this order.
Definition: Logger.cpp:16
Logger * logger
Definition: Module.h:371
float dutyTime
Definition: Module.h:381
int ivalue
Definition: Command.h:21
float * GetComponentSetStatePtr(std::string guidStr)
Definition: Bus.cpp:109
float timeSinceLast
Definition: Module.h:375
float * sensorPsi
Definition: Module.h:377
float delay
wait number of seconds before executing command
Definition: Command.h:8