Avionics
Dropship Simulator
FDR.cpp
Go to the documentation of this file.
1 #include "Module.h"
2 #include <sys/stat.h>
3 #include <fcntl.h>
4 #include <io.h>
5 
6 Fdr::Fdr(Bus* prmBus, Logger* prmLogger) : Module(prmBus)
7 {
8  logger = prmLogger;
9  bus = prmBus;
10 
12  SYSTEMTIME st;
13  GetLocalTime(&st);
14  char fileName[99];
15  sprintf_s(fileName, 99, "%i-%02i-%02i.fdr", st.wYear, st.wMonth, st.wDay);
16  _sopen_s(&fdrfile, fileName, _O_RDWR | _O_CREAT | _O_TEXT | _O_APPEND | _O_SEQUENTIAL, SH_DENYWR, S_IWRITE);
17  if (fdrfile == -1)
18  {
19  DXUT_ERR_MSGBOX(L"Could not open fdrfile for writing!", errno);
20  DXUTShutdown(errno);
21  }
22  char msg[99];
23  sprintf_s(msg, 99, "FDR::ctor Opened fdrfile \"%s\"", fileName);
24  logger->Log(msg);
25 }
26 
27 void Fdr::FrameMove(float fElapsedTime)
28 {
29  if (bus->FlightFreeze) return;
30 
31  secSinceLast += fElapsedTime;
32  if (secSinceLast < 1.0f)
33  return;
34 
35  secSinceLast = 0.0f;
36 
38  char timemsg[999];
39 
40  SYSTEMTIME st = bus->Time;
41  sprintf_s(timemsg, 999, "%02i:%02i:%02i-%6s,", st.wHour, st.wMinute, st.wSecond, bus->receiptNumber.c_str()); // 1
42  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
43 
44  sprintf_s(timemsg, 999, "%6.3f,", bus->PressureAltitude); // 2
45  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
46 
47  sprintf_s(timemsg, 999, "%3.0f,", bus->IndicatedAirspeed*1943.84449f); // 3
48  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
49 
50  sprintf_s(timemsg, 999, "%03.0f/%03.0f,", D3DXToDegree(bus->HeadingTrue), D3DXToDegree(bus->HeadingTrack)); // 4
51  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
52 
53  sprintf_s(timemsg, 999, "%+5.3f,", bus->NormalAcceleration.x); // 5
54  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
55 
56  sprintf_s(timemsg, 999, "%+3.0f,", D3DXToDegree(bus->PitchAttitude)); // 6
57  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
58 
59  sprintf_s(timemsg, 999, "%+4.0f,", D3DXToDegree(bus->RollAttitude)); // 7
60  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
61 
62  timemsg[0] = 0; // 8
63  for (unsigned i = 0; i < bus->Transmitting.size(); i++)
64  {
65  if (i>0) strcat_s(timemsg, 999, "/");
66  if (bus->Transmitting.at(i))
67  strcat_s(timemsg, 999, "1");
68  else
69  strcat_s(timemsg, 999, "0");
70  }
71  strcat_s(timemsg, 999, ",");
72  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
73 
74  timemsg[0] = 0; // 9
75  for (int i = 0; i < enginesC; i++)
76  {
77  if (i>0) strcat_s(timemsg, 999, "/");
78  char engine[999];
79  sprintf_s(engine, 999, "%5.0f", bus->EngineThrustOutput[i]);
80  strcat_s(timemsg, 999, engine);
81  }
82  strcat_s(timemsg, 999, ",");
83  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
84 
85  sprintf_s(timemsg, 999, "%i,", bus->AFCS.AutopilotEngaged); // 10
86  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
87 
88  sprintf_s(timemsg, 999, "%+5.3f,", bus->NormalAcceleration.y); // 11
89  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
90 
91  sprintf_s(timemsg, 999, "%+6.3f,", bus->PitchControl); // 12
92  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
93 
94  sprintf_s(timemsg, 999, "%+6.3f,", bus->RollControl); // 13
95  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
96 
97  sprintf_s(timemsg, 999, "%+6.3f,", bus->YawControl); // 14
98  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
99 
100  timemsg[0] = 0; // 15
101  for (int i = 0; i < 4; i++)
102  {
103  if (i>0) strcat_s(timemsg, 999, "/");
104  char discreet[999];
105  sprintf_s(discreet, 999, "%+5.2f", bus->DiscreetSurfacePostion[i]);
106  strcat_s(timemsg, 999, discreet);
107  }
108  strcat_s(timemsg, 999, ",");
109  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
110 
111  sprintf_s(timemsg, 999, "%+6.3f,", bus->RollControlSurfacePosition); // 16
112  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
113 
114  sprintf_s(timemsg, 999, "%+6.3f,", bus->YawControlSurfacePosition); // 17
115  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
116 
117  sprintf_s(timemsg, 999, "%+5.3f,", bus->NormalAcceleration.z); // 18
118  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
119 
120  sprintf_s(timemsg, 999, "%+6.3f,", bus->PitchTrimSurfacePosition); // 19
121  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
122 
123  sprintf_s(timemsg, 999, "%+6.3f,", bus->TrailingEdgeFlapsPosition); // 20
124  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
125 
126  sprintf_s(timemsg, 999, "%+6.3f,", bus->LeadingEdgeFlapsPosition); // 21
127  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
128 
129 
130  strcpy_s(timemsg, 999, "\n");
131  _write(fdrfile, timemsg, static_cast<unsigned int>(strlen(timemsg)));
132 }
133 
135 {
137  logger->Log("FDR::dtor Closing fdrfile...");
138  _close(fdrfile);
139  fdrfile = -1;
140 }
float LeadingEdgeFlapsPosition
(21) Leading edge flap or cockpit flap control selection (except when parameters of paragraph (a)(86)...
Definition: Bus.h:67
float EngineThrustOutput[enginesC]
(9) Thrust/power of each engine—primary flight crew reference;
Definition: Bus.h:55
float PressureAltitude
Definition: Bus.h:40
float YawControl
Definition: Bus.h:57
~Fdr()
Definition: FDR.cpp:134
Definition: Logger.h:5
float RollControl
Definition: Bus.h:57
float secSinceLast
Definition: Module.h:358
float RollControlSurfacePosition
Definition: Bus.h:60
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
std::vector< bool > Transmitting
(8) Manual radio transmitter keying, or CVR/DFDR synchronization reference;
Definition: Bus.h:53
Definition: Bus.h:12
D3DXVECTOR3 NormalAcceleration
(5) vertical (11) longitudinal (18) lateral
Definition: Bus.h:47
float PitchTrimSurfacePosition
(19) Pitch trim surface position or parameters of paragraph (a)(82) of this section if currently reco...
Definition: Bus.h:63
float RollAttitude
(7) Roll attitude;
Definition: Bus.h:51
float HeadingTrack
Definition: Bus.h:45
float DiscreetSurfacePostion[4]
Definition: Bus.h:59
#define enginesC
Data Bus.
Definition: Bus.h: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
void FrameMove(float fElapsedTime) override
Definition: FDR.cpp:27
Fdr(Bus *prmBus, Logger *prmLogger)
Definition: FDR.cpp:6
bool FlightFreeze
Definition: Bus.h:290
int fdrfile
Definition: Module.h:359
float TrailingEdgeFlapsPosition
(20) Trailing edge flap or cockpit flap control selection (except when parameters of paragraph (a)(85...
Definition: Bus.h:65
struct Bus::Afcs AFCS
Bus * bus
Definition: Module.h:357
void Log(const char *msg, Level level=Info, int errorCode=0)
These have to be in this order.
Definition: Logger.cpp:16
std::string receiptNumber
Definition: Bus.h:293
float YawControlSurfacePosition
Definition: Bus.h:61
bool AutopilotEngaged
Definition: Bus.h:80
Logger * logger
Definition: Module.h:356
_SYSTEMTIME Time
this section is required flight data (FDR)
Definition: Bus.h:39