Avionics
Dropship Simulator
Bus.cpp
Go to the documentation of this file.
1 #include "Bus.h"
2 
3 void Bus::FrameMove(float fElapsed, double fTime)
4 {
5  assert(!isComparitor);
6 
8  GetLocalTime(&Time);
9  ProgramTime = fTime;
10 
11  for (UINT i = 0; i < commandStream.size(); i++)
12  {
13  if (commandStream.at(i).delay > 0.0f)
14  {
15  commandStream.at(i).delay -= fElapsed;
16  if (commandStream.at(i).delay < 0.0f)
17  {
18  commandStream.at(i).delay = 0.0f;
19  }
20  }
21  else
22  {
23  commandStream.at(i).timeOnStack += fElapsed;
24  if (commandStream.at(i).timeOnStack > commandStream.at(i).ttl)
25  {
26  char msg[199];
27  sprintf_s(msg, 199, "Bus::FrameMove Command sat on the stack for too long (%.1fs): %s", commandStream.at(i).ttl, commandStream.at(i).name.c_str());
28  logger->Log(msg, Logger::Warn);
29  commandStream.erase(commandStream.begin() + i);
30  }
31  }
32  }
33 }
34 
35 Bus::Bus(Logger* prmLogger)
36 {
37  logger = prmLogger;
38  isComparitor = false;
39 }
40 
41 void Bus::AppendCommands(std::vector<Command>* commands)
42 {
43  assert(!isComparitor);
44 
45  for (UINT j = 0; j < commands->size(); j++)
46  {
47  if (commands->at(j).name == "Component")
48  {
49  Systems::Component* component = GetComponent(commands->at(j).guid);
50  if (commands->at(j).fvalue == -1.0f) // toggle
51  {
52  if (component->setState == 0.0f)
53  component->setState = 1.0f;
54  else
55  component->setState = 0.0f;
56  }
57  }
58  else
59  {
60  commandStream.push_back(commands->at(j));
61  std::string msg = "Bus::AppendCommands Adding command: " + commands->at(j).name;
62  logger->Log(msg.c_str());
63  }
64  }
65 }
66 
67 bool Bus::IsCommandOnStack(std::string commandName)
68 {
69  for (UINT i = 0; i < commandStream.size(); i++)
70  {
71  if (commandStream.at(i).name == commandName)
72  return true;
73  }
74  return false;
75 }
76 
78 {
79  for (UINT i = 0; i < components.size(); i++)
80  {
81  if (components.at(i)->guidStr == guidStr)
82  return components.at(i);
83  }
84  return nullptr;
85 }
86 
87 
88 Nullable<float> Bus::GetComponentStateFloat(std::string guidStr)
89 {
90  Nullable<float> boolState;
91  for (UINT i = 0; i < components.size(); i++)
92  {
93  if (components.at(i)->guidStr == guidStr)
94  {
95  if (components.at(i)->currentState != -999.0f)
96  {
97  boolState = components.at(i)->currentState;
98  }
99  return boolState;
100  }
101  }
102 
103  char str[199];
104  sprintf_s(str, 199, "Bus::GetComponentStateFloat could not find component: %s", guidStr.c_str());
105  logger->Log(str, Logger::Error);
106  return boolState;
107 }
108 
109 float* Bus::GetComponentSetStatePtr(std::string guidStr)
110 {
111  for (UINT i = 0; i < components.size(); i++)
112  {
113  if (components.at(i)->guidStr == guidStr)
114  {
115  return &components.at(i)->setState;
116  }
117  }
118 
119  char str[199];
120  sprintf_s(str, 199, "Bus::GetComponentSetStatePtr could not find component: %s", guidStr.c_str());
121  logger->Log(str, Logger::Error);
122  return nullptr;
123 }
124 
125 float* Bus::GetComponentCurrentStatePtr(std::string guidStr)
126 {
127  for (UINT i = 0; i < components.size(); i++)
128  {
129  if (components.at(i)->guidStr == guidStr)
130  {
131  return &components.at(i)->currentState;
132  }
133  }
134 
135  char str[199];
136  sprintf_s(str, 199, "Bus::GetComponentCurrentStatePtr could not find component: %s", guidStr.c_str());
137  logger->Log(str, Logger::Error);
138  return nullptr;
139 }
140 
142 {
143  for (UINT i = 0; i < components.size(); i++)
144  {
145  if (components.at(i)->guidStr == guidStr)
146  {
147  return &components.at(i)->fault;
148  }
149  }
150 
151  char str[199];
152  sprintf_s(str, 199, "Bus::GetComponentFaultStatePtr could not find component: %s", guidStr.c_str());
153  logger->Log(str, Logger::Error);
154  return nullptr;
155 }
double ProgramTime
Identified a need for these in modules.
Definition: Bus.h:289
std::vector< Command > commandStream
Definition: Bus.h:20
Definition: Logger.h:5
Systems::Fault * GetComponentFaultStatePtr(std::string guidStr)
Definition: Bus.cpp:141
Systems::Component * GetComponent(std::string guidStr)
Definition: Bus.cpp:77
Bus(Logger *prmLogger)
Definition: Bus.cpp:35
void AppendCommands(std::vector< Command > *commands)
Definition: Bus.cpp:41
void FrameMove(float fElapsed, double fTime)
Definition: Bus.cpp:3
void Log(const char *msg, Level level=Info, int errorCode=0)
These have to be in this order.
Definition: Logger.cpp:16
std::vector< Systems::Component * > components
SYSTEMS SUPPORT.
Definition: Bus.h:371
float * GetComponentSetStatePtr(std::string guidStr)
Definition: Bus.cpp:109
bool isComparitor
Definition: Bus.h:19
bool IsCommandOnStack(std::string commandName)
Definition: Bus.cpp:67
_SYSTEMTIME Time
this section is required flight data (FDR)
Definition: Bus.h:39
Logger * logger
Definition: Bus.h:15