eis/eqpalg/.do_not_use/unused_algs/AlgHeater.cpp

93 lines
3.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <base/BitTool.h>
#include <eqpalg/algs/AlgHeater.h>
#include <utility/StringHelper.h>
#include <zlib/MemTrk.h>
extern std::map<std::string, ITEM> glob_items;
int AlgHeater::init() {
LOG d("AlgHeater::init", AUTO_CATCH_PID);
int ret = 0;
try {
} catch (const std::exception &e) {
d.Error() << mix_cc::get_nested_exception(e) << std::endl;
ret = -1;
}
return ret;
}
AlgHeater::AlgHeater(const string name, const Json::Value rulejson,
const string ruleId)
: AlgBase(name, rulejson, ruleId) {
// CMemTable<MOD_CACHE> mod1("ZONE0",1);
// gb_data = mod1();
this->init();
m_start = -1;
temp_start = 0.0;
}
AlgHeater::~AlgHeater() {}
int AlgHeater::calculate(string &outjson) {
LOG d("AlgHeater::calculate", AUTO_CATCH_PID);
outjson = "";
int ret = 0;
try {
// m_tags[0] : 加热器实际温度
// m_tags[1] : 加热器ready信号
// m_tags[2] : 加热器运行信号
HD3TimeRegion timeRegion;
if (glob_items[m_tags[1]].value == 0) {
timeRegion.left.nSec = time(0);
timeRegion.right.nSec = time(0);
string msg = "加热器ready信号为0加热器异常";
// d.Info() << msg << endl;
string tmp = this->build_alarm_info(MsgLevel::ERROR, rule_id_, rule_name_,
"HEATER", msg, timeRegion);
if (!tmp.empty())
outjson = tmp;
} else {
if (m_start > 0) {
time_t m_curr = this->mstime();
timeRegion.left.nSec = m_start / 1000;
timeRegion.right.nSec = m_curr / 1000;
if (m_curr - m_start < m_json_param["heat"]["time"].asInt()) {
return 0;
}
double temp_end = glob_items[m_tags[0]].value;
if (temp_end - temp_start <
m_json_param["limit_alarm"]["value"][1].asDouble()) {
string msg = m_json_param["limit_alarm"]["content"][1].asString() +
" " + "当前温度增幅为" +
std::to_string(temp_end - temp_start);
string tmp = this->build_alarm_info(MsgLevel::WARN, rule_id_, rule_name_,
"HEATER", msg, timeRegion);
if (!tmp.empty())
outjson = tmp;
} else if (temp_end - temp_start <
m_json_param["limit_error"]["value"][1].asDouble()) {
string msg = m_json_param["limit_error"]["content"][1].asString() +
" " + "当前温度增幅为" +
std::to_string(temp_end - temp_start);
string tmp = this->build_alarm_info(MsgLevel::ERROR, rule_id_, rule_name_,
"HEATER", msg, timeRegion);
if (!tmp.empty())
outjson = tmp;
} else {
// d.Debug() << rule_name_ << " 数据正常! " << endl;
}
m_start = -1;
} else {
int presignal = glob_items[m_tags[2]].valueold;
int nowsignal = glob_items[m_tags[2]].value;
if (nowsignal == 1 && presignal == 0) {
m_start = this->mstime();
}
}
}
} catch (const std::exception &e) {
d.Error() << mix_cc::get_nested_exception(e) << std::endl;
ret = -1;
}
return ret;
}