Avionics
Dropship Simulator
Virtualization.cpp
Go to the documentation of this file.
1 #include "../Virtualization.h"
2 
3 namespace Systems
4 {
6  {
7  logger = prmLogger;
8  bus = prmBus;
9 
10  logger->Log("Virtualization::ctor LoadFile...");
11  LoadFile();
12 
13  logger->Log("Virtualization::ctor Initialize...");
14  Initialize();
15  }
16 
18  {
19  logger->Log("Virtualization::dtor...");
20 
22 
23  // release resources
24  for (std::vector<Component*>::iterator it = bus->components.begin(); it != bus->components.end(); ++it)
25  {
26  delete *it;
27  }
28  }
29 
30  void Virtualization::FrameMove(double fTime)
31  {
32  // have to cycle through all connectors and components pushing along fluid, current... analysing states
33  if (doComponent)
34  {
35  bus->components.at(currentComponent++)->FrameMove(fTime);
36  if (currentComponent == bus->components.size())
37  {
38  currentComponent = 0;
39  }
40  doComponent = false;
41  }
42  else
43  {
44  connectors.at(currentConnector++).FrameMove(fTime, logger);
45  if (currentConnector == connectors.size())
46  {
47  currentConnector = 0;
48  }
49  doComponent = true;
50  }
51  }
52 
54  {
55  for (UINT j = 0; j < connectors.size(); j++)
56  {
57  if (connectors.at(j).guid == guid)
58  return &connectors.at(j);
59  }
60  return nullptr;
61  }
62 
64  {
65  for (UINT j = 0; j < bus->components.size(); j++)
66  {
67  if (bus->components.at(j)->guid == guid)
68  return bus->components.at(j);
69  }
70  return nullptr;
71  }
72 
74  {
75  for (UINT i = 0; i < connectors.size(); i++)
76  {
77  Connector* connector = &connectors.at(i);
78 
79  // see if we can find connector by dependency
80  connector->dependsOn = FindConnectorByGuid(connector->dependency);
81  if (connector->dependsOn == nullptr)
82  {
83  connector->dependsOn = FindComponentByGuid(connector->dependency);
84  }
85  if (connector->dependsOn == nullptr)
86  {
87  char msg[99];
88  sprintf_s(msg, 99, "Could not find connector %i dependency!", i);
89  logger->Log(msg, Logger::Fatal);
90  }
91  }
92 
93  for (UINT i = 0; i < bus->components.size(); i++)
94  {
95  Component* component = bus->components.at(i);
96  if (component->attachedTo != GUID_NULL)
97  {
98  component->attachedToComponent = FindComponentByGuid(component->attachedTo);
99  if (component->attachedToComponent == nullptr)
100  {
101  char msg[99];
102  sprintf_s(msg, 99, "Could not find component %i attachment!", i);
103  logger->Log(msg, Logger::Fatal);
104  }
105  }
106  for (UINT j = 0; j < component->dependencies.size(); j++)
107  {
108  System system = Undefined;
109 
110  Dependency* dependency = &component->dependencies.at(j);
111  for (UINT k = 0; k < dependency->loops.size(); k++)
112  {
113  Connector* connector = FindConnectorByGuid(dependency->loops.at(k));
114  if (connector == nullptr)
115  {
116  char msg[99];
117  sprintf_s(msg, 99, "Could not find component %i dependency %i loop %i connector!", i, j, k);
118  logger->Log(msg, Logger::Fatal);
119  exit(0);
120  }
121  else
122  {
123  if (system != Undefined && connector->system != system)
124  {
125  char msg[99];
126  sprintf_s(msg, 99, "All the loops in component %i dependency %i do not match system %i!", i, j, static_cast<int>(system));
127  logger->Log(msg, Logger::Fatal);
128  exit(0);
129  }
130  else
131  {
132  system = connector->system;
133  }
134  }
135  dependency->connectors.push_back(connector); // have to do this regardless to make sure the ordinal of the loop matches
136  }
137  if (system == Undefined)
138  {
139  char msg[99];
140  sprintf_s(msg, 99, "None of the loops in component %i dependency %i have a system type?", i, j);
141  logger->Log(msg, Logger::Fatal);
142  exit(0);
143  }
144  dependency->system = system;
145  }
146  }
147  }
148 
150  {
151  FILE* asmstream = nullptr;
152 
154  if (fopen_s(&asmstream, "Dropship.cmp", "rt") != 0)
155  {
156  logger->Log("Virtualization::LoadFile Could not load component file!", Logger::Level::Error, errno);
157  return;
158  }
159 
160  fscanf_s(asmstream, "%f ,\n", &filever2);
161 
162  int connectorCount;
163  fscanf_s(asmstream, "%d ,\n", &connectorCount);
164  for (int i = 0; i < connectorCount; i++)
165  {
166  Connector connector;
167 
168  char guidChar[99];
169  fscanf_s(asmstream, "%s ,", guidChar, 99);
170  connector.guidStr = guidChar;
171 
172  unsigned long p0;
173  int p1, p2, p3, p4, p5, p6, p7, p8, p9, p10;
174  int err = sscanf_s(guidChar, "%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
175  &p0, &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10);
176  if (err == 11)
177  {
178  connector.guid.Data1 = p0;
179  connector.guid.Data2 = static_cast<unsigned short>(p1);
180  connector.guid.Data3 = static_cast<unsigned short>(p2);
181  connector.guid.Data4[0] = static_cast<unsigned char>(p3);
182  connector.guid.Data4[1] = static_cast<unsigned char>(p4);
183  connector.guid.Data4[2] = static_cast<unsigned char>(p5);
184  connector.guid.Data4[3] = static_cast<unsigned char>(p6);
185  connector.guid.Data4[4] = static_cast<unsigned char>(p7);
186  connector.guid.Data4[5] = static_cast<unsigned char>(p8);
187  connector.guid.Data4[6] = static_cast<unsigned char>(p9);
188  connector.guid.Data4[7] = static_cast<unsigned char>(p10);
189  }
190  else
191  {
192  logger->Log("Virtualization::LoadFile Invalid GUID for connector", Logger::Level::Error, i);
193  }
194 
195  err = fscanf_s(asmstream, "%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X ,",
196  &p0, &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10);
197  if (err == 11)
198  {
199  connector.dependency.Data1 = p0;
200  connector.dependency.Data2 = static_cast<unsigned short>(p1);
201  connector.dependency.Data3 = static_cast<unsigned short>(p2);
202  connector.dependency.Data4[0] = static_cast<unsigned char>(p3);
203  connector.dependency.Data4[1] = static_cast<unsigned char>(p4);
204  connector.dependency.Data4[2] = static_cast<unsigned char>(p5);
205  connector.dependency.Data4[3] = static_cast<unsigned char>(p6);
206  connector.dependency.Data4[4] = static_cast<unsigned char>(p7);
207  connector.dependency.Data4[5] = static_cast<unsigned char>(p8);
208  connector.dependency.Data4[6] = static_cast<unsigned char>(p9);
209  connector.dependency.Data4[7] = static_cast<unsigned char>(p10);
210  }
211  else
212  {
213  logger->Log("Virtualization::LoadFile Invalid GUID for connector dependency", Logger::Level::Error, i);
214  }
215 
216  fscanf_s(asmstream, "%f ,%f ,%f ,%f ,%f ,%f ,%d ,%f ,%f ,%f ,%f ,%d ,\n",
217  &connector.start.x,
218  &connector.start.y,
219  &connector.start.z,
220  &connector.end.x,
221  &connector.end.y,
222  &connector.end.z,
223  &connector.system,
224  &connector.capacityPressureEtc,
225  &connector.propogatedLoad,
226  &connector.hpPhysicalRemaining,
227  &connector.hpEnergyRemaining,
228  &connector.fault);
229  connector.location = (connector.start + connector.end) / 2;
230 
232  connector.hpPhysical = connector.hpEnergy = 0;
233 
234  connectors.push_back(connector);
235  }
236 
238  int componentCount;
239  fscanf_s(asmstream, "%d ,\n", &componentCount);
240  for (int i = 0; i < componentCount; i++)
241  {
242  ComponentType componentType;
243  System system;
244 
246  fscanf_s(asmstream, "%d ,%d ,", &componentType, &system);
247 
248  Component* component;
249 
250  switch (componentType)
251  {
252  case Solenoid_Relay:
253  component = new Relay(logger);
254  break;
255  case Hard_Switch:
256  component = new Switch(logger);
257  break;
258  case Reservoir:
259  if (system == Electrical)
260  component = new Battery(logger);
261  else
262  component = new Component(logger);
263  break;
264  case Sensor_Real:
265  component = new Real(logger);
266  break;
267  case Sensor_Temperature:
268  component = new TempSensor(logger);
269  break;
270  case Motor_:
271  if (system == Propulsion)
272  component = new Starter(logger);
273  else
274  component = new Component(logger);
275  break;
276  case N1_:
277  component = new N1(logger);
278  break;
279  case N2_:
280  component = new N2(logger);
281  break;
282  case Igniter_:
283  component = new Igniter(logger);
284  break;
285  case Combustion_Chamber:
286  component = new Combustion(logger);
287  break;
288  default:
289  component = new Component(logger);
290  break;
291  }
292 
293  component->system = system;
294 
295  fscanf_s(asmstream, "%f ,%f ,%f ,%f, %f, %d, %d ,%f ,%f ,%f ,%f ,%f ,%f ,%f ,%f ,%f ,\n",
296  &component->location.x,
297  &component->location.y,
298  &component->location.z,
299  &component->averageServiceLife,
300  &component->serviceLifeCycleHit,
301  &component->hpPhysical,
302  &component->hpEnergy,
303  &component->weight,
304  &component->cost,
305  &component->pickupPressure,
306  &component->dropoutPressure,
307  &component->maxPressure,
308  &component->loadDraw,
309  &component->minTemp,
310  &component->maxTemp,
311  &component->maxCapacity);
312 
313  char bob[MAX_PATH];
314  int bytes = fscanf_s(asmstream, "%[^\n]\n", bob, 99);
315  if (bytes > 0 && _strcmpi(bob, "unused") != 0)
316  component->make = bob;
317  else
318  component->make.clear();
319  bytes = fscanf_s(asmstream, "%[^\n]\n", bob, 99);
320  if (bytes > 0 && _strcmpi(bob, "unused") != 0)
321  component->model = bob;
322  else
323  component->model.clear();
324  bytes = fscanf_s(asmstream, "%[^\n]\n", bob, 99);
325  if (bytes > 0 && _strcmpi(bob, "unused") != 0)
326  component->description = bob;
327  else
328  component->description.clear();
330 
331 
332  char guidChar[99];
333  fscanf_s(asmstream, "%s ,", guidChar, 99);
334  component->guidStr = guidChar;
335 
336  unsigned long p0;
337  int p1, p2, p3, p4, p5, p6, p7, p8, p9, p10;
338 
339  int err = sscanf_s(guidChar, "%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
340  &p0, &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10);
341  if (err == 11)
342  {
343  component->guid.Data1 = p0;
344  component->guid.Data2 = static_cast<unsigned short>(p1);
345  component->guid.Data3 = static_cast<unsigned short>(p2);
346  component->guid.Data4[0] = static_cast<unsigned char>(p3);
347  component->guid.Data4[1] = static_cast<unsigned char>(p4);
348  component->guid.Data4[2] = static_cast<unsigned char>(p5);
349  component->guid.Data4[3] = static_cast<unsigned char>(p6);
350  component->guid.Data4[4] = static_cast<unsigned char>(p7);
351  component->guid.Data4[5] = static_cast<unsigned char>(p8);
352  component->guid.Data4[6] = static_cast<unsigned char>(p9);
353  component->guid.Data4[7] = static_cast<unsigned char>(p10);
354  }
355  else
356  {
357  logger->Log("Virtualization::LoadFile Invalid GUID for component", Logger::Level::Error, i);
358  }
359 
360  err = fscanf_s(asmstream, "%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X ,",
361  &p0, &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10);
362  if (err == 11)
363  {
364  component->attachedTo.Data1 = p0;
365  component->attachedTo.Data2 = static_cast<unsigned short>(p1);
366  component->attachedTo.Data3 = static_cast<unsigned short>(p2);
367  component->attachedTo.Data4[0] = static_cast<unsigned char>(p3);
368  component->attachedTo.Data4[1] = static_cast<unsigned char>(p4);
369  component->attachedTo.Data4[2] = static_cast<unsigned char>(p5);
370  component->attachedTo.Data4[3] = static_cast<unsigned char>(p6);
371  component->attachedTo.Data4[4] = static_cast<unsigned char>(p7);
372  component->attachedTo.Data4[5] = static_cast<unsigned char>(p8);
373  component->attachedTo.Data4[6] = static_cast<unsigned char>(p9);
374  component->attachedTo.Data4[7] = static_cast<unsigned char>(p10);
375  }
376  else
377  {
378  logger->Log("Virtualization::LoadFile Invalid GUID for component attachment", Logger::Level::Error, i);
379  }
380 
381  bytes = fscanf_s(asmstream, "%[^\n]\n", bob, 99);
382  if (bytes > 0)
383  component->name = bob;
384  else
385  component->name.clear();
386 
387  float fakeFloat; // we don't store currentState anymore
388  fscanf_s(asmstream, "%f ,%f ,%f ,%f ,%f ,%f ,%f ,%f ,%d ,\n",
389  &component->setState,
390  &fakeFloat,
391  &component->temperature,
392  &component->capacityPressureEtc,
393  &component->propogatedLoad,
394  &component->serviceLifeRemaining,
395  &component->hpPhysicalRemaining,
396  &component->hpEnergyRemaining,
397  &component->fault);
398 
399 
401  if (componentType == Sensor_Real)
402  {
403  component->fault = NoSignal;
404  component->setState = -999.0f;
405  }
406 
408  int dependencyCount;
409  fscanf_s(asmstream, "%d ,\n", &dependencyCount);
410  for (int j = 0; j < dependencyCount; j++)
411  {
412  int loopCount, boolFailover;
413  Dependency dependency;
414  fscanf_s(asmstream, "%d ,%d ,%d ,%d ,\n",
415  &loopCount,
416  &dependency.currentLoop,
417  &dependency.defaultLoop,
418  &boolFailover);
419  dependency.autoFailover = boolFailover == 1;
420 
421 
422  for (int k = 0; k < loopCount; k++)
423  {
424  GUID loopGuid;
425 
426  err = fscanf_s(asmstream, "%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X ,",
427  &p0, &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10);
428  if (err == 11)
429  {
430  loopGuid.Data1 = p0;
431  loopGuid.Data2 = static_cast<unsigned short>(p1);
432  loopGuid.Data3 = static_cast<unsigned short>(p2);
433  loopGuid.Data4[0] = static_cast<unsigned char>(p3);
434  loopGuid.Data4[1] = static_cast<unsigned char>(p4);
435  loopGuid.Data4[2] = static_cast<unsigned char>(p5);
436  loopGuid.Data4[3] = static_cast<unsigned char>(p6);
437  loopGuid.Data4[4] = static_cast<unsigned char>(p7);
438  loopGuid.Data4[5] = static_cast<unsigned char>(p8);
439  loopGuid.Data4[6] = static_cast<unsigned char>(p9);
440  loopGuid.Data4[7] = static_cast<unsigned char>(p10);
441  }
442  else
443  {
444  char str[499];
445  sprintf_s(str, 499, "Invalid GUID for component %i dependency %i loop: %i", i, j, k);
446  logger->Log(str, Logger::Level::Error);
447  }
448 
449  dependency.loops.push_back(loopGuid);
450  }
451  component->dependencies.push_back(dependency);
452  }
453  bus->components.push_back(component);
454  }
455 
456  fclose(asmstream);
457  }
458 
460  {
461  if (filever2 == 0.0f)
462  {
463  logger->Log("Virtualization::SaveFile File was never loaded, returning!", Logger::Level::Error);
464  return;
465  }
466 
467  FILE* asmstream = nullptr;
468 
470  if (fopen_s(&asmstream, "Dropship.cmp", "rt") != 0)
471  {
472  logger->Log("Virtualization::SaveFile Could not load component file!", Logger::Level::Error, errno);
473  return;
474  }
475 
476  fscanf_s(asmstream, "%f ,\n", &filever2);
477 
478  int connectorCount;
479  fscanf_s(asmstream, "%d ,\n", &connectorCount);
480  for (int i = 0; i < connectorCount; i++)
481  {
482  Connector connector;
483  unsigned long p0;
484  int p1, p2, p3, p4, p5, p6, p7, p8, p9, p10;
485 
486  int err = fscanf_s(asmstream, "%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X ,",
487  &p0, &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10);
488  if (err == 11)
489  {
490  connector.guid.Data1 = p0;
491  connector.guid.Data2 = static_cast<unsigned short>(p1);
492  connector.guid.Data3 = static_cast<unsigned short>(p2);
493  connector.guid.Data4[0] = static_cast<unsigned char>(p3);
494  connector.guid.Data4[1] = static_cast<unsigned char>(p4);
495  connector.guid.Data4[2] = static_cast<unsigned char>(p5);
496  connector.guid.Data4[3] = static_cast<unsigned char>(p6);
497  connector.guid.Data4[4] = static_cast<unsigned char>(p7);
498  connector.guid.Data4[5] = static_cast<unsigned char>(p8);
499  connector.guid.Data4[6] = static_cast<unsigned char>(p9);
500  connector.guid.Data4[7] = static_cast<unsigned char>(p10);
501  }
502  else
503  {
504  logger->Log("Virtualization::SaveFile Invalid GUID for connector", Logger::Level::Error, i);
505  }
506 
507  err = fscanf_s(asmstream, "%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X ,",
508  &p0, &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10);
509  if (err == 11)
510  {
511  connector.dependency.Data1 = p0;
512  connector.dependency.Data2 = static_cast<unsigned short>(p1);
513  connector.dependency.Data3 = static_cast<unsigned short>(p2);
514  connector.dependency.Data4[0] = static_cast<unsigned char>(p3);
515  connector.dependency.Data4[1] = static_cast<unsigned char>(p4);
516  connector.dependency.Data4[2] = static_cast<unsigned char>(p5);
517  connector.dependency.Data4[3] = static_cast<unsigned char>(p6);
518  connector.dependency.Data4[4] = static_cast<unsigned char>(p7);
519  connector.dependency.Data4[5] = static_cast<unsigned char>(p8);
520  connector.dependency.Data4[6] = static_cast<unsigned char>(p9);
521  connector.dependency.Data4[7] = static_cast<unsigned char>(p10);
522  }
523  else
524  {
525  logger->Log("Invalid GUID for connector dependency", Logger::Level::Error, i);
526  }
527 
528  fscanf_s(asmstream, "%f ,%f ,%f ,%f ,%f ,%f ,%d ,%f ,%f ,%f ,%f ,%d ,\n",
529  &connector.start.x,
530  &connector.start.y,
531  &connector.start.z,
532  &connector.end.x,
533  &connector.end.y,
534  &connector.end.z,
535  &connector.system,
536  &connector.capacityPressureEtc,
537  &connector.propogatedLoad,
538  &connector.hpPhysicalRemaining,
539  &connector.hpEnergyRemaining,
540  &connector.fault);
541  connector.location = (connector.start + connector.end) / 2;
542 
544  connector.hpPhysical = connector.hpEnergy = 0;
545 
546  connectors.push_back(connector);
547  }
548 
550  int componentCount;
551  fscanf_s(asmstream, "%d ,\n", &componentCount);
552  for (int i = 0; i < componentCount; i++)
553  {
554  ComponentType componentType;
555  System system;
556 
558  fscanf_s(asmstream, "%d ,%d ,", &componentType, &system);
559 
560  Component* component;
561 
562  switch (componentType)
563  {
564  case Solenoid_Relay:
565  component = new Relay(logger);
566  break;
567  case Hard_Switch:
568  component = new Switch(logger);
569  break;
570  case Reservoir:
571  if (system == Electrical)
572  component = new Battery(logger);
573  else
574  component = new Component(logger);
575  break;
576  default:
577  component = new Component(logger);
578  break;
579  }
580 
581  component->system = system;
582 
583  fscanf_s(asmstream, "%f ,%f ,%f ,%f, %f, %d, %d ,%f ,%f ,%f ,%f ,%f ,%f ,%f ,%f ,%f ,\n",
584  &component->location.x,
585  &component->location.y,
586  &component->location.z,
587  &component->averageServiceLife,
588  &component->serviceLifeCycleHit,
589  &component->hpPhysical,
590  &component->hpEnergy,
591  &component->weight,
592  &component->cost,
593  &component->pickupPressure,
594  &component->dropoutPressure,
595  &component->maxPressure,
596  &component->loadDraw,
597  &component->minTemp,
598  &component->maxTemp,
599  &component->maxCapacity);
600 
601  char bob[MAX_PATH];
602  int bytes = fscanf_s(asmstream, "%[^\n]\n", bob, 99);
603  if (bytes > 0 && _strcmpi(bob, "unused") != 0)
604  component->make = bob;
605  else
606  component->make.clear();
607  bytes = fscanf_s(asmstream, "%[^\n]\n", bob, 99);
608  if (bytes > 0 && _strcmpi(bob, "unused") != 0)
609  component->model = bob;
610  else
611  component->model.clear();
612  bytes = fscanf_s(asmstream, "%[^\n]\n", bob, 99);
613  if (bytes > 0 && _strcmpi(bob, "unused") != 0)
614  component->description = bob;
615  else
616  component->description.clear();
618 
619 
620  char guidChar[99];
621  fscanf_s(asmstream, "%s ,", guidChar, 99);
622  component->guidStr = guidChar;
623 
624  unsigned long p0;
625  int p1, p2, p3, p4, p5, p6, p7, p8, p9, p10;
626 
627  int err = sscanf_s(guidChar, "%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
628  &p0, &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10);
629  if (err == 11)
630  {
631  component->guid.Data1 = p0;
632  component->guid.Data2 = static_cast<unsigned short>(p1);
633  component->guid.Data3 = static_cast<unsigned short>(p2);
634  component->guid.Data4[0] = static_cast<unsigned char>(p3);
635  component->guid.Data4[1] = static_cast<unsigned char>(p4);
636  component->guid.Data4[2] = static_cast<unsigned char>(p5);
637  component->guid.Data4[3] = static_cast<unsigned char>(p6);
638  component->guid.Data4[4] = static_cast<unsigned char>(p7);
639  component->guid.Data4[5] = static_cast<unsigned char>(p8);
640  component->guid.Data4[6] = static_cast<unsigned char>(p9);
641  component->guid.Data4[7] = static_cast<unsigned char>(p10);
642  }
643  else
644  {
645  logger->Log("Invalid GUID for component", Logger::Level::Error, i);
646  }
647 
648  err = fscanf_s(asmstream, "%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X ,",
649  &p0, &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10);
650  if (err == 11)
651  {
652  component->attachedTo.Data1 = p0;
653  component->attachedTo.Data2 = static_cast<unsigned short>(p1);
654  component->attachedTo.Data3 = static_cast<unsigned short>(p2);
655  component->attachedTo.Data4[0] = static_cast<unsigned char>(p3);
656  component->attachedTo.Data4[1] = static_cast<unsigned char>(p4);
657  component->attachedTo.Data4[2] = static_cast<unsigned char>(p5);
658  component->attachedTo.Data4[3] = static_cast<unsigned char>(p6);
659  component->attachedTo.Data4[4] = static_cast<unsigned char>(p7);
660  component->attachedTo.Data4[5] = static_cast<unsigned char>(p8);
661  component->attachedTo.Data4[6] = static_cast<unsigned char>(p9);
662  component->attachedTo.Data4[7] = static_cast<unsigned char>(p10);
663  }
664  else
665  {
666  logger->Log("Invalid GUID for component attachment", Logger::Level::Error, i);
667  }
668 
669  bytes = fscanf_s(asmstream, "%[^\n]\n", bob, 99);
670  if (bytes > 0)
671  component->name = bob;
672  else
673  component->name.clear();
674 
676  fscanf_s(asmstream, "%f ,%f ,%f ,%f ,%f ,%f ,%f ,%f ,%lu ,\n",
677  &component->setState,
678  &component->currentState,
679  &component->temperature,
680  &component->capacityPressureEtc,
681  &component->propogatedLoad,
682  &component->serviceLifeRemaining,
683  &component->hpPhysicalRemaining,
684  &component->hpEnergyRemaining,
685  &component->fault);
686 
687 
689  int dependencyCount;
690  fscanf_s(asmstream, "%d ,\n", &dependencyCount);
691  for (int j = 0; j < dependencyCount; j++)
692  {
693  int loopCount, boolFailover;
694  Dependency dependency;
695  fscanf_s(asmstream, "%d ,%d ,%d ,%d ,\n",
696  &loopCount,
697  &dependency.currentLoop,
698  &dependency.defaultLoop,
699  &boolFailover);
700  dependency.autoFailover = boolFailover == 1;
701 
702 
703  for (int k = 0; k < loopCount; k++)
704  {
705  GUID loopGuid;
706 
707  err = fscanf_s(asmstream, "%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X ,",
708  &p0, &p1, &p2, &p3, &p4, &p5, &p6, &p7, &p8, &p9, &p10);
709  if (err == 11)
710  {
711  loopGuid.Data1 = p0;
712  loopGuid.Data2 = static_cast<unsigned short>(p1);
713  loopGuid.Data3 = static_cast<unsigned short>(p2);
714  loopGuid.Data4[0] = static_cast<unsigned char>(p3);
715  loopGuid.Data4[1] = static_cast<unsigned char>(p4);
716  loopGuid.Data4[2] = static_cast<unsigned char>(p5);
717  loopGuid.Data4[3] = static_cast<unsigned char>(p6);
718  loopGuid.Data4[4] = static_cast<unsigned char>(p7);
719  loopGuid.Data4[5] = static_cast<unsigned char>(p8);
720  loopGuid.Data4[6] = static_cast<unsigned char>(p9);
721  loopGuid.Data4[7] = static_cast<unsigned char>(p10);
722  }
723  else
724  {
725  char str[499];
726  sprintf_s(str, 499, "Invalid GUID for component %i dependency %i loop: %i", i, j, k);
727  logger->Log(str, Logger::Level::Error);
728  }
729 
730  dependency.loops.push_back(loopGuid);
731  }
732  component->dependencies.push_back(dependency);
733  }
734  bus->components.push_back(component);
735  }
736 
737  fclose(asmstream);
738  }
739 }
float propogatedLoad
propogated demand
Definition: BaseComponent.h:26
float pickupPressure
Minimum pressure/voltage to activate.
Definition: Component.h:34
Connector * FindConnectorByGuid(GUID guid)
starter is very specific, load differential
Definition: Component.h:125
float dropoutPressure
Minimum pressure/voltage to keep active.
Definition: Component.h:36
Igniter is very specific, on or off set, we get the pulses.
Definition: Component.h:158
std::vector< Connector * > connectors
Definition: Dependency.h:12
Definition: Logger.h:5
N1 is very specific, load differential.
Definition: Component.h:147
These have to be in this order.
Definition: BaseComponent.h:12
std::string name
Definition: Component.h:21
Combustion Chamber is very specific, on or off set, we get the pulses.
Definition: Component.h:169
Hard switch.
Definition: Enumerations.h:30
Component * attachedToComponent
Definition: Component.h:19
float temperature
componentInfo
Definition: Component.h:47
std::string description
Definition: Component.h:43
Definition: Bus.h:12
float averageServiceLife
Average service life in hours.
Definition: Component.h:26
std::string model
Definition: Component.h:43
float capacityPressureEtc
propogated supply
Definition: BaseComponent.h:24
float serviceLifeCycleHit
Power-on service life cycle hit.
Definition: Component.h:28
Switch is a direct-set (no control voltage, command from bus from physical switch) which takes a supp...
Definition: Component.h:91
float serviceLifeRemaining
Definition: Component.h:48
void Log(const char *msg, Level level=Info, int errorCode=0)
These have to be in this order.
Definition: Logger.cpp:16
std::vector< Dependency > dependencies
Definition: Component.h:22
void FrameMove(double fTime)
BaseComponent * dependsOn
Definition: Connector.h:12
Is a real environment-related simulator sensor.
Definition: Enumerations.h:49
Component * FindComponentByGuid(GUID guid) const
D3DXVECTOR3 end
Definition: Connector.h:13
std::vector< Systems::Component * > components
SYSTEMS SUPPORT.
Definition: Bus.h:371
Uses control voltage control to turn on and off flow.
Definition: Enumerations.h:32
std::string make
Definition: Component.h:43
D3DXVECTOR3 start
Definition: Connector.h:13
Tank, battery.
Definition: Enumerations.h:24
std::vector< Connector > connectors
N2 is very specific, load differential.
Definition: Component.h:136
Temperature sensor reads data from setState (or attached component?) and puts it on currentState assu...
Definition: Component.h:102
std::vector< GUID > loops
Definition: Dependency.h:11
real components simply take setState and apply it to currentState, they run their own fault states ...
Definition: Component.h:182