← Documentation
ADS-IDAC Engine 5.0.0
CommandControlCenter.cpp
Go to the documentation of this file.
1// CommandControlCenter.cpp: implementation of the CommandControlCenter class.
2//
4
8#include "../Branch/BranchRecord.h"
9#include <boost/serialization/export.hpp>
10#include "../Global/SimulationContext.h"
11#include <boost/archive/binary_oarchive.hpp>
12#include <boost/archive/binary_iarchive.hpp>
13BOOST_CLASS_EXPORT_IMPLEMENT(CommandControlCenter)
14using namespace std;
15
16
18// Construction/Destruction
20
21// #ifndef _CONSOLE
22
23// // the following global variables are for network version only
24// extern CStringList theActivitiesStrList;
25
26// #endif
27
29
30}
31
33}
34
35void CommandControlCenter::addGoal(const std::shared_ptr<BranchGoal> &_pt, int _associated_branch_id) {
36 auto ccu_pt = make_unique<CommandControlUnit>();
37 ccu_pt->goal = _pt; // shares ownership with the cluster branch (no adoption)
38 ccu_pt->copyTimer(*_pt);
39 ccu_pt->setAssociatedBranchID(_associated_branch_id);
40 commands.push_back(std::move(ccu_pt));
41}
42void CommandControlCenter::addStrategy(const std::shared_ptr<BranchStrategy> &_pt, int _associated_branch_id) {
43 auto ccu_pt = make_unique<CommandControlUnit>();
44 ccu_pt->strategy = _pt; // shares ownership with the cluster branch (no adoption)
45 ccu_pt->copyTimer(*_pt);
46 ccu_pt->setAssociatedBranchID(_associated_branch_id);
47 commands.push_back(std::move(ccu_pt));
48}
49void CommandControlCenter::addSubGoal(const std::shared_ptr<BranchSubGoal> &_pt, int _associated_branch_id) {
50 auto ccu_pt = make_unique<CommandControlUnit>();
51 ccu_pt->subgoal = _pt; // shares ownership with the cluster branch (no adoption)
52 ccu_pt->copyTimer(*_pt);
53 ccu_pt->setAssociatedBranchID(_associated_branch_id);
54 commands.push_back(std::move(ccu_pt));
55}
56void CommandControlCenter::addDiagnosis(const std::shared_ptr<BranchDiagnosis> &_pt, int _associated_branch_id) {
57 auto ccu_pt = make_unique<CommandControlUnit>();
58 ccu_pt->diagnosis = _pt; // shares ownership with the cluster branch (no adoption)
59 ccu_pt->copyTimer(*_pt);
60 ccu_pt->setAssociatedBranchID(_associated_branch_id);
61 commands.push_back(std::move(ccu_pt));
62}
63void CommandControlCenter::addActionObjective(const std::shared_ptr<BranchActionObjective> &_pt, int _associated_branch_id) {
64 auto ccu_pt = make_unique<CommandControlUnit>();
65 ccu_pt->action_objective = _pt; // shares ownership with the cluster branch (no adoption)
66 ccu_pt->copyTimer(*_pt);
67 ccu_pt->setAssociatedBranchID(_associated_branch_id);
68 commands.push_back(std::move(ccu_pt));
69}
70void CommandControlCenter::addActionPack(const std::shared_ptr<BranchActionPack> &_pt, int _associated_branch_id) {
71 auto ccu_pt = make_unique<CommandControlUnit>();
72 ccu_pt->action_pack = _pt; // shares ownership with the cluster branch (no adoption)
73 ccu_pt->copyTimer(*_pt);
74 ccu_pt->setAssociatedBranchID(_associated_branch_id);
75 commands.push_back(std::move(ccu_pt));
76}
77void CommandControlCenter::addAction(const std::shared_ptr<BranchAction> &_pt, int _associated_branch_id) {
78 auto ccu_pt = make_unique<CommandControlUnit>();
79 ccu_pt->action = _pt; // shares ownership with the cluster branch (no adoption)
80 ccu_pt->copyTimer(*_pt);
81 ccu_pt->setAssociatedBranchID(_associated_branch_id);
82 commands.push_back(std::move(ccu_pt));
83}
84void CommandControlCenter::addExpectedAlarmState(const std::shared_ptr<BranchExpectedAlarmState> &_pt, int _associated_branch_id) {
85 auto ccu_pt = make_unique<CommandControlUnit>();
86 ccu_pt->alarm_state = _pt; // shares ownership with the cluster branch (no adoption)
87 ccu_pt->copyTimer(*_pt);
88 ccu_pt->setAssociatedBranchID(_associated_branch_id);
89 commands.push_back(std::move(ccu_pt));
90}
91void CommandControlCenter::addExpectedComponentState(const std::shared_ptr<BranchExpectedComponentState> &_pt, int _associated_branch_id) {
92 auto ccu_pt = make_unique<CommandControlUnit>();
93 ccu_pt->component_state = _pt; // shares ownership with the cluster branch (no adoption)
94 ccu_pt->copyTimer(*_pt);
95 ccu_pt->setAssociatedBranchID(_associated_branch_id);
96 commands.push_back(std::move(ccu_pt));
97}
98void CommandControlCenter::addExpectedSupportSystemState(const std::shared_ptr<BranchExpectedSupportSystemState> &_pt, int _associated_branch_id) {
99 auto ccu_pt = make_unique<CommandControlUnit>();
100 ccu_pt->support_system_state = _pt; // shares ownership with the cluster branch (no adoption)
101 ccu_pt->copyTimer(*_pt);
102 ccu_pt->setAssociatedBranchID(_associated_branch_id);
103 commands.push_back(std::move(ccu_pt));
104}
105void CommandControlCenter::addExpectedParameterTrend(const std::shared_ptr<BranchExpectedParameterTrend> &_pt, int _associated_branch_id) {
106 auto ccu_pt = make_unique<CommandControlUnit>();
107 ccu_pt->parameter_trend = _pt; // shares ownership with the cluster branch (no adoption)
108 ccu_pt->copyTimer(*_pt);
109 ccu_pt->setAssociatedBranchID(_associated_branch_id);
110 commands.push_back(std::move(ccu_pt));
111}
112void CommandControlCenter::addExpectedParameterValue(const std::shared_ptr<BranchExpectedParameterValue> &_pt, int _associated_branch_id) {
113 auto ccu_pt = make_unique<CommandControlUnit>();
114 ccu_pt->parameter_value = _pt; // shares ownership with the cluster branch (no adoption)
115 ccu_pt->copyTimer(*_pt);
116 ccu_pt->setAssociatedBranchID(_associated_branch_id);
117 commands.push_back(std::move(ccu_pt));
118}
119void CommandControlCenter::addExpectedParameterDifference(const std::shared_ptr<BranchExpectedParameterDifference> &_pt, int _associated_branch_id) {
120 auto ccu_pt = make_unique<CommandControlUnit>();
121 ccu_pt->parameter_difference = _pt; // shares ownership with the cluster branch (no adoption)
122 ccu_pt->copyTimer(*_pt);
123 ccu_pt->setAssociatedBranchID(_associated_branch_id);
124 commands.push_back(std::move(ccu_pt));
125}
126void CommandControlCenter::addMentalBelief(const std::shared_ptr<BranchExpectedMentalBelief> &_pt, int _associated_branch_id) {
127 auto ccu_pt = make_unique<CommandControlUnit>();
128 ccu_pt->mental_belief = _pt; // shares ownership with the cluster branch (no adoption)
129 ccu_pt->copyTimer(*_pt);
130 ccu_pt->setAssociatedBranchID(_associated_branch_id);
131 commands.push_back(std::move(ccu_pt));
132}
133
134void CommandControlCenter::addScannedParameter(const std::shared_ptr<BranchScannedParameter> &_pt, int _associated_branch_id) {
135 auto ccu_pt = make_unique<CommandControlUnit>();
136 ccu_pt->scanned_parameter = _pt; // shares ownership with the cluster branch (no adoption)
137 ccu_pt->copyTimer(*_pt);
138 ccu_pt->setAssociatedBranchID(_associated_branch_id);
139 commands.push_back(std::move(ccu_pt));
140}
141
142void CommandControlCenter::addProcedureStep(const std::shared_ptr<BranchProcedureStep> &_pt, int _associated_branch_id) {
143 auto ccu_pt = make_unique<CommandControlUnit>();
144 ccu_pt->procedure_step = _pt; // shares ownership with the cluster branch (no adoption)
145 ccu_pt->copyTimer(*_pt);
146 ccu_pt->setAssociatedBranchID(_associated_branch_id);
147 commands.push_back(std::move(ccu_pt));
148}
149void CommandControlCenter::addInstinctiveResponseProcedure(const std::shared_ptr<BranchProcedureStep> &_pt, int _associated_branch_id) {
150 auto ccu_pt = make_unique<CommandControlUnit>();
151 ccu_pt->instinctive_response_procedure = _pt; // shares ownership with the cluster branch (no adoption)
152 ccu_pt->copyTimer(*_pt);
153 ccu_pt->setAssociatedBranchID(_associated_branch_id);
154 commands.push_back(std::move(ccu_pt));
155}
156void CommandControlCenter::addInfoGatherMode(const std::shared_ptr<BranchInfoGatherMode> &_pt, int _associated_branch_id) {
157 auto ccu_pt = make_unique<CommandControlUnit>();
158 ccu_pt->info_gather_mode = _pt; // shares ownership with the cluster branch (no adoption)
159 ccu_pt->copyTimer(*_pt);
160 ccu_pt->setAssociatedBranchID(_associated_branch_id);
161 commands.push_back(std::move(ccu_pt));
162}
163void CommandControlCenter::addHWReliability(const std::shared_ptr<BranchSystemAction> &_pt, int _associated_branch_id) {
164 auto ccu_pt = make_unique<CommandControlUnit>();
165 ccu_pt->HW_reliability = _pt; // shares ownership with the cluster branch (no adoption)
166 ccu_pt->copyTimer(*_pt);
167 ccu_pt->setAssociatedBranchID(_associated_branch_id);
168 commands.push_back(std::move(ccu_pt));
169}
170void CommandControlCenter::addSSReliability(const std::shared_ptr<BranchSupportSystemAction> &_pt, int _associated_branch_id) {
171 auto ccu_pt = make_unique<CommandControlUnit>();
172 ccu_pt->SS_reliability = _pt; // shares ownership with the cluster branch (no adoption)
173 ccu_pt->copyTimer(*_pt);
174 ccu_pt->setAssociatedBranchID(_associated_branch_id);
175 commands.push_back(std::move(ccu_pt));
176}
177void CommandControlCenter::addNewAlarm(const std::shared_ptr<BranchSystemAlarmState> &_pt, int _associated_branch_id) {
178 auto ccu_pt = make_unique<CommandControlUnit>();
179 ccu_pt->new_alarm = _pt; // shares ownership with the cluster branch (no adoption)
180 ccu_pt->copyTimer(*_pt);
181 ccu_pt->setAssociatedBranchID(_associated_branch_id);
182 commands.push_back(std::move(ccu_pt));
183}
184
186 decltype(commands)::iterator commands_itr;
187 for (commands_itr = commands.begin(); commands_itr != commands.end(); commands_itr++) {
188 (*commands_itr)->reduceRemainingTime(x);
189 }
190 for (commands_itr = commands_residual.begin(); commands_itr != commands_residual.end(); commands_itr++) {
191 (*commands_itr)->reduceRemainingTime(x);
192 }
193}
194
196
197 string str;
198 decltype(commands)::iterator commands_itr;
199 this->reduceRemainingTime(0.5);
200 commands_itr = commands.begin();
201 while (commands_itr != commands.end()) {
202 if ((*commands_itr)->getRemainingTime() <= 0.0) {
203 if ((*commands_itr)->goal != 0) {
204 (*commands_itr)->goal->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
205 (*commands_itr)->goal->setTimeOfCommunication(r5pars_.timesno);
206 str = (*commands_itr)->goal->translateMessage();
207 g_sim.Communication_place.goal.push_back(std::move((*commands_itr)->goal));
209 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
210 } else if ((*commands_itr)->strategy != 0) {
211 (*commands_itr)->strategy->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
212 (*commands_itr)->strategy->setTimeOfCommunication(r5pars_.timesno);
213 str = (*commands_itr)->strategy->translateMessage();
214 g_sim.Communication_place.strategy.push_back(std::move((*commands_itr)->strategy));
216 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
217 } else if ((*commands_itr)->subgoal != 0) {
218 (*commands_itr)->subgoal->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
219 (*commands_itr)->subgoal->setTimeOfCommunication(r5pars_.timesno);
220 str = (*commands_itr)->subgoal->translateMessage();
221 g_sim.Communication_place.subgoal.push_back(std::move((*commands_itr)->subgoal));
223 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
224 } else if ((*commands_itr)->diagnosis != 0) {
225 (*commands_itr)->diagnosis->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
226 (*commands_itr)->diagnosis->setTimeOfCommunication(r5pars_.timesno);
227 str = (*commands_itr)->diagnosis->translateMessage();
228 g_sim.Communication_place.diagnosis.push_back(std::move((*commands_itr)->diagnosis));
230 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
231 } else if ((*commands_itr)->action_objective != 0) {
232 (*commands_itr)->action_objective->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
233 (*commands_itr)->action_objective->setTimeOfCommunication(r5pars_.timesno);
234 g_sim.Communication_place.action_objective.push_back(std::move((*commands_itr)->action_objective));
235 } else if ((*commands_itr)->action_pack != 0) {
236 (*commands_itr)->action_pack->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
237 (*commands_itr)->action_pack->setTimeOfCommunication(r5pars_.timesno);
238 g_sim.Communication_place.action_pack.push_back(std::move((*commands_itr)->action_pack));
239 } else if ((*commands_itr)->action != 0) {
240 if ((*commands_itr)->action->getIntendedReceiver() == sim::Source::Plant) {
241 (*commands_itr)->action->setTimeAtWhichThisControlIsActivated(r5pars_.timesno);
242 } else {
243 (*commands_itr)->action->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
244 (*commands_itr)->action->setTimeOfCommunication(r5pars_.timesno);
245 }
246 str = (*commands_itr)->action->translateMessage();
247 g_sim.Communication_place.action.push_back(std::move((*commands_itr)->action));
249 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
250 } else if ((*commands_itr)->alarm_state != 0) {
251 (*commands_itr)->alarm_state->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
252 (*commands_itr)->alarm_state->setTimeOfCommunication(r5pars_.timesno);
253 str = (*commands_itr)->alarm_state->translateMessage();
254 g_sim.Communication_place.alarm_state.push_back(std::move((*commands_itr)->alarm_state));
256 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
257 } else if ((*commands_itr)->component_state != 0) {
258 (*commands_itr)->component_state->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
259 (*commands_itr)->component_state->setTimeOfCommunication(r5pars_.timesno);
260 str = (*commands_itr)->component_state->translateMessage();
261 g_sim.Communication_place.component_state.push_back(std::move((*commands_itr)->component_state));
263 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
264 } else if ((*commands_itr)->support_system_state != 0) {
265 (*commands_itr)->support_system_state->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
266 (*commands_itr)->support_system_state->setTimeOfCommunication(r5pars_.timesno);
267 str = (*commands_itr)->support_system_state->translateMessage();
268 g_sim.Communication_place.support_system_state.push_back(std::move((*commands_itr)->support_system_state));
270 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
271 }
272 // parameter trends are delivered too (expectations that use "RATE_" parameters depend on them)
273 else if ((*commands_itr)->parameter_trend != 0) {
274 (*commands_itr)->parameter_trend->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
275 (*commands_itr)->parameter_trend->setTimeOfCommunication(r5pars_.timesno);
276 str = (*commands_itr)->parameter_trend->translateMessage();
277 g_sim.Communication_place.parameter_trend.push_back(std::move((*commands_itr)->parameter_trend));
279 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
280 } else if ((*commands_itr)->parameter_value != 0) {
281 (*commands_itr)->parameter_value->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
282 (*commands_itr)->parameter_value->setTimeOfCommunication(r5pars_.timesno);
283 str = (*commands_itr)->parameter_value->translateMessage();
284 g_sim.Communication_place.parameter_value.push_back(std::move((*commands_itr)->parameter_value));
286 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
287 } else if ((*commands_itr)->parameter_difference != 0) {
288 (*commands_itr)->parameter_difference->first_mental_parameter.setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
289 (*commands_itr)->parameter_difference->second_mental_parameter.setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
290 (*commands_itr)->parameter_difference->setTimeOfCommunication(r5pars_.timesno);
291 str = (*commands_itr)->parameter_difference->translateMessage();
292 g_sim.Communication_place.parameter_difference.push_back(std::move((*commands_itr)->parameter_difference));
294 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
295 } else if ((*commands_itr)->procedure_step != 0) {
296 (*commands_itr)->procedure_step->setTimeOfCommunication(r5pars_.timesno);
297 str = (*commands_itr)->procedure_step->translateMessage();
298 g_sim.Communication_place.procedure_step.push_back(std::move((*commands_itr)->procedure_step));
300 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
301 } else if ((*commands_itr)->instinctive_response_procedure != 0) {
302 (*commands_itr)->instinctive_response_procedure->setTimeOfCommunication(r5pars_.timesno);
303 str = (*commands_itr)->instinctive_response_procedure->translateMessage();
304 g_sim.Communication_place.instinctive_response_procedure.push_back(std::move((*commands_itr)->instinctive_response_procedure));
306 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
307 } else if ((*commands_itr)->info_gather_mode != 0) {
308 (*commands_itr)->info_gather_mode->setTimeOfCommunication(r5pars_.timesno);
309 str = (*commands_itr)->info_gather_mode->translateMessage();
310 g_sim.Communication_place.info_gather_mode.push_back(std::move((*commands_itr)->info_gather_mode));
312 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
313 } else if ((*commands_itr)->HW_reliability != 0) {
314 (*commands_itr)->HW_reliability->setTimeAtWhichThisControlIsActivated(r5pars_.timesno);
315 (*commands_itr)->HW_reliability->setTimeOfCommunication(r5pars_.timesno);
316 str = (*commands_itr)->HW_reliability->translateMessage();
317 g_sim.Communication_place.HW_reliability.push_back(std::move((*commands_itr)->HW_reliability));
319 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
320 } else if ((*commands_itr)->SS_reliability != 0) {
321 (*commands_itr)->SS_reliability->setTimeAtWhichThisControlIsActivated(r5pars_.timesno);
322 (*commands_itr)->SS_reliability->setTimeOfCommunication(r5pars_.timesno);
323 str = (*commands_itr)->SS_reliability->translateMessage();
324 g_sim.Communication_place.SS_reliability.push_back(std::move((*commands_itr)->SS_reliability));
326 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
327 } else if ((*commands_itr)->mental_belief != 0) {
328 (*commands_itr)->mental_belief->setTimeOfCommunication(r5pars_.timesno);
329 str = (*commands_itr)->mental_belief->translateMessage();
330 g_sim.Communication_place.mental_belief.push_back(std::move((*commands_itr)->mental_belief));
332 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
333 } else if ((*commands_itr)->scanned_parameter != 0) {
334 (*commands_itr)->scanned_parameter->setTimeOfCommunication(r5pars_.timesno);
335 str = (*commands_itr)->scanned_parameter->translateMessage();
336 g_sim.Communication_place.scanned_parameter.push_back(std::move((*commands_itr)->scanned_parameter));
338 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
339 } else if ((*commands_itr)->new_alarm != 0) {
340 (*commands_itr)->new_alarm->setTimeAtWhichThisAlarmIsActivated(r5pars_.timesno);
341 str = "New Alarm: ";
342 // indicate if the alarm actuates or clears
343 if ((*commands_itr)->new_alarm->getDisplayedAlarmState() == sim::State::On) {
344 str += " Actuation ";
345 } else {
346 str += " Clear ";
347 }
348 str += (*commands_itr)->new_alarm->getAlarmName();
349 g_sim.Communication_place.new_alarm.push_back(std::move((*commands_itr)->new_alarm));
351 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
352 } else {
353 //output error message
354 ofstream fout("err messages.txt", ios::app);
355 cout << "CommandControlCenter::sendInfoToCommunicationPlace; commands has unrecognizable object" << endl;
356 fout << r5pars_.timesno
357 << " CommandControlCenter::sendInfoToCommunicationPlace; commands has unrecognizable object\n";
358 fout.close();
359 }
360 (*commands_itr)->releaseAllMembers();
361 commands_itr = commands.erase(commands_itr);
362 } else {
363 commands_itr++;
364 }
365 }
366 //for command residual
367 commands_itr = commands_residual.begin();
368 while (commands_itr != commands_residual.end()) {
369 if ((*commands_itr)->getRemainingTime() <= 0.0 && (*commands_itr)->getStateOfActivation() == sim::None) {
370 (*commands_itr)->setStateOfActivation(sim::State::Succeed);
371 if ((*commands_itr)->goal != 0) {
372 (*commands_itr)->goal->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
373 (*commands_itr)->goal->setTimeOfCommunication(r5pars_.timesno);
374 str = (*commands_itr)->goal->translateMessage();
375 g_sim.Communication_place.goal.push_back(std::move((*commands_itr)->goal));
377 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
378 } else if ((*commands_itr)->strategy != 0) {
379 (*commands_itr)->strategy->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
380 (*commands_itr)->strategy->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
381 str = (*commands_itr)->strategy->translateMessage();
382 g_sim.Communication_place.strategy.push_back(std::move((*commands_itr)->strategy));
384 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
385 } else if ((*commands_itr)->subgoal != 0) {
386 (*commands_itr)->subgoal->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
387 (*commands_itr)->subgoal->setTimeOfCommunication(r5pars_.timesno);
388 str = (*commands_itr)->subgoal->translateMessage();
389 g_sim.Communication_place.subgoal.push_back(std::move((*commands_itr)->subgoal));
391 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
392 } else if ((*commands_itr)->diagnosis != 0) {
393 (*commands_itr)->diagnosis->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
394 (*commands_itr)->diagnosis->setTimeOfCommunication(r5pars_.timesno);
395 str = (*commands_itr)->diagnosis->translateMessage();
396 g_sim.Communication_place.diagnosis.push_back(std::move((*commands_itr)->diagnosis));
398 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
399 } else if ((*commands_itr)->action_objective != 0) {
400 (*commands_itr)->action_objective->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
401 (*commands_itr)->action_objective->setTimeOfCommunication(r5pars_.timesno);
402 g_sim.Communication_place.action_objective.push_back(std::move((*commands_itr)->action_objective));
403 } else if ((*commands_itr)->action_pack != 0) {
404 (*commands_itr)->action_pack->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
405 (*commands_itr)->action_pack->setTimeOfCommunication(r5pars_.timesno);
406 g_sim.Communication_place.action_pack.push_back(std::move((*commands_itr)->action_pack));
407 } else if ((*commands_itr)->action != 0) {
408 if ((*commands_itr)->action->getIntendedReceiver() == sim::Source::Plant) {
409 (*commands_itr)->action->setTimeAtWhichThisControlIsActivated(r5pars_.timesno);
410 } else {
411 (*commands_itr)->action->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
412 (*commands_itr)->action->setTimeOfCommunication(r5pars_.timesno);
413 }
414 str = (*commands_itr)->action->translateMessage();
415 g_sim.Communication_place.action.push_back(std::move((*commands_itr)->action));
417 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
418 } else if ((*commands_itr)->alarm_state != 0) {
419 (*commands_itr)->alarm_state->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
420 (*commands_itr)->alarm_state->setTimeOfCommunication(r5pars_.timesno);
421 str = (*commands_itr)->alarm_state->translateMessage();
422 g_sim.Communication_place.alarm_state.push_back(std::move((*commands_itr)->alarm_state));
424 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
425 } else if ((*commands_itr)->component_state != 0) {
426 (*commands_itr)->component_state->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
427 (*commands_itr)->component_state->setTimeOfCommunication(r5pars_.timesno);
428 str = (*commands_itr)->component_state->translateMessage();
429 g_sim.Communication_place.component_state.push_back(std::move((*commands_itr)->component_state));
431 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
432 } else if ((*commands_itr)->support_system_state != 0) {
433 (*commands_itr)->support_system_state->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
434 (*commands_itr)->support_system_state->setTimeOfCommunication(r5pars_.timesno);
435 str = (*commands_itr)->support_system_state->translateMessage();
436 g_sim.Communication_place.support_system_state.push_back(std::move((*commands_itr)->support_system_state));
438 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
439 }
440 // parameter trends are delivered too
441 else if ((*commands_itr)->parameter_trend != 0) {
442 (*commands_itr)->parameter_trend->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
443 (*commands_itr)->parameter_trend->setTimeOfCommunication(r5pars_.timesno);
444 str = (*commands_itr)->parameter_trend->translateMessage();
445 g_sim.Communication_place.parameter_trend.push_back(std::move((*commands_itr)->parameter_trend));
447 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
448 }
449 //
450 else if ((*commands_itr)->parameter_value != 0) {
451 (*commands_itr)->parameter_value->setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
452 (*commands_itr)->parameter_value->setTimeOfCommunication(r5pars_.timesno);
453 str = (*commands_itr)->parameter_value->translateMessage();
454 g_sim.Communication_place.parameter_value.push_back(std::move((*commands_itr)->parameter_value));
456 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
457 } else if ((*commands_itr)->parameter_difference != 0) {
458 (*commands_itr)->parameter_difference->first_mental_parameter.setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
459 (*commands_itr)->parameter_difference->second_mental_parameter.setTimeAtWhichThisInfoIsPerceived(r5pars_.timesno);
460 (*commands_itr)->parameter_difference->setTimeOfCommunication(r5pars_.timesno);
461 str = (*commands_itr)->parameter_difference->translateMessage();
462 g_sim.Communication_place.parameter_difference.push_back(std::move((*commands_itr)->parameter_difference));
464 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
465 } else if ((*commands_itr)->procedure_step != 0) {
466 (*commands_itr)->procedure_step->setTimeOfCommunication(r5pars_.timesno);
467 str = (*commands_itr)->procedure_step->translateMessage();
468 g_sim.Communication_place.procedure_step.push_back(std::move((*commands_itr)->procedure_step));
470 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
471 } else if ((*commands_itr)->instinctive_response_procedure != 0) {
472 (*commands_itr)->instinctive_response_procedure->setTimeOfCommunication(r5pars_.timesno);
473 str = (*commands_itr)->instinctive_response_procedure->translateMessage();
474 g_sim.Communication_place.instinctive_response_procedure.push_back(std::move((*commands_itr)->instinctive_response_procedure));
476 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
477 } else if ((*commands_itr)->info_gather_mode != 0) {
478 (*commands_itr)->info_gather_mode->setTimeOfCommunication(r5pars_.timesno);
479 str = (*commands_itr)->info_gather_mode->translateMessage();
480 g_sim.Communication_place.info_gather_mode.push_back(std::move((*commands_itr)->info_gather_mode));
482 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
483 } else if ((*commands_itr)->mental_belief != 0) {
484 (*commands_itr)->mental_belief->setTimeOfCommunication(r5pars_.timesno);
485 str = (*commands_itr)->mental_belief->translateMessage();
486 g_sim.Communication_place.mental_belief.push_back(std::move((*commands_itr)->mental_belief));
488 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
489 } else if ((*commands_itr)->scanned_parameter != 0) {
490 (*commands_itr)->scanned_parameter->setTimeOfCommunication(r5pars_.timesno);
491 str = (*commands_itr)->scanned_parameter->translateMessage();
492 g_sim.Communication_place.scanned_parameter.push_back(std::move((*commands_itr)->scanned_parameter));
494 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
495 } else if ((*commands_itr)->HW_reliability != 0) {
496 (*commands_itr)->HW_reliability->setTimeAtWhichThisControlIsActivated(r5pars_.timesno);
497 (*commands_itr)->HW_reliability->setTimeOfCommunication(r5pars_.timesno);
498 str = (*commands_itr)->HW_reliability->translateMessage();
499 g_sim.Communication_place.HW_reliability.push_back(std::move((*commands_itr)->HW_reliability));
501 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
502 } else if ((*commands_itr)->SS_reliability != 0) {
503 (*commands_itr)->SS_reliability->setTimeAtWhichThisControlIsActivated(r5pars_.timesno);
504 (*commands_itr)->SS_reliability->setTimeOfCommunication(r5pars_.timesno);
505 str = (*commands_itr)->SS_reliability->translateMessage();
506 g_sim.Communication_place.SS_reliability.push_back(std::move((*commands_itr)->SS_reliability));
508 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
509 } else if ((*commands_itr)->new_alarm != 0) {
510 (*commands_itr)->new_alarm->setTimeAtWhichThisAlarmIsActivated(r5pars_.timesno);
511 str = "New Alarm: ";
512 // indicate if the alarm actuates or clears
513 if ((*commands_itr)->new_alarm->getDisplayedAlarmState() == sim::State::On) {
514 str += " Actuation ";
515 } else {
516 str += " Clear ";
517 }
518 str += (*commands_itr)->new_alarm->getAlarmName();
519 g_sim.Communication_place.new_alarm.push_back(std::move((*commands_itr)->new_alarm));
521 g_sim.Aux_info.addRecord(str, (*commands_itr)->getAssociatedBranchID());
522 } else {
523 //output error message
524 ofstream fout("err messages.txt", ios::app);
525 cout << "CommandControlCenter::sendInfoToCommunicationPlace; commands_residual has unrecognizable object"
526 << " ptr=" << (void*)(*commands_itr).get()
527 << " goal=" << (void*)(*commands_itr)->goal.get()
528 << " strategy=" << (void*)(*commands_itr)->strategy.get()
529 << " subgoal=" << (void*)(*commands_itr)->subgoal.get()
530 << " diagnosis=" << (void*)(*commands_itr)->diagnosis.get()
531 << " action=" << (void*)(*commands_itr)->action.get()
532 << " procedure_step=" << (void*)(*commands_itr)->procedure_step.get()
533 << " HW_reliability=" << (void*)(*commands_itr)->HW_reliability.get()
534 << " SS_reliability=" << (void*)(*commands_itr)->SS_reliability.get()
535 << " remainingTime=" << (*commands_itr)->getRemainingTime()
536 << " branchID=" << (*commands_itr)->getAssociatedBranchID()
537 << endl;
538 fout << r5pars_.timesno
539 << " CommandControlCenter::sendInfoToCommunicationPlace; commands_residual has unrecognizable object\n";
540 fout.close();
541 }
542 commands_itr++;
543 } else if ((*commands_itr)->getStateOfActivation() == sim::State::Succeed) {
544 commands_itr = commands_residual.erase(commands_itr);
545 } else if ((*commands_itr)->getRemainingTime() <= 0.0) {
546 commands_itr = commands_residual.erase(commands_itr);
547 } else {
548 commands_itr++;
549 }
550 }
551}
554}
556 commands.clear();
557 commands_residual.clear();
558}
559
561 commands.clear();
562 commands_residual.clear();
563}
566}
569}
571 for (auto& src : _cc.commands) {
572 auto ptr = make_unique<CommandControlUnit>();
573 ptr->copyCommandControlUnit(*src);
574 commands_residual.push_back(std::move(ptr));
575 }
576 for (auto& src : _cc.commands_residual) {
577 if (src->getStateOfActivation() != sim::State::Succeed) {
578 auto ptr = make_unique<CommandControlUnit>();
579 ptr->copyCommandControlUnit(*src);
580 commands_residual.push_back(std::move(ptr));
581 }
582 }
583}
584
586 for (auto& src : _cc.commands_residual) {
587 auto ptr = make_unique<CommandControlUnit>();
588 ptr->copyCommandControlUnit(*src);
589 commands_residual.push_back(std::move(ptr));
590 }
591}
593 fout << "CommandControlCenter\n" << commands.size() << ' ';
594 for (auto& c : commands) {
595 c->saveCommandControlUnitToFile(fout);
596 }
597 fout << commands_residual.size() << ' ';
598 for (auto& c : commands_residual) {
599 c->saveCommandControlUnitToFile(fout);
600 }
601}
603 int i, num;
604 CommandControlUnit *commands_pt;
605 string str;
606 fin >> str >> num;
607 if (str != "CommandControlCenter") {
608 ofstream fout("err messages.txt", ios::app);
609 cout << "CommandControlCenter::retrieveCommandControlCenterFromFile retrieval error in previous function" << endl;
610 fout << r5pars_.timesno
611 << " CommandControlCenter::retrieveCommandControlCenterFromFile retrieval error in previous function\n";
612 fout.close();
613 r5pars_.sim_err = true;
614 g_sim.Branch_center.setTempESMessage("CommandControlCenter::retrieveCommandControlCenterFromFile Prior err.");
616 return;
617 }
618
619 for (i = 0; i < num; i++) {
620 auto ptr = make_unique<CommandControlUnit>();
621 ptr->retrieveCommandControlUnitFromFile(fin);
622 //the retrieved info is saved into commands_residual
623 this->commands_residual.push_back(std::move(ptr));
624 }
625 fin >> num;
626 for (i = 0; i < num; i++) {
627 auto ptr = make_unique<CommandControlUnit>();
628 ptr->retrieveCommandControlUnitFromFile(fin);
629 if (ptr->getStateOfActivation() != sim::State::Succeed) {
630 this->commands_residual.push_back(std::move(ptr));
631 }
632 }
633}
634
635// Prints the message to standard output, prefixed with the simulation time, only
636// when _CONSOLE is defined at compile time. Without that definition the function
637// does nothing (the network GUI path below is commented out).
638
639void CommandControlCenter::displayInformation(string strInformation) {
640#ifndef _CONSOLE
641 // CString strMsg; // CString used only for network version
642 // strMsg.Format("%f %s", r5pars_.timesno, strInformation.c_str());
643 // theActivitiesStrList.AddTail(strMsg);
644#else
645 cout << " " << r5pars_.timesno << " " << strInformation << endl;
646#endif
647}
Command/control dispatch — routes crew decisions to plant actions and branch generation.
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
void addRecord(std::string, int)
void setTempTypeOfConsequence(Consequence)
Stores the consequence of the end state the running sequence will get.
void setTempESMessage(std::string)
Stores the description of the end state the running sequence will get if it is terminated (set by mod...
std::vector< std::shared_ptr< BranchSubGoal > > subgoal
Definition: BranchUnit.h:55
std::vector< std::shared_ptr< BranchExpectedParameterTrend > > parameter_trend
Definition: BranchUnit.h:63
std::vector< std::shared_ptr< BranchInfoGatherMode > > info_gather_mode
Definition: BranchUnit.h:68
std::vector< std::shared_ptr< BranchProcedureStep > > instinctive_response_procedure
Definition: BranchUnit.h:67
std::vector< std::shared_ptr< BranchGoal > > goal
Definition: BranchUnit.h:53
std::vector< std::shared_ptr< BranchActionPack > > action_pack
Definition: BranchUnit.h:58
std::vector< std::shared_ptr< BranchExpectedSupportSystemState > > support_system_state
Definition: BranchUnit.h:62
std::vector< std::shared_ptr< BranchExpectedParameterDifference > > parameter_difference
Definition: BranchUnit.h:65
std::vector< std::shared_ptr< BranchDiagnosis > > diagnosis
Definition: BranchUnit.h:56
std::vector< std::shared_ptr< BranchExpectedMentalBelief > > mental_belief
Definition: BranchUnit.h:69
std::vector< std::shared_ptr< BranchExpectedParameterValue > > parameter_value
Definition: BranchUnit.h:64
std::vector< std::shared_ptr< BranchScannedParameter > > scanned_parameter
Definition: BranchUnit.h:70
std::vector< std::shared_ptr< BranchExpectedComponentState > > component_state
Definition: BranchUnit.h:61
std::vector< std::shared_ptr< BranchStrategy > > strategy
Definition: BranchUnit.h:54
std::vector< std::shared_ptr< BranchProcedureStep > > procedure_step
Definition: BranchUnit.h:66
std::vector< std::shared_ptr< BranchExpectedAlarmState > > alarm_state
Definition: BranchUnit.h:60
std::vector< std::shared_ptr< BranchAction > > action
Definition: BranchUnit.h:59
std::vector< std::shared_ptr< BranchActionObjective > > action_objective
Definition: BranchUnit.h:57
void addNewAlarm(const std::shared_ptr< BranchSystemAlarmState > &, int)
void addSubGoal(const std::shared_ptr< BranchSubGoal > &, int)
void addExpectedParameterTrend(const std::shared_ptr< BranchExpectedParameterTrend > &, int)
void addDiagnosis(const std::shared_ptr< BranchDiagnosis > &, int)
void addActionObjective(const std::shared_ptr< BranchActionObjective > &, int)
void addExpectedParameterValue(const std::shared_ptr< BranchExpectedParameterValue > &, int)
void addActionPack(const std::shared_ptr< BranchActionPack > &, int)
void addExpectedComponentState(const std::shared_ptr< BranchExpectedComponentState > &, int)
void copyCommandControlCenterToRestartInfo(CommandControlCenter &)
void addExpectedSupportSystemState(const std::shared_ptr< BranchExpectedSupportSystemState > &, int)
std::list< std::unique_ptr< CommandControlUnit > > commands_residual
void addSSReliability(const std::shared_ptr< BranchSupportSystemAction > &, int)
void addHWReliability(const std::shared_ptr< BranchSystemAction > &, int)
void addAction(const std::shared_ptr< BranchAction > &, int)
void displayInformation(std::string strInformation)
std::list< std::unique_ptr< CommandControlUnit > > commands
void saveCommandControlCenterToFile(std::ofstream &)
void addExpectedAlarmState(const std::shared_ptr< BranchExpectedAlarmState > &, int)
void copyCommandControlCenterFromRestartInfo(CommandControlCenter &)
void retrieveCommandControlCenterFromFile(std::ifstream &)
void addMentalBelief(const std::shared_ptr< BranchExpectedMentalBelief > &, int)
void addExpectedParameterDifference(const std::shared_ptr< BranchExpectedParameterDifference > &, int)
void addStrategy(const std::shared_ptr< BranchStrategy > &, int)
void addInstinctiveResponseProcedure(const std::shared_ptr< BranchProcedureStep > &, int)
void addScannedParameter(const std::shared_ptr< BranchScannedParameter > &, int)
void addInfoGatherMode(const std::shared_ptr< BranchInfoGatherMode > &, int)
void addProcedureStep(const std::shared_ptr< BranchProcedureStep > &, int)
void addGoal(const std::shared_ptr< BranchGoal > &, int)
std::vector< std::shared_ptr< BranchSystemAction > > HW_reliability
std::vector< std::shared_ptr< BranchSystemAlarmState > > new_alarm
std::vector< std::shared_ptr< BranchSupportSystemAction > > SS_reliability
struct @0 r5pars_
constexpr int Plant
Definition: SimConstants.h:135
constexpr int On
Definition: SimConstants.h:105
constexpr int Succeed
Definition: SimConstants.h:104
constexpr int None
Definition: SimConstants.h:75
CommunicationPlace Communication_place
Inter-module communication.
AnalysisInfoContainer Aux_info
Analysis records.
BranchRecord Branch_center
Dynamic event tree state.