qvvr has bug
This commit is contained in:
@@ -185,6 +185,8 @@ int IED_COUNT = 300; //默认300
|
||||
|
||||
extern int INITFLAG;
|
||||
|
||||
extern uint32_t g_ontime_blocked_times;
|
||||
|
||||
//lnk2024-8-14添加角型接线标志,0不存在角形接线,1存在角形接线
|
||||
int isdelta_flag = 0;
|
||||
|
||||
@@ -1442,7 +1444,12 @@ int parse_rpt_log_ini()
|
||||
if(tmp == NULL){std::cerr << "front read ied config error!" << std::endl;continue;}
|
||||
qDebug() << tmp << endl;
|
||||
|
||||
apr_snprintf(str, sizeof(str), tmp, cpuno + 1);
|
||||
//apr_snprintf(str, sizeof(str), tmp, cpuno + 1);
|
||||
|
||||
//ied_usr->LD_info[cpuno].LD_name = apr_pstrdup(g_init_pool, str);
|
||||
|
||||
//已经分配过内存,直接复制到里面
|
||||
apr_snprintf(ied_usr->LD_info[cpuno].LD_name, sizeof(ied_usr->LD_info[cpuno].LD_name), tmp, cpuno + 1);
|
||||
|
||||
delete[] tmp;
|
||||
|
||||
@@ -3453,12 +3460,14 @@ int terminal_ledger_web(QMap<QString, terminal_dev*>* terminal_dev_map,
|
||||
// 参数验证
|
||||
if (num <= 0) {
|
||||
std::cerr << "Error: 'num' must be greater than 0." << std::endl;
|
||||
DIY_ERRORLOG("process","【ERROR】前置的多进程最大进程号为:%d,应该为大于0的整数",num);
|
||||
return 1; // 返回适当的错误码
|
||||
}
|
||||
|
||||
index = index - 1;
|
||||
if (index < 0 || index >= num) {
|
||||
std::cerr << "Error: 'index' must be in the range [0, num-1]." << std::endl;
|
||||
std::cerr << "Error: 'index' must be in the range [0, num]." << std::endl;
|
||||
DIY_ERRORLOG("process","【ERROR】前置当前进程的进程号为:%d,应该为0到最大进程号范围内的整数",index);
|
||||
return 1; // 返回适当的错误码
|
||||
}
|
||||
}
|
||||
@@ -3466,6 +3475,7 @@ int terminal_ledger_web(QMap<QString, terminal_dev*>* terminal_dev_map,
|
||||
// 获取参数
|
||||
if (codes.empty()) {
|
||||
std::cerr << "Error: 'codes' vector is empty." << std::endl;
|
||||
DIY_ERRORLOG("process","【ERROR】前置的%s%d号进程调用web台账接口的入参为空",get_front_msg_from_subdir(), g_front_seg_index);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -3558,9 +3568,7 @@ int terminal_ledger_web(QMap<QString, terminal_dev*>* terminal_dev_map,
|
||||
}*/
|
||||
while (1) {
|
||||
// 请求接口
|
||||
SendJsonAPI_web(WEB_DEVICE, "", parm.c_str(), &ptr);
|
||||
|
||||
|
||||
SendJsonAPI_web(WEB_DEVICE, "", parm.c_str(), &ptr);
|
||||
|
||||
if (ptr != NULL) {
|
||||
|
||||
@@ -3826,9 +3834,14 @@ int parse_device_cfg_web()
|
||||
|
||||
std::cout << "input_jstr: " << input_jstr << std::endl; // 输出结果
|
||||
|
||||
DIY_DEBUGLOG("process","【DEBUG】前置的%s%d号进程调用web接口获取台账使用的请求输入为:%s",get_front_msg_from_subdir(), g_front_seg_index,input_jstr);
|
||||
|
||||
codes.push_back(input_jstr); //是否需要筛选状态直接在配置文件控制
|
||||
|
||||
terminal_ledger_web(&terminal_dev_map,codes,g_front_seg_index,g_front_seg_num);
|
||||
if(terminal_ledger_web(&terminal_dev_map,codes,g_front_seg_index,g_front_seg_num)){
|
||||
return APR_EBADF;
|
||||
}
|
||||
|
||||
codes.clear();
|
||||
|
||||
//调试用
|
||||
@@ -3855,9 +3868,15 @@ int parse_device_cfg_web()
|
||||
|
||||
//判断是否相等
|
||||
if(max_process_num != max_index){
|
||||
// 调用执行脚本函数
|
||||
close_listening_socket();
|
||||
execute_bash("reset", max_process_num, "all");
|
||||
if(max_process_num > 0 && max_process_num < 10){
|
||||
DIY_WARNLOG("process","【WARN】前置比对台账获取的进程数:%s和本地配置的进程数:%s,不匹配,按照台账进程数重置前置的进程数量",max_process_num,max_index);
|
||||
// 调用执行脚本函数
|
||||
close_listening_socket();
|
||||
execute_bash("reset", max_process_num, "all");
|
||||
}
|
||||
else{
|
||||
DIY_ERRORLOG("process","【ERROR】前置从台账获取的进程数:%s不符合范围1~9,按照本地配置进程数启动进程",max_process_num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3865,6 +3884,8 @@ int parse_device_cfg_web()
|
||||
|
||||
std::cout << "terminal_ledger_num:" << count_cfg << std::endl;
|
||||
|
||||
DIY_DEBUGLOG("process","【DEBUG】前置的%s%d号进程调用获取到的台账的数量为:%d",get_front_msg_from_subdir(), g_front_seg_index,count_cfg);
|
||||
|
||||
//如果当前进程获取的台账为0,按照配置数量申请空间,台账内容为空
|
||||
g_node->n_clients = count_cfg;
|
||||
|
||||
@@ -3877,9 +3898,12 @@ int parse_device_cfg_web()
|
||||
g_node->clients = (ied_t**)apr_pcalloc(g_cfg_pool, count_cfg * sizeof(ied_t*));
|
||||
//添加提示
|
||||
std::cout << "!!!!!!!!!!single process can not add any ledger unless reboot!!!!!!!"<< std::endl;
|
||||
|
||||
DIY_WARNLOG("process","【WARN】前置的%s%d号进程获取到的台账的数量大于配置文件中给单个进程配置的台账数量:%d,这个进程将按照获取到的台账的数量来创建台账空间,这个进程不能直接通过台账添加来新增台账,只能通过重启进程或者先删除已有台账再添加台账的方式来添加新台账",get_front_msg_from_subdir(), g_front_seg_index,IED_COUNT);
|
||||
}
|
||||
else{
|
||||
g_node->clients = (ied_t**)apr_pcalloc(g_cfg_pool, IED_COUNT * sizeof(ied_t*));//g_node->clients 这块大内存空间存储了 count_cfg 个 ied_t* 类型的指针(即一个指针数组)这是(指向内存块的指针)的指针数组
|
||||
DIY_INFOLOG("process","【NORMAL】前置的%s%d号进程根据配置文件中给单个进程配置的台账数量:%d来创建台账空间",get_front_msg_from_subdir(), g_front_seg_index,IED_COUNT);
|
||||
}
|
||||
|
||||
//把ied放入数组
|
||||
@@ -4555,6 +4579,9 @@ void OnTimerThread::run()
|
||||
}
|
||||
counter++;
|
||||
|
||||
//清空计数器
|
||||
g_ontime_blocked_times =0;
|
||||
|
||||
msleep(1000);
|
||||
}
|
||||
printf(">>>OnTimerThread::run() is end!!!\n");
|
||||
@@ -6466,9 +6493,9 @@ void send_reply_to_kafka(const std::string& guid, const std::string& step, const
|
||||
oss << "{"
|
||||
<< "\"guid\":\"" << guid << "\","
|
||||
<< "\"step\":\"" << step << "\","
|
||||
<< "\"result\":\"" << result << "\""
|
||||
<< "\"processNo\":\"" << g_front_seg_index << "\""
|
||||
<< "\"frontType\":\"" << get_front_type_from_subdir() << "\""
|
||||
<< "\"result\":\"" << result << "\","
|
||||
<< "\"processNo\":\"" << g_front_seg_index << "\","
|
||||
<< "\"frontType\":\"" << get_front_type_from_subdir() << "\","
|
||||
<< "\"nodeId\":\"" << FRONT_INST << "\""
|
||||
<< "}";
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
extern unsigned int g_node_id;
|
||||
extern int g_front_seg_index;
|
||||
extern std::string FRONT_INST;
|
||||
extern char subdir[128];
|
||||
extern node_t* g_node;
|
||||
|
||||
@@ -77,6 +78,14 @@ bool create_directory_recursive(const std::string& path) {
|
||||
return true;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
std::string extract_logger_id(const std::string& logger_name) {
|
||||
size_t pos = logger_name.find('.');
|
||||
if (pos != std::string::npos && pos + 1 < logger_name.size()) {
|
||||
return logger_name.substr(pos + 1);
|
||||
}
|
||||
return ""; // 没有找到 '.' 或 '.' 后为空
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
TypedLogger::TypedLogger() {}
|
||||
TypedLogger::TypedLogger(const Logger& l, int t) : logger(l), logtype(t) {}
|
||||
|
||||
@@ -126,7 +135,8 @@ protected:
|
||||
if (level == ERROR_LOG_LEVEL || level == WARN_LOG_LEVEL || g_debug_switch.match(logger_name, level, logtype)) {
|
||||
std::ostringstream oss;
|
||||
oss << "{\"processNo\":\"" << intToString(g_front_seg_index)
|
||||
<< "\",\"id\":\"" << logger_name
|
||||
<< "\",\"nodeId\":\"" << FRONT_INST
|
||||
<< "\",\"businessId\":\"" << extract_logger_id(logger_name)
|
||||
<< "\",\"level\":\"" << level_str
|
||||
<< "\",\"grade\":\"" << level
|
||||
<< "\",\"logtype\":\"" << (logtype == LOGTYPE_COM ? "com" : "data")
|
||||
@@ -354,8 +364,12 @@ void init_loggers() {
|
||||
logger_map[device_key + ".DATA"] = TypedLogger(device_logger, LOGTYPE_DATA);
|
||||
|
||||
char buf[256];
|
||||
sprintf(buf, "终端id:%s终端级日志初始化完毕", ied_usr->terminal_id);
|
||||
LOG4CPLUS_DEBUG(logger_map[device_key + ".DATA"].logger, buf);
|
||||
//sprintf(buf, "终端id:%s终端级日志初始化完毕", ied_usr->terminal_id);
|
||||
//LOG4CPLUS_DEBUG(logger_map[device_key + ".DATA"].logger, buf);
|
||||
//format_log_msg(buf,sizeof(buf),"终端id:%s终端级日志初始化完毕", ied_usr->terminal_id);
|
||||
//log_debug(std::string(device_key + ".DATA").c_str(),buf);
|
||||
std::string full_key_t = device_key + ".DATA";
|
||||
DIY_WARNLOG(full_key_t.c_str(),"终端id:%s终端级日志初始化完毕", ied_usr->terminal_id);
|
||||
|
||||
// 初始化监测点
|
||||
// 监测点 logger 名称格式:monitor.<mp_id>.COM / .DATA
|
||||
@@ -371,9 +385,14 @@ void init_loggers() {
|
||||
logger_map[mon_key.str() + ".COM"] = TypedLogger(mon_logger, LOGTYPE_COM);
|
||||
logger_map[mon_key.str() + ".DATA"] = TypedLogger(mon_logger, LOGTYPE_DATA);
|
||||
|
||||
char buf[256];
|
||||
sprintf(buf, "监测点id:%s监测点级日志初始化完毕", ied_usr->LD_info[i].mp_id);
|
||||
LOG4CPLUS_DEBUG(logger_map[mon_key.str() + ".DATA"].logger, buf);
|
||||
//char buf[256];
|
||||
//sprintf(buf, "监测点id:%s监测点级日志初始化完毕", ied_usr->LD_info[i].mp_id);
|
||||
//LOG4CPLUS_DEBUG(logger_map[mon_key.str() + ".DATA"].logger, buf);
|
||||
//format_log_msg(buf,sizeof(buf),"监测点id:%s监测点级日志初始化完毕", ied_usr->LD_info[i].mp_id);
|
||||
//log_debug(std::string(mon_key.str() + ".DATA").c_str(),buf);
|
||||
std::string full_key_m = mon_key.str() + ".DATA";
|
||||
DIY_WARNLOG(full_key_m.c_str(),"监测点:%s - id:%s监测点级日志初始化完毕", ied_usr->LD_info[i].name,ied_usr->LD_info[i].mp_id);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -433,7 +452,11 @@ void remove_loggers_by_terminal_id(const char* terminal_id_cstr) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// 公共函数
|
||||
void log4_log_with_level(const char* key, const char* msg, int level) {
|
||||
@@ -459,8 +482,25 @@ extern "C" {
|
||||
void send_reply_to_kafka_c(const char* guid, const char* step, const char* result) {
|
||||
send_reply_to_kafka(std::string(guid), std::string(step), std::string(result));
|
||||
}
|
||||
|
||||
//标准化日志接口
|
||||
void format_log_msg(char* buf, size_t buf_size, const char* fmt, ...) {
|
||||
// 写入时间
|
||||
time_t now = time(NULL);
|
||||
struct tm tm_info;
|
||||
localtime_r(&now, &tm_info);
|
||||
strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S ", &tm_info); // 时间+空格
|
||||
|
||||
// 处理可变参数并写入剩余内容
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsnprintf(buf + strlen(buf), buf_size - strlen(buf), fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user