Initial commit: EIS C++ project with multi-process code
This commit is contained in:
commit
7e602c7bc1
40
.gitignore
vendored
Normal file
40
.gitignore
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
# Compiled libraries and objects
|
||||
*.a
|
||||
*.a.*
|
||||
*.aBK
|
||||
*.abk
|
||||
*.so
|
||||
*.so.*
|
||||
*.o
|
||||
*.obj
|
||||
*.lo
|
||||
*.la
|
||||
|
||||
# Backup files
|
||||
*~
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.bin
|
||||
|
||||
# DLLs
|
||||
*.dll
|
||||
*.dylib
|
||||
|
||||
# Python bytecode
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*.pyd
|
||||
|
||||
# Build directories and artifacts
|
||||
*build*/
|
||||
*.o.d
|
||||
*.o.cmd
|
||||
|
||||
# Test executables
|
||||
Testing/
|
||||
|
||||
# IDE (keep only if team agrees; uncomment if needed)
|
||||
# .vscode/
|
||||
29
.vscode/c_cpp_properties.json
vendored
Normal file
29
.vscode/c_cpp_properties.json
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${VCPKG_INCLUDE_PATH}",
|
||||
"~/code/",
|
||||
"~/code/inc/",
|
||||
"/opt/iPlature/ThirdParty/Ice/include",
|
||||
"/opt/iPlature/ThirdParty/SQLAPI/include",
|
||||
"/opt/iPlature/ThirdParty/bdb-18.1.25/include",
|
||||
"/opt/iPlature/ThirdParty/bzip2-1.0.6/include",
|
||||
"/opt/iPlature/ThirdParty/expat/include",
|
||||
"/opt/iPlature/ThirdParty/mcpp-2.7.2-13/include",
|
||||
"/opt/iPlature/ThirdParty/openssl-1.0.2t/include",
|
||||
"/opt/iPlature/include",
|
||||
"/opt/iHyperDB/library/include",
|
||||
"/opt/iXComPCS/Include"
|
||||
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": " /opt/rh/devtoolset-10/root/usr/bin/gcc",
|
||||
"cStandard": "c17",
|
||||
"cppStandard": "c++20",
|
||||
"intelliSenseMode": "gcc-x64"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
5
.vscode/extensions.json
vendored
Normal file
5
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"ms-vscode.cpptools"
|
||||
]
|
||||
}
|
||||
226
.vscode/settings.json
vendored
Normal file
226
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,226 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"*.log": "log",
|
||||
"*.tcc": "cpp",
|
||||
"string": "cpp",
|
||||
"array": "cpp",
|
||||
"bitset": "cpp",
|
||||
"string_view": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"regex": "cpp",
|
||||
"utility": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"deque": "cpp",
|
||||
"list": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"atomic": "cpp",
|
||||
"strstream": "cpp",
|
||||
"bit": "cpp",
|
||||
"chrono": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"complex": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"map": "cpp",
|
||||
"set": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"ratio": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"fstream": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"new": "cpp",
|
||||
"ostream": "cpp",
|
||||
"shared_mutex": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"cfenv": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"thread": "cpp",
|
||||
"any": "cpp",
|
||||
"typeindex": "cpp",
|
||||
"variant": "cpp",
|
||||
"*.h++": "cpp",
|
||||
"queue": "cpp",
|
||||
"mutex": "cpp",
|
||||
"future": "cpp",
|
||||
"csignal": "cpp",
|
||||
"codecvt": "cpp",
|
||||
"*.ipp": "cpp",
|
||||
"locale": "cpp",
|
||||
"hash_map": "cpp",
|
||||
"cassert": "cpp",
|
||||
"cerrno": "cpp",
|
||||
"cfloat": "cpp",
|
||||
"ciso646": "cpp",
|
||||
"climits": "cpp",
|
||||
"ios": "cpp",
|
||||
"stack": "cpp",
|
||||
"cstdbool": "cpp",
|
||||
"valarray": "cpp",
|
||||
"filesystem": "cpp",
|
||||
"core": "cpp",
|
||||
"compare": "cpp",
|
||||
"concepts": "cpp",
|
||||
"forward_list": "cpp",
|
||||
"unordered_set": "cpp",
|
||||
"ranges": "cpp",
|
||||
"stop_token": "cpp",
|
||||
"coroutine": "cpp",
|
||||
"__bit_reference": "cpp",
|
||||
"__bits": "cpp",
|
||||
"__config": "cpp",
|
||||
"__debug": "cpp",
|
||||
"__errc": "cpp",
|
||||
"__functional_base": "cpp",
|
||||
"__hash_table": "cpp",
|
||||
"__locale": "cpp",
|
||||
"__mutex_base": "cpp",
|
||||
"__node_handle": "cpp",
|
||||
"__nullptr": "cpp",
|
||||
"__split_buffer": "cpp",
|
||||
"__string": "cpp",
|
||||
"__threading_support": "cpp",
|
||||
"__tree": "cpp",
|
||||
"__tuple": "cpp",
|
||||
"semaphore": "cpp",
|
||||
"eigen": "cpp",
|
||||
"__functional_03": "cpp",
|
||||
"__functional_base_03": "cpp",
|
||||
"__memory": "cpp",
|
||||
"csetjmp": "cpp",
|
||||
"*.autogenerated_defines": "cpp",
|
||||
"dense": "cpp",
|
||||
"*.in": "cpp",
|
||||
"charconv": "cpp",
|
||||
"cuchar": "cpp",
|
||||
"numbers": "cpp",
|
||||
"scoped_allocator": "cpp",
|
||||
"span": "cpp",
|
||||
"*.hpp0000": "cpp",
|
||||
"armadillo": "cpp",
|
||||
"geometry": "cpp",
|
||||
"iterativelinearsolvers": "cpp",
|
||||
"netfwd": "cpp",
|
||||
"rope": "cpp",
|
||||
"slist": "cpp",
|
||||
"source_location": "cpp"
|
||||
},
|
||||
"better-comments.highlightPlainText": true,
|
||||
"better-comments.tags": [
|
||||
{
|
||||
"tag": "!",
|
||||
"color": "#FF2D00",
|
||||
"strikethrough": false,
|
||||
"underline": false,
|
||||
"backgroundColor": "transparent",
|
||||
"bold": false,
|
||||
"italic": false
|
||||
},
|
||||
{
|
||||
"tag": "?",
|
||||
"color": "#3498DB",
|
||||
"strikethrough": false,
|
||||
"underline": false,
|
||||
"backgroundColor": "transparent",
|
||||
"bold": false,
|
||||
"italic": false
|
||||
},
|
||||
{
|
||||
"tag": "//",
|
||||
"color": "#474747",
|
||||
"strikethrough": true,
|
||||
"underline": false,
|
||||
"backgroundColor": "transparent",
|
||||
"bold": false,
|
||||
"italic": false
|
||||
},
|
||||
{
|
||||
"tag": "todo",
|
||||
"color": "#FF8C00",
|
||||
"strikethrough": false,
|
||||
"underline": false,
|
||||
"backgroundColor": "transparent",
|
||||
"bold": false,
|
||||
"italic": false
|
||||
},
|
||||
{
|
||||
"tag": "*",
|
||||
"color": "#98C379",
|
||||
"strikethrough": false,
|
||||
"underline": false,
|
||||
"backgroundColor": "transparent",
|
||||
"bold": false,
|
||||
"italic": false
|
||||
}
|
||||
],
|
||||
"doxdocgen.file.copyrightTag": [
|
||||
"Copyright: Baosight Co. Ltd.",
|
||||
"DO NOT COPY/USE WITHOUT PERMISSION"
|
||||
],
|
||||
"doxdocgen.file.fileOrder": [
|
||||
"file",
|
||||
"brief",
|
||||
"author",
|
||||
"version",
|
||||
"date",
|
||||
"empty",
|
||||
"copyright",
|
||||
"empty",
|
||||
"custom"
|
||||
],
|
||||
"doxdocgen.generic.order": [
|
||||
"brief",
|
||||
"tparam",
|
||||
"param",
|
||||
"return"
|
||||
],
|
||||
"doxdocgen.generic.paramTemplate": "@param{indent:8}{param}{indent:25}My Param doc",
|
||||
"doxdocgen.generic.returnTemplate": "@return {type} ",
|
||||
"doxdocgen.generic.splitCasingSmartText": true,
|
||||
"cmake.configureOnOpen": false,
|
||||
"cSpell.words": [
|
||||
"CRGS",
|
||||
"ICEI",
|
||||
"IHDB",
|
||||
"Plature",
|
||||
"baosight",
|
||||
"cmtr",
|
||||
"fftw",
|
||||
"ihyper",
|
||||
"dlib"
|
||||
],
|
||||
"cmake.sourceDirectory": "${workspaceFolder}/mix_cc",
|
||||
"python.formatting.provider": "yapf",
|
||||
"C_Cpp.default.compilerPath": " /opt/rh/devtoolset-10/root/usr/bin/gcc",
|
||||
"files.autoGuessEncoding": true,
|
||||
"C_Cpp.autocompleteAddParentheses": true,
|
||||
"C_Cpp.clang_format_fallbackStyle": "Google",
|
||||
"C_Cpp.clang_format_sortIncludes": false,
|
||||
"C_Cpp.errorSquiggles": "Disabled",
|
||||
}
|
||||
61
RICS/CMakeLists.txt
Normal file
61
RICS/CMakeLists.txt
Normal file
@ -0,0 +1,61 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(RICS VERSION 0.1)
|
||||
|
||||
set(CONFIG_FILE_PATH "config.json")
|
||||
|
||||
include(../cmake_include/public.cmake)
|
||||
include(../cmake_include/baosight.cmake)
|
||||
include(../cmake_include/mix_cc.cmake)
|
||||
|
||||
find_package(
|
||||
Boost
|
||||
COMPONENTS system filesystem serialization context regex container iostreams
|
||||
stacktrace_addr2line unit_test_framework
|
||||
REQUIRED)
|
||||
|
||||
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-omit-frame-pointer -Wno-deprecated-declarations")
|
||||
# set(CMAKE_BUILD_TYPE "Release")
|
||||
set(CMAKE_BUILD_TYPE "Debug")
|
||||
aux_source_directory(./ DIR_ROOT)
|
||||
|
||||
set(LINK_OPTION
|
||||
${ICE}
|
||||
${IPLATURE}
|
||||
${SQL}
|
||||
${FREEZE}
|
||||
${BASE_LIB}
|
||||
${CODE_LIB}
|
||||
${IDA}
|
||||
${LEGACY_JSON}
|
||||
${IHDB_LIB}
|
||||
${MIX_CC_DEBUG}
|
||||
${MIX_CC_UTILITY}
|
||||
${MIX_CC_SQL}
|
||||
rt
|
||||
stdc++
|
||||
c
|
||||
m
|
||||
)
|
||||
|
||||
add_executable(
|
||||
RICS
|
||||
${DIR_ROOT}
|
||||
)
|
||||
|
||||
target_link_libraries(RICS
|
||||
${LINK_OPTION}
|
||||
${Boost_LIBRARIES}
|
||||
${mix_cc}
|
||||
nlohmann_json::nlohmann_json )
|
||||
|
||||
target_include_directories(
|
||||
RICS
|
||||
PUBLIC ./
|
||||
../
|
||||
${my_lib_include}
|
||||
${legacy_include}
|
||||
${iplature_include}
|
||||
${iXcom}Include)
|
||||
|
||||
set_target_properties(RICS PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${bin_dir})
|
||||
|
||||
32
RICS/RICS.cc
Normal file
32
RICS/RICS.cc
Normal file
@ -0,0 +1,32 @@
|
||||
#include "mix_cc/debug/pre_define.h"
|
||||
#include <RICS/RICS.h>
|
||||
#include <RICS/RICS_icei.h>
|
||||
#include <glob/GlobDefine.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility/IniProperty.h>
|
||||
|
||||
using namespace baosight;
|
||||
|
||||
RICS::RICS() { logger_ = std::make_unique<LOG>("RICS"); }
|
||||
|
||||
RICS::~RICS() { logger_->Info() << "-------RICS::end-------" << std::endl; }
|
||||
|
||||
int RICS::start() {
|
||||
logger_->Info() << "-------RICS::start-------" << std::endl;
|
||||
con_mag_ = std::make_shared<ConnectionMag>();
|
||||
con_mag_->dbLogin();
|
||||
try {
|
||||
auto module_name = name();
|
||||
RICS_server = new RICSICEI();
|
||||
this->add(string("baosight/") + name(), RICS_server);
|
||||
} catch (::Ice::LocalException &e) {
|
||||
logger_->Error() << "Can not add baosight/RICS, error: " << e << endl;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// PACE_SERVER_INSTALL(RICS) //应用程序主入口,传入参数为定义的类名
|
||||
PACE_PLATFORM_SERVER_INSTALL(RICS, APPVERSION);
|
||||
51
RICS/RICS.h
Normal file
51
RICS/RICS.h
Normal file
@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file RICS.h
|
||||
* @brief 数据保存
|
||||
* @author your name (you@domain.com)
|
||||
* @version 0.1
|
||||
* @date 2025-09-26
|
||||
*
|
||||
* Copyright: Baosight Co. Ltd.
|
||||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||||
*
|
||||
*/
|
||||
#include <RICS/RICS_icei.h>
|
||||
#include <glob/ConnectionMag.h>
|
||||
#include <iostream>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <memory>
|
||||
#include <pace/Component.h>
|
||||
#include <pace/pace.h>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace baosight {
|
||||
/**
|
||||
* @brief 负载程序的启动和初始变量信息的加载
|
||||
*/
|
||||
class RICS : public Component {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new RICS object
|
||||
*/
|
||||
RICS();
|
||||
|
||||
/**
|
||||
* @brief Destroy the RICS object
|
||||
*/
|
||||
virtual ~RICS();
|
||||
|
||||
/**
|
||||
* @brief 启动进程
|
||||
* @return int
|
||||
*/
|
||||
virtual int start();
|
||||
|
||||
private:
|
||||
MessageICEPtr RICS_server; ///< Ice通信模块
|
||||
std::unique_ptr<LOG> logger_;
|
||||
std::shared_ptr<ConnectionMag> con_mag_; ///< DB2连接管理器,邹师傅的模块需要
|
||||
};
|
||||
}; // namespace baosight
|
||||
759
RICS/RICS_alg.cc
Normal file
759
RICS/RICS_alg.cc
Normal file
@ -0,0 +1,759 @@
|
||||
#include <RICS/RICS_alg.h>
|
||||
#include <RICS/table_struct/t_rule_cfg.h>
|
||||
#include <RICS/utility.h>
|
||||
#include <mix_cc/sql.h>
|
||||
#include <mix_cc/sql/database/db2_t.h>
|
||||
RICSAlg::RICSAlg() {
|
||||
logger_ = std::make_unique<LOG>("RICSAlg");
|
||||
SingletonTemplate<Item2Chines>::GetInstance()("test");
|
||||
}
|
||||
RICSAlg::~RICSAlg() {}
|
||||
void RICSAlg::alg_handle(int algid) {
|
||||
|
||||
try {
|
||||
// 载入T_RULE_CFG表,从其中读取算法
|
||||
T_RULE_CFG t_rule_cfg;
|
||||
auto sql_statement =
|
||||
select(t_rule_cfg.algId(), t_rule_cfg.ruleId(), t_rule_cfg.ruleName(),
|
||||
t_rule_cfg.remark(), t_rule_cfg.ruleGroup(), t_rule_cfg.eqpid(),
|
||||
t_rule_cfg.flag(), t_rule_cfg.ruleParam())
|
||||
.from(t_rule_cfg)
|
||||
.where(t_rule_cfg.algId() == algid);
|
||||
auto rule_list_maybe = mix_cc::sql::exec<db2_t, T_RULE_CFG>(sql_statement);
|
||||
if (rule_list_maybe.is_just()) {
|
||||
int tagMax = 0;
|
||||
auto rule_list = rule_list_maybe.unsafe_get_just();
|
||||
logger_->Info() << "rules in DB:" << rule_list.size() << endl;
|
||||
CfgRuleInfo cfg_rule_info;
|
||||
for (auto x : rule_list) {
|
||||
RuleInfo rule_info;
|
||||
// logger_->Debug() << "ID:" << x.ruleId << " AlgID:" << x.algId
|
||||
// << " Name:" << x.ruleName << " Flag:" << x.flag
|
||||
// << endl;
|
||||
rule_info.rule_name = x.ruleName;
|
||||
rule_info.remark = x.remark;
|
||||
rule_info.eqpid = x.eqpid;
|
||||
rule_info.rule_group = x.ruleGroup;
|
||||
auto param_info = mix_cc::json::parse(x.ruleParam);
|
||||
if (param_info.contains("output")) {
|
||||
rule_info.alarm_reason =
|
||||
param_info.at("output").at("reason").at("value").get<string>();
|
||||
rule_info.alarm_content =
|
||||
param_info.at("output").at("error").at("value").get<string>();
|
||||
}
|
||||
rule_info.pre_condition = param_info.at("before_exec").get<string>();
|
||||
rule_info.pre_result = param_info.at("function")
|
||||
.at("pre_result")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
|
||||
const auto tag_dict = param_info["tags"];
|
||||
const int tag_size = tag_dict.size();
|
||||
tagMax = std::max(tagMax, tag_size);
|
||||
rule_info.tags_item.resize(tag_size);
|
||||
rule_info.tags_chinese.resize(tag_size);
|
||||
for (auto y : tag_dict.items()) {
|
||||
int item_index = stoi(y.key().substr(3));
|
||||
if (item_index > tag_size) {
|
||||
logger_->Error()
|
||||
<< "ruleid:" << x.ruleId << ",rulename:" << x.ruleName
|
||||
<< ",tag max:" << tag_size << ",now tag index:" << item_index
|
||||
<< std::endl;
|
||||
continue;
|
||||
}
|
||||
auto itemi = y.value().at("value").get<std::string>();
|
||||
rule_info.tags_item[item_index - 1] = itemi;
|
||||
rule_info.tags_chinese[item_index - 1] =
|
||||
SingletonTemplate<Item2Chines>::GetInstance()(itemi);
|
||||
}
|
||||
auto fun_json = param_info.at("function");
|
||||
exp_handle(fun_json, rule_info, algid);
|
||||
cfg_rule_info[x.ruleId] = rule_info;
|
||||
}
|
||||
alg_rule_info_[algid] = cfg_rule_info;
|
||||
alg_2_tagMax[algid] = tagMax;
|
||||
logger_->Debug() << "alg_2_tagMax[algid]:" << alg_2_tagMax[algid]
|
||||
<< std::endl;
|
||||
} else {
|
||||
logger_->Debug() << "algid:" << algid << " 无规则" << std::endl;
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
logger_->Error() << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void RICSAlg::timed_task() {
|
||||
logger_->Debug() << "test" << std::endl;
|
||||
for (auto item : AlgId) {
|
||||
logger_->Debug() << "item:" << item << std::endl;
|
||||
alg_handle(item);
|
||||
string jvalue = get_json_by_algid(item);
|
||||
|
||||
string jkey = unitNo_ + "_Alg_" + std::to_string(item);
|
||||
write_memcaced(jkey, jvalue);
|
||||
logger_->Debug() << "jkey:" << jkey
|
||||
<< ",jvalue size:" << alg_rule_info_[item].size()
|
||||
<< std::endl;
|
||||
// logger_->Debug() << "jkey:" << jkey << ",jvalue:" << jvalue << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void RICSAlg::dispose(int event_no, const ::Ice::ByteSeq &seq) {
|
||||
string str(seq.begin(), seq.end());
|
||||
logger_->Debug() << "seq:" << str << std::endl;
|
||||
}
|
||||
void RICSAlg::exp_handle(json &funciton_param, RuleInfo &ruleInfo, int algid) {
|
||||
|
||||
switch (algid) {
|
||||
case 1: {
|
||||
ruleInfo.exp_str.resize(1);
|
||||
ruleInfo.exp_str[0] = funciton_param.at("result").at("value").get<string>();
|
||||
} break;
|
||||
case 2: {
|
||||
ruleInfo.exp_str.resize(2);
|
||||
ruleInfo.exp_str[0] =
|
||||
funciton_param.at("filter_exp").at("value").get<string>();
|
||||
ruleInfo.exp_str[1] = funciton_param.at("result").at("value").get<string>();
|
||||
ruleInfo.limit_down = funciton_param.at("result")
|
||||
.at("param")
|
||||
.at("limit_down")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
ruleInfo.limit_up = funciton_param.at("result")
|
||||
.at("param")
|
||||
.at("limit_up")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
if (funciton_param.at("result").at("param").contains("unit")) {
|
||||
ruleInfo.unit = funciton_param.at("result")
|
||||
.at("param")
|
||||
.at("unit")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
}
|
||||
} break;
|
||||
case 3: {
|
||||
ruleInfo.exp_str.resize(3);
|
||||
ruleInfo.exp_str[0] =
|
||||
funciton_param.at("action_start").at("value").get<string>();
|
||||
ruleInfo.exp_str[1] =
|
||||
funciton_param.at("action_end").at("value").get<string>();
|
||||
ruleInfo.exp_str[2] = funciton_param.at("result").at("value").get<string>();
|
||||
ruleInfo.params.resize(2);
|
||||
ruleInfo.params[0] = funciton_param.at("action_start")
|
||||
.at("param")
|
||||
.at("hold")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
ruleInfo.params[1] = funciton_param.at("action_end")
|
||||
.at("param")
|
||||
.at("timeout")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
} break;
|
||||
case 4: {
|
||||
ruleInfo.exp_str.resize(3);
|
||||
ruleInfo.exp_str[0] =
|
||||
funciton_param.at("action_start").at("value").get<string>();
|
||||
ruleInfo.exp_str[1] =
|
||||
funciton_param.at("action_end").at("value").get<string>();
|
||||
ruleInfo.exp_str[2] = funciton_param.at("result").at("value").get<string>();
|
||||
ruleInfo.params.resize(2);
|
||||
ruleInfo.params[0] = funciton_param.at("action_start")
|
||||
.at("param")
|
||||
.at("hold")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
ruleInfo.params[1] = funciton_param.at("action_end")
|
||||
.at("param")
|
||||
.at("timeout")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
ruleInfo.limit_down = funciton_param.at("result")
|
||||
.at("param")
|
||||
.at("limit_down")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
ruleInfo.limit_up = funciton_param.at("result")
|
||||
.at("param")
|
||||
.at("limit_up")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
if (funciton_param.at("result").at("param").contains("unit")) {
|
||||
ruleInfo.unit = funciton_param.at("result")
|
||||
.at("param")
|
||||
.at("unit")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
}
|
||||
} break;
|
||||
case 5: {
|
||||
ruleInfo.exp_str.resize(2);
|
||||
ruleInfo.exp_str[0] =
|
||||
funciton_param.at("filter_exp").at("value").get<string>();
|
||||
ruleInfo.exp_str[1] = funciton_param.at("result").at("value").get<string>();
|
||||
|
||||
ruleInfo.params.resize(1);
|
||||
ruleInfo.params[0] = funciton_param.at("result")
|
||||
.at("param")
|
||||
.at("hold_time")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
|
||||
ruleInfo.limit_down = funciton_param.at("result")
|
||||
.at("param")
|
||||
.at("limit_down")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
ruleInfo.limit_up = funciton_param.at("result")
|
||||
.at("param")
|
||||
.at("limit_up")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
if (funciton_param.at("result").at("param").contains("unit")) {
|
||||
ruleInfo.unit = funciton_param.at("result")
|
||||
.at("param")
|
||||
.at("unit")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
}
|
||||
} break;
|
||||
case 6: {
|
||||
ruleInfo.exp_str.resize(1);
|
||||
ruleInfo.exp_str[0] = funciton_param.at("result").at("value").get<string>();
|
||||
|
||||
ruleInfo.params.resize(1);
|
||||
ruleInfo.params[0] = funciton_param.at("result")
|
||||
.at("param")
|
||||
.at("limit_time")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
|
||||
} break;
|
||||
case 7: {
|
||||
ruleInfo.exp_str.resize(1);
|
||||
ruleInfo.exp_str[0] = funciton_param.at("result").at("value").get<string>();
|
||||
|
||||
ruleInfo.params.resize(1);
|
||||
ruleInfo.params[0] = funciton_param.at("result")
|
||||
.at("param")
|
||||
.at("limit_times")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
|
||||
} break;
|
||||
case 8: {
|
||||
ruleInfo.exp_str.resize(1);
|
||||
ruleInfo.exp_str[0] =
|
||||
funciton_param.at("limit_error").at("value").get<string>();
|
||||
|
||||
ruleInfo.params.resize(4);
|
||||
ruleInfo.params[0] = funciton_param.at("limit_error")
|
||||
.at("param")
|
||||
.at("interval_time")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
ruleInfo.params[1] = funciton_param.at("limit_error")
|
||||
.at("param")
|
||||
.at("deltaX")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
ruleInfo.params[2] = funciton_param.at("limit_error")
|
||||
.at("param")
|
||||
.at("diff")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
ruleInfo.params[3] = funciton_param.at("limit_error")
|
||||
.at("param")
|
||||
.at("CS_AVG_SIZE")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
|
||||
} break;
|
||||
case 12: {
|
||||
ruleInfo.exp_str.resize(3);
|
||||
ruleInfo.exp_str[0] = funciton_param.at("result").at("value").get<string>();
|
||||
ruleInfo.exp_str[1] =
|
||||
funciton_param.at("sample_X").at("value").get<string>();
|
||||
ruleInfo.exp_str[2] =
|
||||
funciton_param.at("sample_Y").at("value").get<string>();
|
||||
|
||||
ruleInfo.params.resize(1);
|
||||
ruleInfo.params[0] = funciton_param.at("sample_Y")
|
||||
.at("param")
|
||||
.at("scale")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
} break;
|
||||
case 13: {
|
||||
ruleInfo.exp_str.resize(3);
|
||||
ruleInfo.exp_str[0] = funciton_param.at("result").at("value").get<string>();
|
||||
ruleInfo.exp_str[1] =
|
||||
funciton_param.at("sample_X").at("value").get<string>();
|
||||
ruleInfo.exp_str[2] =
|
||||
funciton_param.at("sample_Y").at("value").get<string>();
|
||||
|
||||
ruleInfo.params.resize(2);
|
||||
ruleInfo.params[0] = funciton_param.at("sample_Y")
|
||||
.at("param")
|
||||
.at("scale")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
ruleInfo.params[1] = funciton_param.at("sample_Y")
|
||||
.at("param")
|
||||
.at("min_len")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
} break;
|
||||
case 14: {
|
||||
ruleInfo.exp_str.resize(1);
|
||||
ruleInfo.exp_str[0] =
|
||||
funciton_param.at("limit_error").at("value").get<string>();
|
||||
|
||||
ruleInfo.params.resize(4);
|
||||
ruleInfo.params[0] = funciton_param.at("limit_error")
|
||||
.at("param")
|
||||
.at("interval_time")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
ruleInfo.params[1] = funciton_param.at("limit_error")
|
||||
.at("param")
|
||||
.at("deltaX")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
ruleInfo.params[2] = funciton_param.at("limit_error")
|
||||
.at("param")
|
||||
.at("diff")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
ruleInfo.params[3] = funciton_param.at("limit_error")
|
||||
.at("param")
|
||||
.at("CS_AVG_SIZE")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
|
||||
} break;
|
||||
case 15: {
|
||||
ruleInfo.exp_str.resize(1);
|
||||
ruleInfo.exp_str[0] = funciton_param.at("dataX").at("value").get<string>();
|
||||
ruleInfo.params.resize(1);
|
||||
ruleInfo.params[0] = funciton_param.at("dataX")
|
||||
.at("param")
|
||||
.at("lenth")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
} break;
|
||||
case 16:
|
||||
case 18: {
|
||||
ruleInfo.exp_str.resize(2);
|
||||
ruleInfo.exp_str[0] =
|
||||
funciton_param.at("pre_exp").at("value").get<string>();
|
||||
ruleInfo.exp_str[1] = funciton_param.at("input").at("value").get<string>();
|
||||
ruleInfo.params.resize(4);
|
||||
if (funciton_param.at("input").at("param").contains("unit")) {
|
||||
ruleInfo.unit = funciton_param.at("input")
|
||||
.at("param")
|
||||
.at("unit")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
}
|
||||
ruleInfo.params[0] = funciton_param.at("input")
|
||||
.at("param")
|
||||
.at("detect_mode")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
ruleInfo.params[1] = funciton_param.at("input")
|
||||
.at("param")
|
||||
.at("limit_warn")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
ruleInfo.params[2] = funciton_param.at("input")
|
||||
.at("param")
|
||||
.at("limit_error")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
if (funciton_param.at("input").at("param").contains("hold_time")) {
|
||||
ruleInfo.params[3] = funciton_param.at("input")
|
||||
.at("param")
|
||||
.at("hold_time")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
} else {
|
||||
ruleInfo.params[3] = "0";
|
||||
}
|
||||
|
||||
} break;
|
||||
case 17: {
|
||||
ruleInfo.exp_str.resize(2);
|
||||
ruleInfo.exp_str[0] =
|
||||
funciton_param.at("filter_exp").at("value").get<string>();
|
||||
ruleInfo.exp_str[1] = funciton_param.at("result").at("value").get<string>();
|
||||
ruleInfo.params.resize(3);
|
||||
if (funciton_param.at("result").at("param").contains("unit")) {
|
||||
ruleInfo.unit = funciton_param.at("result")
|
||||
.at("param")
|
||||
.at("unit")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
}
|
||||
|
||||
ruleInfo.params[0] = funciton_param.at("result")
|
||||
.at("param")
|
||||
.at("limit_warn")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
ruleInfo.params[1] = funciton_param.at("result")
|
||||
.at("param")
|
||||
.at("limit_error")
|
||||
.at("value")
|
||||
.get<string>();
|
||||
} break;
|
||||
default:
|
||||
logger_->Debug() << "algid:" << algid << " error!" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
string RICSAlg::get_json_by_algid(int algid) {
|
||||
nlohmann::json js1;
|
||||
vector<string> columns_name{
|
||||
"规则名称", "设备id", "规则分组", "规则描述",
|
||||
"报警原因", "报警内容", "前置条件", "执行前置条件表达式",
|
||||
};
|
||||
vector<vector<string>> data;
|
||||
const auto &algRuleIfo = alg_rule_info_[algid];
|
||||
for (int i = 0; i < 8; i++) {
|
||||
vector<string> coli_data;
|
||||
for (auto &item : algRuleIfo) {
|
||||
coli_data.push_back(item.second.get_value(i));
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
}
|
||||
switch (algid) {
|
||||
|
||||
case 1: {
|
||||
columns_name.push_back("报警条件表达式");
|
||||
vector<string> coli_data;
|
||||
for (const auto &item : algRuleIfo) {
|
||||
coli_data.push_back(item.second.exp_str[0]);
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
} break;
|
||||
case 2: {
|
||||
columns_name.push_back("数据筛选表达式");
|
||||
columns_name.push_back("监控变量表达式");
|
||||
columns_name.push_back("单位");
|
||||
columns_name.push_back("下限");
|
||||
columns_name.push_back("上限");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
vector<string> coli_data;
|
||||
for (const auto &item : algRuleIfo) {
|
||||
if (i < 2) {
|
||||
coli_data.push_back(item.second.exp_str[i]);
|
||||
} else if (i == 2) {
|
||||
coli_data.push_back(item.second.unit);
|
||||
} else if (i == 3) {
|
||||
coli_data.push_back(item.second.limit_down);
|
||||
} else {
|
||||
coli_data.push_back(item.second.limit_up);
|
||||
}
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
}
|
||||
|
||||
} break;
|
||||
case 3: {
|
||||
columns_name.push_back("动作表达式");
|
||||
columns_name.push_back("反馈表达式");
|
||||
columns_name.push_back("监控变量表达式");
|
||||
columns_name.push_back("是否保持");
|
||||
columns_name.push_back("超时时间");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
vector<string> coli_data;
|
||||
for (const auto &item : algRuleIfo) {
|
||||
if (i < 3) {
|
||||
coli_data.push_back(item.second.exp_str[i]);
|
||||
} else {
|
||||
coli_data.push_back(item.second.params[i - 3]);
|
||||
}
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
}
|
||||
} break;
|
||||
case 4: {
|
||||
columns_name.push_back("动作表达式");
|
||||
columns_name.push_back("反馈表达式");
|
||||
columns_name.push_back("监控变量条件表达式");
|
||||
columns_name.push_back("是否保持");
|
||||
columns_name.push_back("超时时间");
|
||||
columns_name.push_back("单位");
|
||||
columns_name.push_back("下限");
|
||||
columns_name.push_back("上限");
|
||||
for (int i = 0; i < 8; i++) {
|
||||
vector<string> coli_data;
|
||||
for (const auto &item : algRuleIfo) {
|
||||
if (i < 3) {
|
||||
coli_data.push_back(item.second.exp_str[i]);
|
||||
} else if (i == 3) {
|
||||
coli_data.push_back(item.second.params[0]);
|
||||
} else if (i == 4) {
|
||||
coli_data.push_back(item.second.params[1]);
|
||||
} else if (i == 5) {
|
||||
coli_data.push_back(item.second.unit);
|
||||
} else if (i == 6) {
|
||||
coli_data.push_back(item.second.limit_down);
|
||||
} else {
|
||||
coli_data.push_back(item.second.limit_up);
|
||||
}
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
}
|
||||
} break;
|
||||
case 5: {
|
||||
columns_name.push_back("数据筛选表达式");
|
||||
columns_name.push_back("监控变量表达式");
|
||||
columns_name.push_back("单位");
|
||||
columns_name.push_back("下限");
|
||||
columns_name.push_back("上限");
|
||||
columns_name.push_back("持续时间[ms]");
|
||||
for (int i = 0; i < 6; i++) {
|
||||
vector<string> coli_data;
|
||||
for (const auto &item : algRuleIfo) {
|
||||
if (i < 2) {
|
||||
coli_data.push_back(item.second.exp_str[i]);
|
||||
} else if (i == 2) {
|
||||
coli_data.push_back(item.second.unit);
|
||||
} else if (i == 3) {
|
||||
coli_data.push_back(item.second.limit_down);
|
||||
} else if (i == 4) {
|
||||
coli_data.push_back(item.second.limit_up);
|
||||
} else {
|
||||
coli_data.push_back(item.second.params[0]);
|
||||
}
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
}
|
||||
} break;
|
||||
case 6: {
|
||||
columns_name.push_back("检测条件表达式");
|
||||
columns_name.push_back("最大保持时间[小时]");
|
||||
for (int i = 0; i < 2; i++) {
|
||||
vector<string> coli_data;
|
||||
for (const auto &item : algRuleIfo) {
|
||||
if (i == 0) {
|
||||
coli_data.push_back(item.second.exp_str[0]);
|
||||
} else {
|
||||
coli_data.push_back(item.second.params[0]);
|
||||
}
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
}
|
||||
} break;
|
||||
case 7: {
|
||||
columns_name.push_back("检测条件表达式");
|
||||
columns_name.push_back("最大出现次数");
|
||||
for (int i = 0; i < 2; i++) {
|
||||
vector<string> coli_data;
|
||||
for (const auto &item : algRuleIfo) {
|
||||
if (i == 0) {
|
||||
coli_data.push_back(item.second.exp_str[0]);
|
||||
} else {
|
||||
coli_data.push_back(item.second.params[0]);
|
||||
}
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
}
|
||||
} break;
|
||||
case 8: {
|
||||
columns_name.push_back("报警条件表达式");
|
||||
columns_name.push_back("查询均值时间[s]");
|
||||
columns_name.push_back("单位时间间隔[min]");
|
||||
columns_name.push_back("监控量斜率(减少为用负值)");
|
||||
columns_name.push_back("连续出现的次数");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
vector<string> coli_data;
|
||||
for (const auto &item : algRuleIfo) {
|
||||
if (i == 0) {
|
||||
coli_data.push_back(item.second.exp_str[0]);
|
||||
} else {
|
||||
coli_data.push_back(item.second.params[i - 1]);
|
||||
}
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
}
|
||||
} break;
|
||||
case 12: {
|
||||
columns_name.push_back("筛选条件表达式");
|
||||
columns_name.push_back("X表达式");
|
||||
columns_name.push_back("Y表达式");
|
||||
columns_name.push_back("数据误差比(0~1)");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
vector<string> coli_data;
|
||||
for (const auto &item : algRuleIfo) {
|
||||
if (i < 3) {
|
||||
coli_data.push_back(item.second.exp_str[i]);
|
||||
} else {
|
||||
coli_data.push_back(item.second.params[0]);
|
||||
}
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
}
|
||||
} break;
|
||||
case 13: {
|
||||
columns_name.push_back("筛选条件表达式");
|
||||
columns_name.push_back("X表达式");
|
||||
columns_name.push_back("Y表达式");
|
||||
columns_name.push_back("数据误差比(0~1)");
|
||||
columns_name.push_back("相关性计算数据最小长度");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
vector<string> coli_data;
|
||||
for (const auto &item : algRuleIfo) {
|
||||
if (i < 3) {
|
||||
coli_data.push_back(item.second.exp_str[i]);
|
||||
} else {
|
||||
coli_data.push_back(item.second.params[i - 3]);
|
||||
}
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
}
|
||||
} break;
|
||||
case 14: {
|
||||
columns_name.push_back("报警条件表达式");
|
||||
columns_name.push_back("查询均值时间[s]");
|
||||
columns_name.push_back("单位时间间隔[min]");
|
||||
columns_name.push_back("监控量变化率[%](减少为用负值)");
|
||||
columns_name.push_back("连续出现的次数");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
vector<string> coli_data;
|
||||
for (const auto &item : algRuleIfo) {
|
||||
if (i == 0) {
|
||||
coli_data.push_back(item.second.exp_str[0]);
|
||||
} else {
|
||||
coli_data.push_back(item.second.params[i - 1]);
|
||||
}
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
}
|
||||
} break;
|
||||
case 15: {
|
||||
columns_name.push_back("监控变量表达式");
|
||||
columns_name.push_back("监测窗数据量[100,1000]");
|
||||
for (int i = 0; i < 2; i++) {
|
||||
vector<string> coli_data;
|
||||
for (const auto &item : algRuleIfo) {
|
||||
if (i == 0) {
|
||||
coli_data.push_back(item.second.exp_str[0]);
|
||||
} else {
|
||||
coli_data.push_back(item.second.params[0]);
|
||||
}
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
}
|
||||
|
||||
} break;
|
||||
case 16: {
|
||||
columns_name.push_back("前提条件表达式");
|
||||
columns_name.push_back("多变量求和表达式");
|
||||
columns_name.push_back("单位");
|
||||
columns_name.push_back("检测模式");
|
||||
columns_name.push_back("超时警告:离群变量超均值百分比");
|
||||
columns_name.push_back("报警:离群变量超均值百分比");
|
||||
columns_name.push_back("持续时间[ms]");
|
||||
for (int i = 0; i < 7; i++) {
|
||||
vector<string> coli_data;
|
||||
for (const auto &item : algRuleIfo) {
|
||||
if (i < 2) {
|
||||
coli_data.push_back(item.second.exp_str[i]);
|
||||
} else if (i == 2) {
|
||||
coli_data.push_back(item.second.unit);
|
||||
} else {
|
||||
coli_data.push_back(item.second.params[i - 3]);
|
||||
}
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
}
|
||||
|
||||
} break;
|
||||
case 17: {
|
||||
columns_name.push_back("数据筛选表达式");
|
||||
columns_name.push_back("超限结果表达式");
|
||||
columns_name.push_back("单位");
|
||||
columns_name.push_back("警告:限幅");
|
||||
columns_name.push_back("报警:限幅");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
vector<string> coli_data;
|
||||
for (const auto &item : algRuleIfo) {
|
||||
if (i < 2) {
|
||||
coli_data.push_back(item.second.exp_str[i]);
|
||||
} else if (i == 2) {
|
||||
coli_data.push_back(item.second.unit);
|
||||
} else {
|
||||
coli_data.push_back(item.second.params[i - 3]);
|
||||
}
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
}
|
||||
|
||||
} break;
|
||||
case 18: {
|
||||
columns_name.push_back("前提条件表达式");
|
||||
columns_name.push_back("多变量求和表达式");
|
||||
columns_name.push_back("单位");
|
||||
columns_name.push_back("检测模式");
|
||||
columns_name.push_back("超时警告:离群变量超均值");
|
||||
columns_name.push_back("报警:离群变量超均值");
|
||||
columns_name.push_back("持续时间[ms]");
|
||||
for (int i = 0; i < 7; i++) {
|
||||
vector<string> coli_data;
|
||||
for (const auto &item : algRuleIfo) {
|
||||
if (i < 2) {
|
||||
coli_data.push_back(item.second.exp_str[i]);
|
||||
} else if (i == 2) {
|
||||
coli_data.push_back(item.second.unit);
|
||||
} else {
|
||||
coli_data.push_back(item.second.params[i - 3]);
|
||||
}
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
}
|
||||
|
||||
} break;
|
||||
default:
|
||||
logger_->Debug() << "algid:" << algid << " error!" << std::endl;
|
||||
break;
|
||||
}
|
||||
const int tagMaxNum = alg_2_tagMax[algid];
|
||||
for (int i = 0; i < tagMaxNum; i++) {
|
||||
string tagi = "tag" + std::to_string(i + 1);
|
||||
columns_name.push_back(tagi);
|
||||
vector<string> coli_data;
|
||||
for (const auto &item : algRuleIfo) {
|
||||
coli_data.push_back(item.second.tags_item_get(i));
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
}
|
||||
|
||||
for (int i = 0; i < tagMaxNum; i++) {
|
||||
string tagi = "tag" + std::to_string(i + 1) + "中文";
|
||||
columns_name.push_back(tagi);
|
||||
vector<string> coli_data;
|
||||
for (const auto &item : algRuleIfo) {
|
||||
coli_data.push_back(item.second.tags_chinese_get(i));
|
||||
}
|
||||
data.push_back(coli_data);
|
||||
}
|
||||
js1["columns"] = columns_name;
|
||||
js1["data"] = data;
|
||||
return js1.dump();
|
||||
}
|
||||
|
||||
bool RICSAlg::write_memcaced(string jkey, string jvalue) {
|
||||
auto reSult = m_memclient.Insert(jkey.c_str(), jvalue.c_str());
|
||||
if (1 != reSult) {
|
||||
this->logger_->Debug()
|
||||
<< "update_eqp_status()"
|
||||
<< "m_memclient.Insert异常[0,set data fail;-1,key=null or value=null]:"
|
||||
<< reSult << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
67
RICS/RICS_alg.h
Normal file
67
RICS/RICS_alg.h
Normal file
@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file RICS_alg.h
|
||||
* @brief 从 DsmMapConfig::TableName(ZONE10)共享文件 读取 start end tags
|
||||
* 查ihd获取数据,保存文件
|
||||
* @author your name (you@domain.com)
|
||||
* @version 0.1
|
||||
* @date 2025-10-10
|
||||
*
|
||||
* Copyright: Baosight Co. Ltd.
|
||||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||||
*
|
||||
*/
|
||||
#include <RICS/item2chinese.hpp>
|
||||
#include <RICS/public.h>
|
||||
#include <common/Macro.h>
|
||||
#include <glob/SingletonTemplate.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <memory>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <zlib/MemCachedClient.h> ///MemCachedClient
|
||||
#include <zlib/MemVar.h>
|
||||
#include <zlib/zoneDef.h>
|
||||
using json = nlohmann::json;
|
||||
using namespace baosight;
|
||||
class RICSAlg {
|
||||
private:
|
||||
std::unique_ptr<LOG> logger_;
|
||||
std::map<int, CfgRuleInfo> alg_rule_info_; ///<规则信息 ruleid-RuleInfo
|
||||
std::map<string, string> key2values;
|
||||
std::map<int, int> alg_2_tagMax; ///<算法 对应 tagMax
|
||||
MemCachedClient m_memclient; ///< MemCachedClient
|
||||
const vector<int> AlgId = {1, 2, 3, 4, 5, 6, 7, 8,
|
||||
12, 13, 14, 15, 16, 17, 18};
|
||||
string unitNo_ = string(CMemVar::Const()->UnitNo); ///<机组号
|
||||
public:
|
||||
RICSAlg();
|
||||
~RICSAlg();
|
||||
/**
|
||||
* @brief 根据算法好处理数据
|
||||
* @param ruleid My Param doc
|
||||
*/
|
||||
void alg_handle(int algid);
|
||||
|
||||
/**
|
||||
* @brief 定时保存数据
|
||||
* 1. 获取所有的ruleid
|
||||
* 2.遍历ruleid,检测共享内存是否有ruleid的key
|
||||
* 3.调用RICS_handle
|
||||
*/
|
||||
void timed_task();
|
||||
|
||||
void dispose(int event_no, const ::Ice::ByteSeq &);
|
||||
|
||||
/**
|
||||
* @brief 分算法号 处理信息 表达式 参数
|
||||
* @param param My Param doc
|
||||
* @param ruleInfo My Param doc
|
||||
*/
|
||||
void exp_handle(json &funciton_param, RuleInfo &ruleInfo, int algid);
|
||||
|
||||
string get_json_by_algid(int algid);
|
||||
|
||||
bool write_memcaced(string jkey, string jvalue);
|
||||
};
|
||||
47
RICS/RICS_icei.cc
Normal file
47
RICS/RICS_icei.cc
Normal file
@ -0,0 +1,47 @@
|
||||
#include <RICS/RICS_icei.h>
|
||||
#include <RICS/utility.h>
|
||||
#include <common/L2Event.h>
|
||||
#include <dao/DbStandardDBAX.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
RICSICEI::RICSICEI() {
|
||||
this->logger_ = std::make_unique<LOG>("RICS_icei");
|
||||
RICS_alg_ = std::make_unique<RICSAlg>();
|
||||
RICS_alg_->timed_task();
|
||||
}
|
||||
|
||||
RICSICEI::~RICSICEI() { logger_->Info() << "RICSICEI::~RICSICEI()" << endl; }
|
||||
|
||||
void baosight::RICSICEI::SendDataShort(::Ice::Int eventNo,
|
||||
const ::Ice::ByteSeq &seq,
|
||||
::Ice::Int length,
|
||||
const Ice::Current ¤t) {
|
||||
logger_->Info() << "event no:" << eventNo << endl; /* ALARM! */
|
||||
string str(seq.begin(), seq.end());
|
||||
logger_->Debug() << "seq str:" << str << std::endl;
|
||||
// 根据电文号调用,执行分派任务操作
|
||||
switch (eventNo) {
|
||||
case 99999:
|
||||
logger_->Debug() << "test" << std::endl;
|
||||
RICS_alg_->dispose(eventNo, seq);
|
||||
break;
|
||||
|
||||
default:
|
||||
logger_->Error() << "wrong event No.!" << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void baosight::RICSICEI::SendDataLong(
|
||||
::Ice::Int eventNo, const ::Ice::ByteSeq &seq, ::Ice::Int length,
|
||||
const ::std::string &sender, const ::std::string &receiver,
|
||||
const ::std::string &additional, const Ice::Current ¤t) {}
|
||||
|
||||
void baosight::RICSICEI::TimeNotify(::Ice::Int eventNo,
|
||||
const ::Ice::ByteSeq &seq,
|
||||
const Ice::Current ¤t) {
|
||||
RICS_alg_->timed_task();
|
||||
logger_->Debug() << " RICS_alg_->timed_task()" << std::endl;
|
||||
}
|
||||
64
RICS/RICS_icei.h
Normal file
64
RICS/RICS_icei.h
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
#pragma once
|
||||
/**
|
||||
* @file RICS_icei.h
|
||||
* @brief RICS的ICE
|
||||
* @author your name (you@domain.com)
|
||||
* @version 0.1
|
||||
* @date 2023-12-22
|
||||
*
|
||||
* Copyright: Baosight Co. Ltd.
|
||||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||||
*
|
||||
*/
|
||||
#include <RICS/RICS_alg.h>
|
||||
#include <RICS/public.h>
|
||||
#include <common/L2Event.h>
|
||||
#include <ctime>
|
||||
#include <dao/DbStandardDBAX.h>
|
||||
#include <glob/SingletonTemplate.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <memory>
|
||||
#include <proxy/MessageICE.h>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
|
||||
namespace baosight {
|
||||
|
||||
/**
|
||||
* @brief Ice接口类实现,其中包含了对不同电文的调用
|
||||
*/
|
||||
class RICSICEI : virtual public MessageICE {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Eqp Alg I C E I object
|
||||
*/
|
||||
RICSICEI();
|
||||
virtual ~RICSICEI();
|
||||
|
||||
/**
|
||||
* @brief 简单数据调用接口
|
||||
*/
|
||||
virtual void SendDataShort(::Ice::Int, const ::Ice::ByteSeq &, ::Ice::Int,
|
||||
const Ice::Current &);
|
||||
|
||||
/**
|
||||
* @brief 复杂数据调用接口
|
||||
*/
|
||||
virtual void SendDataLong(::Ice::Int, const ::Ice::ByteSeq &, ::Ice::Int,
|
||||
const ::std::string &, const ::std::string &,
|
||||
const ::std::string &, const Ice::Current &);
|
||||
|
||||
/**
|
||||
* @brief 定时器调用接口
|
||||
*/
|
||||
virtual void TimeNotify(::Ice::Int, const ::Ice::ByteSeq &,
|
||||
const Ice::Current &);
|
||||
|
||||
private:
|
||||
std::unique_ptr<LOG> logger_; ///< 本地logger
|
||||
std::unique_ptr<RICSAlg> RICS_alg_;
|
||||
};
|
||||
|
||||
} // namespace baosight
|
||||
54
RICS/item2chinese.hpp
Normal file
54
RICS/item2chinese.hpp
Normal file
@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file item2chinese.hpp
|
||||
* @brief
|
||||
* @author your name (you@domain.com)
|
||||
* @version 0.1
|
||||
* @date 2026-01-15
|
||||
*
|
||||
* Copyright: Baosight Co. Ltd.
|
||||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||||
*
|
||||
*/
|
||||
|
||||
#include <glob/BinaryTele.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <zlib/MemVar.h>
|
||||
#include <zlib/zoneDef.h>
|
||||
class Item2Chines {
|
||||
private:
|
||||
std::unordered_map<std::string, std::string> data_;
|
||||
|
||||
BinaryTele binary_tele{CMemVar::Const()->event_eis_start, "T_LOV_FDAAITEM"};
|
||||
|
||||
private:
|
||||
void select_fdaaitem() {
|
||||
|
||||
const auto prefix = string(CMemVar::Const()->UnitNo) + "_";
|
||||
for (int i = CMemVar::Const()->event_eis_start;
|
||||
i <= CMemVar::Const()->event_eis_end; i++) {
|
||||
binary_tele.ReBuild(i);
|
||||
auto size = binary_tele.size();
|
||||
for (int j = 0; j < size; j++) {
|
||||
std::string item = binary_tele[j].item;
|
||||
std::string chinese = binary_tele[j].chinese;
|
||||
// auto item_name = prefix + item;
|
||||
auto item_name = item;
|
||||
data_[item_name] = chinese;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
std::string operator()(const std::string &item) const {
|
||||
auto it = data_.find(item);
|
||||
if (it != data_.end()) {
|
||||
return it->second; // 返回找到的翻译副本
|
||||
}
|
||||
return item; // 安全地返回传入项的副本
|
||||
}
|
||||
|
||||
Item2Chines() { select_fdaaitem(); }
|
||||
~Item2Chines() {}
|
||||
};
|
||||
20
RICS/json/eqp_status.json
Normal file
20
RICS/json/eqp_status.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"tag1name": [
|
||||
3,
|
||||
3,
|
||||
3,
|
||||
3
|
||||
],
|
||||
"tag2name": [
|
||||
32,
|
||||
42,
|
||||
5,
|
||||
5
|
||||
],
|
||||
"time": [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
}
|
||||
10
RICS/json/norm_info.json
Normal file
10
RICS/json/norm_info.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"start": 1760068800000,
|
||||
"end": 1760068980000,
|
||||
"tags": [
|
||||
"C308_IW_3G_LV_J02_03",
|
||||
"C308_BR2_1_V_act",
|
||||
"C308_BR2_1_V_set"
|
||||
],
|
||||
"data_type": "RuleAlertData"
|
||||
}
|
||||
86
RICS/public.h
Normal file
86
RICS/public.h
Normal file
@ -0,0 +1,86 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file public.h
|
||||
* @brief 规则信息
|
||||
* @author your name (you@domain.com)
|
||||
* @version 0.1
|
||||
* @date 2026-02-04
|
||||
*
|
||||
* Copyright: Baosight Co. Ltd.
|
||||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||||
*
|
||||
*/
|
||||
#include "mix_cc/json.h"
|
||||
#include <chrono>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <zlib/MemMap.hpp>
|
||||
using std::map;
|
||||
using std::string;
|
||||
struct RuleInfo {
|
||||
string rule_name;
|
||||
string eqpid;
|
||||
string rule_group;
|
||||
string remark;
|
||||
string alarm_reason;
|
||||
string alarm_content;
|
||||
string pre_condition;
|
||||
string pre_result;
|
||||
vector<string> exp_str;
|
||||
vector<string> tags_item;
|
||||
vector<string> tags_chinese;
|
||||
string limit_down;
|
||||
string limit_up;
|
||||
string unit;
|
||||
vector<string> params;
|
||||
RuleInfo() {}
|
||||
~RuleInfo() {}
|
||||
|
||||
string get_value(int i) const {
|
||||
switch (i) {
|
||||
case 0:
|
||||
return rule_name;
|
||||
break;
|
||||
case 1:
|
||||
return eqpid;
|
||||
break;
|
||||
case 2:
|
||||
return rule_group;
|
||||
break;
|
||||
case 3:
|
||||
return remark;
|
||||
break;
|
||||
case 4:
|
||||
return alarm_reason;
|
||||
break;
|
||||
case 5:
|
||||
return alarm_content;
|
||||
break;
|
||||
case 6:
|
||||
return pre_condition;
|
||||
case 7:
|
||||
return pre_result;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
string tags_item_get(int i) const {
|
||||
if (i < tags_item.size()) {
|
||||
return tags_item[i];
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
string tags_chinese_get(int i) const {
|
||||
if (i < tags_chinese.size()) {
|
||||
return tags_chinese[i];
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
using CfgRuleInfo = std::map<string, RuleInfo>;
|
||||
21
RICS/table_struct/fv_pdi.h
Normal file
21
RICS/table_struct/fv_pdi.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file fv_pdi.h
|
||||
* @brief 视图 卷-生产时间-长度-重量
|
||||
* @author your name (you@domain.com)
|
||||
* @version 0.1
|
||||
* @date 2023-12-22
|
||||
*
|
||||
* Copyright: Baosight Co. Ltd.
|
||||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||||
*
|
||||
*/
|
||||
#include <string>
|
||||
#include "mix_cc/sql/make_table.h"
|
||||
#include "mix_cc/type/mix_time.h"
|
||||
using namespace mix_cc::sql;
|
||||
using namespace std::chrono;
|
||||
|
||||
MIX_CC_SQL_MAKE_TABLE(FV_PDI, (std::string, entId), (double, length),
|
||||
(double, witdh), (double, thick), (double, weight),
|
||||
(mix_cc::mix_time_t, startime));
|
||||
20
RICS/table_struct/t_eqp_data.h
Normal file
20
RICS/table_struct/t_eqp_data.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file t_eqp_data.h
|
||||
* @brief 设备编号,有效性,检修规则,检修参数
|
||||
* @author your name (you@domain.com)
|
||||
* @version 0.1
|
||||
* @date 2023-12-22
|
||||
*
|
||||
* Copyright: Baosight Co. Ltd.
|
||||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||||
*
|
||||
*/
|
||||
#include <string>
|
||||
#include "mix_cc/sql/make_table.h"
|
||||
#include "mix_cc/type/mix_time.h"
|
||||
using namespace mix_cc::sql;
|
||||
using namespace std::chrono;
|
||||
|
||||
MIX_CC_SQL_MAKE_TABLE(T_EQP_DATA, (std::string, eqpId), (std::string, flag),
|
||||
(int, ruletype), (double, value),(int,eqpidtype));
|
||||
21
RICS/table_struct/t_eqp_repair.h
Normal file
21
RICS/table_struct/t_eqp_repair.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file t_eqp_repair.h
|
||||
* @brief 设备编号,上次检修时间,检修计划,实际数据
|
||||
* @author your name (you@domain.com)
|
||||
* @version 0.1
|
||||
* @date 2023-12-22
|
||||
*
|
||||
* Copyright: Baosight Co. Ltd.
|
||||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||||
*
|
||||
*/
|
||||
#include <string>
|
||||
#include "mix_cc/sql/make_table.h"
|
||||
#include "mix_cc/type/mix_time.h"
|
||||
using namespace mix_cc::sql;
|
||||
using namespace std::chrono;
|
||||
|
||||
MIX_CC_SQL_MAKE_TABLE(T_EQP_REPAIR, (std::string, eqpid),
|
||||
(mix_cc::mix_time_t, repairdate),
|
||||
(mix_cc::mix_time_t, repairplan), (double, data));
|
||||
24
RICS/table_struct/t_rule_cfg.h
Normal file
24
RICS/table_struct/t_rule_cfg.h
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
#pragma once
|
||||
/**
|
||||
* @file t_rule_cfg.h
|
||||
* @brief 算法配置表
|
||||
* @author Cat (null.null.null@qq.com)
|
||||
* @version 0.1
|
||||
* @date 2021-09-17
|
||||
*
|
||||
* Copyright: Baosight Co. Ltd.
|
||||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||||
*
|
||||
*/
|
||||
#include "mix_cc/sql/make_table.h"
|
||||
#include <string>
|
||||
using namespace mix_cc::sql;
|
||||
using namespace std::chrono;
|
||||
|
||||
MIX_CC_SQL_MAKE_TABLE(T_RULE_CFG, (std::string, ruleId), (std::string, remark),
|
||||
(std::string, ruleGroup), (int, algId), (int, flag),
|
||||
(std::string, ruleName), (std::string, ruleParam),
|
||||
(double, paddingUp), (double, paddingDown),
|
||||
(int, TaskSeq), (std::string, eqpid),
|
||||
(mix_cc::mix_time_t, toc));
|
||||
98
RICS/utility.cc
Normal file
98
RICS/utility.cc
Normal file
@ -0,0 +1,98 @@
|
||||
#include <RICS/utility.h>
|
||||
|
||||
namespace UtilityTools {
|
||||
|
||||
TimePoint time_point2zero(TimePoint time_point) {
|
||||
return second_zero2time_point(time_point2second_zero(time_point));
|
||||
}
|
||||
|
||||
int time_point2second_zero(TimePoint time_point) {
|
||||
int seconds = (time_point.time_since_epoch().count()) / (size_t)pow(10, 9);
|
||||
return 86400 * (int)((seconds + 28800) / 86400) - 28800;
|
||||
}
|
||||
|
||||
TimePoint second_zero2time_point(int seconds) {
|
||||
auto st_s = std::chrono::seconds(seconds);
|
||||
auto time_date =
|
||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds>(
|
||||
st_s);
|
||||
return time_date;
|
||||
}
|
||||
|
||||
TimePoint millsecond_zero2time_point(int64_t millseconds) {
|
||||
auto st_s = std::chrono::milliseconds(millseconds);
|
||||
auto time_date = std::chrono::time_point<std::chrono::system_clock,
|
||||
std::chrono::milliseconds>(st_s);
|
||||
return time_date;
|
||||
}
|
||||
|
||||
int diff_days(TimePoint stime, TimePoint etime) {
|
||||
return std::chrono::duration_cast<days>(etime - stime).count();
|
||||
}
|
||||
|
||||
TimePoint string2TimePoint(std::string time_str, const std::string &fmt) {
|
||||
std::tm tm = {};
|
||||
std::stringstream ss(time_str);
|
||||
ss >> std::get_time(&tm, fmt.c_str());
|
||||
return std::chrono::system_clock::from_time_t(std::mktime(&tm));
|
||||
}
|
||||
|
||||
int save_json_file(std::string path_ruleid, std::string file_name_date,
|
||||
nlohmann::json content, std::string root_dir) {
|
||||
try {
|
||||
// 将 JSON 对象写入文件
|
||||
|
||||
std::string file_path = root_dir + "/" + path_ruleid;
|
||||
std::string file_name = file_path + "/" + file_name_date + ".json";
|
||||
if (fs::exists(file_name)) {
|
||||
return 1;
|
||||
}
|
||||
if (create_path(file_path)) {
|
||||
std::ofstream ofs(file_name); // 创建文件输出流对象,打开文件 "data.json"
|
||||
ofs << content.dump(4); // 将 JSON 内容以字符串形式(带4空格缩进)写入文件
|
||||
ofs.close(); // 关闭文件
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
throw;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
bool jsonReader(std::string file_path, json &sjson) {
|
||||
// 1. 创建文件流并打开文件
|
||||
std::ifstream file(file_path);
|
||||
if (!file.is_open()) {
|
||||
return false;
|
||||
}
|
||||
// 2. 解析JSON数据
|
||||
try {
|
||||
file >> sjson; // 方式1: 直接使用流操作符解析文件
|
||||
// 也可以使用显式解析: jsonData = json::parse(file);
|
||||
} catch (const std::exception &e) {
|
||||
file.close();
|
||||
return false;
|
||||
}
|
||||
// 3. 关闭文件
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
bool create_path(std::string path) {
|
||||
try {
|
||||
// 检查路径是否存在
|
||||
if (!fs::exists(path)) {
|
||||
// 递归创建所有不存在的目录
|
||||
return fs::create_directories(path);
|
||||
}
|
||||
} catch (const fs::filesystem_error &e) {
|
||||
// 捕获并输出文件系统操作中的异常
|
||||
throw;
|
||||
return false; // 返回非零值表示错误
|
||||
}
|
||||
}
|
||||
|
||||
bool is_file_exists(std::string file_path) { return fs::exists(file_path); }
|
||||
|
||||
} // namespace UtilityTools
|
||||
90
RICS/utility.h
Normal file
90
RICS/utility.h
Normal file
@ -0,0 +1,90 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
/**
|
||||
* @file utility.h
|
||||
* @brief 时间工具函数
|
||||
* @author your name (you@domain.com)
|
||||
* @version 0.1
|
||||
* @date 2023-12-22
|
||||
*
|
||||
* Copyright: Baosight Co. Ltd.
|
||||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||||
*
|
||||
*/
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <sstream>
|
||||
#include <filesystem> // C++17 文件系统库
|
||||
namespace fs = std::filesystem; // 简化命名空间
|
||||
using namespace std::chrono;
|
||||
using std::chrono::system_clock;
|
||||
using TimePoint = system_clock::time_point;
|
||||
using TimeDur = milliseconds;
|
||||
|
||||
namespace UtilityTools {
|
||||
using json = nlohmann::json;
|
||||
/**
|
||||
* @brief 时间转当日凌晨时间
|
||||
* @param time_point My Param doc
|
||||
* @return TimePoint
|
||||
*/
|
||||
TimePoint time_point2zero(TimePoint time_point);
|
||||
|
||||
/**
|
||||
* @brief 时间点 转 时间戳秒 (当日凌晨)
|
||||
* @param time_point My Param doc
|
||||
* @return int
|
||||
*/
|
||||
int time_point2second_zero(TimePoint time_point);
|
||||
/**
|
||||
* @brief 时间戳秒 转 时间点
|
||||
* @param seconds My Param doc
|
||||
* @return TimePoint
|
||||
*/
|
||||
TimePoint second_zero2time_point(int seconds);
|
||||
|
||||
TimePoint millsecond_zero2time_point(int64_t millseconds);
|
||||
/**
|
||||
* @brief 时间差 天
|
||||
* @param stime My Param doc
|
||||
* @param etime My Param doc
|
||||
* @return int
|
||||
*/
|
||||
int diff_days(TimePoint stime, TimePoint etime);
|
||||
/**
|
||||
* @brief str时间转chrono时间
|
||||
* @param date My Param doc
|
||||
* @param fmt My Param doc
|
||||
* @return TimePoint
|
||||
*/
|
||||
TimePoint string2TimePoint(std::string date,
|
||||
const std::string &fmt = "%Y-%m-%d %H:%M:%S");
|
||||
|
||||
/**
|
||||
* @brief 保存json文件
|
||||
* @param path_ruleid My Param doc
|
||||
* @param file_name_date My Param doc
|
||||
* @param content My Param doc
|
||||
* @param root_dir My Param doc
|
||||
* @return int
|
||||
* @return 0--保存成功;1--文件已存在;-1--保存异常
|
||||
*/
|
||||
int save_json_file(std::string path_ruleid,std::string file_name_date, json content,
|
||||
std::string root_dir = "/dscdata/RuleNormData");
|
||||
/**
|
||||
* @brief json文件读取到 json
|
||||
* @param file_path My Param doc
|
||||
* @param sjson My Param doc
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool jsonReader(std::string file_path, json &sjson);
|
||||
bool create_path(std::string path);
|
||||
bool is_file_exists(std::string file_path);
|
||||
|
||||
} // namespace UtilityTools
|
||||
63
TestProject/CronTab/CMakeLists.txt
Normal file
63
TestProject/CronTab/CMakeLists.txt
Normal file
@ -0,0 +1,63 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(CronTab VERSION 0.1)
|
||||
|
||||
set(CONFIG_FILE_PATH "config.json")
|
||||
|
||||
include(../../cmake_include/public.cmake)
|
||||
include(../../cmake_include/baosight.cmake)
|
||||
include(../../cmake_include/mix_cc.cmake)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-omit-frame-pointer -Wno-deprecated-declarations")
|
||||
aux_source_directory(./ DIR_ROOT)
|
||||
|
||||
|
||||
set(LINK_OPTION
|
||||
${ICE}
|
||||
${IPLATURE}
|
||||
${SQL}
|
||||
${FREEZE}
|
||||
${BASE_LIB}
|
||||
${CODE_LIB}
|
||||
${IDA}
|
||||
${LEGACY_JSON}
|
||||
${MEMCACHE_LIB}
|
||||
${IHDB_LIB}
|
||||
rt
|
||||
stdc++
|
||||
c
|
||||
m
|
||||
)
|
||||
|
||||
add_executable(
|
||||
CronTab
|
||||
${DIR_ROOT}
|
||||
)
|
||||
|
||||
target_link_libraries(CronTab
|
||||
${LINK_OPTION}
|
||||
${mix_cc}
|
||||
Eigen3::Eigen )
|
||||
|
||||
target_include_directories(
|
||||
CronTab
|
||||
PUBLIC ./
|
||||
../
|
||||
../../
|
||||
${my_lib_include}
|
||||
${legacy_include}
|
||||
${iplature_include}
|
||||
${ihdb_include}
|
||||
${memcache_include}
|
||||
${Boost_INCLUDE_DIR}
|
||||
${iXcom}Include)
|
||||
|
||||
message("my_lib_include:${my_lib_include}")
|
||||
message("legacy_include:${legacy_include}")
|
||||
message("iplature_include:${iplature_include}")
|
||||
message("ihdb_include:${ihdb_include}")
|
||||
message("memcache_include:${memcache_include}")
|
||||
# message("Boost_INCLUDE_DIR:${Boost_INCLUDE_DIR}")
|
||||
|
||||
|
||||
set_target_properties(CronTab PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${bin_dir})
|
||||
|
||||
30
TestProject/CronTab/CronTab.cc
Normal file
30
TestProject/CronTab/CronTab.cc
Normal file
@ -0,0 +1,30 @@
|
||||
#include <TestProject/CronTab/CronTab.h>
|
||||
#include <TestProject/CronTab/CronTab_icei.h>
|
||||
#include <glob/GlobDefine.h>
|
||||
#include <utility/IniProperty.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "mix_cc/debug/pre_define.h"
|
||||
|
||||
using namespace baosight;
|
||||
|
||||
CronTab::CronTab() { logger_ = std::make_unique<LOG>("CronTab"); }
|
||||
|
||||
CronTab::~CronTab() {}
|
||||
|
||||
int CronTab::start() {
|
||||
logger_->Info() << "-------CronTab::start-------" << std::endl;
|
||||
try {
|
||||
auto module_name = name();
|
||||
CronTab_server = new CronTabICEI();
|
||||
this->add(string("baosight/") + name(), CronTab_server);
|
||||
} catch (::Ice::LocalException& e) {
|
||||
logger_->Error() << "Can not add baosight/CronTab, error: " << e << endl;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// PACE_SERVER_INSTALL(CronTab) //应用程序主入口,传入参数为定义的类名
|
||||
PACE_PLATFORM_SERVER_INSTALL(CronTab, APPVERSION);
|
||||
39
TestProject/CronTab/CronTab.h
Normal file
39
TestProject/CronTab/CronTab.h
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#include <TestProject/CronTab/CronTab_icei.h>
|
||||
#include <glob/ConnectionMag.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <pace/Component.h>
|
||||
#include <pace/pace.h>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace baosight {
|
||||
/**
|
||||
* @brief 负载程序的启动和初始变量信息的加载
|
||||
*/
|
||||
class CronTab : public Component {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new CronTab object
|
||||
*/
|
||||
CronTab();
|
||||
|
||||
/**
|
||||
* @brief Destroy the CronTab object
|
||||
*/
|
||||
virtual ~CronTab();
|
||||
|
||||
/**
|
||||
* @brief 启动进程
|
||||
* @return int
|
||||
*/
|
||||
virtual int start();
|
||||
|
||||
private:
|
||||
MessageICEPtr CronTab_server; ///< Ice通信模块
|
||||
std::unique_ptr<LOG> logger_;
|
||||
};
|
||||
}; // namespace baosight
|
||||
110
TestProject/CronTab/CronTab_icei.cc
Normal file
110
TestProject/CronTab/CronTab_icei.cc
Normal file
@ -0,0 +1,110 @@
|
||||
|
||||
#include <TestProject/CronTab/CronTab_icei.h>
|
||||
#include <TestProject/CronTab/cron_timer.h>
|
||||
#include <common/L2Event.h>
|
||||
#include <dao/DbStandardDBAX.h>
|
||||
#include <mix_cc/utility/read_config.h>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
std::atomic_bool _shutDown;
|
||||
|
||||
CronTabICEI::CronTabICEI() {
|
||||
this->logger_ = std::make_unique<LOG>("CronTab_icei");
|
||||
// auto cronTab_config_maybe = mix_cc::read_config_maybe("utility", "CronTab");
|
||||
// if (cronTab_config_maybe.is_nothing()) {
|
||||
// logger_->Error() << "配置读取失败" << endl;
|
||||
// _shutDown = true;
|
||||
// }
|
||||
|
||||
// auto cronTab_config = cronTab_config_maybe.unsafe_get_just();
|
||||
// vector<std::string> proxy_vec =
|
||||
// cronTab_config.at("proxy").get<vector<std::string>>();
|
||||
// vector<std::string> exp_vec =
|
||||
// cronTab_config.at("exp").get<vector<std::string>>();
|
||||
// vector<int> eventno_vec = cronTab_config.at("eventno").get<vector<int>>();
|
||||
// int p_size = proxy_vec.size();
|
||||
// int e_size = exp_vec.size();
|
||||
// int ev_size = eventno_vec.size();
|
||||
// if (p_size != e_size || p_size == 0 || ev_size == 0 || ev_size != p_size) {
|
||||
// logger_->Error() << "配置为空 或配置不匹配,proxy size:" << p_size
|
||||
// << ",exp size:" << e_size << endl;
|
||||
// _shutDown = true;
|
||||
// }
|
||||
|
||||
// for (int i = 0; i < p_size; i++) {
|
||||
// logger_->Debug() << "proxy:" << proxy_vec[i];
|
||||
// vec_prox_.push_back(ProxyMag::GetAppICEPrx(proxy_vec[i]));
|
||||
// }
|
||||
|
||||
// ::Ice::ByteSeq seq;
|
||||
|
||||
// cron_timer::TimerMgr mgr;
|
||||
// for (int i = 0; i < p_size; i++) {
|
||||
// // mgr.AddTimer(exp_vec[i], [&,i](void) {
|
||||
// // this->logger_->Debug() << "Test--1--" << i << endl;
|
||||
// // });
|
||||
// mgr.AddTimer(exp_vec[i], [&, i, &seq, &proxy_vec, &exp_vec](void) {
|
||||
// // every second
|
||||
// // this->logger_->Debug() << "1 second cron timer hit--1" << endl;
|
||||
// try {
|
||||
// vec_prox_[i]->TimeNotify(eventno_vec[i], seq);
|
||||
// this->logger_->Info() << "proxy:" << proxy_vec[i]
|
||||
// << ",exp:" << exp_vec[i] << ",is OK!" << endl;
|
||||
// } catch (const std::exception& e) {
|
||||
// this->logger_->Error()
|
||||
// << "proxy:" << proxy_vec[i] << ",exp:" << exp_vec[i]
|
||||
// << ",ERROR:" << e.what() << endl;
|
||||
// }
|
||||
|
||||
// // vec_prox_[0]->SendDataShort(1, seq, seq.size());
|
||||
// // this->logger_->Debug() << "1 second cron timer hit--2" << endl;
|
||||
// });
|
||||
// }
|
||||
|
||||
// while (!_shutDown) {
|
||||
// auto nearest_timer = (std::min)(
|
||||
// std::chrono::system_clock::now() + std::chrono::milliseconds(500),
|
||||
// mgr.GetNearestTime());
|
||||
// std::this_thread::sleep_until(nearest_timer);
|
||||
// mgr.Update();
|
||||
// }
|
||||
}
|
||||
|
||||
CronTabICEI::~CronTabICEI() {
|
||||
_shutDown = true;
|
||||
logger_->Debug() << "CronTabICEI::~CronTabICEI()" << endl;
|
||||
}
|
||||
|
||||
void baosight::CronTabICEI::SendDataShort(::Ice::Int eventNo,
|
||||
const ::Ice::ByteSeq& seq,
|
||||
::Ice::Int length,
|
||||
const Ice::Current& current) {
|
||||
// string data(seq.begin(), seq.end());
|
||||
logger_->Info() << "CronTabICEI::SendDataShort:" << endl;
|
||||
// if (eventNo == 12) {
|
||||
// logger_->Debug() << "Test:" << eventNo << ",size:" << seq.size() << endl;
|
||||
// }
|
||||
|
||||
// send2pyml_->SendDataShort(eventNo, seq, length);
|
||||
// logger_->Info() << "CronTabICEI::SendDataShort 结束!" << endl;
|
||||
}
|
||||
|
||||
void baosight::CronTabICEI::SendDataLong(
|
||||
::Ice::Int eventNo, const ::Ice::ByteSeq& seq, ::Ice::Int length,
|
||||
const ::std::string& sender, const ::std::string& receiver,
|
||||
const ::std::string& additional, const Ice::Current& current) {}
|
||||
|
||||
void baosight::CronTabICEI::TimeNotify(::Ice::Int eventNo,
|
||||
const ::Ice::ByteSeq& seq,
|
||||
const Ice::Current& current) {
|
||||
// logger_->Debug() << "CronTab" << endl;
|
||||
// string proxyName = "baosight/ptest1";
|
||||
// string keyValue = "CronTab 2 baosight/ptest1!";
|
||||
// int length = keyValue.size();
|
||||
// ::Ice::ByteSeq sendData((unsigned char*)keyValue.c_str(),
|
||||
// (unsigned char*)keyValue.c_str() + length);
|
||||
// ProxyMag::GetAppICEPrx(proxyName)->SendDataShort(eventNo, sendData,
|
||||
// sendData.size());
|
||||
logger_->Debug() << "Test!" << eventNo << endl;
|
||||
}
|
||||
50
TestProject/CronTab/CronTab_icei.h
Normal file
50
TestProject/CronTab/CronTab_icei.h
Normal file
@ -0,0 +1,50 @@
|
||||
|
||||
#pragma once
|
||||
#include <common/L2Event.h>
|
||||
#include <dao/DbStandardDBAX.h>
|
||||
#include <glob/ProxyMag.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <proxy/MessageICE.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
namespace baosight {
|
||||
|
||||
/**
|
||||
* @brief Ice接口类实现,其中包含了对不同电文的调用
|
||||
*/
|
||||
class CronTabICEI : virtual public MessageICE {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Eqp Alg I C E I object
|
||||
*/
|
||||
CronTabICEI();
|
||||
virtual ~CronTabICEI();
|
||||
|
||||
/**
|
||||
* @brief 简单数据调用接口
|
||||
*/
|
||||
virtual void SendDataShort(::Ice::Int, const ::Ice::ByteSeq&, ::Ice::Int,
|
||||
const Ice::Current&);
|
||||
|
||||
/**
|
||||
* @brief 复杂数据调用接口
|
||||
*/
|
||||
virtual void SendDataLong(::Ice::Int, const ::Ice::ByteSeq&, ::Ice::Int,
|
||||
const ::std::string&, const ::std::string&,
|
||||
const ::std::string&, const Ice::Current&);
|
||||
|
||||
/**
|
||||
* @brief 定时器调用接口
|
||||
*/
|
||||
virtual void TimeNotify(::Ice::Int, const ::Ice::ByteSeq&,
|
||||
const Ice::Current&);
|
||||
|
||||
private:
|
||||
std::unique_ptr<LOG> logger_; ///< 本地logger
|
||||
std::vector<baosight::MessageICEPrx> vec_prox_;
|
||||
};
|
||||
|
||||
} // namespace baosight
|
||||
499
TestProject/CronTab/cron_timer.h
Normal file
499
TestProject/CronTab/cron_timer.h
Normal file
@ -0,0 +1,499 @@
|
||||
#pragma once
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace cron_timer {
|
||||
class Text {
|
||||
public:
|
||||
// Used to split strings separated by spaces, consecutive spaces are counted
|
||||
// as a separator
|
||||
static size_t SplitStr(std::vector<std::string>& os, const std::string& is,
|
||||
char c) {
|
||||
os.clear();
|
||||
auto start = is.find_first_not_of(c, 0);
|
||||
while (start != std::string::npos) {
|
||||
auto end = is.find_first_of(c, start);
|
||||
if (end == std::string::npos) {
|
||||
os.emplace_back(is.substr(start));
|
||||
break;
|
||||
} else {
|
||||
os.emplace_back(is.substr(start, end - start));
|
||||
start = is.find_first_not_of(c, end + 1);
|
||||
}
|
||||
}
|
||||
return os.size();
|
||||
}
|
||||
|
||||
static size_t SplitInt(std::vector<int>& number_result, const std::string& is,
|
||||
char c) {
|
||||
std::vector<std::string> string_result;
|
||||
SplitStr(string_result, is, c);
|
||||
|
||||
number_result.clear();
|
||||
for (size_t i = 0; i < string_result.size(); i++) {
|
||||
const std::string& value = string_result[i];
|
||||
number_result.emplace_back(atoi(value.data()));
|
||||
}
|
||||
|
||||
return number_result.size();
|
||||
}
|
||||
|
||||
static std::vector<std::string> ParseParam(const std::string& is, char c) {
|
||||
std::vector<std::string> result;
|
||||
ParseParam(result, is, c);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Used to segment strings separated by commas, consecutive commas are counted
|
||||
// as multiple delimiters
|
||||
static size_t ParseParam(std::vector<std::string>& result,
|
||||
const std::string& is, char c) {
|
||||
result.clear();
|
||||
size_t start = 0;
|
||||
while (start < is.size()) {
|
||||
auto end = is.find_first_of(c, start);
|
||||
if (end != std::string::npos) {
|
||||
result.emplace_back(is.substr(start, end - start));
|
||||
start = end + 1;
|
||||
} else {
|
||||
result.emplace_back(is.substr(start));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (start == is.size()) {
|
||||
result.emplace_back(std::string());
|
||||
}
|
||||
return result.size();
|
||||
}
|
||||
};
|
||||
|
||||
class CronExpression {
|
||||
public:
|
||||
enum DATA_TYPE {
|
||||
DT_SECOND = 0,
|
||||
DT_MINUTE = 1,
|
||||
DT_HOUR = 2,
|
||||
DT_DAY_OF_MONTH = 3,
|
||||
DT_MONTH = 4,
|
||||
DT_YEAR = 5,
|
||||
DT_MAX,
|
||||
};
|
||||
|
||||
static bool GetValues(const std::string& input, DATA_TYPE data_type,
|
||||
std::vector<int>& values) {
|
||||
//
|
||||
// attention: enum seperater is ';' not ',' for using it in csv
|
||||
//
|
||||
|
||||
static const char CRON_SEPERATOR_ENUM = ';';
|
||||
static const char CRON_SEPERATOR_RANGE = '-';
|
||||
static const char CRON_SEPERATOR_INTERVAL = '/';
|
||||
|
||||
if (input == "*") {
|
||||
auto pair_range = GetRangeFromType(data_type);
|
||||
for (auto i = pair_range.first; i <= pair_range.second; ++i) {
|
||||
values.push_back(i);
|
||||
}
|
||||
} else if (input.find_first_of(CRON_SEPERATOR_ENUM) != std::string::npos) {
|
||||
// enum
|
||||
std::vector<int> v;
|
||||
Text::SplitInt(v, input, CRON_SEPERATOR_ENUM);
|
||||
std::pair<int, int> pair_range = GetRangeFromType(data_type);
|
||||
for (auto value : v) {
|
||||
if (value < pair_range.first || value > pair_range.second) {
|
||||
return false;
|
||||
}
|
||||
values.push_back(value);
|
||||
}
|
||||
} else if (input.find_first_of(CRON_SEPERATOR_RANGE) != std::string::npos) {
|
||||
// range
|
||||
std::vector<int> v;
|
||||
Text::SplitInt(v, input, CRON_SEPERATOR_RANGE);
|
||||
if (v.size() != 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int from = v[0];
|
||||
int to = v[1];
|
||||
std::pair<int, int> pair_range = GetRangeFromType(data_type);
|
||||
if (from < pair_range.first || to > pair_range.second) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = from; i <= to; i++) {
|
||||
values.push_back(i);
|
||||
}
|
||||
} else if (input.find_first_of(CRON_SEPERATOR_INTERVAL) !=
|
||||
std::string::npos) {
|
||||
// interval
|
||||
std::vector<int> v;
|
||||
Text::SplitInt(v, input, CRON_SEPERATOR_INTERVAL);
|
||||
if (v.size() != 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int from = v[0];
|
||||
int interval = v[1];
|
||||
std::pair<int, int> pair_range = GetRangeFromType(data_type);
|
||||
if (from < pair_range.first || interval < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = from; i <= pair_range.second; i += interval) {
|
||||
values.push_back(i);
|
||||
}
|
||||
} else {
|
||||
// specific value
|
||||
std::pair<int, int> pair_range = GetRangeFromType(data_type);
|
||||
int value = atoi(input.data());
|
||||
if (value < pair_range.first || value > pair_range.second) {
|
||||
return false;
|
||||
}
|
||||
|
||||
values.push_back(value);
|
||||
}
|
||||
|
||||
assert(values.size() > 0);
|
||||
return values.size() > 0;
|
||||
}
|
||||
|
||||
private:
|
||||
static std::pair<int, int> GetRangeFromType(DATA_TYPE data_type) {
|
||||
int from = 0;
|
||||
int to = 0;
|
||||
|
||||
switch (data_type) {
|
||||
case CronExpression::DT_SECOND:
|
||||
case CronExpression::DT_MINUTE:
|
||||
from = 0;
|
||||
to = 59;
|
||||
break;
|
||||
case CronExpression::DT_HOUR:
|
||||
from = 0;
|
||||
to = 23;
|
||||
break;
|
||||
case CronExpression::DT_DAY_OF_MONTH:
|
||||
from = 1;
|
||||
to = 31;
|
||||
break;
|
||||
case CronExpression::DT_MONTH:
|
||||
from = 1;
|
||||
to = 12;
|
||||
break;
|
||||
case CronExpression::DT_YEAR:
|
||||
from = 1970;
|
||||
to = 2099;
|
||||
break;
|
||||
case CronExpression::DT_MAX:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return std::make_pair(from, to);
|
||||
}
|
||||
};
|
||||
|
||||
class TimerMgr;
|
||||
class BaseTimer;
|
||||
using FUNC_CALLBACK = std::function<void()>;
|
||||
using TimerPtr = std::shared_ptr<BaseTimer>;
|
||||
|
||||
class BaseTimer : public std::enable_shared_from_this<BaseTimer> {
|
||||
friend class TimerMgr;
|
||||
|
||||
public:
|
||||
BaseTimer(TimerMgr& owner, FUNC_CALLBACK&& func, int count)
|
||||
: m_owner(owner),
|
||||
m_func(std::move(func)),
|
||||
m_triggerTime(std::chrono::system_clock::now()),
|
||||
m_countLeft(count),
|
||||
m_canceled(false) {}
|
||||
virtual ~BaseTimer() {}
|
||||
inline void Cancel();
|
||||
|
||||
// trigger time of the timer
|
||||
std::chrono::system_clock::time_point GetTriggerTime() const {
|
||||
return m_triggerTime;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void CreateTriggerTime(bool next) = 0;
|
||||
inline void DoFunc();
|
||||
|
||||
protected:
|
||||
TimerMgr& m_owner;
|
||||
FUNC_CALLBACK m_func;
|
||||
std::chrono::system_clock::time_point m_triggerTime;
|
||||
int m_countLeft;
|
||||
bool m_canceled;
|
||||
};
|
||||
|
||||
struct CronWheel {
|
||||
CronWheel() : cur_index(0) {}
|
||||
|
||||
size_t cur_index;
|
||||
std::vector<int> values;
|
||||
};
|
||||
|
||||
class CronTimer : public BaseTimer {
|
||||
friend class TimerMgr;
|
||||
|
||||
public:
|
||||
CronTimer(TimerMgr& owner, std::vector<CronWheel>&& wheels,
|
||||
FUNC_CALLBACK&& func, int count)
|
||||
: BaseTimer(owner, std::move(func), count), m_wheels(std::move(wheels)) {
|
||||
tm local_tm;
|
||||
time_t time_now = time(nullptr);
|
||||
|
||||
#ifdef _WIN32
|
||||
localtime_s(&local_tm, &time_now);
|
||||
#else
|
||||
localtime_r(&time_now, &local_tm);
|
||||
#endif // _WIN32
|
||||
|
||||
std::vector<int> init_values;
|
||||
init_values.push_back(local_tm.tm_sec);
|
||||
init_values.push_back(local_tm.tm_min);
|
||||
init_values.push_back(local_tm.tm_hour);
|
||||
init_values.push_back(local_tm.tm_mday);
|
||||
init_values.push_back(local_tm.tm_mon + 1);
|
||||
init_values.push_back(local_tm.tm_year + 1900);
|
||||
|
||||
std::pair<size_t, bool> pairValue = std::make_pair(0, false);
|
||||
for (int i = CronExpression::DT_YEAR; i >= 0; i--) {
|
||||
pairValue = GetMinValid(i, init_values[i], pairValue.second);
|
||||
m_wheels[i].cur_index = pairValue.first;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void CreateTriggerTime(bool next) {
|
||||
if (next) {
|
||||
Next(CronExpression::DT_SECOND);
|
||||
}
|
||||
|
||||
tm next_tm;
|
||||
memset(&next_tm, 0, sizeof(next_tm));
|
||||
next_tm.tm_sec = GetCurValue(CronExpression::DT_SECOND);
|
||||
next_tm.tm_min = GetCurValue(CronExpression::DT_MINUTE);
|
||||
next_tm.tm_hour = GetCurValue(CronExpression::DT_HOUR);
|
||||
next_tm.tm_mday = GetCurValue(CronExpression::DT_DAY_OF_MONTH);
|
||||
next_tm.tm_mon = GetCurValue(CronExpression::DT_MONTH) - 1;
|
||||
next_tm.tm_year = GetCurValue(CronExpression::DT_YEAR) - 1900;
|
||||
|
||||
m_triggerTime = std::chrono::system_clock::from_time_t(mktime(&next_tm));
|
||||
}
|
||||
|
||||
// move to the next trigger time
|
||||
void Next(int data_type) {
|
||||
if (data_type >= CronExpression::DT_MAX) {
|
||||
// overflowed, this timer is invalid, should be removed
|
||||
m_canceled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
auto& wheel = m_wheels[data_type];
|
||||
if (wheel.cur_index == wheel.values.size() - 1) {
|
||||
wheel.cur_index = 0;
|
||||
Next(data_type + 1);
|
||||
} else {
|
||||
++wheel.cur_index;
|
||||
}
|
||||
}
|
||||
|
||||
// return index, is changed
|
||||
std::pair<size_t, bool> GetMinValid(int data_type, int value,
|
||||
bool changed) const {
|
||||
auto& wheel = m_wheels[data_type];
|
||||
if (changed) {
|
||||
return std::make_pair(0, true);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < wheel.values.size(); i++) {
|
||||
if (wheel.values[i] < value) {
|
||||
continue;
|
||||
} else if (wheel.values[i] == value) {
|
||||
return std::make_pair(i, false);
|
||||
} else {
|
||||
return std::make_pair(i, true);
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_pair(0, true);
|
||||
}
|
||||
|
||||
int GetCurValue(int data_type) const {
|
||||
const auto& wheel = m_wheels[data_type];
|
||||
return wheel.values[wheel.cur_index];
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<CronWheel> m_wheels;
|
||||
};
|
||||
|
||||
class LaterTimer : public BaseTimer {
|
||||
friend class TimerMgr;
|
||||
|
||||
public:
|
||||
LaterTimer(TimerMgr& owner, int milliseconds, FUNC_CALLBACK&& func, int count)
|
||||
: BaseTimer(owner, std::move(func), count),
|
||||
m_milliSeconds(milliseconds) {}
|
||||
|
||||
private:
|
||||
virtual void CreateTriggerTime(bool next) {
|
||||
m_triggerTime += std::chrono::milliseconds(m_milliSeconds);
|
||||
}
|
||||
|
||||
private:
|
||||
const int m_milliSeconds;
|
||||
};
|
||||
|
||||
class TimerMgr {
|
||||
friend class BaseTimer;
|
||||
friend class CronTimer;
|
||||
friend class LaterTimer;
|
||||
|
||||
public:
|
||||
TimerMgr() {}
|
||||
TimerMgr(const TimerMgr&) = delete;
|
||||
const TimerMgr& operator=(const TimerMgr&) = delete;
|
||||
|
||||
void Stop() { m_timers.clear(); }
|
||||
|
||||
enum {
|
||||
RUN_FOREVER = 0,
|
||||
};
|
||||
|
||||
TimerPtr AddTimer(const std::string& timer_string, FUNC_CALLBACK&& func,
|
||||
int count = RUN_FOREVER) {
|
||||
std::vector<std::string> v;
|
||||
Text::SplitStr(v, timer_string, ' ');
|
||||
if (v.size() != CronExpression::DT_MAX) {
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<CronWheel> wheels;
|
||||
for (int i = 0; i < CronExpression::DT_MAX; i++) {
|
||||
const auto& expression = v[i];
|
||||
CronExpression::DATA_TYPE data_type = CronExpression::DATA_TYPE(i);
|
||||
CronWheel wheel;
|
||||
if (!CronExpression::GetValues(expression, data_type, wheel.values)) {
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
wheels.emplace_back(wheel);
|
||||
}
|
||||
|
||||
auto p = std::make_shared<CronTimer>(*this, std::move(wheels),
|
||||
std::move(func), count);
|
||||
p->CreateTriggerTime(false);
|
||||
insert(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
TimerPtr AddDelayTimer(int milliseconds, FUNC_CALLBACK&& func,
|
||||
int count = 1) {
|
||||
assert(milliseconds > 0);
|
||||
milliseconds = (std::max)(milliseconds, 1);
|
||||
auto p = std::make_shared<LaterTimer>(*this, milliseconds, std::move(func),
|
||||
count);
|
||||
p->CreateTriggerTime(true);
|
||||
insert(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
std::chrono::system_clock::time_point GetNearestTime() {
|
||||
auto it = m_timers.begin();
|
||||
if (it == m_timers.end()) {
|
||||
return (std::chrono::system_clock::time_point::max)();
|
||||
} else {
|
||||
return it->first;
|
||||
}
|
||||
}
|
||||
|
||||
size_t Update() {
|
||||
auto time_now = std::chrono::system_clock::now();
|
||||
size_t count = 0;
|
||||
|
||||
for (auto it = m_timers.begin(); it != m_timers.end();) {
|
||||
auto expire_time = it->first;
|
||||
if (expire_time > time_now) {
|
||||
break;
|
||||
}
|
||||
|
||||
// attention: this is a copy, not a reference
|
||||
auto timer_set = it->second;
|
||||
it = m_timers.erase(it);
|
||||
|
||||
for (auto p : timer_set) {
|
||||
p->DoFunc();
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private:
|
||||
void insert(const TimerPtr& p) {
|
||||
auto t = p->GetTriggerTime();
|
||||
auto it = m_timers.find(t);
|
||||
if (it == m_timers.end()) {
|
||||
std::set<TimerPtr> s;
|
||||
s.insert(p);
|
||||
m_timers[t] = s;
|
||||
} else {
|
||||
std::set<TimerPtr>& s = it->second;
|
||||
s.insert(p);
|
||||
}
|
||||
}
|
||||
|
||||
void remove(const TimerPtr& p) {
|
||||
auto t = p->GetTriggerTime();
|
||||
auto it = m_timers.find(t);
|
||||
if (it == m_timers.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::set<TimerPtr>& s = it->second;
|
||||
s.erase(p);
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<std::chrono::system_clock::time_point, std::set<TimerPtr>> m_timers;
|
||||
};
|
||||
|
||||
void BaseTimer::Cancel() {
|
||||
auto self = shared_from_this();
|
||||
m_owner.remove(self);
|
||||
m_canceled = true;
|
||||
}
|
||||
|
||||
void BaseTimer::DoFunc() {
|
||||
m_func();
|
||||
CreateTriggerTime(true);
|
||||
|
||||
// the timer can be cancelled in m_func()
|
||||
if (!m_canceled) {
|
||||
if (m_countLeft == TimerMgr::RUN_FOREVER || m_countLeft > 1) {
|
||||
if (m_countLeft > 1) {
|
||||
m_countLeft--;
|
||||
}
|
||||
|
||||
auto self = shared_from_this();
|
||||
m_owner.insert(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace cron_timer
|
||||
57
TestProject/DCR/CMakeLists.txt
Normal file
57
TestProject/DCR/CMakeLists.txt
Normal file
@ -0,0 +1,57 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(DCR VERSION 0.1)
|
||||
|
||||
set(CONFIG_FILE_PATH "config.json")
|
||||
set(vcpkg_include "/opt/vcpkg/installed/x64-linux/include")
|
||||
include(../../cmake_include/public.cmake)
|
||||
include(../../cmake_include/baosight.cmake)
|
||||
include(../../cmake_include/mix_cc.cmake)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-omit-frame-pointer -Wno-deprecated-declarations")
|
||||
aux_source_directory(./ DIR_ROOT)
|
||||
aux_source_directory(connection CONNECTION)
|
||||
|
||||
|
||||
set(LINK_OPTION
|
||||
${ICE}
|
||||
${IPLATURE}
|
||||
${SQL}
|
||||
${FREEZE}
|
||||
${BASE_LIB}
|
||||
${CODE_LIB}
|
||||
${IDA}
|
||||
${LEGACY_JSON}
|
||||
${MEMCACHE_LIB}
|
||||
${IHDB_LIB}
|
||||
rt
|
||||
stdc++
|
||||
c
|
||||
m
|
||||
)
|
||||
|
||||
add_executable(
|
||||
DCR
|
||||
${DIR_ROOT}
|
||||
${CONNECTION}
|
||||
|
||||
)
|
||||
|
||||
target_link_libraries(DCR
|
||||
${LINK_OPTION}
|
||||
Eigen3::Eigen )
|
||||
|
||||
target_include_directories(
|
||||
DCR
|
||||
PUBLIC ./
|
||||
../
|
||||
../../
|
||||
${vcpkg_include}
|
||||
${my_lib_include}
|
||||
${legacy_include}
|
||||
${iplature_include}
|
||||
${ihdb_include}
|
||||
${memcache_include}
|
||||
${iXcom}Include)
|
||||
|
||||
|
||||
set_target_properties(DCR PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${bin_dir})
|
||||
|
||||
32
TestProject/DCR/DCR.cc
Normal file
32
TestProject/DCR/DCR.cc
Normal file
@ -0,0 +1,32 @@
|
||||
#include <TestProject/DCR/DCR.h>
|
||||
#include <TestProject/DCR/DCR_icei.h>
|
||||
#include <glob/GlobDefine.h>
|
||||
#include <utility/IniProperty.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "mix_cc/debug/pre_define.h"
|
||||
|
||||
using namespace baosight;
|
||||
|
||||
DCR::DCR() { logger_ = std::make_unique<LOG>("DCR"); }
|
||||
|
||||
DCR::~DCR() {}
|
||||
|
||||
int DCR::start() {
|
||||
logger_->Info() << "-------DCR::start-------" << std::endl;
|
||||
con_mag_ = std::make_shared<ConnectionMag>();
|
||||
con_mag_->dbLogin();
|
||||
try {
|
||||
auto module_name = name();
|
||||
DCR_server = new DCRICEI();
|
||||
this->add(string("baosight/") + name(), DCR_server);
|
||||
} catch (::Ice::LocalException& e) {
|
||||
logger_->Error() << "Can not add baosight/DCR, error: " << e << endl;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// PACE_SERVER_INSTALL(DCR) //应用程序主入口,传入参数为定义的类名
|
||||
PACE_PLATFORM_SERVER_INSTALL(DCR, APPVERSION);
|
||||
40
TestProject/DCR/DCR.h
Normal file
40
TestProject/DCR/DCR.h
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
#include <TestProject/DCR/DCR_icei.h>
|
||||
#include <glob/ConnectionMag.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <pace/Component.h>
|
||||
#include <pace/pace.h>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace baosight {
|
||||
/**
|
||||
* @brief 负载程序的启动和初始变量信息的加载
|
||||
*/
|
||||
class DCR : public Component {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new DCR object
|
||||
*/
|
||||
DCR();
|
||||
|
||||
/**
|
||||
* @brief Destroy the DCR object
|
||||
*/
|
||||
virtual ~DCR();
|
||||
|
||||
/**
|
||||
* @brief 启动进程
|
||||
* @return int
|
||||
*/
|
||||
virtual int start();
|
||||
|
||||
private:
|
||||
std::shared_ptr<ConnectionMag> con_mag_; ///< DB2连接管理器,邹师傅的模块需要
|
||||
MessageICEPtr DCR_server; ///< Ice通信模块
|
||||
std::unique_ptr<LOG> logger_;
|
||||
};
|
||||
}; // namespace baosight
|
||||
51
TestProject/DCR/DCR_icei.cc
Normal file
51
TestProject/DCR/DCR_icei.cc
Normal file
@ -0,0 +1,51 @@
|
||||
|
||||
#include <TestProject/DCR/DCR_icei.h>
|
||||
#include <common/L2Event.h>
|
||||
#include <dao/DbStandardDBAX.h>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
DCRICEI::DCRICEI() {
|
||||
this->logger_ = std::make_unique<LOG>("DCR_icei");
|
||||
snaps_ptr_ = std::make_unique<SnapShot>();
|
||||
}
|
||||
|
||||
DCRICEI::~DCRICEI() {}
|
||||
|
||||
void baosight::DCRICEI::SendDataShort(::Ice::Int eventNo,
|
||||
const ::Ice::ByteSeq& seq,
|
||||
::Ice::Int length,
|
||||
const Ice::Current& current) {
|
||||
logger_->Info() << "DCRICEI::SendDataShort:" << endl;
|
||||
}
|
||||
|
||||
void baosight::DCRICEI::SendDataLong(
|
||||
::Ice::Int eventNo, const ::Ice::ByteSeq& seq, ::Ice::Int length,
|
||||
const ::std::string& sender, const ::std::string& receiver,
|
||||
const ::std::string& additional, const Ice::Current& current) {}
|
||||
|
||||
void baosight::DCRICEI::TimeNotify(::Ice::Int eventNo,
|
||||
const ::Ice::ByteSeq& seq,
|
||||
const Ice::Current& current) {
|
||||
if (snaps_ptr_ != nullptr) {
|
||||
// logger_->Debug() << "DCR,ihd is conneced:" << snaps_ptr_->is_connected()
|
||||
// << "-----1----" << endl;
|
||||
// logger_->Debug() << "DCR,ihd is conneced:" << snaps_ptr_->to_connect()
|
||||
// << endl;
|
||||
// logger_->Debug() << "DCR,ihd is conneced:" << snaps_ptr_->is_connected()
|
||||
// << endl;
|
||||
// snaps_ptr_->update_data(2020);
|
||||
// logger_->Debug() << "snaps_ptr_->GetTagIDs:" << endl;
|
||||
logger_->Debug() << "eventNo:" << eventNo
|
||||
<< ",DCR,ihd is conneced:" << snaps_ptr_->to_connect()
|
||||
<< endl;
|
||||
|
||||
if (eventNo > CMemVar::Const()->event_eis_end ||
|
||||
eventNo < CMemVar::Const()->event_eis_start) {
|
||||
logger_->Error() << "eventNo Error!---" << eventNo << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
snaps_ptr_->update_data(eventNo);
|
||||
}
|
||||
}
|
||||
50
TestProject/DCR/DCR_icei.h
Normal file
50
TestProject/DCR/DCR_icei.h
Normal file
@ -0,0 +1,50 @@
|
||||
|
||||
#pragma once
|
||||
#include <TestProject/DCR/Snapshot.h>
|
||||
#include <common/L2Event.h>
|
||||
#include <dao/DbStandardDBAX.h>
|
||||
#include <glob/ProxyMag.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <proxy/MessageICE.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
namespace baosight {
|
||||
|
||||
/**
|
||||
* @brief Ice接口类实现,其中包含了对不同电文的调用
|
||||
*/
|
||||
class DCRICEI : virtual public MessageICE {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Eqp Alg I C E I object
|
||||
*/
|
||||
DCRICEI();
|
||||
virtual ~DCRICEI();
|
||||
|
||||
/**
|
||||
* @brief 简单数据调用接口
|
||||
*/
|
||||
virtual void SendDataShort(::Ice::Int, const ::Ice::ByteSeq&, ::Ice::Int,
|
||||
const Ice::Current&);
|
||||
|
||||
/**
|
||||
* @brief 复杂数据调用接口
|
||||
*/
|
||||
virtual void SendDataLong(::Ice::Int, const ::Ice::ByteSeq&, ::Ice::Int,
|
||||
const ::std::string&, const ::std::string&,
|
||||
const ::std::string&, const Ice::Current&);
|
||||
|
||||
/**
|
||||
* @brief 定时器调用接口
|
||||
*/
|
||||
virtual void TimeNotify(::Ice::Int, const ::Ice::ByteSeq&,
|
||||
const Ice::Current&);
|
||||
|
||||
private:
|
||||
std::unique_ptr<LOG> logger_; ///< 本地logger
|
||||
std::unique_ptr<SnapShot> snaps_ptr_;
|
||||
};
|
||||
|
||||
} // namespace baosight
|
||||
135
TestProject/DCR/Snapshot.cpp
Normal file
135
TestProject/DCR/Snapshot.cpp
Normal file
@ -0,0 +1,135 @@
|
||||
#include <TestProject/DCR/Snapshot.h>
|
||||
#include <TestProject/DCR/connection/connection.h>
|
||||
#include <mix_cc/type/mix_time.h>
|
||||
SnapShot::SnapShot() {
|
||||
logger_ = std::make_unique<LOG>("SnapShot");
|
||||
DCR::ihd::auto_connect();
|
||||
if (DCR::ihd::Connection::State::disconnected ==
|
||||
DCR::ihd::read_conn().state) {
|
||||
logger_->Error() << "ihd connect failure! " << endl;
|
||||
}
|
||||
GetTagIDs(2020);
|
||||
logger_->Debug() << "SnapShot::SnapShot()" << (int)DCR::ihd::read_conn().state
|
||||
<< ",thid:" << DCR::ihd::read_conn().tid << endl;
|
||||
}
|
||||
SnapShot::~SnapShot() {
|
||||
DCR::ihd::disconnect_maybe(DCR::ihd::read_conn());
|
||||
for (auto& it : m_mapfix) {
|
||||
if (it.second != nullptr) {
|
||||
delete it.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
bool SnapShot::is_connected() {
|
||||
logger_->Debug() << "SnapShot::is_connected()"
|
||||
<< (int)DCR::ihd::read_conn().state
|
||||
<< ",thid:" << DCR::ihd::read_conn().tid << endl;
|
||||
return (int)DCR::ihd::read_conn().state;
|
||||
}
|
||||
|
||||
bool SnapShot::to_connect() {
|
||||
if (DCR::ihd::Connection::State::disconnected ==
|
||||
DCR::ihd::read_conn().state) {
|
||||
DCR::ihd::auto_connect();
|
||||
}
|
||||
return (int)DCR::ihd::read_conn().state;
|
||||
}
|
||||
bool SnapShot::GetTagIDs(int eventNo) {
|
||||
if (mv_tagids_.find(eventNo) == mv_tagids_.end()) {
|
||||
logger_->Debug() << "SnapShot::GetTagIDs---1" << std::endl;
|
||||
binary_tele.ReBuild(eventNo);
|
||||
logger_->Debug() << "SnapShot::GetTagIDs---2" << std::endl;
|
||||
int size = binary_tele.size();
|
||||
logger_->Debug() << "binary_tele size:" << size << std::endl;
|
||||
mv_tagids_[eventNo].nTagNum = size;
|
||||
std::vector<std::string> items;
|
||||
for (int i = 0; i < size; i++) {
|
||||
// sprintf(mv_tagids_[eventNo].szTagNames[i], "%s_%s",
|
||||
// msz_unit_no,binary_tele[i].item);
|
||||
strcpy(mv_tagids_[eventNo].szTagNames[i], binary_tele[i].item);
|
||||
}
|
||||
int nRet = tag3_query_ids_by_names(
|
||||
mv_tagids_[eventNo].nTagNum, mv_tagids_[eventNo].szTagNames,
|
||||
mv_tagids_[eventNo].tagID, mv_tagids_[eventNo].nErrCodes);
|
||||
if (nRet == RD_SUCCESS) {
|
||||
// for (int j = 0; j < size; j++) {
|
||||
// logger_->Debug() << "eventNo:" << eventNo
|
||||
// << ",item:" << mv_tagids_[eventNo].szTagNames[j]
|
||||
// << ",tagid:" << mv_tagids_[eventNo].tagID[j]
|
||||
// << std::endl;
|
||||
// }
|
||||
return true;
|
||||
} else {
|
||||
for (int j = 0; j < size; j++) {
|
||||
if (mv_tagids_[eventNo].nErrCodes[j] = !RD_SUCCESS) {
|
||||
logger_->Error() << "eventNo:" << eventNo
|
||||
<< ",item:" << mv_tagids_[eventNo].szTagNames[j]
|
||||
<< ",tagid:" << mv_tagids_[eventNo].tagID[j]
|
||||
<< ",ErrCode:" << mv_tagids_[eventNo].nErrCodes[j]
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
logger_->Error() << "SnapShot::GetTagIDs failure!---ErrCode:" << nRet
|
||||
<< std::endl;
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mv_tagids_[eventNo].nTagNum == 0) {
|
||||
logger_->Debug() << "SnapShot::GetTagIDs()---- No data item!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SnapShot::update_data(int eventNo) {
|
||||
if (m_mapfix.find(eventNo) == m_mapfix.end()) {
|
||||
m_mapfix.insert(make_pair(
|
||||
eventNo,
|
||||
new CMemFix<PLC_DATA>(std::to_string(eventNo), TEL_CACHE_SIZE)));
|
||||
}
|
||||
if (GetTagIDs(eventNo)) {
|
||||
int nRet = sn3_query_snapshots(
|
||||
mv_tagids_[eventNo].nTagNum, mv_tagids_[eventNo].tagID,
|
||||
mv_tagids_[eventNo].pRec, mv_tagids_[eventNo].nErrCodes);
|
||||
if (nRet == RD_SUCCESS) {
|
||||
binary_tele.ReBuild(eventNo);
|
||||
for (int j = 0; j < mv_tagids_[eventNo].nTagNum; j++) {
|
||||
if (mv_tagids_[eventNo].nErrCodes[j] == RD_SUCCESS) {
|
||||
binary_tele[j] = (float)mv_tagids_[eventNo].pRec[j].NumberValue();
|
||||
logger_->Debug() << "eventNo:" << eventNo
|
||||
<< ",item:" << mv_tagids_[eventNo].szTagNames[j]
|
||||
<< ",tagid:" << mv_tagids_[eventNo].tagID[j]
|
||||
<< ",value:"
|
||||
<< mv_tagids_[eventNo].pRec[j].NumberValue()
|
||||
<< ",time:"
|
||||
<< mix_cc::mix_time_t(
|
||||
HD3Time(mv_tagids_[eventNo].pRec[j].nSec,
|
||||
mv_tagids_[eventNo].pRec[j].nMsec))
|
||||
.to_formatted_time("%Y-%m-%d %H:%M:%S:%M")
|
||||
<< std::endl;
|
||||
} else {
|
||||
logger_->Error() << "eventNo:" << eventNo
|
||||
<< ",item:" << mv_tagids_[eventNo].szTagNames[j]
|
||||
<< ",tagid:" << mv_tagids_[eventNo].tagID[j]
|
||||
<< ",ErrCode:" << mv_tagids_[eventNo].nErrCodes[j]
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int j = 0; j < mv_tagids_[eventNo].nTagNum; j++) {
|
||||
if (mv_tagids_[eventNo].nErrCodes[j] != RD_SUCCESS) {
|
||||
logger_->Error() << "eventNo:" << eventNo
|
||||
<< ",item:" << mv_tagids_[eventNo].szTagNames[j]
|
||||
<< ",tagid:" << mv_tagids_[eventNo].tagID[j]
|
||||
<< ",ErrCode:" << mv_tagids_[eventNo].nErrCodes[j]
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
char* buff = binary_tele.GetTeleData();
|
||||
m_mapfix[eventNo]->push((PLC_DATA*)buff);
|
||||
}
|
||||
}
|
||||
43
TestProject/DCR/Snapshot.h
Normal file
43
TestProject/DCR/Snapshot.h
Normal file
@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
#include <TestProject/DCR/cache/TagIdCache.h>
|
||||
#include <TestProject/DCR/ihdb_header.h>
|
||||
#include <glob/BinaryTele.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <zlib/MemVar.h>
|
||||
#include <zlib/zoneDef.h>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <zlib/MemFix.hpp>
|
||||
const int IHD_SIZE_MAX = 10000;
|
||||
const int TAGNAME_MAXLEN = 256;
|
||||
// char tagNames[IHD_SIZE_MAX][TAGNAME_MAXLEN];
|
||||
|
||||
struct IHD_TAGID {
|
||||
int32 nTagNum = 0;
|
||||
char szTagNames[IHD_SIZE_MAX][TAGNAME_MAXLEN];
|
||||
HD3_TAG_TYPE tagTypes[IHD_SIZE_MAX];
|
||||
uint32 tagID[IHD_SIZE_MAX];
|
||||
int32 nErrCodes[IHD_SIZE_MAX];
|
||||
HD3Record pRec[IHD_SIZE_MAX];
|
||||
};
|
||||
|
||||
class SnapShot {
|
||||
public:
|
||||
SnapShot();
|
||||
~SnapShot();
|
||||
bool is_connected();
|
||||
|
||||
bool to_connect();
|
||||
|
||||
bool GetTagIDs(int eventNo);
|
||||
|
||||
void update_data(int eventNo);
|
||||
|
||||
private:
|
||||
std::unique_ptr<LOG> logger_; ///< 本地logger
|
||||
// BinaryTele binary_tele{2020, "T_LOV_FDAAITEM"};
|
||||
BinaryTele binary_tele{CMemVar::Const()->event_eis_start, "T_LOV_FDAAITEM"};
|
||||
std::map<int, IHD_TAGID> mv_tagids_;
|
||||
map<int, CMemFix<PLC_DATA>*> m_mapfix;
|
||||
};
|
||||
19
TestProject/DCR/cache/TagIdCache.h
vendored
Normal file
19
TestProject/DCR/cache/TagIdCache.h
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
// #pragma once
|
||||
// #include <TestProject/DCR/ihdb_header.h>
|
||||
// #include <map>
|
||||
// namespace {
|
||||
|
||||
// const int IHD_SIZE_MAX = 10000;
|
||||
// const int TAGNAME_MAXLEN = 256;
|
||||
// char tagNames[IHD_SIZE_MAX][TAGNAME_MAXLEN];
|
||||
// struct IHD_TAGID {
|
||||
// int32 nTagNum;
|
||||
// char szTagNames[IHD_SIZE_MAX][TAGNAME_MAXLEN];
|
||||
// HD3_TAG_TYPE tagTypes[IHD_SIZE_MAX];
|
||||
// uint32 tagID[IHD_SIZE_MAX];
|
||||
// int32 nErrCodes[IHD_SIZE_MAX];
|
||||
// };
|
||||
|
||||
|
||||
// } // namespace
|
||||
111
TestProject/DCR/connection/connection.cc
Normal file
111
TestProject/DCR/connection/connection.cc
Normal file
@ -0,0 +1,111 @@
|
||||
#include <TestProject/DCR/connection/connection.h>
|
||||
#include <TestProject/DCR/connection/read_config.h>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace DCR {
|
||||
|
||||
namespace ihd {
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace {
|
||||
thread_local Connection local_conn;
|
||||
}
|
||||
auto read_conn_config_maybe() -> maybe<Connection::Config> {
|
||||
return fp::lift_maybe(
|
||||
[](nlohmann::json config_json) {
|
||||
Connection::Config conn_config;
|
||||
// 如果配置信息不为空,则根据配置信息初始化连接配置
|
||||
snprintf(conn_config.hd3_conn.szAddress,
|
||||
sizeof(conn_config.hd3_conn.szAddress), "%s",
|
||||
config_json.at("ip_address").get<std::string>().c_str());
|
||||
conn_config.hd3_conn.nPort = config_json.at("port").get<int64_t>();
|
||||
conn_config.hd3_conn.nTimeout =
|
||||
config_json.at("time_out").get<int64_t>();
|
||||
conn_config.username = config_json.at("username").get<std::string>();
|
||||
conn_config.password = config_json.at("password").get<std::string>();
|
||||
return conn_config;
|
||||
},
|
||||
read_config_maybe("utility", "ihyper_db"));
|
||||
}
|
||||
|
||||
auto init_conn_maybe(maybe<Connection::Config>&& conn_config_maybe)
|
||||
-> maybe<Connection> {
|
||||
// connect to ihyperDB
|
||||
return fwd::apply(
|
||||
conn_config_maybe, fwd::lift_maybe([](Connection::Config conn_config) {
|
||||
nt3_connect(&conn_config.hd3_conn);
|
||||
return conn_config;
|
||||
}),
|
||||
fwd::lift_maybe([](Connection::Config conn_config) {
|
||||
auto ret_code = sc3_login(conn_config.username.c_str(),
|
||||
conn_config.password.c_str());
|
||||
if (ret_code != RD_SUCCESS) {
|
||||
return Connection{.state = Connection::State::disconnected,
|
||||
.tid = std::this_thread::get_id()};
|
||||
}
|
||||
return Connection{.state = Connection::State::connected,
|
||||
.tid = std::this_thread::get_id()};
|
||||
}));
|
||||
}
|
||||
|
||||
auto disconnect_maybe(maybe<Connection> conn_maybe) -> maybe<Connection> {
|
||||
return fp::lift_maybe(
|
||||
[](Connection conn) {
|
||||
if (conn.state == Connection::State::connected) {
|
||||
auto ret_code = nt3_disconnect();
|
||||
if (ret_code == RD_SUCCESS) {
|
||||
conn.state = Connection::State::disconnected;
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
return conn;
|
||||
},
|
||||
conn_maybe);
|
||||
}
|
||||
|
||||
auto connect_maybe(maybe<Connection> conn_maybe) -> maybe<Connection> {
|
||||
return fp::lift_maybe(
|
||||
[](Connection conn) {
|
||||
if (conn.state == Connection::State::disconnected) {
|
||||
auto ret_code = nt3_connect(&conn.config.hd3_conn);
|
||||
if (ret_code == RD_SUCCESS) {
|
||||
ret_code = sc3_login(conn.config.username.c_str(),
|
||||
conn.config.password.c_str());
|
||||
if (ret_code == RD_SUCCESS) {
|
||||
conn.state = Connection::State::connected;
|
||||
}
|
||||
}
|
||||
}
|
||||
return conn;
|
||||
},
|
||||
conn_maybe);
|
||||
}
|
||||
|
||||
auto read_conn_state() -> Connection::State { return local_conn.state; }
|
||||
|
||||
auto read_conn() -> Connection { return local_conn; }
|
||||
|
||||
auto store_conn_to_local(Connection& conn) -> Connection {
|
||||
local_conn = conn;
|
||||
return local_conn;
|
||||
}
|
||||
|
||||
auto auto_connect() -> maybe<Connection> {
|
||||
if (read_conn_state() == Connection::State::disconnected) {
|
||||
auto conn_maybe = init_conn_maybe(read_conn_config_maybe());
|
||||
return fp::lift_maybe(
|
||||
[](Connection conn) {
|
||||
store_conn_to_local(conn);
|
||||
return store_conn_to_local(conn);
|
||||
},
|
||||
conn_maybe);
|
||||
}
|
||||
return read_conn();
|
||||
}
|
||||
|
||||
} // namespace ihd
|
||||
} // namespace DCR
|
||||
53
TestProject/DCR/connection/connection.h
Normal file
53
TestProject/DCR/connection/connection.h
Normal file
@ -0,0 +1,53 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <TestProject/DCR/fp.h>
|
||||
#include <TestProject/DCR/ihdb_header.h>
|
||||
#include <stdint.h>
|
||||
#include <atomic>
|
||||
#include <future>
|
||||
#include <mutex>
|
||||
#include <numeric>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
namespace DCR {
|
||||
|
||||
namespace ihd {
|
||||
/**
|
||||
* @brief IhyperDB的连接
|
||||
*/
|
||||
struct Connection {
|
||||
// 由于iHyperDB的设计独特,一个进程只使用一个iHyperDB连接
|
||||
// 且ihyperDB的连接一经建立,即使断开网络连接,也不会自动释放,故不再对其使用手动释放
|
||||
struct Config {
|
||||
// 基本信息
|
||||
std::string username;
|
||||
std::string password;
|
||||
HD3Connection hd3_conn;
|
||||
};
|
||||
enum class State { disconnected, connected };
|
||||
Config config;
|
||||
State state;
|
||||
std::thread::id tid;
|
||||
};
|
||||
|
||||
auto read_conn_config_maybe() -> maybe<Connection::Config>;
|
||||
|
||||
auto init_conn_maybe(maybe<Connection::Config>&& conn_config_maybe)
|
||||
-> maybe<Connection>;
|
||||
|
||||
auto disconnect_maybe(maybe<Connection> conn_maybe) -> maybe<Connection>;
|
||||
|
||||
auto connect_maybe(maybe<Connection> conn_maybe) -> maybe<Connection>;
|
||||
|
||||
auto read_conn_state() -> Connection::State;
|
||||
|
||||
auto read_conn() -> Connection;
|
||||
|
||||
auto store_conn_to_local(Connection& conn) -> Connection;
|
||||
|
||||
auto auto_connect() -> maybe<Connection>; ///<对外实际使用
|
||||
|
||||
} // namespace ihd
|
||||
} // namespace DCR
|
||||
20
TestProject/DCR/connection/read_config.cc
Normal file
20
TestProject/DCR/connection/read_config.cc
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
#include <TestProject/DCR/connection/read_config.h>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <sstream>
|
||||
#define CONFIG_FILE_PATH "/users/dsc/code/config/config.json"
|
||||
namespace DCR {
|
||||
maybe<json> read_config_maybe(std::string&& category, std::string&& entry) {
|
||||
try {
|
||||
auto data = fp::read_text_file(CONFIG_FILE_PATH)();
|
||||
return json::parse(data).at(category).at(entry);
|
||||
} catch (std::exception& e) {
|
||||
return {};
|
||||
} catch (...) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
} // namespace DCR
|
||||
18
TestProject/DCR/connection/read_config.h
Normal file
18
TestProject/DCR/connection/read_config.h
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
#pragma once
|
||||
#include <TestProject/DCR/fp.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <string>
|
||||
namespace DCR {
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
/**
|
||||
* @brief Get the config object
|
||||
* @param category 配置的类别
|
||||
* @param entry 配置对应的类别的入口
|
||||
* @return json
|
||||
*/
|
||||
maybe<json> read_config_maybe(std::string&& category, std::string&& entry);
|
||||
|
||||
} // namespace DCR
|
||||
26
TestProject/DCR/find.h
Normal file
26
TestProject/DCR/find.h
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include <TestProject/DCR/fplus_define.h>
|
||||
#include <type_traits>
|
||||
namespace DCR {
|
||||
namespace fp {
|
||||
/**
|
||||
* @brief find element in container by maybe
|
||||
* @tparam Container
|
||||
* @tparam T
|
||||
* @param container
|
||||
* @param element
|
||||
* @return maybe<typename Container::iterator>
|
||||
*/
|
||||
template <typename Container, typename T>
|
||||
auto find(const Container& container, const T& element)
|
||||
-> maybe<typename Container::const_iterator> {
|
||||
// equals end, means there is NO element in container
|
||||
auto iter = container.find(element);
|
||||
if (iter == container.end()) {
|
||||
return {};
|
||||
}
|
||||
return iter;
|
||||
}
|
||||
} // namespace fp
|
||||
|
||||
} // namespace DCR
|
||||
3
TestProject/DCR/fp.h
Normal file
3
TestProject/DCR/fp.h
Normal file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
#include <TestProject/DCR/find.h>
|
||||
#include <TestProject/DCR/fplus_define.h>
|
||||
18
TestProject/DCR/fplus_define.h
Normal file
18
TestProject/DCR/fplus_define.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <fplus/fplus.hpp>
|
||||
|
||||
namespace DCR {
|
||||
namespace fp
|
||||
{
|
||||
using namespace fplus;
|
||||
}
|
||||
|
||||
namespace fwd
|
||||
{
|
||||
using namespace fp::fwd;
|
||||
}
|
||||
|
||||
using fp::maybe;
|
||||
using fp::result;
|
||||
|
||||
} // namespace DCR
|
||||
6
TestProject/DCR/ihdb_header.h
Normal file
6
TestProject/DCR/ihdb_header.h
Normal file
@ -0,0 +1,6 @@
|
||||
#include "ihdb_inc/error_code.h"
|
||||
#include "ihdb_inc/data_types.h"
|
||||
#include "ihdb_inc/hd3Enum.h"
|
||||
#include "ihdb_inc/hd3MaskDefine.h"
|
||||
#include "ihdb_inc/hd3Struct.h"
|
||||
#include "ihdb_inc/hdKingAPI.h"
|
||||
97
TestProject/DCR/ihdb_inc/IhyperDBcommon.hh
Normal file
97
TestProject/DCR/ihdb_inc/IhyperDBcommon.hh
Normal file
@ -0,0 +1,97 @@
|
||||
/*--------------------------------------------------------------------------------
|
||||
* 2017/9/30 14:21:51
|
||||
*--------------------------------------------------------------------------------
|
||||
* PLANT :
|
||||
* MODULE :
|
||||
*
|
||||
* SHORT DESCRIPTION : iHyperDBÉúÃ÷Îļþ
|
||||
* FILE : IhyperDBTransform.h
|
||||
* AUTHOR : AUTO GENERATION
|
||||
*--------------------------------------------------------------------------------
|
||||
* Copyright (c) rmbai@baosight.com 2012
|
||||
*--------------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _H_IHYPERDB_COMMON_H_
|
||||
#define _H_IHYPERDB_COMMON_H_
|
||||
|
||||
#ifdef _WIN32
|
||||
//#include <Winsock2.h>
|
||||
#else
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#include <common/L2Event.h>
|
||||
#include <common/typedefL1.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <utility/IniProperty.h>
|
||||
#include <zhd/data_types.h>
|
||||
#include <zhd/error_code.h>
|
||||
#include <zhd/hd3Enum.h>
|
||||
#include <zhd/hd3Struct.h>
|
||||
//#include <zhd/ihyperdb.h>
|
||||
|
||||
using namespace log4cplus;
|
||||
using namespace baosight;
|
||||
|
||||
#define TAGNAME_MAXLEN 256
|
||||
|
||||
namespace ihdcommon {
|
||||
|
||||
inline int getNowDurationSecFromGreen() {
|
||||
time_t startTimeL, ti1970;
|
||||
time(&startTimeL);
|
||||
ti1970 = time(NULL);
|
||||
int sec = startTimeL;
|
||||
// printf("NowDurationSecFromGreen:%d\n", sec);
|
||||
return sec;
|
||||
}
|
||||
|
||||
inline int getNowMSec() {
|
||||
struct timeb tb;
|
||||
ftime(&tb);
|
||||
int msec = tb.millitm;
|
||||
// printf("NowMSec:%d\n", msec);
|
||||
return msec;
|
||||
}
|
||||
|
||||
inline void IHDValue(HD3Record snapshotsSaved[], int index, bool value) {
|
||||
// LOG d("IHDValue");
|
||||
// d.Debug() << "Index:" << index << " Value:" << value << endl;
|
||||
snapshotsSaved[index].nTagType = HD3_TAG_TYPE_INT8;
|
||||
snapshotsSaved[index].value.nInt8 = value;
|
||||
snapshotsSaved[index].nSec = getNowDurationSecFromGreen();
|
||||
snapshotsSaved[index].nMsec = getNowMSec();
|
||||
snapshotsSaved[index].nQuality = 192;
|
||||
}
|
||||
|
||||
inline void IHDValue(HD3Record snapshotsSaved[], int index, int value) {
|
||||
snapshotsSaved[index].nTagType = HD3_TAG_TYPE_INT32;
|
||||
snapshotsSaved[index].value.nInt32 = value;
|
||||
snapshotsSaved[index].nSec = getNowDurationSecFromGreen();
|
||||
snapshotsSaved[index].nMsec = getNowMSec();
|
||||
snapshotsSaved[index].nQuality = 192;
|
||||
}
|
||||
|
||||
inline void IHDValue(HD3Record snapshotsSaved[], int index, float value) {
|
||||
snapshotsSaved[index].nTagType = HD3_TAG_TYPE_FLOAT32;
|
||||
snapshotsSaved[index].value.fFloat32 = value;
|
||||
snapshotsSaved[index].nSec = getNowDurationSecFromGreen();
|
||||
snapshotsSaved[index].nMsec = getNowMSec();
|
||||
snapshotsSaved[index].nQuality = 192;
|
||||
}
|
||||
|
||||
inline void IHDValue(HD3Record snapshotsSaved[], int index, const char *value,
|
||||
int length) {
|
||||
snapshotsSaved[index].nTagType = HD3_TAG_TYPE_STRING;
|
||||
snapshotsSaved[index].value.strBlob.pBuf = new char[length + 1];
|
||||
strcpy(snapshotsSaved[index].value.strBlob.pBuf, value);
|
||||
snapshotsSaved[index].value.strBlob.nLenBuf = length + 1;
|
||||
snapshotsSaved[index].nSec = getNowDurationSecFromGreen();
|
||||
snapshotsSaved[index].nMsec = getNowMSec();
|
||||
snapshotsSaved[index].nQuality = 192;
|
||||
}
|
||||
|
||||
}; // namespace ihdcommon
|
||||
#endif
|
||||
138
TestProject/DCR/ihdb_inc/data_types.h
Normal file
138
TestProject/DCR/ihdb_inc/data_types.h
Normal file
@ -0,0 +1,138 @@
|
||||
/**
|
||||
* @file
|
||||
* @brief Data type definition for different platforms
|
||||
* @author Chunfeng Shen
|
||||
* @date 2009/03/15
|
||||
* @version Initial Version
|
||||
*
|
||||
* Define basic data types on different platforms. e.g., uint64 means unsigned
|
||||
* int occupying 64 bits
|
||||
*/
|
||||
#ifndef DATA_TYPE_H
|
||||
#define DATA_TYPE_H
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
/* boolean type and constant variable */
|
||||
#ifndef __cplusplus
|
||||
typedef signed char bool;
|
||||
#define true 1
|
||||
#define false 0
|
||||
#endif
|
||||
|
||||
#define SIZEOF_CHAR 1
|
||||
|
||||
// number of bytes in a short
|
||||
#if (USHRT_MAX) == 255U
|
||||
# define SIZEOF_SHORT 1
|
||||
#elif (USHRT_MAX) == 65535U
|
||||
# define SIZEOF_SHORT 2
|
||||
#elif (USHRT_MAX) == 4294967295U
|
||||
# define SIZEOF_SHORT 4
|
||||
#elif (USHRT_MAX) == 18446744073709551615U
|
||||
# define SIZEOF_SHORT 8
|
||||
#else
|
||||
# error: unsupported short size, must be updated for this platform!
|
||||
#endif
|
||||
|
||||
// number of bytes in an int
|
||||
#if (UINT_MAX) == 65535U
|
||||
# define SIZEOF_INT 2
|
||||
#elif (UINT_MAX) == 4294967295U
|
||||
# define SIZEOF_INT 4
|
||||
#elif (UINT_MAX) == 18446744073709551615U
|
||||
# define SIZEOF_INT 8
|
||||
#else
|
||||
# error: unsupported int size, must be updated for this platform!
|
||||
#endif
|
||||
|
||||
// number of bytes in a long
|
||||
#if (ULONG_MAX) == 65535UL
|
||||
# define SIZEOF_LONG 2
|
||||
#elif ((ULONG_MAX) == 4294967295UL)
|
||||
# define SIZEOF_LONG 4
|
||||
#elif ((ULONG_MAX) == 18446744073709551615UL)
|
||||
# define SIZEOF_LONG 8
|
||||
#else
|
||||
# error: unsupported long size, must be updated for this platform!
|
||||
#endif
|
||||
|
||||
#if _MSC_VER <= 1200 //ULL can not be supported by vc6.0
|
||||
#else
|
||||
#if defined (ULLONG_MAX)
|
||||
# if ((ULLONG_MAX) == 4294967295ULL)
|
||||
# define SIZEOF_LONG_LONG 4
|
||||
# elif ((ULLONG_MAX) == 18446744073709551615ULL)
|
||||
# define SIZEOF_LONG_LONG 8
|
||||
# endif
|
||||
#elif defined (ULONGLONG_MAX)
|
||||
# if ((ULONGLONG_MAX) == 4294967295ULL)
|
||||
# define SIZEOF_LONG_LONG 4
|
||||
# elif ((ULONGLONG_MAX) == 18446744073709551615ULL)
|
||||
# define SIZEOF_LONG_LONG 8
|
||||
# endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifndef AIX
|
||||
typedef char int8;
|
||||
#endif
|
||||
typedef unsigned char uint8;
|
||||
|
||||
#if SIZEOF_SHORT == 2
|
||||
typedef short int16;
|
||||
#elif SIZEOF_INT == 2
|
||||
typedef int int16;
|
||||
#endif
|
||||
|
||||
#if SIZEOF_SHORT == 2
|
||||
typedef unsigned short uint16;
|
||||
#elif SIZEOF_INT == 2
|
||||
typedef unsigned int uint16;
|
||||
#endif
|
||||
|
||||
#if SIZEOF_INT == 4
|
||||
typedef int int32;
|
||||
#elif SIZEOF_LONG == 4
|
||||
typedef long int32;
|
||||
#endif
|
||||
|
||||
#if SIZEOF_INT == 4
|
||||
typedef unsigned int uint32;
|
||||
#elif SIZEOF_LONG == 4
|
||||
typedef unsigned long uint32;
|
||||
#endif
|
||||
|
||||
#if defined (__MINGW32__)
|
||||
typedef signed long long int64;
|
||||
#elif SIZEOF_LONG == 8
|
||||
typedef long int64;
|
||||
#elif SIZEOF_LONG_LONG == 8
|
||||
typedef signed long long int64;
|
||||
#elif defined WIN32
|
||||
typedef signed __int64 int64;
|
||||
#else
|
||||
typedef signed long long int64;
|
||||
#endif
|
||||
|
||||
#if defined (__MINGW32__)
|
||||
typedef unsigned long long uint64;
|
||||
#elif SIZEOF_LONG == 8
|
||||
typedef unsigned long uint64;
|
||||
#elif SIZEOF_LONG_LONG == 8
|
||||
typedef unsigned long long uint64;
|
||||
#elif defined WIN32
|
||||
typedef unsigned __int64 uint64;
|
||||
#else
|
||||
typedef unsigned long long uint64;
|
||||
#endif
|
||||
|
||||
//#define float32 float
|
||||
//#define float64 double
|
||||
|
||||
typedef double float64;
|
||||
typedef float float32;
|
||||
|
||||
#endif // DATA_TYPE_H
|
||||
1758
TestProject/DCR/ihdb_inc/error_code.h
Normal file
1758
TestProject/DCR/ihdb_inc/error_code.h
Normal file
File diff suppressed because it is too large
Load Diff
900
TestProject/DCR/ihdb_inc/hd3Enum.h
Normal file
900
TestProject/DCR/ihdb_inc/hd3Enum.h
Normal file
@ -0,0 +1,900 @@
|
||||
/**
|
||||
* @file hd3Enum.h
|
||||
* @brief hd3 enum
|
||||
* @author: hd3 tream
|
||||
* @date 03/02/2015
|
||||
* @version initialize version
|
||||
* Copyright: Shanghai Baosight Software Co., Ltd.
|
||||
*/
|
||||
#ifndef HD3_INCLUDE_GUARD_HD3ENUM_H
|
||||
#define HD3_INCLUDE_GUARD_HD3ENUM_H
|
||||
|
||||
/*
|
||||
* most enumerations in ihyperdb.h are transplanted here
|
||||
* MIN in enum is the minimum legal value
|
||||
* MAX in enum is the maximum legal value
|
||||
*/
|
||||
|
||||
#define HD3_A // add
|
||||
#define HD3_D // delete
|
||||
#define HD3_M // modify
|
||||
|
||||
// 接口参数输入输出标识
|
||||
#define hd3_in
|
||||
#define hd3_out
|
||||
#define hd3_inout
|
||||
|
||||
// 长度限制
|
||||
enum {
|
||||
HD3_PAGE_SIZE = 4096,
|
||||
HD3_LEN_IP = 16,
|
||||
HD3_LEN_MAC = 32,
|
||||
HD3_LEN_ADDRESS = 256,
|
||||
HD3_LEN_TAG_NAME = 128,
|
||||
HD3_LEN_TAG_DESC = 1024,
|
||||
HD3_LEN_USER_NAME = 32,
|
||||
HD3_LEN_USER_DESC = 64,
|
||||
HD3_LEN_PASSWORD = 64,
|
||||
HD3_LEN_TRUST_NAME = 64,
|
||||
HD3_LEN_AUTH_NAME = 32,
|
||||
HD3_LEN_AUTH_DESC = 64,
|
||||
HD3_LEN_GROUP_NAME = 32,
|
||||
HD3_LEN_GROUP_DESC = 64,
|
||||
HD3_LEN_ENG_UNITS = 32,
|
||||
HD3_LEN_INSTRUMENT_ADDRESS = 256,
|
||||
HD3_LEN_INTERFACE_NAME = 64,
|
||||
HD3_LEN_DIGITAL_SET_NAME = 32,
|
||||
HD3_LEN_DIGITAL_SET_STATE_NAME = 32,
|
||||
HD3_LEN_EXT_STRING = 512,
|
||||
// 报警相关
|
||||
HD3_LEN_ALARM_TEST = 128,
|
||||
HD3_LEN_ALARM_ACTION = 128,
|
||||
HD3_LEN_ALARM_GROUP_NAME = 128,
|
||||
HD3_LEN_ALARM_GROUP_DESC = 128,
|
||||
HD3_LEN_ALARM_COMMENT = 256,
|
||||
// 查询项
|
||||
HD3_LEN_QUERY_ITEM_VALUE = 128,
|
||||
// 采集器相关
|
||||
HD3_LEN_COLLECTOR_NAME = 64,
|
||||
HD3_LEN_COLLECTOR_DESC = 128,
|
||||
HD3_LEN_COLLECTOR_EXT_PARAM = 512,
|
||||
// 设备相关
|
||||
HD3_LEN_DEVICE_NAME = 64,
|
||||
HD3_LEN_DEVICE_DESC = 128,
|
||||
HD3_LEN_DEVICE_ADDRESS = 32,
|
||||
HD3_LEN_DEVICE_EXT_PARAM = 512,
|
||||
// 扫描组相关
|
||||
HD3_LEN_SCANGROUP_NAME = 64,
|
||||
HD3_LEN_SCANGROUP_DESC = 128,
|
||||
HD3_LEN_SCANGROUP_EXT_PARAM = 512,
|
||||
// 过滤表达式
|
||||
HD3_LEN_FILTER_EXPR = 128,
|
||||
// 计算表达式
|
||||
HD3_LEN_CALC_EXPR = 256,
|
||||
// iHyperDB数据源名称
|
||||
HD3_LEN_HD_SRV_NAME = 64,
|
||||
// 源值长度
|
||||
HD3_LEN_VAR_TYPE_VALUE = 1000,
|
||||
// OEM
|
||||
HD3_LEN_LICENSE_OEM_VCODE = 4,
|
||||
// server node
|
||||
HD3_LEN_NODE_NAME = 32,
|
||||
HD3_LEN_NODE_DESC = 64,
|
||||
//hd version
|
||||
HD3_LEN_HD_VERSION = 128
|
||||
};
|
||||
|
||||
// 个数以及值限制
|
||||
enum {
|
||||
HD3_DIGITALSET_STATE_MAX_NUM = 256,
|
||||
HD3_DIGITALSET_STATE_VAL_MIN = -128,
|
||||
HD3_DIGITALSET_STATE_VAL_MAX = 127,
|
||||
HD3_API_TAG_NUM_MAX = 65535,
|
||||
HD3_API_CLIENT_MAX_SOCKET_NUM = 100, // 单台机器上API最多SOCKET个数
|
||||
HD3_API_BATCH_ADD_MAX_TAG_NUM = 1000 // 批量接口每次添加的最大点数
|
||||
};
|
||||
|
||||
// Tag属性列
|
||||
enum HD3_COMM_PROP_ENUM { // 基本的Tag属性
|
||||
HD3_COMM_PROP_MIN = 0,
|
||||
HD3_COMM_PROP_TAG_NAME = HD3_COMM_PROP_MIN,
|
||||
HD3_COMM_PROP_ARCHIVING,
|
||||
HD3_COMM_PROP_CHANGE_DATE,
|
||||
HD3_COMM_PROP_CHANGER,
|
||||
HD3_COMM_PROP_COMP_DEV,
|
||||
HD3_COMM_PROP_COMP_MAX_TIME,
|
||||
HD3_COMM_PROP_COMP_TYPE,
|
||||
HD3_COMM_PROP_CREATION_DATE,
|
||||
HD3_COMM_PROP_CREATOR,
|
||||
HD3_COMM_PROP_REC_ACCESS,
|
||||
HD3_COMM_PROP_REC_NORMAL_GROUP,
|
||||
HD3_COMM_PROP_REC_OWNER_GROUP,
|
||||
HD3_COMM_PROP_DESCRIPTOR,
|
||||
HD3_COMM_PROP_DIGITAL_SET,
|
||||
HD3_COMM_PROP_ENG_UNITS,
|
||||
HD3_COMM_PROP_EXC_MAX_TIME,
|
||||
HD3_COMM_PROP_EXC_DEV,
|
||||
HD3_COMM_PROP_TAGID,
|
||||
HD3_COMM_PROP_TAG_TYPE,
|
||||
HD3_COMM_PROP_TAG_ACCESS,
|
||||
HD3_COMM_PROP_TAG_NORMAL_GROUP,
|
||||
HD3_COMM_PROP_TAG_OWNER_GROUP,
|
||||
HD3_COMM_PROP_SCAN,
|
||||
HD3_COMM_PROP_SPAN,
|
||||
HD3_COMM_PROP_MIN_VALUE,
|
||||
HD3_COMM_PROP_TAG_CLASS,
|
||||
HD3_COMM_PROP_TAG_AVALIABLE,
|
||||
HD3_COMM_PROP_PARAM1,
|
||||
HD3_COMM_PROP_PARAM2,
|
||||
HD3_COMM_PROP_PARAM3,
|
||||
HD3_COMM_PROP_PARAM4,
|
||||
HD3_COMM_PROP_PARAM5,
|
||||
HD3_COMM_PROP_OPC_STATE,
|
||||
HD3_COMM_PROP_IMV_STRING,
|
||||
HD3_COMM_PROP_EXT_STRING1,
|
||||
HD3_COMM_PROP_EXT_STRING2,
|
||||
HD3_COMM_PROP_MAX = HD3_COMM_PROP_EXT_STRING2
|
||||
};
|
||||
|
||||
enum HD3_PT_EXT_PROP_ENUM { // 普通点特有的属性
|
||||
HD3_PT_EXT_PROP_MIN = 0,
|
||||
HD3_PT_EXT_PROP_INSTRUMENT_ADDRESS = HD3_PT_EXT_PROP_MIN,
|
||||
HD3_PT_EXT_PROP_INSTRUMENT_ADDRESS_TYPE,
|
||||
HD3_PT_EXT_PROP_COLLECTOR_NAME,
|
||||
HD3_PT_EXT_PROP_COLLECTOR_ID,
|
||||
HD3_PT_EXT_PROP_DEVICE_NAME,
|
||||
HD3_PT_EXT_PROP_DEVICE_ID,
|
||||
HD3_PT_EXT_PROP_SCAN_GROUP_NAME,
|
||||
HD3_PT_EXT_PROP_SCAN_GROUP_ID,
|
||||
HD3_PT_EXT_PROP_DATA_ORDER,
|
||||
HD3_PT_EXT_PROP_MAX = HD3_PT_EXT_PROP_DATA_ORDER
|
||||
};
|
||||
|
||||
enum HD3_AM_EXT_PROP_ENUM { // 报警点特有的属性
|
||||
HD3_AM_EXT_PROP_MIN = 0,
|
||||
HD3_AM_EXT_PROP_TEST1 = HD3_AM_EXT_PROP_MIN,
|
||||
HD3_AM_EXT_PROP_TEST2,
|
||||
HD3_AM_EXT_PROP_TEST3,
|
||||
HD3_AM_EXT_PROP_TEST4,
|
||||
HD3_AM_EXT_PROP_ACTION1,
|
||||
HD3_AM_EXT_PROP_ACTION2,
|
||||
HD3_AM_EXT_PROP_ACTION3,
|
||||
HD3_AM_EXT_PROP_ACTION4,
|
||||
HD3_AM_EXT_PROP_SOURCE_TAG,
|
||||
HD3_AM_EXT_PROP_ALARM_GROUP_ID,
|
||||
HD3_AM_EXT_PROP_AUTOACK,
|
||||
HD3_AM_EXT_PROP_TIME_DEADBAND,
|
||||
HD3_AM_EXT_PROP_VALUE_DEADBAND,
|
||||
HD3_AM_EXT_PROP_MAX = HD3_AM_EXT_PROP_VALUE_DEADBAND
|
||||
};
|
||||
|
||||
enum HD3_ST_EXT_PROP_ENUM { // 统计点特有的属性
|
||||
HD3_ST_EXT_PROP_MIN = 0,
|
||||
HD3_ST_EXT_PROP_SOURCE_TAG_NAME = HD3_ST_EXT_PROP_MIN,
|
||||
HD3_ST_EXT_PROP_STATS_TYPE,
|
||||
HD3_ST_EXT_PROP_SAMPLE_START_DATE,
|
||||
HD3_ST_EXT_PROP_SAMPLE_MODE,
|
||||
HD3_ST_EXT_PROP_SAMPLE_INTERVAL,
|
||||
HD3_ST_EXT_PROP_SAMPLE_BEGIN_OFFSET,
|
||||
HD3_ST_EXT_PROP_SAMPLE_END_OFFSET,
|
||||
HD3_ST_EXT_PROP_SAMPLE_MONTH_BEGIN_DAY,
|
||||
HD3_ST_EXT_PROP_SAMPLE_MONTH_END_DAY,
|
||||
HD3_ST_EXT_PROP_BEGIN_TIMESTAMP,
|
||||
HD3_ST_EXT_PROP_TIMESTAMP_OFFSET,
|
||||
HD3_ST_EXT_PROP_SCAN_PERIOD,
|
||||
HD3_ST_EXT_PROP_PCT_GOOD,
|
||||
HD3_ST_EXT_PROP_FILTER_EXPR,
|
||||
HD3_ST_EXT_PROP_DROP_BAD_MODE,
|
||||
HD3_ST_EXT_PROP_COUNT_PARAM1,
|
||||
HD3_ST_EXT_PROP_COUNT_PARAM2,
|
||||
HD3_ST_EXT_PROP_SAMPLE_TYPE,
|
||||
HD3_ST_EXT_PROP_INTERP_OFFSET,
|
||||
HD3_ST_EXT_PROP_INTERP_PERIOD,
|
||||
HD3_ST_EXT_PROP_CONVER_TYPE,
|
||||
HD3_ST_EXT_PROP_CONVERSION,
|
||||
HD3_ST_EXT_PROP_FILTER_FAIL_MODE,
|
||||
HD3_ST_EXT_PROP_CALC_PERIOD,
|
||||
HD3_ST_EXT_PROP_RESET,
|
||||
HD3_ST_EXT_PROP_USE_BAD_VALUE,
|
||||
HD3_ST_EXT_PROP_MAX = HD3_ST_EXT_PROP_USE_BAD_VALUE
|
||||
};
|
||||
|
||||
enum HD3_CA_EXT_PROP_ENUM { // 计算点特有的属性
|
||||
HD3_CA_EXT_PROP_MIN = 0,
|
||||
HD3_CA_EXT_PROP_CALC_MODE = HD3_CA_EXT_PROP_MIN,
|
||||
HD3_CA_EXT_PROP_CALC_PERIOD,
|
||||
HD3_CA_EXT_PROP_CALC_EXPR,
|
||||
HD3_CA_EXT_PROP_CALC_HISTORY,
|
||||
HD3_CA_EXT_PROP_CALC_START_DATE,
|
||||
HD3_CA_EXT_PROP_CALC_END_DATE,
|
||||
HD3_CA_EXT_PROP_HAVE_END_TIME,
|
||||
HD3_CA_EXT_PROP_SOURCE_TAG,
|
||||
HD3_CA_EXT_PROP_MAX = HD3_CA_EXT_PROP_SOURCE_TAG
|
||||
};
|
||||
|
||||
enum HD3_SPC_EXT_PROP_ENUM { // SPC报警点特有的属性
|
||||
HD3_SPC_EXT_PROP_MIN = 0,
|
||||
HD3_SPC_EXT_PROP_SOURCE_TAG_NAME = HD3_SPC_EXT_PROP_MIN,
|
||||
HD3_SPC_EXT_PROP_ALARM_GROUP_ID,
|
||||
HD3_SPC_EXT_PROP_CTRL_CHART_TYPE,
|
||||
HD3_SPC_EXT_PROP_TRIGGER_MODE,
|
||||
HD3_SPC_EXT_PROP_SAMPLE_SIZE,
|
||||
HD3_SPC_EXT_PROP_SAMPLE_INTERVAL,
|
||||
HD3_SPC_EXT_PROP_AUTO_ACK,
|
||||
HD3_SPC_EXT_PROP_RULE,
|
||||
HD3_SPC_EXT_PROP_MAX = HD3_SPC_EXT_PROP_RULE
|
||||
};
|
||||
|
||||
// 字符编码格式
|
||||
enum HD3_CHARSET {
|
||||
HD3_SYS, // 系统默认字符集
|
||||
HD3_ANSI, // ANSI 字符集,包含GB2312,GBK,GB18030
|
||||
HD3_UNICODE // Unicode字符集
|
||||
};
|
||||
|
||||
// 网络连接状态
|
||||
enum HD3_NET_STATUS {
|
||||
HD3_NET_GOOD = 0, // net(connect) good
|
||||
HD3_NET_BAD
|
||||
};
|
||||
|
||||
// 许可证状态
|
||||
enum HD3_LICENSE {
|
||||
HD3_LICENSE_INVALID = 0, // 许可证无效,一般是2小时试用版过期
|
||||
HD3_LICENSE_VALID, // 有效许可证
|
||||
HD3_LICENSE_VALID_TEMP // 临时许可证,2小时试用版
|
||||
};
|
||||
|
||||
// 数据质量
|
||||
enum HD3_QUALITY {
|
||||
HD3_QUALITY_GOOD = 0xC0, // 一个典型的Good值, 192
|
||||
HD3_QUALITY_BAD = 0xFF3F, // 质量为Bad
|
||||
//统计记录用这个值来表示统计区域没有一条Good的原始记录,质量为bad
|
||||
HD3_QUALITY_BAD_STATS_NO_GOOD_REC = 0xFF3E,
|
||||
// 表达式过滤
|
||||
HD3_QUALITY_EXPR_FILTER = 65527,
|
||||
// 设备状态点质量
|
||||
HD3_QUALITY_DEVICE_MIN = 65528,
|
||||
HD3_QUALITY_DEVICE_DISCONN = 65528,
|
||||
HD3_QUALITY_DEVICE_CONN = 65529,
|
||||
HD3_QUALITY_DEVICE_MAX = 65529,
|
||||
// 采集器状态点质量
|
||||
HD3_QUALITY_CT_MIN = 65530,
|
||||
HD3_QUALITY_CT_TIMEOUT = 65530,
|
||||
HD3_QUALITY_CT_SHUTDOWN = 65531,
|
||||
HD3_QUALITY_CT_ACTIVE = 65532,
|
||||
HD3_QUALITY_CT_BOOTING = 65533,
|
||||
HD3_QUALITY_CT_MAX = 65533,
|
||||
// 无法连接设备
|
||||
HD3_QUALITY_IO_TIMEOUT = 65534,
|
||||
// 停机记录
|
||||
HD3_QUALITY_IO_HALT = 65535
|
||||
};
|
||||
|
||||
// Tag点类型
|
||||
enum HD3_TAG_TYPE {
|
||||
HD3_TAG_TYPE_MIN = 0,
|
||||
HD3_TAG_TYPE_INT8 = HD3_TAG_TYPE_MIN,
|
||||
HD3_TAG_TYPE_INT16,
|
||||
HD3_TAG_TYPE_INT32,
|
||||
HD3_TAG_TYPE_FLOAT32,
|
||||
HD3_TAG_TYPE_FLOAT64,
|
||||
HD3_TAG_TYPE_DIGITAL,
|
||||
HD3_TAG_TYPE_STRING,
|
||||
HD3_TAG_TYPE_BLOB,
|
||||
HD3_TAG_TYPE_MAX = HD3_TAG_TYPE_BLOB
|
||||
};
|
||||
|
||||
// Tag点类别
|
||||
enum HD3_TAG_CLASS {
|
||||
HD3_TAG_CLASS_MIN = 0,
|
||||
HD3_TAG_CLASS_BASIC = HD3_TAG_CLASS_MIN,
|
||||
HD3_TAG_CLASS_ALARM,
|
||||
HD3_TAG_CLASS_STATS,
|
||||
HD3_TAG_CLASS_CALC,
|
||||
HD3_TAG_CLASS_SPC,
|
||||
HD3_TAG_CLASS_SYS,
|
||||
HD3_TAG_CLASS_MAX = HD3_TAG_CLASS_SYS
|
||||
};
|
||||
|
||||
// Tag是否可用
|
||||
enum HD3_TAG_AVALIABLE {
|
||||
HD3_TAG_AVALIABLE_MIN = 0,
|
||||
HD3_TAG_AVALIABLE_NO = HD3_TAG_AVALIABLE_MIN,
|
||||
HD3_TAG_AVALIABLE_YES,
|
||||
HD3_TAG_AVALIABLE_MAX = HD3_TAG_AVALIABLE_YES
|
||||
};
|
||||
|
||||
// 扫描类型
|
||||
enum HD3_SCAN_TYPE {
|
||||
HD3_SCAN_TYPE_MIN = 0,
|
||||
HD3_SCAN_TYPE_POOL = HD3_SCAN_TYPE_MIN, // 轮询模式
|
||||
HD3_SCAN_TYPE_ADVISE, // 通知模式
|
||||
HD3_SCAN_TYPE_MAX = HD3_SCAN_TYPE_ADVISE
|
||||
};
|
||||
|
||||
// 压缩类型
|
||||
enum HD3_COMP_TYPE {
|
||||
HD3_COMP_TYPE_MIN = 0,
|
||||
HD3_COMP_TYPE_NO = HD3_COMP_TYPE_MIN,
|
||||
HD3_COMP_TYPE_SDT,
|
||||
HD3_COMP_TYPE_MAX = HD3_COMP_TYPE_SDT
|
||||
};
|
||||
|
||||
// 报警变更类型
|
||||
enum HD3_AM_CHANGE {
|
||||
HD3_AM_CHANGE_MIN = 0,
|
||||
HD3_AM_CHANGE_NEW = HD3_AM_CHANGE_MIN,
|
||||
HD3_AM_CHANGE_ACK,
|
||||
HD3_AM_CHANGE_RESTORE,
|
||||
HD3_AM_CHANGE_COMMENT,
|
||||
HD3_AM_CHANGE_MAX = HD3_AM_CHANGE_COMMENT
|
||||
};
|
||||
|
||||
// 报警确认方式
|
||||
enum HD3_AM_ACK_TYPE {
|
||||
HD3_AM_ACK_TYPE_MIN = 0,
|
||||
HD3_AM_ACK_TYPE_MANUAL = HD3_AM_ACK_TYPE_MIN,
|
||||
HD3_AM_ACK_TYPE_AUTO,
|
||||
HD3_AM_ACK_TYPE_MAX = HD3_AM_ACK_TYPE_AUTO
|
||||
};
|
||||
|
||||
// 监视点类型
|
||||
enum HD3_MONITOR_TYPE {
|
||||
HD3_MONITOR_TYPE_MIN = 0,
|
||||
HD3_MONITOR_TYPE_ALARM = HD3_MONITOR_TYPE_MIN,
|
||||
HD3_MONITOR_TYPE_MAX = HD3_MONITOR_TYPE_ALARM
|
||||
};
|
||||
|
||||
// 报警查询索引
|
||||
enum HD3_AM_REC_QUERY {
|
||||
HD3_AM_REC_QUERY_MIN = 0,
|
||||
HD3_AM_REC_QUERY_PRIORITY = HD3_AM_REC_QUERY_MIN, // 优先级
|
||||
HD3_AM_REC_QUERY_ACK, // 确认状态
|
||||
HD3_AM_REC_QUERY_ALARM_TYPE, // 报警类型
|
||||
HD3_AM_REC_QUERY_NORMAL, // 是否查询正常的报警记录
|
||||
HD3_AM_REC_QUERY_MAX = HD3_AM_REC_QUERY_NORMAL
|
||||
};
|
||||
|
||||
// 报警确认类型
|
||||
enum HD3_AM__REC_ACK_TYPE {
|
||||
HD3_AM__REC_ACK_TYPE_MIN = 1,
|
||||
HD3_AM__REC_ACK_TYPE_MANUAL = HD3_AM__REC_ACK_TYPE_MIN,
|
||||
HD3_AM__REC_ACK_TYPE_AUTO,
|
||||
HD3_AM__REC_ACK_TYPE_MAX = HD3_AM__REC_ACK_TYPE_AUTO
|
||||
};
|
||||
|
||||
// 报警确认状态
|
||||
enum HD3_AM_REC_ACK_STATE {
|
||||
HD3_AM_REC_ACK_STATE_MIN = 0,
|
||||
HD3_AM_REC_ACK_STATE_NO = HD3_AM_REC_ACK_STATE_MIN,
|
||||
HD3_AM_REC_ACK_STATE_YES,
|
||||
HD3_AM_REC_ACK_STATE_MAX = HD3_AM_REC_ACK_STATE_YES
|
||||
};
|
||||
|
||||
// 报警恢复状态
|
||||
enum HD3_AM_REC_RESTORE_STATE {
|
||||
HD3_AM_REC_RESTORE_STATE_MIN = 0,
|
||||
HD3_AM_REC_RESTORE_STATE_NO = HD3_AM_REC_RESTORE_STATE_MIN,
|
||||
HD3_AM_REC_RESTORE_STATE_YES,
|
||||
HD3_AM_REC_RESTORE_STATE_MAX = HD3_AM_REC_RESTORE_STATE_YES
|
||||
};
|
||||
|
||||
// 报警记录的优先级
|
||||
enum HD3_AM_REC_PRIORITY {
|
||||
HD3_AM_REC_PRIORITY_MIN = 1,
|
||||
HD3_AM_REC_PRIORITY_FIRST = HD3_AM_REC_PRIORITY_MIN,
|
||||
HD3_AM_REC_PRIORITY_SECOND,
|
||||
HD3_AM_REC_PRIORITY_THIRD,
|
||||
HD3_AM_REC_PRIORITY_FORTH,
|
||||
HD3_AM_REC_PRIORITY_MAX = HD3_AM_REC_PRIORITY_FORTH
|
||||
};
|
||||
|
||||
// 报警类型
|
||||
enum HD3_AM_REC_TYPE {
|
||||
HD3_AM_REC_TYPE_MIN = 1,
|
||||
HD3_AM_REC_TYPE_LOLO = HD3_AM_REC_TYPE_MIN,
|
||||
HD3_AM_REC_TYPE_LOW,
|
||||
HD3_AM_REC_TYPE_HIHI,
|
||||
HD3_AM_REC_TYPE_HIGH,
|
||||
HD3_AM_REC_TYPE_CHANGE,
|
||||
HD3_AM_REC_TYPE_MAX = HD3_AM_REC_TYPE_CHANGE
|
||||
};
|
||||
|
||||
// 报警属性索引
|
||||
enum HD3_AM_REC_INDEX {
|
||||
HD3_AM_REC_INDEX_MIN = 0,
|
||||
HD3_AM_REC_INDEX_ALARM_TAG_ID = HD3_AM_REC_INDEX_MIN,
|
||||
HD3_AM_REC_INDEX_START_TIME,
|
||||
HD3_AM_REC_INDEX_END_TIME,
|
||||
HD3_AM_REC_INDEX_ACK_TIME,
|
||||
HD3_AM_REC_INDEX_COMMENT_TIME,
|
||||
HD3_AM_REC_INDEX_ACKED,
|
||||
HD3_AM_REC_INDEX_RESTORED,
|
||||
HD3_AM_REC_INDEX_PRIORITY,
|
||||
HD3_AM_REC_INDEX_ACK_TYPE,
|
||||
HD3_AM_REC_INDEX_ALARM_TYPE,
|
||||
HD3_AM_REC_INDEX_SRC_VALUE,
|
||||
HD3_AM_REC_INDEX_TEST,
|
||||
HD3_AM_REC_INDEX_COMMENT,
|
||||
HD3_AM_REC_INDEX_ACKER,
|
||||
HD3_AM_REC_INDEX_COMMENTOR,
|
||||
HD3_AM_REC_INDEX_MAX = HD3_AM_REC_INDEX_COMMENTOR
|
||||
};
|
||||
|
||||
// 数据查询,查询项
|
||||
enum HD3_PT_REC_QUERY {
|
||||
HD3_PT_REC_QUERY_MIN = 0,
|
||||
HD3_PT_REC_QUERY_QUALITY = HD3_PT_REC_QUERY_MIN,
|
||||
HD3_PT_REC_QUERY_VALUE,
|
||||
HD3_PT_REC_QUERY_MAX = HD3_PT_REC_QUERY_VALUE
|
||||
};
|
||||
|
||||
// 键值关系
|
||||
enum HD3_RELATION {
|
||||
HD3_RELATION_MIN = 0,
|
||||
HD3_RELATION_EQUAL = HD3_RELATION_MIN,
|
||||
HD3_RELATION_NON_EQUAL,
|
||||
HD3_RELATION_GREAT,
|
||||
HD3_RELATION_LESS,
|
||||
HD3_RELATION_GREAT_EQUAL,
|
||||
HD3_RELATION_LESS_EQUAL,
|
||||
HD3_RELATION_LIKE,
|
||||
HD3_RELATION_MAX = HD3_RELATION_LIKE
|
||||
};
|
||||
|
||||
// Driver types
|
||||
enum HD3_DRIVER_TYPE {
|
||||
HD3_DRIVER_TYPE_MIN = 1,
|
||||
HD3_DRIVER_TYPE_OPC = HD3_DRIVER_TYPE_MIN,
|
||||
HD3_DRIVER_TYPE_TCPMODBUS,
|
||||
HD3_DRIVER_TYPE_MAX = HD3_DRIVER_TYPE_TCPMODBUS
|
||||
};
|
||||
|
||||
// 统计类型
|
||||
enum HD3_STATS_TYPE {
|
||||
HD3_STATS_TYPE_LIMIT_MIN = 0,
|
||||
HD3_STATS_TYPE_MAX = HD3_STATS_TYPE_LIMIT_MIN, //最大值
|
||||
HD3_STATS_TYPE_MIN, // 最小值
|
||||
HD3_STATS_TYPE_SUM, // 求和
|
||||
HD3_STATS_TYPE_LAST, // 最新值
|
||||
HD3_STATS_TYPE_PCT_GOOD, // 可信度
|
||||
HD3_STATS_TYPE_ARITH_MEAN, // 算术平均值
|
||||
HD3_STATS_TYPE_TIME_WEIGHTED_MEAN, // 时间加权平均值
|
||||
HD3_STATS_TYPE_INTEGRAL, // 积分
|
||||
HD3_STATS_TYPE_COUNT_CHG_VALUE, // 值变化
|
||||
HD3_STATS_TYPE_COUNT_CHG_FROM_LESS_TO_GREAT, // 区间变化,从<=到>=
|
||||
HD3_STATS_TYPE_COUNT_CHG_FROM_GREAT_TO_LESS, // 区间变化,从>=到<=
|
||||
HD3_STATS_TYPE_DIFF, // 差值统计
|
||||
HD3_STATS_TYPE_COUNT_IN_RANGE, // 值在区间
|
||||
HD3_STATS_TYPE_COUNT_NOT_IN_RANGE, // 值不在区间
|
||||
HD3_STATS_TYPE_RANGE, // 极差
|
||||
HD3_STATS_TYPE_STANDARD_DEVIATION, // 标准差
|
||||
HD3_STATS_TYPE_TIME_GT, // 大于某个值的时间
|
||||
HD3_STATS_TYPE_TIME_GE, // 大于等于某个值的时间
|
||||
HD3_STATS_TYPE_TIME_EQ, // 等于某个值的时间
|
||||
HD3_STATS_TYPE_TIME_NE, // 不等于某个值的时间
|
||||
HD3_STATS_TYPE_TIME_LT, // 小于某个值的时间
|
||||
HD3_STATS_TYPE_TIME_LE, // 小于等于某个值的时间
|
||||
HD3_STATS_TYPE_TIME_IN_RANGE, // 在某个值区间的时间
|
||||
HD3_STATS_TYPE_TIME_NOT_IN_RANGE, // 不在某个值区间的时间
|
||||
HD3_STATS_TYPE_LIMIT_MAX = HD3_STATS_TYPE_TIME_NOT_IN_RANGE // 统计类型值的最大值, 做校验用
|
||||
};
|
||||
|
||||
// 统计点采样模式/统计方式
|
||||
enum HD3_STATS_SAMPLE_MODE {
|
||||
HD3_STATS_SAMPLE_MODE_MIN = 0,
|
||||
HD3_STATS_SAMPLE_MODE_INTERVAL = HD3_STATS_SAMPLE_MODE_MIN, // 统计等间隔采样
|
||||
HD3_STATS_SAMPLE_MODE_EVERY_DAY, // 统计每天同时段采样
|
||||
HD3_STATS_SAMPLE_MODE_EVERY_MONTH, // 统计每月同时段采样
|
||||
HD3_STATS_SAMPLE_MODE_TIME_MOVING, // 时间移动采样
|
||||
HD3_STATS_SAMPLE_MODE_FOREVER, // 时间移动采样
|
||||
HD3_STATS_SAMPLE_MODE_MAX = HD3_STATS_SAMPLE_MODE_FOREVER
|
||||
};
|
||||
|
||||
//统计转换类型
|
||||
enum HD3_STATS_CONVERSION_TYPE {
|
||||
HD3_STATS_CONVERSION_TYPE_MIN = 0,
|
||||
HD3_STATS_CONVERSION_TYPE_AMPLIFICATION = HD3_STATS_CONVERSION_TYPE_MIN, // 统计值放大
|
||||
HD3_STATS_CONVERSION_TYPE_MINIFICATION, // 统计值缩小
|
||||
HD3_STATS_CONVERSION_TYPE_MAX = HD3_STATS_CONVERSION_TYPE_MINIFICATION // 最大值,做校验
|
||||
};
|
||||
|
||||
//统计点采样方式
|
||||
enum HD3_STATS_SAMPLE_TYPE {
|
||||
HD3_STATS_SAMPLE_TYPE_MIN = 0,
|
||||
HD3_STATS_SAMPLE_TYPE_RAW = HD3_STATS_SAMPLE_TYPE_MIN, // 采样点都是原始值
|
||||
HD3_STATS_SAMPLE_TYPE_LINER_INTERP, // 采样点都是线性插值
|
||||
HD3_STATS_SAMPLE_TYPE_PREV_INTERP, // 采样点都是前向插值
|
||||
HD3_STATS_SAMPLE_TYPE_MAX = HD3_STATS_SAMPLE_TYPE_PREV_INTERP // 最大采样类型值
|
||||
};
|
||||
|
||||
//统计点弃坏点模式
|
||||
enum HD3_STATS_DROP_BAD_MODE {
|
||||
HD3_STATS_DROP_BAD_MODE_MIN = 0,
|
||||
HD3_STATS_DROP_BAD_MODE_REC = HD3_STATS_DROP_BAD_MODE_MIN, // 弃坏点模式——弃bad记录
|
||||
HD3_STATS_DROP_BAD_MODE_AREA, // 弃坏点模式——弃bad记录相邻的区域
|
||||
HD3_STATS_DROP_BAD_MODE_MAX = HD3_STATS_DROP_BAD_MODE_AREA
|
||||
};
|
||||
|
||||
// 求均值模式
|
||||
enum HD3_STATS_WEIGHT_MODE {
|
||||
HD3_STATS_WEIGHT_MODE_MIN = 1,
|
||||
HD3_STATS_WEIGHT_MODE_TIMED = HD3_STATS_WEIGHT_MODE_MIN, // 以时间为权值
|
||||
HD3_STATS_WEIGHT_MODE_RECORD, // 无权值
|
||||
HD3_STATS_WEIGHT_MODE_MAX = HD3_STATS_WEIGHT_MODE_RECORD
|
||||
};
|
||||
|
||||
// count计算模式,值变化模式和区间变化模式
|
||||
enum HD3_STATS_COUNT_MODE {
|
||||
HD3_STATS_COUNT_MODE_MIN = 1,
|
||||
HD3_STATS_COUNT_MODE_CHANGE_VALUE = HD3_STATS_COUNT_MODE_MIN,
|
||||
HD3_STATS_COUNT_MODE_GREATER_CHANGE_TO_LESS,
|
||||
HD3_STATS_COUNT_MODE_LESS_CHANGE_TO_GREATE,
|
||||
HD3_STATS_COUNT_MODE_IN_RANGE,
|
||||
HD3_STATS_COUNT_MODE_NOT_IN_RANGE,
|
||||
HD3_STATS_COUNT_MODE_MAX = HD3_STATS_COUNT_MODE_NOT_IN_RANGE
|
||||
};
|
||||
|
||||
// 过滤表达式计算失败是否需过滤
|
||||
enum HD3_STATS_FILTER_FAIL_MODE {
|
||||
HD3_STATS_FILTER_FAIL_MODE_MIN = 0,
|
||||
HD3_STATS_FILTER_FAIL_MODE_FIL = HD3_STATS_FILTER_FAIL_MODE_MIN, // filter
|
||||
HD3_STATS_FILTER_FAIL_MODE_NO_FIL,
|
||||
HD3_STATS_FILTER_FAIL_MODE_MAX = HD3_STATS_FILTER_FAIL_MODE_NO_FIL
|
||||
};
|
||||
|
||||
// 计算点模式
|
||||
enum HD3_CALC_MODE {
|
||||
HD3_CALC_MODE_MIN = 0,
|
||||
HD3_CALC_MODE_POLL = HD3_CALC_MODE_MIN, // 计算模式——轮询
|
||||
HD3_CALC_MODE_NOTIFY, // 计算模式——通知
|
||||
HD3_CALC_MODE_MAX = HD3_CALC_MODE_NOTIFY // 计算模式的最大值,用来校验
|
||||
};
|
||||
|
||||
// 采集器类型
|
||||
enum HD3_COLLECTOR_TYPE {
|
||||
HD3_COLLECTOR_TYPE_MIN = -1,
|
||||
HD3_COLLECTOR_TYPE_INVALID = HD3_COLLECTOR_TYPE_MIN,
|
||||
HD3_COLLECTOR_TYPE_OPC,
|
||||
HD3_COLLECTOR_TYPE_MODBUS,
|
||||
HD3_COLLECTOR_TYPE_RDB,
|
||||
HD3_COLLECTOR_TYPE_HD2HD,
|
||||
HD3_COLLECTOR_TYPE_MAX = HD3_COLLECTOR_TYPE_HD2HD
|
||||
};
|
||||
|
||||
// 记录的插值查询模式
|
||||
enum HD3_REC_INTERP_QUERY_MODE {
|
||||
HD3_REC_INTERP_QUERY_MODE_MIN = 0,
|
||||
HD3_REC_INTERP_QUERY_MODE_LINEAR = HD3_REC_INTERP_QUERY_MODE_MIN, // 线性插值
|
||||
HD3_REC_INTERP_QUERY_MODE_PREV, // 前向插值
|
||||
HD3_REC_INTERP_QUERY_MODE_MAX = HD3_REC_INTERP_QUERY_MODE_PREV // 最大值,用来校验
|
||||
};
|
||||
|
||||
// 数据量状态集
|
||||
enum HD3_DIGITAL_SET {
|
||||
HD3_DIGITAL_SET_MAX_NUM = 256,
|
||||
HD3_DIGITAL_SET_MAX_VAL = 127,
|
||||
HD3_DIGITAL_SET_MIN_VAL = -128
|
||||
};
|
||||
|
||||
// 采集器状态点类型
|
||||
enum HD_CT_STATUS_TAG_TYPE {
|
||||
HD3_CT_STATUS_TAG_TYPE_MIN = 1,
|
||||
HD3_CT_STATUS_TAG_TYPE_COLLECTOR = HD3_CT_STATUS_TAG_TYPE_MIN,
|
||||
HD3_CT_STATUS_TAG_TYPE_DEVICE,
|
||||
HD3_CT_STATUS_TAG_TYPE_MAX = HD3_CT_STATUS_TAG_TYPE_DEVICE
|
||||
};
|
||||
|
||||
// SPC报警控制图类型对应于SPCBasicDef.h中的枚举类型 SPCChartType
|
||||
enum HD3_SPC_CTRL_CHART_TYPE {
|
||||
HD3_SPC_CTRL_CHART_TYPE_MIN = 13,// 控制图类型的最小值,用来做参数校验
|
||||
HD3_SPC_CTRL_CHART_TYPE_XBAR = HD3_SPC_CTRL_CHART_TYPE_MIN, // XBar类型
|
||||
HD3_SPC_CTRL_CHART_TYPE_R, // R图
|
||||
HD3_SPC_CTRL_CHART_TYPE_S, // S图
|
||||
HD3_SPC_CTRL_CHART_TYPE_MAX = HD3_SPC_CTRL_CHART_TYPE_S // 控制图类型的最大值,用来做参数校验
|
||||
};
|
||||
|
||||
// SPC报警触发模式
|
||||
enum HD3_SPC_TRIGGER_MODE {
|
||||
HD3_SPC_TRIGGER_MODE_MIN = 0,
|
||||
HD3_SPC_TRIGGER_MODE_TRIGGER = HD3_SPC_TRIGGER_MODE_MIN,
|
||||
HD3_SPC_TRIGGER_MODE_MAX = HD3_SPC_TRIGGER_MODE_TRIGGER
|
||||
};
|
||||
|
||||
// SPC报警属性索引
|
||||
enum HD3_SPC_REC_INDEX {
|
||||
HD3_SPC_REC_INDEX_MIN = 0,
|
||||
HD3_SPC_REC_INDEX_SPC_TAG_ID = HD3_SPC_REC_INDEX_MIN,
|
||||
HD3_SPC_REC_INDEX_START_TIME,
|
||||
HD3_SPC_REC_INDEX_END_TIME,
|
||||
HD3_SPC_REC_INDEX_ACK_TIME,
|
||||
HD3_SPC_REC_INDEX_COMMENT_TIME,
|
||||
HD3_SPC_REC_INDEX_ACKED,
|
||||
HD3_SPC_REC_INDEX_ACK_TYPE,
|
||||
HD3_SPC_REC_INDEX_RESTORED,
|
||||
HD3_SPC_REC_INDEX_COMMENTED,
|
||||
HD3_SPC_REC_INDEX_ALARM_VALUE,
|
||||
HD3_SPC_REC_INDEX_RULE,
|
||||
HD3_SPC_REC_INDEX_SRC_VALUE,
|
||||
HD3_SPC_REC_INDEX_COMMENT,
|
||||
HD3_SPC_REC_INDEX_ACKER,
|
||||
HD3_SPC_REC_INDEX_COMMENTOR,
|
||||
HD3_SPC_REC_INDEX_MAX = HD3_SPC_REC_INDEX_COMMENTOR
|
||||
};
|
||||
|
||||
// SPC报警规则M,N值的最大值和最小值
|
||||
enum HD3_SPC_RULE_M_N_VALUE {
|
||||
HD3_SPC_RULE_M_N_VALUE_MIN = 1,
|
||||
HD3_SPC_RULE_M_N_VALUE_MAX = 99
|
||||
};
|
||||
|
||||
// SPC报警值索引
|
||||
enum HD3_SPC_VALUE_RULE_INDEX {
|
||||
HD3_SPC_VALUE_RULE_INDEX_MIN = 0,
|
||||
HD3_SPC_VALUE_RULE_INDEX1 = HD3_SPC_VALUE_RULE_INDEX_MIN,
|
||||
HD3_SPC_VALUE_RULE_INDEX2,
|
||||
HD3_SPC_VALUE_RULE_INDEX3,
|
||||
HD3_SPC_VALUE_RULE_INDEX4,
|
||||
HD3_SPC_VALUE_RULE_INDEX5,
|
||||
HD3_SPC_VALUE_RULE_INDEX6,
|
||||
HD3_SPC_VALUE_RULE_INDEX7,
|
||||
HD3_SPC_VALUE_RULE_INDEX8,
|
||||
HD3_SPC_VALUE_RULE_INDEX_MAX = HD3_SPC_VALUE_RULE_INDEX8
|
||||
};
|
||||
|
||||
// OPC发布状态
|
||||
enum HD3_TAG_OPC_STATE {
|
||||
HD3_TAG_OPC_STATE_MIN =0,
|
||||
HD3_TAG_OPC_STATE_UNRELEASE = HD3_TAG_OPC_STATE_MIN,
|
||||
HD3_TAG_OPC_STATE_RELEASE,
|
||||
HD3_TAG_OPC_STATE_MAX = HD3_TAG_OPC_STATE_RELEASE
|
||||
};
|
||||
|
||||
// 模块类型
|
||||
enum HD3_MODULE_TYPE {
|
||||
HD3_MODULE_TYPE_MIN = 0,
|
||||
HD3_MODULE_TYPE_COLLECTOR = HD3_MODULE_TYPE_MIN,
|
||||
HD3_MODULE_TYPE_CALC,
|
||||
HD3_MODULE_TYPE_MAX = HD3_MODULE_TYPE_CALC
|
||||
};
|
||||
|
||||
// 变更类型
|
||||
enum HD3_ALTERATION_TYPE {
|
||||
HD3_ALTERATION_TYPE_MIN = 0,
|
||||
HD3_ALTERATION_TYPE_ADD = HD3_ALTERATION_TYPE_MIN,
|
||||
HD3_ALTERATION_TYPE_MODIFY,
|
||||
HD3_ALTERATION_TYPE_DELETE,
|
||||
HD3_ALTERATION_TYPE_MAX = HD3_ALTERATION_TYPE_DELETE
|
||||
};
|
||||
|
||||
// 采集器相关变更实体的类别
|
||||
enum HD3_ALTERATION_ENTRY {
|
||||
HD3_ALTERATION_ENTRY_MIN = 0,
|
||||
HD3_ALTERATION_ENTRY_COLLECTOR = HD3_ALTERATION_ENTRY_MIN,
|
||||
HD3_ALTERATION_ENTRY_DEVICE,
|
||||
HD3_ALTERATION_ENTRY_SCANGROUP,
|
||||
HD3_ALTERATION_ENTRY_TAG,
|
||||
HD3_ALTERATION_ENTRY_MAX = HD3_ALTERATION_ENTRY_TAG
|
||||
};
|
||||
|
||||
// 通知对象类型
|
||||
enum HD3_NOTIFY_OBJ_TYPE {
|
||||
HD3_NOTIFY_OBJ_TYPE_MIN = 0,
|
||||
HD3_NOTIFY_OBJ_TYPE_NORMAL_TAG = HD3_NOTIFY_OBJ_TYPE_MIN,
|
||||
HD3_NOTIFY_OBJ_TYPE_ALARM_TAG,
|
||||
HD3_NOTIFY_OBJ_TYPE_STAT_TAG,
|
||||
HD3_NOTIFY_OBJ_TYPE_CALC_TAG,
|
||||
HD3_NOTIFY_OBJ_TYPE_COLLECTOR,
|
||||
HD3_NOTIFY_OBJ_TYPE_SCANGROUP,
|
||||
HD3_NOTIFY_OBJ_TYPE_DEVICE,
|
||||
HD3_NOTIFY_OBJ_TYPE_ALARM_GROUP,
|
||||
HD3_NOTIFY_OBJ_TYPE_DIGITAL_SET,
|
||||
HD3_NOTIFY_OBJ_TYPE_MAX = HD3_NOTIFY_OBJ_TYPE_DIGITAL_SET
|
||||
};
|
||||
|
||||
// 权限项
|
||||
enum HD3_SC_ITEM_TYPE {
|
||||
HD3_SC_ITEM_TYPE_MIN = 1,
|
||||
HD3_SC_ITEM_TYPE_TAG = HD3_SC_ITEM_TYPE_MIN,
|
||||
HD3_SC_ITEM_TYPE_GROUP,
|
||||
HD3_SC_ITEM_TYPE_DISPATCH,
|
||||
HD3_SC_ITEM_TYPE_MAX = HD3_SC_ITEM_TYPE_DISPATCH
|
||||
};
|
||||
|
||||
// 字节序
|
||||
enum HD3_DATA_ORDER {
|
||||
HD3_DATA_ORDER_MIN = 0,
|
||||
HD3_DATA_ORDER_NO = HD3_DATA_ORDER_MIN,
|
||||
HD3_DATA_ORDER_12,
|
||||
HD3_DATA_ORDER_21,
|
||||
HD3_DATA_ORDER_1234,
|
||||
HD3_DATA_ORDER_2143,
|
||||
HD3_DATA_ORDER_3412,
|
||||
HD3_DATA_ORDER_4321,
|
||||
HD3_DATA_ORDER_12345678,
|
||||
HD3_DATA_ORDER_21436587,
|
||||
HD3_DATA_ORDER_34127856,
|
||||
HD3_DATA_ORDER_43218765,
|
||||
HD3_DATA_ORDER_56781234,
|
||||
HD3_DATA_ORDER_65872143,
|
||||
HD3_DATA_ORDER_78563412,
|
||||
HD3_DATA_ORDER_87654321,
|
||||
HD3_ENDIAN_MAX = HD3_DATA_ORDER_87654321
|
||||
};
|
||||
|
||||
enum HD3_MODBUS_CONNECT_TYPE {
|
||||
HD3_MODBUS_CONNECT_TYPE_MIN = 0,
|
||||
HD3_MODBUS_CONNECT_TYPE_TCP = HD3_MODBUS_CONNECT_TYPE_MIN,
|
||||
HD3_MODBUS_CONNECT_TYPE_RTU,
|
||||
HD3_MODBUS_CONNECT_TYPE_SERIAL,
|
||||
HD3_MODBUS_CONNECT_TYPE_MAX = HD3_MODBUS_CONNECT_TYPE_SERIAL
|
||||
};
|
||||
|
||||
// modbus data point type
|
||||
enum HD3_INS_POINT_TYPE {
|
||||
HD3_INS_POINT_TYPE_MIN = 0,
|
||||
HD3_INS_POINT_TYPE_INT8 = HD3_INS_POINT_TYPE_MIN,
|
||||
HD3_INS_POINT_TYPE_UINT8,
|
||||
HD3_INS_POINT_TYPE_INT16,
|
||||
HD3_INS_POINT_TYPE_UINT16,
|
||||
HD3_INS_POINT_TYPE_INT32,
|
||||
HD3_INS_POINT_TYPE_UINT32,
|
||||
HD3_INS_POINT_TYPE_FLOAT,
|
||||
HD3_INS_POINT_TYPE_DOUBLE,
|
||||
HD3_INS_POINT_TYPE_STRING,
|
||||
HD3_INS_POINT_TYPE_BLOB,
|
||||
HD3_INS_POINT_TYPE_DIGITAL,
|
||||
HD3_INS_POINT_TYPE_MAX = HD3_INS_POINT_TYPE_DIGITAL
|
||||
};
|
||||
|
||||
enum HD3_MODBUS_SERIAL_CHECKPARITY {
|
||||
HD3_MODBUS_SERIAL_CHECKPARITY_MIN = 0,
|
||||
HD3_MODBUS_SERIAL_CHECKPARITY_NONE = HD3_MODBUS_SERIAL_CHECKPARITY_MIN,
|
||||
HD3_MODBUS_SERIAL_CHECKPARITY_ODD,
|
||||
HD3_MODBUS_SERIAL_CHECKPARITY_EVEN,
|
||||
HD3_MODBUS_SERIAL_CHECKPARITY_MAX = HD3_MODBUS_SERIAL_CHECKPARITY_EVEN
|
||||
};
|
||||
|
||||
// 其它枚举值
|
||||
enum {
|
||||
HD3_BASE = 2,
|
||||
HD3_CLIENT_SOCKET_MAX = 100 // 单客户端和服务端连接的个数
|
||||
};
|
||||
|
||||
//Tag 列ID
|
||||
enum {
|
||||
HD3_TAG_COL_COMM_PROP_MIN = 0,
|
||||
HD3_TAG_COL_COMM_PROP_TAG_NAME = HD3_TAG_COL_COMM_PROP_MIN,
|
||||
HD3_TAG_COL_COMM_PROP_ARCHIVING,
|
||||
HD3_TAG_COL_COMM_PROP_CHANGE_DATE,
|
||||
HD3_TAG_COL_COMM_PROP_CHANGER,
|
||||
HD3_TAG_COL_COMM_PROP_COMP_DEV,
|
||||
HD3_TAG_COL_COMM_PROP_COMP_MAX_TIME,
|
||||
HD3_TAG_COL_COMM_PROP_COMP_TYPE,
|
||||
HD3_TAG_COL_COMM_PROP_CREATION_DATE,
|
||||
HD3_TAG_COL_COMM_PROP_CREATOR,
|
||||
HD3_TAG_COL_COMM_PROP_REC_ACCESS,
|
||||
HD3_TAG_COL_COMM_PROP_REC_NORMAL_GROUP,
|
||||
HD3_TAG_COL_COMM_PROP_REC_OWNER_GROUP,
|
||||
HD3_TAG_COL_COMM_PROP_DESCRIPTOR,
|
||||
HD3_TAG_COL_COMM_PROP_DIGITAL_SET,
|
||||
HD3_TAG_COL_COMM_PROP_ENG_UNITS,
|
||||
HD3_TAG_COL_COMM_PROP_EXC_MAX_TIME,
|
||||
HD3_TAG_COL_COMM_PROP_EXC_DEV,
|
||||
HD3_TAG_COL_COMM_PROP_TAGID,
|
||||
HD3_TAG_COL_COMM_PROP_TAG_TYPE,
|
||||
HD3_TAG_COL_COMM_PROP_TAG_ACCESS,
|
||||
HD3_TAG_COL_COMM_PROP_TAG_NORMAL_GROUP,
|
||||
HD3_TAG_COL_COMM_PROP_TAG_OWNER_GROUP,
|
||||
HD3_TAG_COL_COMM_PROP_SCAN,
|
||||
HD3_TAG_COL_COMM_PROP_SPAN,
|
||||
HD3_TAG_COL_COMM_PROP_MIN_VALUE,
|
||||
HD3_TAG_COL_COMM_PROP_TAG_CLASS,
|
||||
HD3_TAG_COL_COMM_PROP_TAG_AVALIABLE,
|
||||
HD3_TAG_COL_COMM_PROP_PARAM1,
|
||||
HD3_TAG_COL_COMM_PROP_PARAM2,
|
||||
HD3_TAG_COL_COMM_PROP_PARAM3,
|
||||
HD3_TAG_COL_COMM_PROP_PARAM4,
|
||||
HD3_TAG_COL_COMM_PROP_PARAM5,
|
||||
HD3_TAG_COL_COMM_PROP_OPCREALSE,
|
||||
HD3_TAG_COL_COMM_PROP_IMV_STRING,
|
||||
HD3_TAG_COL_COMM_PROP_EXT_STRING1,
|
||||
HD3_TAG_COL_COMM_PROP_EXT_STRING2,
|
||||
HD3_TAG_COL_COMM_PROP_MAX = HD3_TAG_COL_COMM_PROP_EXT_STRING2,
|
||||
|
||||
HD3_TAG_COL_PT_EXT_PROP_MIN = 100,
|
||||
HD3_TAG_COL_PT_EXT_PROP_INSTRUMENT_ADDRESS = HD3_TAG_COL_PT_EXT_PROP_MIN,
|
||||
HD3_TAG_COL_PT_EXT_PROP_INSTRUMENT_ADDRESS_TYPE,
|
||||
HD3_TAG_COL_PT_EXT_PROP_COLLECTOR_NAME,
|
||||
HD3_TAG_COL_PT_EXT_PROP_COLLECTOR_ID,
|
||||
HD3_TAG_COL_PT_EXT_PROP_DEVICE_NAME,
|
||||
HD3_TAG_COL_PT_EXT_PROP_DEVICE_ID,
|
||||
HD3_TAG_COL_PT_EXT_PROP_SCAN_GROUP_NAME,
|
||||
HD3_TAG_COL_PT_EXT_PROP_SCAN_GROUP_ID,
|
||||
HD3_TAG_COL_PT_EXT_PROP_DATA_ORDER,
|
||||
HD3_TAG_COL_PT_EXT_PROP_MAX = HD3_TAG_COL_PT_EXT_PROP_DATA_ORDER,
|
||||
|
||||
HD3_TAG_COL_AM_EXT_PROP_MIN = 200,
|
||||
HD3_TAG_COL_AM_EXT_PROP_TEST1 = HD3_TAG_COL_AM_EXT_PROP_MIN,
|
||||
HD3_TAG_COL_AM_EXT_PROP_TEST2,
|
||||
HD3_TAG_COL_AM_EXT_PROP_TEST3,
|
||||
HD3_TAG_COL_AM_EXT_PROP_TEST4,
|
||||
HD3_TAG_COL_AM_EXT_PROP_ACTION1,
|
||||
HD3_TAG_COL_AM_EXT_PROP_ACTION2,
|
||||
HD3_TAG_COL_AM_EXT_PROP_ACTION3,
|
||||
HD3_TAG_COL_AM_EXT_PROP_ACTION4,
|
||||
HD3_TAG_COL_AM_EXT_PROP_SOURCE_TAG,
|
||||
HD3_TAG_COL_AM_EXT_PROP_ALARM_GROUP_ID,
|
||||
HD3_TAG_COL_AM_EXT_PROP_AUTOACK,
|
||||
HD3_TAG_COL_AM_EXT_PROP_TIME_DEADBAND,
|
||||
HD3_TAG_COL_AM_EXT_PROP_VALUE_DEADBAND,
|
||||
HD3_TAG_COL_AM_EXT_PROP_MAX = HD3_TAG_COL_AM_EXT_PROP_VALUE_DEADBAND,
|
||||
|
||||
HD3_TAG_COL_SPC_EXT_PROP_MIN = 300,
|
||||
HD3_TAG_COL_SPC_EXT_PROP_SOURCE_TAG_NAME = HD3_TAG_COL_SPC_EXT_PROP_MIN,
|
||||
HD3_TAG_COL_SPC_EXT_PROP_ALARM_GROUP_ID,
|
||||
HD3_TAG_COL_SPC_EXT_PROP_CTRL_CHART_TYPE,
|
||||
HD3_TAG_COL_SPC_EXT_PROP_TRIGGER_MODE,
|
||||
HD3_TAG_COL_SPC_EXT_PROP_SAMPLE_SIZE,
|
||||
HD3_TAG_COL_SPC_EXT_PROP_SAMPLE_INTERVAL,
|
||||
HD3_TAG_COL_SPC_EXT_PROP_AUTO_ACK,
|
||||
HD3_TAG_COL_SPC_EXT_PROP_RULE,
|
||||
HD3_TAG_COL_SPC_EXT_PROP_MAX = HD3_TAG_COL_SPC_EXT_PROP_RULE,
|
||||
|
||||
HD3_TAG_COL_ST_EXT_PROP_MIN = 400,
|
||||
HD3_TAG_COL_ST_EXT_PROP_SOURCE_TAG_NAME = HD3_TAG_COL_ST_EXT_PROP_MIN,
|
||||
HD3_TAG_COL_ST_EXT_PROP_STATS_TYPE,
|
||||
HD3_TAG_COL_ST_EXT_PROP_SAMPLE_START_DATE,
|
||||
HD3_TAG_COL_ST_EXT_PROP_SAMPLE_MODE,
|
||||
HD3_TAG_COL_ST_EXT_PROP_SAMPLE_INTERVAL,
|
||||
HD3_TAG_COL_ST_EXT_PROP_SAMPLE_BEGIN_OFFSET,
|
||||
HD3_TAG_COL_ST_EXT_PROP_SAMPLE_END_OFFSET,
|
||||
HD3_TAG_COL_ST_EXT_PROP_SAMPLE_MONTH_BEGIN_DAY,
|
||||
HD3_TAG_COL_ST_EXT_PROP_SAMPLE_MONTH_END_DAY,
|
||||
HD3_TAG_COL_ST_EXT_PROP_BEGIN_TIMESTAMP,
|
||||
HD3_TAG_COL_ST_EXT_PROP_TIMESTAMP_OFFSET,
|
||||
HD3_TAG_COL_ST_EXT_PROP_SCAN_PERIOD,
|
||||
HD3_TAG_COL_ST_EXT_PROP_PCT_GOOD,
|
||||
HD3_TAG_COL_ST_EXT_PROP_FILTER_EXPR,
|
||||
HD3_TAG_COL_ST_EXT_PROP_DROP_BAD_MODE,
|
||||
HD3_TAG_COL_ST_EXT_PROP_COUNT_PARAM1,
|
||||
HD3_TAG_COL_ST_EXT_PROP_COUNT_PARAM2,
|
||||
HD3_TAG_COL_ST_EXT_PROP_SAMPLE_TYPE,
|
||||
HD3_TAG_COL_ST_EXT_PROP_INTERP_OFFSET,
|
||||
HD3_TAG_COL_ST_EXT_PROP_INTERP_PERIOD,
|
||||
HD3_TAG_COL_ST_EXT_PROP_CONVER_TYPE,
|
||||
HD3_TAG_COL_ST_EXT_PROP_CONVERSION,
|
||||
HD3_TAG_COL_ST_EXT_PROP_FILTER_FAIL_MODE,
|
||||
HD3_TAG_COL_ST_EXT_PROP_CALC_PERIOD,
|
||||
HD3_TAG_COL_ST_EXT_PROP_RESET,
|
||||
HD3_TAG_COL_ST_EXT_PROP_USE_BAD_VALUE,
|
||||
HD3_TAG_COL_ST_EXT_PROP_MAX = HD3_TAG_COL_ST_EXT_PROP_USE_BAD_VALUE,
|
||||
|
||||
HD3_TAG_COL_CA_EXT_PROP_MIN = 500,
|
||||
HD3_TAG_COL_CA_EXT_PROP_CALC_MODE = HD3_TAG_COL_CA_EXT_PROP_MIN,
|
||||
HD3_TAG_COL_CA_EXT_PROP_CALC_PERIOD,
|
||||
HD3_TAG_COL_CA_EXT_PROP_CALC_EXPR,
|
||||
HD3_TAG_COL_CA_EXT_PROP_CALC_HISTORY,
|
||||
HD3_TAG_COL_CA_EXT_PROP_CALC_START_DATE,
|
||||
HD3_TAG_COL_CA_EXT_PROP_CALC_END_DATE,
|
||||
HD3_TAG_COL_CA_EXT_PROP_HAVE_END_TIME,
|
||||
HD3_TAG_COL_CA_EXT_PROP_SRC_TAG_NAME,
|
||||
HD3_TAG_COL_CA_EXT_PROP_MAX = HD3_TAG_COL_CA_EXT_PROP_SRC_TAG_NAME
|
||||
};
|
||||
|
||||
// 冗余状态
|
||||
enum HD3_RY_STATUS{
|
||||
HD3_RY_STATUS_UNACTIVE = 0,
|
||||
HD3_RY_STATUS_ACTIVE = 1
|
||||
};
|
||||
|
||||
// 冗余状态, 内部使用
|
||||
enum HD3_SRV_RY_STATUS{
|
||||
HD3_SRV_RY_STATUS_UNAVILABLE = 0,
|
||||
HD3_SRV_RY_STATUS_HOST = 1,
|
||||
HD3_SRV_RY_STATUS_BACKUP = 2
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
217
TestProject/DCR/ihdb_inc/hd3MaskDefine.h
Normal file
217
TestProject/DCR/ihdb_inc/hd3MaskDefine.h
Normal file
@ -0,0 +1,217 @@
|
||||
/**
|
||||
* @file hd3MaskDefine.h
|
||||
* @brief
|
||||
* @author: hd3 tream
|
||||
* @date 03/09/2015
|
||||
* @version initialize version
|
||||
* Copyright: Shanghai Baosight Software Co. Ltd.
|
||||
*/
|
||||
#ifndef HD3_INCLUDE_GUARD_HD3MASKDEFINE_H
|
||||
#define HD3_INCLUDE_GUARD_HD3MASKDEFINE_H
|
||||
|
||||
#include "data_types.h"
|
||||
#include "hd3Enum.h"
|
||||
|
||||
/*
|
||||
* 掩码宏定义命名规则:
|
||||
* 将对应的枚举项的前缀“HD3”改为“HD3M”即可
|
||||
*/
|
||||
|
||||
#define HD3M_ALL ((int64)0XFFFFFFFFFFFFFFFFLL)
|
||||
// Tag类别掩码
|
||||
|
||||
#define HD3M_TAG_CLASS_BASIC ((int64)1 << HD3_TAG_CLASS_BASIC)
|
||||
#define HD3M_TAG_CLASS_ALARM ((int64)1 << HD3_TAG_CLASS_ALARM)
|
||||
#define HD3M_TAG_CLASS_STATS ((int64)1 << HD3_TAG_CLASS_STATS)
|
||||
#define HD3M_TAG_CLASS_CALC ((int64)1 << HD3_TAG_CLASS_CALC)
|
||||
#define HD3M_TAG_CLASS_SPC ((int64)1 <<HD3_TAG_CLASS_SPC)
|
||||
#define HD3M_TAG_CLASS_SYS ((int64)1 <<HD3_TAG_CLASS_SYS)
|
||||
|
||||
// Tag属性掩码
|
||||
#define HD3M_COMM_PROP_TAG_NAME ((int64)1 << HD3_COMM_PROP_TAG_NAME)
|
||||
#define HD3M_COMM_PROP_ARCHIVING ((int64)1 << HD3_COMM_PROP_ARCHIVING)
|
||||
#define HD3M_COMM_PROP_CHANGE_DATE ((int64)1 << HD3_COMM_PROP_CHANGE_DATE)
|
||||
#define HD3M_COMM_PROP_CHANGER ((int64)1 << HD3_COMM_PROP_CHANGER)
|
||||
#define HD3M_COMM_PROP_COMP_DEV ((int64)1 << HD3_COMM_PROP_COMP_DEV)
|
||||
#define HD3M_COMM_PROP_COMP_MAX_TIME ((int64)1 << HD3_COMM_PROP_COMP_MAX_TIME)
|
||||
#define HD3M_COMM_PROP_COMP_TYPE ((int64)1 << HD3_COMM_PROP_COMP_TYPE)
|
||||
#define HD3M_COMM_PROP_CREATION_DATE ((int64)1 << HD3_COMM_PROP_CREATION_DATE)
|
||||
#define HD3M_COMM_PROP_CREATOR ((int64)1 << HD3_COMM_PROP_CREATOR)
|
||||
#define HD3M_COMM_PROP_REC_ACCESS ((int64)1 << HD3_COMM_PROP_REC_ACCESS)
|
||||
#define HD3M_COMM_PROP_REC_NORMAL_GROUP ((int64)1 << HD3_COMM_PROP_REC_NORMAL_GROUP)
|
||||
#define HD3M_COMM_PROP_REC_OWNER_GROUP ((int64)1 << HD3_COMM_PROP_REC_OWNER_GROUP)
|
||||
#define HD3M_COMM_PROP_DESCRIPTOR ((int64)1 << HD3_COMM_PROP_DESCRIPTOR)
|
||||
#define HD3M_COMM_PROP_DIGITAL_SET ((int64)1 << HD3_COMM_PROP_DIGITAL_SET)
|
||||
#define HD3M_COMM_PROP_ENG_UNITS ((int64)1 << HD3_COMM_PROP_ENG_UNITS)
|
||||
#define HD3M_COMM_PROP_EXC_MAX_TIME ((int64)1 << HD3_COMM_PROP_EXC_MAX_TIME)
|
||||
#define HD3M_COMM_PROP_EXC_DEV ((int64)1 << HD3_COMM_PROP_EXC_DEV)
|
||||
#define HD3M_COMM_PROP_TAGID ((int64)1 << HD3_COMM_PROP_TAGID)
|
||||
#define HD3M_COMM_PROP_TAG_TYPE ((int64)1 << HD3_COMM_PROP_TAG_TYPE)
|
||||
#define HD3M_COMM_PROP_TAG_ACCESS ((int64)1 << HD3_COMM_PROP_TAG_ACCESS)
|
||||
#define HD3M_COMM_PROP_TAG_NORMAL_GROUP ((int64)1 << HD3_COMM_PROP_TAG_NORMAL_GROUP)
|
||||
#define HD3M_COMM_PROP_TAG_OWNER_GROUP ((int64)1 << HD3_COMM_PROP_TAG_OWNER_GROUP)
|
||||
#define HD3M_COMM_PROP_SCAN ((int64)1 << HD3_COMM_PROP_SCAN)
|
||||
#define HD3M_COMM_PROP_SPAN ((int64)1 << HD3_COMM_PROP_SPAN)
|
||||
#define HD3M_COMM_PROP_MIN_VALUE ((int64)1 << HD3_COMM_PROP_MIN_VALUE)
|
||||
#define HD3M_COMM_PROP_TAG_CLASS ((int64)1 << HD3_COMM_PROP_TAG_CLASS)
|
||||
#define HD3M_COMM_PROP_TAG_AVALIABLE ((int64)1 << HD3_COMM_PROP_TAG_AVALIABLE)
|
||||
#define HD3M_COMM_PROP_PARAM1 ((int64)1 << HD3_COMM_PROP_PARAM1)
|
||||
#define HD3M_COMM_PROP_PARAM2 ((int64)1 << HD3_COMM_PROP_PARAM2)
|
||||
#define HD3M_COMM_PROP_PARAM3 ((int64)1 << HD3_COMM_PROP_PARAM3)
|
||||
#define HD3M_COMM_PROP_PARAM4 ((int64)1 << HD3_COMM_PROP_PARAM4)
|
||||
#define HD3M_COMM_PROP_PARAM5 ((int64)1 << HD3_COMM_PROP_PARAM5)
|
||||
#define HD3M_COMM_PROP_OPC_STATE ((int64)1 << HD3_COMM_PROP_OPC_STATE)
|
||||
#define HD3M_COMM_PROP_IMV_STRING ((int64)1 << HD3_COMM_PROP_IMV_STRING)
|
||||
#define HD3M_COMM_PROP_EXT_STRING1 ((int64)1 << HD3_COMM_PROP_EXT_STRING1)
|
||||
#define HD3M_COMM_PROP_EXT_STRING2 ((int64)1 << HD3_COMM_PROP_EXT_STRING2)
|
||||
// 普通点属性掩码
|
||||
#define HD3M_PT_EXT_PROP_INSTRUMENT_ADDRESS ((int64)1 << HD3_PT_EXT_PROP_INSTRUMENT_ADDRESS)
|
||||
#define HD3M_PT_EXT_PROP_INSTRUMENT_ADDRESS_TYPE ((int64)1 << HD3_PT_EXT_PROP_INSTRUMENT_ADDRESS_TYPE)
|
||||
#define HD3M_PT_EXT_PROP_COLLECTOR_NAME ((int64)1 << HD3_PT_EXT_PROP_COLLECTOR_NAME)
|
||||
#define HD3M_PT_EXT_PROP_COLLECTOR_ID ((int64)1 << HD3_PT_EXT_PROP_COLLECTOR_ID)
|
||||
#define HD3M_PT_EXT_PROP_DEVICE_NAME ((int64)1 << HD3_PT_EXT_PROP_DEVICE_NAME)
|
||||
#define HD3M_PT_EXT_PROP_DEVICE_ID ((int64)1 << HD3_PT_EXT_PROP_DEVICE_ID)
|
||||
#define HD3M_PT_EXT_PROP_SCAN_GROUP_NAME ((int64)1 << HD3_PT_EXT_PROP_SCAN_GROUP_NAME)
|
||||
#define HD3M_PT_EXT_PROP_SCAN_GROUP_ID ((int64)1 << HD3_PT_EXT_PROP_SCAN_GROUP_ID)
|
||||
#define HD3M_PT_EXT_PROP_DATA_ORDER ((int64)1 << HD3_PT_EXT_PROP_DATA_ORDER)
|
||||
|
||||
// 报警点属性掩码
|
||||
#define HD3M_AM_EXT_PROP_TEST1 ((int64)1 << HD3_AM_EXT_PROP_TEST1)
|
||||
#define HD3M_AM_EXT_PROP_TEST2 ((int64)1 << HD3_AM_EXT_PROP_TEST2)
|
||||
#define HD3M_AM_EXT_PROP_TEST3 ((int64)1 << HD3_AM_EXT_PROP_TEST3)
|
||||
#define HD3M_AM_EXT_PROP_TEST4 ((int64)1 << HD3_AM_EXT_PROP_TEST4)
|
||||
#define HD3M_AM_EXT_PROP_ACTION1 ((int64)1 << HD3_AM_EXT_PROP_ACTION1)
|
||||
#define HD3M_AM_EXT_PROP_ACTION2 ((int64)1 << HD3_AM_EXT_PROP_ACTION2)
|
||||
#define HD3M_AM_EXT_PROP_ACTION3 ((int64)1 << HD3_AM_EXT_PROP_ACTION3)
|
||||
#define HD3M_AM_EXT_PROP_ACTION4 ((int64)1 << HD3_AM_EXT_PROP_ACTION4)
|
||||
#define HD3M_AM_EXT_PROP_SOURCE_TAG ((int64)1 << HD3_AM_EXT_PROP_SOURCE_TAG)
|
||||
#define HD3M_AM_EXT_PROP_ALARM_GROUP_ID ((int64)1 << HD3_AM_EXT_PROP_ALARM_GROUP_ID)
|
||||
#define HD3M_AM_EXT_PROP_AUTOACK ((int64)1 << HD3_AM_EXT_PROP_AUTOACK)
|
||||
#define HD3M_AM_EXT_PROP_TIME_DEADBAND ((int64)1 << HD3_AM_EXT_PROP_TIME_DEADBAND)
|
||||
#define HD3M_AM_EXT_PROP_VALUE_DEADBAND ((int64)1 << HD3_AM_EXT_PROP_VALUE_DEADBAND)
|
||||
|
||||
// 统计点属性掩码
|
||||
#define HD3M_ST_EXT_PROP_SOURCE_TAG_NAME ((int64)1 << HD3_ST_EXT_PROP_SOURCE_TAG_NAME)
|
||||
#define HD3M_ST_EXT_PROP_STATS_TYPE ((int64)1 << HD3_ST_EXT_PROP_STATS_TYPE)
|
||||
#define HD3M_ST_EXT_PROP_SAMPLE_START_DATE ((int64)1 << HD3_ST_EXT_PROP_SAMPLE_START_DATE)
|
||||
#define HD3M_ST_EXT_PROP_SAMPLE_MODE ((int64)1 << HD3_ST_EXT_PROP_SAMPLE_MODE)
|
||||
#define HD3M_ST_EXT_PROP_SAMPLE_INTERVAL ((int64)1 << HD3_ST_EXT_PROP_SAMPLE_INTERVAL)
|
||||
#define HD3M_ST_EXT_PROP_SAMPLE_BEGIN_OFFSET ((int64)1 << HD3_ST_EXT_PROP_SAMPLE_BEGIN_OFFSET)
|
||||
#define HD3M_ST_EXT_PROP_SAMPLE_END_OFFSET ((int64)1 << HD3_ST_EXT_PROP_SAMPLE_END_OFFSET)
|
||||
#define HD3M_ST_EXT_PROP_SAMPLE_MONTH_BEGIN_DAY ((int64)1 << HD3_ST_EXT_PROP_SAMPLE_MONTH_BEGIN_DAY)
|
||||
#define HD3M_ST_EXT_PROP_SAMPLE_MONTH_END_DAY ((int64)1 << HD3_ST_EXT_PROP_SAMPLE_MONTH_END_DAY)
|
||||
#define HD3M_ST_EXT_PROP_BEGIN_TIMESTAMP ((int64)1 << HD3_ST_EXT_PROP_BEGIN_TIMESTAMP)
|
||||
#define HD3M_ST_EXT_PROP_TIMESTAMP_OFFSET ((int64)1 << HD3_ST_EXT_PROP_TIMESTAMP_OFFSET)
|
||||
#define HD3M_ST_EXT_PROP_SCAN_PERIOD ((int64)1 << HD3_ST_EXT_PROP_SCAN_PERIOD)
|
||||
#define HD3M_ST_EXT_PROP_PCT_GOOD ((int64)1 << HD3_ST_EXT_PROP_PCT_GOOD)
|
||||
#define HD3M_ST_EXT_PROP_FILTER_EXPR ((int64)1 << HD3_ST_EXT_PROP_FILTER_EXPR)
|
||||
#define HD3M_ST_EXT_PROP_DROP_BAD_MODE ((int64)1 << HD3_ST_EXT_PROP_DROP_BAD_MODE)
|
||||
#define HD3M_ST_EXT_PROP_COUNT_PARAM1 ((int64)1 << HD3_ST_EXT_PROP_COUNT_PARAM1)
|
||||
#define HD3M_ST_EXT_PROP_COUNT_PARAM2 ((int64)1 << HD3_ST_EXT_PROP_COUNT_PARAM2)
|
||||
#define HD3M_ST_EXT_PROP_SAMPLE_TYPE ((int64)1 << HD3_ST_EXT_PROP_SAMPLE_TYPE)
|
||||
#define HD3M_ST_EXT_PROP_INTERP_OFFSET ((int64)1 << HD3_ST_EXT_PROP_INTERP_OFFSET)
|
||||
#define HD3M_ST_EXT_PROP_INTERP_PERIOD ((int64)1 << HD3_ST_EXT_PROP_INTERP_PERIOD)
|
||||
#define HD3M_ST_EXT_PROP_CONVER_TYPE ((int64)1 << HD3_ST_EXT_PROP_CONVER_TYPE)
|
||||
#define HD3M_ST_EXT_PROP_CONVERSION ((int64)1 << HD3_ST_EXT_PROP_CONVERSION)
|
||||
#define HD3M_ST_EXT_PROP_FILTER_FAIL_MODE ((int64)1 << HD3_ST_EXT_PROP_FILTER_FAIL_MODE)
|
||||
#define HD3M_ST_EXT_PROP_CALC_PERIOD ((int64)1 << HD3_ST_EXT_PROP_CALC_PERIOD)
|
||||
#define HD3M_ST_EXT_PROP_RESET ((int64)1 << HD3_ST_EXT_PROP_RESET)
|
||||
#define HD3M_ST_EXT_PROP_USE_BAD_VALUE ((int64)1 << HD3_ST_EXT_PROP_USE_BAD_VALUE)
|
||||
|
||||
//计算点属性掩码
|
||||
#define HD3M_CA_EXT_PROP_CALC_MODE ((int64)1 << HD3_CA_EXT_PROP_CALC_MODE)
|
||||
#define HD3M_CA_EXT_PROP_CALC_PERIOD ((int64)1 << HD3_CA_EXT_PROP_CALC_PERIOD)
|
||||
#define HD3M_CA_EXT_PROP_CALC_EXPR ((int64)1 << HD3_CA_EXT_PROP_CALC_EXPR)
|
||||
#define HD3M_CA_EXT_PROP_CALC_HISTORY ((int64)1 << HD3_CA_EXT_PROP_CALC_HISTORY)
|
||||
#define HD3M_CA_EXT_PROP_CALC_START_DATE ((int64)1 << HD3_CA_EXT_PROP_CALC_START_DATE)
|
||||
#define HD3M_CA_EXT_PROP_CALC_END_DATE ((int64)1 << HD3_CA_EXT_PROP_CALC_END_DATE)
|
||||
#define HD3M_CA_EXT_PROP_HAVE_END_TIME ((int64)1 << HD3_CA_EXT_PROP_HAVE_END_TIME)
|
||||
#define HD3M_CA_EXT_PROP_SOURCE_TAG ((int64)1 << HD3_CA_EXT_PROP_SOURCE_TAG)
|
||||
|
||||
// SPC点属性掩码
|
||||
#define HD3M_SPC_EXT_PROP_SOURCE_TAG_NAME ((int64)1 << HD3_SPC_EXT_PROP_SOURCE_TAG_NAME)
|
||||
#define HD3M_SPC_EXT_PROP_ALARM_GROUP_ID ((int64)1 << HD3_SPC_EXT_PROP_ALARM_GROUP_ID)
|
||||
#define HD3M_SPC_EXT_PROP_CTRL_CHART_TYPE ((int64)1 << HD3_SPC_EXT_PROP_CTRL_CHART_TYPE)
|
||||
#define HD3M_SPC_EXT_PROP_TRIGGER_MODE ((int64)1 << HD3_SPC_EXT_PROP_TRIGGER_MODE)
|
||||
#define HD3M_SPC_EXT_PROP_SAMPLE_SIZE ((int64)1 << HD3_SPC_EXT_PROP_SAMPLE_SIZE)
|
||||
#define HD3M_SPC_EXT_PROP_SAMPLE_INTERVAL ((int64)1 << HD3_SPC_EXT_PROP_SAMPLE_INTERVAL)
|
||||
#define HD3M_SPC_EXT_PROP_AUTO_ACK ((int64)1 << HD3_SPC_EXT_PROP_AUTO_ACK)
|
||||
#define HD3M_SPC_EXT_PROP_RULE ((int64)1 << HD3_SPC_EXT_PROP_RULE)
|
||||
|
||||
// 报警确认状态掩码
|
||||
#define HD3M_AM_REC_ACK_STATE_NO ((int64)1 << HD3_AM_REC_ACK_STATE_NO)
|
||||
#define HD3M_AM_REC_ACK_STATE_YES ((int64)1 << HD3_AM_REC_ACK_STATE_YES)
|
||||
|
||||
// 报警恢复状态掩码
|
||||
#define HD3M_AM_REC_RESTORE_STATE_NO ((int64)1 << HD3_AM_REC_RESTORE_STATE_NO)
|
||||
#define HD3M_AM_REC_RESTORE_STATE_YES ((int64)1 << HD3_AM_REC_RESTORE_STATE_YES)
|
||||
|
||||
// 报警优先级掩码
|
||||
#define HD3M_AM_REC_PRIORITY_FIRST ((int64)1 << HD3_AM_REC_PRIORITY_FIRST)
|
||||
#define HD3M_AM_REC_PRIORITY_SECOND ((int64)1 << HD3_AM_REC_PRIORITY_SECOND)
|
||||
#define HD3M_AM_REC_PRIORITY_THIRD ((int64)1 << HD3_AM_REC_PRIORITY_THIRD)
|
||||
#define HD3M_AM_REC_PRIORITY_FORTH ((int64)1 << HD3_AM_REC_PRIORITY_FORTH)
|
||||
|
||||
// 报警类型掩码
|
||||
#define HD3M_AM_REC_TYPE_LOLO ((int64)1 << HD3_AM_REC_TYPE_LOLO)
|
||||
#define HD3M_AM_REC_TYPE_LOW ((int64)1 << HD3_AM_REC_TYPE_LOW)
|
||||
#define HD3M_AM_REC_TYPE_HIHI ((int64)1 << HD3_AM_REC_TYPE_HIHI)
|
||||
#define HD3M_AM_REC_TYPE_HIGH ((int64)1 << HD3_AM_REC_TYPE_HIGH)
|
||||
#define HD3M_AM_REC_TYPE_CHANGE ((int64)1 <<HD3_AM_REC_TYPE_CHANGE)
|
||||
|
||||
// 报警属性索引掩码
|
||||
#define HD3M_AM_REC_INDEX_ALARM_TAG_ID ((int64)1 << HD3_AM_REC_INDEX_ALARM_TAG_ID)
|
||||
#define HD3M_AM_REC_INDEX_START_TIME ((int64)1 << HD3_AM_REC_INDEX_START_TIME)
|
||||
#define HD3M_AM_REC_INDEX_END_TIME ((int64)1 << HD3_AM_REC_INDEX_END_TIME)
|
||||
#define HD3M_AM_REC_INDEX_ACK_TIME ((int64)1 << HD3_AM_REC_INDEX_ACK_TIME)
|
||||
#define HD3M_AM_REC_INDEX_COMMENT_TIME ((int64)1 << HD3_AM_REC_INDEX_COMMENT_TIME)
|
||||
#define HD3M_AM_REC_INDEX_ACKED ((int64)1 << HD3_AM_REC_INDEX_ACKED)
|
||||
#define HD3M_AM_REC_INDEX_RESTORED ((int64)1 << HD3_AM_REC_INDEX_RESTORED)
|
||||
#define HD3M_AM_REC_INDEX_PRIORITY ((int64)1 << HD3_AM_REC_INDEX_PRIORITY)
|
||||
#define HD3M_AM_REC_INDEX_ACK_TYPE ((int64)1 << HD3_AM_REC_INDEX_ACK_TYPE)
|
||||
#define HD3M_AM_REC_INDEX_ALARM_TYPE ((int64)1 << HD3_AM_REC_INDEX_ALARM_TYPE)
|
||||
#define HD3M_AM_REC_INDEX_SRC_VALUE ((int64)1 << HD3_AM_REC_INDEX_SRC_VALUE)
|
||||
#define HD3M_AM_REC_INDEX_TEST ((int64)1 << HD3_AM_REC_INDEX_TEST)
|
||||
#define HD3M_AM_REC_INDEX_COMMENT ((int64)1 << HD3_AM_REC_INDEX_COMMENT)
|
||||
#define HD3M_AM_REC_INDEX_ACKER ((int64)1 << HD3_AM_REC_INDEX_ACKER)
|
||||
#define HD3M_AM_REC_INDEX_COMMENTOR ((int64)1 << HD3_AM_REC_INDEX_COMMENTOR)
|
||||
|
||||
// SPC报警属性索引掩码
|
||||
#define HD3M_SPC_REC_INDEX_SPC_TAG_ID ((int64)1 << HD3_SPC_REC_INDEX_SPC_TAG_ID)
|
||||
#define HD3M_SPC_REC_INDEX_START_TIME ((int64)1 << HD3_SPC_REC_INDEX_START_TIME)
|
||||
#define HD3M_SPC_REC_INDEX_END_TIME ((int64)1 << HD3_SPC_REC_INDEX_END_TIME)
|
||||
#define HD3M_SPC_REC_INDEX_ACK_TIME ((int64)1 << HD3_SPC_REC_INDEX_ACK_TIME)
|
||||
#define HD3M_SPC_REC_INDEX_COMMENT_TIME ((int64)1 << HD3_SPC_REC_INDEX_COMMENT_TIME)
|
||||
#define HD3M_SPC_REC_INDEX_ACKED ((int64)1 << HD3_SPC_REC_INDEX_ACKED)
|
||||
#define HD3M_SPC_REC_INDEX_ACK_TYPE ((int64)1 << HD3_SPC_REC_INDEX_ACK_TYPE)
|
||||
#define HD3M_SPC_REC_INDEX_RESTORED ((int64)1 << HD3_SPC_REC_INDEX_RESTORED)
|
||||
#define HD3M_SPC_REC_INDEX_COMMENTED ((int64)1 << HD3_SPC_REC_INDEX_COMMENTED)
|
||||
#define HD3M_SPC_REC_INDEX_ALARM_VALUE ((int64)1 << HD3_SPC_REC_INDEX_ALARM_VALUE)
|
||||
#define HD3M_SPC_REC_INDEX_RULE ((int64)1 << HD3_SPC_REC_INDEX_RULE)
|
||||
#define HD3M_SPC_REC_INDEX_SRC_VALUE ((int64)1 << HD3_SPC_REC_INDEX_SRC_VALUE)
|
||||
#define HD3M_SPC_REC_INDEX_COMMENT ((int64)1 << HD3_SPC_REC_INDEX_COMMENT)
|
||||
#define HD3M_SPC_REC_INDEX_ACKER ((int64)1 << HD3_SPC_REC_INDEX_ACKER)
|
||||
#define HD3M_SPC_REC_INDEX_COMMENTOR ((int64)1 << HD3_SPC_REC_INDEX_COMMENTOR)
|
||||
|
||||
// SPC报警值索引掩码
|
||||
#define HD3M_SPC_VALUE_RULE_INDEX1 ((int64)1 << HD3_SPC_VALUE_RULE_INDEX1)
|
||||
#define HD3M_SPC_VALUE_RULE_INDEX2 ((int64)1 << HD3_SPC_VALUE_RULE_INDEX2)
|
||||
#define HD3M_SPC_VALUE_RULE_INDEX3 ((int64)1 << HD3_SPC_VALUE_RULE_INDEX3)
|
||||
#define HD3M_SPC_VALUE_RULE_INDEX4 ((int64)1 << HD3_SPC_VALUE_RULE_INDEX4)
|
||||
#define HD3M_SPC_VALUE_RULE_INDEX5 ((int64)1 << HD3_SPC_VALUE_RULE_INDEX5)
|
||||
#define HD3M_SPC_VALUE_RULE_INDEX6 ((int64)1 << HD3_SPC_VALUE_RULE_INDEX6)
|
||||
#define HD3M_SPC_VALUE_RULE_INDEX7 ((int64)1 << HD3_SPC_VALUE_RULE_INDEX7)
|
||||
#define HD3M_SPC_VALUE_RULE_INDEX8 ((int64)1 << HD3_SPC_VALUE_RULE_INDEX8)
|
||||
|
||||
// 通知对象类型掩码
|
||||
#define HD3M_NOTIFY_OBJ_TYPE_NORMAL_TAG ((int64)1 << HD3_NOTIFY_OBJ_TYPE_NORMAL_TAG)
|
||||
#define HD3M_NOTIFY_OBJ_TYPE_ALARM_TAG ((int64)1 << HD3_NOTIFY_OBJ_TYPE_ALARM_TAG)
|
||||
#define HD3M_NOTIFY_OBJ_TYPE_STAT_TAG ((int64)1 << HD3_NOTIFY_OBJ_TYPE_STAT_TAG)
|
||||
#define HD3M_NOTIFY_OBJ_TYPE_CALC_TAG ((int64)1 << HD3_NOTIFY_OBJ_TYPE_CALC_TAG)
|
||||
#define HD3M_NOTIFY_OBJ_TYPE_COLLECTOR ((int64)1 << HD3_NOTIFY_OBJ_TYPE_COLLECTOR)
|
||||
#define HD3M_NOTIFY_OBJ_TYPE_SCANGROUP ((int64)1 << HD3_NOTIFY_OBJ_TYPE_SCANGROUP)
|
||||
#define HD3M_NOTIFY_OBJ_TYPE_DEVICE ((int64)1 << HD3_NOTIFY_OBJ_TYPE_DEVICE)
|
||||
#define HD3M_NOTIFY_OBJ_TYPE_ALARM_GROUP ((int64)1 << HD3_NOTIFY_OBJ_TYPE_ALARM_GROUP)
|
||||
#define HD3M_NOTIFY_OBJ_TYPE_DIGITAL_SET ((int64)1 << HD3_NOTIFY_OBJ_TYPE_DIGITAL_SET)
|
||||
|
||||
#endif
|
||||
661
TestProject/DCR/ihdb_inc/hd3Struct.h
Normal file
661
TestProject/DCR/ihdb_inc/hd3Struct.h
Normal file
@ -0,0 +1,661 @@
|
||||
/**
|
||||
* @file hd3Struct.h
|
||||
* @brief hd3 struct
|
||||
* @author: hd3 team
|
||||
* @date 03/02/2015
|
||||
* @version initialize version
|
||||
* Copyright: Shanghai Baosight Software Co., Ltd.
|
||||
*/
|
||||
#ifndef HD3_INCLUDE_GUARD_HD3STRUCT_H
|
||||
#define HD3_INCLUDE_GUARD_HD3STRUCT_H
|
||||
|
||||
#include "data_types.h"
|
||||
#include "hd3Enum.h"
|
||||
#include "hd3MaskDefine.h"
|
||||
#include <string>
|
||||
|
||||
#ifndef HD3_DEFINE_GUARD_HD3HANDLE
|
||||
#define HD3_DEFINE_GUARD_HD3HANDLE
|
||||
typedef void* HD3HANDLE;
|
||||
#endif
|
||||
|
||||
// HD3_SOCKET 定义
|
||||
#ifndef WIN32
|
||||
# ifndef SOCKET
|
||||
# define SOCKET int
|
||||
# endif
|
||||
#else
|
||||
# ifndef SOCKET
|
||||
# if defined(_WIN64)
|
||||
typedef __int64 INT_PTR, *PINT_PTR;
|
||||
typedef unsigned __int64 UINT_PTR, *PUINT_PTR;
|
||||
# else
|
||||
typedef _W64 int INT_PTR, *PINT_PTR;
|
||||
typedef _W64 unsigned int UINT_PTR, *PUINT_PTR;
|
||||
# endif
|
||||
typedef UINT_PTR SOCKET;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// epsilon of compare double with 0
|
||||
#define HD3_EPSILON (double)0.00001
|
||||
|
||||
// 所有Tag点共有属性
|
||||
#define HD3_COMM_TAG_PROP \
|
||||
char szTagName[HD3_LEN_TAG_NAME * HD3_BASE]; \
|
||||
bool bArchiving; \
|
||||
uint32 nChangeDate; \
|
||||
char szChanger[HD3_LEN_USER_NAME * HD3_BASE]; \
|
||||
float fCompDev; \
|
||||
int32 nCompMaxTime; \
|
||||
enum HD3_COMP_TYPE nCompType; \
|
||||
uint32 nCreationDate; \
|
||||
char szCreator[HD3_LEN_USER_NAME * HD3_BASE]; \
|
||||
uint8 nRecAccess; \
|
||||
char szRecNormalGroup[HD3_LEN_USER_NAME * HD3_BASE]; \
|
||||
char szRecOwnerGroup[HD3_LEN_USER_NAME * HD3_BASE]; \
|
||||
char szDescriptor[HD3_LEN_TAG_DESC * HD3_BASE]; \
|
||||
char szDigitalSet[HD3_LEN_DIGITAL_SET_NAME * HD3_BASE]; \
|
||||
char szEngUnits[HD3_LEN_ENG_UNITS * HD3_BASE]; \
|
||||
int32 nExcMaxTime; \
|
||||
float fExcDev; \
|
||||
uint32 nTagID; \
|
||||
enum HD3_TAG_TYPE nTagType; \
|
||||
uint8 nTagAccess; \
|
||||
char szTagNormalGroup[HD3_LEN_USER_NAME * HD3_BASE]; \
|
||||
char szTagOwnerGroup[HD3_LEN_USER_NAME * HD3_BASE]; \
|
||||
bool bScan; \
|
||||
float fSpan; \
|
||||
float fMinValue; \
|
||||
enum HD3_TAG_CLASS nTagClass; \
|
||||
enum HD3_TAG_AVALIABLE nTagAvaliable; \
|
||||
uint8 nParam1; \
|
||||
uint8 nParam2; \
|
||||
uint8 nParam3; \
|
||||
uint8 nParam4; \
|
||||
uint8 nParam5; \
|
||||
enum HD3_TAG_OPC_STATE nOpcState; \
|
||||
char szIMVString[HD3_LEN_EXT_STRING * HD3_BASE]; \
|
||||
char szExtString1[HD3_LEN_EXT_STRING * HD3_BASE]; \
|
||||
char szExtString2[HD3_LEN_EXT_STRING * HD3_BASE]
|
||||
|
||||
// 普通点特有属性
|
||||
#define HD3_PT_TAG_EXT_PROP \
|
||||
HD3_M char szInstrumentAddress[HD3_LEN_INSTRUMENT_ADDRESS * HD3_BASE]; \
|
||||
uint8 nInstrumentAddressType; \
|
||||
char szCollectorName[HD3_LEN_COLLECTOR_NAME * HD3_BASE]; \
|
||||
int32 nCollectorID; \
|
||||
char szDeviceName[HD3_LEN_DEVICE_NAME * HD3_BASE]; \
|
||||
HD3_M uint32 nDeviceID; \
|
||||
char szScanGroupName[HD3_LEN_SCANGROUP_NAME * HD3_BASE]; \
|
||||
HD3_M uint32 nScanGroupID; \
|
||||
enum HD3_DATA_ORDER nDataOrder
|
||||
|
||||
// 报警点特有属性
|
||||
#define HD3_ALARM_TAG_EXT_PROP \
|
||||
char szTest1[HD3_LEN_ALARM_TEST * HD3_BASE]; \
|
||||
char szTest2[HD3_LEN_ALARM_TEST * HD3_BASE]; \
|
||||
char szTest3[HD3_LEN_ALARM_TEST * HD3_BASE]; \
|
||||
char szTest4[HD3_LEN_ALARM_TEST * HD3_BASE]; \
|
||||
char szAction1[HD3_LEN_ALARM_ACTION * HD3_BASE]; \
|
||||
char szAction2[HD3_LEN_ALARM_ACTION * HD3_BASE]; \
|
||||
char szAction3[HD3_LEN_ALARM_ACTION * HD3_BASE]; \
|
||||
char szAction4[HD3_LEN_ALARM_ACTION * HD3_BASE]; \
|
||||
char szSourceTagName[HD3_LEN_TAG_NAME * HD3_BASE]; \
|
||||
uint32 nAlarmGroupID; \
|
||||
enum HD3_AM_ACK_TYPE nAutoAck; \
|
||||
int32 nTimeDeadBand; \
|
||||
float fValueDeadBand
|
||||
|
||||
// 统计点特有属性
|
||||
#define HD3_STATS_TAG_EXT_PROP \
|
||||
char szSourceTagName[HD3_LEN_TAG_NAME * HD3_BASE]; \
|
||||
enum HD3_STATS_TYPE nStatsType; \
|
||||
int32 nSampleStartDate; \
|
||||
enum HD3_STATS_SAMPLE_MODE nSampleMode; \
|
||||
HD3_M int32 nSampleInterval; \
|
||||
int32 nSampleBeginOffset; \
|
||||
int32 nSampleEndOffset; \
|
||||
/*TT*/uint8 nSampleMonthBeginDay; \
|
||||
/*TT*/uint8 nSampleMonthEndDay; \
|
||||
bool bBeginTimeStamp; \
|
||||
int32 nTimeStampOffset; \
|
||||
int32 nScanPeriod; \
|
||||
float fPctGood; \
|
||||
char szFilterExpr[HD3_LEN_FILTER_EXPR * HD3_BASE]; \
|
||||
enum HD3_STATS_DROP_BAD_MODE nDropBadMode; \
|
||||
double dCountParam1; \
|
||||
double dCountParam2; \
|
||||
enum HD3_STATS_SAMPLE_TYPE nSampleType; \
|
||||
int32 nInterpOffset; \
|
||||
int32 nInterpPeriod; \
|
||||
enum HD3_STATS_CONVERSION_TYPE nConversionType; \
|
||||
double dConversion; \
|
||||
enum HD3_STATS_FILTER_FAIL_MODE nFilterFailMode; \
|
||||
int32 nCalcPeriod; \
|
||||
bool bReset;\
|
||||
bool bUseBadValue
|
||||
|
||||
// 计算点特有属性
|
||||
#define HD3_CALC_TAG_EXT_PROP \
|
||||
enum HD3_CALC_MODE nCalcMode; \
|
||||
int32 nCalcPeriod; \
|
||||
char szCalcExpr[HD3_LEN_CALC_EXPR * HD3_BASE]; \
|
||||
bool bCalcHistory; \
|
||||
int32 nCalcStartDate; \
|
||||
int32 nCalcEndDate; \
|
||||
bool bHaveEndTime; \
|
||||
char szSourceTagName[HD3_LEN_TAG_NAME * HD3_BASE]
|
||||
|
||||
// SPC规则
|
||||
#define HD3_SPC_RULE \
|
||||
char szUCLTagName[HD3_LEN_TAG_NAME * HD3_BASE];\
|
||||
char szCLTagName[HD3_LEN_TAG_NAME* HD3_BASE];\
|
||||
char szLCLTagName[HD3_LEN_TAG_NAME* HD3_BASE];\
|
||||
char szUSLTagName[HD3_LEN_TAG_NAME* HD3_BASE];\
|
||||
char szLSLTagName[HD3_LEN_TAG_NAME* HD3_BASE];\
|
||||
char szResetTagName[HD3_LEN_TAG_NAME* HD3_BASE];\
|
||||
float64 dUCLDefaultValue;\
|
||||
float64 dCLDefaultVaule;\
|
||||
float64 dLCLDefaultValue;\
|
||||
bool bRule1;\
|
||||
bool bRule2;\
|
||||
bool bRule3;\
|
||||
bool bRule4;\
|
||||
bool bRule5;\
|
||||
bool bRule6;\
|
||||
bool bRule7;\
|
||||
bool bRule8;\
|
||||
uint32 nRule1M;\
|
||||
uint32 nRule2M;\
|
||||
uint32 nRule3M;\
|
||||
uint32 nRule4M;\
|
||||
uint32 nRule5M;\
|
||||
uint32 nRule6M;\
|
||||
uint32 nRule7M;\
|
||||
uint32 nRule8M;\
|
||||
uint32 nRule5N;\
|
||||
uint32 nRule6N;\
|
||||
bool bJudgeContinuous
|
||||
|
||||
// SPC点特有属性
|
||||
#define HD3_SPC_TAG_EXT_PROP \
|
||||
char szSourceTagName[HD3_LEN_TAG_NAME * HD3_BASE]; \
|
||||
uint32 nAlarmGroupID; \
|
||||
enum HD3_SPC_CTRL_CHART_TYPE nCtrlChartType; \
|
||||
enum HD3_SPC_TRIGGER_MODE nTriggerMode; \
|
||||
int32 nSampleSize; \
|
||||
int32 nSampleInterval; \
|
||||
bool bAutoAck; \
|
||||
HD3_SPC_RULE
|
||||
|
||||
/* Tag点属性结构 */
|
||||
HD3_M;
|
||||
typedef struct {
|
||||
HD3_COMM_TAG_PROP;
|
||||
}HD3CommTagProp;
|
||||
|
||||
// 普通点
|
||||
HD3_M;
|
||||
typedef struct {
|
||||
HD3_COMM_TAG_PROP;
|
||||
HD3_PT_TAG_EXT_PROP;
|
||||
}HD3PtTagProp;
|
||||
|
||||
// 报警点
|
||||
typedef struct {
|
||||
HD3_COMM_TAG_PROP;
|
||||
HD3_ALARM_TAG_EXT_PROP;
|
||||
}HD3AlarmTagProp;
|
||||
|
||||
// SPC点
|
||||
typedef struct {
|
||||
HD3_COMM_TAG_PROP;
|
||||
HD3_SPC_TAG_EXT_PROP;
|
||||
}HD3SpcTagProp;
|
||||
|
||||
// 统计点
|
||||
typedef struct {
|
||||
HD3_COMM_TAG_PROP;
|
||||
HD3_STATS_TAG_EXT_PROP;
|
||||
}HD3StatsTagProp;
|
||||
|
||||
// 计算点
|
||||
typedef struct {
|
||||
HD3_COMM_TAG_PROP;
|
||||
HD3_CALC_TAG_EXT_PROP;
|
||||
}HD3CalcTagProp;
|
||||
|
||||
// 许可证信息
|
||||
typedef struct {
|
||||
enum HD3_LICENSE nLicense;
|
||||
int32 nValidSec;
|
||||
uint32 nClientNum;
|
||||
}HD3LicenseInfo;
|
||||
|
||||
/** 时间从1970年1月0日00:00:01到2038年1月19日3:14:06 */
|
||||
typedef struct {
|
||||
int32 month; /**< 1-12 */
|
||||
int32 year; /**< four digit */
|
||||
int32 day; /**< 1-31 */
|
||||
int32 hour; /**< 0-23 */
|
||||
int32 minute; /**< 0-59 */
|
||||
int32 second; /**< 0-59*/
|
||||
int32 mSecond; /**< 0-999*/
|
||||
int32 timezone; /**< -12~12*/
|
||||
}HD3TimeStamp;
|
||||
|
||||
// 时间
|
||||
typedef struct {
|
||||
int32 nSec;
|
||||
int16 nMsec;
|
||||
}HD3Time;
|
||||
|
||||
// 时间区间
|
||||
typedef struct {
|
||||
HD3Time left; // 左区间
|
||||
HD3Time right; // 右区间
|
||||
bool bLeftClosed; // 左区间开或是闭
|
||||
bool bRightClosed; // 右区间开或是闭
|
||||
}HD3TimeRegion;
|
||||
|
||||
// //单一客户端连接信息
|
||||
// typedef struct {
|
||||
// HD3_M uint32 nClientIP;
|
||||
// char szMac[32];
|
||||
// int32 nSocketNum;
|
||||
// HD3_SOCKET nSocket[HD3_CLIENT_SOCKET_MAX];
|
||||
// }HD3ClientConnInfo;
|
||||
//
|
||||
// typedef struct {
|
||||
// HD3_SOCKET nSocket;
|
||||
// int32 nConnectTime;
|
||||
// int32 nPackageRecvNum;
|
||||
// int32 nPackageRecvTime;
|
||||
// char szUserName[HD3_LEN_USER_NAME * HD3_BASE];
|
||||
// }HD3SocketNetInfo;
|
||||
|
||||
// 数据
|
||||
typedef struct {
|
||||
int32 nSec;
|
||||
int16 nMsec;
|
||||
uint16 nQuality;
|
||||
enum HD3_TAG_TYPE nTagType;
|
||||
struct
|
||||
{
|
||||
int8 nInt8;
|
||||
int16 nInt16;
|
||||
int32 nInt32;
|
||||
float32 fFloat32;
|
||||
float64 fFloat64;
|
||||
int8 nDigital;
|
||||
struct
|
||||
{
|
||||
char* pBuf;
|
||||
uint16 nLenBuf;
|
||||
}strBlob;
|
||||
}value;
|
||||
|
||||
inline const double NumberValue()
|
||||
{
|
||||
if(this->nTagType == HD3_TAG_TYPE_INT8)return (double)this->value.nInt8;
|
||||
if(this->nTagType == HD3_TAG_TYPE_INT16)return (double)this->value.nInt16;
|
||||
if(this->nTagType == HD3_TAG_TYPE_INT32)return (double)this->value.nInt32;
|
||||
if(this->nTagType == HD3_TAG_TYPE_FLOAT32)return (double)this->value.fFloat32;
|
||||
if(this->nTagType == HD3_TAG_TYPE_FLOAT64)return (double)this->value.fFloat64;
|
||||
if(this->nTagType == HD3_TAG_TYPE_DIGITAL)return (double)this->value.nDigital;
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline const std::string StringValue()
|
||||
{
|
||||
if(this->nTagType == HD3_TAG_TYPE_STRING)return std::string(this->value.strBlob.pBuf,this->value.strBlob.nLenBuf);
|
||||
return "";
|
||||
}
|
||||
|
||||
}HD3Record;
|
||||
|
||||
// 查询条件(Tag点查询,数据查询,报警记录查询,SPC记录查询)
|
||||
typedef struct {
|
||||
int32 nItemID;
|
||||
enum HD3_RELATION nRelation;
|
||||
char szValue[HD3_LEN_QUERY_ITEM_VALUE * HD3_BASE];
|
||||
}HD3FilterItem;
|
||||
|
||||
// 报警
|
||||
typedef struct {
|
||||
uint32 nAlarmTagID; /**< 报警点ID*/
|
||||
HD3Time tvStartTime; /**< 报警开始时间*/
|
||||
HD3Time tvEndTime; /**< 报警终止时间*/
|
||||
HD3Time tvAckTime; /**< 报警确认时间*/
|
||||
HD3Time tvCommentTime; /**< 报警注释时间*/
|
||||
|
||||
enum HD3_AM_REC_ACK_STATE nAcked; /**< 确认状态*/
|
||||
enum HD3_AM_REC_RESTORE_STATE nRestored; /**< 恢复状态*/
|
||||
enum HD3_AM_REC_PRIORITY nPriority; /**< 优先级*/
|
||||
enum HD3_AM_ACK_TYPE nAckType; /**< 报警确认类型*/
|
||||
enum HD3_AM_REC_TYPE nAlarmType; /**< 报警类型*/
|
||||
|
||||
char szSrcValue[HD3_LEN_VAR_TYPE_VALUE * HD3_BASE]; /**< 源值*/
|
||||
char szTest[HD3_LEN_ALARM_TEST * HD3_BASE]; /**< 违反规则*/
|
||||
char szComment[HD3_LEN_ALARM_COMMENT * HD3_BASE]; /**< 注释*/
|
||||
char szAcker[HD3_LEN_USER_NAME * HD3_BASE]; /**< 确认者*/
|
||||
char szCommentor[HD3_LEN_USER_NAME * HD3_BASE]; /**< 注释者*/
|
||||
}HD3AlarmRecord;
|
||||
|
||||
// SPC
|
||||
typedef struct {
|
||||
uint32 nSPCTagID; /**< SPC报警点ID*/
|
||||
HD3Time tvStartTime; /**< 报警开始时间*/
|
||||
HD3Time tvEndTime; /**< 报警终止时间*/
|
||||
HD3Time tvAckTime; /**< 报警确认时间*/
|
||||
HD3Time tvCommentTime; /**< 报警注释时间*/
|
||||
enum HD3_AM_REC_ACK_STATE nAcked; /**< 确认状态*/
|
||||
enum HD3_AM__REC_ACK_TYPE nAckType; /**< 确认类型,手动还是自动*/
|
||||
enum HD3_AM_REC_RESTORE_STATE nRestored; /**< 恢复状态*/
|
||||
int8 nValue; /**< 报警值*/
|
||||
uint32 nRule1M; /**< 判异规则1的M值*/
|
||||
uint32 nRule2M; /**< 判异规则2的M值*/
|
||||
uint32 nRule3M; /**< 判异规则3的M值*/
|
||||
uint32 nRule4M; /**< 判异规则4的M值*/
|
||||
uint32 nRule5M; /**< 判异规则5的M值*/
|
||||
uint32 nRule5N; /**< 判异规则5的N值*/
|
||||
uint32 nRule6M; /**< 判异规则6的M值*/
|
||||
uint32 nRule6N; /**< 判异规则6的N值*/
|
||||
uint32 nRule7M; /**< 判异规则7的M值*/
|
||||
uint32 nRule8M; /**< 判异规则8的M值*/
|
||||
char szSrcValue[HD3_LEN_VAR_TYPE_VALUE * HD3_BASE]; /**< 源值*/
|
||||
char szComment[HD3_LEN_ALARM_COMMENT * HD3_BASE]; /**< 注释*/
|
||||
char szAcker[HD3_LEN_USER_NAME * HD3_BASE]; /**< 确认者*/
|
||||
char szCommentor[HD3_LEN_USER_NAME * HD3_BASE]; /**< 注释者*/
|
||||
}HD3SpcRecord;
|
||||
|
||||
// iHyperDB 报警组
|
||||
typedef struct {
|
||||
char szName[HD3_LEN_ALARM_GROUP_NAME * HD3_BASE]; /**< 报警组的名字 */
|
||||
char szDesc[HD3_LEN_ALARM_GROUP_DESC * HD3_BASE]; /**< 报警组的描述 */
|
||||
uint32 nGroupID; /**< 报警组的ID */
|
||||
uint32 nParentID; /**< 报警组的上一级组名,第一级组的组名为空即 "" */
|
||||
}HD3AlarmGroup;
|
||||
|
||||
// iHyperDB 历史报警查询条件
|
||||
typedef struct {
|
||||
HD3Time tvStart;
|
||||
HD3Time tvEnd;
|
||||
int64 nAckMask; // HD3AmAckStateMask
|
||||
int64 nTypeMask; // HD3AmTypeMask
|
||||
int64 nPriorMask; // HD3AmPriorityMask
|
||||
int64 nRestoreMask; // HD3AmRestoreStateMask
|
||||
}HD3AlarmQuery;
|
||||
|
||||
// iHyperDB SPC报警查询条件
|
||||
typedef struct {
|
||||
HD3Time tvStart;
|
||||
HD3Time tvEnd;
|
||||
int64 nAckMask; // HD3AmAckStateMask
|
||||
int64 nRestoreMask; // HD3AmRestoreStateMask
|
||||
}HD3SPCQuery;
|
||||
|
||||
// iHyperDB 权限管理: 用户
|
||||
typedef struct {
|
||||
char szUserName[HD3_LEN_USER_NAME * HD3_BASE];
|
||||
char szPasswd[HD3_LEN_PASSWORD * HD3_BASE];
|
||||
char szUserDesc[HD3_LEN_USER_DESC * HD3_BASE];
|
||||
}HD3SecUser;
|
||||
|
||||
// iHyperDB 权限管理: 组
|
||||
typedef struct {
|
||||
char szGroupName[HD3_LEN_GROUP_NAME * HD3_BASE];
|
||||
char szGroupDesc[HD3_LEN_GROUP_DESC * HD3_BASE];
|
||||
}HD3SecGroup;
|
||||
|
||||
// iHyperDB 权限管理: 授权项
|
||||
typedef struct {
|
||||
char szName[HD3_LEN_AUTH_NAME * HD3_BASE];
|
||||
char szDesc[HD3_LEN_AUTH_DESC * HD3_BASE];
|
||||
int32 nAuth;
|
||||
}HD3SecAuthItem;
|
||||
|
||||
// iHyperDB 权限管理: 信任
|
||||
typedef struct {
|
||||
char szTrustName[HD3_LEN_TRUST_NAME * HD3_BASE];
|
||||
HD3_M char szStartIP[HD3_LEN_IP * HD3_BASE];
|
||||
HD3_M char szEndIP[HD3_LEN_IP * HD3_BASE];
|
||||
char szUserName[HD3_LEN_USER_NAME * HD3_BASE];
|
||||
}HD3SecTrust;
|
||||
|
||||
// iHyperDB 权限管理: 安全数据库项:如Tag点、用户组等
|
||||
typedef struct {
|
||||
char szOwnGroupName[HD3_LEN_GROUP_NAME * HD3_BASE];
|
||||
char szOperateGroupName[HD3_LEN_GROUP_NAME * HD3_BASE];
|
||||
int8 nSecurity;
|
||||
}HD3SecItem;
|
||||
|
||||
// 采集器
|
||||
typedef struct {
|
||||
uint32 nID;
|
||||
uint32 nStatusTagID;
|
||||
enum HD3_COLLECTOR_TYPE nType;
|
||||
char szName[HD3_LEN_COLLECTOR_NAME * HD3_BASE];
|
||||
char szDescription[HD3_LEN_COLLECTOR_DESC * HD3_BASE];
|
||||
char szExtParam[HD3_LEN_COLLECTOR_EXT_PARAM * HD3_BASE];
|
||||
|
||||
}HD3Collector;
|
||||
|
||||
// 设备
|
||||
typedef struct {
|
||||
uint32 nID; /**<Device ID. */
|
||||
uint32 nCollectorID; /**<Collector ID. */
|
||||
uint16 nPort;
|
||||
int32 nTimeout;
|
||||
uint32 nStatusTagID;
|
||||
int16 nTryTime;
|
||||
bool bIsPrimary;
|
||||
char szName[HD3_LEN_DEVICE_NAME * HD3_BASE];
|
||||
char szDescription[HD3_LEN_DEVICE_DESC * HD3_BASE];
|
||||
char szAddr[HD3_LEN_DEVICE_ADDRESS * HD3_BASE];
|
||||
char szExtParam[HD3_LEN_DEVICE_EXT_PARAM * HD3_BASE];
|
||||
}HD3Device;
|
||||
|
||||
// 扫描组
|
||||
typedef struct {
|
||||
uint32 nID; /**<Group ID. */
|
||||
char szName[HD3_LEN_SCANGROUP_NAME * HD3_BASE];
|
||||
char szDescrption[HD3_LEN_SCANGROUP_DESC * HD3_BASE];
|
||||
int32 nPeriod;
|
||||
int32 nPhase;
|
||||
enum HD3_SCAN_TYPE nScanType; /**<advise mode or not */
|
||||
uint32 nDeviceID; /**<Device ID. */
|
||||
int32 nDataAddr;
|
||||
int32 nDataLen;
|
||||
char szExtParam[HD3_LEN_SCANGROUP_EXT_PARAM * HD3_BASE];
|
||||
}HD3ScanGroup;
|
||||
|
||||
// 许可证信息项
|
||||
typedef struct {
|
||||
uint32 nTagNumber; //nMaxTagNum
|
||||
uint32 nClientNumber; //nMaxConNum
|
||||
char szVCODE[HD3_LEN_LICENSE_OEM_VCODE * HD3_BASE];
|
||||
uint8 nSupportSPC;
|
||||
uint8 nSupportZT;
|
||||
char szTempAlian[2]; //4字节倍数补齐
|
||||
}HD3LicInfo;
|
||||
|
||||
// 数字量状态集
|
||||
typedef struct {
|
||||
char szName[HD3_LEN_DIGITAL_SET_NAME * HD3_BASE];
|
||||
}HD3DigitalSet;
|
||||
|
||||
// 数据量状态信息
|
||||
typedef struct {
|
||||
uint32 nStateID;
|
||||
char szStateName[HD3_LEN_DIGITAL_SET_STATE_NAME * HD3_BASE];
|
||||
int32 nStateValue;
|
||||
}HD3DsStateInfo;
|
||||
|
||||
// 采集器状态信息
|
||||
typedef struct {
|
||||
uint16 nQuality;
|
||||
int32 nTotalTagNum;
|
||||
int32 nActiveTagNum;
|
||||
}HD3CtStatusInfo;
|
||||
|
||||
// Tag基本信息
|
||||
typedef struct {
|
||||
uint32 nTagID;
|
||||
char szTagName[HD3_LEN_TAG_NAME * HD3_BASE];
|
||||
enum HD3_TAG_TYPE nTagType;
|
||||
enum HD3_TAG_CLASS nTagClass;
|
||||
} HD3TagBasicInfo;
|
||||
|
||||
// 统计相关参数
|
||||
typedef struct {
|
||||
enum HD3_STATS_TYPE nStatsType; //统计类型
|
||||
int32 nTimeRegionNum; //统计时间区间个数,最小值为1,最大值为128
|
||||
HD3TimeRegion* pTimeRegions;//统计时间区间,支持多个统计时间区间
|
||||
float fPercentGood; //信任度(Good的数据个数百分比大于或等于该比例时认为计算出的结果是可信的),0-100
|
||||
enum HD3_STATS_SAMPLE_TYPE nSampleType; //采样方式
|
||||
char szFilterExpr[HD3_LEN_FILTER_EXPR * HD3_BASE]; //数据过滤表达式, 传入空字符串表示不过滤
|
||||
enum HD3_STATS_FILTER_FAIL_MODE nFilterFailMode; //过滤表达式执行失败时对采样数据的处理,过滤还是不过滤
|
||||
double dExtParam1; //计数和计时的参数, 值变化的参数,区间变化的第一个参数,在区间不在区间的第一个参数区间为[dExtParam1, dExtParam2]
|
||||
double dExtParam2; //计数和计时的参数,区间变化的第二个参数,在区间不在区间的第二个参数
|
||||
int32 nOffset; //采样模式为插值时,第一个插值点为startTime+nOffset, 单位为秒
|
||||
int32 nPeriod; //采样模式为插值时,插值点的间隔为nPeriod, 单位为秒
|
||||
bool bUseBadValue; //bad值是否参与统计,true表示bad值参与统计
|
||||
}HD3StRelatedParam;
|
||||
|
||||
// 变更的报告
|
||||
typedef struct {
|
||||
uint32 nChangeID;
|
||||
enum HD3_MODULE_TYPE nModuleType;
|
||||
uint32 nModuleID;
|
||||
enum HD3_ALTERATION_ENTRY nEntry; // nChangeCategory
|
||||
enum HD3_ALTERATION_TYPE nAlterationType;
|
||||
uint32 nSourceID;
|
||||
int32 nVersion;
|
||||
}HD3AlterationReport; //HDChangeHis
|
||||
|
||||
// Tag点掩码
|
||||
typedef struct {
|
||||
int64 nCommMask; // 公共属性的掩码
|
||||
int64 nExtMask;
|
||||
}HD3Mask;
|
||||
|
||||
// 查询过滤项数组
|
||||
typedef struct {
|
||||
int32 nSize;
|
||||
HD3FilterItem* pItem; // array
|
||||
}HD3FilterItemSet;
|
||||
|
||||
// 查询指定页Tag点的参数
|
||||
typedef struct {
|
||||
HD3FilterItemSet itemSet;
|
||||
HD3Mask mask;
|
||||
uint32 nStartID;
|
||||
int32 nCapacity;
|
||||
}HD3PageQueryTagParam;
|
||||
|
||||
// iHyperDB节点信息(配置节点、数据节点)
|
||||
typedef struct {
|
||||
uint32 nID;
|
||||
char szName[HD3_LEN_NODE_NAME * HD3_BASE];
|
||||
char szDesc[HD3_LEN_NODE_DESC * HD3_BASE];
|
||||
char szAddress[HD3_LEN_ADDRESS * HD3_BASE];
|
||||
char szMachineName[HD3_LEN_ADDRESS * HD3_BASE];
|
||||
uint16 nPort;
|
||||
char szBakAddress[HD3_LEN_ADDRESS * HD3_BASE];
|
||||
char szBakMachineName[HD3_LEN_ADDRESS * HD3_BASE];
|
||||
uint16 nBakPort;
|
||||
int32 nTagCapacity;
|
||||
}HD3DataNode;
|
||||
|
||||
// 统计通用参数
|
||||
typedef struct {
|
||||
HD3TimeRegion timeRegion;
|
||||
float fPercentGood;
|
||||
}HD3StFuncComm;
|
||||
|
||||
// API连接参数
|
||||
typedef struct {
|
||||
char szAddress[HD3_LEN_ADDRESS * HD3_BASE];
|
||||
uint16 nPort;
|
||||
char szBakAddress[HD3_LEN_ADDRESS * HD3_BASE];
|
||||
uint16 nBakPort;
|
||||
int32 nTimeout;
|
||||
}HD3Connection;
|
||||
|
||||
// 客户端连接信息
|
||||
typedef struct {
|
||||
uint32 nClientIp;
|
||||
char szMac[32];
|
||||
int32 nSocketNum;
|
||||
SOCKET nSocket[HD3_API_CLIENT_MAX_SOCKET_NUM];
|
||||
}HD3ClientConnInfo;
|
||||
|
||||
// 网络SOCKET信息
|
||||
typedef struct {
|
||||
SOCKET nSocket;
|
||||
int32 nConnectTime;
|
||||
int32 nPackageRecvNum;
|
||||
int32 nPackageRecvTime;
|
||||
char szUserName[HD3_LEN_USER_NAME * HD3_BASE];
|
||||
}HD3SocketNetInfo;
|
||||
|
||||
// 节点配置信息
|
||||
typedef struct {
|
||||
int32 nPort; //网络端口号
|
||||
int32 nArchFileSizeMB; //单个归档文件的大小
|
||||
int32 nArchFileNum; //归档文件个数
|
||||
int32 nSeqFileSizeMB; //单个序列缓存文件的大小
|
||||
int32 nSeqCacheFlushPeriodSec; // 序列缓存刷新频率
|
||||
bool bAutoDisconn; //是否自动断开无数据交互的连接
|
||||
int32 nAutoDisconnPeriodSec; //自动无数据交互连接的超时时间
|
||||
bool bSysInfoCollect; //是否采集系统信息
|
||||
int32 nSysInfoCollectPeriodSec; //系统信息采集间隔
|
||||
bool bDiscardFutureData; //是否丢弃超过服务器时间戳的未来数据
|
||||
int32 nDiscardFutureDataTimeDelterSec; //超过服务器时间戳的时间偏差
|
||||
int64 nMachineTimeMs;
|
||||
char szHDVersion[HD3_LEN_HD_VERSION * HD3_BASE];
|
||||
}HD3DataNodeCfg;
|
||||
|
||||
// 节点冗余状态
|
||||
typedef struct {
|
||||
char szHostIP[HD3_LEN_ADDRESS* HD3_BASE]; //主机IP
|
||||
char szBackIP[HD3_LEN_ADDRESS* HD3_BASE]; //备机IP
|
||||
enum HD3_RY_STATUS nHostStatus; //主机状态
|
||||
enum HD3_RY_STATUS nBackupStatus; //备机状态
|
||||
}HD3DataNodeStatus;
|
||||
|
||||
typedef struct {
|
||||
uint32 nID; //ack id
|
||||
uint32 nAlarmTagID; // alarm tag id
|
||||
uint32 nServerID; //serverid
|
||||
uint32 nOrginalTagID; //alarm tag orginal tag id
|
||||
HD3Time alarmTime; //alarm time
|
||||
HD3Time ackTime; //ack time
|
||||
uint32 nAckerID; //acker id
|
||||
char szAcker[HD3_LEN_USER_NAME * HD3_BASE]; //acker
|
||||
}HD3Ack;
|
||||
|
||||
typedef struct {
|
||||
uint32 nID; //comment id
|
||||
uint32 nAlarmTagID; // alarm tag id
|
||||
uint32 nServerID; //serverid
|
||||
uint32 nOrginalTagID; //alarm tag orginal tag id
|
||||
HD3Time alarmTime; //alarm time
|
||||
HD3Time commentTime; //comment time
|
||||
uint32 nCommentorID; //commentor id
|
||||
char szCommentor[HD3_LEN_USER_NAME * HD3_BASE]; //commentor
|
||||
char szComment[HD3_LEN_ALARM_COMMENT * HD3_BASE]; //comment
|
||||
}HD3Comment;
|
||||
|
||||
// 配置节点冗余状态
|
||||
typedef struct {
|
||||
char szHostIP[HD3_LEN_ADDRESS* HD3_BASE]; //主机IP
|
||||
char szBackIP[HD3_LEN_ADDRESS* HD3_BASE]; //备机IP
|
||||
enum HD3_RY_STATUS nHostStatus; //主机状态
|
||||
enum HD3_RY_STATUS nBackupStatus; //备机状态
|
||||
}HD3ConfigCenterStatus;
|
||||
|
||||
|
||||
#endif
|
||||
2836
TestProject/DCR/ihdb_inc/hdKingAPI.h
Normal file
2836
TestProject/DCR/ihdb_inc/hdKingAPI.h
Normal file
File diff suppressed because it is too large
Load Diff
1088
TestProject/DCR/ihdb_inc/ihyperdb.h
Normal file
1088
TestProject/DCR/ihdb_inc/ihyperdb.h
Normal file
File diff suppressed because it is too large
Load Diff
81
TestProject/ProxyTest/CMakeLists.txt
Normal file
81
TestProject/ProxyTest/CMakeLists.txt
Normal file
@ -0,0 +1,81 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(ProxyTest VERSION 0.1)
|
||||
|
||||
set(CONFIG_FILE_PATH "config.json")
|
||||
|
||||
include(../../cmake_include/public.cmake)
|
||||
include(../../cmake_include/baosight.cmake)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-omit-frame-pointer -Wno-deprecated-declarations")
|
||||
aux_source_directory(./ DIR_ROOT)
|
||||
|
||||
|
||||
set(LINK_OPTION
|
||||
${ICE}
|
||||
${IPLATURE}
|
||||
${SQL}
|
||||
${FREEZE}
|
||||
${BASE_LIB}
|
||||
${CODE_LIB}
|
||||
${IDA}
|
||||
${LEGACY_JSON}
|
||||
${MEMCACHE_LIB}
|
||||
${IHDB_LIB}
|
||||
rt
|
||||
stdc++
|
||||
c
|
||||
m
|
||||
)
|
||||
|
||||
add_executable(
|
||||
ProxyTest
|
||||
${DIR_ROOT}
|
||||
)
|
||||
|
||||
target_link_libraries(ProxyTest
|
||||
${LINK_OPTION}
|
||||
Eigen3::Eigen )
|
||||
|
||||
target_include_directories(
|
||||
ProxyTest
|
||||
PUBLIC ./
|
||||
../
|
||||
../../
|
||||
${my_lib_include}
|
||||
${legacy_include}
|
||||
${iplature_include}
|
||||
${ihdb_include}
|
||||
${memcache_include}
|
||||
${iXcom}Include)
|
||||
|
||||
message("my_lib_include:${my_lib_include}")
|
||||
message("legacy_include:${legacy_include}")
|
||||
message("iplature_include:${iplature_include}")
|
||||
message("ihdb_include:${ihdb_include}")
|
||||
message("memcache_include:${memcache_include}")
|
||||
|
||||
|
||||
|
||||
set_target_properties(ProxyTest PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${bin_dir})
|
||||
|
||||
# ###################### add test ########################
|
||||
# 1. loss_compress_test
|
||||
#
|
||||
# ##############################################################################
|
||||
# include(../cmake_include/unit_test.cmake)
|
||||
|
||||
# add_executable(loss_compress_test ${DISTRIBUTION} test/loss_compress_test.cc)
|
||||
# target_link_libraries(loss_compress_test ${LINK_OPTION}
|
||||
# Boost::unit_test_framework)
|
||||
# target_include_directories(
|
||||
# loss_compress_test PUBLIC ./ ../ ../../inc ../../inc/dbinc
|
||||
# ${iPlature_include})
|
||||
|
||||
# set_target_properties(loss_compress_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY
|
||||
# ${UNIT_TEST_BIN_OUTPUT_DIR})
|
||||
|
||||
# enable_testing()
|
||||
# add_test(
|
||||
# NAME loss_compress_test
|
||||
# WORKING_DIRECTORY ${UNIT_TEST_BIN_OUTPUT_DIR}
|
||||
# COMMAND loss_compress_test)
|
||||
30
TestProject/ProxyTest/ProxyTest.cc
Normal file
30
TestProject/ProxyTest/ProxyTest.cc
Normal file
@ -0,0 +1,30 @@
|
||||
#include <TestProject/ProxyTest/ProxyTest.h>
|
||||
#include <TestProject/ProxyTest/ProxyTest_icei.h>
|
||||
#include <glob/GlobDefine.h>
|
||||
#include <utility/IniProperty.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "mix_cc/debug/pre_define.h"
|
||||
|
||||
using namespace baosight;
|
||||
|
||||
ProxyTest::ProxyTest() { logger_ = std::make_unique<LOG>("ProxyTest"); }
|
||||
|
||||
ProxyTest::~ProxyTest() {}
|
||||
|
||||
int ProxyTest::start() {
|
||||
logger_->Info() << "-------ProxyTest::start-------" << std::endl;
|
||||
try {
|
||||
auto module_name = name();
|
||||
ProxyTest_server = new ProxyTestICEI();
|
||||
this->add(string("baosight/") + name(), ProxyTest_server);
|
||||
} catch (::Ice::LocalException& e) {
|
||||
logger_->Error() << "Can not add baosight/ProxyTest, error: " << e << endl;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// PACE_SERVER_INSTALL(ProxyTest) //应用程序主入口,传入参数为定义的类名
|
||||
PACE_PLATFORM_SERVER_INSTALL(ProxyTest, APPVERSION);
|
||||
39
TestProject/ProxyTest/ProxyTest.h
Normal file
39
TestProject/ProxyTest/ProxyTest.h
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#include <TestProject/ProxyTest/ProxyTest_icei.h>
|
||||
#include <glob/ConnectionMag.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <pace/Component.h>
|
||||
#include <pace/pace.h>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace baosight {
|
||||
/**
|
||||
* @brief 负载程序的启动和初始变量信息的加载
|
||||
*/
|
||||
class ProxyTest : public Component {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new ProxyTest object
|
||||
*/
|
||||
ProxyTest();
|
||||
|
||||
/**
|
||||
* @brief Destroy the ProxyTest object
|
||||
*/
|
||||
virtual ~ProxyTest();
|
||||
|
||||
/**
|
||||
* @brief 启动进程
|
||||
* @return int
|
||||
*/
|
||||
virtual int start();
|
||||
|
||||
private:
|
||||
MessageICEPtr ProxyTest_server; ///< Ice通信模块
|
||||
std::unique_ptr<LOG> logger_;
|
||||
};
|
||||
}; // namespace baosight
|
||||
48
TestProject/ProxyTest/ProxyTest_icei.cc
Normal file
48
TestProject/ProxyTest/ProxyTest_icei.cc
Normal file
@ -0,0 +1,48 @@
|
||||
|
||||
#include <TestProject/ProxyTest/ProxyTest_icei.h>
|
||||
#include <common/L2Event.h>
|
||||
#include <dao/DbStandardDBAX.h>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
ProxyTestICEI::ProxyTestICEI() {
|
||||
this->logger_ = std::make_unique<LOG>("ProxyTest_icei");
|
||||
string proxyName = "baosight/pyml";
|
||||
send2pyml_ = ProxyMag::GetAppICEPrx(proxyName);
|
||||
// send2pyml_ =
|
||||
// ProxyMag::GetAppICEPrx("baosight/pyml:tcp -h 192.1.130.25 -p 12011");
|
||||
}
|
||||
|
||||
ProxyTestICEI::~ProxyTestICEI() {}
|
||||
|
||||
void baosight::ProxyTestICEI::SendDataShort(::Ice::Int eventNo,
|
||||
const ::Ice::ByteSeq& seq,
|
||||
::Ice::Int length,
|
||||
const Ice::Current& current) {
|
||||
if (eventNo == 13) {
|
||||
logger_->Debug() << "Test:" << eventNo << ",size:" << seq.size() << endl;
|
||||
}
|
||||
// string data(seq.begin(), seq.end());
|
||||
logger_->Info() << "ProxyTestICEI::SendDataShort:" << endl;
|
||||
|
||||
// send2pyml_->SendDataShort(eventNo, seq, length);
|
||||
// logger_->Info() << "ProxyTestICEI::SendDataShort 结束!" << endl;
|
||||
}
|
||||
|
||||
void baosight::ProxyTestICEI::SendDataLong(
|
||||
::Ice::Int eventNo, const ::Ice::ByteSeq& seq, ::Ice::Int length,
|
||||
const ::std::string& sender, const ::std::string& receiver,
|
||||
const ::std::string& additional, const Ice::Current& current) {}
|
||||
|
||||
void baosight::ProxyTestICEI::TimeNotify(::Ice::Int eventNo,
|
||||
const ::Ice::ByteSeq& seq,
|
||||
const Ice::Current& current) {
|
||||
logger_->Debug() << "ProxyTest" << endl;
|
||||
// string proxyName = "baosight/ptest1";
|
||||
// string keyValue = "ProxyTest 2 baosight/ptest1!";
|
||||
// int length = keyValue.size();
|
||||
// ::Ice::ByteSeq sendData((unsigned char*)keyValue.c_str(),
|
||||
// (unsigned char*)keyValue.c_str() + length);
|
||||
// ProxyMag::GetAppICEPrx(proxyName)->SendDataShort(eventNo, sendData,
|
||||
// sendData.size());
|
||||
}
|
||||
49
TestProject/ProxyTest/ProxyTest_icei.h
Normal file
49
TestProject/ProxyTest/ProxyTest_icei.h
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
#pragma once
|
||||
#include <common/L2Event.h>
|
||||
#include <dao/DbStandardDBAX.h>
|
||||
#include <glob/ProxyMag.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <proxy/MessageICE.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
namespace baosight {
|
||||
|
||||
/**
|
||||
* @brief Ice接口类实现,其中包含了对不同电文的调用
|
||||
*/
|
||||
class ProxyTestICEI : virtual public MessageICE {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Eqp Alg I C E I object
|
||||
*/
|
||||
ProxyTestICEI();
|
||||
virtual ~ProxyTestICEI();
|
||||
|
||||
/**
|
||||
* @brief 简单数据调用接口
|
||||
*/
|
||||
virtual void SendDataShort(::Ice::Int, const ::Ice::ByteSeq&, ::Ice::Int,
|
||||
const Ice::Current&);
|
||||
|
||||
/**
|
||||
* @brief 复杂数据调用接口
|
||||
*/
|
||||
virtual void SendDataLong(::Ice::Int, const ::Ice::ByteSeq&, ::Ice::Int,
|
||||
const ::std::string&, const ::std::string&,
|
||||
const ::std::string&, const Ice::Current&);
|
||||
|
||||
/**
|
||||
* @brief 定时器调用接口
|
||||
*/
|
||||
virtual void TimeNotify(::Ice::Int, const ::Ice::ByteSeq&,
|
||||
const Ice::Current&);
|
||||
|
||||
private:
|
||||
std::unique_ptr<LOG> logger_; ///< 本地logger
|
||||
baosight::MessageICEPrx send2pyml_;
|
||||
};
|
||||
|
||||
} // namespace baosight
|
||||
55
TestProject/ProxyTest/mix_tools.0000h
Normal file
55
TestProject/ProxyTest/mix_tools.0000h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file mix_tools.h
|
||||
* @brief 1.计算综合评价指标
|
||||
* @author your name (you@domain.com)
|
||||
* @version 0.1
|
||||
* @date 2024-01-24
|
||||
*
|
||||
* Copyright: Baosight Co. Ltd.
|
||||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||||
*
|
||||
*/
|
||||
#include <eigen3/Eigen/Eigen>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
using std::map;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
namespace MixTools {
|
||||
/**
|
||||
* @brief 计算综合评价指标
|
||||
* @param ref My Param doc
|
||||
* @param act My Param doc
|
||||
* @return double
|
||||
*/
|
||||
double CalCEI(vector<double> ref, vector<double> act);
|
||||
/**
|
||||
* @brief 计算要求情况的位置
|
||||
* @param data My Param doc
|
||||
* @param isStart My Param doc
|
||||
* @return vector<int>
|
||||
*/
|
||||
vector<int> CalPos(Eigen::VectorXd data, string fun);
|
||||
|
||||
using TwoArgFun = std::function<bool(double, double)>;
|
||||
/**
|
||||
* @brief 从0到1
|
||||
* @param last My Param doc
|
||||
* @param now My Param doc
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool check_start(double last, double now);
|
||||
/**
|
||||
* @brief 从1到0
|
||||
* @param last My Param doc
|
||||
* @param now My Param doc
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool check_end(double last, double now);
|
||||
|
||||
} // namespace MixTools
|
||||
29
TestProject/ProxyTest/mix_tools.000cc
Normal file
29
TestProject/ProxyTest/mix_tools.000cc
Normal file
@ -0,0 +1,29 @@
|
||||
#include "mix_tools.h"
|
||||
|
||||
namespace {
|
||||
const map<string, MixTools::TwoArgFun> Funs = {{"start", check_start}, {"end", check_end}}
|
||||
}
|
||||
namespace MixTools {
|
||||
double CalCEI(vector<double> ref, vector<double> act) {
|
||||
int data_size = ref.size();
|
||||
if (size != act.size() || ref.empty()) {
|
||||
return -1;
|
||||
} else {
|
||||
double cei = 0;
|
||||
for (int i = 0; i < data_size; i++) {
|
||||
cei += fabs(ref[i] - act[i]);
|
||||
}
|
||||
return cei / double(data_size);
|
||||
}
|
||||
}
|
||||
|
||||
vector<int> CalPos(Eigen::VectorXd data, string fun) {}
|
||||
|
||||
bool check_start(double last, double now) {
|
||||
return int(last) == 0 && int(now) == 1;
|
||||
}
|
||||
|
||||
bool check_end(double last, double now) {
|
||||
return int(last) == 1 && int(now) == 0;
|
||||
}
|
||||
} // namespace MixTools
|
||||
42
TestProject/ProxyTest/shm/item_data.h
Normal file
42
TestProject/ProxyTest/shm/item_data.h
Normal file
@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file item_data.h
|
||||
* @brief 查询ihd在一段时间的数据,最多1024个tag点
|
||||
* @author your name (you@domain.com)
|
||||
* @version 0.1
|
||||
* @date 2024-01-11
|
||||
*
|
||||
* Copyright: Baosight Co. Ltd.
|
||||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||||
*
|
||||
*/
|
||||
#include <mix_cc/shm.h>
|
||||
namespace ItemShm {
|
||||
namespace SHM = mix_cc::shm;
|
||||
namespace bipc = mix_cc::shm::bip;
|
||||
|
||||
const static std::string dir_path = "/users/dsc/shm";
|
||||
const static std::string shm_file = "ItemData"; ///<映射文件名
|
||||
const double data_size = 1024; ///< 数据大小 MB
|
||||
const int max_item_num = 1024; ///<最大数据个数
|
||||
static bipc::managed_mapped_file obj_mapped_file(
|
||||
bipc::open_or_create, (dir_path + "/" + shm_file + "_boost.mmap").c_str(),
|
||||
mix_cc::data_size::MB(data_size));
|
||||
|
||||
typedef double ItemData[max_item_num]; ///<一个时间点上,所有item的数据值
|
||||
|
||||
struct IhdTimeRecord {
|
||||
int stime; ///<查询的开始时间
|
||||
int etime; ///<查询的结束时间
|
||||
int data_size; ///<查询的数据长度
|
||||
};
|
||||
|
||||
/*单例 vector item的数据,每个原始位一个时间戳的所有数据,最长1024个tag点*/
|
||||
const static bipc::offset_ptr<SHM::Vector<ItemData>> ItemDataPtr =
|
||||
SHM::VectorBuilder<ItemData>::find_or_construct(&obj_mapped_file, shm_file);
|
||||
|
||||
/*单例 TimeRecord 保持 记录的起止时间*/
|
||||
const static bipc::offset_ptr<IhdTimeRecord> IhdTimeRecordPtr =
|
||||
obj_mapped_file.find_or_construct<IhdTimeRecord>("IhdTimeRecord")();
|
||||
|
||||
} // namespace ItemShm
|
||||
63
TestProject/PyProject/ptest1.py
Normal file
63
TestProject/PyProject/ptest1.py
Normal file
@ -0,0 +1,63 @@
|
||||
#!/users/dsc/bin/Python3
|
||||
#-*-coding: UTF-8 -*-
|
||||
import IcePy
|
||||
import sys,traceback,Ice,os
|
||||
import MessageICE_ice
|
||||
import time
|
||||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
|
||||
module_name="ptest1"#本模块名
|
||||
target_module_name="ProxyTest"#ice发送目标模块名
|
||||
_M_baosight = Ice.openModule('baosight')
|
||||
log_file='/iPlature/log/{}.log'.format(module_name)
|
||||
max_bytes=10* 1024 * 1024#日志大小10M
|
||||
backup_count=20#日志数量
|
||||
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.INFO)
|
||||
formatter = logging.Formatter('%(asctime)s|%(levelname)s| %(message)s')
|
||||
filehandler = logging.handlers.RotatingFileHandler(log_file, mode='a', maxBytes=max_bytes, backupCount=backup_count)#每 1024Bytes重写一个文件,保留2(backupCount) 个旧文件
|
||||
filehandler.setFormatter(formatter)
|
||||
logger.addHandler(filehandler)
|
||||
|
||||
class Ptest1(MessageICE_ice._M_baosight.MessageICE):
|
||||
def SendDataShort(self, eventNo, seq, length, context=None):
|
||||
logger.info("SendDataShort eventNo:"+str(eventNo))
|
||||
logger.info(seq)
|
||||
|
||||
def SendDataLong(self, eventNo, seq, length, context=None):
|
||||
logger.info("eventNo:"+str(eventNo))
|
||||
|
||||
def TimeNotify(self, eventNo, seq, length, context=None):
|
||||
logger.info("TimeNotify eventNo:"+str(eventNo))
|
||||
with Ice.initialize(sys.argv) as communicator:
|
||||
base = communicator.stringToProxy("baosight/{}".format(target_module_name)).ice_oneway().ice_secure(False)
|
||||
proxy = _M_baosight.MessageICEPrx.uncheckedCast(base)
|
||||
if not proxy:
|
||||
logging.error("invalid proxy")
|
||||
sys.exit(1)
|
||||
# seq= ("{} 2 {}".format(module_name,target_module_name)).decode("utf-8")
|
||||
seq=b'Test py - c++'
|
||||
proxy.SendDataShort(eventNo, seq,len(seq))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
default={
|
||||
"identity":"baosight/{}".format(module_name),#identity
|
||||
"adapterName":"DefaultAdapter",
|
||||
"endpoints":"tcp",
|
||||
"entry":Ptest1()
|
||||
}
|
||||
with Ice.initialize(sys.argv) as communicator:
|
||||
print("start")
|
||||
properties = communicator.getProperties()
|
||||
adapter = communicator.createObjectAdapterWithEndpoints(default["adapterName"],default["endpoints"])
|
||||
identity = properties.getProperty("Identity")
|
||||
if identity == None or identity == "":
|
||||
identity = default["identity"]
|
||||
print("identity" + identity)
|
||||
id = Ice.stringToIdentity(identity)
|
||||
adapter.add(default["entry"], id)
|
||||
adapter.activate()
|
||||
communicator.waitForShutdown()
|
||||
18
TestProject/PyProject/testpkl.py
Normal file
18
TestProject/PyProject/testpkl.py
Normal file
@ -0,0 +1,18 @@
|
||||
#!/users/dsc/bin/Python3
|
||||
#-*-coding: UTF-8 -*-
|
||||
# from Serialization import Serialization,Deserialization
|
||||
# a={"a":1,"b":2}
|
||||
# file_name="test"
|
||||
# c=Serialization(file_name,a)
|
||||
# print(c)
|
||||
# b={"c":3,"d":4}
|
||||
# e=Deserialization(file_name)
|
||||
# if(e):
|
||||
# print("e---")
|
||||
# print(e)
|
||||
# print(a)
|
||||
# print(b)
|
||||
from mntest import mnTest,mnTrain
|
||||
print(mnTrain)
|
||||
|
||||
|
||||
28
TestProject/RNG/BaseData.h
Normal file
28
TestProject/RNG/BaseData.h
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#include <mlpack/core.hpp>
|
||||
#include <mlpack/core/data/split_data.hpp>
|
||||
namespace BaseData {
|
||||
using namespace mlpack;
|
||||
using namespace arma;
|
||||
const size_t MaxNum = 36000;
|
||||
struct BaseData {
|
||||
static arma::vec vec1;
|
||||
struct Init {
|
||||
static arma::vec init(double x0, double xn) {
|
||||
arma::vec vec2;
|
||||
vec2.ones(MaxNum*2);
|
||||
for (int i = 0; i < MaxNum; i++) {
|
||||
vec2[i] = x0 + i * (xn - x0) / (double)MaxNum;
|
||||
vec2[MaxNum+i] = xn - i * (xn - x0) / (double)MaxNum;
|
||||
}
|
||||
return vec2;
|
||||
}
|
||||
};
|
||||
|
||||
double operator()(size_t index) { return vec1[index % (2*MaxNum)]; }
|
||||
};
|
||||
|
||||
// arma::vec BaseData::BaseData::vec1
|
||||
arma::vec BaseData::vec1 = BaseData::Init::init(600, 300);
|
||||
|
||||
}; // namespace BaseData
|
||||
77
TestProject/RNG/CMakeLists.txt
Normal file
77
TestProject/RNG/CMakeLists.txt
Normal file
@ -0,0 +1,77 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(RNG VERSION 0.1)
|
||||
|
||||
set(CONFIG_FILE_PATH "config.json")
|
||||
|
||||
include(../../cmake_include/public.cmake)
|
||||
include(../../cmake_include/baosight.cmake)
|
||||
include(../../cmake_include/mix_cc.cmake)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-omit-frame-pointer -Wno-deprecated-declarations")
|
||||
|
||||
find_package(mlpack CONFIG REQUIRED)
|
||||
find_package(Armadillo CONFIG REQUIRED)
|
||||
|
||||
aux_source_directory(./ DIR_ROOT)
|
||||
|
||||
|
||||
set(LINK_OPTION
|
||||
${ICE}
|
||||
${IPLATURE}
|
||||
${SQL}
|
||||
${FREEZE}
|
||||
${BASE_LIB}
|
||||
${CODE_LIB}
|
||||
${IDA}
|
||||
${LEGACY_JSON}
|
||||
${IHDB_LIB}
|
||||
rt
|
||||
stdc++
|
||||
c
|
||||
m
|
||||
)
|
||||
|
||||
add_executable(
|
||||
RNG
|
||||
${DIR_ROOT}
|
||||
)
|
||||
|
||||
target_link_libraries(RNG
|
||||
${LINK_OPTION}
|
||||
mlpack::mlpack)
|
||||
|
||||
target_include_directories(
|
||||
RNG
|
||||
PUBLIC ./
|
||||
../
|
||||
${my_lib_include}
|
||||
${legacy_include}
|
||||
${iplature_include}
|
||||
${ihdb_include}
|
||||
${memcache_include}
|
||||
${}
|
||||
${iXcom}Include)
|
||||
|
||||
set_target_properties(RNG PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${bin_dir})
|
||||
|
||||
# ###################### add test ########################
|
||||
# 1. loss_compress_test
|
||||
#
|
||||
# ##############################################################################
|
||||
# include(../cmake_include/unit_test.cmake)
|
||||
|
||||
# add_executable(loss_compress_test ${DISTRIBUTION} test/loss_compress_test.cc)
|
||||
# target_link_libraries(loss_compress_test ${LINK_OPTION}
|
||||
# Boost::unit_test_framework)
|
||||
# target_include_directories(
|
||||
# loss_compress_test PUBLIC ./ ../ ../../inc ../../inc/dbinc
|
||||
# ${iPlature_include})
|
||||
|
||||
# set_target_properties(loss_compress_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY
|
||||
# ${UNIT_TEST_BIN_OUTPUT_DIR})
|
||||
|
||||
# enable_testing()
|
||||
# add_test(
|
||||
# NAME loss_compress_test
|
||||
# WORKING_DIRECTORY ${UNIT_TEST_BIN_OUTPUT_DIR}
|
||||
# COMMAND loss_compress_test)
|
||||
208
TestProject/RNG/Generator.cc
Normal file
208
TestProject/RNG/Generator.cc
Normal file
@ -0,0 +1,208 @@
|
||||
|
||||
#include <TestProject/RNG/BaseData.h>
|
||||
#include <TestProject/RNG/Generator.h>
|
||||
#include <TestProject/RNG/RandT.h>
|
||||
#include <TestProject/RNG/read_csv.hpp>
|
||||
BaseData::BaseData data1;
|
||||
// ReadCSV::DoubleData ddata("D102-1#酸槽数据.csv"); ///< 2列:入口流量,出口流量
|
||||
ReadCSV::DoubleData
|
||||
ddata("数据毛刺-仿真.csv"); ///< 4列:实际速度,实际电流,设定速度,spderr
|
||||
ReadCSV::DoubleData gdata("毛刺数据.csv"); ///< 6列:RW_o_Drv_ActSpd
|
||||
///< RW_o_Drv_Current
|
||||
///< RW_o_Drv_TQ_Ref
|
||||
///< RW_o_Drv_SpdRegInt
|
||||
///< RW_o_Drv_SpdErr RW_o_Drv_AVF
|
||||
ReadCSV::DoubleData spbdata(
|
||||
"转矩减小-速度偏差大-仿真2.csv"); ///< 4列:实际速度,实际电流,实际转矩,设定速度
|
||||
ReadCSV::DoubleData
|
||||
liquid_data("液位.csv"); ///< 4列:实际速度,实际电流,实际转矩,设定速度
|
||||
// ReadCSV::IntData idata("D302-压辊数据.csv"); ///< 2列:阀动作,接近开关信号
|
||||
ReadCSV::IntData
|
||||
idata("C308仿-压辊数据.csv"); ///< 3列:阀动作- 开,接近开关信号-开,阀动作-关
|
||||
ReadCSV::DoubleData
|
||||
ddata_cn("D102-3#BR电流数据.csv"); ///< 4列:2/3/4电流,速度设定值
|
||||
ReadCSV::DoubleData
|
||||
ddata_cb("D102-3#BR异常电流数据.csv"); ///< 4列:2/3/4电流,速度设定值
|
||||
|
||||
ReadCSV::IntData car_data("D302-2#小车减速位.csv"); ///< 2列:位置,接近开关
|
||||
ReadCSV::DoubleData std1_wr("D302-1#机架正弯.csv"); ///< 2列:给定,反馈
|
||||
ReadCSV::DoubleData std5_wr("D302-工作辊正弯DS.csv"); ///< 2列:给定,反馈
|
||||
ReadCSV::DoubleData loop3("D302-3#活套1-5电流.csv"); ///< 5列:1-5电机电流
|
||||
ReadCSV::DoubleData c308fur2col("C308速度毛刺仿真.csv"); ///< 2列 正常 毛刺
|
||||
ReadCSV::IntData
|
||||
std4_cr("D102-4#机架上中间辊窜辊.csv"); ///< 5列:编码器-4个窜动
|
||||
ReadCSV::IntData loop8_bool("D102-loop8.csv"); ///< 2列:DS,OS
|
||||
|
||||
Generator::Generator() {
|
||||
stime = chrono::system_clock::now();
|
||||
logger_ = std::make_unique<LOG>("Generator");
|
||||
}
|
||||
Generator::~Generator() {
|
||||
// if (!map_tables_.empty()) {
|
||||
// auto iter = map_tables_.begin();
|
||||
// while (iter != map_tables_.end()) {
|
||||
// delete iter->second;
|
||||
// iter->second = nullptr;
|
||||
// map_tables_.erase(iter++);
|
||||
// }
|
||||
// }
|
||||
for (auto &it : m_mapfix) {
|
||||
if (it.second != nullptr) {
|
||||
delete it.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
bool Generator::wtite_in_shm(int event_no) {
|
||||
try {
|
||||
// if (map_tables_.find(event_no) == map_tables_.end()) {
|
||||
// map_tables_[event_no] =
|
||||
// new CMemTable<PLC_DATA>(StringHelper::ToString<int>(event_no),
|
||||
// 100);
|
||||
// }
|
||||
// logger_->Debug() << "wtite_in_shm Test--1" << endl;
|
||||
if (m_mapfix.find(event_no) == m_mapfix.end()) {
|
||||
m_mapfix.insert(
|
||||
make_pair(event_no, new CMemFix<PLC_DATA>(std::to_string(event_no),
|
||||
TEL_CACHE_SIZE)));
|
||||
}
|
||||
|
||||
binary_tele.ReBuild(event_no);
|
||||
int size = binary_tele.size();
|
||||
// binary_tele.Print();
|
||||
size_t data_index =
|
||||
((chrono::system_clock::now() - stime).count() / (size_t)pow(10, 6)) /
|
||||
20; ///<时间-下标
|
||||
logger_->Debug() << "wtite_in_shm Test--2"
|
||||
<< "---data_index:" << data_index << endl;
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (binary_tele[i].type[0] == 'b') {
|
||||
/*bool量*/
|
||||
if (binary_tele[i].length != '1') {
|
||||
binary_tele[i] = RandT::randomBool();
|
||||
if (strcmp(binary_tele[i].item, "3G-DSA-B01-01B") == 0) {
|
||||
/*2#张力辊压辊打开*/
|
||||
binary_tele[i] = (float)idata(data_index, 0);
|
||||
} else if (strcmp(binary_tele[i].item, "3G-PX-B01-01") == 0) {
|
||||
/*2#张力辊压辊打开位*/
|
||||
binary_tele[i] = (float)idata(data_index, 1);
|
||||
} else if (strcmp(binary_tele[i].item, "3G-DSA-B01-01A") == 0) {
|
||||
/*2#张力辊压辊关闭*/
|
||||
binary_tele[i] = (float)idata(data_index, 2);
|
||||
}
|
||||
|
||||
else if (strcmp(binary_tele[i].item, "ENT_DR_2R22_limi") == 0) {
|
||||
/*No.2入口钢卷小车-后退极限接近开关*/
|
||||
binary_tele[i] = (float)car_data(data_index, 1);
|
||||
} else if (strcmp(binary_tele[i].item, "ENT_DR_2R11_act") == 0) {
|
||||
/*4#机架窜辊动作1*/
|
||||
binary_tele[i] = (float)std4_cr(data_index, 1);
|
||||
} else if (strcmp(binary_tele[i].item, "ENT_DR_2R12_act") == 0) {
|
||||
/*4#机架窜辊动作2*/
|
||||
binary_tele[i] = (float)std4_cr(data_index, 2);
|
||||
} else if (strcmp(binary_tele[i].item, "ENT_DR_2R11_limi") == 0) {
|
||||
/*4#机架窜辊动作3*/
|
||||
binary_tele[i] = (float)std4_cr(data_index, 3);
|
||||
} else if (strcmp(binary_tele[i].item, "ENT_DR_2R12_limi") == 0) {
|
||||
/*4#机架窜辊动作4*/
|
||||
binary_tele[i] = (float)std4_cr(data_index, 4);
|
||||
} else if (strcmp(binary_tele[i].item, "ENT_DR_2_run") == 0) {
|
||||
/*入口活套-No.8摆动门传动侧关闭极限接近开关*/
|
||||
binary_tele[i] = (float)loop8_bool(data_index, 0);
|
||||
} else if (strcmp(binary_tele[i].item, "ENT_DR_2_Ft") == 0) {
|
||||
/*入口活套-No.8摆动门操作侧关闭极限接近开关*/
|
||||
binary_tele[i] = (float)loop8_bool(data_index, 1);
|
||||
}
|
||||
|
||||
} else {
|
||||
logger_->Error() << "event_no:" << event_no << ",数据项:"
|
||||
<< binary_tele[i].chinese
|
||||
<< ",item:" << binary_tele[i].item
|
||||
<< "类型长度不匹配,"
|
||||
<< "type:" << binary_tele[i].type
|
||||
<< ",lenth:" << binary_tele[i].length << std::endl;
|
||||
}
|
||||
} else {
|
||||
/*模拟量*/
|
||||
strcpy((char *)binary_tele[i].value, binary_tele[i].defaultValue);
|
||||
float dataN = binary_tele[i];
|
||||
binary_tele[i] = float(dataN + RandT::RandT(-0.01, 0.01));
|
||||
|
||||
if (strcmp(binary_tele[i].item, "BR1_1_V_act") == 0) {
|
||||
/*1#张力辊1#辊 实际速度*/
|
||||
binary_tele[i] =
|
||||
(float)binary_tele[i] + (float)c308fur2col(data_index, 1);
|
||||
} else if (strcmp(binary_tele[i].item, "BR1_2_V_act") == 0) {
|
||||
/*2#张力辊1#辊 设定速度*/
|
||||
binary_tele[i] =
|
||||
(float)binary_tele[i] + (float)c308fur2col(data_index, 0);
|
||||
} else if (strcmp(binary_tele[i].item, "BR2_1_V_act") == 0) {
|
||||
/*2#张力辊1#辊 实际电流*/
|
||||
binary_tele[i] =
|
||||
(float)binary_tele[i] + (float)c308fur2col(data_index, 0);
|
||||
} else if (strcmp(binary_tele[i].item, "BR2_2_V_act") == 0) {
|
||||
/*2#张力辊2#辊 实际速度*/
|
||||
binary_tele[i] =
|
||||
(float)binary_tele[i] + (float)c308fur2col(data_index, 1);
|
||||
} else if (strcmp(binary_tele[i].item, "BR2_2_I_act") == 0) {
|
||||
/*2#张力辊2#辊 实际电流*/
|
||||
binary_tele[i] = (float)spbdata(data_index, 1);
|
||||
} else if (strcmp(binary_tele[i].item, "BR2_2_TQ_act") == 0) {
|
||||
/*2#张力辊2#辊 实际转矩*/
|
||||
binary_tele[i] = (float)spbdata(data_index, 2);
|
||||
} else if (strcmp(binary_tele[i].item, "IW_3G_LV_J02_03") == 0) {
|
||||
/*入口液压站液位*/
|
||||
binary_tele[i] = (float)liquid_data(data_index, 0);
|
||||
} else if (strcmp(binary_tele[i].item, "TCM-4-82-BDRef-1-118") == 0) {
|
||||
/*1#机架工作辊正弯辊压力给定*/
|
||||
binary_tele[i] = (float)std1_wr(data_index, 0);
|
||||
} else if (strcmp(binary_tele[i].item, "TCM-4-82-BD-1-101") == 0) {
|
||||
/*1#机架工作辊正弯辊压力反馈*/
|
||||
binary_tele[i] = (float)std1_wr(data_index, 1);
|
||||
} else if (strcmp(binary_tele[i].item, "TCM-72-150-BDRef-5-134") == 0) {
|
||||
/*5#机架工作辊DS正弯辊压力给定*/
|
||||
binary_tele[i] = (float)std5_wr(data_index, 0);
|
||||
} else if (strcmp(binary_tele[i].item, "TCM-72-150-BD-5-117") == 0) {
|
||||
/*5#机架工作辊DS正弯辊压力反馈*/
|
||||
binary_tele[i] = (float)std5_wr(data_index, 1);
|
||||
} else if (strcmp(binary_tele[i].item, "ENT_BR_4R1_torfbk") == 0) {
|
||||
/*3#活套1#电机电流*/
|
||||
binary_tele[i] = (float)loop3(data_index, 0);
|
||||
} else if (strcmp(binary_tele[i].item, "ENT_BR_4R2_torfbk") == 0) {
|
||||
/*3#活套2#电机电流*/
|
||||
binary_tele[i] = (float)loop3(data_index, 1);
|
||||
} else if (strcmp(binary_tele[i].item, "ENT_BR_4R3_torfbk") == 0) {
|
||||
/*3#活套3#电机电流*/
|
||||
binary_tele[i] = (float)loop3(data_index, 2);
|
||||
} else if (strcmp(binary_tele[i].item, "ENT_BR_4R3_curfbk") == 0) {
|
||||
/*3#活套4#电机电流*/
|
||||
binary_tele[i] = (float)loop3(data_index, 3);
|
||||
} else if (strcmp(binary_tele[i].item, "ENT_BR_4R1_curfbk") == 0) {
|
||||
/*3#活套5#电机电流*/
|
||||
binary_tele[i] = (float)loop3(data_index, 4);
|
||||
} else if (strcmp(binary_tele[i].item, "ENT_BR_4R2_curfbk") == 0) {
|
||||
/*4#机架上中间辊窜辊编码器*/
|
||||
binary_tele[i] = (float)std4_cr(data_index, 0);
|
||||
} else if (strcmp(binary_tele[i].item, "ACD-3-42-FQ-2") == 0) {
|
||||
/*3#酸槽出口流量 ---Test*/
|
||||
binary_tele[i] = (float)RandT::randomBool();
|
||||
} else {
|
||||
// logger_->Debug() << "test:" << binary_tele[i].item
|
||||
// << ",value:" << binary_tele[i] << endl;
|
||||
}
|
||||
|
||||
// logger_->Debug() << "vale:" << binary_tele[i].value << "," << dataN
|
||||
// << endl;
|
||||
}
|
||||
}
|
||||
// binary_tele.Print();
|
||||
char *buff = binary_tele.GetTeleData();
|
||||
// this->logger_->Debug() << buff << endl;
|
||||
// map_tables_[event_no]->push((PLC_DATA*)buff);
|
||||
m_mapfix[event_no]->push((PLC_DATA *)buff);
|
||||
// ((BinaryTele*)buff)->Print();
|
||||
return true;
|
||||
} catch (const std::exception &e) {
|
||||
logger_->Error() << "wtite_in_shm Error!" << e.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
26
TestProject/RNG/Generator.h
Normal file
26
TestProject/RNG/Generator.h
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <glob/BinaryTele.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <zlib/MemVar.h>
|
||||
#include <zlib/zoneDef.h>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <numeric>
|
||||
#include <string>
|
||||
#include <zlib/MemFix.hpp>
|
||||
#include <zlib/MemTable.hpp>
|
||||
using namespace chrono;
|
||||
class Generator {
|
||||
public:
|
||||
Generator();
|
||||
~Generator();
|
||||
bool wtite_in_shm(int event_no);
|
||||
|
||||
private:
|
||||
std::unique_ptr<LOG> logger_;
|
||||
BinaryTele binary_tele{CMemVar::Const()->event_eis_start, "T_LOV_FDAAITEM"};
|
||||
// map<int, CMemTable<PLC_DATA>*> map_tables_;
|
||||
map<int, CMemFix<PLC_DATA>*> m_mapfix;
|
||||
chrono::system_clock::time_point stime;
|
||||
};
|
||||
32
TestProject/RNG/RNG.cc
Normal file
32
TestProject/RNG/RNG.cc
Normal file
@ -0,0 +1,32 @@
|
||||
#include <TestProject/RNG/RNG.h>
|
||||
#include <TestProject/RNG/RNG_icei.h>
|
||||
#include <glob/GlobDefine.h>
|
||||
#include <utility/IniProperty.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "mix_cc/debug/pre_define.h"
|
||||
|
||||
using namespace baosight;
|
||||
|
||||
RNG::RNG() { logger_ = std::make_unique<LOG>("RNG"); }
|
||||
|
||||
RNG::~RNG() {}
|
||||
|
||||
int RNG::start() {
|
||||
logger_->Info() << "-------RNG::start-------" << std::endl;
|
||||
con_mag_ = std::make_shared<ConnectionMag>();
|
||||
con_mag_->dbLogin();
|
||||
try {
|
||||
auto module_name = name();
|
||||
RNG_server = new RNGICEI();
|
||||
this->add(string("baosight/") + name(), RNG_server);
|
||||
} catch (::Ice::LocalException& e) {
|
||||
logger_->Error() << "Can not add baosight/RNG, error: " << e << endl;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// PACE_SERVER_INSTALL(RNG) //应用程序主入口,传入参数为定义的类名
|
||||
PACE_PLATFORM_SERVER_INSTALL(RNG, APPVERSION);
|
||||
40
TestProject/RNG/RNG.h
Normal file
40
TestProject/RNG/RNG.h
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
#include <TestProject/RNG/RNG_icei.h>
|
||||
#include <glob/ConnectionMag.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <pace/Component.h>
|
||||
#include <pace/pace.h>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace baosight {
|
||||
/**
|
||||
* @brief 负载程序的启动和初始变量信息的加载
|
||||
*/
|
||||
class RNG : public Component {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new RNG object
|
||||
*/
|
||||
RNG();
|
||||
|
||||
/**
|
||||
* @brief Destroy the RNG object
|
||||
*/
|
||||
virtual ~RNG();
|
||||
|
||||
/**
|
||||
* @brief 启动进程
|
||||
* @return int
|
||||
*/
|
||||
virtual int start();
|
||||
|
||||
private:
|
||||
MessageICEPtr RNG_server; ///< Ice通信模块
|
||||
std::shared_ptr<ConnectionMag> con_mag_; ///< DB2连接管理器,邹师傅的模块需要
|
||||
std::unique_ptr<LOG> logger_;
|
||||
};
|
||||
}; // namespace baosight
|
||||
39
TestProject/RNG/RNG_icei.cc
Normal file
39
TestProject/RNG/RNG_icei.cc
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
#include <TestProject/RNG/RNG_icei.h>
|
||||
#include <common/L2Event.h>
|
||||
#include <dao/DbStandardDBAX.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#define CACHE_OUTTIME 50ms
|
||||
|
||||
RNGICEI::RNGICEI() { this->logger_ = std::make_unique<LOG>("RNG_icei"); }
|
||||
|
||||
RNGICEI::~RNGICEI() {}
|
||||
|
||||
void baosight::RNGICEI::SendDataShort(::Ice::Int eventNo,
|
||||
const ::Ice::ByteSeq& seq,
|
||||
::Ice::Int length,
|
||||
const Ice::Current& current) {}
|
||||
|
||||
void baosight::RNGICEI::SendDataLong(
|
||||
::Ice::Int eventNo, const ::Ice::ByteSeq& seq, ::Ice::Int length,
|
||||
const ::std::string& sender, const ::std::string& receiver,
|
||||
const ::std::string& additional, const Ice::Current& current) {}
|
||||
|
||||
void baosight::RNGICEI::TimeNotify(::Ice::Int eventNo,
|
||||
const ::Ice::ByteSeq& seq,
|
||||
const Ice::Current& current) {
|
||||
if (eventNo == 2000) {
|
||||
// logger_->Debug() << "Test!" << endl;
|
||||
generator_.wtite_in_shm(eventNo);
|
||||
logger_->Debug() << "update eventNo:" << eventNo << endl;
|
||||
} else if (eventNo == 2001) {
|
||||
generator_.wtite_in_shm(eventNo);
|
||||
logger_->Debug() << "update eventNo:" << eventNo << endl;
|
||||
} else {
|
||||
generator_.wtite_in_shm(eventNo);
|
||||
logger_->Debug() << "update eventNo:" << eventNo << endl;
|
||||
}
|
||||
// logger_->Debug() << "Test!---------" << std::endl;
|
||||
}
|
||||
49
TestProject/RNG/RNG_icei.h
Normal file
49
TestProject/RNG/RNG_icei.h
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
#pragma once
|
||||
#include <TestProject/RNG/Generator.h>
|
||||
#include <common/L2Event.h>
|
||||
#include <dao/DbStandardDBAX.h>
|
||||
#include <log4cplus/LOG.h>
|
||||
#include <proxy/MessageICE.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
namespace baosight {
|
||||
|
||||
/**
|
||||
* @brief Ice接口类实现,其中包含了对不同电文的调用
|
||||
*/
|
||||
class RNGICEI : virtual public MessageICE {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Eqp Alg I C E I object
|
||||
*/
|
||||
RNGICEI();
|
||||
virtual ~RNGICEI();
|
||||
|
||||
/**
|
||||
* @brief 简单数据调用接口
|
||||
*/
|
||||
virtual void SendDataShort(::Ice::Int, const ::Ice::ByteSeq&, ::Ice::Int,
|
||||
const Ice::Current&);
|
||||
|
||||
/**
|
||||
* @brief 复杂数据调用接口
|
||||
*/
|
||||
virtual void SendDataLong(::Ice::Int, const ::Ice::ByteSeq&, ::Ice::Int,
|
||||
const ::std::string&, const ::std::string&,
|
||||
const ::std::string&, const Ice::Current&);
|
||||
|
||||
/**
|
||||
* @brief 定时器调用接口
|
||||
*/
|
||||
virtual void TimeNotify(::Ice::Int, const ::Ice::ByteSeq&,
|
||||
const Ice::Current&);
|
||||
|
||||
private:
|
||||
std::unique_ptr<LOG> logger_; ///< 本地logger
|
||||
Generator generator_;
|
||||
};
|
||||
|
||||
} // namespace baosight
|
||||
32
TestProject/RNG/RandT.h
Normal file
32
TestProject/RNG/RandT.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <time.h>
|
||||
#include <cmath>
|
||||
namespace RandT {
|
||||
template <typename T>
|
||||
T RandT(T _min, T _max) {
|
||||
T temp;
|
||||
if (_min > _max) {
|
||||
temp = _max;
|
||||
_max = _min;
|
||||
_min = temp;
|
||||
}
|
||||
return rand() / (double)RAND_MAX * (_max - _min) + _min;
|
||||
}
|
||||
|
||||
double GuassRand(double mean = 0, double sigma = 0) {
|
||||
double U1 = rand() * 1.0f / RAND_MAX; // 0~1均匀分布
|
||||
double U2 = rand() * 1.0f / RAND_MAX; // 0~1均匀分布
|
||||
double Z =
|
||||
sqrt(-2 * log(U1)) * cos(2 * M_PI * U2); // 均值为0,方差为1的正态分布
|
||||
double Y;
|
||||
if (sigma >= 0) {
|
||||
Y = mean + sqrt(sigma) * Z;
|
||||
} else {
|
||||
Y = mean + Z;
|
||||
}
|
||||
return Y;
|
||||
}
|
||||
|
||||
bool randomBool() { return 0 + (rand() % (1 - 0 + 1)) == 1; }
|
||||
|
||||
} // namespace RandT
|
||||
68
TestProject/RNG/read_csv.hpp
Normal file
68
TestProject/RNG/read_csv.hpp
Normal file
@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
namespace ReadCSV {
|
||||
using std::string;
|
||||
using std::vector;
|
||||
const string dir_root = "/users/dsc/code/TestProject/data_files";
|
||||
template <typename T>
|
||||
struct ReadCSV {
|
||||
vector<vector<T>> operator()(string file_name) {
|
||||
vector<vector<T>> res;
|
||||
string file_dir = dir_root + "/" + file_name;
|
||||
std::ifstream infile(file_dir, std::ios::in);
|
||||
string line;
|
||||
string word;
|
||||
using std::is_same_v;
|
||||
if (!infile.is_open()) {
|
||||
std::cout << "Error: opening file fail" << std::endl;
|
||||
std::exit(1);
|
||||
}
|
||||
while (std::getline(infile, line)) {
|
||||
std::istringstream sin;
|
||||
sin.str(line);
|
||||
vector<T> line_data;
|
||||
while (std::getline(sin, word, ',')) {
|
||||
if constexpr (is_same_v<T, double>) {
|
||||
line_data.push_back(std::stod(word));
|
||||
} else if constexpr (is_same_v<T, int>) {
|
||||
line_data.push_back(std::stoi(word));
|
||||
}
|
||||
}
|
||||
res.push_back(line_data);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
};
|
||||
using ReadCSVF = ReadCSV<double>;
|
||||
using ReadCSVI = ReadCSV<int>;
|
||||
|
||||
template <typename T>
|
||||
struct FlowData {
|
||||
ReadCSVF readf;
|
||||
ReadCSVI readi;
|
||||
vector<vector<T>> data;
|
||||
int length;
|
||||
int cols;
|
||||
FlowData(string file_name = "D102-1#酸槽数据.csv") {
|
||||
if constexpr (is_same_v<T, double>) {
|
||||
data = readf(file_name);
|
||||
} else if constexpr (is_same_v<T, int>) {
|
||||
data = readi(file_name);
|
||||
}
|
||||
length = data.size();
|
||||
cols = data[0].size();
|
||||
}
|
||||
double operator()(int index, int col) {
|
||||
return data[index % length][col % cols];
|
||||
}
|
||||
};
|
||||
|
||||
using DoubleData = FlowData<double>;
|
||||
using IntData = FlowData<int>;
|
||||
}; // namespace ReadCSV
|
||||
38
TestProject/SHM/EqpmRecord.h
Normal file
38
TestProject/SHM/EqpmRecord.h
Normal file
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @file EqpmShm.h
|
||||
* @brief 共享内存 map,用于将后台规则数据提供给页面使用
|
||||
* @author your name (you@domain.com)
|
||||
* @version 0.1
|
||||
* @date 2023-10-18
|
||||
*
|
||||
* Copyright: Baosight Co. Ltd.
|
||||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include <mutex>
|
||||
#include "shm_header.h"
|
||||
namespace EqpmShm {
|
||||
|
||||
using namespace ShmHeader;
|
||||
|
||||
const static std::string dir_path = "/users/dsc/shm";
|
||||
const static std::string shm_file = "EqpmRecord"; ///<映射文件名
|
||||
const static std::string int_file = "Eqpmtime"; ///<映射文件名
|
||||
const double data_size = 500; ///< 数据大小 MB
|
||||
|
||||
static managed_mapped_file_t obj_mapped_file(
|
||||
bipc::open_or_create, (dir_path + "/" + shm_file + "_boost.mmap").c_str(),
|
||||
mix_cc::data_size::MB(data_size));
|
||||
|
||||
static void_allocator default_allocator(
|
||||
obj_mapped_file.get_segment_manager()); ///<默认分配器
|
||||
|
||||
///<定义数据
|
||||
struct EqpmRecord {
|
||||
int64_t stime;
|
||||
int64_t etime;
|
||||
|
||||
};
|
||||
|
||||
} // namespace EqpmShm
|
||||
287
TestProject/SHM/RuleStatShm.h
Normal file
287
TestProject/SHM/RuleStatShm.h
Normal file
@ -0,0 +1,287 @@
|
||||
/**
|
||||
* @file RuleStatShm.h
|
||||
* @brief 共享内存 map,用于将后台规则数据提供给页面使用
|
||||
* @author your name (you@domain.com)
|
||||
* @version 0.1
|
||||
* @date 2023-10-18
|
||||
*
|
||||
* Copyright: Baosight Co. Ltd.
|
||||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include <mutex>
|
||||
#include "shm_header.h"
|
||||
namespace RuleStatShm {
|
||||
|
||||
using namespace ShmHeader;
|
||||
|
||||
const static std::string dir_path = "/users/dsc/shm";
|
||||
const static std::string shm_file = "MapRuleStat"; ///<映射文件名
|
||||
const double data_size = 500; ///< 数据大小 MB
|
||||
const size_t stat_size_min = 1000; ///<统计样本最小批处理量
|
||||
const size_t stat_size_max = 10000; ///<统计样本最大储存量
|
||||
|
||||
static managed_mapped_file_t obj_mapped_file(
|
||||
bipc::open_or_create, (dir_path + "/" + shm_file + "_boost.mmap").c_str(),
|
||||
mix_cc::data_size::MB(data_size));
|
||||
|
||||
static void_allocator default_allocator(
|
||||
obj_mapped_file.get_segment_manager()); ///<默认分配器
|
||||
|
||||
static char_string key_object("", default_allocator);
|
||||
static char_string key_delete("", default_allocator);
|
||||
|
||||
///<定义数据
|
||||
struct RuleStat {
|
||||
/** 动态数据 规则触发更新 **/
|
||||
double alarm_value = 0; ///<最新报警值
|
||||
double current_value = 0; ///<当前值
|
||||
double limit_up = 0; ///<上限
|
||||
double limit_down = 0; ///<下限
|
||||
vector_s items; ///<数据项
|
||||
vector_d stat_values; ///<统计值,用于cron
|
||||
bool fetch_mark = false; ///<取数据标记
|
||||
|
||||
/** 静态数据 定时更新 **/
|
||||
double running_time = 0; ///<累积的运行时间
|
||||
int64_t shear_times = 0; ///<剪切次数
|
||||
int64_t alarm_times = 0; ///<报警次数
|
||||
bipc::string last_alarm_time = "无报警"; ///<上次报警时间
|
||||
bipc::string dev_coder; ///<设备编码
|
||||
|
||||
RuleStat()
|
||||
: items(default_allocator),
|
||||
stat_values(default_allocator) {} ///<共享内存的内存分配
|
||||
/** 数据操作 **/
|
||||
mix_cc::json invert2json() {
|
||||
mix_cc::json js1;
|
||||
/** 动态数据 规则触发更新 **/
|
||||
js1["alarm_value"] = alarm_value; ///<最新报警值
|
||||
js1["current_value"] = current_value; ///<当前值
|
||||
js1["limit_up"] = limit_up; ///<上限阈值
|
||||
js1["limit_down"] = limit_down; ///<下限阈值
|
||||
js1["items"] = items; ///< tag点
|
||||
|
||||
/** 静态数据 定时更新 **/
|
||||
js1["running_time"] = running_time; ///<统计的运行时间
|
||||
js1["shear_times"] = shear_times; ///<剪切次数
|
||||
js1["alarm_times"] = alarm_times; ///<报警次数
|
||||
js1["last_alarm_time"] = last_alarm_time; ///<上次报警时间
|
||||
js1["dev_coder"] = dev_coder; ///<设备编码
|
||||
return js1;
|
||||
}
|
||||
bool update_dynamic(const RuleStat& value) {
|
||||
alarm_value = value.alarm_value;
|
||||
current_value = value.current_value;
|
||||
limit_up = value.limit_up;
|
||||
limit_down = value.limit_down;
|
||||
items = value.items;
|
||||
}
|
||||
bool update_static(const RuleStat& value) {
|
||||
running_time = value.running_time;
|
||||
shear_times = value.shear_times;
|
||||
alarm_times = value.alarm_times;
|
||||
last_alarm_time = value.last_alarm_time;
|
||||
dev_coder = value.dev_coder;
|
||||
}
|
||||
};
|
||||
|
||||
///< key 是string的情况
|
||||
typedef std::pair<const char_string, RuleStat> pair_s; ///< key-value
|
||||
typedef bipc::node_allocator<pair_s, mapped_segment_manager_t>
|
||||
allocator_s; ///<映射文件
|
||||
typedef std::less<char_string> less_s;
|
||||
typedef bipc::map<char_string, RuleStat, less_s, allocator_s> MapRuleStat_s;
|
||||
typedef MapRuleStat_s::iterator map_iter_s;
|
||||
|
||||
///<定义数据操作
|
||||
struct MapRuleStat {
|
||||
private:
|
||||
MapRuleStat_s* p_msg_map = obj_mapped_file.find_or_construct<MapRuleStat_s>(
|
||||
shm_file.c_str())(less_s(), obj_mapped_file.get_segment_manager());
|
||||
std::mutex local_mutext{}; ///<共享锁
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief 更新 key对应的整个value
|
||||
* @param key My Param doc
|
||||
* @param value My Param doc
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool update(const std::string& key, const RuleStat& value) {
|
||||
std::lock_guard<std::mutex> guard(local_mutext);
|
||||
try {
|
||||
key_object = key.c_str();
|
||||
p_msg_map->operator[](key_object) = value;
|
||||
return true;
|
||||
} catch (const std::exception& e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief 更新 key对应value的动态 或 静态数据
|
||||
* @param key
|
||||
* @param value
|
||||
* @param is_dynamic 是否更新动态数据
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool update_dynamic(const std::string& key, const RuleStat& value,
|
||||
bool is_dynamic = true) {
|
||||
std::lock_guard<std::mutex> guard(local_mutext);
|
||||
try {
|
||||
key_object = key.c_str();
|
||||
if (p_msg_map->find(key_object) != p_msg_map->end()) {
|
||||
if (is_dynamic) {
|
||||
p_msg_map->operator[](key_object).update_dynamic(value);
|
||||
return true;
|
||||
} else {
|
||||
p_msg_map->operator[](key_object).update_static(value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
p_msg_map->operator[](key_object) = value;
|
||||
return true;
|
||||
} catch (const std::exception& e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 删除 key-value
|
||||
* @param key
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool delete_data(const std::string& key) {
|
||||
std::lock_guard<std::mutex> guard(local_mutext);
|
||||
try {
|
||||
key_delete = key.c_str();
|
||||
if (p_msg_map->find(key_delete) != p_msg_map->end()) {
|
||||
p_msg_map->erase(key_delete);
|
||||
}
|
||||
return true;
|
||||
} catch (const std::exception& e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
size_t size() {
|
||||
std::lock_guard<std::mutex> guard(local_mutext);
|
||||
return p_msg_map->size();
|
||||
}
|
||||
|
||||
bool empty() {
|
||||
std::lock_guard<std::mutex> guard(local_mutext);
|
||||
return p_msg_map->empty();
|
||||
}
|
||||
/**
|
||||
* @brief 统计数据存储
|
||||
* @param key My Param doc
|
||||
* @param value My Param doc
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool add_stat_value(const std::string& key, const double& value) {
|
||||
try {
|
||||
std::lock_guard<std::mutex> guard(local_mutext);
|
||||
key_object = key.c_str();
|
||||
if (p_msg_map->operator[](key_object).fetch_mark) {
|
||||
p_msg_map->operator[](key_object).stat_values.clear();
|
||||
p_msg_map->operator[](key_object).fetch_mark = false;
|
||||
}
|
||||
if (p_msg_map->operator[](key_object).stat_values.size() <
|
||||
stat_size_max) {
|
||||
p_msg_map->operator[](key_object).stat_values.push_back(value);
|
||||
}
|
||||
return true;
|
||||
} catch (const std::exception& e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief 获取统计数据
|
||||
* @param key ruleid
|
||||
* @param value 数据结果
|
||||
* @return bool
|
||||
*/
|
||||
bool get_stat_value(const std::string& key, RuleStat& value) {
|
||||
try {
|
||||
std::lock_guard<std::mutex> guard(local_mutext);
|
||||
key_object = key.c_str();
|
||||
if (!p_msg_map->operator[](key_object).fetch_mark &&
|
||||
p_msg_map->operator[](key_object).stat_values.size() >
|
||||
stat_size_min) {
|
||||
value.stat_values = p_msg_map->operator[](key_object).stat_values;
|
||||
p_msg_map->operator[](key_object).fetch_mark = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (const std::exception& e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** find 共享内存数据中, vector<key> 存在的数据
|
||||
* @brief
|
||||
* @param ruleid My Param doc
|
||||
* @return std::vector<std::string>
|
||||
*/
|
||||
std::vector<std::string> find_rule_id(
|
||||
const std::vector<std::string>& ruleid) {
|
||||
std::lock_guard<std::mutex> guard(local_mutext);
|
||||
std::vector<std::string> res;
|
||||
if (p_msg_map->empty()) {
|
||||
return {};
|
||||
}
|
||||
for (auto iter1 = p_msg_map->begin(); iter1 != p_msg_map->end(); iter1++) {
|
||||
auto resV = std::find(ruleid.begin(), ruleid.end(), iter1->first);
|
||||
if (resV != ruleid.end()) {
|
||||
res.push_back(iter1->first);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/** find 共享内存数据中 vector<key> 不存在的数据
|
||||
* @brief
|
||||
* @param ruleid My Param doc
|
||||
* @return std::vector<std::string>
|
||||
*/
|
||||
std::vector<std::string> find_no_rule_id(
|
||||
const std::vector<std::string>& ruleid) {
|
||||
std::lock_guard<std::mutex> guard(local_mutext);
|
||||
std::vector<std::string> res;
|
||||
if (p_msg_map->empty()) {
|
||||
return {};
|
||||
}
|
||||
for (auto iter1 = p_msg_map->begin(); iter1 != p_msg_map->end(); iter1++) {
|
||||
auto resV = std::find(ruleid.begin(), ruleid.end(), iter1->first);
|
||||
if (resV == ruleid.end()) {
|
||||
res.push_back(iter1->first);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 将数据转换成 string
|
||||
* @return std::string;失败为 "ERROR"
|
||||
*/
|
||||
std::string GetDataJson() {
|
||||
std::lock_guard<std::mutex> guard(local_mutext);
|
||||
try {
|
||||
mix_cc::json js1;
|
||||
for (auto iter = p_msg_map->begin(); iter != p_msg_map->end(); iter++) {
|
||||
js1[iter->first] = iter->second.invert2json();
|
||||
}
|
||||
return js1.dump();
|
||||
} catch (const std::exception& e) {
|
||||
return "ERROR";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace RuleStatShm
|
||||
163
TestProject/SHM/SerializeMap.h
Normal file
163
TestProject/SHM/SerializeMap.h
Normal file
@ -0,0 +1,163 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file SerializeMap.h
|
||||
* @brief
|
||||
* @author your name (you@domain.com)
|
||||
* @version 0.1
|
||||
* @date 2023-12-22
|
||||
*
|
||||
* Copyright: Baosight Co. Ltd.
|
||||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||||
*
|
||||
*/
|
||||
#include <boost/archive/text_iarchive.hpp>
|
||||
#include <boost/archive/text_oarchive.hpp>
|
||||
#include <boost/serialization/vector.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include "shm_header.h"
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
namespace SerializeMapShm {
|
||||
|
||||
using namespace ShmHeader;
|
||||
|
||||
const static std::string dir_path =
|
||||
"/users/dsc/code/TestProject/ShmTest/build/";
|
||||
const static std::string shm_file = "SerializeMap"; ///<映射文件名
|
||||
const double data_size = 5; ///< 数据大小 MB
|
||||
static managed_mapped_file_t obj_mapped_file(
|
||||
bipc::open_or_create, (dir_path + "/" + shm_file + "_boost.mmap").c_str(),
|
||||
mix_cc::data_size::MB(data_size));
|
||||
static void_allocator default_allocator(
|
||||
obj_mapped_file.get_segment_manager()); ///<默认分配器
|
||||
|
||||
static char_string key_object("", default_allocator);
|
||||
static char_string value_object("", default_allocator);
|
||||
///< key 是string的情况
|
||||
typedef std::pair<const char_string, bipc::string> pair_ss; ///< key-value
|
||||
typedef bipc::node_allocator<pair_ss, mapped_segment_manager_t>
|
||||
allocator_ss; ///<映射文件
|
||||
typedef std::less<char_string> less_s;
|
||||
typedef bipc::map<char_string, bipc::string, less_s, allocator_ss> SerializeMap;
|
||||
typedef SerializeMap::iterator SerializeMapiter;
|
||||
|
||||
namespace {
|
||||
static bipc::offset_ptr<SerializeMap> SerializeMapPtr =
|
||||
obj_mapped_file.find_or_construct<SerializeMap>(shm_file.c_str())(
|
||||
less_s(), obj_mapped_file.get_segment_manager());
|
||||
|
||||
std::mutex local_mutext{}; ///<共享锁
|
||||
} // namespace
|
||||
|
||||
/**
|
||||
* @brief 反序列化的对象一定要确保带有空参构造函数,这是一个线程安全的版本
|
||||
* @tparam Tp
|
||||
* @param data My Param doc
|
||||
* @return std::string
|
||||
*/
|
||||
template <typename Tp>
|
||||
std::string serialize(Tp data) {
|
||||
std::ostringstream oss;
|
||||
boost::archive::text_oarchive oa(oss);
|
||||
boost::serialization::save(oa, data, 0);
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 反序列化的对象一定要确保带有空参构造函数
|
||||
* @tparam Tp
|
||||
* @param str My Param doc
|
||||
* @return Tp
|
||||
*/
|
||||
template <typename Tp>
|
||||
Tp deserialize(std::string str) {
|
||||
Tp data;
|
||||
std::stringstream ss;
|
||||
ss << str;
|
||||
boost::archive::text_iarchive ia(ss);
|
||||
boost::serialization::load(ia, data, 0);
|
||||
return data;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @brief 反序列化的对象一定要确保带有空参构造函数,这是一个线程安全的版本
|
||||
// * @tparam Tp
|
||||
// * @param data My Param doc
|
||||
// * @return std::string
|
||||
// */
|
||||
// template <typename Tp>
|
||||
// std::string serialize(Tp data) {
|
||||
// std::stringstream ss;
|
||||
// boost::archive::text_oarchive oa(ss);
|
||||
// oa << data;
|
||||
// return ss.str();
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @brief 反序列化的对象一定要确保带有空参构造函数
|
||||
// * @tparam Tp
|
||||
// * @param str My Param doc
|
||||
// * @return Tp
|
||||
// */
|
||||
// template <typename Tp>
|
||||
// Tp deserialize(std::string str) {
|
||||
// std::stringstream ss;
|
||||
// ss << str;
|
||||
// boost::archive::text_iarchive ia(ss);
|
||||
// Tp i;
|
||||
// ia >> i;
|
||||
// return i;
|
||||
// }
|
||||
|
||||
bool delete_data(const std::string& key) {
|
||||
key_object = key.c_str();
|
||||
if (SerializeMapPtr.get()->find(key_object) == SerializeMapPtr.get()->end()) {
|
||||
return false;
|
||||
} else {
|
||||
SerializeMapPtr.get()->erase(key_object);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool insert(const std::string& key, T data) {
|
||||
key_object = key.c_str();
|
||||
cout << "key_object:" << key_object << endl;
|
||||
std::lock_guard<std::mutex> guard(local_mutext);
|
||||
std::string res = serialize(data);
|
||||
cout << res << endl;
|
||||
if (res.size() != 0) {
|
||||
try {
|
||||
if (SerializeMapPtr.get()->find(key_object) ==
|
||||
SerializeMapPtr.get()->end()) {
|
||||
SerializeMapPtr.get()->operator[](key_object) = res;
|
||||
cout << "key_object:" << key_object << ",不存在" << endl;
|
||||
} else {
|
||||
cout << "key_object:" << key_object << ",已存在" << endl;
|
||||
}
|
||||
return true;
|
||||
} catch (const std::exception& e) {
|
||||
cout << e.what() << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T get_data(const std::string& key) {
|
||||
try {
|
||||
key_object = key.c_str();
|
||||
std::lock_guard<std::mutex> guard(local_mutext);
|
||||
std::string res = SerializeMapPtr.get()->operator[](key_object);
|
||||
return deserialize<T>(res);
|
||||
} catch (const std::exception& e) {
|
||||
cout << e.what() << endl;
|
||||
|
||||
}
|
||||
|
||||
return deserialize<T>("dsd");
|
||||
}
|
||||
|
||||
} // namespace SerializeMapShm
|
||||
29
TestProject/SHM/ShmMap.h
Normal file
29
TestProject/SHM/ShmMap.h
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
#include <mix_cc/shm.h>
|
||||
namespace EqpmShm {
|
||||
namespace SHM = mix_cc::shm;
|
||||
namespace bipc = mix_cc::shm::bip;
|
||||
|
||||
const static std::string dir_path = "/users/dsc/code/TestProject/ShmTest/build";
|
||||
const static std::string shm_file = "ShmMap"; ///<映射文件名
|
||||
const double data_size = 5; ///< 数据大小 MB
|
||||
|
||||
static bipc::managed_mapped_file obj_mapped_file(
|
||||
bipc::open_or_create, (dir_path + "/" + shm_file + "_boost.mmap").c_str(),
|
||||
mix_cc::data_size::MB(data_size));
|
||||
|
||||
/**
|
||||
* @brief 记录的开始时间,结束时间,默认日重量,日长度
|
||||
*/
|
||||
struct TimeRecord {
|
||||
int stime;
|
||||
int etime;
|
||||
double per_weight; ///<千克
|
||||
double per_length; ///<米
|
||||
};
|
||||
/*单例 map 记录每天的重量 长度*/
|
||||
const static bipc::offset_ptr<SHM::Map<int, SHM::String>> EqpmRecordPtr =
|
||||
SHM::MapBuilder<int, SHM::String>::find_or_construct(&obj_mapped_file,
|
||||
shm_file);
|
||||
|
||||
} // namespace EqpmShm
|
||||
16
TestProject/SHM/container.h
Normal file
16
TestProject/SHM/container.h
Normal file
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* @file mix_cc/shm/container.h
|
||||
* @brief
|
||||
* @author Cat (null.null.null@qq.com)
|
||||
* @version 0.1
|
||||
* @date 2021-05-07
|
||||
*
|
||||
* Copyright: Baosight Co. Ltd.
|
||||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include
|
||||
#include "container/map.h"
|
||||
#include "container/string.h"
|
||||
#include "container/vector.h"
|
||||
36
TestProject/SHM/segment.hpp
Normal file
36
TestProject/SHM/segment.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include <boost/interprocess/allocators/allocator.hpp>
|
||||
#include <boost/interprocess/managed_mapped_file.hpp>
|
||||
#include <boost/interprocess/managed_shared_memory.hpp>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
typedef boost::interprocess::managed_mapped_file mapped_file_t;
|
||||
typedef boost::interprocess::managed_shared_memory shared_memory_t;
|
||||
|
||||
template <typename segment>
|
||||
class Segment {
|
||||
public:
|
||||
typedef segment segment_t;
|
||||
typedef typename segment_t::segment_manager segment_manager_t;
|
||||
|
||||
public:
|
||||
Segment(const char* name, size_t size)
|
||||
: m_name(name),
|
||||
m_size(size),
|
||||
m_segment(boost::interprocess::open_or_create, m_name.c_str(), m_size) {
|
||||
}
|
||||
|
||||
segment_t& operator()() { return m_segment; }
|
||||
/*
|
||||
...省略
|
||||
*/
|
||||
private:
|
||||
std::string m_name;
|
||||
size_t m_size;
|
||||
segment_t m_segment;
|
||||
};
|
||||
|
||||
typedef Segment<mapped_file_t> MapedFile;
|
||||
typedef Segment<shared_memory_t> SharedMemory;
|
||||
66
TestProject/SHM/shm_header.h
Normal file
66
TestProject/SHM/shm_header.h
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
* @file shm_header.h
|
||||
* @brief 共享内存 map vector 容器的头文件
|
||||
* @author your name (you@domain.com)
|
||||
* @version 0.1
|
||||
* @date 2023-10-18
|
||||
*
|
||||
* Copyright: Baosight Co. Ltd.
|
||||
* DO NOT COPY/USE WITHOUT PERMISSION
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include <mix_cc/json.h>
|
||||
#include <mix_cc/type/data_size.h>
|
||||
#include <boost/container/string.hpp>
|
||||
#include <boost/interprocess/allocators/node_allocator.hpp>
|
||||
#include <boost/interprocess/containers/map.hpp>
|
||||
#include <boost/interprocess/containers/string.hpp>
|
||||
#include <boost/interprocess/containers/vector.hpp>
|
||||
#include <boost/interprocess/managed_mapped_file.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
namespace ShmHeader {
|
||||
|
||||
namespace bipc = ::boost::interprocess;
|
||||
typedef bipc::managed_mapped_file managed_mapped_file_t; ///<映射文件
|
||||
typedef bipc::managed_mapped_file::segment_manager mapped_segment_manager_t;
|
||||
///< vector<int>
|
||||
typedef bipc::node_allocator<int, mapped_segment_manager_t> vec_allocator_i;
|
||||
typedef boost::container::vector<int, vec_allocator_i> vector_i;
|
||||
///< vector<float>
|
||||
typedef bipc::node_allocator<float, mapped_segment_manager_t> vec_allocator_f;
|
||||
typedef boost::container::vector<float, vec_allocator_f> vector_f;
|
||||
///< vector<double>
|
||||
typedef bipc::node_allocator<double, mapped_segment_manager_t> vec_allocator_d;
|
||||
typedef boost::container::vector<double, vec_allocator_d> vector_d;
|
||||
///< vector<string>
|
||||
typedef bipc::node_allocator<bipc::string, mapped_segment_manager_t>
|
||||
vec_allocator_s;
|
||||
typedef boost::container::vector<bipc::string, vec_allocator_s> vector_s;
|
||||
///<万能 allocator
|
||||
typedef bipc::node_allocator<void, mapped_segment_manager_t>
|
||||
void_allocator; ///<万能 allocator
|
||||
///< string
|
||||
typedef bipc::node_allocator<char, mapped_segment_manager_t> char_allocator;
|
||||
typedef bipc::basic_string<char, std::char_traits<char>, char_allocator>
|
||||
char_string;
|
||||
|
||||
///< map 数据
|
||||
template <class Key, class Value>
|
||||
using MapPair = std::pair<Key, Value>;
|
||||
///< map 分配器
|
||||
template <class Key, class Value>
|
||||
using AllocatorMap =
|
||||
bipc::node_allocator<MapPair<Key, Value>, mapped_segment_manager_t>;
|
||||
///< map的key排序
|
||||
template <class Key>
|
||||
using Mapless = std::less<Key>;
|
||||
///< map
|
||||
template <class Key, class Value>
|
||||
using MapValue = bipc::map<Key, Value, Mapless<Key>, AllocatorMap<Key, Value>>;
|
||||
///< map 迭代器
|
||||
template <class Key, class Value>
|
||||
using MapValueIter = MapValue<Key, Value>::iterator;
|
||||
|
||||
} // namespace ShmHeader
|
||||
41
TestProject/ShmTest/CMakeLists.txt
Normal file
41
TestProject/ShmTest/CMakeLists.txt
Normal file
@ -0,0 +1,41 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(ShmTest)
|
||||
|
||||
include(../../cmake_include/public.cmake)
|
||||
include(../../cmake_include/baosight.cmake)
|
||||
include(../../cmake_include/mix_cc.cmake)
|
||||
|
||||
find_package(
|
||||
Boost
|
||||
COMPONENTS system filesystem serialization context regex container iostreams
|
||||
stacktrace_addr2line unit_test_framework
|
||||
REQUIRED)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-omit-frame-pointer -Wno-deprecated-declarations")
|
||||
aux_source_directory(./ DIR_ROOT)
|
||||
|
||||
|
||||
set(LINK_OPTION
|
||||
${LIBTHREAD}
|
||||
${Boost_LIBRARIES}
|
||||
rt
|
||||
stdc++
|
||||
c
|
||||
m
|
||||
)
|
||||
|
||||
add_executable(
|
||||
ShmTest
|
||||
${DIR_ROOT})
|
||||
|
||||
target_link_libraries(ShmTest
|
||||
${LINK_OPTION}
|
||||
)
|
||||
|
||||
message( ${Boost_INCLUDE_DIRS} )
|
||||
|
||||
target_include_directories(
|
||||
ShmTest
|
||||
PUBLIC ./
|
||||
../
|
||||
../../
|
||||
${Boost_INCLUDE_DIRS})
|
||||
9
TestProject/ShmTest/main.cc
Normal file
9
TestProject/ShmTest/main.cc
Normal file
@ -0,0 +1,9 @@
|
||||
#include<TestProject/SHM/ShmMap.h>
|
||||
#include <iostream>
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
int main(){
|
||||
|
||||
return 0;
|
||||
}
|
||||
22
TestProject/crontablCpp/CMakeLists.txt
Normal file
22
TestProject/crontablCpp/CMakeLists.txt
Normal file
@ -0,0 +1,22 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(Test VERSION 0.1)
|
||||
|
||||
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-omit-frame-pointer -Wno-deprecated-declarations")
|
||||
|
||||
aux_source_directory(./ DIR_ROOT)
|
||||
|
||||
|
||||
|
||||
add_executable(
|
||||
Test
|
||||
${DIR_ROOT})
|
||||
|
||||
target_link_libraries(Test)
|
||||
|
||||
target_include_directories(
|
||||
Test
|
||||
PUBLIC )
|
||||
|
||||
|
||||
530
TestProject/crontablCpp/cron_timer.h
Normal file
530
TestProject/crontablCpp/cron_timer.h
Normal file
@ -0,0 +1,530 @@
|
||||
#pragma once
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace cron_timer {
|
||||
class Text {
|
||||
public:
|
||||
// Used to split strings separated by spaces, consecutive spaces are counted
|
||||
// as a separator
|
||||
static size_t SplitStr(std::vector<std::string>& os, const std::string& is,
|
||||
char c) {
|
||||
os.clear();
|
||||
auto start = is.find_first_not_of(c, 0);
|
||||
while (start != std::string::npos) {
|
||||
auto end = is.find_first_of(c, start);
|
||||
if (end == std::string::npos) {
|
||||
os.emplace_back(is.substr(start));
|
||||
break;
|
||||
} else {
|
||||
os.emplace_back(is.substr(start, end - start));
|
||||
start = is.find_first_not_of(c, end + 1);
|
||||
}
|
||||
}
|
||||
return os.size();
|
||||
}
|
||||
|
||||
static size_t SplitInt(std::vector<int>& number_result, const std::string& is,
|
||||
char c) {
|
||||
std::vector<std::string> string_result;
|
||||
SplitStr(string_result, is, c);
|
||||
|
||||
number_result.clear();
|
||||
for (size_t i = 0; i < string_result.size(); i++) {
|
||||
const std::string& value = string_result[i];
|
||||
number_result.emplace_back(atoi(value.data()));
|
||||
}
|
||||
|
||||
return number_result.size();
|
||||
}
|
||||
|
||||
static std::vector<std::string> ParseParam(const std::string& is, char c) {
|
||||
std::vector<std::string> result;
|
||||
ParseParam(result, is, c);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Used to segment strings separated by commas, consecutive commas are counted
|
||||
// as multiple delimiters
|
||||
static size_t ParseParam(std::vector<std::string>& result,
|
||||
const std::string& is, char c) {
|
||||
result.clear();
|
||||
size_t start = 0;
|
||||
while (start < is.size()) {
|
||||
auto end = is.find_first_of(c, start);
|
||||
if (end != std::string::npos) {
|
||||
result.emplace_back(is.substr(start, end - start));
|
||||
start = end + 1;
|
||||
} else {
|
||||
result.emplace_back(is.substr(start));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (start == is.size()) {
|
||||
result.emplace_back(std::string());
|
||||
}
|
||||
return result.size();
|
||||
}
|
||||
};
|
||||
|
||||
class CronExpression {
|
||||
public:
|
||||
enum DATA_TYPE {
|
||||
DT_SECOND = 0,
|
||||
DT_MINUTE = 1,
|
||||
DT_HOUR = 2,
|
||||
DT_DAY_OF_MONTH = 3,
|
||||
DT_MONTH = 4,
|
||||
DT_YEAR = 5,
|
||||
DT_MAX,
|
||||
};
|
||||
/**
|
||||
* @brief 将 [sec,min,hour,day,mon,year] 的数值 取出
|
||||
* @param input in 解除的子表达式
|
||||
* @param data_type in 子表达式的类型 [sec,min,hour,day,mon,year]
|
||||
* @param values out 子表达式结果向量
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
static bool GetValues(const std::string& input, DATA_TYPE data_type,
|
||||
std::vector<int>& values) {
|
||||
//
|
||||
// attention: enum seperater is ';' not ',' for using it in csv
|
||||
//
|
||||
|
||||
static const char CRON_SEPERATOR_ENUM = ';'; ///<多个指定时间点
|
||||
static const char CRON_SEPERATOR_RANGE = '-'; ///< a to b 时间范围
|
||||
static const char CRON_SEPERATOR_INTERVAL =
|
||||
'/'; ///< a/b 表示 a, a+b, a+2b,……
|
||||
|
||||
if (input == "*") {
|
||||
auto pair_range = GetRangeFromType(data_type);
|
||||
for (auto i = pair_range.first; i <= pair_range.second; ++i) {
|
||||
values.push_back(i);
|
||||
}
|
||||
} else if (input.find_first_of(CRON_SEPERATOR_ENUM) != std::string::npos) {
|
||||
// enum
|
||||
std::vector<int> v;
|
||||
Text::SplitInt(v, input, CRON_SEPERATOR_ENUM);
|
||||
std::pair<int, int> pair_range = GetRangeFromType(data_type);
|
||||
for (auto value : v) {
|
||||
if (value < pair_range.first || value > pair_range.second) {
|
||||
return false;
|
||||
}
|
||||
values.push_back(value);
|
||||
}
|
||||
} else if (input.find_first_of(CRON_SEPERATOR_RANGE) != std::string::npos) {
|
||||
// range
|
||||
std::vector<int> v;
|
||||
Text::SplitInt(v, input, CRON_SEPERATOR_RANGE);
|
||||
if (v.size() != 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int from = v[0];
|
||||
int to = v[1];
|
||||
std::pair<int, int> pair_range = GetRangeFromType(data_type);
|
||||
if (from < pair_range.first || to > pair_range.second) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = from; i <= to; i++) {
|
||||
values.push_back(i);
|
||||
}
|
||||
} else if (input.find_first_of(CRON_SEPERATOR_INTERVAL) !=
|
||||
std::string::npos) {
|
||||
// interval
|
||||
std::vector<int> v;
|
||||
Text::SplitInt(v, input, CRON_SEPERATOR_INTERVAL);
|
||||
if (v.size() != 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int from = v[0];
|
||||
int interval = v[1];
|
||||
std::pair<int, int> pair_range = GetRangeFromType(data_type);
|
||||
if (from < pair_range.first || interval < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = from; i <= pair_range.second; i += interval) {
|
||||
values.push_back(i);
|
||||
}
|
||||
} else {
|
||||
// specific value
|
||||
std::pair<int, int> pair_range = GetRangeFromType(data_type);
|
||||
int value = atoi(input.data());
|
||||
if (value < pair_range.first || value > pair_range.second) {
|
||||
return false;
|
||||
}
|
||||
|
||||
values.push_back(value);
|
||||
}
|
||||
|
||||
assert(values.size() > 0);
|
||||
return values.size() > 0;
|
||||
}
|
||||
|
||||
private:
|
||||
static std::pair<int, int> GetRangeFromType(DATA_TYPE data_type) {
|
||||
int from = 0;
|
||||
int to = 0;
|
||||
|
||||
switch (data_type) {
|
||||
case CronExpression::DT_SECOND:
|
||||
case CronExpression::DT_MINUTE:
|
||||
from = 0;
|
||||
to = 59;
|
||||
break;
|
||||
case CronExpression::DT_HOUR:
|
||||
from = 0;
|
||||
to = 23;
|
||||
break;
|
||||
case CronExpression::DT_DAY_OF_MONTH:
|
||||
from = 1;
|
||||
to = 31;
|
||||
break;
|
||||
case CronExpression::DT_MONTH:
|
||||
from = 1;
|
||||
to = 12;
|
||||
break;
|
||||
case CronExpression::DT_YEAR:
|
||||
from = 1970;
|
||||
to = 2099;
|
||||
break;
|
||||
case CronExpression::DT_MAX:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return std::make_pair(from, to);
|
||||
}
|
||||
};
|
||||
|
||||
class TimerMgr;
|
||||
class BaseTimer;
|
||||
using FUNC_CALLBACK = std::function<void()>;
|
||||
using TimerPtr = std::shared_ptr<BaseTimer>;
|
||||
|
||||
class BaseTimer : public std::enable_shared_from_this<BaseTimer> {
|
||||
friend class TimerMgr;
|
||||
|
||||
public:
|
||||
BaseTimer(TimerMgr& owner, FUNC_CALLBACK&& func, int count)
|
||||
: m_owner(owner),
|
||||
m_func(std::move(func)),
|
||||
m_triggerTime(std::chrono::system_clock::now()),
|
||||
m_countLeft(count),
|
||||
m_canceled(false) {}
|
||||
virtual ~BaseTimer() {}
|
||||
inline void Cancel();
|
||||
|
||||
// trigger time of the timer
|
||||
std::chrono::system_clock::time_point GetTriggerTime() const {
|
||||
return m_triggerTime;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void CreateTriggerTime(bool next) = 0;
|
||||
inline void DoFunc();
|
||||
|
||||
protected:
|
||||
TimerMgr& m_owner;
|
||||
FUNC_CALLBACK m_func;
|
||||
std::chrono::system_clock::time_point m_triggerTime;
|
||||
int m_countLeft;
|
||||
bool m_canceled;
|
||||
};
|
||||
|
||||
struct CronWheel {
|
||||
CronWheel() : cur_index(0) {}
|
||||
|
||||
size_t cur_index; ///< values的下标
|
||||
std::vector<int> values; ///< 每一层时间轮上 有记录的值
|
||||
};
|
||||
|
||||
class CronTimer : public BaseTimer {
|
||||
friend class TimerMgr;
|
||||
|
||||
public:
|
||||
CronTimer(TimerMgr& owner, std::vector<CronWheel>&& wheels,
|
||||
FUNC_CALLBACK&& func, int count)
|
||||
: BaseTimer(owner, std::move(func), count), m_wheels(std::move(wheels)) {
|
||||
tm local_tm;
|
||||
time_t time_now = time(nullptr);
|
||||
|
||||
#ifdef _WIN32
|
||||
localtime_s(&local_tm, &time_now);
|
||||
#else
|
||||
localtime_r(&time_now, &local_tm);
|
||||
#endif // _WIN32
|
||||
|
||||
std::vector<int> init_values;
|
||||
init_values.push_back(local_tm.tm_sec);
|
||||
init_values.push_back(local_tm.tm_min);
|
||||
init_values.push_back(local_tm.tm_hour);
|
||||
init_values.push_back(local_tm.tm_mday);
|
||||
init_values.push_back(local_tm.tm_mon + 1);
|
||||
init_values.push_back(local_tm.tm_year + 1900);
|
||||
|
||||
std::pair<size_t, bool> pairValue = std::make_pair(0, false);
|
||||
/*最近一次需要执行的时间*/
|
||||
for (int i = CronExpression::DT_YEAR; i >= 0; i--) {
|
||||
pairValue = GetMinValid(i, init_values[i], pairValue.second);
|
||||
m_wheels[i].cur_index = pairValue.first;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Create a Trigger Time object
|
||||
* 生成需要定时执行 的时间点
|
||||
* @param next My Param doc
|
||||
*/
|
||||
virtual void CreateTriggerTime(bool next) {
|
||||
if (next) {
|
||||
Next(CronExpression::DT_SECOND);
|
||||
}
|
||||
|
||||
tm next_tm;
|
||||
memset(&next_tm, 0, sizeof(next_tm));
|
||||
next_tm.tm_sec = GetCurValue(CronExpression::DT_SECOND);
|
||||
next_tm.tm_min = GetCurValue(CronExpression::DT_MINUTE);
|
||||
next_tm.tm_hour = GetCurValue(CronExpression::DT_HOUR);
|
||||
next_tm.tm_mday = GetCurValue(CronExpression::DT_DAY_OF_MONTH);
|
||||
next_tm.tm_mon = GetCurValue(CronExpression::DT_MONTH) - 1;
|
||||
next_tm.tm_year = GetCurValue(CronExpression::DT_YEAR) - 1900;
|
||||
|
||||
m_triggerTime = std::chrono::system_clock::from_time_t(mktime(&next_tm));
|
||||
}
|
||||
|
||||
// move to the next trigger time
|
||||
void Next(int data_type) {
|
||||
if (data_type >= CronExpression::DT_MAX) {
|
||||
// overflowed, this timer is invalid, should be removed
|
||||
m_canceled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
auto& wheel = m_wheels[data_type];
|
||||
if (wheel.cur_index == wheel.values.size() - 1) {
|
||||
wheel.cur_index = 0;
|
||||
Next(data_type + 1);
|
||||
} else {
|
||||
++wheel.cur_index;
|
||||
}
|
||||
}
|
||||
|
||||
// return index, is changed
|
||||
std::pair<size_t, bool> GetMinValid(int data_type, int value,
|
||||
bool changed) const {
|
||||
auto& wheel = m_wheels[data_type];
|
||||
if (changed) {
|
||||
return std::make_pair(0, true);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < wheel.values.size(); i++) {
|
||||
if (wheel.values[i] < value) {
|
||||
continue;
|
||||
} else if (wheel.values[i] == value) {
|
||||
return std::make_pair(i, false);
|
||||
} else {
|
||||
return std::make_pair(i, true);
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_pair(0, true);
|
||||
}
|
||||
|
||||
int GetCurValue(int data_type) const {
|
||||
const auto& wheel = m_wheels[data_type];
|
||||
return wheel.values[wheel.cur_index];
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<CronWheel> m_wheels;
|
||||
};
|
||||
|
||||
class LaterTimer : public BaseTimer {
|
||||
friend class TimerMgr;
|
||||
|
||||
public:
|
||||
LaterTimer(TimerMgr& owner, int milliseconds, FUNC_CALLBACK&& func, int count)
|
||||
: BaseTimer(owner, std::move(func), count),
|
||||
m_milliSeconds(milliseconds) {}
|
||||
|
||||
private:
|
||||
virtual void CreateTriggerTime(bool next) {
|
||||
m_triggerTime += std::chrono::milliseconds(m_milliSeconds);
|
||||
}
|
||||
|
||||
private:
|
||||
const int m_milliSeconds;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 时间轮 管理
|
||||
*/
|
||||
class TimerMgr {
|
||||
/**
|
||||
* @brief 友元类 直接操作 友元类的public成员
|
||||
*/
|
||||
friend class BaseTimer;
|
||||
friend class CronTimer;
|
||||
friend class LaterTimer;
|
||||
|
||||
public:
|
||||
TimerMgr() {}
|
||||
TimerMgr(const TimerMgr&) = delete;
|
||||
const TimerMgr& operator=(const TimerMgr&) = delete;
|
||||
|
||||
void Stop() { m_timers.clear(); }
|
||||
|
||||
enum {
|
||||
RUN_FOREVER = 0,
|
||||
};
|
||||
|
||||
TimerPtr AddTimer(const std::string& timer_string, FUNC_CALLBACK&& func,
|
||||
int count = RUN_FOREVER) {
|
||||
std::vector<std::string> v;
|
||||
Text::SplitStr(v, timer_string, ' ');
|
||||
if (v.size() != CronExpression::DT_MAX) {
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<CronWheel> wheels; ///< [sec,min,hour,day,mon,year]
|
||||
for (int i = 0; i < CronExpression::DT_MAX; i++) {
|
||||
const auto& expression = v[i];
|
||||
CronExpression::DATA_TYPE data_type = CronExpression::DATA_TYPE(i);
|
||||
CronWheel wheel;
|
||||
if (!CronExpression::GetValues(expression, data_type, wheel.values)) {
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
wheels.emplace_back(wheel);
|
||||
}
|
||||
|
||||
auto p = std::make_shared<CronTimer>(*this, std::move(wheels),
|
||||
std::move(func), count);
|
||||
p->CreateTriggerTime(false);
|
||||
insert(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
TimerPtr AddDelayTimer(int milliseconds, FUNC_CALLBACK&& func,
|
||||
int count = 1) {
|
||||
assert(milliseconds > 0);
|
||||
milliseconds = (std::max)(milliseconds, 1);
|
||||
auto p = std::make_shared<LaterTimer>(*this, milliseconds, std::move(func),
|
||||
count);
|
||||
p->CreateTriggerTime(true);
|
||||
insert(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
std::chrono::system_clock::time_point GetNearestTime() {
|
||||
auto it = m_timers.begin();
|
||||
if (it == m_timers.end()) {
|
||||
return (std::chrono::system_clock::time_point::max)();
|
||||
} else {
|
||||
return it->first;
|
||||
}
|
||||
}
|
||||
|
||||
size_t Update() {
|
||||
auto time_now = std::chrono::system_clock::now();
|
||||
size_t count = 0;
|
||||
|
||||
for (auto it = m_timers.begin(); it != m_timers.end();) {
|
||||
auto expire_time = it->first; ///<需要执行的时间点
|
||||
if (expire_time > time_now) {
|
||||
break; ///<还未到执行时间
|
||||
}
|
||||
|
||||
// attention: this is a copy, not a reference
|
||||
auto timer_set = it->second;
|
||||
it = m_timers.erase(it);
|
||||
///<当前时间点 所有需要被执行的函数
|
||||
for (auto p : timer_set) {
|
||||
p->DoFunc();
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief 需要执行的插入时间-执行函数set
|
||||
* 如果已经存在的时间点,即 m_timers的key已存在,则插入
|
||||
* TimerPtr到std::set<TimerPtr>
|
||||
* 否则新建 std::set<TimerPtr>
|
||||
* @param p My Param doc
|
||||
*/
|
||||
void insert(const TimerPtr& p) {
|
||||
auto t = p->GetTriggerTime();
|
||||
auto it = m_timers.find(t);
|
||||
if (it == m_timers.end()) {
|
||||
std::set<TimerPtr> s;
|
||||
s.insert(p);
|
||||
m_timers[t] = s;
|
||||
} else {
|
||||
std::set<TimerPtr>& s = it->second;
|
||||
s.insert(p);
|
||||
}
|
||||
}
|
||||
|
||||
void remove(const TimerPtr& p) {
|
||||
auto t = p->GetTriggerTime();
|
||||
auto it = m_timers.find(t);
|
||||
if (it == m_timers.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::set<TimerPtr>& s = it->second;
|
||||
s.erase(p);
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief 需要调用函数的时间点-TimerPtr
|
||||
* key-value
|
||||
*/
|
||||
std::map<std::chrono::system_clock::time_point, std::set<TimerPtr>> m_timers;
|
||||
};
|
||||
|
||||
void BaseTimer::Cancel() {
|
||||
auto self = shared_from_this();
|
||||
m_owner.remove(self);
|
||||
m_canceled = true;
|
||||
}
|
||||
|
||||
void BaseTimer::DoFunc() {
|
||||
m_func(); ///<执行函数
|
||||
CreateTriggerTime(true); ///<重置下次时间
|
||||
|
||||
// the timer can be cancelled in m_func()
|
||||
if (!m_canceled) {
|
||||
if (m_countLeft == TimerMgr::RUN_FOREVER || m_countLeft > 1) {
|
||||
if (m_countLeft > 1) {
|
||||
m_countLeft--;
|
||||
}
|
||||
|
||||
auto self = shared_from_this();
|
||||
m_owner.insert(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace cron_timer
|
||||
172
TestProject/crontablCpp/main.cpp
Normal file
172
TestProject/crontablCpp/main.cpp
Normal file
@ -0,0 +1,172 @@
|
||||
#include <stdio.h>
|
||||
#include <atomic>
|
||||
#include <cstdarg>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#include "cron_timer.h"
|
||||
|
||||
std::atomic_bool _shutDown;
|
||||
|
||||
#ifdef _WIN32
|
||||
BOOL WINAPI ConsoleHandler(DWORD CtrlType) {
|
||||
switch (CtrlType) {
|
||||
case CTRL_C_EVENT:
|
||||
case CTRL_CLOSE_EVENT:
|
||||
case CTRL_LOGOFF_EVENT:
|
||||
case CTRL_SHUTDOWN_EVENT:
|
||||
_shutDown = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
#else
|
||||
void signal_hander(int signo) {
|
||||
printf("catch a signal:%d\n:", signo);
|
||||
_shutDown = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string FormatDateTime(const std::chrono::system_clock::time_point& time) {
|
||||
uint64_t micro =
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
time.time_since_epoch())
|
||||
.count() -
|
||||
std::chrono::duration_cast<std::chrono::seconds>(time.time_since_epoch())
|
||||
.count() *
|
||||
1000000;
|
||||
char _time[64] = {0};
|
||||
time_t tt = std::chrono::system_clock::to_time_t(time);
|
||||
struct tm local_time;
|
||||
|
||||
#ifdef _WIN32
|
||||
localtime_s(&local_time, &tt);
|
||||
#else
|
||||
localtime_r(&tt, &local_time);
|
||||
#endif // _WIN32
|
||||
|
||||
std::snprintf(_time, sizeof(_time), "%d-%02d-%02d %02d:%02d:%02d.%06ju",
|
||||
local_time.tm_year + 1900, local_time.tm_mon + 1,
|
||||
local_time.tm_mday, local_time.tm_hour, local_time.tm_min,
|
||||
local_time.tm_sec, micro);
|
||||
return std::string(_time);
|
||||
}
|
||||
|
||||
void Log(const char* fmt, ...) {
|
||||
char buf[4096];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsnprintf(buf, sizeof(buf) - 1, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
std::string time_now = FormatDateTime(std::chrono::system_clock::now());
|
||||
printf("%s %s\n", time_now.c_str(), buf);
|
||||
}
|
||||
|
||||
void TestSplitStr() {
|
||||
std::vector<std::string> v;
|
||||
assert(cron_timer::Text::SplitStr(v, "", ' ') == 0);
|
||||
assert(cron_timer::Text::SplitStr(v, " ", ' ') == 0);
|
||||
assert(cron_timer::Text::SplitStr(v, "a", ' ') == 1);
|
||||
assert(cron_timer::Text::SplitStr(v, "abcc", ' ') == 1);
|
||||
assert(cron_timer::Text::SplitStr(v, "abc def", ' ') == 2);
|
||||
assert(cron_timer::Text::SplitStr(v, " abc def", ' ') == 2);
|
||||
assert(cron_timer::Text::SplitStr(v, " abc def ", ' ') == 2);
|
||||
assert(cron_timer::Text::SplitStr(v, " abc def ", ' ') == 2);
|
||||
|
||||
assert(cron_timer::Text::ParseParam(v, "", ',') == 1);
|
||||
assert(cron_timer::Text::ParseParam(v, " ", ',') == 1);
|
||||
assert(cron_timer::Text::ParseParam(v, "a", ',') == 1);
|
||||
assert(cron_timer::Text::ParseParam(v, "abcc", ',') == 1);
|
||||
assert(cron_timer::Text::ParseParam(v, "abc,def", ',') == 2);
|
||||
assert(cron_timer::Text::ParseParam(v, "abc,,def", ',') == 3);
|
||||
assert(cron_timer::Text::ParseParam(v, ",,abc,,,def,,", ',') == 8);
|
||||
assert(cron_timer::Text::ParseParam(v, ",,,", ',') == 4);
|
||||
}
|
||||
|
||||
void TestCronTimerInMainThread() {
|
||||
cron_timer::TimerMgr mgr;
|
||||
|
||||
mgr.AddTimer("* * * * * *", [](void) {
|
||||
// every second
|
||||
Log("1 second cron timer hit");
|
||||
});
|
||||
|
||||
mgr.AddTimer("0 15 12 * * *", [](void) {
|
||||
// every second
|
||||
Log("指定时间点 12:15 cron timer hit");
|
||||
});
|
||||
|
||||
mgr.AddTimer("0/3 * * * * *", [](void) {
|
||||
// every 3 seconds
|
||||
Log("3 second cron timer hit");
|
||||
});
|
||||
|
||||
mgr.AddTimer("0 * * * * *", [](void) {
|
||||
// every minute
|
||||
Log("1 minute cron timer hit");
|
||||
});
|
||||
|
||||
mgr.AddTimer("15;30;33 * * * * *", [](void) {
|
||||
// specific second
|
||||
Log("cron timer hit at 15s or 30s or 33s");
|
||||
});
|
||||
|
||||
mgr.AddTimer("40-50 * * * * *", [](void) {
|
||||
// seconds interval
|
||||
Log("cron timer hit between 40s to 50s");
|
||||
});
|
||||
|
||||
std::weak_ptr<cron_timer::BaseTimer> timer =
|
||||
mgr.AddDelayTimer(3000, [](void) {
|
||||
// after 3 seconds
|
||||
Log("3 second delay timer hit");
|
||||
});
|
||||
|
||||
// can be cancelled
|
||||
if (auto ptr = timer.lock(); ptr != nullptr) {
|
||||
ptr->Cancel();
|
||||
}
|
||||
|
||||
mgr.AddDelayTimer(10000,
|
||||
[](void) {
|
||||
// every 10 seconds for 3 times
|
||||
Log("10 second delay timer hit");
|
||||
},
|
||||
3);
|
||||
Log("10 second delay timer added");
|
||||
|
||||
while (!_shutDown) {
|
||||
auto nearest_timer = (std::min)(
|
||||
std::chrono::system_clock::now() + std::chrono::milliseconds(500),
|
||||
mgr.GetNearestTime());
|
||||
std::this_thread::sleep_until(nearest_timer);
|
||||
auto reseult11 = mgr.Update();
|
||||
Log(std::to_string(reseult11).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
#ifdef _WIN32
|
||||
SetConsoleCtrlHandler(ConsoleHandler, TRUE);
|
||||
EnableMenuItem(GetSystemMenu(GetConsoleWindow(), false), SC_CLOSE,
|
||||
MF_GRAYED | MF_BYCOMMAND);
|
||||
#else
|
||||
signal(SIGINT, signal_hander);
|
||||
#endif
|
||||
|
||||
TestSplitStr();
|
||||
TestCronTimerInMainThread();
|
||||
return 0;
|
||||
}
|
||||
431960
TestProject/data_files/C308仿-压辊数据.csv
Normal file
431960
TestProject/data_files/C308仿-压辊数据.csv
Normal file
File diff suppressed because it is too large
Load Diff
35424
TestProject/data_files/C308速度毛刺仿真.csv
Normal file
35424
TestProject/data_files/C308速度毛刺仿真.csv
Normal file
File diff suppressed because it is too large
Load Diff
432000
TestProject/data_files/D102-1#酸槽数据.csv
Normal file
432000
TestProject/data_files/D102-1#酸槽数据.csv
Normal file
File diff suppressed because it is too large
Load Diff
72000
TestProject/data_files/D102-3#BR异常电流数据.csv
Normal file
72000
TestProject/data_files/D102-3#BR异常电流数据.csv
Normal file
File diff suppressed because it is too large
Load Diff
432000
TestProject/data_files/D102-3#BR电流数据.csv
Normal file
432000
TestProject/data_files/D102-3#BR电流数据.csv
Normal file
File diff suppressed because it is too large
Load Diff
216000
TestProject/data_files/D102-4#机架上中间辊窜辊.csv
Normal file
216000
TestProject/data_files/D102-4#机架上中间辊窜辊.csv
Normal file
File diff suppressed because it is too large
Load Diff
216000
TestProject/data_files/D102-loop8.csv
Normal file
216000
TestProject/data_files/D102-loop8.csv
Normal file
File diff suppressed because it is too large
Load Diff
359400
TestProject/data_files/D302-1#机架正弯.csv
Normal file
359400
TestProject/data_files/D302-1#机架正弯.csv
Normal file
File diff suppressed because it is too large
Load Diff
288000
TestProject/data_files/D302-2#小车减速位.csv
Normal file
288000
TestProject/data_files/D302-2#小车减速位.csv
Normal file
File diff suppressed because it is too large
Load Diff
359400
TestProject/data_files/D302-3#活套1-5电流.csv
Normal file
359400
TestProject/data_files/D302-3#活套1-5电流.csv
Normal file
File diff suppressed because it is too large
Load Diff
432000
TestProject/data_files/D302-压辊数据.csv
Normal file
432000
TestProject/data_files/D302-压辊数据.csv
Normal file
File diff suppressed because it is too large
Load Diff
144000
TestProject/data_files/D302-工作辊正弯DS.csv
Normal file
144000
TestProject/data_files/D302-工作辊正弯DS.csv
Normal file
File diff suppressed because it is too large
Load Diff
40435
TestProject/data_files/数据毛刺-仿真.csv
Normal file
40435
TestProject/data_files/数据毛刺-仿真.csv
Normal file
File diff suppressed because it is too large
Load Diff
10000
TestProject/data_files/毛刺数据.csv
Normal file
10000
TestProject/data_files/毛刺数据.csv
Normal file
File diff suppressed because it is too large
Load Diff
30000
TestProject/data_files/液位.csv
Normal file
30000
TestProject/data_files/液位.csv
Normal file
File diff suppressed because it is too large
Load Diff
3159
TestProject/data_files/转矩减小-速度偏差大-仿真2.csv
Normal file
3159
TestProject/data_files/转矩减小-速度偏差大-仿真2.csv
Normal file
File diff suppressed because it is too large
Load Diff
42
TestProject/ihd_test/CMakeLists.txt
Normal file
42
TestProject/ihd_test/CMakeLists.txt
Normal file
@ -0,0 +1,42 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(ihdTest)
|
||||
|
||||
include(../../cmake_include/public.cmake)
|
||||
include(../../cmake_include/baosight.cmake)
|
||||
include(../../cmake_include/mix_cc.cmake)
|
||||
|
||||
# find_package(
|
||||
# Boost
|
||||
# COMPONENTS system filesystem serialization context regex container iostreams
|
||||
# stacktrace_addr2line unit_test_framework
|
||||
# REQUIRED)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-omit-frame-pointer -Wno-deprecated-declarations")
|
||||
aux_source_directory(./ DIR_ROOT)
|
||||
|
||||
|
||||
set(LINK_OPTION
|
||||
${LIBTHREAD}
|
||||
# ${Boost_LIBRARIES}
|
||||
${IHDB_LIB}
|
||||
rt
|
||||
stdc++
|
||||
c
|
||||
m
|
||||
)
|
||||
|
||||
add_executable(
|
||||
ihdTest
|
||||
${DIR_ROOT})
|
||||
|
||||
target_link_libraries(ihdTest
|
||||
${LINK_OPTION}
|
||||
)
|
||||
|
||||
# message( ${Boost_INCLUDE_DIRS} )
|
||||
|
||||
target_include_directories(
|
||||
ihdTest
|
||||
PUBLIC ./
|
||||
../
|
||||
../../)
|
||||
# ${Boost_INCLUDE_DIRS})
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user