Avionics
Dropship Simulator
Diagnostics.cpp
Go to the documentation of this file.
1 #include "Instrument.h"
2 #include "psapi.h"
3 
4 Diagnostics::Diagnostics(int prmX, int prmY, float prmXScale, float prmYScale) : Instrument(prmX, prmY, prmXScale, prmYScale)
5 {
6 }
7 
8 void Diagnostics::Render(float fElapsed)
9 {
10  int yy = y + 24; // advance because of the per screen display
11 
12  // Output statistics
13  WCHAR msg[99];
14  swprintf_s(msg, 99, L"%.1f fps / %.1f fps", bus->frameRate, bus->DisplayFps);
15  DrawTextW(msg, 5, yy, DT_NOCLIP, D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f), 0, "Diagnostics");
16  yy += 24;
17 
18  swprintf_s(msg, 99, L"Command buffer: %i", bus->commandStream.size());
19  DrawText(msg, 5, yy += 24, DT_NOCLIP, D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f), 0, "Diagnostics");
20 
21 
22  PROCESS_MEMORY_COUNTERS pmc;
23  GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
24  swprintf_s(msg, 99, L"Memory used: %i kB", pmc.WorkingSetSize / 1024);
25  DrawText(msg, 5, yy += 24, DT_NOCLIP, D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f), 0, "Diagnostics");
26 
27 
28  Nullable<float> avionicsBayTemp = bus->GetComponentStateFloat("721D4FC2-F13E-47B3-9A21-B7FE9A1C677C");
29  if (avionicsBayTemp.is_set())
30  swprintf_s(msg, 99, L"AvionicsBayTemp: %.1f°C (%.1f°F)", avionicsBayTemp.get(), avionicsBayTemp.get() * 9.0f / 5.0f + 32.0f);
31  else
32  swprintf_s(msg, 99, L"AvionicsBayTemp: NO SIGNAL");
33  DrawText(msg, 5, yy += 24, DT_NOCLIP, D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f), 0, "Diagnostics");
34 
35  Nullable<float> pneumaticPressure = bus->GetComponentStateFloat("0E1C068F-F901-4C1A-AC12-10F53E894579");
36  if (pneumaticPressure.is_set())
37  swprintf_s(msg, 99, L"pneumaticPressure: %.1f PSI", pneumaticPressure.get());
38  else
39  swprintf_s(msg, 99, L"pneumaticPressure: NO SIGNAL");
40  DrawText(msg, 5, yy += 24, DT_NOCLIP, D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f), 0, "Diagnostics");
41 
42  swprintf_s(msg, 99, L"PlatformAcc: %.2f %.2f %.2f", bus->PlatformAcceleration.x, bus->PlatformAcceleration.y, bus->PlatformAcceleration.z);
43  DrawText(msg, 5, yy += 24, DT_NOCLIP, D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f), 0, "Diagnostics");
44  swprintf_s(msg, 99, L"MCU: FL %.1f FR %.1f BL %.1f BR %.1f", bus->PlatformFrontLeftBellow, bus->PlatformFrontRightBellow, bus->PlatformBackLeftBellow, bus->PlatformBackRightBellow);
45  DrawText(msg, 5, yy += 24, DT_NOCLIP, D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f), 0, "Diagnostics");
46  yy += 24;
47 
49  swprintf_s(msg, 99, L"Pitch: %.2f Roll: %.2f Yaw: %.2f", bus->PitchControl, bus->RollControl, bus->YawControl);
50  DrawText(msg, 5, yy += 24, DT_NOCLIP, D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f), 0, "Diagnostics");
51 
53  swprintf_s(msg, 99, L"Engine1: %.2f Engine2: %.2f", bus->EngineThrustCommand[0], bus->EngineThrustCommand[1]);
54  DrawText(msg, 5, yy += 24, DT_NOCLIP, D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f), 0, "Diagnostics");
55 
57  swprintf_s(msg, 99, L"%4.1f", bus->PitchTrim);
58  DrawText(msg, 966, 706, DT_NOCLIP, D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f), 0, "Diagnostics");
59 
60  yy += 24;
61 
63  swprintf_s(msg, 99, L"AOA: %.1f°", D3DXToDegree(bus->AngleOfAttack));
64  DrawText(msg, 5, yy += 24, DT_NOCLIP, D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f), 0, "Diagnostics");
65  yy += 24;
66 
67 
68  static float oldhdg = 0.0f;
69  float _yaw = (bus->HeadingTrue - oldhdg);
70  if (_yaw < -D3DX_PI) _yaw += D3DX_PI*2.0f;
71  if (_yaw > D3DX_PI) _yaw -= D3DX_PI*2.0f;
72  oldhdg = bus->HeadingTrue;
73  _yaw /= fElapsed; // radians per second
74 
77  float desiredyaw = 0.0f;
78  if (bus->IndicatedAirspeed != 0.0f)
79  desiredyaw = 19.041542139258135684237466284211f * tanf(bus->RollAttitude)*cos(bus->PitchAttitude) / (bus->IndicatedAirspeed / sqrtf(bus->AirDensity) * 1943.84449f); // km/s to knots is 1943.84449
80  float yawcorr = desiredyaw - _yaw; // say we are 10 and we want 0 then 0-10 is -10 perfect!
81 
82  float dampen = yawcorr / 0.05235987756f; // Yaw damper
83  if (dampen > 0.3f) dampen = 0.3f;
84  if (dampen < -0.3f) dampen = -0.3f;
85  swprintf_s(msg, 99, L"Yaw correction: %.1f", dampen);
86  DrawText(msg, 5, yy += 24, DT_NOCLIP, D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f), 0, "Diagnostics");
87 
88  yy += 24;
89  swprintf_s(msg, 99, L"RA: %.3f km, GS DEV: %.3f rad", bus->RadioAltitude, bus->GlideslopeDeviation);
90  DrawText(msg, 5, yy += 24, DT_NOCLIP, D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f), 0, "Diagnostics");
91  yy += 24;
92  swprintf_s(msg, 99, L"Scenario Minutes: %.1f (%.1f)", bus->ScenarioTimer / 60.0, bus->ScenarioScore);
93  DrawText(msg, 5, yy += 24, DT_NOCLIP, D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f), 0, "Diagnostics");
94  yy += 24;
95 
96  Nullable<float> sunrise = bus->GetComponentStateFloat("AAE97FDE-1AEB-4E21-8D66-29D55F500D61");
97  if (sunrise.is_set())
98  swprintf_s(msg, 99, L"Sunrise: %02i:%02i AM", static_cast<int>(floorf(sunrise.get())), static_cast<int>(fmodf(sunrise.get(), 1.0f)*60.0f));
99  else
100  swprintf_s(msg, 99, L"Sunrise: NO SIGNAL");
101  DrawText(msg, 5, yy += 24, DT_NOCLIP, D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f), 0, "Diagnostics");
102 
103  Nullable<float> sunset = bus->GetComponentStateFloat("1EC47487-BCA5-4CD4-8E20-494D490906B0");
104  if (sunset.is_set())
105  swprintf_s(msg, 99, L"Sunset: %02i:%02i PM", static_cast<int>(floorf(sunset.get())), static_cast<int>(fmodf(sunset.get(), 1.0f)*60.0f));
106  else
107  swprintf_s(msg, 99, L"Sunset: NO SIGNAL");
108  DrawText(msg, 5, yy += 24, DT_NOCLIP, D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f), 0, "Diagnostics");
109 
110  yy += 24;
111 
112  static float peak = 0.0f;
113  Nullable<float> vibrationMils = bus->GetComponentStateFloat("D259893C-95EA-419C-90F3-17EB20320A9C");
114  if (vibrationMils.is_set())
115  {
116  if (fabsf(vibrationMils.get()) > peak)
117  peak = fabsf(vibrationMils.get());
118  swprintf_s(msg, 99, L"Vibration (Mils): %.2f (Peak %.2f)", vibrationMils.get(), peak);
119  }
120  else
121  swprintf_s(msg, 99, L"Vibration (Mils): NO SIGNAL");
122  DrawText(msg, 5, yy += 24, DT_NOCLIP, D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f), 0, "Diagnostics");
123 
124 };
float EngineThrustCommand[enginesC]
(57) Thrust command (when an information source is installed);
Definition: Bus.h:231
double PlatformFrontRightBellow
Definition: Bus.h:32
void DrawText(const WCHAR *str, int x, int y, int flags, D3DXCOLOR color, int font, std::string elementName)
Definition: Instrument.h:56
std::vector< Command > commandStream
Definition: Bus.h:20
float YawControl
Definition: Bus.h:57
double PlatformFrontLeftBellow
Definition: Bus.h:33
float RollControl
Definition: Bus.h:57
float IndicatedAirspeed
(3) Indicated Airspeed in km per second?
Definition: Bus.h:42
float PitchAttitude
(6) Pitch attitude;
Definition: Bus.h:49
float PitchControl
Definition: Bus.h:57
float HeadingTrue
(4) Heading–primary flight crew reference (if selectable, record discrete, true or magnetic); ...
Definition: Bus.h:44
float PitchTrim
Definition: Bus.h:259
float AirDensity
Definition: Bus.h:276
float RollAttitude
(7) Roll attitude;
Definition: Bus.h:51
Bus * bus
Definition: Instrument.h:21
Abstract base class for instrumentation By definition, instruments don&#39;t do any of the work (they don...
Definition: Instrument.h:15
Diagnostics(int prmX, int prmY, float prmXScale, float prmYScale)
Definition: Diagnostics.cpp:4
float RadioAltitude
Definition: Bus.h:134
float DisplayFps
Definition: Bus.h:296
void Render(float fElapsed) override
Definition: Diagnostics.cpp:8
float AngleOfAttack
Definition: Bus.h:150
double PlatformBackLeftBellow
Definition: Bus.h:31
float frameRate
Definition: Bus.h:35
bool is_set() const
Definition: Nullable.h:86
D3DXVECTOR3 PlatformAcceleration
Definition: Bus.h:29
float ScenarioScore
Definition: Bus.h:294
float ScenarioTimer
Definition: Bus.h:292
double PlatformBackRightBellow
Definition: Bus.h:30
T get() const
Definition: Nullable.h:79
float GlideslopeDeviation
Definition: Bus.h:136