←
Documentation
ADS-IDAC Engine
5.0.0
ControlState.cpp
Go to the documentation of this file.
1
// ControlState.cpp: implementation of the ControlState class.
2
//
4
5
#include "
ControlState.h
"
6
#include "../Global/TermConversions.h"
7
#include "../Branch/BranchRecord.h"
8
#include <boost/serialization/export.hpp>
9
#include "../Global/SimulationContext.h"
10
#include <boost/archive/binary_oarchive.hpp>
11
#include <boost/archive/binary_iarchive.hpp>
12
BOOST_CLASS_EXPORT_IMPLEMENT(
ControlState
)
13
using namespace
std;
14
16
// Construction/Destruction
18
19
ControlState::ControlState
()
20
{
21
displyed_control_state
=
sim::State::Auto
;
22
displyed_control_state_when_fail
=
sim::State::Auto
;
// deterministic default, overwritten by readInfoFromFile
23
SystemControl::setTypeOfControl
(
DisplayType::ControlState
);
24
}
25
26
ControlState::~ControlState
()
27
{
28
29
}
30
void
ControlState::setDisplayedControlStateWhenFail
(
int
n){
displyed_control_state_when_fail
= n;}
31
int
ControlState::getDisplayedControlStateWhenFail
(){
return
displyed_control_state_when_fail
;}
32
void
ControlState::setDisplayedControlState
(
int
n){
displyed_control_state
= n;}
33
int
ControlState::getDisplayedControlState
(){
return
displyed_control_state
;}
34
void
ControlState::readInfoFromFile
(ifstream &fin){
35
string
str;
36
SystemControl::readInfoFromFile
(fin);
37
fin >> str;
38
if
(str ==
"ON"
){
39
displyed_control_state_when_fail
=
sim::State::On
;}
40
else
if
(str ==
"OFF"
){
41
displyed_control_state_when_fail
=
sim::State::Off
;}
42
else
if
(str ==
"OPEN"
){
43
displyed_control_state_when_fail
=
sim::State::Open
;}
44
else
if
(str ==
"CLOSE"
){
45
displyed_control_state_when_fail
=
sim::State::Close
;}
46
else
if
(str ==
"NONE"
){
47
displyed_control_state_when_fail
=
sim::None
;
48
}
49
else
{
50
ofstream fout(
"err messages.txt"
, ios::app);
51
cout <<
"ControlState::readInfoFromFile Control "
<<
SystemControl::getDisplayName
() <<
" whose displayed_control_state_when_fail "
52
<<
displyed_control_state_when_fail
<<
" can not be recognized."
<< endl;
53
fout <<
r5pars_
.timesno <<
" ControlState::readInfoFromFile Control "
<<
SystemControl::getDisplayName
() <<
" whose displayed_control_state_when_fail "
54
<<
displyed_control_state_when_fail
<<
" can not be recognized.\n"
;
55
fout.close();
56
r5pars_
.sim_err =
true
;
57
g_sim
.
Branch_center
.
setTempESMessage
(
"ControlState::readInfoFromFile err."
);
58
g_sim
.
Branch_center
.
setTempTypeOfConsequence
(
Consequence::NoKB
);
59
}
60
}
61
void
ControlState::updateDisplayedControlState
(
SystemModule
&_th,
int
_control_state){
62
InteractiveVariable
*iv_ptr;
63
iv_ptr =
SystemControl::getPtrToCorrespondingInteractiveVariable
();
64
if
(iv_ptr == 0){
65
SystemControl::setPtrToCorrespondingInteractiveVariable
((
InteractiveVariable
*) _th.
getComponentFromSystemMap
(
SystemControl::getCorrespondingComponentNameOfControl
()));
66
iv_ptr =
SystemControl::getPtrToCorrespondingInteractiveVariable
();
67
}
68
if
(iv_ptr != 0){
69
if
(
SystemControl::getFunctionalState
() ==
sim::State::Succeed
){
70
switch
(_control_state){
71
case
sim::State::Open
:
72
iv_ptr->
setInputValue
(
SystemControl::getValueForOnOrFullyOpen
());
73
this->
setDisplayedControlState
(
sim::State::Open
);
74
break
;
75
case
sim::State::Close
:
76
iv_ptr->
setInputValue
(
SystemControl::getValueForOffOrFullyClose
());
77
this->
setDisplayedControlState
(
sim::State::Close
);
78
break
;
79
case
sim::State::On
:
80
iv_ptr->
setInputValue
(
SystemControl::getValueForOnOrFullyOpen
());
81
this->
setDisplayedControlState
(
sim::State::On
);
82
break
;
83
case
sim::State::Off
:
84
iv_ptr->
setInputValue
(
SystemControl::getValueForOffOrFullyClose
());
85
this->
setDisplayedControlState
(
sim::State::Off
);
86
break
;
87
default
:
88
break
;
89
ofstream fout(
"err messages.txt"
, ios::app);
90
cout <<
" ControlState::updateDisplayedControlState Component "
<<
SystemControl::getCorrespondingComponentNameOfControl
()
91
<<
"whose control state "
<< _control_state <<
" can not be recognized."
<< endl;
92
fout <<
r5pars_
.timesno <<
" ControlState::updateDisplayedControlState Component "
<<
SystemControl::getCorrespondingComponentNameOfControl
()
93
<<
"whose control state "
<< _control_state <<
" can not be recognized.\n"
;
94
fout.close();
95
r5pars_
.sim_err =
true
;
96
g_sim
.
Branch_center
.
setTempESMessage
(
"ControlState::updateDisplayedControlState err."
);
97
g_sim
.
Branch_center
.
setTempTypeOfConsequence
(
Consequence::AdsSimErr
);
98
}
99
}
100
else
{
//control fails
101
if
(
displyed_control_state_when_fail
!=
sim::None
){
102
this->
setDisplayedControlState
(
displyed_control_state_when_fail
);
103
}
104
}
105
}
106
else
{
107
ofstream fout(
"err messages.txt"
, ios::app);
108
cout <<
" ControlState::updateDisplayedControlState Component "
<<
SystemControl::getCorrespondingComponentNameOfControl
()
109
<<
" can not be located."
<< endl;
110
fout <<
r5pars_
.timesno <<
" ControlState::updateDisplayedControlState Component "
<<
SystemControl::getCorrespondingComponentNameOfControl
()
111
<<
" can not be located.\n"
;
112
fout.close();
113
r5pars_
.sim_err =
true
;
114
g_sim
.
Branch_center
.
setTempESMessage
(
"ControlState::updateDisplayedControlState err."
);
115
g_sim
.
Branch_center
.
setTempTypeOfConsequence
(
Consequence::AdsSimErr
);
116
}
117
}
118
void
ControlState::performValueControl
(
SystemModule
&_th,
double
_control_value){
119
InteractiveVariable
*iv_ptr;
120
iv_ptr =
SystemControl::getPtrToCorrespondingInteractiveVariable
();
121
if
(iv_ptr == 0){
122
SystemControl::setPtrToCorrespondingInteractiveVariable
((
InteractiveVariable
*) _th.
getComponentFromSystemMap
(
SystemControl::getCorrespondingComponentNameOfControl
()));
123
iv_ptr =
SystemControl::getPtrToCorrespondingInteractiveVariable
();
124
}
125
if
(iv_ptr != 0){
126
iv_ptr->
setInputValue
(_control_value);
127
iv_ptr->
setNeedToInteract
(
true
);
128
// update control value
129
this->
setControlValue
(_control_value);
130
this->
setDisplayedControlState
(_control_value);
131
//
132
}
133
else
{
134
ofstream fout(
"err messages.txt"
, ios::app);
135
cout <<
" ControlState::performValueControl InteractiveVariable: "
<< this->
getCorrespondingComponentNameOfControl
() <<
" could not be found"
<< endl;
136
fout <<
r5pars_
.timesno <<
" ControlState::performValueControl InteractiveVariable: "
<< this->
getCorrespondingComponentNameOfControl
() <<
" could not be found.\n"
;
137
fout.close();
138
r5pars_
.sim_err =
true
;
139
g_sim
.
Branch_center
.
setTempESMessage
(
"ControlState::performValueControl err."
);
140
g_sim
.
Branch_center
.
setTempTypeOfConsequence
(
Consequence::AdsSimErr
);
141
}
142
}
143
144
void
ControlState::performDisplayedControlState
(
SystemModule
&_th,
int
_control_state){
145
InteractiveVariable
*iv_ptr;
146
iv_ptr =
SystemControl::getPtrToCorrespondingInteractiveVariable
();
147
if
(iv_ptr == 0){
148
SystemControl::setPtrToCorrespondingInteractiveVariable
((
InteractiveVariable
*) _th.
getComponentFromSystemMap
(
SystemControl::getCorrespondingComponentNameOfControl
()));
149
iv_ptr =
SystemControl::getPtrToCorrespondingInteractiveVariable
();
150
}
151
if
(iv_ptr != 0){
152
if
(
SystemControl::getFunctionalState
() ==
sim::State::Succeed
){
153
switch
(_control_state){
154
case
sim::State::Open
:
155
iv_ptr->
setInputValue
(
SystemControl::getValueForOnOrFullyOpen
());
156
iv_ptr->
setNeedToInteract
(
true
);
157
this->
setDisplayedControlState
(
sim::State::Open
);
158
break
;
159
case
sim::State::Close
:
160
iv_ptr->
setInputValue
(
SystemControl::getValueForOffOrFullyClose
());
161
iv_ptr->
setNeedToInteract
(
true
);
162
this->
setDisplayedControlState
(
sim::State::Close
);
163
break
;
164
case
sim::State::On
:
165
iv_ptr->
setInputValue
(
SystemControl::getValueForOnOrFullyOpen
());
166
iv_ptr->
setNeedToInteract
(
true
);
167
this->
setDisplayedControlState
(
sim::State::On
);
168
break
;
169
case
sim::State::Off
:
170
iv_ptr->
setInputValue
(
SystemControl::getValueForOffOrFullyClose
());
171
iv_ptr->
setNeedToInteract
(
true
);
172
this->
setDisplayedControlState
(
sim::State::Off
);
173
break
;
174
default
:
175
break
;
176
ofstream fout(
"err messages.txt"
, ios::app);
177
cout <<
" ControlState::updateDisplayedControlState Component "
<<
SystemControl::getCorrespondingComponentNameOfControl
()
178
<<
"whose control state "
<< _control_state <<
" can not be recognized."
<< endl;
179
fout <<
r5pars_
.timesno <<
" ControlState::updateDisplayedControlState Component "
<<
SystemControl::getCorrespondingComponentNameOfControl
()
180
<<
"whose control state "
<< _control_state <<
" can not be recognized.\n"
;
181
fout.close();
182
r5pars_
.sim_err =
true
;
183
g_sim
.
Branch_center
.
setTempESMessage
(
"ControlState::performDisplayedControlState err."
);
184
g_sim
.
Branch_center
.
setTempTypeOfConsequence
(
Consequence::AdsSimErr
);
185
}
186
}
187
else
{
//control fails
188
if
(
displyed_control_state_when_fail
!=
sim::None
){
189
this->
setDisplayedControlState
(
displyed_control_state_when_fail
);
190
}
191
}
192
}
193
else
{
194
ofstream fout(
"err messages.txt"
, ios::app);
195
cout <<
" ControlState::updateDisplayedControlState Component "
<<
SystemControl::getCorrespondingComponentNameOfControl
()
196
<<
" can not be located."
<< endl;
197
fout <<
r5pars_
.timesno <<
" ControlState::updateDisplayedControlState Component "
<<
SystemControl::getCorrespondingComponentNameOfControl
()
198
<<
" can not be located.\n"
;
199
fout.close();
200
r5pars_
.sim_err =
true
;
201
g_sim
.
Branch_center
.
setTempESMessage
(
"ControlState::performDisplayedControlState err."
);
202
g_sim
.
Branch_center
.
setTempTypeOfConsequence
(
Consequence::AdsSimErr
);
203
}
204
}
205
void
ControlState::initiateDisplayedControlState
(
SystemModule
&_th){
206
InteractiveVariable
*iv_ptr;
207
double
iv_value;
208
iv_ptr =
SystemControl::getPtrToCorrespondingInteractiveVariable
();
209
if
(iv_ptr == 0){
210
SystemControl::setPtrToCorrespondingInteractiveVariable
((
InteractiveVariable
*) _th.
getComponentFromSystemMap
(
SystemControl::getCorrespondingComponentNameOfControl
()));
211
iv_ptr =
SystemControl::getPtrToCorrespondingInteractiveVariable
();
212
}
213
if
(iv_ptr != 0){
214
iv_value = iv_ptr->
getDisplayValue
();
215
switch
(
displyed_control_state_when_fail
){
216
case
sim::State::Open
:
case
sim::State::Close
:
217
if
(fabs(iv_value -
SystemControl::getValueForOnOrFullyOpen
()) < 1.0E-6) {
218
this->
setDisplayedControlState
(
sim::State::Open
);
219
}
220
else
if
(fabs(iv_value -
SystemControl::getValueForOffOrFullyClose
()) < 1.0E-6){
221
this->
setDisplayedControlState
(
sim::State::Close
);
222
}
223
else
{
224
this->
setDisplayedControlState
(
sim::State::Auto
);
225
}
226
break
;
227
case
sim::State::On
:
case
sim::State::Off
:
228
if
(fabs(iv_value -
SystemControl::getValueForOnOrFullyOpen
()) < 1.0E-6) {
229
this->
setDisplayedControlState
(
sim::State::On
);
230
}
231
else
if
(fabs(iv_value -
SystemControl::getValueForOffOrFullyClose
()) < 1.0E-6){
232
this->
setDisplayedControlState
(
sim::State::Off
);
233
}
234
else
{
235
this->
setDisplayedControlState
(
sim::State::Auto
);
236
}
237
break
;
238
default
:
239
break
;
240
ofstream fout(
"err messages.txt"
, ios::app);
241
cout <<
" ControlState::initiateDisplayedControlState Component "
<<
SystemControl::getCorrespondingComponentNameOfControl
()
242
<<
"whose displyed_control_state_when_fail "
<<
displyed_control_state_when_fail
<<
" can not be recognized."
<< endl;
243
fout <<
r5pars_
.timesno <<
" ControlState::initiateDisplayedControlState Component "
<<
SystemControl::getCorrespondingComponentNameOfControl
()
244
<<
"whose displyed_control_state_when_fail "
<<
displyed_control_state_when_fail
<<
" can not be recognized.\n"
;
245
fout.close();
246
r5pars_
.sim_err =
true
;
247
g_sim
.
Branch_center
.
setTempESMessage
(
"ControlState::initiateDisplayedControlState err."
);
248
g_sim
.
Branch_center
.
setTempTypeOfConsequence
(
Consequence::AdsSimErr
);
249
}
250
}
251
else
{
252
ofstream fout(
"err messages.txt"
, ios::app);
253
cout <<
" ControlState::initiateDisplayedControlState Component "
<<
SystemControl::getCorrespondingComponentNameOfControl
()
254
<<
" can not be located."
<< endl;
255
fout <<
r5pars_
.timesno <<
" ControlState::initiateDisplayedControlState Component "
<<
SystemControl::getCorrespondingComponentNameOfControl
()
256
<<
" can not be located.\n"
;
257
fout.close();
258
r5pars_
.sim_err =
true
;
259
g_sim
.
Branch_center
.
setTempESMessage
(
"ControlState::initiateDisplayedControlState err."
);
260
g_sim
.
Branch_center
.
setTempTypeOfConsequence
(
Consequence::AdsSimErr
);
261
}
262
}
263
string
ControlState::getDisplayedControlStateString
(){
264
string
c_state;
265
switch
(
displyed_control_state
){
266
case
sim::State::Open
:
267
c_state =
"OPEN"
;
268
break
;
269
case
sim::State::Close
:
270
c_state =
"CLOSE"
;
271
break
;
272
case
sim::State::On
:
273
c_state =
"ON"
;
274
break
;
275
case
sim::State::Off
:
276
c_state =
"OFF"
;
277
break
;
278
default
:
279
c_state =
"UNKNOWN"
;
280
break
;
281
}
282
return
c_state;
283
}
284
285
void
ControlState::copyControlState
(
ControlState
&_cs){
286
displyed_control_state
= _cs.
getDisplayedControlState
();
287
displyed_control_state_when_fail
= _cs.
getDisplayedControlStateWhenFail
();
288
SystemControl::copySystemControl
(_cs);
289
}
290
void
ControlState::saveControlStateToFile
(ofstream &fout){
291
this->
saveSystemControlToFile
(fout);
292
fout <<
displyed_control_state
<<
' '
<<
displyed_control_state_when_fail
<<
'\n'
;
293
}
294
void
ControlState::retrieveControlStateFromFile
(ifstream &fin){
295
this->
retrieveSystemControlFromFile
(fin);
296
fin >>
displyed_control_state
>>
displyed_control_state_when_fail
;
297
}
ControlState.h
DisplayType::ControlState
@ ControlState
Consequence::NoKB
@ NoKB
Consequence::AdsSimErr
@ AdsSimErr
g_sim
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
Definition:
SimulationContext.cpp:7
BranchRecord::setTempTypeOfConsequence
void setTempTypeOfConsequence(Consequence)
Stores the consequence of the end state the running sequence will get.
Definition:
BranchRecord.cpp:1641
BranchRecord::setTempESMessage
void setTempESMessage(std::string)
Stores the description of the end state the running sequence will get if it is terminated (set by mod...
Definition:
BranchRecord.cpp:1640
ControlElement::getDisplayName
std::string getDisplayName()
Definition:
ControlElement.cpp:40
ControlElement::setControlValue
void setControlValue(double)
Definition:
ControlElement.cpp:63
ControlElement::getCorrespondingComponentNameOfControl
std::string getCorrespondingComponentNameOfControl()
Definition:
ControlElement.cpp:41
ControlElement::getValueForOnOrFullyOpen
double getValueForOnOrFullyOpen()
Definition:
ControlElement.cpp:43
ControlElement::getValueForOffOrFullyClose
double getValueForOffOrFullyClose()
Definition:
ControlElement.cpp:44
ControlElement::readInfoFromFile
void readInfoFromFile(std::ifstream &)
Definition:
ControlElement.cpp:46
ControlState
Definition:
ControlState.h:21
ControlState::displyed_control_state_when_fail
int displyed_control_state_when_fail
Definition:
ControlState.h:39
ControlState::getDisplayedControlStateString
std::string getDisplayedControlStateString()
Definition:
ControlState.cpp:263
ControlState::retrieveControlStateFromFile
void retrieveControlStateFromFile(std::ifstream &)
Definition:
ControlState.cpp:294
ControlState::updateDisplayedControlState
void updateDisplayedControlState(SystemModule &, int)
Definition:
ControlState.cpp:61
ControlState::displyed_control_state
int displyed_control_state
Definition:
ControlState.h:39
ControlState::ControlState
ControlState()
Definition:
ControlState.cpp:19
ControlState::initiateDisplayedControlState
void initiateDisplayedControlState(SystemModule &)
Definition:
ControlState.cpp:205
ControlState::readInfoFromFile
void readInfoFromFile(std::ifstream &)
Definition:
ControlState.cpp:34
ControlState::performValueControl
void performValueControl(SystemModule &, double)
Definition:
ControlState.cpp:118
ControlState::performDisplayedControlState
void performDisplayedControlState(SystemModule &, int)
Definition:
ControlState.cpp:144
ControlState::getDisplayedControlStateWhenFail
int getDisplayedControlStateWhenFail()
Definition:
ControlState.cpp:31
ControlState::getDisplayedControlState
int getDisplayedControlState()
Definition:
ControlState.cpp:33
ControlState::saveControlStateToFile
void saveControlStateToFile(std::ofstream &)
Definition:
ControlState.cpp:290
ControlState::setDisplayedControlState
void setDisplayedControlState(int)
Definition:
ControlState.cpp:32
ControlState::~ControlState
virtual ~ControlState()
Definition:
ControlState.cpp:26
ControlState::copyControlState
void copyControlState(ControlState &)
Definition:
ControlState.cpp:285
ControlState::setDisplayedControlStateWhenFail
void setDisplayedControlStateWhenFail(int)
Definition:
ControlState.cpp:30
InteractiveVariable
Definition:
InteractiveVariable.h:16
InteractiveVariable::setInputValue
void setInputValue(double val)
Definition:
InteractiveVariable.cpp:29
InteractiveVariable::getDisplayValue
double getDisplayValue()
Definition:
InteractiveVariable.cpp:35
InteractiveVariable::setNeedToInteract
void setNeedToInteract(bool flag)
Definition:
InteractiveVariable.cpp:36
SystemControl::getPtrToCorrespondingInteractiveVariable
InteractiveVariable * getPtrToCorrespondingInteractiveVariable()
Definition:
SystemControl.cpp:39
SystemControl::setPtrToCorrespondingInteractiveVariable
void setPtrToCorrespondingInteractiveVariable(InteractiveVariable *)
Definition:
SystemControl.cpp:36
SystemControl::setTypeOfControl
void setTypeOfControl(DisplayType)
Definition:
SystemControl.cpp:35
SystemControl::saveSystemControlToFile
void saveSystemControlToFile(std::ofstream &)
Definition:
SystemControl.cpp:48
SystemControl::getFunctionalState
int getFunctionalState()
Definition:
SystemControl.cpp:37
SystemControl::retrieveSystemControlFromFile
void retrieveSystemControlFromFile(std::ifstream &)
Definition:
SystemControl.cpp:55
SystemControl::copySystemControl
void copySystemControl(SystemControl &)
Definition:
SystemControl.cpp:41
SystemModule
Definition:
SystemModule.h:28
SystemModule::getComponentFromSystemMap
THElement * getComponentFromSystemMap(std::string)
Definition:
SystemModule.cpp:501
r5pars_
struct @0 r5pars_
sim::State::On
constexpr int On
Definition:
SimConstants.h:105
sim::State::Off
constexpr int Off
Definition:
SimConstants.h:106
sim::State::Succeed
constexpr int Succeed
Definition:
SimConstants.h:104
sim::State::Open
constexpr int Open
Definition:
SimConstants.h:116
sim::State::Auto
constexpr int Auto
Definition:
SimConstants.h:112
sim::State::Close
constexpr int Close
Definition:
SimConstants.h:117
sim::None
constexpr int None
Definition:
SimConstants.h:75
SimulationContext::Branch_center
BranchRecord Branch_center
Dynamic event tree state.
Definition:
SimulationContext.h:45
src
ADSIDAC
ControlPanel
ControlState.cpp
Generated by
1.9.4