117 lines
3.2 KiB
C
117 lines
3.2 KiB
C
|
|
#pragma once
|
|||
|
|
/**
|
|||
|
|
* @file ExpModule.h
|
|||
|
|
* @brief 表达式模块
|
|||
|
|
* @author your name (you@domain.com)
|
|||
|
|
* @version 0.1
|
|||
|
|
* @date 2025-08-20
|
|||
|
|
*
|
|||
|
|
* Copyright: Baosight Co. Ltd.
|
|||
|
|
* DO NOT COPY/USE WITHOUT PERMISSION
|
|||
|
|
*
|
|||
|
|
*/
|
|||
|
|
#include "mix_cc/ihyper_db.h"
|
|||
|
|
#include "mix_cc/json.h"
|
|||
|
|
#include "mix_cc/matheval/matheval.hpp"
|
|||
|
|
#include <chrono>
|
|||
|
|
#include <eqpalg/utility/StatExp.hpp>
|
|||
|
|
#include <log4cplus/LOG.h>
|
|||
|
|
#include <map>
|
|||
|
|
#include <memory>
|
|||
|
|
#include <string>
|
|||
|
|
#include <vector>
|
|||
|
|
using std::map;
|
|||
|
|
using std::string;
|
|||
|
|
using std::vector;
|
|||
|
|
using MExp = mix_cc::matheval::Expression;
|
|||
|
|
using namespace std::chrono;
|
|||
|
|
using std::chrono::system_clock;
|
|||
|
|
using TimePoint = system_clock::time_point;
|
|||
|
|
using TimeDur = milliseconds;
|
|||
|
|
|
|||
|
|
class ExpModule {
|
|||
|
|
public:
|
|||
|
|
ExpModule(std::map<std::string, double> &vars_ref, vector<string> &m_tags,
|
|||
|
|
bool &is_exp_alg_ref);
|
|||
|
|
~ExpModule();
|
|||
|
|
ExpModule() = delete;
|
|||
|
|
ExpModule &operator=(const ExpModule &) = delete;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 添加表达式
|
|||
|
|
* @param exp_name 表达式名称
|
|||
|
|
* @param exp_str 表达式字符串
|
|||
|
|
* @return int
|
|||
|
|
*/
|
|||
|
|
int add_exp(string exp_name, string exp_str);
|
|||
|
|
/**
|
|||
|
|
* @brief 更新数据,更新表达式的值
|
|||
|
|
* @return int
|
|||
|
|
*/
|
|||
|
|
int update();
|
|||
|
|
|
|||
|
|
void fun_reset();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 更新数据,更新表达式的值 通过指定数据
|
|||
|
|
* @param queried_data 指定数据项
|
|||
|
|
* @return int
|
|||
|
|
*/
|
|||
|
|
int update(Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> queried_data,
|
|||
|
|
std::vector<TimePoint> queried_time, int row = 0);
|
|||
|
|
/**
|
|||
|
|
* @brief 获取表达式的值
|
|||
|
|
* @param exp_name 表达式名称
|
|||
|
|
* @return double
|
|||
|
|
*/
|
|||
|
|
double get_value(string exp_name);
|
|||
|
|
/**
|
|||
|
|
* @brief
|
|||
|
|
*/
|
|||
|
|
void print_value();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief Get the exp str object
|
|||
|
|
* @param exp_name My Param doc
|
|||
|
|
* @return string
|
|||
|
|
*/
|
|||
|
|
string get_exp_str(string exp_name);
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
/**
|
|||
|
|
* @brief 表达式变量,表达式初始化
|
|||
|
|
*/
|
|||
|
|
void init();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 更新数据 共享内存
|
|||
|
|
*/
|
|||
|
|
void refresh_exp_vars_mem();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 更新数据 指定数据
|
|||
|
|
* @param queried_data
|
|||
|
|
*/
|
|||
|
|
void refresh_exp_ihd_mem(
|
|||
|
|
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> queried_data,
|
|||
|
|
std::vector<TimePoint> queried_time, int row);
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
map<string, double> &mm_vars; ///< 表达式系统变量map
|
|||
|
|
map<string, double> exp_result_; ///<表达式计算结果
|
|||
|
|
map<string, std::unique_ptr<MExp>> exp_ptr_; ///表达式名称-表达式
|
|||
|
|
map<string, string> exp_str_; ///<表达式名称-表达式字符串
|
|||
|
|
vector<string> &m_tags; ///< 保存的tag点名
|
|||
|
|
std::unique_ptr<LOG> logger_; ///<日志
|
|||
|
|
TimePoint now_time_; ///< 当前正在执行时的时间
|
|||
|
|
/**
|
|||
|
|
* @brief 自定义带状态函数
|
|||
|
|
* KeepT , ///< 保持时间
|
|||
|
|
* KeepC, ///<出现次数
|
|||
|
|
* RiseEdge, ///<上升沿出现次数
|
|||
|
|
* Detect ///<为真检测次数
|
|||
|
|
*/
|
|||
|
|
StatExp::FunVars fun_vars_;
|
|||
|
|
bool &is_exp_alg_; ///<是否是表达式ExpBase对象
|
|||
|
|
};
|