← Documentation
ADS-IDAC Engine 5.0.0
RoutineMonitorUnit.cpp
Go to the documentation of this file.
1// RoutineMonitorUnit.cpp: implementation of the RoutineMonitorUnit class.
2//
4
5#include <iostream>
6#include <fstream>
7
9#include "../Crew/OperatorDM.h"
10#include "../Global/SimulationContext.h"
11
12
13using namespace std;
14
16// Construction/Destruction
18
20 this->m_relevance = 1;
21 this->m_last_update_time = 0;
22 this->m_MR_unit_pt = NULL;
23 this->m_ID_MR_unit = "";
24}
25
27
28}
29
31 string str, ID_str;
32 string err_mes;
33 float Interval;
34
35 ReasonMachine *RM_pt;
36 if (this->m_operator == sim::Operator::ODM) { RM_pt = g_sim.Decision_Maker.m_RM.get(); }
37 else if (this->m_operator == sim::Operator::OAT) { RM_pt = g_sim.Action_Taker.m_RM.get(); }
38 else {}//add error message
39
40 fin >> str >> ID_str;
41 if (str.compare("Concept_Name:") != 0) {
42 err_mes = "Concept_Name is missing in Routine_Monitor_List txt file. \n";
43 err_mes += "And " + ID_str + " is misplaced";
44 this->ErrorMessage(err_mes);
45 return;
46 }
47 this->m_MR_unit_pt = RM_pt->m_MR->CheckExistenceByConceptName(ID_str);
48 if (this->m_MR_unit_pt == NULL) {
49 err_mes = "Error in the Routine_Monitor_List txt file \n";
50 err_mes += "could not find this concept in semantic base: " + ID_str;
51 this->ErrorMessage(err_mes);
52 return;
53 }
54
55 fin >> str >> Interval;
56 if (str.compare("Monitor_Interval:") != 0) {
57 err_mes = "Monitor_Interval of " + ID_str + " is missing in Routine_Monitor_List txt file. \n";
58 this->ErrorMessage(err_mes);
59 return;
60 }
61 this->m_desired_monitor_interval = Interval;
62}
63
65 MRParameterUnit *P_pt;
68 MRAlarmUnit *A_pt;
69 double update_time;
70
71 if (this->m_MR_unit_pt == NULL) { return 0; }//error message
72 switch (this->m_MR_unit_pt->m_ID_Type) {
73 case 201: P_pt = (MRParameterUnit *) this->m_MR_unit_pt;
74 if (P_pt->m_recent_parameter_value != NULL) {
75 update_time = P_pt->m_recent_parameter_value->m_time_perceived;
76 } else {
77 update_time = 0;
78 }
79 break;
80 case 202: C_pt = (MRComponentStateUnit *) this->m_MR_unit_pt;
81 if (C_pt->m_CS_type == 0) {
82 if (C_pt->m_recent_state != NULL) {
83 update_time = C_pt->m_recent_state->m_time_perceived;
84 } else {
85 update_time = 0;
86 }
87 } else if (C_pt->m_CS_type == 1) {
88 if (C_pt->m_recent_position_value != NULL) {
89 update_time = C_pt->m_recent_position_value->m_time_perceived;
90 } else {
91 update_time = 0;
92 }
93 } else {}//error message
94 break;
95 case 203: A_pt = (MRAlarmUnit *) this->m_MR_unit_pt;
96 if (A_pt->m_recent_state != NULL) {
97 update_time = A_pt->m_recent_state->m_time_perceived;
98 } else {
99 update_time = 0;
100 }
101 break;
102 case 204: SS_pt = (MRSupportSystemStateUnit *) this->m_MR_unit_pt;
103 if (SS_pt->m_recent_state != NULL) {
104 update_time = SS_pt->m_recent_state->m_time_perceived;
105 } else {
106 update_time = 0;
107 }
108 break;
109 default:
110 //error message
111 break;
112 }
113 this->m_last_update_time = update_time;
114 return this->m_last_update_time;
115}
116
118 cout << r5pars_.timesno << " " << str << " inRoutineMonitorUnit.cpp" << '\n';
119 ofstream fout("err messages.txt", ios::app);
120 fout << r5pars_.timesno << " " << str << '\n';
121 fout.close();
122 //r5pars_.terminateall = true;
123}
124
126 this->CopyIDElementToRestartInfo((IDElement *) _monitor_pt);
128 this->m_last_update_time = _monitor_pt->m_last_update_time;
129 this->m_operator = _monitor_pt->m_operator;
130 if (_monitor_pt->m_MR_unit_pt != NULL) {
131 this->m_ID_MR_unit = _monitor_pt->m_MR_unit_pt->m_ID;
132 } else {
133 this->m_ID_MR_unit = _monitor_pt->m_ID_MR_unit;
134 }
135
136}
137
139 ReasonMachine *RM_pt;
140 RM_pt = (ReasonMachine *) _pt;
141 //IDElement * m_MR_unit_pt;
142 this->m_MR_unit_pt = RM_pt->m_MR->FindMRUnitByID(this->m_ID_MR_unit);
143 if (this->m_MR_unit_pt == NULL) {
144 this->ErrorMessage("could not find the corresponding MR unit " + this->m_ID_MR_unit);
145 return;
146 }
147}
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
void CopyIDElementToRestartInfo(IDElement *)
Definition: IDElement.cpp:23
int m_ID_Type
Definition: IDElement.h:15
std::string m_ID
Definition: IDElement.h:16
std::unique_ptr< MRStateSchema > m_recent_state
Definition: MRAlarmUnit.h:34
std::unique_ptr< MRStateSchema > m_recent_state
std::unique_ptr< MRValueSchema > m_recent_position_value
std::unique_ptr< MRValueSchema > m_recent_parameter_value
std::unique_ptr< MRStateSchema > m_recent_state
std::unique_ptr< ReasonMachine > m_RM
Definition: Operator.h:55
std::unique_ptr< MentalRepresentation > m_MR
void ReadRoutineMonitorUnitInfoFromInputFile(std::ifstream &)
void CopyRMUinfoFromAnother(RoutineMonitorUnit *)
void ErrorMessage(std::string)
void BuildConnectionsForThisRoutineMonitorUnit(void *)
struct @0 r5pars_
constexpr int ODM
Definition: SimConstants.h:145
constexpr int OAT
Definition: SimConstants.h:144
OperatorAT Action_Taker
Crew action execution model.
OperatorDM Decision_Maker
Crew decision-making model.