4040#include " thd_engine.h"
4141
4242// Clamp to cdev min state or trip specific min if valid
43- int cthd_cdev::thd_clamp_state_min (int _state, int temp_min_state)
43+ int cthd_cdev::thd_clamp_state_min (int _state, int temp_min_state, int temp_max_state )
4444{
45- int _min_state = min_state;
45+ if (min_state <= max_state) {
46+ int _min_state = min_state;
4647
47- if (_min_state >= max_state) {
48- if (temp_min_state && temp_min_state <= _min_state)
49- _min_state = temp_min_state;
50- } else {
51- if (temp_min_state && temp_min_state >= _min_state)
48+ if (temp_min_state > min_state)
5249 _min_state = temp_min_state;
53- }
5450
55- thd_log_debug ( " def_min_state:%d curr_min_state:%d \n " , min_state,
56- _min_state) ;
51+ if (_state < _min_state)
52+ _state = _min_state;
5753
58- if ((_min_state <= max_state && _state <= _min_state)
59- || (_min_state >= max_state && _state >= _min_state))
60- return _min_state;
61- else
54+ thd_log_debug (" def_min_state:%d curr_min_state:%d _state:%d\n " , min_state, temp_min_state, _state);
6255 return _state;
56+ }
57+
58+ int _max_state = max_state;
59+
60+ if (temp_max_state > max_state)
61+ _max_state = temp_max_state;
62+
63+ if (_state < _max_state)
64+ _state = _max_state;
65+
66+ thd_log_debug (" def_max_state:%d curr_max_state:%d _state:%d\n " , max_state, temp_max_state, _state);
67+
68+ return _state;
6369}
6470
6571// Clamp to cdev max state or trip specific max if valid
66- int cthd_cdev::thd_clamp_state_max (int _state, int temp_max_state)
72+ int cthd_cdev::thd_clamp_state_max (int _state, int temp_min_state, int temp_max_state)
6773{
68- int _max_state = max_state;
74+ if (min_state <= max_state) {
75+ int _max_state = max_state;
6976
70- if (min_state >= _max_state) {
71- if (temp_max_state && temp_max_state >= _max_state)
77+ if (temp_max_state < max_state)
7278 _max_state = temp_max_state;
73- } else {
74- if (temp_max_state && temp_max_state <= _max_state)
75- _max_state = temp_max_state;
76- }
7779
78- thd_log_debug ( " def_max_state:%d temp_max_state:%d curr_max_state:%d \n " ,
79- max_state, temp_max_state, _max_state) ;
80+ if (_state > _max_state)
81+ _state = _max_state;
8082
81- if ((min_state <= _max_state && _state >= _max_state)
82- || (min_state >= _max_state && _state <= _max_state))
83- return _max_state;
84- else
83+ thd_log_debug (" def_max_state:%d curr_max_state:%d _state:%d\n " , max_state, temp_max_state, _state);
8584 return _state;
85+ }
86+
87+ int _min_state = min_state;
88+
89+ if (temp_min_state > min_state)
90+ _min_state = temp_min_state;
91+
92+ if (_state > _min_state)
93+ _state = _min_state;
94+
95+ thd_log_debug (" def_max_state:%d curr_max_state:%d _state:%d\n " , min_state, temp_min_state, _state);
96+
97+ return _state;
8698}
8799
88100int cthd_cdev::thd_cdev_exponential_controller (int set_point, int target_temp,
@@ -98,7 +110,7 @@ int cthd_cdev::thd_cdev_exponential_controller(int set_point, int target_temp,
98110 _curr_state = get_curr_state (true );
99111 // Clamp the current state to min_state, as we start from min to max for
100112 // activation of a cooling device
101- _curr_state = thd_clamp_state_min (_curr_state, temp_min_state);
113+ _curr_state = thd_clamp_state_min (_curr_state, temp_min_state, temp_max_state );
102114 thd_log_debug (
103115 " thd_cdev_set_%d:curr state %d max state %d temp_min:%d temp_max:%d\n " ,
104116 index, _curr_state, _max_state, temp_min_state, temp_max_state);
@@ -135,15 +147,16 @@ int cthd_cdev::thd_cdev_exponential_controller(int set_point, int target_temp,
135147 }
136148
137149 // Make sure that the state is not beyond max_state
138- _state = thd_clamp_state_max (_state, temp_max_state);
150+ _state = thd_clamp_state_max (_state, temp_min_state, temp_max_state);
139151
140152 trend_increase = true ;
141153 thd_log_debug (" op->device:%s %d\n " , type_str.c_str (), _state);
142154 set_curr_state (_state, control);
143155 } else {
144156 // Get the latest state, which is not the latest from the hardware but last set state to the device
145157 _curr_state = get_curr_state ();
146- _curr_state = thd_clamp_state_max (_curr_state);
158+ // _curr_state = thd_clamp_state_max(_curr_state);
159+ _curr_state = thd_clamp_state_max (_curr_state, temp_min_state, temp_max_state);
147160
148161 thd_log_debug (" thd_cdev_set_%d:curr state %d max state %d\n " , index,
149162 _curr_state, _max_state);
@@ -159,13 +172,15 @@ int cthd_cdev::thd_cdev_exponential_controller(int set_point, int target_temp,
159172 _state = _curr_state - inc_dec_val;
160173
161174 // Make sure that it is not beyond min_state
162- _state = thd_clamp_state_min (_state);
175+ _state = thd_clamp_state_min (_state, temp_min_state, temp_max_state);
176+ // _state = thd_clamp_state_min(_state);
163177 thd_log_info (" op->device:%s %d\n " , type_str.c_str (), _state);
164178 set_curr_state (_state, control);
165179 } else {
180+ _state = thd_clamp_state_min (min_state, temp_min_state, temp_max_state);
166181 thd_log_debug (" op->device: force min %s %d\n " , type_str.c_str (),
167- min_state );
168- set_curr_state (min_state , control);
182+ _state );
183+ set_curr_state (_state , control);
169184 }
170185 }
171186
0 commit comments