eis/eqpalg/.do_not_use/otheralg/exp.h

201 lines
4.9 KiB
C
Raw Permalink Normal View History

#pragma once
/**
* @file eqpalg/algs/exp.h
* @brief
*
* @author Cat (null.null.null@qq.com)
* @version 0.1
* @date 2021-09-13
*
* Copyright: Baosight Co. Ltd.
* DO NOT COPY/USE WITHOUT PERMISSION
*
*/
#include <eqpalg/alg_base.h>
#include <eqpalg/define/public.h>
#include <eqpalg/gb_item_memory.h>
#include <glob/SingletonTemplate.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <vector>
// 三个表达式执行结构,对应三个进程类型
struct exec_cron_t {};
struct exec_task_t {};
struct exec_mon_t {};
/**
* @brief
*/
class Exp : public AlgBase {
public:
Exp(const string& name, const mix_cc::json& rule_json, const string& ruleId,
size_t dims);
~Exp() override;
public:
/**
* @brief
* @return int
*/
virtual int init() override;
/**
* @brief
* @return std::string
*/
AlarmInfo exec_mon() override;
/**
* @brief Set the last alarm time object
* unpause时mm_vars
* @param time_point My Param doc
*/
virtual void set_last_alarm_time(
TimePoint time_point = system_clock::now()) override;
/**
* @brief Set the usable object
* set_usable mm_vars
* @param usable My Param doc
*/
virtual void set_usable(bool usable) override;
/**
* @brief ihdb中获取历史数据
* TAG点的历史数据确实存储在了IHDB中
* @param time_range
* @return AlarmInfo
*/
std::vector<AlarmInfo> exec_task(mix_cc::time_range_t time_range) override;
/**
* @brief
* @return AlarmInfo
*/
virtual AlarmInfo mon_proc();
virtual mix_cc::json exec_cron();
virtual AlarmInfo cron_proc();
private:
/**
* @brief
* @return int
*/
int reload_config_data_source();
/**
* @brief
* @return int
*/
int reload_config_exp_act();
private:
/**
* @brief
* @return int
*/
int reload_config_exp_feedback();
protected:
/**
* @brief
* @return int
*/
int refresh_exp_vars_mem();
/**
* @brief ihyperDB查询到的数据载入到表达式变量中
* @param row
* @return int
*/
int refresh_exp_vars_ihd(int row);
int first_fill_mm_vars();
protected:
/**
* @brief
* @param expstr My Param doc
*/
void print_exp_vars(const string& expstr = "");
protected:
std::unique_ptr<mix_cc::matheval::Expression> exp_act_; ///< 动作表达式
std::unique_ptr<mix_cc::matheval::Expression> exp_feedback_; ///< 反馈表达式
std::unique_ptr<mix_cc::matheval::Expression> exp_result_; ///< 数值表达式
std::map<std::string, double> mm_vars; ///< 表达式系统变量map
string exp_str_; ///< 表达式字符串
string error_str_; ///< 错误字符串
protected:
const size_t dims_; ///< 数据维度数量
TimeDur time_out_; ///< 反馈限制超时时间
TimePoint act_start_time_; ///<动作开始时间
bool act_triggered_; ///< 开始动作是否触发
bool act_started_ =
false; ///< 动作是否开始(即使之前触发过,但是也可能由于超时、未保持而停止)
bool feedback_triggered_; ///< 反馈是否触发
bool m_timemode; ///< 执行的时间模式
int refresh_counts_ = 0; ///< 当数据源是共享内存时开机保证前4次 mm_vars有值
protected:
bool feedback_mode_ = false; ///< 有反馈的表达式模式
bool keep_mode_ = false; ///< 开始动作是否需要保持
protected:
/**
* @brief
* s{tagN}
* 使
* @return true
* @return false
*/
bool act_start_done();
/**
* @brief
* 使退
* @return true
* @return false
*/
bool act_not_hold();
/**
* @brief
*
* @return true
* @return false
*/
bool act_done();
/**
* @brief
* 使
* @return true
* @return false
*/
bool act_timeout();
protected:
/**
* @brief
* @return AlarmInfo
*/
AlarmInfo get_timeout_alarm();
};