refactor: 集成 FbStateMachine 到 ExpBase::mon_proc()
This commit is contained in:
parent
fad4ee8e38
commit
0106e553a0
@ -41,6 +41,7 @@ int ExpBase::init() {
|
|||||||
ret += this->reload_config_exp_act(); /*5.动作表达式*/
|
ret += this->reload_config_exp_act(); /*5.动作表达式*/
|
||||||
if (feedback_mode_) {
|
if (feedback_mode_) {
|
||||||
ret += this->reload_config_exp_feedback(); /*6.反馈表达式*/
|
ret += this->reload_config_exp_feedback(); /*6.反馈表达式*/
|
||||||
|
fb_fsm_.configure(keep_mode_, time_out_);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exp_type_ == ExpType::Bound || exp_type_ == ExpType::CondBound ||
|
if (exp_type_ == ExpType::Bound || exp_type_ == ExpType::CondBound ||
|
||||||
@ -296,51 +297,49 @@ AlarmInfo ExpBase::mon_proc() {
|
|||||||
act_triggered_ = static_cast<bool>(result_value);
|
act_triggered_ = static_cast<bool>(result_value);
|
||||||
// 如果是反馈模式
|
// 如果是反馈模式
|
||||||
if (feedback_mode_) {
|
if (feedback_mode_) {
|
||||||
feedback_done_ = false;
|
// === 使用 FbStateMachine ===
|
||||||
if (act_start_done()) {
|
auto [fbState, needFunReset] = fb_fsm_.update(
|
||||||
if (rule_id_ == string(CMemVar::Const()->printRuleid)) {
|
act_triggered_, now_time_, expr_engine_->vars(), m_tags.size());
|
||||||
logger_->Debug() << "act_start_done!" << std::endl;
|
|
||||||
expr_engine_->printVars();
|
if (needFunReset) {
|
||||||
|
expr_engine_->markFunVarsNeedReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fbState == FbState::Started) {
|
||||||
|
// 刚启动,下周期继续
|
||||||
|
// query_time_range 左边界设为动作开始时间
|
||||||
|
query_time_range_.set_left(now_time_);
|
||||||
return AlarmInfo{};
|
return AlarmInfo{};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (act_not_hold()) {
|
if (fbState == FbState::NotHold) {
|
||||||
if (rule_id_ == string(CMemVar::Const()->printRuleid)) {
|
|
||||||
logger_->Debug()
|
|
||||||
<< "act_not_hold!---fun_vars_.refresh_fun_vars---start"
|
|
||||||
<< std::endl;
|
|
||||||
expr_engine_->printVars();
|
|
||||||
}
|
|
||||||
expr_engine_->markFunVarsNeedReset();
|
|
||||||
return AlarmInfo{};
|
return AlarmInfo{};
|
||||||
}
|
}
|
||||||
if (act_done()) {
|
|
||||||
feedback_done_ = true;
|
if (fbState == FbState::InProgress) {
|
||||||
this->query_time_range_.set_left(
|
// 检查反馈条件
|
||||||
|
bool fbCond = expr_engine_->evaluateBool("feedback");
|
||||||
|
bool done = fb_fsm_.checkFeedback(fbCond, now_time_, expr_engine_->vars());
|
||||||
|
if (done) {
|
||||||
|
// 动作完成,计算结果
|
||||||
|
query_time_range_.set_left(
|
||||||
query_time_range_.get_right() -
|
query_time_range_.get_right() -
|
||||||
milliseconds(int(mm_vars["time"])));
|
milliseconds(static_cast<int>(expr_engine_->vars()["time"])));
|
||||||
result_value = expr_engine_->evaluate("result");
|
result_value = expr_engine_->evaluate("result");
|
||||||
expr_engine_->markFunVarsNeedReset();
|
expr_engine_->markFunVarsNeedReset();
|
||||||
this->rule_stat_.limit_down = limit_down_;
|
rule_stat_.limit_down = limit_down_;
|
||||||
this->rule_stat_.limit_up = limit_up_;
|
rule_stat_.limit_up = limit_up_;
|
||||||
rule_stat_.current_value = result_value;
|
rule_stat_.current_value = result_value;
|
||||||
expr_engine_->printVars();
|
|
||||||
logger_->Debug() << " action end:"
|
|
||||||
<< mix_cc::mix_time_t(query_time_range_.get_right())
|
|
||||||
.to_formatted_time()
|
|
||||||
<< " timediff:" << mm_vars["time"]
|
|
||||||
<< " exp:" << exp_str_ << "=" << result_value << endl;
|
|
||||||
if (exp_type_ == ExpType::CondBound) {
|
if (exp_type_ == ExpType::CondBound) {
|
||||||
if (this->is_learning_) {
|
if (is_learning_) {
|
||||||
SingletonTemp<EqpStat>::GetInstance().add_stat_values(
|
SingletonTemp<EqpStat>::GetInstance().add_stat_values(
|
||||||
this->rule_id_, result_value);
|
rule_id_, result_value);
|
||||||
}
|
}
|
||||||
if (this->detect_up_down(result_value)) {
|
if (detect_up_down(result_value)) {
|
||||||
rule_stat_.alarm_value = result_value;
|
rule_stat_.alarm_value = result_value;
|
||||||
std::string msg = "";
|
std::string msg = "";
|
||||||
if (m_timemode) {
|
if (fb_fsm_.isTimeMode()) {
|
||||||
/*动作时间类*/
|
|
||||||
msg = error_str_ + ":" + DAA::double2str(result_value) +
|
msg = error_str_ + ":" + DAA::double2str(result_value) +
|
||||||
"ms,时间范围:[0," + DAA::double2str(limit_up_) + "] ms";
|
"ms,时间范围:[0," + DAA::double2str(limit_up_) + "] ms";
|
||||||
} else {
|
} else {
|
||||||
@ -348,35 +347,30 @@ AlarmInfo ExpBase::mon_proc() {
|
|||||||
",合理区间:[" + DAA::double2strLimit(limit_down_) + "," +
|
",合理区间:[" + DAA::double2strLimit(limit_down_) + "," +
|
||||||
DAA::double2strLimit(limit_up_) + "]" + unit_;
|
DAA::double2strLimit(limit_up_) + "]" + unit_;
|
||||||
}
|
}
|
||||||
logger_->Debug()
|
|
||||||
<< "报警!!!!" << msg << ",last_alarm_time_:"
|
|
||||||
<< mix_cc::mix_time_t(last_alarm_time_).to_formatted_time()
|
|
||||||
<< endl;
|
|
||||||
return utility::build_alarm_info(
|
return utility::build_alarm_info(
|
||||||
utility::get_msg_level(limit_down_, limit_up_, result_value),
|
utility::get_msg_level(limit_down_, limit_up_, result_value),
|
||||||
rule_id_, rule_name_, "EXP4", msg, this->get_alarm_time());
|
rule_id_, rule_name_, "EXP4", msg, get_alarm_time());
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (result_value) {
|
if (result_value) {
|
||||||
rule_stat_.alarm_value = result_value;
|
rule_stat_.alarm_value = result_value;
|
||||||
std::string msg_tag = "";
|
auto msg = rule_name_ + " " + error_str_;
|
||||||
auto msg = rule_name_ + " " + error_str_ + msg_tag;
|
|
||||||
logger_->Debug()
|
|
||||||
<< "报警!!!!" << msg << ",last_alarm_time_:"
|
|
||||||
<< mix_cc::mix_time_t(last_alarm_time_).to_formatted_time()
|
|
||||||
<< endl;
|
|
||||||
return utility::build_alarm_info(MsgLevel::ERROR, rule_id_,
|
return utility::build_alarm_info(MsgLevel::ERROR, rule_id_,
|
||||||
rule_name_, "EXP3", msg,
|
rule_name_, "EXP3", msg,
|
||||||
this->get_alarm_time());
|
get_alarm_time());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (act_timeout()) {
|
// fbCondition 不满足,继续 InProgress
|
||||||
expr_engine_->markFunVarsNeedReset();
|
|
||||||
return this->get_timeout_alarm();
|
|
||||||
return AlarmInfo{};
|
return AlarmInfo{};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fbState == FbState::Timeout) {
|
||||||
|
return get_timeout_alarm();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Idle state (from terminal auto-reset) — nothing to do
|
||||||
|
return AlarmInfo{};
|
||||||
}
|
}
|
||||||
// 不是动作反馈
|
// 不是动作反馈
|
||||||
else {
|
else {
|
||||||
@ -682,7 +676,7 @@ bool ExpBase::act_timeout() {
|
|||||||
|
|
||||||
// 得到报警超时信息
|
// 得到报警超时信息
|
||||||
AlarmInfo ExpBase::get_timeout_alarm() {
|
AlarmInfo ExpBase::get_timeout_alarm() {
|
||||||
if (!m_timemode) {
|
if (!fb_fsm_.isTimeMode()) {
|
||||||
return AlarmInfo{};
|
return AlarmInfo{};
|
||||||
}
|
}
|
||||||
string msg =
|
string msg =
|
||||||
@ -752,10 +746,10 @@ int ExpBase::reload_config_exp_feedback() {
|
|||||||
|
|
||||||
if (exp_str_.find("time", 0) != string::npos &&
|
if (exp_str_.find("time", 0) != string::npos &&
|
||||||
exp_type_ == ExpType::CondBound) {
|
exp_type_ == ExpType::CondBound) {
|
||||||
m_timemode = true;
|
fb_fsm_.setTimeMode(true);
|
||||||
rule_stat_.unit = "ms";
|
rule_stat_.unit = "ms";
|
||||||
} else {
|
} else {
|
||||||
m_timemode = false;
|
fb_fsm_.setTimeMode(false);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -1207,10 +1201,7 @@ bool ExpBase::get_prr() {
|
|||||||
this->now_prr_ = prr_result;
|
this->now_prr_ = prr_result;
|
||||||
|
|
||||||
if (!this->now_prr_) {
|
if (!this->now_prr_) {
|
||||||
/*-------动作反馈标记-重置------*/
|
fb_fsm_.forceReset();
|
||||||
this->act_started_ = false;
|
|
||||||
this->act_triggered_ = false;
|
|
||||||
this->feedback_triggered_ = false;
|
|
||||||
}
|
}
|
||||||
return prr_result;
|
return prr_result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
#include <eqpalg/utility/HoldTime.h>
|
#include <eqpalg/utility/HoldTime.h>
|
||||||
#include <eqpalg/utility/StatExp.hpp>
|
#include <eqpalg/utility/StatExp.hpp>
|
||||||
#include <eqpalg/utility/item2chinese.hpp>
|
#include <eqpalg/utility/item2chinese.hpp>
|
||||||
|
#include <eqpalg/utility/fb_state_machine.h>
|
||||||
#include <glob/SingletonTemplate.h>
|
#include <glob/SingletonTemplate.h>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -161,7 +162,7 @@ protected:
|
|||||||
|
|
||||||
bool feedback_triggered_ = false;
|
bool feedback_triggered_ = false;
|
||||||
|
|
||||||
bool m_timemode = false;
|
FbStateMachine fb_fsm_;
|
||||||
|
|
||||||
int refresh_counts_ = 0;
|
int refresh_counts_ = 0;
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user